| Index: chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_context_menu_browsertest.cc (revision 136836)
|
| +++ chrome/browser/extensions/extension_context_menu_browsertest.cc (working copy)
|
| @@ -5,16 +5,20 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/app/chrome_command_ids.h"
|
| #include "chrome/browser/extensions/extension_browsertest.h"
|
| +#include "chrome/browser/extensions/extension_context_menu_model.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/extensions/extension_test_message_listener.h"
|
| +#include "chrome/browser/extensions/test_extension_management_policy.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/tab_contents/render_view_context_menu.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| #include "content/public/common/context_menu_params.h"
|
| +#include "grit/generated_resources.h"
|
| #include "net/base/mock_host_resolver.h"
|
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/models/menu_model.h"
|
|
|
| using WebKit::WebContextMenuData;
|
| @@ -33,7 +37,8 @@
|
|
|
| virtual ~TestRenderViewContextMenu() {}
|
|
|
| - bool HasExtensionItemWithLabel(const std::string& label) {
|
| + // *** revert ***
|
| + int ExtensionItemIdWithLabel(const std::string& label) {
|
| string16 label16 = UTF8ToUTF16(label);
|
| std::map<int, ExtensionMenuItem::Id>::iterator i;
|
| for (i = extension_item_map_.begin(); i != extension_item_map_.end(); ++i) {
|
| @@ -41,11 +46,15 @@
|
| string16 tmp_label;
|
| EXPECT_TRUE(GetItemLabel(id, &tmp_label));
|
| if (tmp_label == label16)
|
| - return true;
|
| + return id.uid;
|
| }
|
| - return false;
|
| + return -1;
|
| }
|
|
|
| + bool HasExtensionItemWithLabel(const std::string& label) {
|
| + return (ExtensionItemIdWithLabel(label) != -1);
|
| + }
|
| +
|
| // Looks in the menu for an extension item with |id|, and if it is found and
|
| // has a label, that is put in |result| and we return true. Otherwise returns
|
| // false.
|
| @@ -508,3 +517,35 @@
|
| TestEnabledContextMenu(true);
|
| TestEnabledContextMenu(false);
|
| }
|
| +
|
| +// Tests that applicable menu items are disabled when an
|
| +// ExtensionManagementPolicy prohibits them.
|
| +IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, PolicyDisablesItems) {
|
| + ASSERT_TRUE(LoadContextMenuExtension("simple"));
|
| + ExtensionService* service = browser()->profile()->GetExtensionService();
|
| + ASSERT_TRUE(service != NULL);
|
| + ASSERT_FALSE(service->extensions()->is_empty());
|
| + // We need an extension to pass to the menu constructor, but we don't care
|
| + // which one.
|
| + ExtensionSet::const_iterator i = service->extensions()->begin();
|
| + const Extension* extension = *i;
|
| + ASSERT_TRUE(extension != NULL);
|
| +
|
| + scoped_refptr<ExtensionContextMenuModel> menu(
|
| + new ExtensionContextMenuModel(extension, browser()));
|
| +
|
| + ExtensionManagementPolicy* policy = service->extension_management_policy();
|
| + policy->UnregisterAllDelegates();
|
| +
|
| + // Actions should be enabled.
|
| + ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::DISABLE));
|
| + ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
|
| +
|
| + TestExtensionManagementPolicyDelegate policy_delegate(
|
| + TestExtensionManagementPolicyDelegate::PROHIBIT_MODIFY_STATUS);
|
| + policy->RegisterDelegate(&policy_delegate);
|
| +
|
| + // Now the actions are disabled.
|
| + ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::DISABLE));
|
| + ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
|
| +}
|
|
|