| 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 "chrome/browser/extensions/extension_context_menu_model.h" | 5 #include "chrome/browser/extensions/extension_context_menu_model.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 10 #include "chrome/browser/extensions/menu_manager.h" | 10 #include "chrome/browser/extensions/menu_manager.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 service()->AddExtension(extension.get()); | 140 service()->AddExtension(extension.get()); |
| 141 | 141 |
| 142 scoped_ptr<Browser> browser = CreateBrowser(profile()); | 142 scoped_ptr<Browser> browser = CreateBrowser(profile()); |
| 143 scoped_refptr<ExtensionContextMenuModel> menu( | 143 scoped_refptr<ExtensionContextMenuModel> menu( |
| 144 new ExtensionContextMenuModel(extension.get(), browser.get())); | 144 new ExtensionContextMenuModel(extension.get(), browser.get())); |
| 145 | 145 |
| 146 ExtensionSystem* system = ExtensionSystem::Get(profile()); | 146 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
| 147 system->management_policy()->UnregisterAllProviders(); | 147 system->management_policy()->UnregisterAllProviders(); |
| 148 | 148 |
| 149 // Uninstallation should be, by default, enabled. | 149 // Uninstallation should be, by default, enabled. |
| 150 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | 150 EXPECT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); |
| 151 | 151 |
| 152 TestManagementPolicyProvider policy_provider( | 152 TestManagementPolicyProvider policy_provider( |
| 153 TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 153 TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 154 system->management_policy()->RegisterProvider(&policy_provider); | 154 system->management_policy()->RegisterProvider(&policy_provider); |
| 155 | 155 |
| 156 // If there's a policy provider that requires the extension stay enabled, then | 156 // If there's a policy provider that requires the extension stay enabled, then |
| 157 // uninstallation should be disabled. | 157 // uninstallation should be disabled. |
| 158 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | 158 EXPECT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); |
| 159 int uninstall_index = |
| 160 menu->GetIndexOfCommandId(ExtensionContextMenuModel::UNINSTALL); |
| 161 // There should also be an icon to visually indicate why uninstallation is |
| 162 // forbidden. |
| 163 gfx::Image icon; |
| 164 EXPECT_TRUE(menu->GetIconAt(uninstall_index, &icon)); |
| 165 EXPECT_FALSE(icon.IsEmpty()); |
| 159 | 166 |
| 160 // Don't leave |policy_provider| dangling. | 167 // Don't leave |policy_provider| dangling. |
| 161 system->management_policy()->UnregisterProvider(&policy_provider); | 168 system->management_policy()->UnregisterProvider(&policy_provider); |
| 162 } | 169 } |
| 163 | 170 |
| 164 // Tests the context menu for a component extension. | 171 // Tests the context menu for a component extension. |
| 165 TEST_F(ExtensionContextMenuModelTest, ComponentExtensionContextMenu) { | 172 TEST_F(ExtensionContextMenuModelTest, ComponentExtensionContextMenu) { |
| 166 InitializeEmptyExtensionService(); | 173 InitializeEmptyExtensionService(); |
| 167 | 174 |
| 168 std::string name("component"); | 175 std::string name("component"); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 browser_action.get(), | 361 browser_action.get(), |
| 355 browser.get(), | 362 browser.get(), |
| 356 ExtensionContextMenuModel::TRANSITIVELY_VISIBLE, | 363 ExtensionContextMenuModel::TRANSITIVELY_VISIBLE, |
| 357 nullptr); | 364 nullptr); |
| 358 index = GetCommandIndex(menu, visibility_command); | 365 index = GetCommandIndex(menu, visibility_command); |
| 359 EXPECT_NE(-1, index); | 366 EXPECT_NE(-1, index); |
| 360 EXPECT_EQ(redesign_keep_string, menu->GetLabelAt(index)); | 367 EXPECT_EQ(redesign_keep_string, menu->GetLabelAt(index)); |
| 361 } | 368 } |
| 362 | 369 |
| 363 } // namespace extensions | 370 } // namespace extensions |
| OLD | NEW |