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 "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 ProtocolHandlerRegistry* registry) { | 89 ProtocolHandlerRegistry* registry) { |
| 90 content::ContextMenuParams params = CreateParams(MenuItem::LINK); | 90 content::ContextMenuParams params = CreateParams(MenuItem::LINK); |
| 91 params.unfiltered_link_url = params.link_url; | 91 params.unfiltered_link_url = params.link_url; |
| 92 std::unique_ptr<TestRenderViewContextMenu> menu( | 92 std::unique_ptr<TestRenderViewContextMenu> menu( |
| 93 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params)); | 93 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params)); |
| 94 menu->set_protocol_handler_registry(registry); | 94 menu->set_protocol_handler_registry(registry); |
| 95 menu->Init(); | 95 menu->Init(); |
| 96 return menu; | 96 return menu; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Returns a test context menu for a chrome:// url not permitted to open in | |
| 100 // incognito mode. | |
| 101 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenuOnChromeLink( | |
| 102 content::WebContents* web_contents, | |
| 103 ProtocolHandlerRegistry* registry) { | |
| 104 content::ContextMenuParams params = CreateParams(MenuItem::LINK); | |
| 105 params.unfiltered_link_url = params.link_url = GURL("chrome://settings"); | |
| 106 std::unique_ptr<TestRenderViewContextMenu> menu( | |
| 107 new TestRenderViewContextMenu(web_contents->GetMainFrame(), params)); | |
| 108 menu->set_protocol_handler_registry(registry); | |
| 109 menu->Init(); | |
| 110 return menu; | |
| 111 } | |
| 112 | |
| 99 } // namespace | 113 } // namespace |
| 100 | 114 |
| 101 class RenderViewContextMenuTest : public testing::Test { | 115 class RenderViewContextMenuTest : public testing::Test { |
| 102 protected: | 116 protected: |
| 103 RenderViewContextMenuTest() = default; | 117 RenderViewContextMenuTest() = default; |
| 104 | 118 |
| 105 // Proxy defined here to minimize friend classes in RenderViewContextMenu | 119 // Proxy defined here to minimize friend classes in RenderViewContextMenu |
| 106 static bool ExtensionContextAndPatternMatch( | 120 static bool ExtensionContextAndPatternMatch( |
| 107 const content::ContextMenuParams& params, | 121 const content::ContextMenuParams& params, |
| 108 MenuItem::ContextList contexts, | 122 MenuItem::ContextList contexts, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 387 |
| 374 void TearDown() override { | 388 void TearDown() override { |
| 375 registry_.reset(); | 389 registry_.reset(); |
| 376 ChromeRenderViewHostTestHarness::TearDown(); | 390 ChromeRenderViewHostTestHarness::TearDown(); |
| 377 } | 391 } |
| 378 | 392 |
| 379 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenu() { | 393 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenu() { |
| 380 return ::CreateContextMenu(web_contents(), registry_.get()); | 394 return ::CreateContextMenu(web_contents(), registry_.get()); |
| 381 } | 395 } |
| 382 | 396 |
| 397 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenuOnChromeLink() { | |
| 398 return ::CreateContextMenuOnChromeLink(web_contents(), registry_.get()); | |
|
lazyboy
2017/05/02 23:44:55
Is there a reason not to put the implementation ri
elawrence
2017/05/03 01:44:47
Done.
I was mimic'ing the pattern of CreateContex
| |
| 399 } | |
| 400 | |
| 383 void AppendImageItems(TestRenderViewContextMenu* menu) { | 401 void AppendImageItems(TestRenderViewContextMenu* menu) { |
| 384 menu->AppendImageItems(); | 402 menu->AppendImageItems(); |
| 385 } | 403 } |
| 386 | 404 |
| 387 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { | 405 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { |
| 388 drp_test_context_ = | 406 drp_test_context_ = |
| 389 data_reduction_proxy::DataReductionProxyTestContext::Builder() | 407 data_reduction_proxy::DataReductionProxyTestContext::Builder() |
| 390 .WithParamsFlags( | 408 .WithParamsFlags( |
| 391 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) | 409 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) |
| 392 .WithMockConfig() | 410 .WithMockConfig() |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 | 466 |
| 449 // Disable Incognito mode. | 467 // Disable Incognito mode. |
| 450 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 468 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
| 451 IncognitoModePrefs::DISABLED); | 469 IncognitoModePrefs::DISABLED); |
| 452 menu = CreateContextMenu(); | 470 menu = CreateContextMenu(); |
| 453 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | 471 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 454 EXPECT_FALSE( | 472 EXPECT_FALSE( |
| 455 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | 473 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 456 } | 474 } |
| 457 | 475 |
| 476 // Verifies Incognito Mode is not enabled for links disallowed in Incognito. | |
| 477 TEST_F(RenderViewContextMenuPrefsTest, | |
| 478 DisableOpenInIncognitoWindowForChromeUrls) { | |
| 479 std::unique_ptr<TestRenderViewContextMenu> menu( | |
| 480 CreateContextMenuOnChromeLink()); | |
| 481 | |
| 482 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | |
| 483 EXPECT_FALSE( | |
| 484 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | |
| 485 } | |
| 486 | |
| 458 // Make sure the checking custom command id that is not enabled will not | 487 // Make sure the checking custom command id that is not enabled will not |
| 459 // cause DCHECK failure. | 488 // cause DCHECK failure. |
| 460 TEST_F(RenderViewContextMenuPrefsTest, | 489 TEST_F(RenderViewContextMenuPrefsTest, |
| 461 IsCustomCommandIdEnabled) { | 490 IsCustomCommandIdEnabled) { |
| 462 std::unique_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 491 std::unique_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
| 463 | 492 |
| 464 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); | 493 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); |
| 465 } | 494 } |
| 466 | 495 |
| 467 // Verify that request headers specify that data reduction proxy should return | 496 // Verify that request headers specify that data reduction proxy should return |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 params.unfiltered_link_url = params.link_url; | 549 params.unfiltered_link_url = params.link_url; |
| 521 content::WebContents* wc = web_contents(); | 550 content::WebContents* wc = web_contents(); |
| 522 std::unique_ptr<TestRenderViewContextMenu> menu( | 551 std::unique_ptr<TestRenderViewContextMenu> menu( |
| 523 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); | 552 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); |
| 524 AppendImageItems(menu.get()); | 553 AppendImageItems(menu.get()); |
| 525 | 554 |
| 526 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE)); | 555 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE)); |
| 527 | 556 |
| 528 DestroyDataReductionProxySettings(); | 557 DestroyDataReductionProxySettings(); |
| 529 } | 558 } |
| OLD | NEW |