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/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(GURL unfiltered_url, GURL url, |
| 49 blink::WebContextMenuData::MediaType media_type) { | |
|
Alexei Svitkine (slow)
2015/02/20 18:37:27
This doesn't follow style. Run "git cl format"?
Not at Google. Contact bengr
2015/02/21 00:11:17
Done.
| |
| 47 content::ContextMenuParams params; | 50 content::ContextMenuParams params; |
| 48 params.media_type = blink::WebContextMenuData::MediaTypeNone; | 51 params.media_type = media_type; |
| 49 params.unfiltered_link_url = unfiltered_url; | 52 params.unfiltered_link_url = unfiltered_url; |
| 50 params.link_url = url; | 53 params.link_url = url; |
| 54 params.src_url = url; | |
| 51 WebContents* web_contents = | 55 WebContents* web_contents = |
| 52 browser()->tab_strip_model()->GetActiveWebContents(); | 56 browser()->tab_strip_model()->GetActiveWebContents(); |
| 53 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); | 57 params.page_url = web_contents->GetController().GetActiveEntry()->GetURL(); |
| 54 #if defined(OS_MACOSX) | 58 #if defined(OS_MACOSX) |
| 55 params.writing_direction_default = 0; | 59 params.writing_direction_default = 0; |
| 56 params.writing_direction_left_to_right = 0; | 60 params.writing_direction_left_to_right = 0; |
| 57 params.writing_direction_right_to_left = 0; | 61 params.writing_direction_right_to_left = 0; |
| 58 #endif // OS_MACOSX | 62 #endif // OS_MACOSX |
| 59 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( | 63 TestRenderViewContextMenu* menu = new TestRenderViewContextMenu( |
| 60 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 64 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| 61 params); | 65 params); |
| 62 menu->Init(); | 66 menu->Init(); |
| 63 return menu; | 67 return menu; |
| 64 } | 68 } |
| 69 | |
| 70 TestRenderViewContextMenu* CreateContextMenu(GURL unfiltered_url, GURL url) { | |
|
Alexei Svitkine (slow)
2015/02/20 18:37:27
Pass params by const refs.
Same as above.
Also,
Not at Google. Contact bengr
2015/02/21 00:11:16
Done.
| |
| 71 return CreateContextMenu( | |
| 72 unfiltered_url, url, blink::WebContextMenuData::MediaTypeNone); | |
| 73 } | |
| 65 }; | 74 }; |
| 66 | 75 |
| 67 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 76 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 68 OpenEntryPresentForNormalURLs) { | 77 OpenEntryPresentForNormalURLs) { |
| 69 scoped_ptr<TestRenderViewContextMenu> menu( | 78 scoped_ptr<TestRenderViewContextMenu> menu( |
| 70 CreateContextMenu(GURL("http://www.google.com/"), | 79 CreateContextMenu(GURL("http://www.google.com/"), |
| 71 GURL("http://www.google.com/"))); | 80 GURL("http://www.google.com/"))); |
| 72 | 81 |
| 73 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 82 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 74 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 83 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); | 300 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); |
| 292 menu.Init(); | 301 menu.Init(); |
| 293 | 302 |
| 294 // The item shouldn't be enabled in the menu. | 303 // The item shouldn't be enabled in the menu. |
| 295 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); | 304 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); |
| 296 | 305 |
| 297 // Ensure that viewing page info doesn't crash even if you can get to it. | 306 // Ensure that viewing page info doesn't crash even if you can get to it. |
| 298 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); | 307 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); |
| 299 } | 308 } |
| 300 | 309 |
| 310 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, DataSaverOpenOrigImageInNewTab) { | |
| 311 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 312 command_line->AppendSwitch( | |
| 313 data_reduction_proxy::switches::kEnableDataReductionProxy); | |
| 314 | |
| 315 scoped_ptr<TestRenderViewContextMenu> menu( | |
| 316 CreateContextMenu(GURL(""), | |
| 317 GURL("http://url.com/image.png"), | |
| 318 blink::WebContextMenuData::MediaTypeImage)); | |
| 319 | |
| 320 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); | |
| 321 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB)); | |
| 322 } | |
| 323 | |
| 324 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | |
| 325 DataSaverHttpsOpenImageInNewTab) { | |
| 326 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 327 command_line->AppendSwitch( | |
| 328 data_reduction_proxy::switches::kEnableDataReductionProxy); | |
| 329 | |
| 330 scoped_ptr<TestRenderViewContextMenu> menu( | |
| 331 CreateContextMenu(GURL(""), | |
| 332 GURL("https://url.com/image.png"), | |
| 333 blink::WebContextMenuData::MediaTypeImage)); | |
| 334 | |
| 335 ASSERT_FALSE( | |
| 336 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB)); | |
| 337 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB)); | |
| 338 } | |
| 339 | |
| 340 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenImageInNewTab) { | |
| 341 scoped_ptr<TestRenderViewContextMenu> menu( | |
| 342 CreateContextMenu(GURL(""), | |
| 343 GURL("http://url.com/image.png"), | |
| 344 blink::WebContextMenuData::MediaTypeImage)); | |
| 345 ASSERT_FALSE( | |
| 346 menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB)); | |
| 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 |