| 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..99ae981e2917604cdacf9585ea489cffb8bd2343 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,43 @@ 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,
|
| + const std::string& expected) {
|
| + // menu_observer executes the menu item command with |command_id|.
|
| + ContextMenuNotificationObserver menu_observer(command_id);
|
| + // Right click on the center (50, 50) of the div with dimension (100, 100).
|
| + OpenContextMenuAtPoint(50, 50);
|
| +
|
| + // 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 +140,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 +154,33 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, RealMenu) {
|
| EXPECT_EQ(GURL("about:blank"), tab->GetURL());
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, 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(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 +298,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();
|
|
|