Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
| 7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 8 #include "chrome/browser/extensions/extension_context_menu_model.h" | |
| 8 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/extensions/test_management_policy.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 14 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 12 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/common/context_menu_params.h" | 18 #include "content/public/common/context_menu_params.h" |
| 16 #include "net/base/mock_host_resolver.h" | 19 #include "net/base/mock_host_resolver.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 18 #include "ui/base/models/menu_model.h" | 21 #include "ui/base/models/menu_model.h" |
| 19 | 22 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 501 page_url, GURL(), frame_url, std::string("Page item"))); | 504 page_url, GURL(), frame_url, std::string("Page item"))); |
| 502 ASSERT_TRUE(MenuHasItemWithLabel( | 505 ASSERT_TRUE(MenuHasItemWithLabel( |
| 503 page_url, GURL(), frame_url, std::string("Frame item"))); | 506 page_url, GURL(), frame_url, std::string("Frame item"))); |
| 504 } | 507 } |
| 505 | 508 |
| 506 // Tests enabling and disabling a context menu item. | 509 // Tests enabling and disabling a context menu item. |
| 507 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) { | 510 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Enabled) { |
| 508 TestEnabledContextMenu(true); | 511 TestEnabledContextMenu(true); |
| 509 TestEnabledContextMenu(false); | 512 TestEnabledContextMenu(false); |
| 510 } | 513 } |
| 514 | |
| 515 // Tests that applicable menu items are disabled when a ManagementPolicy | |
| 516 // prohibits them. | |
| 517 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, PolicyDisablesItems) { | |
| 518 ASSERT_TRUE(LoadContextMenuExtension("simple")); | |
| 519 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 520 ASSERT_TRUE(service != NULL); | |
| 521 ASSERT_FALSE(service->extensions()->is_empty()); | |
| 522 // We need an extension to pass to the menu constructor, but we don't care | |
|
Aaron Boodman
2012/05/22 15:56:11
Nit: add a blank line here.
| |
| 523 // which one. | |
| 524 ExtensionSet::const_iterator i = service->extensions()->begin(); | |
| 525 const extensions::Extension* extension = *i; | |
| 526 ASSERT_TRUE(extension != NULL); | |
| 527 | |
| 528 scoped_refptr<ExtensionContextMenuModel> menu( | |
| 529 new ExtensionContextMenuModel(extension, browser())); | |
| 530 | |
| 531 ExtensionSystem::Get( | |
| 532 browser()->profile())->management_policy()->UnregisterAllProviders(); | |
| 533 | |
| 534 // Actions should be enabled. | |
| 535 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::DISABLE)); | |
| 536 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | |
| 537 | |
| 538 extensions::TestManagementPolicyProvider policy_provider( | |
| 539 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | |
| 540 ExtensionSystem::Get( | |
| 541 browser()->profile())->management_policy()->RegisterProvider( | |
| 542 &policy_provider); | |
| 543 | |
| 544 // Now the actions are disabled. | |
| 545 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::DISABLE)); | |
| 546 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | |
|
Aaron Boodman
2012/05/22 15:56:11
Yay, this came out clean.
| |
| 547 } | |
| OLD | NEW |