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

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

Issue 559603002: Add new ExtensionManagement preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes addressing #16 Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <vector>
6 7
8 #include "base/json/json_parser.h"
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/testing_pref_service.h" 11 #include "base/prefs/testing_pref_service.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_management.h" 13 #include "chrome/browser/extensions/extension_management.h"
14 #include "chrome/browser/extensions/extension_management_test_util.h"
12 #include "chrome/browser/extensions/external_policy_loader.h" 15 #include "chrome/browser/extensions/external_policy_loader.h"
13 #include "extensions/browser/pref_names.h" 16 #include "extensions/browser/pref_names.h"
17 #include "extensions/common/manifest.h"
14 #include "extensions/common/manifest_constants.h" 18 #include "extensions/common/manifest_constants.h"
15 #include "extensions/common/url_pattern.h" 19 #include "extensions/common/url_pattern.h"
16 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h"
17 22
18 namespace extensions { 23 namespace extensions {
19 24
20 namespace { 25 namespace {
26
21 const char kTargetExtension[] = "abcdefghijklmnopabcdefghijklmnop"; 27 const char kTargetExtension[] = "abcdefghijklmnopabcdefghijklmnop";
28 const char kTargetExtension2[] = "bcdefghijklmnopabcdefghijklmnopa";
29 const char kTargetExtension3[] = "cdefghijklmnopabcdefghijklmnopab";
22 const char kOtherExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 30 const char kOtherExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
23 const char kExampleUpdateUrl[] = "http://example.com/update_url"; 31 const char kExampleUpdateUrl[] = "http://example.com/update_url";
32
33 const char kExampleDictPreference[] =
34 "{"
35 " \"abcdefghijklmnopabcdefghijklmnop\": {" // kTargetExtension
36 " \"installation_mode\": \"allowed\","
37 " },"
38 " \"bcdefghijklmnopabcdefghijklmnopa\": {" // kTargetExtension2
39 " \"installation_mode\": \"force_installed\","
40 " \"update_url\": \"http://example.com/update_url\","
41 " },"
42 " \"cdefghijklmnopabcdefghijklmnopab\": {" // kTargetExtension3
43 " \"installation_mode\": \"normal_installed\","
44 " \"update_url\": \"http://example.com/update_url\","
45 " },"
46 " \"*\": {"
47 " \"installation_mode\": \"blocked\","
48 " \"install_sources\": [\"*://foo.com/*\"],"
49 " \"allowed_types\": [\"theme\", \"user_script\"],"
50 " },"
51 "}";
52
24 } // namespace 53 } // namespace
25 54
26 class ExtensionManagementTest : public testing::Test { 55 class ExtensionManagementServiceTest : public testing::Test {
27 public: 56 public:
28 ExtensionManagementTest() {} 57 typedef ExtensionManagementPrefUpdater<TestingPrefServiceSimple> PrefUpdater;
29 virtual ~ExtensionManagementTest() {} 58
59 ExtensionManagementServiceTest() {}
60 virtual ~ExtensionManagementServiceTest() {}
30 61
31 // testing::Test: 62 // testing::Test:
32 virtual void SetUp() OVERRIDE { 63 virtual void SetUp() OVERRIDE {
33 InitPrefService(); 64 InitPrefService();
34 } 65 }
35 66
36 void InitPrefService() { 67 void InitPrefService() {
37 extension_management_.reset(); 68 extension_management_.reset();
38 pref_service_.reset(new TestingPrefServiceSimple()); 69 pref_service_.reset(new TestingPrefServiceSimple());
39 pref_service_->registry()->RegisterListPref( 70 pref_service_->registry()->RegisterListPref(
40 pref_names::kAllowedInstallSites); 71 pref_names::kAllowedInstallSites);
41 pref_service_->registry()->RegisterListPref(pref_names::kAllowedTypes); 72 pref_service_->registry()->RegisterListPref(pref_names::kAllowedTypes);
42 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList); 73 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList);
43 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList); 74 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList);
44 pref_service_->registry()->RegisterDictionaryPref( 75 pref_service_->registry()->RegisterDictionaryPref(
45 pref_names::kInstallForceList); 76 pref_names::kInstallForceList);
77 pref_service_->registry()->RegisterDictionaryPref(
78 pref_names::kExtensionManagement);
46 extension_management_.reset(new ExtensionManagement(pref_service_.get())); 79 extension_management_.reset(new ExtensionManagement(pref_service_.get()));
47 } 80 }
48 81
49 void SetPref(bool managed, const char* path, base::Value* value) { 82 void SetPref(bool managed, const char* path, base::Value* value) {
50 if (managed) 83 if (managed)
51 pref_service_->SetManagedPref(path, value); 84 pref_service_->SetManagedPref(path, value);
52 else 85 else
53 pref_service_->SetUserPref(path, value); 86 pref_service_->SetUserPref(path, value);
54 } 87 }
55 88
56 void RemovePref(bool managed, const char* path) { 89 void RemovePref(bool managed, const char* path) {
57 if (managed) 90 if (managed)
58 pref_service_->RemoveManagedPref(path); 91 pref_service_->RemoveManagedPref(path);
59 else 92 else
60 pref_service_->RemoveUserPref(path); 93 pref_service_->RemoveUserPref(path);
61 } 94 }
62 95
96 void SetExampleDictPref() {
97 std::string error_msg;
98 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError(
99 kExampleDictPreference,
100 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS,
101 NULL,
102 &error_msg));
103 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY))
104 << error_msg;
105 SetPref(true, pref_names::kExtensionManagement, parsed.release());
106 }
107
63 protected: 108 protected:
64 scoped_ptr<TestingPrefServiceSimple> pref_service_; 109 scoped_ptr<TestingPrefServiceSimple> pref_service_;
65 scoped_ptr<ExtensionManagement> extension_management_; 110 scoped_ptr<ExtensionManagement> extension_management_;
66 }; 111 };
67 112
68 class ExtensionAdminPolicyTest : public ExtensionManagementTest { 113 class ExtensionAdminPolicyTest : public ExtensionManagementServiceTest {
69 public: 114 public:
70 ExtensionAdminPolicyTest() {} 115 ExtensionAdminPolicyTest() {}
71 virtual ~ExtensionAdminPolicyTest() {} 116 virtual ~ExtensionAdminPolicyTest() {}
72 117
73 void CreateExtension(Manifest::Location location) { 118 void CreateExtension(Manifest::Location location) {
74 base::DictionaryValue values; 119 base::DictionaryValue values;
75 CreateExtensionFromValues(location, &values); 120 CreateExtensionFromValues(location, &values);
76 } 121 }
77 122
78 void CreateHostedApp(Manifest::Location location) { 123 void CreateHostedApp(Manifest::Location location) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 189
145 bool ExtensionAdminPolicyTest::MustRemainEnabled(const Extension* extension, 190 bool ExtensionAdminPolicyTest::MustRemainEnabled(const Extension* extension,
146 base::string16* error) { 191 base::string16* error) {
147 InitPrefService(); 192 InitPrefService();
148 return extension_management_->GetProvider()->MustRemainEnabled(extension, 193 return extension_management_->GetProvider()->MustRemainEnabled(extension,
149 error); 194 error);
150 } 195 }
151 196
152 // Verify that preference controlled by legacy ExtensionInstallSources policy is 197 // Verify that preference controlled by legacy ExtensionInstallSources policy is
153 // handled well. 198 // handled well.
154 TEST_F(ExtensionManagementTest, LegacyInstallSources) { 199 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) {
155 base::ListValue allowed_sites_pref; 200 base::ListValue allowed_sites_pref;
156 allowed_sites_pref.AppendString("https://www.example.com/foo"); 201 allowed_sites_pref.AppendString("https://www.example.com/foo");
157 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); 202 allowed_sites_pref.AppendString("https://corp.mycompany.com/*");
158 SetPref( 203 SetPref(
159 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); 204 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
160 const URLPatternSet& allowed_sites = 205 const URLPatternSet& allowed_sites =
161 extension_management_->ReadGlobalSettings().install_sources; 206 extension_management_->ReadGlobalSettings().install_sources;
162 ASSERT_TRUE(extension_management_->ReadGlobalSettings() 207 ASSERT_TRUE(extension_management_->ReadGlobalSettings()
163 .has_restricted_install_sources); 208 .has_restricted_install_sources);
164 EXPECT_FALSE(allowed_sites.is_empty()); 209 EXPECT_FALSE(allowed_sites.is_empty());
165 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); 210 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo")));
166 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); 211 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar")));
167 EXPECT_TRUE( 212 EXPECT_TRUE(
168 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); 213 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry")));
169 EXPECT_FALSE( 214 EXPECT_FALSE(
170 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); 215 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry")));
171 } 216 }
172 217
173 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is 218 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is
174 // handled well. 219 // handled well.
175 TEST_F(ExtensionManagementTest, LegacyAllowedTypes) { 220 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) {
176 base::ListValue allowed_types_pref; 221 base::ListValue allowed_types_pref;
177 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); 222 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME);
178 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); 223 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT);
179 224
180 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); 225 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy());
181 const std::vector<Manifest::Type>& allowed_types = 226 const std::vector<Manifest::Type>& allowed_types =
182 extension_management_->ReadGlobalSettings().allowed_types; 227 extension_management_->ReadGlobalSettings().allowed_types;
183 ASSERT_TRUE( 228 ASSERT_TRUE(
184 extension_management_->ReadGlobalSettings().has_restricted_allowed_types); 229 extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
185 EXPECT_TRUE(allowed_types.size() == 2); 230 EXPECT_TRUE(allowed_types.size() == 2);
186 EXPECT_FALSE(std::find(allowed_types.begin(), 231 EXPECT_FALSE(std::find(allowed_types.begin(),
187 allowed_types.end(), 232 allowed_types.end(),
188 Manifest::TYPE_EXTENSION) != allowed_types.end()); 233 Manifest::TYPE_EXTENSION) != allowed_types.end());
189 EXPECT_TRUE(std::find(allowed_types.begin(), 234 EXPECT_TRUE(std::find(allowed_types.begin(),
190 allowed_types.end(), 235 allowed_types.end(),
191 Manifest::TYPE_THEME) != allowed_types.end()); 236 Manifest::TYPE_THEME) != allowed_types.end());
192 EXPECT_TRUE(std::find(allowed_types.begin(), 237 EXPECT_TRUE(std::find(allowed_types.begin(),
193 allowed_types.end(), 238 allowed_types.end(),
194 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); 239 Manifest::TYPE_USER_SCRIPT) != allowed_types.end());
195 } 240 }
196 241
197 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy 242 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy
198 // is handled well. 243 // is handled well.
199 TEST_F(ExtensionManagementTest, LegacyInstallBlacklist) { 244 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) {
200 base::ListValue denied_list_pref; 245 base::ListValue denied_list_pref;
201 denied_list_pref.AppendString(kTargetExtension); 246 denied_list_pref.AppendString(kTargetExtension);
202 247
203 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 248 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
204 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, 249 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
205 ExtensionManagement::INSTALLATION_BLOCKED); 250 ExtensionManagement::INSTALLATION_BLOCKED);
206 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, 251 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
207 ExtensionManagement::INSTALLATION_ALLOWED); 252 ExtensionManagement::INSTALLATION_ALLOWED);
208 } 253 }
209 254
210 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy 255 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy
211 // is handled well. 256 // is handled well.
212 TEST_F(ExtensionManagementTest, LegacyInstallWhitelist) { 257 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) {
213 base::ListValue denied_list_pref; 258 base::ListValue denied_list_pref;
214 denied_list_pref.AppendString("*"); 259 denied_list_pref.AppendString("*");
215 base::ListValue allowed_list_pref; 260 base::ListValue allowed_list_pref;
216 allowed_list_pref.AppendString(kTargetExtension); 261 allowed_list_pref.AppendString(kTargetExtension);
217 262
218 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 263 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
219 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 264 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
220 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, 265 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
221 ExtensionManagement::INSTALLATION_ALLOWED); 266 ExtensionManagement::INSTALLATION_ALLOWED);
222 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, 267 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
223 ExtensionManagement::INSTALLATION_BLOCKED); 268 ExtensionManagement::INSTALLATION_BLOCKED);
224 269
225 // Verify that install whitelist preference set by user is ignored. 270 // Verify that install whitelist preference set by user is ignored.
226 RemovePref(true, pref_names::kInstallAllowList); 271 RemovePref(true, pref_names::kInstallAllowList);
227 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 272 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
228 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, 273 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
229 ExtensionManagement::INSTALLATION_BLOCKED); 274 ExtensionManagement::INSTALLATION_BLOCKED);
230 } 275 }
231 276
232 // Verify that preference controlled by legacy ExtensionInstallForcelist policy 277 // Verify that preference controlled by legacy ExtensionInstallForcelist policy
233 // is handled well. 278 // is handled well.
234 TEST_F(ExtensionManagementTest, LegacyInstallForcelist) { 279 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) {
235 base::DictionaryValue forced_list_pref; 280 base::DictionaryValue forced_list_pref;
236 ExternalPolicyLoader::AddExtension( 281 ExternalPolicyLoader::AddExtension(
237 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); 282 &forced_list_pref, kTargetExtension, kExampleUpdateUrl);
238 283
239 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); 284 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
240 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, 285 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
241 ExtensionManagement::INSTALLATION_FORCED); 286 ExtensionManagement::INSTALLATION_FORCED);
242 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url, 287 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url,
243 kExampleUpdateUrl); 288 kExampleUpdateUrl);
244 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode, 289 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
245 ExtensionManagement::INSTALLATION_ALLOWED); 290 ExtensionManagement::INSTALLATION_ALLOWED);
246 291
247 // Verify that install forcelist preference set by user is ignored. 292 // Verify that install forcelist preference set by user is ignored.
248 RemovePref(true, pref_names::kInstallForceList); 293 RemovePref(true, pref_names::kInstallForceList);
249 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); 294 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
250 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode, 295 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
251 ExtensionManagement::INSTALLATION_ALLOWED); 296 ExtensionManagement::INSTALLATION_ALLOWED);
252 } 297 }
253 298
299 // Tests parsing of new dictionary preference.
300 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) {
301 SetExampleDictPref();
302
303 // Verifies the installation mode settings.
304 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
305 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
306 ExtensionManagement::INSTALLATION_ALLOWED);
307 EXPECT_EQ(
308 extension_management_->ReadById(kTargetExtension2).installation_mode,
309 ExtensionManagement::INSTALLATION_FORCED);
310 EXPECT_EQ(extension_management_->ReadById(kTargetExtension2).update_url,
311 kExampleUpdateUrl);
312 EXPECT_EQ(
313 extension_management_->ReadById(kTargetExtension3).installation_mode,
314 ExtensionManagement::INSTALLATION_RECOMMENDED);
315 EXPECT_EQ(extension_management_->ReadById(kTargetExtension3).update_url,
316 kExampleUpdateUrl);
317 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
318 ExtensionManagement::INSTALLATION_BLOCKED);
319
320 // Verifies global settings.
321 EXPECT_TRUE(extension_management_->ReadGlobalSettings()
322 .has_restricted_install_sources);
323 const URLPatternSet& allowed_sites =
324 extension_management_->ReadGlobalSettings().install_sources;
325 EXPECT_EQ(allowed_sites.size(), 1u);
326 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry")));
327 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry")));
328
329 EXPECT_TRUE(
330 extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
331 const std::vector<Manifest::Type>& allowed_types =
332 extension_management_->ReadGlobalSettings().allowed_types;
333 EXPECT_EQ(allowed_types.size(), 2u);
334 EXPECT_TRUE(std::find(allowed_types.begin(),
335 allowed_types.end(),
336 Manifest::TYPE_THEME) != allowed_types.end());
337 EXPECT_TRUE(std::find(allowed_types.begin(),
338 allowed_types.end(),
339 Manifest::TYPE_USER_SCRIPT) != allowed_types.end());
340 }
341
342 // Tests functionality of new preference as to deprecate legacy
343 // ExtensionInstallSources policy.
344 TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
345 // Set the legacy preference, and verifies that it works.
346 base::ListValue allowed_sites_pref;
347 allowed_sites_pref.AppendString("https://www.example.com/foo");
348 SetPref(
349 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
350 EXPECT_TRUE(extension_management_->ReadGlobalSettings()
351 .has_restricted_install_sources);
352 EXPECT_TRUE(
353 extension_management_->ReadGlobalSettings()
354 .install_sources.MatchesURL(GURL("https://www.example.com/foo")));
355
356 // Set the new dictionary preference.
357 {
358 PrefUpdater updater(pref_service_.get());
359 updater.ClearInstallSources();
360 }
361 // Verifies that the new one overrides the legacy ones.
362 EXPECT_TRUE(extension_management_->ReadGlobalSettings()
363 .has_restricted_install_sources);
364 EXPECT_FALSE(
365 extension_management_->ReadGlobalSettings()
366 .install_sources.MatchesURL(GURL("https://www.example.com/foo")));
367
368 // Updates the new dictionary preference.
369 {
370 PrefUpdater updater(pref_service_.get());
371 updater.AddInstallSource("https://corp.mycompany.com/*");
372 }
373 EXPECT_TRUE(extension_management_->ReadGlobalSettings()
374 .has_restricted_install_sources);
375 EXPECT_TRUE(extension_management_->ReadGlobalSettings()
376 .install_sources.MatchesURL(
377 GURL("https://corp.mycompany.com/entry")));
378 }
379
380 // Tests functionality of new preference as to deprecate legacy
381 // ExtensionAllowedTypes policy.
382 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) {
383 // Set the legacy preference, and verifies that it works.
384 base::ListValue allowed_types_pref;
385 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT);
386 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy());
387 EXPECT_TRUE(
388 extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
389 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(),
390 1u);
391 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0],
392 Manifest::TYPE_USER_SCRIPT);
393
394 // Set the new dictionary preference.
395 {
396 PrefUpdater updater(pref_service_.get());
397 updater.ClearAllowedTypes();
398 }
399 // Verifies that the new one overrides the legacy ones.
400 EXPECT_TRUE(
401 extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
402 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(),
403 0u);
404
405 // Updates the new dictionary preference.
406 {
407 PrefUpdater updater(pref_service_.get());
408 updater.AddAllowedType("theme");
409 }
410 EXPECT_TRUE(
411 extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
412 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(),
413 1u);
414 EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0],
415 Manifest::TYPE_THEME);
416 }
417
418 // Tests functionality of new preference as to deprecate legacy
419 // ExtensionInstallBlacklist policy.
420 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) {
421 // Set the new dictionary preference.
422 {
423 PrefUpdater updater(pref_service_.get());
424 updater.SetBlacklistedByDefault(false); // Allowed by default.
425 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false);
426 }
427 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
428 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
429 ExtensionManagement::INSTALLATION_BLOCKED);
430 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
431 ExtensionManagement::INSTALLATION_ALLOWED);
432
433 // Set legacy preference.
434 base::ListValue denied_list_pref;
435 denied_list_pref.AppendString("*");
436 denied_list_pref.AppendString(kTargetExtension2);
437 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
438
439 base::ListValue allowed_list_pref;
440 allowed_list_pref.AppendString(kTargetExtension);
441 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
442
443 // Verifies that the new one have higher priority over the legacy ones.
444 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
445 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
446 ExtensionManagement::INSTALLATION_BLOCKED);
447 EXPECT_EQ(
448 extension_management_->ReadById(kTargetExtension2).installation_mode,
449 ExtensionManagement::INSTALLATION_BLOCKED);
450 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
451 ExtensionManagement::INSTALLATION_ALLOWED);
452 }
453
454 // Tests functionality of new preference as to deprecate legacy
455 // ExtensionInstallWhitelist policy.
456 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) {
457 // Set the new dictionary preference.
458 {
459 PrefUpdater updater(pref_service_.get());
460 updater.SetBlacklistedByDefault(true); // Disallowed by default.
461 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true);
462 }
463 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
464 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
465 ExtensionManagement::INSTALLATION_ALLOWED);
466 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
467 ExtensionManagement::INSTALLATION_BLOCKED);
468
469 // Set legacy preference.
470 base::ListValue denied_list_pref;
471 denied_list_pref.AppendString(kTargetExtension);
472 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
473
474 base::ListValue allowed_list_pref;
475 allowed_list_pref.AppendString(kTargetExtension2);
476 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
477
478 // Verifies that the new one have higher priority over the legacy ones.
479 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
480 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
481 ExtensionManagement::INSTALLATION_ALLOWED);
482 EXPECT_EQ(
483 extension_management_->ReadById(kTargetExtension2).installation_mode,
484 ExtensionManagement::INSTALLATION_ALLOWED);
485 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
486 ExtensionManagement::INSTALLATION_BLOCKED);
487 }
488
489 // Tests functionality of new preference as to deprecate legacy
490 // ExtensionInstallForcelist policy.
491 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) {
492 // Set some legacy preferences, to verify that the new one overrides the
493 // legacy ones.
494 base::ListValue denied_list_pref;
495 denied_list_pref.AppendString(kTargetExtension);
496 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
497
498 // Set the new dictionary preference.
499 {
500 PrefUpdater updater(pref_service_.get());
501 updater.SetIndividualExtensionAutoInstalled(
502 kTargetExtension, kExampleUpdateUrl, true);
503 }
504 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
505 ExtensionManagement::INSTALLATION_FORCED);
506 EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url,
507 kExampleUpdateUrl);
508 EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
509 ExtensionManagement::INSTALLATION_ALLOWED);
510 }
511
254 // Tests the flag value indicating that extensions are blacklisted by default. 512 // Tests the flag value indicating that extensions are blacklisted by default.
255 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { 513 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) {
256 EXPECT_FALSE(BlacklistedByDefault(NULL)); 514 EXPECT_FALSE(BlacklistedByDefault(NULL));
257 515
258 base::ListValue blacklist; 516 base::ListValue blacklist;
259 blacklist.Append(new base::StringValue(kOtherExtension)); 517 blacklist.Append(new base::StringValue(kOtherExtension));
260 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); 518 EXPECT_FALSE(BlacklistedByDefault(&blacklist));
261 blacklist.Append(new base::StringValue("*")); 519 blacklist.Append(new base::StringValue("*"));
262 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 520 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
263 521
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 EXPECT_FALSE(error.empty()); 651 EXPECT_FALSE(error.empty());
394 652
395 CreateExtension(Manifest::INTERNAL); 653 CreateExtension(Manifest::INTERNAL);
396 error.clear(); 654 error.clear();
397 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); 655 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL));
398 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); 656 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error));
399 EXPECT_TRUE(error.empty()); 657 EXPECT_TRUE(error.empty());
400 } 658 }
401 659
402 } // namespace extensions 660 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_test_util.cc ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698