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 518ea4ba48e4a91090a43bac842b5d820cfc4052..e256699c0d82d17b1ca6b866ca2907d9990e2634 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" |
| @@ -52,6 +53,42 @@ class ContextMenuBrowserTest : public InProcessBrowserTest { |
| menu->Init(); |
| return menu; |
| } |
| + |
| + void OpenContextMenuAtPoint(int x, int y) { |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + // Open context menu |
| + blink::WebMouseEvent mouse_event; |
| + mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| + mouse_event.x = x; |
| + mouse_event.y = y; |
| + gfx::Rect offset = tab->GetContainerBounds(); |
| + mouse_event.globalX = x + offset.x(); |
| + mouse_event.globalY = y + 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); |
| + } |
| + |
| + void ExecuteCustomMenuCommandAndVerifyTabTitle(unsigned command_id, |
|
lazyboy
2014/09/19 21:38:18
Fix indentation of params.
pals
2014/09/22 05:05:26
Done.
|
| + const std::string& expected) { |
| + // menu_observer executes the menu item command with |command_id|. |
| + ContextMenuNotificationObserver menu_observer(command_id); |
| + OpenContextMenuAtPoint(50, 50); |
|
lazyboy
2014/09/19 21:38:18
Add a comment noting the significance of point (50
pals
2014/09/22 05:05:26
Done.
|
| + |
| + // The menu_observer will execute the action corresponding to |command_id|, |
| + // wait for the title to change. |
| + base::string16 title = base::ASCIIToUTF16(expected); |
| + content::WebContents* tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + content::TitleWatcher title_watcher(tab, title); |
| + ASSERT_EQ(title, title_watcher.WaitAndGetTitle()); |
| + |
| + // Verify that it's the correct tab. |
| + EXPECT_EQ(base::ASCIIToUTF16(expected), tab->GetTitle()); |
| + } |
| }; |
| IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| @@ -102,20 +139,9 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, RealMenu) { |
| browser(), GURL("data:text/html,<a href='about:blank'>link</a>")); |
| // Open a context menu. |
| - blink::WebMouseEvent mouse_event; |
| - mouse_event.type = blink::WebInputEvent::MouseDown; |
| - mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| - mouse_event.x = 15; |
| - mouse_event.y = 15; |
| + OpenContextMenuAtPoint(15, 15); |
| content::WebContents* tab = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - gfx::Rect offset = tab->GetContainerBounds(); |
| - mouse_event.globalX = 15 + offset.x(); |
| - mouse_event.globalY = 15 + offset.y(); |
| - mouse_event.clickCount = 1; |
| - tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| - mouse_event.type = blink::WebInputEvent::MouseUp; |
| - tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| // The menu_observer will select "Open in new tab", wait for the new tab to |
| // be added. |
| @@ -127,6 +153,35 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, RealMenu) { |
| EXPECT_EQ(GURL("about:blank"), tab->GetURL()); |
| } |
| +IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
|
lazyboy
2014/09/19 21:38:18
nit: this can fit in one line.
pals
2014/09/22 05:05:26
Done.
|
| + CustomMenu) { |
| + 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( |
|
lazyboy
2014/09/19 21:38:18
nit: can fit in one line.
pals
2014/09/22 05:05:26
Done.
|
| + browser(), url); |
| + |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST, "Title 1"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 1, "Title 2"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 2, "Title 3"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 3, "Title 4"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 4, "Title 5"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 5, "Title 6"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 6, "Title 7"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 7, "Title 8"); |
| + ExecuteCustomMenuCommandAndVerifyTabTitle( |
| + IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 8, "Title 9"); |
| +} |
| + |
| // 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( |
| @@ -244,16 +299,7 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, SuggestedFileName) { |
| kSuggestedFilename + "'>link</a>")); |
| // Open a context menu. |
| - blink::WebMouseEvent mouse_event; |
| - mouse_event.type = blink::WebInputEvent::MouseDown; |
| - mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| - mouse_event.x = 15; |
| - mouse_event.y = 15; |
| - content::WebContents* tab = |
| - browser()->tab_strip_model()->GetActiveWebContents(); |
| - tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| - mouse_event.type = blink::WebInputEvent::MouseUp; |
| - tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| + OpenContextMenuAtPoint(15, 15); |
| // Wait for context menu to be visible. |
| menu_observer.WaitForMenu(); |