| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_service_test_base.h" | 10 #include "chrome/browser/extensions/extension_service_test_base.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 service()->AddExtension(extension.get()); | 151 service()->AddExtension(extension.get()); |
| 152 | 152 |
| 153 scoped_ptr<Browser> browser = CreateBrowser(profile()); | 153 scoped_ptr<Browser> browser = CreateBrowser(profile()); |
| 154 scoped_refptr<ExtensionContextMenuModel> menu( | 154 scoped_refptr<ExtensionContextMenuModel> menu( |
| 155 new ExtensionContextMenuModel(extension.get(), browser.get())); | 155 new ExtensionContextMenuModel(extension.get(), browser.get())); |
| 156 | 156 |
| 157 ExtensionSystem* system = ExtensionSystem::Get(profile()); | 157 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
| 158 system->management_policy()->UnregisterAllProviders(); | 158 system->management_policy()->UnregisterAllProviders(); |
| 159 | 159 |
| 160 // Uninstallation should be, by default, enabled. | 160 // Uninstallation should be, by default, enabled. |
| 161 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | 161 EXPECT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); |
| 162 | 162 |
| 163 TestManagementPolicyProvider policy_provider( | 163 TestManagementPolicyProvider policy_provider( |
| 164 TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 164 TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
| 165 system->management_policy()->RegisterProvider(&policy_provider); | 165 system->management_policy()->RegisterProvider(&policy_provider); |
| 166 | 166 |
| 167 // If there's a policy provider that requires the extension stay enabled, then | 167 // If there's a policy provider that requires the extension stay enabled, then |
| 168 // uninstallation should be disabled. | 168 // uninstallation should be disabled. |
| 169 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | 169 EXPECT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); |
| 170 int uninstall_index = |
| 171 menu->GetIndexOfCommandId(ExtensionContextMenuModel::UNINSTALL); |
| 172 // There should also be an icon to visually indicate why uninstallation is |
| 173 // forbidden. |
| 174 gfx::Image icon; |
| 175 EXPECT_TRUE(menu->GetIconAt(uninstall_index, &icon)); |
| 176 EXPECT_FALSE(icon.IsEmpty()); |
| 170 | 177 |
| 171 // Don't leave |policy_provider| dangling. | 178 // Don't leave |policy_provider| dangling. |
| 172 system->management_policy()->UnregisterProvider(&policy_provider); | 179 system->management_policy()->UnregisterProvider(&policy_provider); |
| 173 } | 180 } |
| 174 | 181 |
| 175 // Tests the context menu for a component extension. | 182 // Tests the context menu for a component extension. |
| 176 TEST_F(ExtensionContextMenuModelTest, ComponentExtensionContextMenu) { | 183 TEST_F(ExtensionContextMenuModelTest, ComponentExtensionContextMenu) { |
| 177 InitializeEmptyExtensionService(); | 184 InitializeEmptyExtensionService(); |
| 178 | 185 |
| 179 std::string name("component"); | 186 std::string name("component"); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 browser_action.get(), | 372 browser_action.get(), |
| 366 browser.get(), | 373 browser.get(), |
| 367 ExtensionContextMenuModel::TRANSITIVELY_VISIBLE, | 374 ExtensionContextMenuModel::TRANSITIVELY_VISIBLE, |
| 368 nullptr); | 375 nullptr); |
| 369 index = GetCommandIndex(menu, visibility_command); | 376 index = GetCommandIndex(menu, visibility_command); |
| 370 EXPECT_NE(-1, index); | 377 EXPECT_NE(-1, index); |
| 371 EXPECT_EQ(redesign_keep_string, menu->GetLabelAt(index)); | 378 EXPECT_EQ(redesign_keep_string, menu->GetLabelAt(index)); |
| 372 } | 379 } |
| 373 | 380 |
| 374 } // namespace extensions | 381 } // namespace extensions |
| OLD | NEW |