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

Unified Diff: chrome/browser/policy/configuration_policy_handler_unittest.cc

Issue 10542048: Add a group policy controlling which sites can install extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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/policy/configuration_policy_handler_unittest.cc
diff --git a/chrome/browser/policy/configuration_policy_handler_unittest.cc b/chrome/browser/policy/configuration_policy_handler_unittest.cc
index 17bfeaab7733f09f39a6536dc3038c3bc5a4c21f..baba2ba1382f7bdcd787cf99bb11f311f637d667 100644
--- a/chrome/browser/policy/configuration_policy_handler_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_handler_unittest.cc
@@ -62,4 +62,63 @@ TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) {
EXPECT_TRUE(base::Value::Equals(&list, value));
}
+TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) {
+ base::ListValue list;
+ PolicyMap policy_map;
+ PolicyErrorMap errors;
+ ExtensionURLPatternListPolicyHandler handler(
+ key::kExtensionInstallSources,
+ prefs::kExtensionAllowedInstallSites);
+
+ policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, list.DeepCopy());
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ list.Append(Value::CreateStringValue("http://*.google.com/*"));
+ policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, list.DeepCopy());
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ list.Append(Value::CreateStringValue("<all_urls>"));
+ policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, list.DeepCopy());
+ EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_TRUE(errors.empty());
+
+ list.Append(Value::CreateStringValue("invalid"));
+ policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, list.DeepCopy());
+ EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_FALSE(errors.empty());
+ EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallSources).empty());
+
+ // URLPattern syntax has a different way to express 'all urls'. Though '*'
+ // would be compatible today, it would be brittle, so we disallow.
+ list.Append(Value::CreateStringValue("*"));
+ policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, list.DeepCopy());
+ EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
+ EXPECT_FALSE(errors.empty());
+ EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallSources).empty());
+}
+
+TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) {
+ base::ListValue list;
+ PolicyMap policy_map;
+ PrefValueMap prefs;
+ base::Value* value = NULL;
+ ExtensionURLPatternListPolicyHandler handler(
+ key::kExtensionInstallSources,
+ prefs::kExtensionAllowedInstallSites);
+
+ list.Append(Value::CreateStringValue("https://corp.monkey.net/*"));
+ policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, list.DeepCopy());
+ handler.ApplyPolicySettings(policy_map, &prefs);
+ EXPECT_TRUE(prefs.GetValue(prefs::kExtensionAllowedInstallSites, &value));
+ EXPECT_TRUE(base::Value::Equals(&list, value));
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698