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/command_line.h" |
7 #include "base/macros.h" | 8 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 15 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
15 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 16 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 17 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
23 #include "components/search_engines/template_url_data.h" | 25 #include "components/search_engines/template_url_data.h" |
24 #include "components/search_engines/template_url_service.h" | 26 #include "components/search_engines/template_url_service.h" |
25 #include "content/public/browser/browser_message_filter.h" | 27 #include "content/public/browser/browser_message_filter.h" |
26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
28 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
29 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
32 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
33 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
34 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
35 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 37 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
36 #include "third_party/WebKit/public/web/WebInputEvent.h" | 38 #include "third_party/WebKit/public/web/WebInputEvent.h" |
37 | 39 |
38 using content::WebContents; | 40 using content::WebContents; |
39 | 41 |
40 namespace { | 42 namespace { |
41 | 43 |
42 class ContextMenuBrowserTest : public InProcessBrowserTest { | 44 class ContextMenuBrowserTest : public InProcessBrowserTest { |
43 public: | 45 public: |
44 ContextMenuBrowserTest() { } | 46 ContextMenuBrowserTest() {} |
45 | 47 |
46 TestRenderViewContextMenu* CreateContextMenu(GURL unfiltered_url, GURL url) { | 48 TestRenderViewContextMenu* CreateContextMenu( |
| 49 const GURL& unfiltered_url, |
| 50 const GURL& url, |
| 51 blink::WebContextMenuData::MediaType media_type) { |
47 content::ContextMenuParams params; | 52 content::ContextMenuParams params; |
48 params.media_type = blink::WebContextMenuData::MediaTypeNone; | 53 params.media_type = media_type; |
49 params.unfiltered_link_url = unfiltered_url; | 54 params.unfiltered_link_url = unfiltered_url; |
50 params.link_url = url; | 55 params.link_url = url; |
| 56 params.src_url = url; |
51 WebContents* web_contents = | 57 WebContents* web_contents = |
52 browser()->tab_strip_model()->GetActiveWebContents(); | 58 browser()->tab_strip_model()->GetActiveWebContents(); |
53 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); | 59 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); |
54 #if defined(OS_MACOSX) | 60 #if defined(OS_MACOSX) |
55 params.writing_direction_default = 0; | 61 params.writing_direction_default = 0; |
56 params.writing_direction_left_to_right = 0; | 62 params.writing_direction_left_to_right = 0; |
57 params.writing_direction_right_to_left = 0; | 63 params.writing_direction_right_to_left = 0; |
58 #endif // OS_MACOSX | 64 #endif // OS_MACOSX |
59 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 65 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
60 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 66 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
61 params); | 67 params); |
62 menu->Init(); | 68 menu->Init(); |
63 return menu; | 69 return menu; |
64 } | 70 } |
| 71 |
| 72 TestRenderViewContextMenu* CreateContextMenuMediaTypeNone( |
| 73 const GURL& unfiltered_url, |
| 74 const GURL& url) { |
| 75 return CreateContextMenu(unfiltered_url, url, |
| 76 blink::WebContextMenuData::MediaTypeNone); |
| 77 } |
65 }; | 78 }; |
66 | 79 |
67 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 80 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
68 OpenEntryPresentForNormalURLs) { | 81 OpenEntryPresentForNormalURLs) { |
69 scoped_ptr<TestRenderViewContextMenu> menu( | 82 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenuMediaTypeNone( |
70 CreateContextMenu(GURL("http://www.google.com/"), | 83 GURL("http://www.google.com/"), GURL("http://www.google.com/"))); |
71 GURL("http://www.google.com/"))); | |
72 | 84 |
73 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 85 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
74 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 86 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
75 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 87 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
76 } | 88 } |
77 | 89 |
78 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 90 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
79 OpenEntryAbsentForFilteredURLs) { | 91 OpenEntryAbsentForFilteredURLs) { |
80 scoped_ptr<TestRenderViewContextMenu> menu( | 92 scoped_ptr<TestRenderViewContextMenu> menu( |
81 CreateContextMenu(GURL("chrome://history"), | 93 CreateContextMenuMediaTypeNone(GURL("chrome://history"), GURL())); |
82 GURL())); | |
83 | 94 |
84 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 95 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
85 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 96 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
86 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 97 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
87 } | 98 } |
88 | 99 |
89 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 100 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
90 ContextMenuForCanvas) { | 101 ContextMenuForCanvas) { |
91 content::ContextMenuParams params; | 102 content::ContextMenuParams params; |
92 params.media_type = blink::WebContextMenuData::MediaTypeCanvas; | 103 params.media_type = blink::WebContextMenuData::MediaTypeCanvas; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); | 302 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); |
292 menu.Init(); | 303 menu.Init(); |
293 | 304 |
294 // The item shouldn't be enabled in the menu. | 305 // The item shouldn't be enabled in the menu. |
295 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); | 306 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); |
296 | 307 |
297 // Ensure that viewing page info doesn't crash even if you can get to it. | 308 // Ensure that viewing page info doesn't crash even if you can get to it. |
298 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); | 309 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); |
299 } | 310 } |
300 | 311 |
| 312 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, DataSaverOpenOrigImageInNewTab) { |
| 313 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 314 command_line->AppendSwitch( |
| 315 data_reduction_proxy::switches::kEnableDataReductionProxy); |
| 316 |
| 317 scoped_ptr<TestRenderViewContextMenu> menu( |
| 318 CreateContextMenu(GURL(), GURL("http://url.com/image.png"), |
| 319 blink::WebContextMenuData::MediaTypeImage)); |
| 320 |
| 321 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); |
| 322 ASSERT_TRUE(menu->IsItemPresent( |
| 323 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); |
| 324 } |
| 325 |
| 326 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 327 DataSaverHttpsOpenImageInNewTab) { |
| 328 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 329 command_line->AppendSwitch( |
| 330 data_reduction_proxy::switches::kEnableDataReductionProxy); |
| 331 |
| 332 scoped_ptr<TestRenderViewContextMenu> menu( |
| 333 CreateContextMenu(GURL(), GURL("https://url.com/image.png"), |
| 334 blink::WebContextMenuData::MediaTypeImage)); |
| 335 |
| 336 ASSERT_FALSE( |
| 337 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); |
| 338 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); |
| 339 } |
| 340 |
| 341 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) { |
| 342 scoped_ptr<TestRenderViewContextMenu> menu( |
| 343 CreateContextMenu(GURL(), GURL("http://url.com/image.png"), |
| 344 blink::WebContextMenuData::MediaTypeImage)); |
| 345 ASSERT_FALSE( |
| 346 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB)); |
| 347 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); |
| 348 } |
| 349 |
301 class ThumbnailResponseWatcher : public content::NotificationObserver { | 350 class ThumbnailResponseWatcher : public content::NotificationObserver { |
302 public: | 351 public: |
303 enum QuitReason { | 352 enum QuitReason { |
304 STILL_RUNNING = 0, | 353 STILL_RUNNING = 0, |
305 THUMBNAIL_RECEIVED, | 354 THUMBNAIL_RECEIVED, |
306 RENDER_PROCESS_GONE, | 355 RENDER_PROCESS_GONE, |
307 }; | 356 }; |
308 | 357 |
309 class MessageFilter : public content::BrowserMessageFilter { | 358 class MessageFilter : public content::BrowserMessageFilter { |
310 public: | 359 public: |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 browser()->tab_strip_model()->GetActiveWebContents(); | 520 browser()->tab_strip_model()->GetActiveWebContents(); |
472 ThumbnailResponseWatcher watcher(tab->GetRenderProcessHost()); | 521 ThumbnailResponseWatcher watcher(tab->GetRenderProcessHost()); |
473 AttemptImageSearch(); | 522 AttemptImageSearch(); |
474 | 523 |
475 // The browser should receive a response from the renderer, because the | 524 // The browser should receive a response from the renderer, because the |
476 // renderer should not crash. | 525 // renderer should not crash. |
477 EXPECT_EQ(ThumbnailResponseWatcher::THUMBNAIL_RECEIVED, watcher.Wait()); | 526 EXPECT_EQ(ThumbnailResponseWatcher::THUMBNAIL_RECEIVED, watcher.Wait()); |
478 } | 527 } |
479 | 528 |
480 } // namespace | 529 } // namespace |
OLD | NEW |