OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 12 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
13 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" | 13 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" |
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
22 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
25 #include "net/test/embedded_test_server/embedded_test_server.h" | |
25 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 26 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
26 #include "third_party/WebKit/public/web/WebInputEvent.h" | 27 #include "third_party/WebKit/public/web/WebInputEvent.h" |
27 | 28 |
28 using content::WebContents; | 29 using content::WebContents; |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 class ContextMenuBrowserTest : public InProcessBrowserTest { | 33 class ContextMenuBrowserTest : public InProcessBrowserTest { |
33 public: | 34 public: |
34 ContextMenuBrowserTest() { } | 35 ContextMenuBrowserTest() { } |
(...skipping 10 matching lines...) Expand all Loading... | |
45 params.writing_direction_default = 0; | 46 params.writing_direction_default = 0; |
46 params.writing_direction_left_to_right = 0; | 47 params.writing_direction_left_to_right = 0; |
47 params.writing_direction_right_to_left = 0; | 48 params.writing_direction_right_to_left = 0; |
48 #endif // OS_MACOSX | 49 #endif // OS_MACOSX |
49 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 50 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
50 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 51 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
51 params); | 52 params); |
52 menu->Init(); | 53 menu->Init(); |
53 return menu; | 54 return menu; |
54 } | 55 } |
56 | |
57 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.
| |
58 const std::string& expected) { | |
59 content::WebContents* tab = | |
60 browser()->tab_strip_model()->GetActiveWebContents(); | |
61 // 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.
| |
62 blink::WebMouseEvent mouse_event; | |
63 mouse_event.button = blink::WebMouseEvent::ButtonRight; | |
64 mouse_event.x = 50; | |
65 mouse_event.y = 50; | |
66 gfx::Rect offset = tab->GetContainerBounds(); | |
67 mouse_event.globalX = 50 + offset.x(); | |
68 mouse_event.globalY = 50 + offset.y(); | |
69 mouse_event.clickCount = 1; | |
70 // menu_observer executes the menu item command with |command_id|. | |
71 ContextMenuNotificationObserver menu_observer( | |
72 command_id); | |
73 mouse_event.type = blink::WebInputEvent::MouseDown; | |
74 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
75 mouse_event.type = blink::WebInputEvent::MouseUp; | |
76 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
77 | |
78 // The menu_observer will execute the action corresponding to |command_id|, | |
79 // wait for the title to change. | |
80 base::string16 title = base::ASCIIToUTF16(expected); | |
81 content::TitleWatcher title_watcher(tab, title); | |
82 ASSERT_EQ(title, title_watcher.WaitAndGetTitle()); | |
83 | |
84 // Verify that it's the correct tab. | |
85 EXPECT_EQ(base::ASCIIToUTF16(expected), tab->GetTitle()); | |
86 } | |
55 }; | 87 }; |
56 | 88 |
57 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 89 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
58 OpenEntryPresentForNormalURLs) { | 90 OpenEntryPresentForNormalURLs) { |
59 scoped_ptr<TestRenderViewContextMenu> menu( | 91 scoped_ptr<TestRenderViewContextMenu> menu( |
60 CreateContextMenu(GURL("http://www.google.com/"), | 92 CreateContextMenu(GURL("http://www.google.com/"), |
61 GURL("http://www.google.com/"))); | 93 GURL("http://www.google.com/"))); |
62 | 94 |
63 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 95 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
64 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 96 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 // The menu_observer will select "Open in new tab", wait for the new tab to | 152 // The menu_observer will select "Open in new tab", wait for the new tab to |
121 // be added. | 153 // be added. |
122 tab_observer.Wait(); | 154 tab_observer.Wait(); |
123 tab = tab_observer.GetTab(); | 155 tab = tab_observer.GetTab(); |
124 content::WaitForLoadStop(tab); | 156 content::WaitForLoadStop(tab); |
125 | 157 |
126 // Verify that it's the correct tab. | 158 // Verify that it's the correct tab. |
127 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); | 159 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); |
128 } | 160 } |
129 | 161 |
162 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | |
163 CustomMenu) { | |
164 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
165 // Go to a test page | |
166 GURL url = embedded_test_server()->GetURL( | |
167 "/context_menu/custom_context_menu.html"); | |
168 ui_test_utils::NavigateToURL( | |
169 browser(), url); | |
170 | |
171 executeCustomMenuCommandAndVerifyTabTitle( | |
172 IDC_CONTENT_CONTEXT_CUSTOM_FIRST, "Title 1"); | |
173 executeCustomMenuCommandAndVerifyTabTitle( | |
174 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 1, "Title 2"); | |
175 executeCustomMenuCommandAndVerifyTabTitle( | |
176 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 2, "Title 3"); | |
177 executeCustomMenuCommandAndVerifyTabTitle( | |
178 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 3, "Title 4"); | |
179 executeCustomMenuCommandAndVerifyTabTitle( | |
180 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 4, "Title 5"); | |
181 executeCustomMenuCommandAndVerifyTabTitle( | |
182 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 5, "Title 6"); | |
183 executeCustomMenuCommandAndVerifyTabTitle( | |
184 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 6, "Title 7"); | |
185 executeCustomMenuCommandAndVerifyTabTitle( | |
186 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 7, "Title 8"); | |
187 executeCustomMenuCommandAndVerifyTabTitle( | |
188 IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 8, "Title 9"); | |
189 } | |
190 | |
130 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. | 191 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. |
131 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { | 192 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { |
132 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( | 193 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
133 content::NotificationService::AllSources()); | 194 content::NotificationService::AllSources()); |
134 | 195 |
135 ASSERT_TRUE(test_server()->Start()); | 196 ASSERT_TRUE(test_server()->Start()); |
136 GURL echoheader(test_server()->GetURL("echoheader?Referer")); | 197 GURL echoheader(test_server()->GetURL("echoheader?Referer")); |
137 | 198 |
138 // Go to a |page| with a link to echoheader URL. | 199 // Go to a |page| with a link to echoheader URL. |
139 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); | 200 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 menu.Init(); | 343 menu.Init(); |
283 | 344 |
284 // The item shouldn't be enabled in the menu. | 345 // The item shouldn't be enabled in the menu. |
285 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); | 346 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); |
286 | 347 |
287 // Ensure that viewing page info doesn't crash even if you can get to it. | 348 // Ensure that viewing page info doesn't crash even if you can get to it. |
288 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); | 349 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); |
289 } | 350 } |
290 | 351 |
291 } // namespace | 352 } // namespace |
OLD | NEW |