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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 373 |
374 void TearDown() override { | 374 void TearDown() override { |
375 registry_.reset(); | 375 registry_.reset(); |
376 ChromeRenderViewHostTestHarness::TearDown(); | 376 ChromeRenderViewHostTestHarness::TearDown(); |
377 } | 377 } |
378 | 378 |
379 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenu() { | 379 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenu() { |
380 return ::CreateContextMenu(web_contents(), registry_.get()); | 380 return ::CreateContextMenu(web_contents(), registry_.get()); |
381 } | 381 } |
382 | 382 |
| 383 // Returns a test context menu for a chrome:// url not permitted to open in |
| 384 // incognito mode. |
| 385 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenuOnChromeLink() { |
| 386 content::ContextMenuParams params = CreateParams(MenuItem::LINK); |
| 387 params.unfiltered_link_url = params.link_url = GURL("chrome://settings"); |
| 388 std::unique_ptr<TestRenderViewContextMenu> menu( |
| 389 new TestRenderViewContextMenu(web_contents()->GetMainFrame(), params)); |
| 390 menu->set_protocol_handler_registry(registry_.get()); |
| 391 menu->Init(); |
| 392 return menu; |
| 393 } |
| 394 |
383 void AppendImageItems(TestRenderViewContextMenu* menu) { | 395 void AppendImageItems(TestRenderViewContextMenu* menu) { |
384 menu->AppendImageItems(); | 396 menu->AppendImageItems(); |
385 } | 397 } |
386 | 398 |
387 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { | 399 void SetupDataReductionProxy(bool enable_data_reduction_proxy) { |
388 drp_test_context_ = | 400 drp_test_context_ = |
389 data_reduction_proxy::DataReductionProxyTestContext::Builder() | 401 data_reduction_proxy::DataReductionProxyTestContext::Builder() |
390 .WithParamsFlags( | 402 .WithParamsFlags( |
391 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) | 403 data_reduction_proxy::DataReductionProxyParams::kPromoAllowed) |
392 .WithMockConfig() | 404 .WithMockConfig() |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 460 |
449 // Disable Incognito mode. | 461 // Disable Incognito mode. |
450 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 462 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
451 IncognitoModePrefs::DISABLED); | 463 IncognitoModePrefs::DISABLED); |
452 menu = CreateContextMenu(); | 464 menu = CreateContextMenu(); |
453 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | 465 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
454 EXPECT_FALSE( | 466 EXPECT_FALSE( |
455 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); | 467 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
456 } | 468 } |
457 | 469 |
| 470 // Verifies Incognito Mode is not enabled for links disallowed in Incognito. |
| 471 TEST_F(RenderViewContextMenuPrefsTest, |
| 472 DisableOpenInIncognitoWindowForDisallowedUrls) { |
| 473 std::unique_ptr<TestRenderViewContextMenu> menu( |
| 474 CreateContextMenuOnChromeLink()); |
| 475 |
| 476 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 477 EXPECT_FALSE( |
| 478 menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD)); |
| 479 } |
| 480 |
458 // Make sure the checking custom command id that is not enabled will not | 481 // Make sure the checking custom command id that is not enabled will not |
459 // cause DCHECK failure. | 482 // cause DCHECK failure. |
460 TEST_F(RenderViewContextMenuPrefsTest, | 483 TEST_F(RenderViewContextMenuPrefsTest, |
461 IsCustomCommandIdEnabled) { | 484 IsCustomCommandIdEnabled) { |
462 std::unique_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 485 std::unique_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
463 | 486 |
464 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); | 487 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_CUSTOM_FIRST)); |
465 } | 488 } |
466 | 489 |
467 // Verify that request headers specify that data reduction proxy should return | 490 // 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; | 543 params.unfiltered_link_url = params.link_url; |
521 content::WebContents* wc = web_contents(); | 544 content::WebContents* wc = web_contents(); |
522 std::unique_ptr<TestRenderViewContextMenu> menu( | 545 std::unique_ptr<TestRenderViewContextMenu> menu( |
523 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); | 546 new TestRenderViewContextMenu(wc->GetMainFrame(), params)); |
524 AppendImageItems(menu.get()); | 547 AppendImageItems(menu.get()); |
525 | 548 |
526 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE)); | 549 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_LOAD_ORIGINAL_IMAGE)); |
527 | 550 |
528 DestroyDataReductionProxySettings(); | 551 DestroyDataReductionProxySettings(); |
529 } | 552 } |
OLD | NEW |