Chromium Code Reviews| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 // The menu_observer will select "Open in new tab", wait for the new tab to | 127 // The menu_observer will select "Open in new tab", wait for the new tab to |
| 127 // be added. | 128 // be added. |
| 128 tab_observer.Wait(); | 129 tab_observer.Wait(); |
| 129 tab = tab_observer.GetTab(); | 130 tab = tab_observer.GetTab(); |
| 130 content::WaitForLoadStop(tab); | 131 content::WaitForLoadStop(tab); |
| 131 | 132 |
| 132 // Verify that it's the correct tab. | 133 // Verify that it's the correct tab. |
| 133 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); | 134 EXPECT_EQ(GURL("about:blank"), tab->GetURL()); |
| 134 } | 135 } |
| 135 | 136 |
| 137 // GTK requires a X11-level mouse event to open a context menu correctly. | |
| 138 #if defined(TOOLKIT_GTK) | |
| 139 #define MAYBE_RealCustomMenu DISABLED_RealCustomMenu | |
| 140 #else | |
| 141 #define MAYBE_RealCustomMenu RealCustomMenu | |
| 142 #endif | |
| 143 // Opens a link in a new tab via a "real" context menu. | |
| 144 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | |
| 145 MAYBE_RealCustomMenu) { | |
| 146 // menu_observer executes the first menu item command. | |
| 147 ContextMenuNotificationObserver menu_observer(47000); | |
| 148 | |
| 149 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 150 // Go to a test page | |
| 151 GURL url = embedded_test_server()->GetURL( | |
| 152 "/context_menu/custom_context_menu.html"); | |
| 153 ui_test_utils::NavigateToURL( | |
| 154 browser(), url); | |
| 155 | |
| 156 // Open a context menu. | |
| 157 blink::WebMouseEvent mouse_event; | |
| 158 mouse_event.button = blink::WebMouseEvent::ButtonRight; | |
| 159 mouse_event.x = 50; | |
| 160 mouse_event.y = 50; | |
| 161 content::WebContents* tab = | |
| 162 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 163 gfx::Rect offset = tab->GetContainerBounds(); | |
| 164 mouse_event.globalX = 50 + offset.x(); | |
| 165 mouse_event.globalY = 50 + offset.y(); | |
| 166 mouse_event.clickCount = 1; | |
| 167 mouse_event.type = blink::WebInputEvent::MouseDown; | |
| 168 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
| 169 mouse_event.type = blink::WebInputEvent::MouseUp; | |
| 170 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
| 171 | |
| 172 // The menu_observer will execute the action corresponding to item 1, | |
| 173 // wait for the title to change. | |
| 174 base::string16 title_1 = base::ASCIIToUTF16("Title 1"); | |
| 175 content::TitleWatcher title_1_watcher(tab, title_1); | |
| 176 ASSERT_EQ(title_1, title_1_watcher.WaitAndGetTitle()); | |
| 177 | |
| 178 // Verify that it's the correct tab. | |
| 179 EXPECT_EQ(base::ASCIIToUTF16("Title 1"), tab->GetTitle()); | |
| 180 | |
| 181 menu_observer.setCommandId(47002); | |
|
lazyboy
2014/05/24 15:26:31
Probably use IDC_CONTENT_CONTEXT_CUSTOM_FIRST + 2?
| |
| 182 mouse_event.type = blink::WebInputEvent::MouseDown; | |
| 183 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
| 184 mouse_event.type = blink::WebInputEvent::MouseUp; | |
| 185 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
| 186 | |
| 187 // The menu_observer will execute the action corresponding to item 3, | |
| 188 // wait for the title to change. | |
| 189 content::TitleWatcher title_3_watcher(tab, base::ASCIIToUTF16("Title 3")); | |
| 190 ASSERT_EQ(base::ASCIIToUTF16("Title 3"), title_3_watcher.WaitAndGetTitle()); | |
| 191 | |
| 192 // Verify that it's the correct tab. | |
| 193 EXPECT_EQ(base::ASCIIToUTF16("Title 3"), tab->GetTitle()); | |
| 194 } | |
| 195 | |
| 136 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. | 196 // Verify that "Open Link in New Tab" doesn't send URL fragment as referrer. |
| 137 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { | 197 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenInNewTabReferrer) { |
| 138 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( | 198 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
| 139 content::NotificationService::AllSources()); | 199 content::NotificationService::AllSources()); |
| 140 | 200 |
| 141 ASSERT_TRUE(test_server()->Start()); | 201 ASSERT_TRUE(test_server()->Start()); |
| 142 GURL echoheader(test_server()->GetURL("echoheader?Referer")); | 202 GURL echoheader(test_server()->GetURL("echoheader?Referer")); |
| 143 | 203 |
| 144 // Go to a |page| with a link to echoheader URL. | 204 // Go to a |page| with a link to echoheader URL. |
| 145 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); | 205 GURL page("data:text/html,<a href='" + echoheader.spec() + "'>link</a>"); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 // Verify that the referrer on the page matches |kEmptyReferrer|. | 290 // Verify that the referrer on the page matches |kEmptyReferrer|. |
| 231 std::string page_referrer; | 291 std::string page_referrer; |
| 232 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 292 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 233 tab, | 293 tab, |
| 234 "window.domAutomationController.send(window.document.referrer);", | 294 "window.domAutomationController.send(window.document.referrer);", |
| 235 &page_referrer)); | 295 &page_referrer)); |
| 236 ASSERT_EQ(kEmptyReferrer, page_referrer); | 296 ASSERT_EQ(kEmptyReferrer, page_referrer); |
| 237 } | 297 } |
| 238 | 298 |
| 239 } // namespace | 299 } // namespace |
| OLD | NEW |