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

Side by Side Diff: chrome/browser/extensions/extension_management_apitest.cc

Issue 10382149: Refactor the various ways to control what users can do to extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/extensions/extension_service.h" 6 #include "chrome/browser/extensions/extension_service.h"
7 #include "chrome/browser/extensions/extension_system.h"
7 #include "chrome/browser/extensions/extension_test_message_listener.h" 8 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/extensions/test_management_policy.h"
8 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
15 17
18 using extensions::Extension;
19
16 namespace { 20 namespace {
17 21
18 // Find a browser other than |browser|. 22 // Find a browser other than |browser|.
19 Browser* FindOtherBrowser(Browser* browser) { 23 Browser* FindOtherBrowser(Browser* browser) {
20 Browser* found = NULL; 24 Browser* found = NULL;
21 for (BrowserList::const_iterator it = BrowserList::begin(); 25 for (BrowserList::const_iterator it = BrowserList::begin();
22 it != BrowserList::end(); ++it) { 26 it != BrowserList::end(); ++it) {
23 if (*it == browser) 27 if (*it == browser)
24 continue; 28 continue;
25 found = *it; 29 found = *it;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void LoadAndWaitForLaunch(const std::string& app_path, 62 void LoadAndWaitForLaunch(const std::string& app_path,
59 std::string* out_app_id) { 63 std::string* out_app_id) {
60 ExtensionTestMessageListener launched_app("launched app", false); 64 ExtensionTestMessageListener launched_app("launched app", false);
61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_path))); 65 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_path)));
62 66
63 if (out_app_id) 67 if (out_app_id)
64 *out_app_id = last_loaded_extension_id_; 68 *out_app_id = last_loaded_extension_id_;
65 69
66 ASSERT_TRUE(launched_app.WaitUntilSatisfied()); 70 ASSERT_TRUE(launched_app.WaitUntilSatisfied());
67 } 71 }
72
73 // Returns the extension ID of the first extension found with the given |name|
74 // (from its manifest), or an empty string if no match was found. Includes
75 // both enabled and disabled extensions.
76 std::string GetExtensionIdByName(const ExtensionService* service,
Aaron Boodman 2012/05/22 15:56:11 LoadExtension() returns Extension*. You can just s
77 const std::string& name) {
78 for (ExtensionSet::const_iterator iter = service->extensions()->begin();
79 iter != service->extensions()->end(); ++iter) {
80 const Extension* extension = (*iter);
81 if (extension->name() == name)
82 return extension->id();
83 }
84 for (ExtensionSet::const_iterator iter =
85 service->disabled_extensions()->begin();
86 iter != service->disabled_extensions()->end();
87 ++iter) {
88 const Extension* extension = (*iter);
89 if (extension->name() == name)
90 return extension->id();
91 }
92 return "";
93 }
68 }; 94 };
69 95
70 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Basics) { 96 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Basics) {
71 InstallExtensions(); 97 InstallExtensions();
72 ASSERT_TRUE(RunExtensionSubtest("management/test", "basics.html")); 98 ASSERT_TRUE(RunExtensionSubtest("management/test", "basics.html"));
73 } 99 }
74 100
75 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Uninstall) { 101 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Uninstall) {
76 InstallExtensions(); 102 InstallExtensions();
77 ASSERT_TRUE(RunExtensionSubtest("management/test", "uninstall.html")); 103 ASSERT_TRUE(RunExtensionSubtest("management/test", "uninstall.html"));
78 } 104 }
79 105
106 // Tests actions on extensions when no management policy is in place.
107 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyAllowed) {
108 InstallExtensions();
109 ExtensionService* service = browser()->profile()->GetExtensionService();
110 std::string id = GetExtensionIdByName(service, "enabled_extension");
111 EXPECT_NE("", id);
112
113 // Ensure that all actions are allowed.
114 ExtensionSystem::Get(browser()->profile())->management_policy()
115 ->UnregisterAllProviders();
116
117 ASSERT_TRUE(RunExtensionSubtest("management/management_policy",
118 "allowed.html"));
119 // The last thing the test does is uninstall the "enabled_extension".
120 id = GetExtensionIdByName(service, "enabled_extension");
121 EXPECT_EQ("", id);
122 }
123
124 // Tests actions on extensions when management policy prohibits those actions.
125 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyProhibited) {
126 InstallExtensions();
127 ExtensionService* service = browser()->profile()->GetExtensionService();
128 std::string id = GetExtensionIdByName(service, "enabled_extension");
129 EXPECT_NE("", id);
130
131 // Prohibit status changes.
132 extensions::ManagementPolicy* policy =
133 ExtensionSystem::Get(browser()->profile())->management_policy();
134 policy->UnregisterAllProviders();
135 extensions::TestManagementPolicyProvider provider(
136 extensions::TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
137 policy->RegisterProvider(&provider);
138 ASSERT_TRUE(RunExtensionSubtest("management/management_policy",
139 "prohibited.html"));
140 }
141
80 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchPanelApp) { 142 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchPanelApp) {
81 ExtensionService* service = browser()->profile()->GetExtensionService(); 143 ExtensionService* service = browser()->profile()->GetExtensionService();
82 144
83 // Load an extension that calls launchApp() on any app that gets 145 // Load an extension that calls launchApp() on any app that gets
84 // installed. 146 // installed.
85 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); 147 ExtensionTestMessageListener launcher_loaded("launcher loaded", false);
86 ASSERT_TRUE(LoadExtension( 148 ASSERT_TRUE(LoadExtension(
87 test_data_dir_.AppendASCII("management/launch_on_install"))); 149 test_data_dir_.AppendASCII("management/launch_on_install")));
88 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); 150 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied());
89 151
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 ASSERT_EQ(2, browser()->tab_count()); 241 ASSERT_EQ(2, browser()->tab_count());
180 #else 242 #else
181 // Find the app's browser. Opening in a new window will create 243 // Find the app's browser. Opening in a new window will create
182 // a new browser. 244 // a new browser.
183 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile())); 245 ASSERT_EQ(2u, browser::GetBrowserCount(browser()->profile()));
184 Browser* app_browser = FindOtherBrowser(browser()); 246 Browser* app_browser = FindOtherBrowser(browser());
185 ASSERT_TRUE(app_browser->is_app()); 247 ASSERT_TRUE(app_browser->is_app());
186 ASSERT_FALSE(app_browser->is_type_panel()); 248 ASSERT_FALSE(app_browser->is_type_panel());
187 #endif 249 #endif
188 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698