Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1500)

Unified Diff: chrome/browser/extensions/extension_context_menu_model_unittest.cc

Issue 1135763004: [Extensions Toolbar] Only include relevant items in component extensions' menus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_context_menu_model.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_context_menu_model_unittest.cc
diff --git a/chrome/browser/extensions/extension_context_menu_model_unittest.cc b/chrome/browser/extensions/extension_context_menu_model_unittest.cc
index 0ae2aa3f4973e52fa2c8b21057f1b06c8e81c5c6..e230364c45e0a4feb70fc604203761dd1712ec80 100644
--- a/chrome/browser/extensions/extension_context_menu_model_unittest.cc
+++ b/chrome/browser/extensions/extension_context_menu_model_unittest.cc
@@ -23,9 +23,11 @@
#include "extensions/common/feature_switch.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
+#include "extensions/common/manifest_handlers/options_page_info.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/image/image.h"
namespace extensions {
@@ -93,7 +95,6 @@ class ExtensionContextMenuModelTest : public ExtensionServiceTestBase {
ExtensionContextMenuModelTest::ExtensionContextMenuModelTest() : cur_id_(0) {
}
-
void ExtensionContextMenuModelTest::AddContextItemAndRefreshModel(
MenuManager* manager,
const Extension* extension,
@@ -129,50 +130,90 @@ int ExtensionContextMenuModelTest::CountExtensionItems(
TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) {
InitializeEmptyExtensionService();
- // First, test that a component extension cannot be uninstalled by the
- // standard management policy.
+ // Test that management policy can determine whether or not policy-installed
+ // extensions can be installed/uninstalled.
scoped_refptr<const Extension> extension =
- BuildExtension("component",
- manifest_keys::kBrowserAction,
- Manifest::COMPONENT);
+ BuildExtension("extension",
+ manifest_keys::kPageAction,
+ Manifest::EXTERNAL_POLICY);
ASSERT_TRUE(extension.get());
service()->AddExtension(extension.get());
scoped_ptr<Browser> browser = CreateBrowser(profile());
-
scoped_refptr<ExtensionContextMenuModel> menu(
new ExtensionContextMenuModel(extension.get(), browser.get()));
- // Uninstallation should be disabled.
- EXPECT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
-
- // Also test that management policy can determine whether or not
- // policy-installed extensions can be installed/uninstalled.
- extension = BuildExtension("extension",
- manifest_keys::kPageAction,
- Manifest::INTERNAL);
- ASSERT_TRUE(extension.get());
- service()->AddExtension(extension.get());
-
- menu = new ExtensionContextMenuModel(extension.get(), browser.get());
-
ExtensionSystem* system = ExtensionSystem::Get(profile());
system->management_policy()->UnregisterAllProviders();
- // Actions should be enabled.
+ // Uninstallation should be, by default, enabled.
ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
TestManagementPolicyProvider policy_provider(
TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
system->management_policy()->RegisterProvider(&policy_provider);
- // Now the actions are disabled.
+ // If there's a policy provider that requires the extension stay enabled, then
+ // uninstallation should be disabled.
ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
// Don't leave |policy_provider| dangling.
system->management_policy()->UnregisterProvider(&policy_provider);
}
+// Tests the context menu for a component extension.
+TEST_F(ExtensionContextMenuModelTest, ComponentExtensionContextMenu) {
+ InitializeEmptyExtensionService();
+
+ std::string name("component");
+ scoped_ptr<base::DictionaryValue> manifest =
+ DictionaryBuilder().Set("name", name)
+ .Set("version", "1")
+ .Set("manifest_version", 2)
+ .Set("browser_action", DictionaryBuilder().Pass())
+ .Build();
+
+ scoped_refptr<const Extension> extension =
+ ExtensionBuilder().SetManifest(make_scoped_ptr(manifest->DeepCopy()))
+ .SetID(crx_file::id_util::GenerateId("component"))
+ .SetLocation(Manifest::COMPONENT)
+ .Build();
+ service()->AddExtension(extension.get());
+
+ scoped_ptr<Browser> browser = CreateBrowser(profile());
+
+ scoped_refptr<ExtensionContextMenuModel> menu(
+ new ExtensionContextMenuModel(extension.get(), browser.get()));
+
+ // A component extension's context menu should not include options for
+ // managing extensions or removing it, and should only include an option for
+ // the options page if the extension has one (which this one doesn't).
+ EXPECT_EQ(-1,
+ menu->GetIndexOfCommandId(ExtensionContextMenuModel::CONFIGURE));
+ EXPECT_EQ(-1,
+ menu->GetIndexOfCommandId(ExtensionContextMenuModel::UNINSTALL));
+ EXPECT_EQ(-1, menu->GetIndexOfCommandId(ExtensionContextMenuModel::MANAGE));
+ // The "name" option should be present, but not enabled for component
+ // extensions.
+ EXPECT_NE(-1, menu->GetIndexOfCommandId(ExtensionContextMenuModel::NAME));
+ EXPECT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::NAME));
+
+ // Check that a component extension with an options page does have the options
+ // menu item, and it is enabled.
+ manifest->SetString("options_page", "options_page.html");
+ extension =
+ ExtensionBuilder().SetManifest(manifest.Pass())
+ .SetID(crx_file::id_util::GenerateId("component_opts"))
+ .SetLocation(Manifest::COMPONENT)
+ .Build();
+ menu = new ExtensionContextMenuModel(extension.get(), browser.get());
+ service()->AddExtension(extension.get());
+ EXPECT_TRUE(extensions::OptionsPageInfo::HasOptionsPage(extension.get()));
+ EXPECT_NE(-1,
+ menu->GetIndexOfCommandId(ExtensionContextMenuModel::CONFIGURE));
+ EXPECT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::CONFIGURE));
+}
+
TEST_F(ExtensionContextMenuModelTest, ExtensionItemTest) {
InitializeEmptyExtensionService();
scoped_refptr<const Extension> extension =
« no previous file with comments | « chrome/browser/extensions/extension_context_menu_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698