Chromium Code Reviews| Index: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc |
| diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc b/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc |
| index b797ebc7b46a03ed2a0d57286197e650dab3075f..aae1a67fab819a932e96c0b2c7d09ab484ee45ef 100644 |
| --- a/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc |
| +++ b/chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc |
| @@ -22,6 +22,7 @@ |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/test/browser_test_utils.h" |
| +#include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| @@ -133,6 +134,65 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| EXPECT_EQ(GURL("about:blank"), tab->GetURL()); |
| } |
| +// GTK requires a X11-level mouse event to open a context menu correctly. |
| +#if defined(TOOLKIT_GTK) |
| +#define MAYBE_RealCustomMenu DISABLED_RealCustomMenu |
| +#else |
| +#define MAYBE_RealCustomMenu RealCustomMenu |
| +#endif |
| +// Opens a link in a new tab via a "real" context menu. |
| +IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| + MAYBE_RealCustomMenu) { |
| + // menu_observer executes the first menu item command. |
| + ContextMenuNotificationObserver menu_observer(47000); |
| + |
| + ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| + // Go to a test page |
| + GURL url = embedded_test_server()->GetURL( |
| + "/context_menu/custom_context_menu.html"); |
| + ui_test_utils::NavigateToURL( |
| + browser(), url); |
| + |
| + // Open a context menu. |
| + blink::WebMouseEvent mouse_event; |
| + mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| + mouse_event.x = 50; |
| + mouse_event.y = 50; |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + gfx::Rect offset = tab->GetContainerBounds(); |
| + mouse_event.globalX = 50 + offset.x(); |
| + mouse_event.globalY = 50 + offset.y(); |
| + mouse_event.clickCount = 1; |
| + mouse_event.type = blink::WebInputEvent::MouseDown; |
| + tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| + mouse_event.type = blink::WebInputEvent::MouseUp; |
| + tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| + |
| + // The menu_observer will execute the action corresponding to item 1, |
| + // wait for the title to change. |
| + base::string16 title_1 = base::ASCIIToUTF16("Title 1"); |
| + content::TitleWatcher title_1_watcher(tab, title_1); |
| + ASSERT_EQ(title_1, title_1_watcher.WaitAndGetTitle()); |
| + |
| + // Verify that it's the correct tab. |
| + EXPECT_EQ(base::ASCIIToUTF16("Title 1"), tab->GetTitle()); |
| + |
| + menu_observer.setCommandId(47002); |
|
lazyboy
2014/05/24 15:26:31
Probably use IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 2?
|
| + mouse_event.type = blink::WebInputEvent::MouseDown; |
| + tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| + mouse_event.type = blink::WebInputEvent::MouseUp; |
| + tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| + |
| + // The menu_observer will execute the action corresponding to item 3, |
| + // wait for the title to change. |
| + content::TitleWatcher title_3_watcher(tab, base::ASCIIToUTF16("Title 3")); |
| + ASSERT_EQ(base::ASCIIToUTF16("Title 3"), title_3_watcher.WaitAndGetTitle()); |
| + |
| + // Verify that it's the correct tab. |
| + EXPECT_EQ(base::ASCIIToUTF16("Title 3"), tab->GetTitle()); |
| +} |
| + |
| // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. |
| IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { |
| ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |