Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc

Issue 296153008: Testing contextmenu attribute which enables webpage to add custom menu items to the platform contex… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated test Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ac477a1fc35f9c056a7f6b26cb2166eb0b453917 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,37 @@ class ContextMenuBrowserTest : public InProcessBrowserTest {
menu->Init();
return menu;
}
+
+ void executeCustomMenuCommandAndVerifyTabTitle(unsigned command_id,
brettw 2014/09/02 23:50:29 The formatting of this is all messed up. Also: fun
pals 2014/09/03 17:10:57 Done.
+ const std::string& expected) {
+ content::WebContents* tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ // Open context menu and execute |command_id|
brettw 2014/09/02 23:50:29 This context menu code is almost an exact copy of
pals 2014/09/03 17:10:57 Done.
+ blink::WebMouseEvent mouse_event;
+ mouse_event.button = blink::WebMouseEvent::ButtonRight;
+ mouse_event.x = 50;
+ mouse_event.y = 50;
+ gfx::Rect offset = tab->GetContainerBounds();
+ mouse_event.globalX = 50 + offset.x();
+ mouse_event.globalY = 50 + offset.y();
+ mouse_event.clickCount = 1;
+ // menu_observer executes the menu item command with |command_id|.
+ ContextMenuNotificationObserver menu_observer(
+ command_id);
+ 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 |command_id|,
+ // wait for the title to change.
+ base::string16 title = base::ASCIIToUTF16(expected);
+ 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,
@@ -127,6 +159,35 @@ 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(
« no previous file with comments | « no previous file | chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698