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

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

Issue 602803002: Refactor ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-fix
Patch Set: fix addressing #7 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_management_unittest.cc
diff --git a/chrome/browser/extensions/extension_management_unittest.cc b/chrome/browser/extensions/extension_management_unittest.cc
index 9d9189573dfc9cdb15246a175ca75a81b7ba0e16..35f12f51f5094d82ba34a58976899d27b90c0779 100644
--- a/chrome/browser/extensions/extension_management_unittest.cc
+++ b/chrome/browser/extensions/extension_management_unittest.cc
@@ -11,6 +11,7 @@
#include "base/prefs/testing_pref_service.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_management.h"
+#include "chrome/browser/extensions/extension_management_internal.h"
#include "chrome/browser/extensions/extension_management_test_util.h"
#include "chrome/browser/extensions/external_policy_loader.h"
#include "extensions/browser/pref_names.h"
@@ -93,6 +94,14 @@ class ExtensionManagementServiceTest : public testing::Test {
pref_service_->RemoveUserPref(path);
}
+ const internal::IndividualSettings* ReadById(const ExtensionId& id) {
+ return extension_management_->ReadById(id);
+ }
+
+ const internal::GlobalSettings* ReadGlobalSettings() {
+ return extension_management_->ReadGlobalSettings();
+ }
+
void SetExampleDictPref() {
std::string error_msg;
scoped_ptr<base::Value> parsed(base::JSONReader::ReadAndReturnError(
@@ -202,10 +211,8 @@ TEST_F(ExtensionManagementServiceTest, LegacyInstallSources) {
allowed_sites_pref.AppendString("https://corp.mycompany.com/*");
SetPref(
true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
- const URLPatternSet& allowed_sites =
- extension_management_->ReadGlobalSettings().install_sources;
- ASSERT_TRUE(extension_management_->ReadGlobalSettings()
- .has_restricted_install_sources);
+ const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources;
+ ASSERT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
EXPECT_FALSE(allowed_sites.is_empty());
EXPECT_TRUE(allowed_sites.MatchesURL(GURL("https://www.example.com/foo")));
EXPECT_FALSE(allowed_sites.MatchesURL(GURL("https://www.example.com/bar")));
@@ -224,9 +231,8 @@ TEST_F(ExtensionManagementServiceTest, LegacyAllowedTypes) {
SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy());
const std::vector<Manifest::Type>& allowed_types =
- extension_management_->ReadGlobalSettings().allowed_types;
- ASSERT_TRUE(
- extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
+ ReadGlobalSettings()->allowed_types;
+ ASSERT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
EXPECT_TRUE(allowed_types.size() == 2);
EXPECT_FALSE(std::find(allowed_types.begin(),
allowed_types.end(),
@@ -246,9 +252,9 @@ TEST_F(ExtensionManagementServiceTest, LegacyInstallBlacklist) {
denied_list_pref.AppendString(kTargetExtension);
SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
}
@@ -262,15 +268,15 @@ TEST_F(ExtensionManagementServiceTest, LegacyInstallWhitelist) {
SetPref(true, pref_names::kInstallDenyList, denied_list_pref.DeepCopy());
SetPref(true, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
// Verify that install whitelist preference set by user is ignored.
RemovePref(true, pref_names::kInstallAllowList);
SetPref(false, pref_names::kInstallAllowList, allowed_list_pref.DeepCopy());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
}
@@ -282,17 +288,16 @@ TEST_F(ExtensionManagementServiceTest, LegacyInstallForcelist) {
&forced_list_pref, kTargetExtension, kExampleUpdateUrl);
SetPref(true, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_FORCED);
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url,
- kExampleUpdateUrl);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl);
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
// Verify that install forcelist preference set by user is ignored.
RemovePref(true, pref_names::kInstallForceList);
SetPref(false, pref_names::kInstallForceList, forced_list_pref.DeepCopy());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
}
@@ -302,34 +307,27 @@ TEST_F(ExtensionManagementServiceTest, PreferenceParsing) {
// Verifies the installation mode settings.
EXPECT_TRUE(extension_management_->BlacklistedByDefault());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
- EXPECT_EQ(
- extension_management_->ReadById(kTargetExtension2).installation_mode,
- ExtensionManagement::INSTALLATION_FORCED);
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension2).update_url,
- kExampleUpdateUrl);
- EXPECT_EQ(
- extension_management_->ReadById(kTargetExtension3).installation_mode,
- ExtensionManagement::INSTALLATION_RECOMMENDED);
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension3).update_url,
- kExampleUpdateUrl);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode,
+ ExtensionManagement::INSTALLATION_FORCED);
+ EXPECT_EQ(ReadById(kTargetExtension2)->update_url, kExampleUpdateUrl);
+ EXPECT_EQ(ReadById(kTargetExtension3)->installation_mode,
+ ExtensionManagement::INSTALLATION_RECOMMENDED);
+ EXPECT_EQ(ReadById(kTargetExtension3)->update_url, kExampleUpdateUrl);
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
// Verifies global settings.
- EXPECT_TRUE(extension_management_->ReadGlobalSettings()
- .has_restricted_install_sources);
- const URLPatternSet& allowed_sites =
- extension_management_->ReadGlobalSettings().install_sources;
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
+ const URLPatternSet& allowed_sites = ReadGlobalSettings()->install_sources;
EXPECT_EQ(allowed_sites.size(), 1u);
EXPECT_TRUE(allowed_sites.MatchesURL(GURL("http://foo.com/entry")));
EXPECT_FALSE(allowed_sites.MatchesURL(GURL("http://bar.com/entry")));
- EXPECT_TRUE(
- extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
const std::vector<Manifest::Type>& allowed_types =
- extension_management_->ReadGlobalSettings().allowed_types;
+ ReadGlobalSettings()->allowed_types;
EXPECT_EQ(allowed_types.size(), 2u);
EXPECT_TRUE(std::find(allowed_types.begin(),
allowed_types.end(),
@@ -347,11 +345,9 @@ TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
allowed_sites_pref.AppendString("https://www.example.com/foo");
SetPref(
true, pref_names::kAllowedInstallSites, allowed_sites_pref.DeepCopy());
- EXPECT_TRUE(extension_management_->ReadGlobalSettings()
- .has_restricted_install_sources);
- EXPECT_TRUE(
- extension_management_->ReadGlobalSettings()
- .install_sources.MatchesURL(GURL("https://www.example.com/foo")));
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
+ EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL(
+ GURL("https://www.example.com/foo")));
// Set the new dictionary preference.
{
@@ -359,22 +355,18 @@ TEST_F(ExtensionManagementServiceTest, NewInstallSources) {
updater.ClearInstallSources();
}
// Verifies that the new one overrides the legacy ones.
- EXPECT_TRUE(extension_management_->ReadGlobalSettings()
- .has_restricted_install_sources);
- EXPECT_FALSE(
- extension_management_->ReadGlobalSettings()
- .install_sources.MatchesURL(GURL("https://www.example.com/foo")));
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
+ EXPECT_FALSE(ReadGlobalSettings()->install_sources.MatchesURL(
+ GURL("https://www.example.com/foo")));
// Updates the new dictionary preference.
{
PrefUpdater updater(pref_service_.get());
updater.AddInstallSource("https://corp.mycompany.com/*");
}
- EXPECT_TRUE(extension_management_->ReadGlobalSettings()
- .has_restricted_install_sources);
- EXPECT_TRUE(extension_management_->ReadGlobalSettings()
- .install_sources.MatchesURL(
- GURL("https://corp.mycompany.com/entry")));
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_install_sources);
+ EXPECT_TRUE(ReadGlobalSettings()->install_sources.MatchesURL(
+ GURL("https://corp.mycompany.com/entry")));
}
// Tests functionality of new preference as to deprecate legacy
@@ -384,12 +376,9 @@ TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) {
base::ListValue allowed_types_pref;
allowed_types_pref.AppendInteger(Manifest::TYPE_USER_SCRIPT);
SetPref(true, pref_names::kAllowedTypes, allowed_types_pref.DeepCopy());
- EXPECT_TRUE(
- extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
- EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(),
- 1u);
- EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0],
- Manifest::TYPE_USER_SCRIPT);
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
+ EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u);
+ EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_USER_SCRIPT);
// Set the new dictionary preference.
{
@@ -397,22 +386,17 @@ TEST_F(ExtensionManagementServiceTest, NewAllowedTypes) {
updater.ClearAllowedTypes();
}
// Verifies that the new one overrides the legacy ones.
- EXPECT_TRUE(
- extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
- EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(),
- 0u);
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
+ EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 0u);
// Updates the new dictionary preference.
{
PrefUpdater updater(pref_service_.get());
updater.AddAllowedType("theme");
}
- EXPECT_TRUE(
- extension_management_->ReadGlobalSettings().has_restricted_allowed_types);
- EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types.size(),
- 1u);
- EXPECT_EQ(extension_management_->ReadGlobalSettings().allowed_types[0],
- Manifest::TYPE_THEME);
+ EXPECT_TRUE(ReadGlobalSettings()->has_restricted_allowed_types);
+ EXPECT_EQ(ReadGlobalSettings()->allowed_types.size(), 1u);
+ EXPECT_EQ(ReadGlobalSettings()->allowed_types[0], Manifest::TYPE_THEME);
}
// Tests functionality of new preference as to deprecate legacy
@@ -427,9 +411,9 @@ TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) {
updater.ClearPerExtensionSettings(kOtherExtension);
}
EXPECT_FALSE(extension_management_->BlacklistedByDefault());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
// Set legacy preference.
@@ -444,12 +428,11 @@ TEST_F(ExtensionManagementServiceTest, NewInstallBlacklist) {
// Verifies that the new one have higher priority over the legacy ones.
EXPECT_FALSE(extension_management_->BlacklistedByDefault());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
+ ExtensionManagement::INSTALLATION_BLOCKED);
+ EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
- EXPECT_EQ(
- extension_management_->ReadById(kTargetExtension2).installation_mode,
- ExtensionManagement::INSTALLATION_BLOCKED);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
}
@@ -465,9 +448,9 @@ TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) {
updater.ClearPerExtensionSettings(kOtherExtension);
}
EXPECT_TRUE(extension_management_->BlacklistedByDefault());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
// Set legacy preference.
@@ -481,12 +464,11 @@ TEST_F(ExtensionManagementServiceTest, NewInstallWhitelist) {
// Verifies that the new one have higher priority over the legacy ones.
EXPECT_TRUE(extension_management_->BlacklistedByDefault());
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
+ ExtensionManagement::INSTALLATION_ALLOWED);
+ EXPECT_EQ(ReadById(kTargetExtension2)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
- EXPECT_EQ(
- extension_management_->ReadById(kTargetExtension2).installation_mode,
- ExtensionManagement::INSTALLATION_ALLOWED);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_BLOCKED);
}
@@ -506,11 +488,10 @@ TEST_F(ExtensionManagementServiceTest, NewInstallForcelist) {
kTargetExtension, kExampleUpdateUrl, true);
updater.ClearPerExtensionSettings(kOtherExtension);
}
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->installation_mode,
ExtensionManagement::INSTALLATION_FORCED);
- EXPECT_EQ(extension_management_->ReadById(kTargetExtension).update_url,
- kExampleUpdateUrl);
- EXPECT_EQ(extension_management_->ReadById(kOtherExtension).installation_mode,
+ EXPECT_EQ(ReadById(kTargetExtension)->update_url, kExampleUpdateUrl);
+ EXPECT_EQ(ReadById(kOtherExtension)->installation_mode,
ExtensionManagement::INSTALLATION_ALLOWED);
}

Powered by Google App Engine
This is Rietveld 408576698