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/extension_service_unittest.h" | 7 #include "chrome/browser/extensions/extension_service_unittest.h" |
8 #include "chrome/browser/extensions/extension_system.h" | 8 #include "chrome/browser/extensions/extension_system.h" |
9 #include "chrome/browser/extensions/test_management_policy.h" | 9 #include "chrome/browser/extensions/test_management_policy.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // Build an extension to pass to the menu constructor. It needs an | 28 // Build an extension to pass to the menu constructor. It needs an |
29 // ExtensionAction. | 29 // ExtensionAction. |
30 scoped_refptr<Extension> extension = ExtensionBuilder() | 30 scoped_refptr<Extension> extension = ExtensionBuilder() |
31 .SetManifest(DictionaryBuilder() | 31 .SetManifest(DictionaryBuilder() |
32 .Set("name", "Page Action Extension") | 32 .Set("name", "Page Action Extension") |
33 .Set("version", "1") | 33 .Set("version", "1") |
34 .Set("manifest_version", 2) | 34 .Set("manifest_version", 2) |
35 .Set("page_action", DictionaryBuilder() | 35 .Set("page_action", DictionaryBuilder() |
36 .Set("default_title", "Hello"))) | 36 .Set("default_title", "Hello"))) |
37 .Build(); | 37 .Build(); |
38 ASSERT_TRUE(extension); | 38 ASSERT_TRUE(extension.get()); |
39 service_->AddExtension(extension); | 39 service_->AddExtension(extension.get()); |
40 | 40 |
41 // Create a Browser for the ExtensionContextMenuModel to use. | 41 // Create a Browser for the ExtensionContextMenuModel to use. |
42 Browser::CreateParams params(profile_.get(), | 42 Browser::CreateParams params(profile_.get(), |
43 chrome::HOST_DESKTOP_TYPE_NATIVE); | 43 chrome::HOST_DESKTOP_TYPE_NATIVE); |
44 TestBrowserWindow test_window; | 44 TestBrowserWindow test_window; |
45 params.window = &test_window; | 45 params.window = &test_window; |
46 Browser browser(params); | 46 Browser browser(params); |
47 | 47 |
48 scoped_refptr<ExtensionContextMenuModel> menu( | 48 scoped_refptr<ExtensionContextMenuModel> menu( |
49 new ExtensionContextMenuModel(extension, &browser, NULL)); | 49 new ExtensionContextMenuModel(extension.get(), &browser, NULL)); |
50 | 50 |
51 extensions::ExtensionSystem* system = | 51 extensions::ExtensionSystem* system = |
52 extensions::ExtensionSystem::Get(profile_.get()); | 52 extensions::ExtensionSystem::Get(profile_.get()); |
53 system->management_policy()->UnregisterAllProviders(); | 53 system->management_policy()->UnregisterAllProviders(); |
54 | 54 |
55 // Actions should be enabled. | 55 // Actions should be enabled. |
56 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | 56 ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); |
57 | 57 |
58 extensions::TestManagementPolicyProvider policy_provider( | 58 extensions::TestManagementPolicyProvider policy_provider( |
59 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); | 59 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); |
60 system->management_policy()->RegisterProvider(&policy_provider); | 60 system->management_policy()->RegisterProvider(&policy_provider); |
61 | 61 |
62 // Now the actions are disabled. | 62 // Now the actions are disabled. |
63 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); | 63 ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); |
64 | 64 |
65 // Don't leave |policy_provider| dangling. | 65 // Don't leave |policy_provider| dangling. |
66 system->management_policy()->UnregisterAllProviders(); | 66 system->management_policy()->UnregisterAllProviders(); |
67 } | 67 } |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 } // namespace extensions | 70 } // namespace extensions |
OLD | NEW |