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

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

Issue 2144313002: Plumbing for login apps device policy to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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>
11 11
12 #include "base/json/json_parser.h" 12 #include "base/json/json_parser.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/extension_management_internal.h" 14 #include "chrome/browser/extensions/extension_management_internal.h"
15 #include "chrome/browser/extensions/extension_management_test_util.h" 15 #include "chrome/browser/extensions/extension_management_test_util.h"
16 #include "chrome/browser/extensions/external_policy_loader.h" 16 #include "chrome/browser/extensions/external_policy_loader.h"
17 #include "chrome/browser/extensions/standard_management_policy_provider.h" 17 #include "chrome/browser/extensions/standard_management_policy_provider.h"
18 #include "components/prefs/pref_registry_simple.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "components/prefs/testing_pref_service.h" 19 #include "components/sync_preferences/testing_pref_service_syncable.h"
20 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "extensions/browser/pref_names.h" 21 #include "extensions/browser/pref_names.h"
21 #include "extensions/common/manifest.h" 22 #include "extensions/common/manifest.h"
22 #include "extensions/common/manifest_constants.h" 23 #include "extensions/common/manifest_constants.h"
23 #include "extensions/common/permissions/api_permission.h" 24 #include "extensions/common/permissions/api_permission.h"
24 #include "extensions/common/permissions/permissions_info.h" 25 #include "extensions/common/permissions/permissions_info.h"
25 #include "extensions/common/url_pattern.h" 26 #include "extensions/common/url_pattern.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 #include "url/gurl.h" 28 #include "url/gurl.h"
28 29
29 namespace extensions { 30 namespace extensions {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 " \"installation_mode\": \"blocked\"," 70 " \"installation_mode\": \"blocked\","
70 " \"install_sources\": [\"*://foo.com/*\"]," 71 " \"install_sources\": [\"*://foo.com/*\"],"
71 " \"allowed_types\": [\"theme\", \"user_script\"]," 72 " \"allowed_types\": [\"theme\", \"user_script\"],"
72 " \"blocked_permissions\": [\"fileSystem\", \"downloads\"]," 73 " \"blocked_permissions\": [\"fileSystem\", \"downloads\"],"
73 " }," 74 " },"
74 "}"; 75 "}";
75 76
76 } // namespace 77 } // namespace
77 78
78 class ExtensionManagementServiceTest : public testing::Test { 79 class ExtensionManagementServiceTest : public testing::Test {
79 public: 80 protected:
80 typedef ExtensionManagementPrefUpdater<TestingPrefServiceSimple> PrefUpdater; 81 using PrefUpdater = ExtensionManagementPrefUpdater<
82 sync_preferences::TestingPrefServiceSyncable>;
81 83
82 ExtensionManagementServiceTest() {} 84 ExtensionManagementServiceTest() = default;
83 ~ExtensionManagementServiceTest() override {} 85 ~ExtensionManagementServiceTest() override = default;
84 86
85 // testing::Test: 87 // testing::Test:
86 void SetUp() override { InitPrefService(); } 88 void SetUp() override {
87 89 profile_ = base::MakeUnique<TestingProfile>();
88 void InitPrefService() { 90 pref_service_ = profile_->GetTestingPrefService();
89 extension_management_.reset(); 91 extension_management_ =
90 pref_service_.reset(new TestingPrefServiceSimple()); 92 base::MakeUnique<ExtensionManagement>(profile_.get());
91 pref_service_->registry()->RegisterListPref(
92 pref_names::kAllowedInstallSites);
93 pref_service_->registry()->RegisterListPref(pref_names::kAllowedTypes);
94 pref_service_->registry()->RegisterListPref(pref_names::kInstallDenyList);
95 pref_service_->registry()->RegisterListPref(pref_names::kInstallAllowList);
96 pref_service_->registry()->RegisterDictionaryPref(
97 pref_names::kInstallForceList);
98 pref_service_->registry()->RegisterDictionaryPref(
99 pref_names::kExtensionManagement);
100 extension_management_.reset(new ExtensionManagement(pref_service_.get()));
101 } 93 }
102 94
103 void SetPref(bool managed, const char* path, base::Value* value) { 95 void SetPref(bool managed, const char* path, base::Value* value) {
104 if (managed) 96 if (managed)
105 pref_service_->SetManagedPref(path, value); 97 pref_service_->SetManagedPref(path, value);
106 else 98 else
107 pref_service_->SetUserPref(path, value); 99 pref_service_->SetUserPref(path, value);
108 } 100 }
109 101
110 void RemovePref(bool managed, const char* path) { 102 void RemovePref(bool managed, const char* path) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 137
146 APIPermissionSet GetBlockedAPIPermissionsByUpdateUrl( 138 APIPermissionSet GetBlockedAPIPermissionsByUpdateUrl(
147 const std::string& update_url) { 139 const std::string& update_url) {
148 return GetBlockedAPIPermissions(kNonExistingExtension, update_url); 140 return GetBlockedAPIPermissions(kNonExistingExtension, update_url);
149 } 141 }
150 142
151 void SetExampleDictPref() { 143 void SetExampleDictPref() {
152 std::string error_msg; 144 std::string error_msg;
153 std::unique_ptr<base::Value> parsed = base::JSONReader::ReadAndReturnError( 145 std::unique_ptr<base::Value> parsed = base::JSONReader::ReadAndReturnError(
154 kExampleDictPreference, 146 kExampleDictPreference,
155 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error_msg); 147 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, nullptr,
148 &error_msg);
156 ASSERT_TRUE(parsed && parsed->IsType(base::Value::Type::DICTIONARY)) 149 ASSERT_TRUE(parsed && parsed->IsType(base::Value::Type::DICTIONARY))
157 << error_msg; 150 << error_msg;
158 SetPref(true, pref_names::kExtensionManagement, parsed.release()); 151 SetPref(true, pref_names::kExtensionManagement, parsed.release());
159 } 152 }
160 153
161 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and 154 // Wrapper of ExtensionManagement::GetInstallationMode, |id| and
162 // |update_url| are used to construct an Extension for testing. 155 // |update_url| are used to construct an Extension for testing.
163 ExtensionManagement::InstallationMode GetInstallationMode( 156 ExtensionManagement::InstallationMode GetInstallationMode(
164 const std::string& id, 157 const std::string& id,
165 const std::string& update_url) { 158 const std::string& update_url) {
(...skipping 18 matching lines...) Expand all
184 CreateExtension(Manifest::UNPACKED, version, id, kNonExistingUpdateUrl); 177 CreateExtension(Manifest::UNPACKED, version, id, kNonExistingUpdateUrl);
185 std::string minimum_version_required; 178 std::string minimum_version_required;
186 bool ret = extension_management_->CheckMinimumVersion( 179 bool ret = extension_management_->CheckMinimumVersion(
187 extension.get(), &minimum_version_required); 180 extension.get(), &minimum_version_required);
188 EXPECT_EQ(ret, minimum_version_required.empty()); 181 EXPECT_EQ(ret, minimum_version_required.empty());
189 EXPECT_EQ(ret, extension_management_->CheckMinimumVersion(extension.get(), 182 EXPECT_EQ(ret, extension_management_->CheckMinimumVersion(extension.get(),
190 nullptr)); 183 nullptr));
191 return ret; 184 return ret;
192 } 185 }
193 186
194 protected: 187 content::TestBrowserThreadBundle thread_bundle_;
195 std::unique_ptr<TestingPrefServiceSimple> pref_service_; 188 std::unique_ptr<TestingProfile> profile_;
189 sync_preferences::TestingPrefServiceSyncable* pref_service_ = nullptr;
196 std::unique_ptr<ExtensionManagement> extension_management_; 190 std::unique_ptr<ExtensionManagement> extension_management_;
197 191
198 private: 192 private:
199 // Create an extension with specified |location|, |version|, |id| and 193 // Create an extension with specified |location|, |version|, |id| and
200 // |update_url|. 194 // |update_url|.
201 scoped_refptr<const Extension> CreateExtension( 195 scoped_refptr<const Extension> CreateExtension(
202 Manifest::Location location, 196 Manifest::Location location,
203 const std::string& version, 197 const std::string& version,
204 const std::string& id, 198 const std::string& id,
205 const std::string& update_url) { 199 const std::string& update_url) {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 GetBlockedAPIPermissions(kTargetExtension3, kExampleUpdateUrl)); 516 GetBlockedAPIPermissions(kTargetExtension3, kExampleUpdateUrl));
523 } 517 }
524 518
525 // Tests the 'minimum_version_required' settings of extension management. 519 // Tests the 'minimum_version_required' settings of extension management.
526 TEST_F(ExtensionManagementServiceTest, kMinimumVersionRequired) { 520 TEST_F(ExtensionManagementServiceTest, kMinimumVersionRequired) {
527 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "0.0")); 521 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "0.0"));
528 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.0")); 522 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.0"));
529 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "9999.0")); 523 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "9999.0"));
530 524
531 { 525 {
532 PrefUpdater pref(pref_service_.get()); 526 PrefUpdater pref(pref_service_);
533 pref.SetMinimumVersionRequired(kTargetExtension, "3.0"); 527 pref.SetMinimumVersionRequired(kTargetExtension, "3.0");
534 } 528 }
535 529
536 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "0.0")); 530 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "0.0"));
537 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "2.99")); 531 EXPECT_FALSE(CheckMinimumVersion(kTargetExtension, "2.99"));
538 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.0")); 532 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.0"));
539 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.1")); 533 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "3.0.1"));
540 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "4.0")); 534 EXPECT_TRUE(CheckMinimumVersion(kTargetExtension, "4.0"));
541 } 535 }
542 536
543 // Tests functionality of new preference as to deprecate legacy 537 // Tests functionality of new preference as to deprecate legacy
544 // ExtensionInstallSources policy. 538 // ExtensionInstallSources policy.
545 TEST_F(ExtensionManagementServiceTest, NewInstallSources) { 539 TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
546 // Set the legacy preference, and verifies that it works. 540 // Set the legacy preference, and verifies that it works.
547 base::ListValue allowed_sites_pref; 541 base::ListValue allowed_sites_pref;
548 allowed_sites_pref.AppendString("https://www.example.com/foo"); 542 allowed_sites_pref.AppendString("https://www.example.com/foo");
549 SetPref( 543 SetPref(
550 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy()); 544 true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
551 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 545 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
552 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( 546 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL(
553 GURL("https://www.example.com/foo"))); 547 GURL("https://www.example.com/foo")));
554 548
555 // Set the new dictionary preference. 549 // Set the new dictionary preference.
556 { 550 {
557 PrefUpdater updater(pref_service_.get()); 551 PrefUpdater updater(pref_service_);
558 updater.ClearInstallSources(); 552 updater.ClearInstallSources();
559 } 553 }
560 // Verifies that the new one overrides the legacy ones. 554 // Verifies that the new one overrides the legacy ones.
561 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 555 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
562 EXPECT_FALSE(ReadGlobalSettings()->install_sources.MatchesURL( 556 EXPECT_FALSE(ReadGlobalSettings()->install_sources.MatchesURL(
563 GURL("https://www.example.com/foo"))); 557 GURL("https://www.example.com/foo")));
564 558
565 // Updates the new dictionary preference. 559 // Updates the new dictionary preference.
566 { 560 {
567 PrefUpdater updater(pref_service_.get()); 561 PrefUpdater updater(pref_service_);
568 updater.AddInstallSource("https://corp.mycompany.com/*"); 562 updater.AddInstallSource("https://corp.mycompany.com/*");
569 } 563 }
570 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources); 564 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
571 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL( 565 EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL(
572 GURL("https://corp.mycompany.com/entry"))); 566 GURL("https://corp.mycompany.com/entry")));
573 } 567 }
574 568
575 // Tests functionality of new preference as to deprecate legacy 569 // Tests functionality of new preference as to deprecate legacy
576 // ExtensionAllowedTypes policy. 570 // ExtensionAllowedTypes policy.
577 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) { 571 TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) {
578 // Set the legacy preference, and verifies that it works. 572 // Set the legacy preference, and verifies that it works.
579 base::ListValue allowed_types_pref; 573 base::ListValue allowed_types_pref;
580 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT); 574 allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT);
581 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy()); 575 SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy());
582 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); 576 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
583 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); 577 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u);
584 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT); 578 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT);
585 579
586 // Set the new dictionary preference. 580 // Set the new dictionary preference.
587 { 581 {
588 PrefUpdater updater(pref_service_.get()); 582 PrefUpdater updater(pref_service_);
589 updater.ClearAllowedTypes(); 583 updater.ClearAllowedTypes();
590 } 584 }
591 // Verifies that the new one overrides the legacy ones. 585 // Verifies that the new one overrides the legacy ones.
592 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); 586 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
593 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 0u); 587 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 0u);
594 588
595 // Updates the new dictionary preference. 589 // Updates the new dictionary preference.
596 { 590 {
597 PrefUpdater updater(pref_service_.get()); 591 PrefUpdater updater(pref_service_);
598 updater.AddAllowedType("theme"); 592 updater.AddAllowedType("theme");
599 } 593 }
600 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types); 594 EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
601 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u); 595 EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u);
602 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_THEME); 596 EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_THEME);
603 } 597 }
604 598
605 // Tests functionality of new preference as to deprecate legacy 599 // Tests functionality of new preference as to deprecate legacy
606 // ExtensionInstallBlacklist policy. 600 // ExtensionInstallBlacklist policy.
607 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) { 601 TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) {
608 // Set the new dictionary preference. 602 // Set the new dictionary preference.
609 { 603 {
610 PrefUpdater updater(pref_service_.get()); 604 PrefUpdater updater(pref_service_);
611 updater.SetBlacklistedByDefault(false); // Allowed by default. 605 updater.SetBlacklistedByDefault(false); // Allowed by default.
612 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false); 606 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, false);
613 updater.ClearPerExtensionSettings(kTargetExtension2); 607 updater.ClearPerExtensionSettings(kTargetExtension2);
614 } 608 }
615 EXPECT_FALSE(extension_management_->BlacklistedByDefault()); 609 EXPECT_FALSE(extension_management_->BlacklistedByDefault());
616 EXPECT_EQ(GetInstallationModeById(kTargetExtension), 610 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
617 ExtensionManagement::INSTALLATION_BLOCKED); 611 ExtensionManagement::INSTALLATION_BLOCKED);
618 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), 612 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
619 ExtensionManagement::INSTALLATION_ALLOWED); 613 ExtensionManagement::INSTALLATION_ALLOWED);
620 614
(...skipping 15 matching lines...) Expand all
636 ExtensionManagement::INSTALLATION_BLOCKED); 630 ExtensionManagement::INSTALLATION_BLOCKED);
637 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), 631 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
638 ExtensionManagement::INSTALLATION_ALLOWED); 632 ExtensionManagement::INSTALLATION_ALLOWED);
639 } 633 }
640 634
641 // Tests functionality of new preference as to deprecate legacy 635 // Tests functionality of new preference as to deprecate legacy
642 // ExtensionInstallWhitelist policy. 636 // ExtensionInstallWhitelist policy.
643 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) { 637 TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) {
644 // Set the new dictionary preference. 638 // Set the new dictionary preference.
645 { 639 {
646 PrefUpdater updater(pref_service_.get()); 640 PrefUpdater updater(pref_service_);
647 updater.SetBlacklistedByDefault(true); // Disallowed by default. 641 updater.SetBlacklistedByDefault(true); // Disallowed by default.
648 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true); 642 updater.SetIndividualExtensionInstallationAllowed(kTargetExtension, true);
649 updater.ClearPerExtensionSettings(kTargetExtension2); 643 updater.ClearPerExtensionSettings(kTargetExtension2);
650 } 644 }
651 EXPECT_TRUE(extension_management_->BlacklistedByDefault()); 645 EXPECT_TRUE(extension_management_->BlacklistedByDefault());
652 EXPECT_EQ(GetInstallationModeById(kTargetExtension), 646 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
653 ExtensionManagement::INSTALLATION_ALLOWED); 647 ExtensionManagement::INSTALLATION_ALLOWED);
654 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), 648 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
655 ExtensionManagement::INSTALLATION_BLOCKED); 649 ExtensionManagement::INSTALLATION_BLOCKED);
656 650
(...skipping 20 matching lines...) Expand all
677 // ExtensionInstallForcelist policy. 671 // ExtensionInstallForcelist policy.
678 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) { 672 TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) {
679 // Set some legacy preferences, to verify that the new one overrides the 673 // Set some legacy preferences, to verify that the new one overrides the
680 // legacy ones. 674 // legacy ones.
681 base::ListValue denied_list_pref; 675 base::ListValue denied_list_pref;
682 denied_list_pref.AppendString(kTargetExtension); 676 denied_list_pref.AppendString(kTargetExtension);
683 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy()); 677 SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
684 678
685 // Set the new dictionary preference. 679 // Set the new dictionary preference.
686 { 680 {
687 PrefUpdater updater(pref_service_.get()); 681 PrefUpdater updater(pref_service_);
688 updater.SetIndividualExtensionAutoInstalled( 682 updater.SetIndividualExtensionAutoInstalled(
689 kTargetExtension, kExampleUpdateUrl, true); 683 kTargetExtension, kExampleUpdateUrl, true);
690 } 684 }
691 EXPECT_EQ(GetInstallationModeById(kTargetExtension), 685 EXPECT_EQ(GetInstallationModeById(kTargetExtension),
692 ExtensionManagement::INSTALLATION_FORCED); 686 ExtensionManagement::INSTALLATION_FORCED);
693 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl); 687 CheckAutomaticallyInstalledUpdateUrl(kTargetExtension, kExampleUpdateUrl);
694 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension), 688 EXPECT_EQ(GetInstallationModeById(kNonExistingExtension),
695 ExtensionManagement::INSTALLATION_ALLOWED); 689 ExtensionManagement::INSTALLATION_ALLOWED);
696 } 690 }
697 691
(...skipping 13 matching lines...) Expand all
711 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed)); 705 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed));
712 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced)); 706 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced));
713 EXPECT_TRUE( 707 EXPECT_TRUE(
714 extension_management_->IsInstallationExplicitlyAllowed(recommended)); 708 extension_management_->IsInstallationExplicitlyAllowed(recommended));
715 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked)); 709 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
716 EXPECT_FALSE( 710 EXPECT_FALSE(
717 extension_management_->IsInstallationExplicitlyAllowed(not_specified)); 711 extension_management_->IsInstallationExplicitlyAllowed(not_specified));
718 712
719 { 713 {
720 // Set BlacklistedByDefault() to false. 714 // Set BlacklistedByDefault() to false.
721 PrefUpdater pref(pref_service_.get()); 715 PrefUpdater pref(pref_service_);
722 pref.SetBlacklistedByDefault(false); 716 pref.SetBlacklistedByDefault(false);
723 } 717 }
724 718
725 // The result should remain the same. 719 // The result should remain the same.
726 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed)); 720 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(allowed));
727 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced)); 721 EXPECT_TRUE(extension_management_->IsInstallationExplicitlyAllowed(forced));
728 EXPECT_TRUE( 722 EXPECT_TRUE(
729 extension_management_->IsInstallationExplicitlyAllowed(recommended)); 723 extension_management_->IsInstallationExplicitlyAllowed(recommended));
730 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked)); 724 EXPECT_FALSE(extension_management_->IsInstallationExplicitlyAllowed(blocked));
731 EXPECT_FALSE( 725 EXPECT_FALSE(
732 extension_management_->IsInstallationExplicitlyAllowed(not_specified)); 726 extension_management_->IsInstallationExplicitlyAllowed(not_specified));
733 } 727 }
734 728
735 // Tests the flag value indicating that extensions are blacklisted by default. 729 // Tests the flag value indicating that extensions are blacklisted by default.
736 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) { 730 TEST_F(ExtensionAdminPolicyTest, BlacklistedByDefault) {
737 EXPECT_FALSE(BlacklistedByDefault(NULL)); 731 EXPECT_FALSE(BlacklistedByDefault(nullptr));
738 732
739 base::ListValue blacklist; 733 base::ListValue blacklist;
740 blacklist.AppendString(kNonExistingExtension); 734 blacklist.AppendString(kNonExistingExtension);
741 EXPECT_FALSE(BlacklistedByDefault(&blacklist)); 735 EXPECT_FALSE(BlacklistedByDefault(&blacklist));
742 blacklist.AppendString("*"); 736 blacklist.AppendString("*");
743 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 737 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
744 738
745 blacklist.Clear(); 739 blacklist.Clear();
746 blacklist.AppendString("*"); 740 blacklist.AppendString("*");
747 EXPECT_TRUE(BlacklistedByDefault(&blacklist)); 741 EXPECT_TRUE(BlacklistedByDefault(&blacklist));
748 } 742 }
749 743
750 // Tests UserMayLoad for required extensions. 744 // Tests UserMayLoad for required extensions.
751 TEST_F(ExtensionAdminPolicyTest, UserMayLoadRequired) { 745 TEST_F(ExtensionAdminPolicyTest, UserMayLoadRequired) {
752 CreateExtension(Manifest::COMPONENT); 746 CreateExtension(Manifest::COMPONENT);
753 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), NULL)); 747 EXPECT_TRUE(UserMayLoad(nullptr, nullptr, nullptr, nullptr, extension_.get(),
748 nullptr));
754 base::string16 error; 749 base::string16 error;
755 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), &error)); 750 EXPECT_TRUE(UserMayLoad(nullptr, nullptr, nullptr, nullptr, extension_.get(),
751 &error));
756 EXPECT_TRUE(error.empty()); 752 EXPECT_TRUE(error.empty());
757 753
758 // Required extensions may load even if they're on the blacklist. 754 // Required extensions may load even if they're on the blacklist.
759 base::ListValue blacklist; 755 base::ListValue blacklist;
760 blacklist.AppendString(extension_->id()); 756 blacklist.AppendString(extension_->id());
761 EXPECT_TRUE( 757 EXPECT_TRUE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
762 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); 758 extension_.get(), nullptr));
763 759
764 blacklist.AppendString("*"); 760 blacklist.AppendString("*");
765 EXPECT_TRUE( 761 EXPECT_TRUE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
766 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); 762 extension_.get(), nullptr));
767 } 763 }
768 764
769 // Tests UserMayLoad when no blacklist exists, or it's empty. 765 // Tests UserMayLoad when no blacklist exists, or it's empty.
770 TEST_F(ExtensionAdminPolicyTest, UserMayLoadNoBlacklist) { 766 TEST_F(ExtensionAdminPolicyTest, UserMayLoadNoBlacklist) {
771 CreateExtension(Manifest::INTERNAL); 767 CreateExtension(Manifest::INTERNAL);
772 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), NULL)); 768 EXPECT_TRUE(UserMayLoad(nullptr, nullptr, nullptr, nullptr, extension_.get(),
769 nullptr));
773 base::ListValue blacklist; 770 base::ListValue blacklist;
774 EXPECT_TRUE( 771 EXPECT_TRUE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
775 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); 772 extension_.get(), nullptr));
776 base::string16 error; 773 base::string16 error;
777 EXPECT_TRUE( 774 EXPECT_TRUE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
778 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), &error)); 775 extension_.get(), &error));
779 EXPECT_TRUE(error.empty()); 776 EXPECT_TRUE(error.empty());
780 } 777 }
781 778
782 // Tests UserMayLoad for an extension on the whitelist. 779 // Tests UserMayLoad for an extension on the whitelist.
783 TEST_F(ExtensionAdminPolicyTest, UserMayLoadWhitelisted) { 780 TEST_F(ExtensionAdminPolicyTest, UserMayLoadWhitelisted) {
784 CreateExtension(Manifest::INTERNAL); 781 CreateExtension(Manifest::INTERNAL);
785 782
786 base::ListValue whitelist; 783 base::ListValue whitelist;
787 whitelist.AppendString(extension_->id()); 784 whitelist.AppendString(extension_->id());
788 EXPECT_TRUE( 785 EXPECT_TRUE(UserMayLoad(nullptr, &whitelist, nullptr, nullptr,
789 UserMayLoad(NULL, &whitelist, NULL, NULL, extension_.get(), NULL)); 786 extension_.get(), nullptr));
790 787
791 base::ListValue blacklist; 788 base::ListValue blacklist;
792 blacklist.AppendString(extension_->id()); 789 blacklist.AppendString(extension_->id());
793 EXPECT_TRUE( 790 EXPECT_TRUE(UserMayLoad(nullptr, &whitelist, nullptr, nullptr,
794 UserMayLoad(NULL, &whitelist, NULL, NULL, extension_.get(), NULL)); 791 extension_.get(), nullptr));
795 base::string16 error; 792 base::string16 error;
796 EXPECT_TRUE( 793 EXPECT_TRUE(UserMayLoad(nullptr, &whitelist, nullptr, nullptr,
797 UserMayLoad(NULL, &whitelist, NULL, NULL, extension_.get(), &error)); 794 extension_.get(), &error));
798 EXPECT_TRUE(error.empty()); 795 EXPECT_TRUE(error.empty());
799 } 796 }
800 797
801 // Tests UserMayLoad for an extension on the blacklist. 798 // Tests UserMayLoad for an extension on the blacklist.
802 TEST_F(ExtensionAdminPolicyTest, UserMayLoadBlacklisted) { 799 TEST_F(ExtensionAdminPolicyTest, UserMayLoadBlacklisted) {
803 CreateExtension(Manifest::INTERNAL); 800 CreateExtension(Manifest::INTERNAL);
804 801
805 // Blacklisted by default. 802 // Blacklisted by default.
806 base::ListValue blacklist; 803 base::ListValue blacklist;
807 blacklist.AppendString("*"); 804 blacklist.AppendString("*");
808 EXPECT_FALSE( 805 EXPECT_FALSE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
809 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); 806 extension_.get(), nullptr));
810 base::string16 error; 807 base::string16 error;
811 EXPECT_FALSE( 808 EXPECT_FALSE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
812 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), &error)); 809 extension_.get(), &error));
813 EXPECT_FALSE(error.empty()); 810 EXPECT_FALSE(error.empty());
814 811
815 // Extension on the blacklist, with and without wildcard. 812 // Extension on the blacklist, with and without wildcard.
816 blacklist.AppendString(extension_->id()); 813 blacklist.AppendString(extension_->id());
817 EXPECT_FALSE( 814 EXPECT_FALSE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
818 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); 815 extension_.get(), nullptr));
819 blacklist.Clear(); 816 blacklist.Clear();
820 blacklist.AppendString(extension_->id()); 817 blacklist.AppendString(extension_->id());
821 EXPECT_FALSE( 818 EXPECT_FALSE(UserMayLoad(&blacklist, nullptr, nullptr, nullptr,
822 UserMayLoad(&blacklist, NULL, NULL, NULL, extension_.get(), NULL)); 819 extension_.get(), nullptr));
823 820
824 // With a whitelist. There's no such thing as a whitelist wildcard. 821 // With a whitelist. There's no such thing as a whitelist wildcard.
825 base::ListValue whitelist; 822 base::ListValue whitelist;
826 whitelist.AppendString("behllobkkfkfnphdnhnkndlbkcpglgmj"); 823 whitelist.AppendString("behllobkkfkfnphdnhnkndlbkcpglgmj");
827 EXPECT_FALSE( 824 EXPECT_FALSE(UserMayLoad(&blacklist, &whitelist, nullptr, nullptr,
828 UserMayLoad(&blacklist, &whitelist, NULL, NULL, extension_.get(), NULL)); 825 extension_.get(), nullptr));
829 whitelist.AppendString("*"); 826 whitelist.AppendString("*");
830 EXPECT_FALSE( 827 EXPECT_FALSE(UserMayLoad(&blacklist, &whitelist, nullptr, nullptr,
831 UserMayLoad(&blacklist, &whitelist, NULL, NULL, extension_.get(), NULL)); 828 extension_.get(), nullptr));
832 } 829 }
833 830
834 TEST_F(ExtensionAdminPolicyTest, UserMayLoadAllowedTypes) { 831 TEST_F(ExtensionAdminPolicyTest, UserMayLoadAllowedTypes) {
835 CreateExtension(Manifest::INTERNAL); 832 CreateExtension(Manifest::INTERNAL);
836 EXPECT_TRUE(UserMayLoad(NULL, NULL, NULL, NULL, extension_.get(), NULL)); 833 EXPECT_TRUE(UserMayLoad(nullptr, nullptr, nullptr, nullptr, extension_.get(),
834 nullptr));
837 835
838 base::ListValue allowed_types; 836 base::ListValue allowed_types;
839 EXPECT_FALSE( 837 EXPECT_FALSE(UserMayLoad(nullptr, nullptr, nullptr, &allowed_types,
840 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); 838 extension_.get(), nullptr));
841 839
842 allowed_types.AppendInteger(Manifest::TYPE_EXTENSION); 840 allowed_types.AppendInteger(Manifest::TYPE_EXTENSION);
843 EXPECT_TRUE( 841 EXPECT_TRUE(UserMayLoad(nullptr, nullptr, nullptr, &allowed_types,
844 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); 842 extension_.get(), nullptr));
845 843
846 CreateHostedApp(Manifest::INTERNAL); 844 CreateHostedApp(Manifest::INTERNAL);
847 EXPECT_FALSE( 845 EXPECT_FALSE(UserMayLoad(nullptr, nullptr, nullptr, &allowed_types,
848 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); 846 extension_.get(), nullptr));
849 847
850 CreateHostedApp(Manifest::EXTERNAL_POLICY_DOWNLOAD); 848 CreateHostedApp(Manifest::EXTERNAL_POLICY_DOWNLOAD);
851 EXPECT_FALSE( 849 EXPECT_FALSE(UserMayLoad(nullptr, nullptr, nullptr, &allowed_types,
852 UserMayLoad(NULL, NULL, NULL, &allowed_types, extension_.get(), NULL)); 850 extension_.get(), nullptr));
853 } 851 }
854 852
855 TEST_F(ExtensionAdminPolicyTest, UserMayModifySettings) { 853 TEST_F(ExtensionAdminPolicyTest, UserMayModifySettings) {
856 CreateExtension(Manifest::INTERNAL); 854 CreateExtension(Manifest::INTERNAL);
857 EXPECT_TRUE(UserMayModifySettings(extension_.get(), NULL)); 855 EXPECT_TRUE(UserMayModifySettings(extension_.get(), nullptr));
858 base::string16 error; 856 base::string16 error;
859 EXPECT_TRUE(UserMayModifySettings(extension_.get(), &error)); 857 EXPECT_TRUE(UserMayModifySettings(extension_.get(), &error));
860 EXPECT_TRUE(error.empty()); 858 EXPECT_TRUE(error.empty());
861 859
862 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD); 860 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD);
863 error.clear(); 861 error.clear();
864 EXPECT_FALSE(UserMayModifySettings(extension_.get(), NULL)); 862 EXPECT_FALSE(UserMayModifySettings(extension_.get(), nullptr));
865 EXPECT_FALSE(UserMayModifySettings(extension_.get(), &error)); 863 EXPECT_FALSE(UserMayModifySettings(extension_.get(), &error));
866 EXPECT_FALSE(error.empty()); 864 EXPECT_FALSE(error.empty());
867 } 865 }
868 866
869 TEST_F(ExtensionAdminPolicyTest, MustRemainEnabled) { 867 TEST_F(ExtensionAdminPolicyTest, MustRemainEnabled) {
870 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD); 868 CreateExtension(Manifest::EXTERNAL_POLICY_DOWNLOAD);
871 EXPECT_TRUE(MustRemainEnabled(extension_.get(), NULL)); 869 EXPECT_TRUE(MustRemainEnabled(extension_.get(), nullptr));
872 base::string16 error; 870 base::string16 error;
873 EXPECT_TRUE(MustRemainEnabled(extension_.get(), &error)); 871 EXPECT_TRUE(MustRemainEnabled(extension_.get(), &error));
874 EXPECT_FALSE(error.empty()); 872 EXPECT_FALSE(error.empty());
875 873
876 CreateExtension(Manifest::INTERNAL); 874 CreateExtension(Manifest::INTERNAL);
877 error.clear(); 875 error.clear();
878 EXPECT_FALSE(MustRemainEnabled(extension_.get(), NULL)); 876 EXPECT_FALSE(MustRemainEnabled(extension_.get(), nullptr));
879 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error)); 877 EXPECT_FALSE(MustRemainEnabled(extension_.get(), &error));
880 EXPECT_TRUE(error.empty()); 878 EXPECT_TRUE(error.empty());
881 } 879 }
882 880
883 } // namespace extensions 881 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698