| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 class ContextMenuBrowserTest : public InProcessBrowserTest { | 49 class ContextMenuBrowserTest : public InProcessBrowserTest { |
| 50 public: | 50 public: |
| 51 ContextMenuBrowserTest() { } | 51 ContextMenuBrowserTest() { } |
| 52 | 52 |
| 53 TestRenderViewContextMenu* CreateContextMenu(GURL unfiltered_url, GURL url) { | 53 TestRenderViewContextMenu* CreateContextMenu(GURL unfiltered_url, GURL url) { |
| 54 content::ContextMenuParams params; | 54 content::ContextMenuParams params; |
| 55 params.media_type = WebKit::WebContextMenuData::MediaTypeNone; | 55 params.media_type = WebKit::WebContextMenuData::MediaTypeNone; |
| 56 params.unfiltered_link_url = unfiltered_url; | 56 params.unfiltered_link_url = unfiltered_url; |
| 57 params.link_url = url; | 57 params.link_url = url; |
| 58 WebContents* web_contents = browser()->GetSelectedWebContents(); | 58 WebContents* web_contents = browser()->GetActiveWebContents(); |
| 59 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); | 59 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); |
| 60 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
| 61 params.writing_direction_default = 0; | 61 params.writing_direction_default = 0; |
| 62 params.writing_direction_left_to_right = 0; | 62 params.writing_direction_left_to_right = 0; |
| 63 params.writing_direction_right_to_left = 0; | 63 params.writing_direction_right_to_left = 0; |
| 64 #endif // OS_MACOSX | 64 #endif // OS_MACOSX |
| 65 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 65 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
| 66 browser()->GetSelectedWebContents(), params); | 66 browser()->GetActiveWebContents(), params); |
| 67 menu->Init(); | 67 menu->Init(); |
| 68 return menu; | 68 return menu; |
| 69 } | 69 } |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 72 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 73 OpenEntryPresentForNormalURLs) { | 73 OpenEntryPresentForNormalURLs) { |
| 74 scoped_ptr<TestRenderViewContextMenu> menu( | 74 scoped_ptr<TestRenderViewContextMenu> menu( |
| 75 CreateContextMenu(GURL("http://www.google.com/"), | 75 CreateContextMenu(GURL("http://www.google.com/"), |
| 76 GURL("http://www.google.com/"))); | 76 GURL("http://www.google.com/"))); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 ui_test_utils::NavigateToURL( | 110 ui_test_utils::NavigateToURL( |
| 111 browser(), GURL("data:text/html,<a href='about:blank'>link</a>")); | 111 browser(), GURL("data:text/html,<a href='about:blank'>link</a>")); |
| 112 | 112 |
| 113 // Open a context menu. | 113 // Open a context menu. |
| 114 WebKit::WebMouseEvent mouse_event; | 114 WebKit::WebMouseEvent mouse_event; |
| 115 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 115 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 116 mouse_event.button = WebKit::WebMouseEvent::ButtonRight; | 116 mouse_event.button = WebKit::WebMouseEvent::ButtonRight; |
| 117 mouse_event.x = 15; | 117 mouse_event.x = 15; |
| 118 mouse_event.y = 15; | 118 mouse_event.y = 15; |
| 119 gfx::Rect offset; | 119 gfx::Rect offset; |
| 120 content::WebContents* tab = browser()->GetSelectedWebContents(); | 120 content::WebContents* tab = browser()->GetActiveWebContents(); |
| 121 tab->GetView()->GetContainerBounds(&offset); | 121 tab->GetView()->GetContainerBounds(&offset); |
| 122 mouse_event.globalX = 15 + offset.x(); | 122 mouse_event.globalX = 15 + offset.x(); |
| 123 mouse_event.globalY = 15 + offset.y(); | 123 mouse_event.globalY = 15 + offset.y(); |
| 124 mouse_event.clickCount = 1; | 124 mouse_event.clickCount = 1; |
| 125 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 125 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 126 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 126 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 127 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 127 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 128 | 128 |
| 129 // The menu_observer will select "Open in new tab", wait for the new tab to | 129 // The menu_observer will select "Open in new tab", wait for the new tab to |
| 130 // be added. | 130 // be added. |
| 131 tab_observer.Wait(); | 131 tab_observer.Wait(); |
| 132 tab = tab_observer.GetTab(); | 132 tab = tab_observer.GetTab(); |
| 133 ui_test_utils::WaitForLoadStop(tab); | 133 ui_test_utils::WaitForLoadStop(tab); |
| 134 | 134 |
| 135 // Verify that it's the correct tab. | 135 // Verify that it's the correct tab. |
| 136 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); | 136 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace | 139 } // namespace |
| OLD | NEW |