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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/configuration_policy_handler.h" 5 #include "chrome/browser/policy/configuration_policy_handler.h"
6 #include "chrome/browser/policy/policy_error_map.h" 6 #include "chrome/browser/policy/policy_error_map.h"
7 #include "chrome/browser/policy/policy_map.h" 7 #include "chrome/browser/policy/policy_map.h"
8 #include "chrome/browser/prefs/pref_value_map.h" 8 #include "chrome/browser/prefs/pref_value_map.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "policy/policy_constants.h" 10 #include "policy/policy_constants.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 false); 55 false);
56 56
57 list.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop")); 57 list.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop"));
58 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, 58 policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY,
59 POLICY_SCOPE_USER, list.DeepCopy()); 59 POLICY_SCOPE_USER, list.DeepCopy());
60 handler.ApplyPolicySettings(policy_map, &prefs); 60 handler.ApplyPolicySettings(policy_map, &prefs);
61 EXPECT_TRUE(prefs.GetValue(prefs::kExtensionInstallDenyList, &value)); 61 EXPECT_TRUE(prefs.GetValue(prefs::kExtensionInstallDenyList, &value));
62 EXPECT_TRUE(base::Value::Equals(&list, value)); 62 EXPECT_TRUE(base::Value::Equals(&list, value));
63 } 63 }
64 64
65 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) {
66 base::ListValue list;
67 PolicyMap policy_map;
68 PolicyErrorMap errors;
69 ExtensionURLPatternListPolicyHandler handler(
70 key::kExtensionInstallSources,
71 prefs::kExtensionAllowedInstallSites);
72
73 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
74 POLICY_SCOPE_USER, list.DeepCopy());
75 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
76 EXPECT_TRUE(errors.empty());
77
78 list.Append(Value::CreateStringValue("http://*.google.com/*"));
79 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
80 POLICY_SCOPE_USER, list.DeepCopy());
81 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
82 EXPECT_TRUE(errors.empty());
83
84 list.Append(Value::CreateStringValue("<all_urls>"));
85 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
86 POLICY_SCOPE_USER, list.DeepCopy());
87 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
88 EXPECT_TRUE(errors.empty());
89
90 list.Append(Value::CreateStringValue("invalid"));
91 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
92 POLICY_SCOPE_USER, list.DeepCopy());
93 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
94 EXPECT_FALSE(errors.empty());
95 EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallSources).empty());
96
97 // URLPattern syntax has a different way to express 'all urls'. Though '*'
98 // would be compatible today, it would be brittle, so we disallow.
99 list.Append(Value::CreateStringValue("*"));
100 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
101 POLICY_SCOPE_USER, list.DeepCopy());
102 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
103 EXPECT_FALSE(errors.empty());
104 EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallSources).empty());
105 }
106
107 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) {
108 base::ListValue list;
109 PolicyMap policy_map;
110 PrefValueMap prefs;
111 base::Value* value = NULL;
112 ExtensionURLPatternListPolicyHandler handler(
113 key::kExtensionInstallSources,
114 prefs::kExtensionAllowedInstallSites);
115
116 list.Append(Value::CreateStringValue("https://corp.monkey.net/*"));
117 policy_map.Set(key::kExtensionInstallSources, POLICY_LEVEL_MANDATORY,
118 POLICY_SCOPE_USER, list.DeepCopy());
119 handler.ApplyPolicySettings(policy_map, &prefs);
120 EXPECT_TRUE(prefs.GetValue(prefs::kExtensionAllowedInstallSites, &value));
121 EXPECT_TRUE(base::Value::Equals(&list, value));
122 }
123
65 } // namespace policy 124 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698