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

Unified Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 559603002: Add new ExtensionManagement preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes addressing #16 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service_unittest.cc
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 383b238e402e794187e1dcb896fc433e7556fd7d..37436544da0b4b9372bb0e334e9672d082988421 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -37,6 +37,7 @@
#include "chrome/browser/extensions/extension_creator.h"
#include "chrome/browser/extensions/extension_error_reporter.h"
#include "chrome/browser/extensions/extension_error_ui.h"
+#include "chrome/browser/extensions/extension_management_test_util.h"
#include "chrome/browser/extensions/extension_notification_observer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
@@ -91,7 +92,6 @@
#include "extensions/browser/external_provider_interface.h"
#include "extensions/browser/install_flag.h"
#include "extensions/browser/management_policy.h"
-#include "extensions/browser/pref_names.h"
#include "extensions/browser/test_management_policy.h"
#include "extensions/browser/uninstall_reason.h"
#include "extensions/common/constants.h"
@@ -1104,6 +1104,8 @@ class ExtensionServiceTest : public extensions::ExtensionServiceTestBase,
}
protected:
+ typedef extensions::ExtensionManagementPrefUpdater<TestingPrefServiceSyncable>
+ ManagementPrefUpdater;
scoped_ptr<ExtensionSyncService> extension_sync_service_;
extensions::ExtensionList loaded_;
std::string unloaded_id_;
@@ -3292,10 +3294,10 @@ TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) {
UpdateExtension(good_crx, path, FAILED_SILENTLY);
EXPECT_EQ(1u, registry()->enabled_extensions().size());
- base::ListValue whitelist;
- whitelist.Append(new base::StringValue(good_crx));
- profile_->GetTestingPrefService()->SetManagedPref(
- extensions::pref_names::kInstallAllowList, whitelist.DeepCopy());
+ {
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
+ pref.SetIndividualExtensionInstallationAllowed(good_crx, true);
+ }
test_blacklist.SetBlacklistState(
good_crx, extensions::BLACKLISTED_MALWARE, true);
@@ -3587,10 +3589,8 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
// Blacklist everything.
{
- ListPrefUpdate update(profile()->GetPrefs(),
- extensions::pref_names::kInstallDenyList);
- base::ListValue* blacklist = update.Get();
- blacklist->Append(new base::StringValue("*"));
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
+ pref.SetBlacklistedByDefault(true);
}
// Blacklist prevents us from installing good_crx.
@@ -3600,10 +3600,8 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
// Now whitelist this particular extension.
{
- base::ListValue whitelist;
- whitelist.Append(new base::StringValue(good_crx));
- profile_->GetTestingPrefService()->SetManagedPref(
- extensions::pref_names::kInstallAllowList, whitelist.DeepCopy());
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
+ pref.SetIndividualExtensionInstallationAllowed(good_crx, true);
}
// Ensure we can now install good_crx.
@@ -3613,21 +3611,17 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) {
// Extension blacklisted by policy get unloaded after installing.
TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
- InitializeEmptyExtensionService();
+ InitializeEmptyExtensionServiceWithTestingPrefs();
// Install good_crx.
base::FilePath path = data_dir().AppendASCII("good.crx");
InstallCRX(path, INSTALL_NEW);
EXPECT_EQ(1u, registry()->enabled_extensions().size());
- { // Scope for pref update notification.
- PrefService* prefs = profile()->GetPrefs();
- ListPrefUpdate update(prefs, extensions::pref_names::kInstallDenyList);
- base::ListValue* blacklist = update.Get();
- ASSERT_TRUE(blacklist != NULL);
-
+ {
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
// Blacklist this extension.
- blacklist->Append(new base::StringValue(good_crx));
+ pref.SetIndividualExtensionInstallationAllowed(good_crx, false);
}
// Extension should not be running now.
@@ -3637,14 +3631,12 @@ TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) {
// Tests that component extensions are not blacklisted by policy.
TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
- InitializeEmptyExtensionService();
+ InitializeEmptyExtensionServiceWithTestingPrefs();
// Blacklist everything.
{
- ListPrefUpdate update(profile()->GetPrefs(),
- extensions::pref_names::kInstallDenyList);
- base::ListValue* blacklist = update.Get();
- blacklist->Append(new base::StringValue("*"));
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
+ pref.SetBlacklistedByDefault(true);
}
// Install a component extension.
@@ -3670,10 +3662,8 @@ TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
// Extension should not be uninstalled on blacklist changes.
{
- ListPrefUpdate update(profile()->GetPrefs(),
- extensions::pref_names::kInstallDenyList);
- base::ListValue* blacklist = update.Get();
- blacklist->Append(new base::StringValue(good0));
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
+ pref.SetIndividualExtensionInstallationAllowed(good0, false);
}
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, registry()->enabled_extensions().size());
@@ -3685,20 +3675,12 @@ TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
InitializeEmptyExtensionServiceWithTestingPrefs();
{
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
// Blacklist everything.
- ListPrefUpdate blacklist_update(profile()->GetPrefs(),
- extensions::pref_names::kInstallDenyList);
- base::ListValue* blacklist = blacklist_update.Get();
- blacklist->AppendString("*");
- }
-
- {
+ pref.SetBlacklistedByDefault(true);
// Mark good.crx for force-installation.
- base::DictionaryValue forcelist;
- extensions::ExternalPolicyLoader::AddExtension(
- &forcelist, good_crx, "http://example.com/update_url");
- profile_->GetTestingPrefService()->SetManagedPref(
- extensions::pref_names::kInstallForceList, forcelist.DeepCopy());
+ pref.SetIndividualExtensionAutoInstalled(
+ good_crx, "http://example.com/update_url", true);
}
// Have policy force-install an extension.
@@ -3722,10 +3704,8 @@ TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
// Blacklist update should not uninstall the extension.
{
- ListPrefUpdate update(profile()->GetPrefs(),
- extensions::pref_names::kInstallDenyList);
- base::ListValue* blacklist = update.Get();
- blacklist->Append(new base::StringValue(good0));
+ ManagementPrefUpdater pref(profile_->GetTestingPrefService());
+ pref.SetIndividualExtensionInstallationAllowed(good0, false);
}
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, registry()->enabled_extensions().size());

Powered by Google App Engine
This is Rietveld 408576698