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

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

Issue 671943003: Add update url controlled extension management settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-5
Patch Set: fixes addressing #3 Created 6 years, 1 month 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 <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_parser.h" 9 #include "base/json/json_parser.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 15 matching lines...) Expand all
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace extensions { 28 namespace extensions {
29 29
30 namespace { 30 namespace {
31 31
32 const char kTargetExtension[] = "abcdefghijklmnopabcdefghijklmnop"; 32 const char kTargetExtension[] = "abcdefghijklmnopabcdefghijklmnop";
33 const char kTargetExtension2[] = "bcdefghijklmnopabcdefghijklmnopa"; 33 const char kTargetExtension2[] = "bcdefghijklmnopabcdefghijklmnopa";
34 const char kTargetExtension3[] = "cdefghijklmnopabcdefghijklmnopab"; 34 const char kTargetExtension3[] = "cdefghijklmnopabcdefghijklmnopab";
35 const char kTargetExtension4[] = "defghijklmnopabcdefghijklmnopabc"; 35 const char kTargetExtension4[] = "defghijklmnopabcdefghijklmnopabc";
36 const char kOtherExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
37 const char kExampleUpdateUrl[] = "http://example.com/update_url"; 36 const char kExampleUpdateUrl[] = "http://example.com/update_url";
38 37
38 const char kNonExistingExtension[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
39 const char kNonExistingUpdateUrl[] = "http://example.net/update.xml";
40
39 const char kExampleDictPreference[] = 41 const char kExampleDictPreference[] =
40 "{" 42 "{"
41 " \"abcdefghijklmnopabcdefghijklmnop\": {" // kTargetExtension 43 " \"abcdefghijklmnopabcdefghijklmnop\": {" // kTargetExtension
42 " \"installation_mode\": \"allowed\"," 44 " \"installation_mode\": \"allowed\","
43 " \"blocked_permissions\": [\"fileSystem\", \"bookmarks\"]," 45 " \"blocked_permissions\": [\"fileSystem\", \"bookmarks\"],"
44 " }," 46 " },"
45 " \"bcdefghijklmnopabcdefghijklmnopa\": {" // kTargetExtension2 47 " \"bcdefghijklmnopabcdefghijklmnopa\": {" // kTargetExtension2
46 " \"installation_mode\": \"force_installed\"," 48 " \"installation_mode\": \"force_installed\","
47 " \"update_url\": \"http://example.com/update_url\"," 49 " \"update_url\": \"http://example.com/update_url\","
48 " \"allowed_permissions\": [\"fileSystem\", \"bookmarks\"]," 50 " \"allowed_permissions\": [\"fileSystem\", \"bookmarks\"],"
49 " }," 51 " },"
50 " \"cdefghijklmnopabcdefghijklmnopab\": {" // kTargetExtension3 52 " \"cdefghijklmnopabcdefghijklmnopab\": {" // kTargetExtension3
51 " \"installation_mode\": \"normal_installed\"," 53 " \"installation_mode\": \"normal_installed\","
52 " \"update_url\": \"http://example.com/update_url\"," 54 " \"update_url\": \"http://example.com/update_url\","
53 " \"allowed_permissions\": [\"fileSystem\", \"downloads\"]," 55 " \"allowed_permissions\": [\"fileSystem\", \"downloads\"],"
54 " \"blocked_permissions\": [\"fileSystem\", \"history\"]," 56 " \"blocked_permissions\": [\"fileSystem\", \"history\"],"
55 " }," 57 " },"
56 " \"defghijklmnopabcdefghijklmnopabc\": {" // kTargetExtension4 58 " \"defghijklmnopabcdefghijklmnopabc\": {" // kTargetExtension4
57 " \"installation_mode\": \"blocked\"," 59 " \"installation_mode\": \"blocked\","
58 " }," 60 " },"
61 " \"update_url:http://example.com/update_url\": {" // kExampleUpdateUrl
62 " \"installation_mode\": \"allowed\","
63 " \"allowed_permissions\": [\"downloads\"],"
64 " \"blocked_permissions\": [\"bookmarks\"],"
65 " },"
59 " \"*\": {" 66 " \"*\": {"
60 " \"installation_mode\": \"blocked\"," 67 " \"installation_mode\": \"blocked\","
61 " \"install_sources\": [\"*://foo.com/*\"]," 68 " \"install_sources\": [\"*://foo.com/*\"],"
62 " \"allowed_types\": [\"theme\", \"user_script\"]," 69 " \"allowed_types\": [\"theme\", \"user_script\"],"
63 " \"blocked_permissions\": [\"fileSystem\", \"downloads\"]," 70 " \"blocked_permissions\": [\"fileSystem\", \"downloads\"],"
64 " }," 71 " },"
65 "}"; 72 "}";
66 73
67 } // namespace 74 } // namespace
68 75
(...skipping 29 matching lines...) Expand all
98 pref_service_->SetUserPref(path, value); 105 pref_service_->SetUserPref(path, value);
99 } 106 }
100 107
101 void RemovePref(bool managed, const char* path) { 108 void RemovePref(bool managed, const char* path) {
102 if (managed) 109 if (managed)
103 pref_service_->RemoveManagedPref(path); 110 pref_service_->RemoveManagedPref(path);
104 else 111 else
105 pref_service_->RemoveUserPref(path); 112 pref_service_->RemoveUserPref(path);
106 } 113 }
107 114
108 const internal::IndividualSettings* ReadById(const ExtensionId& id) { 115 const internal::GlobalSettings* ReadGlobalSettings() {
109 return extension_management_->ReadById(id); 116 return extension_management_->global_settings_.get();
110 } 117 }
111 118
112 const internal::GlobalSettings* ReadGlobalSettings() { 119 ExtensionManagement::InstallationMode GetInstallationModeById(
113 return extension_management_->ReadGlobalSettings(); 120 const std::string& id) {
121 return GetInstallationMode(id, kNonExistingUpdateUrl);
122 }
123
124 ExtensionManagement::InstallationMode GetInstallationModeByUpdateUrl(
125 const std::string& update_url) {
126 return GetInstallationMode(kNonExistingExtension, update_url);
127 }
128
129 void CheckAutomaticallyInstalledUpdateUrl(const std::string& id,
130 const std::string& update_url) {
131 auto iter = extension_management_->settings_by_id_.find(id);
132 ASSERT_TRUE(iter != extension_management_->settings_by_id_.end());
133 ASSERT_TRUE((iter->second->installation_mode ==
134 ExtensionManagement::INSTALLATION_FORCED) ||
135 (iter->second->installation_mode ==
136 ExtensionManagement::INSTALLATION_RECOMMENDED));
137 EXPECT_EQ(iter->second->update_url, update_url);
138 }
139
140 APIPermissionSet GetBlockedAPIPermissionsById(const std::string& id) {
141 return GetBlockedAPIPermissions(id, kNonExistingUpdateUrl);
142 }
143
144 APIPermissionSet GetBlockedAPIPermissionsByUpdateUrl(
145 const std::string& update_url) {
146 return GetBlockedAPIPermissions(kNonExistingExtension, update_url);
114 } 147 }
115 148
116 void SetExampleDictPref() { 149 void SetExampleDictPref() {
117 std::string error_msg; 150 std::string error_msg;
118 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError( 151 scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError(
119 kExampleDictPreference, 152 kExampleDictPreference,
120 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, 153 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS,
121 NULL, 154 NULL,
122 &error_msg)); 155 &error_msg));
123 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY)) 156 ASSERT_TRUE(parsed && parsed->IsType(base::Value::TYPE_DICTIONARY))
124 << error_msg; 157 << error_msg;
125 SetPref(true, pref_names::kExtensionManagement, parsed.release()); 158 SetPref(true, pref_names::kExtensionManagement, parsed.release());
126 } 159 }
127 160
161 ExtensionManagement::InstallationMode GetInstallationMode(
162 const std::string& id,
163 const std::string& update_url) {
164 scoped_refptr<const Extension> extension =
165 CreateExtensionWithIdAndUpdateUrl(Manifest::UNPACKED, id, update_url);
166 return extension_management_->GetInstallationMode(extension.get());
167 }
168
169 APIPermissionSet GetBlockedAPIPermissions(const std::string& id,
170 const std::string& update_url) {
171 scoped_refptr<const Extension> extension =
172 CreateExtensionWithIdAndUpdateUrl(Manifest::UNPACKED, id, update_url);
173 return extension_management_->GetBlockedAPIPermissions(extension.get());
174 }
175
128 protected: 176 protected:
129 scoped_ptr<TestingPrefServiceSimple> pref_service_; 177 scoped_ptr<TestingPrefServiceSimple> pref_service_;
130 scoped_ptr<ExtensionManagement> extension_management_; 178 scoped_ptr<ExtensionManagement> extension_management_;
179
180 private:
181 // Create an extension with specified |location|, |id| and |update_url|.
182 scoped_refptr<const Extension> CreateExtensionWithIdAndUpdateUrl(
183 Manifest::Location location,
184 const std::string& id,
185 const std::string& update_url) {
186 base::DictionaryValue manifest_dict;
187 manifest_dict.SetString(manifest_keys::kName, "test");
188 manifest_dict.SetString(manifest_keys::kVersion, "0.1");
189 manifest_dict.SetString(manifest_keys::kUpdateURL, update_url);
190 std::string error;
191 scoped_refptr<const Extension> extension =
192 Extension::Create(base::FilePath(), location, manifest_dict,
193 Extension::NO_FLAGS, id, &error);
194 CHECK(extension.get()) << error;
195 return extension;
196 }
131 }; 197 };
132 198
133 class ExtensionAdminPolicyTest : public ExtensionManagementServiceTest { 199 class ExtensionAdminPolicyTest : public ExtensionManagementServiceTest {
134 public: 200 public:
135 ExtensionAdminPolicyTest() {} 201 ExtensionAdminPolicyTest() {}
136 ~ExtensionAdminPolicyTest() override {} 202 ~ExtensionAdminPolicyTest() override {}
137 203
138 void SetUpPolicyProvider() { 204 void SetUpPolicyProvider() {
139 provider_.reset( 205 provider_.reset(
140 new StandardManagementPolicyProvider(extension_management_.get())); 206 new StandardManagementPolicyProvider(extension_management_.get()));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); 326 Manifest::TYPE_USER_SCRIPT) != allowed_types.end());
261 } 327 }
262 328
263 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy 329 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy
264 // is handled well. 330 // is handled well.
265 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { 331 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) {
266 base::ListValue denied_list_pref; 332 base::ListValue denied_list_pref;
267 denied_list_pref.AppendString(kTargetExtension); 333 denied_list_pref.AppendString(kTargetExtension);
268 334
269 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 335 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
270 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 336 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
271 ExtensionManagement::INSTALLATION_BLOCKED); 337 ExtensionManagement::INSTALLATION_BLOCKED);
272 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 338 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
273 ExtensionManagement::INSTALLATION_ALLOWED); 339 ExtensionManagement::INSTALLATION_ALLOWED);
274 } 340 }
275 341
276 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy 342 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy
277 // is handled well. 343 // is handled well.
278 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { 344 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) {
279 base::ListValue denied_list_pref; 345 base::ListValue denied_list_pref;
280 denied_list_pref.AppendString("*"); 346 denied_list_pref.AppendString("*");
281 base::ListValue allowed_list_pref; 347 base::ListValue allowed_list_pref;
282 allowed_list_pref.AppendString(kTargetExtension); 348 allowed_list_pref.AppendString(kTargetExtension);
283 349
284 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 350 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
285 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 351 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
286 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 352 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
287 ExtensionManagement::INSTALLATION_ALLOWED); 353 ExtensionManagement::INSTALLATION_ALLOWED);
288 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 354 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
289 ExtensionManagement::INSTALLATION_BLOCKED); 355 ExtensionManagement::INSTALLATION_BLOCKED);
290 356
291 // Verify that install whitelist preference set by user is ignored. 357 // Verify that install whitelist preference set by user is ignored.
292 RemovePref(true, pref_names::kInstallAllowList); 358 RemovePref(true, pref_names::kInstallAllowList);
293 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 359 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
294 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 360 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
295 ExtensionManagement::INSTALLATION_BLOCKED); 361 ExtensionManagement::INSTALLATION_BLOCKED);
296 } 362 }
297 363
298 // Verify that preference controlled by legacy ExtensionInstallForcelist policy 364 // Verify that preference controlled by legacy ExtensionInstallForcelist policy
299 // is handled well. 365 // is handled well.
300 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { 366 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) {
301 base::DictionaryValue forced_list_pref; 367 base::DictionaryValue forced_list_pref;
302 ExternalPolicyLoader::AddExtension( 368 ExternalPolicyLoader::AddExtension(
303 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); 369 &forced_list_pref, kTargetExtension, kExampleUpdateUrl);
304 370
305 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); 371 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
306 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 372 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
307 ExtensionManagement::INSTALLATION_FORCED); 373 ExtensionManagement::INSTALLATION_FORCED);
308 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); 374 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl);
309 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 375 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
310 ExtensionManagement::INSTALLATION_ALLOWED); 376 ExtensionManagement::INSTALLATION_ALLOWED);
311 377
312 // Verify that install forcelist preference set by user is ignored. 378 // Verify that install forcelist preference set by user is ignored.
313 RemovePref(true, pref_names::kInstallForceList); 379 RemovePref(true, pref_names::kInstallForceList);
314 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); 380 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
315 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 381 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
316 ExtensionManagement::INSTALLATION_ALLOWED); 382 ExtensionManagement::INSTALLATION_ALLOWED);
317 } 383 }
318 384
319 // Tests parsing of new dictionary preference. 385 // Tests parsing of new dictionary preference.
320 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { 386 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) {
321 SetExampleDictPref(); 387 SetExampleDictPref();
322 388
323 // Verifies the installation mode settings. 389 // Verifies the installation mode settings.
324 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 390 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
325 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 391 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
326 ExtensionManagement::INSTALLATION_ALLOWED); 392 ExtensionManagement::INSTALLATION_ALLOWED);
327 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, 393 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
328 ExtensionManagement::INSTALLATION_FORCED); 394 ExtensionManagement::INSTALLATION_FORCED);
329 EXPECT_EQ(ReadById(kTargetExtension2)->update_url, kExampleUpdateUrl); 395 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension2, kExampleUpdateUrl);
330 EXPECT_EQ(ReadById(kTargetExtension3)->installation_mode, 396 EXPECT_EQ(GetInstallationModeById(kTargetExtension3),
331 ExtensionManagement::INSTALLATION_RECOMMENDED); 397 ExtensionManagement::INSTALLATION_RECOMMENDED);
332 EXPECT_EQ(ReadById(kTargetExtension3)->update_url, kExampleUpdateUrl); 398 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension3, kExampleUpdateUrl);
333 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 399 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
334 ExtensionManagement::INSTALLATION_BLOCKED); 400 ExtensionManagement::INSTALLATION_BLOCKED);
401 EXPECT_EQ(GetInstallationModeByUpdateUrl(kExampleUpdateUrl),
402 ExtensionManagement::INSTALLATION_ALLOWED);
335 403
336 // Verifies global settings. 404 // Verifies global settings.
337 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 405 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
338 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; 406 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources;
339 EXPECT_EQ(allowed_sites.size(), 1u); 407 EXPECT_EQ(allowed_sites.size(), 1u);
340 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); 408 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry")));
341 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); 409 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry")));
342 410
343 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); 411 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
344 const std::vector<Manifest::Type>& allowed_types = 412 const std::vector<Manifest::Type>& allowed_types =
345 ReadGlobalSettings()->allowed_types; 413 ReadGlobalSettings()->allowed_types;
346 EXPECT_EQ(allowed_types.size(), 2u); 414 EXPECT_EQ(allowed_types.size(), 2u);
347 EXPECT_TRUE(std::find(allowed_types.begin(), 415 EXPECT_TRUE(std::find(allowed_types.begin(),
348 allowed_types.end(), 416 allowed_types.end(),
349 Manifest::TYPE_THEME) != allowed_types.end()); 417 Manifest::TYPE_THEME) != allowed_types.end());
350 EXPECT_TRUE(std::find(allowed_types.begin(), 418 EXPECT_TRUE(std::find(allowed_types.begin(),
351 allowed_types.end(), 419 allowed_types.end(),
352 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); 420 Manifest::TYPE_USER_SCRIPT) != allowed_types.end());
353 421
354 // Verifies blocked permission list settings. 422 // Verifies blocked permission list settings.
355 APIPermissionSet api_permission_set; 423 APIPermissionSet api_permission_set;
356 api_permission_set.clear(); 424 api_permission_set.clear();
357 api_permission_set.insert(APIPermission::kFileSystem); 425 api_permission_set.insert(APIPermission::kFileSystem);
358 api_permission_set.insert(APIPermission::kDownloads); 426 api_permission_set.insert(APIPermission::kDownloads);
359 EXPECT_EQ(api_permission_set, 427 EXPECT_EQ(api_permission_set,
360 extension_management_->GetBlockedAPIPermissions(kOtherExtension)); 428 GetBlockedAPIPermissionsById(kNonExistingExtension));
361 429
362 api_permission_set.clear(); 430 api_permission_set.clear();
363 api_permission_set.insert(APIPermission::kFileSystem); 431 api_permission_set.insert(APIPermission::kFileSystem);
364 api_permission_set.insert(APIPermission::kDownloads); 432 api_permission_set.insert(APIPermission::kDownloads);
365 api_permission_set.insert(APIPermission::kBookmark); 433 api_permission_set.insert(APIPermission::kBookmark);
366 EXPECT_EQ(api_permission_set, 434 EXPECT_EQ(api_permission_set, GetBlockedAPIPermissionsById(kTargetExtension));
367 extension_management_->GetBlockedAPIPermissions(kTargetExtension));
368 435
369 api_permission_set.clear(); 436 api_permission_set.clear();
370 api_permission_set.insert(APIPermission::kDownloads); 437 api_permission_set.insert(APIPermission::kDownloads);
371 EXPECT_EQ(api_permission_set, 438 EXPECT_EQ(api_permission_set,
372 extension_management_->GetBlockedAPIPermissions(kTargetExtension2)); 439 GetBlockedAPIPermissionsById(kTargetExtension2));
373 440
374 api_permission_set.clear(); 441 api_permission_set.clear();
375 api_permission_set.insert(APIPermission::kFileSystem); 442 api_permission_set.insert(APIPermission::kFileSystem);
376 api_permission_set.insert(APIPermission::kHistory); 443 api_permission_set.insert(APIPermission::kHistory);
377 EXPECT_EQ(api_permission_set, 444 EXPECT_EQ(api_permission_set,
378 extension_management_->GetBlockedAPIPermissions(kTargetExtension3)); 445 GetBlockedAPIPermissionsById(kTargetExtension3));
446
447 api_permission_set.clear();
448 api_permission_set.insert(APIPermission::kFileSystem);
449 api_permission_set.insert(APIPermission::kBookmark);
450 EXPECT_EQ(api_permission_set,
451 GetBlockedAPIPermissionsByUpdateUrl(kExampleUpdateUrl));
452 }
453
454 // Tests the handling of installation mode in case it's specified in both
455 // per-extension and per-update-url settings.
456 TEST_F(ExtensionManagementServiceTest, InstallationModeConflictHandling) {
457 SetExampleDictPref();
458
459 // Per-extension installation mode settings should always override
460 // per-update-url settings.
461 EXPECT_EQ(GetInstallationMode(kTargetExtension, kExampleUpdateUrl),
462 ExtensionManagement::INSTALLATION_ALLOWED);
463 EXPECT_EQ(GetInstallationMode(kTargetExtension2, kExampleUpdateUrl),
464 ExtensionManagement::INSTALLATION_FORCED);
465 EXPECT_EQ(GetInstallationMode(kTargetExtension3, kExampleUpdateUrl),
466 ExtensionManagement::INSTALLATION_RECOMMENDED);
467 }
468
469 // Tests the handling of blocked permissions in case it's specified in both
470 // per-extension and per-update-url settings.
471 TEST_F(ExtensionManagementServiceTest, BlockedPermissionsConflictHandling) {
472 SetExampleDictPref();
473
474 // Both settings should be enforced.
475 APIPermissionSet blocked_permissions_for_update_url;
476 blocked_permissions_for_update_url.insert(APIPermission::kFileSystem);
477 blocked_permissions_for_update_url.insert(APIPermission::kBookmark);
478
479 APIPermissionSet api_permission_set;
480
481 api_permission_set = blocked_permissions_for_update_url;
482 api_permission_set.insert(APIPermission::kFileSystem);
483 api_permission_set.insert(APIPermission::kDownloads);
484 api_permission_set.insert(APIPermission::kBookmark);
485 EXPECT_EQ(api_permission_set,
486 GetBlockedAPIPermissions(kTargetExtension, kExampleUpdateUrl));
487
488 api_permission_set = blocked_permissions_for_update_url;
489 api_permission_set.insert(APIPermission::kDownloads);
490 EXPECT_EQ(api_permission_set,
491 GetBlockedAPIPermissions(kTargetExtension2, kExampleUpdateUrl));
492
493 api_permission_set = blocked_permissions_for_update_url;
494 api_permission_set.insert(APIPermission::kFileSystem);
495 api_permission_set.insert(APIPermission::kHistory);
496 EXPECT_EQ(api_permission_set,
497 GetBlockedAPIPermissions(kTargetExtension3, kExampleUpdateUrl));
379 } 498 }
380 499
381 // Tests functionality of new preference as to deprecate legacy 500 // Tests functionality of new preference as to deprecate legacy
382 // ExtensionInstallSources policy. 501 // ExtensionInstallSources policy.
383 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { 502 TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
384 // Set the legacy preference, and verifies that it works. 503 // Set the legacy preference, and verifies that it works.
385 base::ListValue allowed_sites_pref; 504 base::ListValue allowed_sites_pref;
386 allowed_sites_pref.AppendString("https://www.example.com/foo"); 505 allowed_sites_pref.AppendString("https://www.example.com/foo");
387 SetPref( 506 SetPref(
388 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); 507 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 561
443 // Tests functionality of new preference as to deprecate legacy 562 // Tests functionality of new preference as to deprecate legacy
444 // ExtensionInstallBlacklist policy. 563 // ExtensionInstallBlacklist policy.
445 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { 564 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) {
446 // Set the new dictionary preference. 565 // Set the new dictionary preference.
447 { 566 {
448 PrefUpdater updater(pref_service_.get()); 567 PrefUpdater updater(pref_service_.get());
449 updater.SetBlacklistedByDefault(false); // Allowed by default. 568 updater.SetBlacklistedByDefault(false); // Allowed by default.
450 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); 569 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false);
451 updater.ClearPerExtensionSettings(kTargetExtension2); 570 updater.ClearPerExtensionSettings(kTargetExtension2);
452 updater.ClearPerExtensionSettings(kOtherExtension);
453 } 571 }
454 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); 572 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
455 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 573 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
456 ExtensionManagement::INSTALLATION_BLOCKED); 574 ExtensionManagement::INSTALLATION_BLOCKED);
457 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 575 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
458 ExtensionManagement::INSTALLATION_ALLOWED); 576 ExtensionManagement::INSTALLATION_ALLOWED);
459 577
460 // Set legacy preference. 578 // Set legacy preference.
461 base::ListValue denied_list_pref; 579 base::ListValue denied_list_pref;
462 denied_list_pref.AppendString("*"); 580 denied_list_pref.AppendString("*");
463 denied_list_pref.AppendString(kTargetExtension2); 581 denied_list_pref.AppendString(kTargetExtension2);
464 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 582 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
465 583
466 base::ListValue allowed_list_pref; 584 base::ListValue allowed_list_pref;
467 allowed_list_pref.AppendString(kTargetExtension); 585 allowed_list_pref.AppendString(kTargetExtension);
468 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 586 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
469 587
470 // Verifies that the new one have higher priority over the legacy ones. 588 // Verifies that the new one have higher priority over the legacy ones.
471 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); 589 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
472 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 590 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
473 ExtensionManagement::INSTALLATION_BLOCKED); 591 ExtensionManagement::INSTALLATION_BLOCKED);
474 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, 592 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
475 ExtensionManagement::INSTALLATION_BLOCKED); 593 ExtensionManagement::INSTALLATION_BLOCKED);
476 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 594 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
477 ExtensionManagement::INSTALLATION_ALLOWED); 595 ExtensionManagement::INSTALLATION_ALLOWED);
478 } 596 }
479 597
480 // Tests functionality of new preference as to deprecate legacy 598 // Tests functionality of new preference as to deprecate legacy
481 // ExtensionInstallWhitelist policy. 599 // ExtensionInstallWhitelist policy.
482 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { 600 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) {
483 // Set the new dictionary preference. 601 // Set the new dictionary preference.
484 { 602 {
485 PrefUpdater updater(pref_service_.get()); 603 PrefUpdater updater(pref_service_.get());
486 updater.SetBlacklistedByDefault(true); // Disallowed by default. 604 updater.SetBlacklistedByDefault(true); // Disallowed by default.
487 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); 605 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true);
488 updater.ClearPerExtensionSettings(kTargetExtension2); 606 updater.ClearPerExtensionSettings(kTargetExtension2);
489 updater.ClearPerExtensionSettings(kOtherExtension);
490 } 607 }
491 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 608 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
492 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 609 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
493 ExtensionManagement::INSTALLATION_ALLOWED); 610 ExtensionManagement::INSTALLATION_ALLOWED);
494 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 611 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
495 ExtensionManagement::INSTALLATION_BLOCKED); 612 ExtensionManagement::INSTALLATION_BLOCKED);
496 613
497 // Set legacy preference. 614 // Set legacy preference.
498 base::ListValue denied_list_pref; 615 base::ListValue denied_list_pref;
499 denied_list_pref.AppendString(kTargetExtension); 616 denied_list_pref.AppendString(kTargetExtension);
500 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 617 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
501 618
502 base::ListValue allowed_list_pref; 619 base::ListValue allowed_list_pref;
503 allowed_list_pref.AppendString(kTargetExtension2); 620 allowed_list_pref.AppendString(kTargetExtension2);
504 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 621 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
505 622
506 // Verifies that the new one have higher priority over the legacy ones. 623 // Verifies that the new one have higher priority over the legacy ones.
507 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 624 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
508 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 625 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
509 ExtensionManagement::INSTALLATION_ALLOWED); 626 ExtensionManagement::INSTALLATION_ALLOWED);
510 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, 627 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
511 ExtensionManagement::INSTALLATION_ALLOWED); 628 ExtensionManagement::INSTALLATION_ALLOWED);
512 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 629 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
513 ExtensionManagement::INSTALLATION_BLOCKED); 630 ExtensionManagement::INSTALLATION_BLOCKED);
514 } 631 }
515 632
516 // Tests functionality of new preference as to deprecate legacy 633 // Tests functionality of new preference as to deprecate legacy
517 // ExtensionInstallForcelist policy. 634 // ExtensionInstallForcelist policy.
518 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { 635 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) {
519 // Set some legacy preferences, to verify that the new one overrides the 636 // Set some legacy preferences, to verify that the new one overrides the
520 // legacy ones. 637 // legacy ones.
521 base::ListValue denied_list_pref; 638 base::ListValue denied_list_pref;
522 denied_list_pref.AppendString(kTargetExtension); 639 denied_list_pref.AppendString(kTargetExtension);
523 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 640 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
524 641
525 // Set the new dictionary preference. 642 // Set the new dictionary preference.
526 { 643 {
527 PrefUpdater updater(pref_service_.get()); 644 PrefUpdater updater(pref_service_.get());
528 updater.SetIndividualExtensionAutoInstalled( 645 updater.SetIndividualExtensionAutoInstalled(
529 kTargetExtension, kExampleUpdateUrl, true); 646 kTargetExtension, kExampleUpdateUrl, true);
530 updater.ClearPerExtensionSettings(kOtherExtension);
531 } 647 }
532 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 648 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
533 ExtensionManagement::INSTALLATION_FORCED); 649 ExtensionManagement::INSTALLATION_FORCED);
534 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); 650 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl);
535 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 651 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
536 ExtensionManagement::INSTALLATION_ALLOWED); 652 ExtensionManagement::INSTALLATION_ALLOWED);
537 } 653 }
538 654
539 // Tests the behavior of IsInstallationExplicitlyAllowed(). 655 // Tests the behavior of IsInstallationExplicitlyAllowed().
540 TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) { 656 TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) {
541 SetExampleDictPref(); 657 SetExampleDictPref();
542 658
543 // Constant name indicates the installation_mode of extensions in example 659 // Constant name indicates the installation_mode of extensions in example
544 // preference. 660 // preference.
545 const char* allowed = kTargetExtension; 661 const char* allowed = kTargetExtension;
546 const char* forced = kTargetExtension2; 662 const char* forced = kTargetExtension2;
547 const char* recommended = kTargetExtension3; 663 const char* recommended = kTargetExtension3;
548 const char* blocked = kTargetExtension4; 664 const char* blocked = kTargetExtension4;
549 const char* not_specified = kOtherExtension; 665 const char* not_specified = kNonExistingExtension;
550 666
551 // BlacklistedByDefault() is true in example preference. 667 // BlacklistedByDefault() is true in example preference.
552 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed)); 668 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed));
553 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced)); 669 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced));
554 EXPECT_TRUE( 670 EXPECT_TRUE(
555 extension_management_->IsInstallationExplicitlyAllowed(recommended)); 671 extension_management_->IsInstallationExplicitlyAllowed(recommended));
556 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked)); 672 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
557 EXPECT_FALSE( 673 EXPECT_FALSE(
558 extension_management_->IsInstallationExplicitlyAllowed(not_specified)); 674 extension_management_->IsInstallationExplicitlyAllowed(not_specified));
559 675
(...skipping 11 matching lines...) Expand all
571 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked)); 687 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
572 EXPECT_FALSE( 688 EXPECT_FALSE(
573 extension_management_->IsInstallationExplicitlyAllowed(not_specified)); 689 extension_management_->IsInstallationExplicitlyAllowed(not_specified));
574 } 690 }
575 691
576 // Tests the flag value indicating that extensions are blacklisted by default. 692 // Tests the flag value indicating that extensions are blacklisted by default.
577 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { 693 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) {
578 EXPECT_FALSE(BlacklistedByDefault(NULL)); 694 EXPECT_FALSE(BlacklistedByDefault(NULL));
579 695
580 base::ListValue blacklist; 696 base::ListValue blacklist;
581 blacklist.Append(new base::StringValue(kOtherExtension)); 697 blacklist.Append(new base::StringValue(kNonExistingExtension));
582 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); 698 EXPECT_FALSE(BlacklistedByDefault(&blacklist));
583 blacklist.Append(new base::StringValue("*")); 699 blacklist.Append(new base::StringValue("*"));
584 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 700 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
585 701
586 blacklist.Clear(); 702 blacklist.Clear();
587 blacklist.Append(new base::StringValue("*")); 703 blacklist.Append(new base::StringValue("*"));
588 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 704 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
589 } 705 }
590 706
591 // Tests UserMayLoad for required extensions. 707 // Tests UserMayLoad for required extensions.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 EXPECT_FALSE(error.empty()); 831 EXPECT_FALSE(error.empty());
716 832
717 CreateExtension(Manifest::INTERNAL); 833 CreateExtension(Manifest::INTERNAL);
718 error.clear(); 834 error.clear();
719 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); 835 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL));
720 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); 836 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error));
721 EXPECT_TRUE(error.empty()); 837 EXPECT_TRUE(error.empty());
722 } 838 }
723 839
724 } // namespace extensions 840 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management_internal.h ('k') | chrome/browser/extensions/extension_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698