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

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: add unit tests 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
128 protected: 161 protected:
Joao da Silva 2014/11/04 14:06:09 Why are some of the helper methods public and othe
binjin 2014/11/05 12:52:42 Done. Moving helper functions to public and intern
162 ExtensionManagement::InstallationMode GetInstallationMode(
163 const std::string& id,
164 const std::string& update_url) {
165 scoped_refptr<const Extension> extension =
166 CreateExtensionWithIdAndUpdateUrl(Manifest::UNPACKED, id, update_url);
167 return extension_management_->GetInstallationMode(extension.get());
168 }
169
170 APIPermissionSet GetBlockedAPIPermissions(const std::string& id,
171 const std::string& update_url) {
172 scoped_refptr<const Extension> extension =
173 CreateExtensionWithIdAndUpdateUrl(Manifest::UNPACKED, id, update_url);
174 return extension_management_->GetBlockedAPIPermissions(extension.get());
175 }
176
177 // Create an extension with specified |location|, |id| and |update_url|.
178 scoped_refptr<const Extension> CreateExtensionWithIdAndUpdateUrl(
179 Manifest::Location location,
180 const std::string& id,
181 const std::string& update_url) {
182 base::DictionaryValue manifest_dict;
183 manifest_dict.SetString(manifest_keys::kName, "test");
184 manifest_dict.SetString(manifest_keys::kVersion, "0.1");
185 manifest_dict.SetString(manifest_keys::kUpdateURL, update_url);
186 std::string error;
187 scoped_refptr<const Extension> extension =
188 Extension::Create(base::FilePath(), location, manifest_dict,
189 Extension::NO_FLAGS, id, &error);
190 CHECK(extension.get()) << error;
191 return extension;
192 }
193
129 scoped_ptr<TestingPrefServiceSimple> pref_service_; 194 scoped_ptr<TestingPrefServiceSimple> pref_service_;
130 scoped_ptr<ExtensionManagement> extension_management_; 195 scoped_ptr<ExtensionManagement> extension_management_;
131 }; 196 };
132 197
133 class ExtensionAdminPolicyTest : public ExtensionManagementServiceTest { 198 class ExtensionAdminPolicyTest : public ExtensionManagementServiceTest {
134 public: 199 public:
135 ExtensionAdminPolicyTest() {} 200 ExtensionAdminPolicyTest() {}
136 ~ExtensionAdminPolicyTest() override {} 201 ~ExtensionAdminPolicyTest() override {}
137 202
138 void SetUpPolicyProvider() { 203 void SetUpPolicyProvider() {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); 325 Manifest::TYPE_USER_SCRIPT) != allowed_types.end());
261 } 326 }
262 327
263 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy 328 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy
264 // is handled well. 329 // is handled well.
265 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { 330 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) {
266 base::ListValue denied_list_pref; 331 base::ListValue denied_list_pref;
267 denied_list_pref.AppendString(kTargetExtension); 332 denied_list_pref.AppendString(kTargetExtension);
268 333
269 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 334 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
270 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 335 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
271 ExtensionManagement::INSTALLATION_BLOCKED); 336 ExtensionManagement::INSTALLATION_BLOCKED);
272 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 337 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
273 ExtensionManagement::INSTALLATION_ALLOWED); 338 ExtensionManagement::INSTALLATION_ALLOWED);
274 } 339 }
275 340
276 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy 341 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy
277 // is handled well. 342 // is handled well.
278 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { 343 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) {
279 base::ListValue denied_list_pref; 344 base::ListValue denied_list_pref;
280 denied_list_pref.AppendString("*"); 345 denied_list_pref.AppendString("*");
281 base::ListValue allowed_list_pref; 346 base::ListValue allowed_list_pref;
282 allowed_list_pref.AppendString(kTargetExtension); 347 allowed_list_pref.AppendString(kTargetExtension);
283 348
284 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 349 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
285 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 350 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
286 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 351 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
287 ExtensionManagement::INSTALLATION_ALLOWED); 352 ExtensionManagement::INSTALLATION_ALLOWED);
288 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 353 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
289 ExtensionManagement::INSTALLATION_BLOCKED); 354 ExtensionManagement::INSTALLATION_BLOCKED);
290 355
291 // Verify that install whitelist preference set by user is ignored. 356 // Verify that install whitelist preference set by user is ignored.
292 RemovePref(true, pref_names::kInstallAllowList); 357 RemovePref(true, pref_names::kInstallAllowList);
293 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 358 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
294 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 359 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
295 ExtensionManagement::INSTALLATION_BLOCKED); 360 ExtensionManagement::INSTALLATION_BLOCKED);
296 } 361 }
297 362
298 // Verify that preference controlled by legacy ExtensionInstallForcelist policy 363 // Verify that preference controlled by legacy ExtensionInstallForcelist policy
299 // is handled well. 364 // is handled well.
300 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { 365 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) {
301 base::DictionaryValue forced_list_pref; 366 base::DictionaryValue forced_list_pref;
302 ExternalPolicyLoader::AddExtension( 367 ExternalPolicyLoader::AddExtension(
303 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); 368 &forced_list_pref, kTargetExtension, kExampleUpdateUrl);
304 369
305 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); 370 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
306 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 371 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
307 ExtensionManagement::INSTALLATION_FORCED); 372 ExtensionManagement::INSTALLATION_FORCED);
308 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); 373 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl);
309 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 374 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
310 ExtensionManagement::INSTALLATION_ALLOWED); 375 ExtensionManagement::INSTALLATION_ALLOWED);
311 376
312 // Verify that install forcelist preference set by user is ignored. 377 // Verify that install forcelist preference set by user is ignored.
313 RemovePref(true, pref_names::kInstallForceList); 378 RemovePref(true, pref_names::kInstallForceList);
314 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); 379 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
315 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 380 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
316 ExtensionManagement::INSTALLATION_ALLOWED); 381 ExtensionManagement::INSTALLATION_ALLOWED);
317 } 382 }
318 383
319 // Tests parsing of new dictionary preference. 384 // Tests parsing of new dictionary preference.
320 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { 385 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) {
321 SetExampleDictPref(); 386 SetExampleDictPref();
322 387
323 // Verifies the installation mode settings. 388 // Verifies the installation mode settings.
324 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 389 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
325 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 390 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
326 ExtensionManagement::INSTALLATION_ALLOWED); 391 ExtensionManagement::INSTALLATION_ALLOWED);
327 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, 392 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
328 ExtensionManagement::INSTALLATION_FORCED); 393 ExtensionManagement::INSTALLATION_FORCED);
329 EXPECT_EQ(ReadById(kTargetExtension2)->update_url, kExampleUpdateUrl); 394 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension2, kExampleUpdateUrl);
330 EXPECT_EQ(ReadById(kTargetExtension3)->installation_mode, 395 EXPECT_EQ(GetInstallationModeById(kTargetExtension3),
331 ExtensionManagement::INSTALLATION_RECOMMENDED); 396 ExtensionManagement::INSTALLATION_RECOMMENDED);
332 EXPECT_EQ(ReadById(kTargetExtension3)->update_url, kExampleUpdateUrl); 397 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension3, kExampleUpdateUrl);
333 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 398 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
334 ExtensionManagement::INSTALLATION_BLOCKED); 399 ExtensionManagement::INSTALLATION_BLOCKED);
400 EXPECT_EQ(GetInstallationModeByUpdateUrl(kExampleUpdateUrl),
401 ExtensionManagement::INSTALLATION_ALLOWED);
335 402
336 // Verifies global settings. 403 // Verifies global settings.
337 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 404 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
338 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; 405 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources;
339 EXPECT_EQ(allowed_sites.size(), 1u); 406 EXPECT_EQ(allowed_sites.size(), 1u);
340 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry"))); 407 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry")));
341 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry"))); 408 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry")));
342 409
343 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); 410 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
344 const std::vector<Manifest::Type>& allowed_types = 411 const std::vector<Manifest::Type>& allowed_types =
345 ReadGlobalSettings()->allowed_types; 412 ReadGlobalSettings()->allowed_types;
346 EXPECT_EQ(allowed_types.size(), 2u); 413 EXPECT_EQ(allowed_types.size(), 2u);
347 EXPECT_TRUE(std::find(allowed_types.begin(), 414 EXPECT_TRUE(std::find(allowed_types.begin(),
348 allowed_types.end(), 415 allowed_types.end(),
349 Manifest::TYPE_THEME) != allowed_types.end()); 416 Manifest::TYPE_THEME) != allowed_types.end());
350 EXPECT_TRUE(std::find(allowed_types.begin(), 417 EXPECT_TRUE(std::find(allowed_types.begin(),
351 allowed_types.end(), 418 allowed_types.end(),
352 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); 419 Manifest::TYPE_USER_SCRIPT) != allowed_types.end());
353 420
354 // Verifies blocked permission list settings. 421 // Verifies blocked permission list settings.
355 APIPermissionSet api_permission_set; 422 APIPermissionSet api_permission_set;
356 api_permission_set.clear(); 423 api_permission_set.clear();
357 api_permission_set.insert(APIPermission::kFileSystem); 424 api_permission_set.insert(APIPermission::kFileSystem);
358 api_permission_set.insert(APIPermission::kDownloads); 425 api_permission_set.insert(APIPermission::kDownloads);
359 EXPECT_EQ(api_permission_set, 426 EXPECT_EQ(api_permission_set,
360 extension_management_->GetBlockedAPIPermissions(kOtherExtension)); 427 GetBlockedAPIPermissionsById(kNonExistingExtension));
361 428
362 api_permission_set.clear(); 429 api_permission_set.clear();
363 api_permission_set.insert(APIPermission::kFileSystem); 430 api_permission_set.insert(APIPermission::kFileSystem);
364 api_permission_set.insert(APIPermission::kDownloads); 431 api_permission_set.insert(APIPermission::kDownloads);
365 api_permission_set.insert(APIPermission::kBookmark); 432 api_permission_set.insert(APIPermission::kBookmark);
366 EXPECT_EQ(api_permission_set, 433 EXPECT_EQ(api_permission_set, GetBlockedAPIPermissionsById(kTargetExtension));
367 extension_management_->GetBlockedAPIPermissions(kTargetExtension));
368 434
369 api_permission_set.clear(); 435 api_permission_set.clear();
370 api_permission_set.insert(APIPermission::kDownloads); 436 api_permission_set.insert(APIPermission::kDownloads);
371 EXPECT_EQ(api_permission_set, 437 EXPECT_EQ(api_permission_set,
372 extension_management_->GetBlockedAPIPermissions(kTargetExtension2)); 438 GetBlockedAPIPermissionsById(kTargetExtension2));
373 439
374 api_permission_set.clear(); 440 api_permission_set.clear();
375 api_permission_set.insert(APIPermission::kFileSystem); 441 api_permission_set.insert(APIPermission::kFileSystem);
376 api_permission_set.insert(APIPermission::kHistory); 442 api_permission_set.insert(APIPermission::kHistory);
377 EXPECT_EQ(api_permission_set, 443 EXPECT_EQ(api_permission_set,
378 extension_management_->GetBlockedAPIPermissions(kTargetExtension3)); 444 GetBlockedAPIPermissionsById(kTargetExtension3));
445
446 api_permission_set.clear();
447 api_permission_set.insert(APIPermission::kFileSystem);
448 api_permission_set.insert(APIPermission::kBookmark);
449 EXPECT_EQ(api_permission_set,
450 GetBlockedAPIPermissionsByUpdateUrl(kExampleUpdateUrl));
451 }
452
453 // Tests the handling of installation mode in case it's specified in both
454 // per-extension and per-update-url settings.
455 TEST_F(ExtensionManagementServiceTest, InstallationModeConflictionHandling) {
Joao da Silva 2014/11/04 14:06:09 InstallationModeConflicHandling
binjin 2014/11/05 12:52:42 Done.
456 SetExampleDictPref();
457
458 // Per-extension installation mode settings should always override
459 // per-update-url settings.
460 EXPECT_EQ(GetInstallationMode(kTargetExtension, kExampleUpdateUrl),
461 ExtensionManagement::INSTALLATION_ALLOWED);
462 EXPECT_EQ(GetInstallationMode(kTargetExtension2, kExampleUpdateUrl),
463 ExtensionManagement::INSTALLATION_FORCED);
464 EXPECT_EQ(GetInstallationMode(kTargetExtension3, kExampleUpdateUrl),
465 ExtensionManagement::INSTALLATION_RECOMMENDED);
466 }
467
468 // Tests the handling of blocked permissions in case it's specified in both
469 // per-extension and per-update-url settings.
470 TEST_F(ExtensionManagementServiceTest, BlockedPermissionsConflictionHandling) {
Joao da Silva 2014/11/04 14:06:10 BlockedPermissionsConflictHandling
binjin 2014/11/05 12:52:42 Done.
471 SetExampleDictPref();
472
473 // Both settings should be enforced.
474 APIPermissionSet blocked_permissions_for_update_url;
475 blocked_permissions_for_update_url.insert(APIPermission::kFileSystem);
476 blocked_permissions_for_update_url.insert(APIPermission::kBookmark);
477
478 APIPermissionSet api_permission_set;
479
480 api_permission_set = blocked_permissions_for_update_url;
481 api_permission_set.insert(APIPermission::kFileSystem);
482 api_permission_set.insert(APIPermission::kDownloads);
483 api_permission_set.insert(APIPermission::kBookmark);
484 EXPECT_EQ(api_permission_set,
485 GetBlockedAPIPermissions(kTargetExtension, kExampleUpdateUrl));
486
487 api_permission_set = blocked_permissions_for_update_url;
488 api_permission_set.insert(APIPermission::kDownloads);
489 EXPECT_EQ(api_permission_set,
490 GetBlockedAPIPermissions(kTargetExtension2, kExampleUpdateUrl));
491
492 api_permission_set = blocked_permissions_for_update_url;
493 api_permission_set.insert(APIPermission::kFileSystem);
494 api_permission_set.insert(APIPermission::kHistory);
495 EXPECT_EQ(api_permission_set,
496 GetBlockedAPIPermissions(kTargetExtension3, kExampleUpdateUrl));
379 } 497 }
380 498
381 // Tests functionality of new preference as to deprecate legacy 499 // Tests functionality of new preference as to deprecate legacy
382 // ExtensionInstallSources policy. 500 // ExtensionInstallSources policy.
383 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { 501 TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
384 // Set the legacy preference, and verifies that it works. 502 // Set the legacy preference, and verifies that it works.
385 base::ListValue allowed_sites_pref; 503 base::ListValue allowed_sites_pref;
386 allowed_sites_pref.AppendString("https://www.example.com/foo"); 504 allowed_sites_pref.AppendString("https://www.example.com/foo");
387 SetPref( 505 SetPref(
388 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); 506 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 560
443 // Tests functionality of new preference as to deprecate legacy 561 // Tests functionality of new preference as to deprecate legacy
444 // ExtensionInstallBlacklist policy. 562 // ExtensionInstallBlacklist policy.
445 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { 563 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) {
446 // Set the new dictionary preference. 564 // Set the new dictionary preference.
447 { 565 {
448 PrefUpdater updater(pref_service_.get()); 566 PrefUpdater updater(pref_service_.get());
449 updater.SetBlacklistedByDefault(false); // Allowed by default. 567 updater.SetBlacklistedByDefault(false); // Allowed by default.
450 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); 568 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false);
451 updater.ClearPerExtensionSettings(kTargetExtension2); 569 updater.ClearPerExtensionSettings(kTargetExtension2);
452 updater.ClearPerExtensionSettings(kOtherExtension);
453 } 570 }
454 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); 571 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
455 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 572 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
456 ExtensionManagement::INSTALLATION_BLOCKED); 573 ExtensionManagement::INSTALLATION_BLOCKED);
457 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 574 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
458 ExtensionManagement::INSTALLATION_ALLOWED); 575 ExtensionManagement::INSTALLATION_ALLOWED);
459 576
460 // Set legacy preference. 577 // Set legacy preference.
461 base::ListValue denied_list_pref; 578 base::ListValue denied_list_pref;
462 denied_list_pref.AppendString("*"); 579 denied_list_pref.AppendString("*");
463 denied_list_pref.AppendString(kTargetExtension2); 580 denied_list_pref.AppendString(kTargetExtension2);
464 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 581 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
465 582
466 base::ListValue allowed_list_pref; 583 base::ListValue allowed_list_pref;
467 allowed_list_pref.AppendString(kTargetExtension); 584 allowed_list_pref.AppendString(kTargetExtension);
468 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 585 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
469 586
470 // Verifies that the new one have higher priority over the legacy ones. 587 // Verifies that the new one have higher priority over the legacy ones.
471 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); 588 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
472 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 589 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
473 ExtensionManagement::INSTALLATION_BLOCKED); 590 ExtensionManagement::INSTALLATION_BLOCKED);
474 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, 591 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
475 ExtensionManagement::INSTALLATION_BLOCKED); 592 ExtensionManagement::INSTALLATION_BLOCKED);
476 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 593 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
477 ExtensionManagement::INSTALLATION_ALLOWED); 594 ExtensionManagement::INSTALLATION_ALLOWED);
478 } 595 }
479 596
480 // Tests functionality of new preference as to deprecate legacy 597 // Tests functionality of new preference as to deprecate legacy
481 // ExtensionInstallWhitelist policy. 598 // ExtensionInstallWhitelist policy.
482 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { 599 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) {
483 // Set the new dictionary preference. 600 // Set the new dictionary preference.
484 { 601 {
485 PrefUpdater updater(pref_service_.get()); 602 PrefUpdater updater(pref_service_.get());
486 updater.SetBlacklistedByDefault(true); // Disallowed by default. 603 updater.SetBlacklistedByDefault(true); // Disallowed by default.
487 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); 604 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true);
488 updater.ClearPerExtensionSettings(kTargetExtension2); 605 updater.ClearPerExtensionSettings(kTargetExtension2);
489 updater.ClearPerExtensionSettings(kOtherExtension);
490 } 606 }
491 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 607 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
492 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 608 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
493 ExtensionManagement::INSTALLATION_ALLOWED); 609 ExtensionManagement::INSTALLATION_ALLOWED);
494 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 610 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
495 ExtensionManagement::INSTALLATION_BLOCKED); 611 ExtensionManagement::INSTALLATION_BLOCKED);
496 612
497 // Set legacy preference. 613 // Set legacy preference.
498 base::ListValue denied_list_pref; 614 base::ListValue denied_list_pref;
499 denied_list_pref.AppendString(kTargetExtension); 615 denied_list_pref.AppendString(kTargetExtension);
500 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 616 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
501 617
502 base::ListValue allowed_list_pref; 618 base::ListValue allowed_list_pref;
503 allowed_list_pref.AppendString(kTargetExtension2); 619 allowed_list_pref.AppendString(kTargetExtension2);
504 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); 620 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
505 621
506 // Verifies that the new one have higher priority over the legacy ones. 622 // Verifies that the new one have higher priority over the legacy ones.
507 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 623 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
508 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 624 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
509 ExtensionManagement::INSTALLATION_ALLOWED); 625 ExtensionManagement::INSTALLATION_ALLOWED);
510 EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode, 626 EXPECT_EQ(GetInstallationModeById(kTargetExtension2),
511 ExtensionManagement::INSTALLATION_ALLOWED); 627 ExtensionManagement::INSTALLATION_ALLOWED);
512 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 628 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
513 ExtensionManagement::INSTALLATION_BLOCKED); 629 ExtensionManagement::INSTALLATION_BLOCKED);
514 } 630 }
515 631
516 // Tests functionality of new preference as to deprecate legacy 632 // Tests functionality of new preference as to deprecate legacy
517 // ExtensionInstallForcelist policy. 633 // ExtensionInstallForcelist policy.
518 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { 634 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) {
519 // Set some legacy preferences, to verify that the new one overrides the 635 // Set some legacy preferences, to verify that the new one overrides the
520 // legacy ones. 636 // legacy ones.
521 base::ListValue denied_list_pref; 637 base::ListValue denied_list_pref;
522 denied_list_pref.AppendString(kTargetExtension); 638 denied_list_pref.AppendString(kTargetExtension);
523 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 639 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
524 640
525 // Set the new dictionary preference. 641 // Set the new dictionary preference.
526 { 642 {
527 PrefUpdater updater(pref_service_.get()); 643 PrefUpdater updater(pref_service_.get());
528 updater.SetIndividualExtensionAutoInstalled( 644 updater.SetIndividualExtensionAutoInstalled(
529 kTargetExtension, kExampleUpdateUrl, true); 645 kTargetExtension, kExampleUpdateUrl, true);
530 updater.ClearPerExtensionSettings(kOtherExtension);
531 } 646 }
532 EXPECT_EQ(ReadById(kTargetExtension)->installation_mode, 647 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
533 ExtensionManagement::INSTALLATION_FORCED); 648 ExtensionManagement::INSTALLATION_FORCED);
534 EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl); 649 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl);
535 EXPECT_EQ(ReadById(kOtherExtension)->installation_mode, 650 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
536 ExtensionManagement::INSTALLATION_ALLOWED); 651 ExtensionManagement::INSTALLATION_ALLOWED);
537 } 652 }
538 653
539 // Tests the behavior of IsInstallationExplicitlyAllowed(). 654 // Tests the behavior of IsInstallationExplicitlyAllowed().
540 TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) { 655 TEST_F(ExtensionManagementServiceTest, IsInstallationExplicitlyAllowed) {
541 SetExampleDictPref(); 656 SetExampleDictPref();
542 657
543 // Constant name indicates the installation_mode of extensions in example 658 // Constant name indicates the installation_mode of extensions in example
544 // preference. 659 // preference.
545 const char* allowed = kTargetExtension; 660 const char* allowed = kTargetExtension;
546 const char* forced = kTargetExtension2; 661 const char* forced = kTargetExtension2;
547 const char* recommended = kTargetExtension3; 662 const char* recommended = kTargetExtension3;
548 const char* blocked = kTargetExtension4; 663 const char* blocked = kTargetExtension4;
549 const char* not_specified = kOtherExtension; 664 const char* not_specified = kNonExistingExtension;
550 665
551 // BlacklistedByDefault() is true in example preference. 666 // BlacklistedByDefault() is true in example preference.
552 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed)); 667 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed));
553 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced)); 668 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced));
554 EXPECT_TRUE( 669 EXPECT_TRUE(
555 extension_management_->IsInstallationExplicitlyAllowed(recommended)); 670 extension_management_->IsInstallationExplicitlyAllowed(recommended));
556 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked)); 671 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
557 EXPECT_FALSE( 672 EXPECT_FALSE(
558 extension_management_->IsInstallationExplicitlyAllowed(not_specified)); 673 extension_management_->IsInstallationExplicitlyAllowed(not_specified));
559 674
(...skipping 11 matching lines...) Expand all
571 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked)); 686 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
572 EXPECT_FALSE( 687 EXPECT_FALSE(
573 extension_management_->IsInstallationExplicitlyAllowed(not_specified)); 688 extension_management_->IsInstallationExplicitlyAllowed(not_specified));
574 } 689 }
575 690
576 // Tests the flag value indicating that extensions are blacklisted by default. 691 // Tests the flag value indicating that extensions are blacklisted by default.
577 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { 692 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) {
578 EXPECT_FALSE(BlacklistedByDefault(NULL)); 693 EXPECT_FALSE(BlacklistedByDefault(NULL));
579 694
580 base::ListValue blacklist; 695 base::ListValue blacklist;
581 blacklist.Append(new base::StringValue(kOtherExtension)); 696 blacklist.Append(new base::StringValue(kNonExistingExtension));
582 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); 697 EXPECT_FALSE(BlacklistedByDefault(&blacklist));
583 blacklist.Append(new base::StringValue("*")); 698 blacklist.Append(new base::StringValue("*"));
584 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 699 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
585 700
586 blacklist.Clear(); 701 blacklist.Clear();
587 blacklist.Append(new base::StringValue("*")); 702 blacklist.Append(new base::StringValue("*"));
588 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 703 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
589 } 704 }
590 705
591 // Tests UserMayLoad for required extensions. 706 // Tests UserMayLoad for required extensions.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 EXPECT_FALSE(error.empty()); 830 EXPECT_FALSE(error.empty());
716 831
717 CreateExtension(Manifest::INTERNAL); 832 CreateExtension(Manifest::INTERNAL);
718 error.clear(); 833 error.clear();
719 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); 834 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL));
720 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); 835 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error));
721 EXPECT_TRUE(error.empty()); 836 EXPECT_TRUE(error.empty());
722 } 837 }
723 838
724 } // namespace extensions 839 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698