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

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

Issue 9694038: OBSOLETE REVIEW. See http://codereview.chromium.org/10382149/ (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) 2011 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_test_message_listener.h" 7 #include "chrome/browser/extensions/extension_test_message_listener.h"
8 #include "chrome/browser/extensions/test_extension_management_policy.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
11 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
14 15
15 namespace { 16 namespace {
16 17
17 // Find a browser other than |browser|. 18 // Find a browser other than |browser|.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 void LoadAndWaitForLaunch(const std::string& app_path, 58 void LoadAndWaitForLaunch(const std::string& app_path,
58 std::string* out_app_id) { 59 std::string* out_app_id) {
59 ExtensionTestMessageListener launched_app("launched app", false); 60 ExtensionTestMessageListener launched_app("launched app", false);
60 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_path))); 61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII(app_path)));
61 62
62 if (out_app_id) 63 if (out_app_id)
63 *out_app_id = last_loaded_extension_id_; 64 *out_app_id = last_loaded_extension_id_;
64 65
65 ASSERT_TRUE(launched_app.WaitUntilSatisfied()); 66 ASSERT_TRUE(launched_app.WaitUntilSatisfied());
66 } 67 }
68
69 // Returns the extension ID of the first extension found with the given |name|
70 // (from its manifest), or an empty string if no match was found. Includes
71 // both enabled and disabled extensions.
72 std::string GetExtensionIdByName(const ExtensionService* service,
73 const std::string& name) {
74 for (ExtensionSet::const_iterator iter = service->extensions()->begin();
75 iter != service->extensions()->end(); ++iter) {
76 const Extension* extension = (*iter);
77 if (extension->name() == name)
78 return extension->id();
79 }
80 for (ExtensionSet::const_iterator iter =
81 service->disabled_extensions()->begin();
82 iter != service->disabled_extensions()->end();
83 ++iter) {
84 const Extension* extension = (*iter);
85 if (extension->name() == name)
86 return extension->id();
87 }
88 return "";
89 }
67 }; 90 };
68 91
69 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Basics) { 92 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Basics) {
70 InstallExtensions(); 93 InstallExtensions();
71 ASSERT_TRUE(RunExtensionSubtest("management/test", "basics.html")); 94 ASSERT_TRUE(RunExtensionSubtest("management/test", "basics.html"));
72 } 95 }
73 96
74 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Uninstall) { 97 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, Uninstall) {
75 InstallExtensions(); 98 InstallExtensions();
76 ASSERT_TRUE(RunExtensionSubtest("management/test", "uninstall.html")); 99 ASSERT_TRUE(RunExtensionSubtest("management/test", "uninstall.html"));
77 } 100 }
78 101
102 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyAllowed) {
103 InstallExtensions();
104 ExtensionService* service = browser()->profile()->GetExtensionService();
105 std::string id = GetExtensionIdByName(service, "enabled_extension");
106 EXPECT_NE("", id);
107
108 // Ensure that all actions are allowed.
109 service->extension_management_policy()->UnregisterAllDelegates();
110
111 ASSERT_TRUE(RunExtensionSubtest("management/management_policy",
112 "allowed.html"));
113 // The last thing the test does is uninstall the "enabled_extension".
114 id = GetExtensionIdByName(service, "enabled_extension");
115 EXPECT_EQ("", id);
116 }
117
118 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, ManagementPolicyProhibited) {
119 InstallExtensions();
120 ExtensionService* service = browser()->profile()->GetExtensionService();
121 std::string id = GetExtensionIdByName(service, "enabled_extension");
122 EXPECT_NE("", id);
123
124 // Prohibit status changes.
125 service->extension_management_policy()->UnregisterAllDelegates();
126 TestExtensionManagementPolicyDelegate management_policy(
127 TestExtensionManagementPolicyDelegate::PROHIBIT_MODIFY_STATUS);
128 service->extension_management_policy()->RegisterDelegate(&management_policy);
129 ASSERT_TRUE(RunExtensionSubtest("management/management_policy",
130 "prohibited.html"));
131 }
132
79 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchPanelApp) { 133 IN_PROC_BROWSER_TEST_F(ExtensionManagementApiTest, LaunchPanelApp) {
80 ExtensionService* service = browser()->profile()->GetExtensionService(); 134 ExtensionService* service = browser()->profile()->GetExtensionService();
81 135
82 // Load an extension that calls launchApp() on any app that gets 136 // Load an extension that calls launchApp() on any app that gets
83 // installed. 137 // installed.
84 ExtensionTestMessageListener launcher_loaded("launcher loaded", false); 138 ExtensionTestMessageListener launcher_loaded("launcher loaded", false);
85 ASSERT_TRUE(LoadExtension( 139 ASSERT_TRUE(LoadExtension(
86 test_data_dir_.AppendASCII("management/launch_on_install"))); 140 test_data_dir_.AppendASCII("management/launch_on_install")));
87 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied()); 141 ASSERT_TRUE(launcher_loaded.WaitUntilSatisfied());
88 142
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 ASSERT_EQ(2, browser()->tab_count()); 232 ASSERT_EQ(2, browser()->tab_count());
179 #else 233 #else
180 // Find the app's browser. Opening in a new window will create 234 // Find the app's browser. Opening in a new window will create
181 // a new browser. 235 // a new browser.
182 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile())); 236 ASSERT_EQ(2u, BrowserList::GetBrowserCount(browser()->profile()));
183 Browser* app_browser = FindOtherBrowser(browser()); 237 Browser* app_browser = FindOtherBrowser(browser());
184 ASSERT_TRUE(app_browser->is_app()); 238 ASSERT_TRUE(app_browser->is_app());
185 ASSERT_FALSE(app_browser->is_type_panel()); 239 ASSERT_FALSE(app_browser->is_type_panel());
186 #endif 240 #endif
187 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698