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

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

Issue 500043003: Add PolicyProvider to ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-1
Patch Set: rebase again Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <set> 6 #include <set>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "chrome/browser/sync/profile_sync_service_factory.h" 65 #include "chrome/browser/sync/profile_sync_service_factory.h"
66 #include "chrome/common/chrome_constants.h" 66 #include "chrome/common/chrome_constants.h"
67 #include "chrome/common/chrome_switches.h" 67 #include "chrome/common/chrome_switches.h"
68 #include "chrome/common/extensions/api/plugins/plugins_handler.h" 68 #include "chrome/common/extensions/api/plugins/plugins_handler.h"
69 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 69 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
70 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" 70 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
71 #include "chrome/common/extensions/manifest_url_handler.h" 71 #include "chrome/common/extensions/manifest_url_handler.h"
72 #include "chrome/common/pref_names.h" 72 #include "chrome/common/pref_names.h"
73 #include "chrome/common/url_constants.h" 73 #include "chrome/common/url_constants.h"
74 #include "chrome/test/base/scoped_browser_locale.h" 74 #include "chrome/test/base/scoped_browser_locale.h"
75 #include "chrome/test/base/testing_pref_service_syncable.h"
75 #include "chrome/test/base/testing_profile.h" 76 #include "chrome/test/base/testing_profile.h"
76 #include "components/crx_file/id_util.h" 77 #include "components/crx_file/id_util.h"
77 #include "components/pref_registry/pref_registry_syncable.h" 78 #include "components/pref_registry/pref_registry_syncable.h"
78 #include "content/public/browser/dom_storage_context.h" 79 #include "content/public/browser/dom_storage_context.h"
79 #include "content/public/browser/gpu_data_manager.h" 80 #include "content/public/browser/gpu_data_manager.h"
80 #include "content/public/browser/indexed_db_context.h" 81 #include "content/public/browser/indexed_db_context.h"
81 #include "content/public/browser/notification_registrar.h" 82 #include "content/public/browser/notification_registrar.h"
82 #include "content/public/browser/notification_service.h" 83 #include "content/public/browser/notification_service.h"
83 #include "content/public/browser/plugin_service.h" 84 #include "content/public/browser/plugin_service.h"
84 #include "content/public/browser/render_process_host.h" 85 #include "content/public/browser/render_process_host.h"
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 #if defined(ENABLE_PLUGINS) 1081 #if defined(ENABLE_PLUGINS)
1081 PluginService::GetInstance()->Init(); 1082 PluginService::GetInstance()->Init();
1082 #endif 1083 #endif
1083 } 1084 }
1084 1085
1085 void InitializeExtensionSyncService() { 1086 void InitializeExtensionSyncService() {
1086 extension_sync_service_.reset(new ExtensionSyncService( 1087 extension_sync_service_.reset(new ExtensionSyncService(
1087 profile(), ExtensionPrefs::Get(browser_context()), service())); 1088 profile(), ExtensionPrefs::Get(browser_context()), service()));
1088 } 1089 }
1089 1090
1091 void InitializeEmptyExtensionServiceWithTestingPrefs() {
1092 ExtensionServiceTestBase::ExtensionServiceInitParams params =
1093 CreateDefaultInitParams();
1094 params.pref_file = base::FilePath();
1095 InitializeExtensionService(params);
1096 }
1097
1090 extensions::ManagementPolicy* GetManagementPolicy() { 1098 extensions::ManagementPolicy* GetManagementPolicy() {
1091 return ExtensionSystem::Get(browser_context())->management_policy(); 1099 return ExtensionSystem::Get(browser_context())->management_policy();
1092 } 1100 }
1093 1101
1094 ExtensionSyncService* extension_sync_service() { 1102 ExtensionSyncService* extension_sync_service() {
1095 return extension_sync_service_.get(); 1103 return extension_sync_service_.get();
1096 } 1104 }
1097 1105
1098 protected: 1106 protected:
1099 scoped_ptr<ExtensionSyncService> extension_sync_service_; 1107 scoped_ptr<ExtensionSyncService> extension_sync_service_;
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after
3267 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3275 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3268 } 3276 }
3269 #endif // defined(ENABLE_BLACKLIST_TESTS) 3277 #endif // defined(ENABLE_BLACKLIST_TESTS)
3270 3278
3271 #if defined(ENABLE_BLACKLIST_TESTS) 3279 #if defined(ENABLE_BLACKLIST_TESTS)
3272 // Unload blacklisted extension on policy change. 3280 // Unload blacklisted extension on policy change.
3273 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { 3281 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
3274 extensions::TestBlacklist test_blacklist; 3282 extensions::TestBlacklist test_blacklist;
3275 3283
3276 // A profile with no extensions installed. 3284 // A profile with no extensions installed.
3277 InitializeEmptyExtensionService(); 3285 InitializeEmptyExtensionServiceWithTestingPrefs();
3278 test_blacklist.Attach(service()->blacklist_); 3286 test_blacklist.Attach(service()->blacklist_);
3279 3287
3280 base::FilePath path = data_dir().AppendASCII("good.crx"); 3288 base::FilePath path = data_dir().AppendASCII("good.crx");
3281 3289
3282 const Extension* good = InstallCRX(path, INSTALL_NEW); 3290 const Extension* good = InstallCRX(path, INSTALL_NEW);
3283 EXPECT_EQ(good_crx, good->id()); 3291 EXPECT_EQ(good_crx, good->id());
3284 UpdateExtension(good_crx, path, FAILED_SILENTLY); 3292 UpdateExtension(good_crx, path, FAILED_SILENTLY);
3285 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 3293 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3286 3294
3287 base::ListValue whitelist; 3295 base::ListValue whitelist;
3288 PrefService* prefs = ExtensionPrefs::Get(profile())->pref_service();
3289 whitelist.Append(new base::StringValue(good_crx)); 3296 whitelist.Append(new base::StringValue(good_crx));
3290 prefs->Set(extensions::pref_names::kInstallAllowList, whitelist); 3297 profile_->GetTestingPrefService()->SetManagedPref(
3298 extensions::pref_names::kInstallAllowList, whitelist.DeepCopy());
3291 3299
3292 test_blacklist.SetBlacklistState( 3300 test_blacklist.SetBlacklistState(
3293 good_crx, extensions::BLACKLISTED_MALWARE, true); 3301 good_crx, extensions::BLACKLISTED_MALWARE, true);
3294 base::RunLoop().RunUntilIdle(); 3302 base::RunLoop().RunUntilIdle();
3295 3303
3296 // The good_crx is blacklisted and the whitelist doesn't negate it. 3304 // The good_crx is blacklisted and the whitelist doesn't negate it.
3297 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); 3305 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true));
3298 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3306 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3299 } 3307 }
3300 #endif // defined(ENABLE_BLACKLIST_TESTS) 3308 #endif // defined(ENABLE_BLACKLIST_TESTS)
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
3568 3576
3569 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs()); 3577 EXPECT_EQ(StringSet(good0), registry()->enabled_extensions().GetIDs());
3570 EXPECT_EQ(StringSet(good1, good2), 3578 EXPECT_EQ(StringSet(good1, good2),
3571 registry()->blacklisted_extensions().GetIDs()); 3579 registry()->blacklisted_extensions().GetIDs());
3572 } 3580 }
3573 3581
3574 #endif // defined(ENABLE_BLACKLIST_TESTS) 3582 #endif // defined(ENABLE_BLACKLIST_TESTS)
3575 3583
3576 // Will not install extension blacklisted by policy. 3584 // Will not install extension blacklisted by policy.
3577 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { 3585 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
3578 InitializeEmptyExtensionService(); 3586 InitializeEmptyExtensionServiceWithTestingPrefs();
3579 3587
3580 // Blacklist everything. 3588 // Blacklist everything.
3581 { 3589 {
3582 ListPrefUpdate update(profile()->GetPrefs(), 3590 ListPrefUpdate update(profile()->GetPrefs(),
3583 extensions::pref_names::kInstallDenyList); 3591 extensions::pref_names::kInstallDenyList);
3584 base::ListValue* blacklist = update.Get(); 3592 base::ListValue* blacklist = update.Get();
3585 blacklist->Append(new base::StringValue("*")); 3593 blacklist->Append(new base::StringValue("*"));
3586 } 3594 }
3587 3595
3588 // Blacklist prevents us from installing good_crx. 3596 // Blacklist prevents us from installing good_crx.
3589 base::FilePath path = data_dir().AppendASCII("good.crx"); 3597 base::FilePath path = data_dir().AppendASCII("good.crx");
3590 InstallCRX(path, INSTALL_FAILED); 3598 InstallCRX(path, INSTALL_FAILED);
3591 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 3599 EXPECT_EQ(0u, registry()->enabled_extensions().size());
3592 3600
3593 // Now whitelist this particular extension. 3601 // Now whitelist this particular extension.
3594 { 3602 {
3595 ListPrefUpdate update(profile()->GetPrefs(), 3603 base::ListValue whitelist;
3596 extensions::pref_names::kInstallAllowList); 3604 whitelist.Append(new base::StringValue(good_crx));
3597 base::ListValue* whitelist = update.Get(); 3605 profile_->GetTestingPrefService()->SetManagedPref(
3598 whitelist->Append(new base::StringValue(good_crx)); 3606 extensions::pref_names::kInstallAllowList, whitelist.DeepCopy());
3599 } 3607 }
3600 3608
3601 // Ensure we can now install good_crx. 3609 // Ensure we can now install good_crx.
3602 InstallCRX(path, INSTALL_NEW); 3610 InstallCRX(path, INSTALL_NEW);
3603 EXPECT_EQ(1u, registry()->enabled_extensions().size()); 3611 EXPECT_EQ(1u, registry()->enabled_extensions().size());
3604 } 3612 }
3605 3613
3606 // Extension blacklisted by policy get unloaded after installing. 3614 // Extension blacklisted by policy get unloaded after installing.
3607 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { 3615 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
3608 InitializeEmptyExtensionService(); 3616 InitializeEmptyExtensionService();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3667 base::ListValue* blacklist = update.Get(); 3675 base::ListValue* blacklist = update.Get();
3668 blacklist->Append(new base::StringValue(good0)); 3676 blacklist->Append(new base::StringValue(good0));
3669 } 3677 }
3670 base::RunLoop().RunUntilIdle(); 3678 base::RunLoop().RunUntilIdle();
3671 ASSERT_EQ(1u, registry()->enabled_extensions().size()); 3679 ASSERT_EQ(1u, registry()->enabled_extensions().size());
3672 EXPECT_TRUE(service()->GetExtensionById(good0, false)); 3680 EXPECT_TRUE(service()->GetExtensionById(good0, false));
3673 } 3681 }
3674 3682
3675 // Tests that policy-installed extensions are not blacklisted by policy. 3683 // Tests that policy-installed extensions are not blacklisted by policy.
3676 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) { 3684 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
3677 InitializeEmptyExtensionService(); 3685 InitializeEmptyExtensionServiceWithTestingPrefs();
3678 3686
3679 { 3687 {
3680 // Blacklist everything. 3688 // Blacklist everything.
3681 ListPrefUpdate blacklist_update(profile()->GetPrefs(), 3689 ListPrefUpdate blacklist_update(profile()->GetPrefs(),
3682 extensions::pref_names::kInstallDenyList); 3690 extensions::pref_names::kInstallDenyList);
3683 base::ListValue* blacklist = blacklist_update.Get(); 3691 base::ListValue* blacklist = blacklist_update.Get();
3684 blacklist->AppendString("*"); 3692 blacklist->AppendString("*");
3693 }
3685 3694
3695 {
3686 // Mark good.crx for force-installation. 3696 // Mark good.crx for force-installation.
3687 DictionaryPrefUpdate forcelist_update( 3697 base::DictionaryValue forcelist;
3688 profile()->GetPrefs(), extensions::pref_names::kInstallForceList);
3689 extensions::ExternalPolicyLoader::AddExtension( 3698 extensions::ExternalPolicyLoader::AddExtension(
3690 forcelist_update.Get(), good_crx, "http://example.com/update_url"); 3699 &forcelist, good_crx, "http://example.com/update_url");
3700 profile_->GetTestingPrefService()->SetManagedPref(
3701 extensions::pref_names::kInstallForceList, forcelist.DeepCopy());
3691 } 3702 }
3692 3703
3693 // Have policy force-install an extension. 3704 // Have policy force-install an extension.
3694 MockExtensionProvider* provider = 3705 MockExtensionProvider* provider =
3695 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD); 3706 new MockExtensionProvider(service(), Manifest::EXTERNAL_POLICY_DOWNLOAD);
3696 AddMockExternalProvider(provider); 3707 AddMockExternalProvider(provider);
3697 provider->UpdateOrAddExtension( 3708 provider->UpdateOrAddExtension(
3698 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx")); 3709 good_crx, "1.0.0.0", data_dir().AppendASCII("good.crx"));
3699 3710
3700 // Reloading extensions should find our externally registered extension 3711 // Reloading extensions should find our externally registered extension
(...skipping 3452 matching lines...) Expand 10 before | Expand all | Expand 10 after
7153 7164
7154 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 7165 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
7155 content::Source<Profile>(profile()), 7166 content::Source<Profile>(profile()),
7156 content::NotificationService::NoDetails()); 7167 content::NotificationService::NoDetails());
7157 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 7168 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
7158 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 7169 EXPECT_EQ(0u, registry()->enabled_extensions().size());
7159 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 7170 EXPECT_EQ(0u, registry()->disabled_extensions().size());
7160 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 7171 EXPECT_EQ(0u, registry()->terminated_extensions().size());
7161 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 7172 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
7162 } 7173 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_system_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698