OLD | NEW |
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 "chrome/browser/extensions/extension_management.h" | 5 #include "chrome/browser/extensions/extension_management.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList); | 94 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList); |
95 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList); | 95 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList); |
96 pref_service_->registry()->RegisterDictionaryPref( | 96 pref_service_->registry()->RegisterDictionaryPref( |
97 pref_names::kInstallForceList); | 97 pref_names::kInstallForceList); |
98 pref_service_->registry()->RegisterDictionaryPref( | 98 pref_service_->registry()->RegisterDictionaryPref( |
99 pref_names::kExtensionManagement); | 99 pref_names::kExtensionManagement); |
100 extension_management_.reset( | 100 extension_management_.reset( |
101 new ExtensionManagement(pref_service_.get(), false)); | 101 new ExtensionManagement(pref_service_.get(), false)); |
102 } | 102 } |
103 | 103 |
104 void SetPref(bool managed, const char* path, base::Value* value) { | 104 void SetPref(bool managed, |
| 105 const char* path, |
| 106 std::unique_ptr<base::Value> value) { |
105 if (managed) | 107 if (managed) |
106 pref_service_->SetManagedPref(path, value); | 108 pref_service_->SetManagedPref(path, std::move(value)); |
107 else | 109 else |
108 pref_service_->SetUserPref(path, value); | 110 pref_service_->SetUserPref(path, std::move(value)); |
109 } | 111 } |
110 | 112 |
111 void RemovePref(bool managed, const char* path) { | 113 void RemovePref(bool managed, const char* path) { |
112 if (managed) | 114 if (managed) |
113 pref_service_->RemoveManagedPref(path); | 115 pref_service_->RemoveManagedPref(path); |
114 else | 116 else |
115 pref_service_->RemoveUserPref(path); | 117 pref_service_->RemoveUserPref(path); |
116 } | 118 } |
117 | 119 |
118 const internal::GlobalSettings* ReadGlobalSettings() { | 120 const internal::GlobalSettings* ReadGlobalSettings() { |
(...skipping 30 matching lines...) Expand all Loading... |
149 return GetBlockedAPIPermissions(kNonExistingExtension, update_url); | 151 return GetBlockedAPIPermissions(kNonExistingExtension, update_url); |
150 } | 152 } |
151 | 153 |
152 void SetExampleDictPref() { | 154 void SetExampleDictPref() { |
153 std::string error_msg; | 155 std::string error_msg; |
154 std::unique_ptr<base::Value> parsed = base::JSONReader::ReadAndReturnError( | 156 std::unique_ptr<base::Value> parsed = base::JSONReader::ReadAndReturnError( |
155 kExampleDictPreference, | 157 kExampleDictPreference, |
156 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); | 158 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); |
157 ASSERT_TRUE(parsed && parsed->IsType(base::Value::Type::DICTIONARY)) | 159 ASSERT_TRUE(parsed && parsed->IsType(base::Value::Type::DICTIONARY)) |
158 << error_msg; | 160 << error_msg; |
159 SetPref(true, pref_names::kExtensionManagement, parsed.release()); | 161 SetPref(true, pref_names::kExtensionManagement, std::move(parsed)); |
160 } | 162 } |
161 | 163 |
162 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and | 164 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and |
163 // |update_url| are used to construct an Extension for testing. | 165 // |update_url| are used to construct an Extension for testing. |
164 ExtensionManagement::InstallationMode GetInstallationMode( | 166 ExtensionManagement::InstallationMode GetInstallationMode( |
165 const std::string& id, | 167 const std::string& id, |
166 const std::string& update_url) { | 168 const std::string& update_url) { |
167 scoped_refptr<const Extension> extension = | 169 scoped_refptr<const Extension> extension = |
168 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url); | 170 CreateExtension(Manifest::UNPACKED, "0.1", id, update_url); |
169 return extension_management_->GetInstallationMode(extension.get()); | 171 return extension_management_->GetInstallationMode(extension.get()); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 265 |
264 protected: | 266 protected: |
265 std::unique_ptr<StandardManagementPolicyProvider> provider_; | 267 std::unique_ptr<StandardManagementPolicyProvider> provider_; |
266 scoped_refptr<Extension> extension_; | 268 scoped_refptr<Extension> extension_; |
267 }; | 269 }; |
268 | 270 |
269 bool ExtensionAdminPolicyTest::BlacklistedByDefault( | 271 bool ExtensionAdminPolicyTest::BlacklistedByDefault( |
270 const base::ListValue* blacklist) { | 272 const base::ListValue* blacklist) { |
271 SetUpPolicyProvider(); | 273 SetUpPolicyProvider(); |
272 if (blacklist) | 274 if (blacklist) |
273 SetPref(true, pref_names::kInstallDenyList, blacklist->DeepCopy()); | 275 SetPref(true, pref_names::kInstallDenyList, blacklist->CreateDeepCopy()); |
274 return extension_management_->BlacklistedByDefault(); | 276 return extension_management_->BlacklistedByDefault(); |
275 } | 277 } |
276 | 278 |
277 bool ExtensionAdminPolicyTest::UserMayLoad( | 279 bool ExtensionAdminPolicyTest::UserMayLoad( |
278 const base::ListValue* blacklist, | 280 const base::ListValue* blacklist, |
279 const base::ListValue* whitelist, | 281 const base::ListValue* whitelist, |
280 const base::DictionaryValue* forcelist, | 282 const base::DictionaryValue* forcelist, |
281 const base::ListValue* allowed_types, | 283 const base::ListValue* allowed_types, |
282 const Extension* extension, | 284 const Extension* extension, |
283 base::string16* error) { | 285 base::string16* error) { |
284 SetUpPolicyProvider(); | 286 SetUpPolicyProvider(); |
285 if (blacklist) | 287 if (blacklist) |
286 SetPref(true, pref_names::kInstallDenyList, blacklist->DeepCopy()); | 288 SetPref(true, pref_names::kInstallDenyList, blacklist->CreateDeepCopy()); |
287 if (whitelist) | 289 if (whitelist) |
288 SetPref(true, pref_names::kInstallAllowList, whitelist->DeepCopy()); | 290 SetPref(true, pref_names::kInstallAllowList, whitelist->CreateDeepCopy()); |
289 if (forcelist) | 291 if (forcelist) |
290 SetPref(true, pref_names::kInstallForceList, forcelist->DeepCopy()); | 292 SetPref(true, pref_names::kInstallForceList, forcelist->CreateDeepCopy()); |
291 if (allowed_types) | 293 if (allowed_types) |
292 SetPref(true, pref_names::kAllowedTypes, allowed_types->DeepCopy()); | 294 SetPref(true, pref_names::kAllowedTypes, allowed_types->CreateDeepCopy()); |
293 return provider_->UserMayLoad(extension, error); | 295 return provider_->UserMayLoad(extension, error); |
294 } | 296 } |
295 | 297 |
296 bool ExtensionAdminPolicyTest::UserMayModifySettings(const Extension* extension, | 298 bool ExtensionAdminPolicyTest::UserMayModifySettings(const Extension* extension, |
297 base::string16* error) { | 299 base::string16* error) { |
298 SetUpPolicyProvider(); | 300 SetUpPolicyProvider(); |
299 return provider_->UserMayModifySettings(extension, error); | 301 return provider_->UserMayModifySettings(extension, error); |
300 } | 302 } |
301 | 303 |
302 bool ExtensionAdminPolicyTest::MustRemainEnabled(const Extension* extension, | 304 bool ExtensionAdminPolicyTest::MustRemainEnabled(const Extension* extension, |
303 base::string16* error) { | 305 base::string16* error) { |
304 SetUpPolicyProvider(); | 306 SetUpPolicyProvider(); |
305 return provider_->MustRemainEnabled(extension, error); | 307 return provider_->MustRemainEnabled(extension, error); |
306 } | 308 } |
307 | 309 |
308 // Verify that preference controlled by legacy ExtensionInstallSources policy is | 310 // Verify that preference controlled by legacy ExtensionInstallSources policy is |
309 // handled well. | 311 // handled well. |
310 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) { | 312 TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) { |
311 base::ListValue allowed_sites_pref; | 313 base::ListValue allowed_sites_pref; |
312 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 314 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
313 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); | 315 allowed_sites_pref.AppendString("https://corp.mycompany.com/*"); |
314 SetPref( | 316 SetPref(true, pref_names::kAllowedInstallSites, |
315 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 317 allowed_sites_pref.CreateDeepCopy()); |
316 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; | 318 const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources; |
317 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); | 319 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
318 EXPECT_FALSE(allowed_sites.is_empty()); | 320 EXPECT_FALSE(allowed_sites.is_empty()); |
319 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); | 321 EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo"))); |
320 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); | 322 EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar"))); |
321 EXPECT_TRUE( | 323 EXPECT_TRUE( |
322 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); | 324 allowed_sites.MatchesURL(GURL("https://corp.mycompany.com/entry"))); |
323 EXPECT_FALSE( | 325 EXPECT_FALSE( |
324 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); | 326 allowed_sites.MatchesURL(GURL("https://www.mycompany.com/entry"))); |
325 } | 327 } |
326 | 328 |
327 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is | 329 // Verify that preference controlled by legacy ExtensionAllowedTypes policy is |
328 // handled well. | 330 // handled well. |
329 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { | 331 TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) { |
330 base::ListValue allowed_types_pref; | 332 base::ListValue allowed_types_pref; |
331 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); | 333 allowed_types_pref.AppendInteger(Manifest::TYPE_THEME); |
332 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 334 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
333 | 335 |
334 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 336 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.CreateDeepCopy()); |
335 const std::vector<Manifest::Type>& allowed_types = | 337 const std::vector<Manifest::Type>& allowed_types = |
336 ReadGlobalSettings()->allowed_types; | 338 ReadGlobalSettings()->allowed_types; |
337 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); | 339 ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
338 EXPECT_EQ(allowed_types.size(), 2u); | 340 EXPECT_EQ(allowed_types.size(), 2u); |
339 EXPECT_FALSE(std::find(allowed_types.begin(), | 341 EXPECT_FALSE(std::find(allowed_types.begin(), |
340 allowed_types.end(), | 342 allowed_types.end(), |
341 Manifest::TYPE_EXTENSION) != allowed_types.end()); | 343 Manifest::TYPE_EXTENSION) != allowed_types.end()); |
342 EXPECT_TRUE(std::find(allowed_types.begin(), | 344 EXPECT_TRUE(std::find(allowed_types.begin(), |
343 allowed_types.end(), | 345 allowed_types.end(), |
344 Manifest::TYPE_THEME) != allowed_types.end()); | 346 Manifest::TYPE_THEME) != allowed_types.end()); |
345 EXPECT_TRUE(std::find(allowed_types.begin(), | 347 EXPECT_TRUE(std::find(allowed_types.begin(), |
346 allowed_types.end(), | 348 allowed_types.end(), |
347 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); | 349 Manifest::TYPE_USER_SCRIPT) != allowed_types.end()); |
348 } | 350 } |
349 | 351 |
350 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy | 352 // Verify that preference controlled by legacy ExtensionInstallBlacklist policy |
351 // is handled well. | 353 // is handled well. |
352 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { | 354 TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) { |
353 base::ListValue denied_list_pref; | 355 base::ListValue denied_list_pref; |
354 denied_list_pref.AppendString(kTargetExtension); | 356 denied_list_pref.AppendString(kTargetExtension); |
355 | 357 |
356 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 358 SetPref(true, pref_names::kInstallDenyList, |
| 359 denied_list_pref.CreateDeepCopy()); |
357 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 360 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
358 ExtensionManagement::INSTALLATION_BLOCKED); | 361 ExtensionManagement::INSTALLATION_BLOCKED); |
359 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 362 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
360 ExtensionManagement::INSTALLATION_ALLOWED); | 363 ExtensionManagement::INSTALLATION_ALLOWED); |
361 } | 364 } |
362 | 365 |
363 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy | 366 // Verify that preference controlled by legacy ExtensionInstallWhitelist policy |
364 // is handled well. | 367 // is handled well. |
365 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { | 368 TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) { |
366 base::ListValue denied_list_pref; | 369 base::ListValue denied_list_pref; |
367 denied_list_pref.AppendString("*"); | 370 denied_list_pref.AppendString("*"); |
368 base::ListValue allowed_list_pref; | 371 base::ListValue allowed_list_pref; |
369 allowed_list_pref.AppendString(kTargetExtension); | 372 allowed_list_pref.AppendString(kTargetExtension); |
370 | 373 |
371 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 374 SetPref(true, pref_names::kInstallDenyList, |
372 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 375 denied_list_pref.CreateDeepCopy()); |
| 376 SetPref(true, pref_names::kInstallAllowList, |
| 377 allowed_list_pref.CreateDeepCopy()); |
373 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 378 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
374 ExtensionManagement::INSTALLATION_ALLOWED); | 379 ExtensionManagement::INSTALLATION_ALLOWED); |
375 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 380 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
376 ExtensionManagement::INSTALLATION_BLOCKED); | 381 ExtensionManagement::INSTALLATION_BLOCKED); |
377 | 382 |
378 // Verify that install whitelist preference set by user is ignored. | 383 // Verify that install whitelist preference set by user is ignored. |
379 RemovePref(true, pref_names::kInstallAllowList); | 384 RemovePref(true, pref_names::kInstallAllowList); |
380 SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 385 SetPref(false, pref_names::kInstallAllowList, |
| 386 allowed_list_pref.CreateDeepCopy()); |
381 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 387 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
382 ExtensionManagement::INSTALLATION_BLOCKED); | 388 ExtensionManagement::INSTALLATION_BLOCKED); |
383 } | 389 } |
384 | 390 |
385 // Verify that preference controlled by legacy ExtensionInstallForcelist policy | 391 // Verify that preference controlled by legacy ExtensionInstallForcelist policy |
386 // is handled well. | 392 // is handled well. |
387 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { | 393 TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) { |
388 base::DictionaryValue forced_list_pref; | 394 base::DictionaryValue forced_list_pref; |
389 ExternalPolicyLoader::AddExtension( | 395 ExternalPolicyLoader::AddExtension( |
390 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); | 396 &forced_list_pref, kTargetExtension, kExampleUpdateUrl); |
391 | 397 |
392 SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 398 SetPref(true, pref_names::kInstallForceList, |
| 399 forced_list_pref.CreateDeepCopy()); |
393 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 400 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
394 ExtensionManagement::INSTALLATION_FORCED); | 401 ExtensionManagement::INSTALLATION_FORCED); |
395 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl); | 402 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl); |
396 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 403 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
397 ExtensionManagement::INSTALLATION_ALLOWED); | 404 ExtensionManagement::INSTALLATION_ALLOWED); |
398 | 405 |
399 // Verify that install forcelist preference set by user is ignored. | 406 // Verify that install forcelist preference set by user is ignored. |
400 RemovePref(true, pref_names::kInstallForceList); | 407 RemovePref(true, pref_names::kInstallForceList); |
401 SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy()); | 408 SetPref(false, pref_names::kInstallForceList, |
| 409 forced_list_pref.CreateDeepCopy()); |
402 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 410 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
403 ExtensionManagement::INSTALLATION_ALLOWED); | 411 ExtensionManagement::INSTALLATION_ALLOWED); |
404 } | 412 } |
405 | 413 |
406 // Tests parsing of new dictionary preference. | 414 // Tests parsing of new dictionary preference. |
407 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { | 415 TEST_F(ExtensionManagementServiceTest, PreferenceParsing) { |
408 SetExampleDictPref(); | 416 SetExampleDictPref(); |
409 | 417 |
410 // Verifies the installation mode settings. | 418 // Verifies the installation mode settings. |
411 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 419 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.1")); | 548 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.1")); |
541 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "4.0")); | 549 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "4.0")); |
542 } | 550 } |
543 | 551 |
544 // Tests functionality of new preference as to deprecate legacy | 552 // Tests functionality of new preference as to deprecate legacy |
545 // ExtensionInstallSources policy. | 553 // ExtensionInstallSources policy. |
546 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { | 554 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { |
547 // Set the legacy preference, and verifies that it works. | 555 // Set the legacy preference, and verifies that it works. |
548 base::ListValue allowed_sites_pref; | 556 base::ListValue allowed_sites_pref; |
549 allowed_sites_pref.AppendString("https://www.example.com/foo"); | 557 allowed_sites_pref.AppendString("https://www.example.com/foo"); |
550 SetPref( | 558 SetPref(true, pref_names::kAllowedInstallSites, |
551 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); | 559 allowed_sites_pref.CreateDeepCopy()); |
552 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); | 560 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); |
553 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( | 561 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( |
554 GURL("https://www.example.com/foo"))); | 562 GURL("https://www.example.com/foo"))); |
555 | 563 |
556 // Set the new dictionary preference. | 564 // Set the new dictionary preference. |
557 { | 565 { |
558 PrefUpdater updater(pref_service_.get()); | 566 PrefUpdater updater(pref_service_.get()); |
559 updater.ClearInstallSources(); | 567 updater.ClearInstallSources(); |
560 } | 568 } |
561 // Verifies that the new one overrides the legacy ones. | 569 // Verifies that the new one overrides the legacy ones. |
(...skipping 10 matching lines...) Expand all Loading... |
572 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( | 580 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( |
573 GURL("https://corp.mycompany.com/entry"))); | 581 GURL("https://corp.mycompany.com/entry"))); |
574 } | 582 } |
575 | 583 |
576 // Tests functionality of new preference as to deprecate legacy | 584 // Tests functionality of new preference as to deprecate legacy |
577 // ExtensionAllowedTypes policy. | 585 // ExtensionAllowedTypes policy. |
578 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { | 586 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { |
579 // Set the legacy preference, and verifies that it works. | 587 // Set the legacy preference, and verifies that it works. |
580 base::ListValue allowed_types_pref; | 588 base::ListValue allowed_types_pref; |
581 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); | 589 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); |
582 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); | 590 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.CreateDeepCopy()); |
583 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); | 591 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); |
584 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); | 592 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); |
585 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT); | 593 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT); |
586 | 594 |
587 // Set the new dictionary preference. | 595 // Set the new dictionary preference. |
588 { | 596 { |
589 PrefUpdater updater(pref_service_.get()); | 597 PrefUpdater updater(pref_service_.get()); |
590 updater.ClearAllowedTypes(); | 598 updater.ClearAllowedTypes(); |
591 } | 599 } |
592 // Verifies that the new one overrides the legacy ones. | 600 // Verifies that the new one overrides the legacy ones. |
(...skipping 23 matching lines...) Expand all Loading... |
616 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); | 624 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); |
617 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 625 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
618 ExtensionManagement::INSTALLATION_BLOCKED); | 626 ExtensionManagement::INSTALLATION_BLOCKED); |
619 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 627 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
620 ExtensionManagement::INSTALLATION_ALLOWED); | 628 ExtensionManagement::INSTALLATION_ALLOWED); |
621 | 629 |
622 // Set legacy preference. | 630 // Set legacy preference. |
623 base::ListValue denied_list_pref; | 631 base::ListValue denied_list_pref; |
624 denied_list_pref.AppendString("*"); | 632 denied_list_pref.AppendString("*"); |
625 denied_list_pref.AppendString(kTargetExtension2); | 633 denied_list_pref.AppendString(kTargetExtension2); |
626 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 634 SetPref(true, pref_names::kInstallDenyList, |
| 635 denied_list_pref.CreateDeepCopy()); |
627 | 636 |
628 base::ListValue allowed_list_pref; | 637 base::ListValue allowed_list_pref; |
629 allowed_list_pref.AppendString(kTargetExtension); | 638 allowed_list_pref.AppendString(kTargetExtension); |
630 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 639 SetPref(true, pref_names::kInstallAllowList, |
| 640 allowed_list_pref.CreateDeepCopy()); |
631 | 641 |
632 // Verifies that the new one have higher priority over the legacy ones. | 642 // Verifies that the new one have higher priority over the legacy ones. |
633 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); | 643 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); |
634 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 644 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
635 ExtensionManagement::INSTALLATION_BLOCKED); | 645 ExtensionManagement::INSTALLATION_BLOCKED); |
636 EXPECT_EQ(GetInstallationModeById(kTargetExtension2), | 646 EXPECT_EQ(GetInstallationModeById(kTargetExtension2), |
637 ExtensionManagement::INSTALLATION_BLOCKED); | 647 ExtensionManagement::INSTALLATION_BLOCKED); |
638 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 648 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
639 ExtensionManagement::INSTALLATION_ALLOWED); | 649 ExtensionManagement::INSTALLATION_ALLOWED); |
640 } | 650 } |
(...skipping 10 matching lines...) Expand all Loading... |
651 } | 661 } |
652 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 662 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
653 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 663 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
654 ExtensionManagement::INSTALLATION_ALLOWED); | 664 ExtensionManagement::INSTALLATION_ALLOWED); |
655 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 665 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
656 ExtensionManagement::INSTALLATION_BLOCKED); | 666 ExtensionManagement::INSTALLATION_BLOCKED); |
657 | 667 |
658 // Set legacy preference. | 668 // Set legacy preference. |
659 base::ListValue denied_list_pref; | 669 base::ListValue denied_list_pref; |
660 denied_list_pref.AppendString(kTargetExtension); | 670 denied_list_pref.AppendString(kTargetExtension); |
661 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 671 SetPref(true, pref_names::kInstallDenyList, |
| 672 denied_list_pref.CreateDeepCopy()); |
662 | 673 |
663 base::ListValue allowed_list_pref; | 674 base::ListValue allowed_list_pref; |
664 allowed_list_pref.AppendString(kTargetExtension2); | 675 allowed_list_pref.AppendString(kTargetExtension2); |
665 SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy()); | 676 SetPref(true, pref_names::kInstallAllowList, |
| 677 allowed_list_pref.CreateDeepCopy()); |
666 | 678 |
667 // Verifies that the new one have higher priority over the legacy ones. | 679 // Verifies that the new one have higher priority over the legacy ones. |
668 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); | 680 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); |
669 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 681 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
670 ExtensionManagement::INSTALLATION_ALLOWED); | 682 ExtensionManagement::INSTALLATION_ALLOWED); |
671 EXPECT_EQ(GetInstallationModeById(kTargetExtension2), | 683 EXPECT_EQ(GetInstallationModeById(kTargetExtension2), |
672 ExtensionManagement::INSTALLATION_ALLOWED); | 684 ExtensionManagement::INSTALLATION_ALLOWED); |
673 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), | 685 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), |
674 ExtensionManagement::INSTALLATION_BLOCKED); | 686 ExtensionManagement::INSTALLATION_BLOCKED); |
675 } | 687 } |
676 | 688 |
677 // Tests functionality of new preference as to deprecate legacy | 689 // Tests functionality of new preference as to deprecate legacy |
678 // ExtensionInstallForcelist policy. | 690 // ExtensionInstallForcelist policy. |
679 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { | 691 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { |
680 // Set some legacy preferences, to verify that the new one overrides the | 692 // Set some legacy preferences, to verify that the new one overrides the |
681 // legacy ones. | 693 // legacy ones. |
682 base::ListValue denied_list_pref; | 694 base::ListValue denied_list_pref; |
683 denied_list_pref.AppendString(kTargetExtension); | 695 denied_list_pref.AppendString(kTargetExtension); |
684 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); | 696 SetPref(true, pref_names::kInstallDenyList, |
| 697 denied_list_pref.CreateDeepCopy()); |
685 | 698 |
686 // Set the new dictionary preference. | 699 // Set the new dictionary preference. |
687 { | 700 { |
688 PrefUpdater updater(pref_service_.get()); | 701 PrefUpdater updater(pref_service_.get()); |
689 updater.SetIndividualExtensionAutoInstalled( | 702 updater.SetIndividualExtensionAutoInstalled( |
690 kTargetExtension, kExampleUpdateUrl, true); | 703 kTargetExtension, kExampleUpdateUrl, true); |
691 } | 704 } |
692 EXPECT_EQ(GetInstallationModeById(kTargetExtension), | 705 EXPECT_EQ(GetInstallationModeById(kTargetExtension), |
693 ExtensionManagement::INSTALLATION_FORCED); | 706 ExtensionManagement::INSTALLATION_FORCED); |
694 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl); | 707 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 EXPECT_FALSE(error.empty()); | 888 EXPECT_FALSE(error.empty()); |
876 | 889 |
877 CreateExtension(Manifest::INTERNAL); | 890 CreateExtension(Manifest::INTERNAL); |
878 error.clear(); | 891 error.clear(); |
879 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); | 892 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); |
880 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); | 893 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); |
881 EXPECT_TRUE(error.empty()); | 894 EXPECT_TRUE(error.empty()); |
882 } | 895 } |
883 | 896 |
884 } // namespace extensions | 897 } // namespace extensions |
OLD | NEW |