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

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

Issue 1350913006: Revert of Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/prefs/pref_value_map.h" 6 #include "base/prefs/pref_value_map.h"
7 #include "chrome/browser/extensions/external_policy_loader.h" 7 #include "chrome/browser/extensions/external_policy_loader.h"
8 #include "chrome/browser/extensions/policy_handlers.h" 8 #include "chrome/browser/extensions/policy_handlers.h"
9 #include "components/policy/core/browser/policy_error_map.h" 9 #include "components/policy/core/browser/policy_error_map.h"
10 #include "components/policy/core/common/policy_map.h" 10 #include "components/policy/core/common/policy_map.h"
11 #include "components/policy/core/common/policy_types.h"
12 #include "components/policy/core/common/schema.h" 11 #include "components/policy/core/common/schema.h"
13 #include "extensions/browser/pref_names.h" 12 #include "extensions/browser/pref_names.h"
14 #include "policy/policy_constants.h" 13 #include "policy/policy_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
16 15
17 namespace extensions { 16 namespace extensions {
18 17
19 const char kTestPref[] = "unit_test.test_pref"; 18 const char kTestPref[] = "unit_test.test_pref";
20 const char kTestManagementPolicy1[] = 19 const char kTestManagementPolicy1[] =
21 "{" 20 "{"
(...skipping 15 matching lines...) Expand all
37 TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) { 36 TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) {
38 base::ListValue list; 37 base::ListValue list;
39 policy::PolicyMap policy_map; 38 policy::PolicyMap policy_map;
40 policy::PolicyErrorMap errors; 39 policy::PolicyErrorMap errors;
41 ExtensionListPolicyHandler handler( 40 ExtensionListPolicyHandler handler(
42 policy::key::kExtensionInstallBlacklist, kTestPref, true); 41 policy::key::kExtensionInstallBlacklist, kTestPref, true);
43 42
44 policy_map.Set(policy::key::kExtensionInstallBlacklist, 43 policy_map.Set(policy::key::kExtensionInstallBlacklist,
45 policy::POLICY_LEVEL_MANDATORY, 44 policy::POLICY_LEVEL_MANDATORY,
46 policy::POLICY_SCOPE_USER, 45 policy::POLICY_SCOPE_USER,
47 policy::POLICY_SOURCE_CLOUD,
48 list.DeepCopy(), 46 list.DeepCopy(),
49 NULL); 47 NULL);
50 errors.Clear(); 48 errors.Clear();
51 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 49 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
52 EXPECT_TRUE(errors.empty()); 50 EXPECT_TRUE(errors.empty());
53 51
54 list.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); 52 list.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop"));
55 policy_map.Set(policy::key::kExtensionInstallBlacklist, 53 policy_map.Set(policy::key::kExtensionInstallBlacklist,
56 policy::POLICY_LEVEL_MANDATORY, 54 policy::POLICY_LEVEL_MANDATORY,
57 policy::POLICY_SCOPE_USER, 55 policy::POLICY_SCOPE_USER,
58 policy::POLICY_SOURCE_CLOUD,
59 list.DeepCopy(), 56 list.DeepCopy(),
60 NULL); 57 NULL);
61 errors.Clear(); 58 errors.Clear();
62 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 59 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
63 EXPECT_TRUE(errors.empty()); 60 EXPECT_TRUE(errors.empty());
64 61
65 list.Append(new base::StringValue("*")); 62 list.Append(new base::StringValue("*"));
66 policy_map.Set(policy::key::kExtensionInstallBlacklist, 63 policy_map.Set(policy::key::kExtensionInstallBlacklist,
67 policy::POLICY_LEVEL_MANDATORY, 64 policy::POLICY_LEVEL_MANDATORY,
68 policy::POLICY_SCOPE_USER, 65 policy::POLICY_SCOPE_USER,
69 policy::POLICY_SOURCE_CLOUD,
70 list.DeepCopy(), 66 list.DeepCopy(),
71 NULL); 67 NULL);
72 errors.Clear(); 68 errors.Clear();
73 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 69 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
74 EXPECT_TRUE(errors.empty()); 70 EXPECT_TRUE(errors.empty());
75 71
76 list.Append(new base::StringValue("invalid")); 72 list.Append(new base::StringValue("invalid"));
77 policy_map.Set(policy::key::kExtensionInstallBlacklist, 73 policy_map.Set(policy::key::kExtensionInstallBlacklist,
78 policy::POLICY_LEVEL_MANDATORY, 74 policy::POLICY_LEVEL_MANDATORY,
79 policy::POLICY_SCOPE_USER, 75 policy::POLICY_SCOPE_USER,
80 policy::POLICY_SOURCE_CLOUD,
81 list.DeepCopy(), 76 list.DeepCopy(),
82 NULL); 77 NULL);
83 errors.Clear(); 78 errors.Clear();
84 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 79 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
85 EXPECT_FALSE(errors.empty()); 80 EXPECT_FALSE(errors.empty());
86 EXPECT_FALSE( 81 EXPECT_FALSE(
87 errors.GetErrors(policy::key::kExtensionInstallBlacklist).empty()); 82 errors.GetErrors(policy::key::kExtensionInstallBlacklist).empty());
88 } 83 }
89 84
90 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) { 85 TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) {
91 base::ListValue policy; 86 base::ListValue policy;
92 base::ListValue expected; 87 base::ListValue expected;
93 policy::PolicyMap policy_map; 88 policy::PolicyMap policy_map;
94 PrefValueMap prefs; 89 PrefValueMap prefs;
95 base::Value* value = NULL; 90 base::Value* value = NULL;
96 ExtensionListPolicyHandler handler( 91 ExtensionListPolicyHandler handler(
97 policy::key::kExtensionInstallBlacklist, kTestPref, false); 92 policy::key::kExtensionInstallBlacklist, kTestPref, false);
98 93
99 policy.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); 94 policy.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop"));
100 expected.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop")); 95 expected.Append(new base::StringValue("abcdefghijklmnopabcdefghijklmnop"));
101 96
102 policy_map.Set(policy::key::kExtensionInstallBlacklist, 97 policy_map.Set(policy::key::kExtensionInstallBlacklist,
103 policy::POLICY_LEVEL_MANDATORY, 98 policy::POLICY_LEVEL_MANDATORY,
104 policy::POLICY_SCOPE_USER, 99 policy::POLICY_SCOPE_USER,
105 policy::POLICY_SOURCE_CLOUD,
106 policy.DeepCopy(), 100 policy.DeepCopy(),
107 NULL); 101 NULL);
108 handler.ApplyPolicySettings(policy_map, &prefs); 102 handler.ApplyPolicySettings(policy_map, &prefs);
109 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 103 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
110 EXPECT_TRUE(base::Value::Equals(&expected, value)); 104 EXPECT_TRUE(base::Value::Equals(&expected, value));
111 105
112 policy.Append(new base::StringValue("invalid")); 106 policy.Append(new base::StringValue("invalid"));
113 policy_map.Set(policy::key::kExtensionInstallBlacklist, 107 policy_map.Set(policy::key::kExtensionInstallBlacklist,
114 policy::POLICY_LEVEL_MANDATORY, 108 policy::POLICY_LEVEL_MANDATORY,
115 policy::POLICY_SCOPE_USER, 109 policy::POLICY_SCOPE_USER,
116 policy::POLICY_SOURCE_CLOUD,
117 policy.DeepCopy(), 110 policy.DeepCopy(),
118 NULL); 111 NULL);
119 handler.ApplyPolicySettings(policy_map, &prefs); 112 handler.ApplyPolicySettings(policy_map, &prefs);
120 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); 113 EXPECT_TRUE(prefs.GetValue(kTestPref, &value));
121 EXPECT_TRUE(base::Value::Equals(&expected, value)); 114 EXPECT_TRUE(base::Value::Equals(&expected, value));
122 } 115 }
123 116
124 TEST(ExtensionInstallForcelistPolicyHandlerTest, CheckPolicySettings) { 117 TEST(ExtensionInstallForcelistPolicyHandlerTest, CheckPolicySettings) {
125 base::ListValue list; 118 base::ListValue list;
126 policy::PolicyMap policy_map; 119 policy::PolicyMap policy_map;
127 policy::PolicyErrorMap errors; 120 policy::PolicyErrorMap errors;
128 ExtensionInstallForcelistPolicyHandler handler; 121 ExtensionInstallForcelistPolicyHandler handler;
129 122
130 policy_map.Set(policy::key::kExtensionInstallForcelist, 123 policy_map.Set(policy::key::kExtensionInstallForcelist,
131 policy::POLICY_LEVEL_MANDATORY, 124 policy::POLICY_LEVEL_MANDATORY,
132 policy::POLICY_SCOPE_USER, 125 policy::POLICY_SCOPE_USER,
133 policy::POLICY_SOURCE_CLOUD,
134 list.DeepCopy(), 126 list.DeepCopy(),
135 NULL); 127 NULL);
136 errors.Clear(); 128 errors.Clear();
137 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 129 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
138 EXPECT_TRUE(errors.empty()); 130 EXPECT_TRUE(errors.empty());
139 131
140 list.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com"); 132 list.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com");
141 policy_map.Set(policy::key::kExtensionInstallForcelist, 133 policy_map.Set(policy::key::kExtensionInstallForcelist,
142 policy::POLICY_LEVEL_MANDATORY, 134 policy::POLICY_LEVEL_MANDATORY,
143 policy::POLICY_SCOPE_USER, 135 policy::POLICY_SCOPE_USER,
144 policy::POLICY_SOURCE_CLOUD,
145 list.DeepCopy(), 136 list.DeepCopy(),
146 NULL); 137 NULL);
147 errors.Clear(); 138 errors.Clear();
148 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 139 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
149 EXPECT_TRUE(errors.empty()); 140 EXPECT_TRUE(errors.empty());
150 141
151 // Add an erroneous entry. This should generate an error, but the good 142 // Add an erroneous entry. This should generate an error, but the good
152 // entry should still be translated successfully. 143 // entry should still be translated successfully.
153 list.AppendString("adfasdf;http://example.com"); 144 list.AppendString("adfasdf;http://example.com");
154 policy_map.Set(policy::key::kExtensionInstallForcelist, 145 policy_map.Set(policy::key::kExtensionInstallForcelist,
155 policy::POLICY_LEVEL_MANDATORY, 146 policy::POLICY_LEVEL_MANDATORY,
156 policy::POLICY_SCOPE_USER, 147 policy::POLICY_SCOPE_USER,
157 policy::POLICY_SOURCE_CLOUD,
158 list.DeepCopy(), 148 list.DeepCopy(),
159 NULL); 149 NULL);
160 errors.Clear(); 150 errors.Clear();
161 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 151 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
162 EXPECT_EQ(1U, errors.size()); 152 EXPECT_EQ(1U, errors.size());
163 153
164 // Add an entry with bad URL, which should generate another error. 154 // Add an entry with bad URL, which should generate another error.
165 list.AppendString("abcdefghijklmnopabcdefghijklmnop;nourl"); 155 list.AppendString("abcdefghijklmnopabcdefghijklmnop;nourl");
166 policy_map.Set(policy::key::kExtensionInstallForcelist, 156 policy_map.Set(policy::key::kExtensionInstallForcelist,
167 policy::POLICY_LEVEL_MANDATORY, 157 policy::POLICY_LEVEL_MANDATORY,
168 policy::POLICY_SCOPE_USER, 158 policy::POLICY_SCOPE_USER,
169 policy::POLICY_SOURCE_CLOUD,
170 list.DeepCopy(), 159 list.DeepCopy(),
171 NULL); 160 NULL);
172 errors.Clear(); 161 errors.Clear();
173 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 162 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
174 EXPECT_EQ(2U, errors.size()); 163 EXPECT_EQ(2U, errors.size());
175 164
176 // Just an extension ID should also generate an error. 165 // Just an extension ID should also generate an error.
177 list.AppendString("abcdefghijklmnopabcdefghijklmnop"); 166 list.AppendString("abcdefghijklmnopabcdefghijklmnop");
178 policy_map.Set(policy::key::kExtensionInstallForcelist, 167 policy_map.Set(policy::key::kExtensionInstallForcelist,
179 policy::POLICY_LEVEL_MANDATORY, 168 policy::POLICY_LEVEL_MANDATORY,
180 policy::POLICY_SCOPE_USER, 169 policy::POLICY_SCOPE_USER,
181 policy::POLICY_SOURCE_CLOUD,
182 list.DeepCopy(), 170 list.DeepCopy(),
183 NULL); 171 NULL);
184 errors.Clear(); 172 errors.Clear();
185 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 173 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
186 EXPECT_EQ(3U, errors.size()); 174 EXPECT_EQ(3U, errors.size());
187 } 175 }
188 176
189 TEST(ExtensionInstallForcelistPolicyHandlerTest, ApplyPolicySettings) { 177 TEST(ExtensionInstallForcelistPolicyHandlerTest, ApplyPolicySettings) {
190 base::ListValue policy; 178 base::ListValue policy;
191 base::DictionaryValue expected; 179 base::DictionaryValue expected;
192 policy::PolicyMap policy_map; 180 policy::PolicyMap policy_map;
193 PrefValueMap prefs; 181 PrefValueMap prefs;
194 base::Value* value = NULL; 182 base::Value* value = NULL;
195 ExtensionInstallForcelistPolicyHandler handler; 183 ExtensionInstallForcelistPolicyHandler handler;
196 184
197 handler.ApplyPolicySettings(policy_map, &prefs); 185 handler.ApplyPolicySettings(policy_map, &prefs);
198 EXPECT_FALSE(prefs.GetValue(pref_names::kInstallForceList, &value)); 186 EXPECT_FALSE(prefs.GetValue(pref_names::kInstallForceList, &value));
199 EXPECT_FALSE(value); 187 EXPECT_FALSE(value);
200 188
201 policy_map.Set(policy::key::kExtensionInstallForcelist, 189 policy_map.Set(policy::key::kExtensionInstallForcelist,
202 policy::POLICY_LEVEL_MANDATORY, 190 policy::POLICY_LEVEL_MANDATORY,
203 policy::POLICY_SCOPE_USER, 191 policy::POLICY_SCOPE_USER,
204 policy::POLICY_SOURCE_CLOUD,
205 policy.DeepCopy(), 192 policy.DeepCopy(),
206 NULL); 193 NULL);
207 handler.ApplyPolicySettings(policy_map, &prefs); 194 handler.ApplyPolicySettings(policy_map, &prefs);
208 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); 195 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value));
209 EXPECT_TRUE(base::Value::Equals(&expected, value)); 196 EXPECT_TRUE(base::Value::Equals(&expected, value));
210 197
211 policy.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com"); 198 policy.AppendString("abcdefghijklmnopabcdefghijklmnop;http://example.com");
212 extensions::ExternalPolicyLoader::AddExtension( 199 extensions::ExternalPolicyLoader::AddExtension(
213 &expected, "abcdefghijklmnopabcdefghijklmnop", "http://example.com"); 200 &expected, "abcdefghijklmnopabcdefghijklmnop", "http://example.com");
214 policy_map.Set(policy::key::kExtensionInstallForcelist, 201 policy_map.Set(policy::key::kExtensionInstallForcelist,
215 policy::POLICY_LEVEL_MANDATORY, 202 policy::POLICY_LEVEL_MANDATORY,
216 policy::POLICY_SCOPE_USER, 203 policy::POLICY_SCOPE_USER,
217 policy::POLICY_SOURCE_CLOUD,
218 policy.DeepCopy(), 204 policy.DeepCopy(),
219 NULL); 205 NULL);
220 handler.ApplyPolicySettings(policy_map, &prefs); 206 handler.ApplyPolicySettings(policy_map, &prefs);
221 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); 207 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value));
222 EXPECT_TRUE(base::Value::Equals(&expected, value)); 208 EXPECT_TRUE(base::Value::Equals(&expected, value));
223 209
224 policy.AppendString("invalid"); 210 policy.AppendString("invalid");
225 policy_map.Set(policy::key::kExtensionInstallForcelist, 211 policy_map.Set(policy::key::kExtensionInstallForcelist,
226 policy::POLICY_LEVEL_MANDATORY, 212 policy::POLICY_LEVEL_MANDATORY,
227 policy::POLICY_SCOPE_USER, 213 policy::POLICY_SCOPE_USER,
228 policy::POLICY_SOURCE_CLOUD,
229 policy.DeepCopy(), 214 policy.DeepCopy(),
230 NULL); 215 NULL);
231 handler.ApplyPolicySettings(policy_map, &prefs); 216 handler.ApplyPolicySettings(policy_map, &prefs);
232 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value)); 217 EXPECT_TRUE(prefs.GetValue(pref_names::kInstallForceList, &value));
233 EXPECT_TRUE(base::Value::Equals(&expected, value)); 218 EXPECT_TRUE(base::Value::Equals(&expected, value));
234 } 219 }
235 220
236 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) { 221 TEST(ExtensionURLPatternListPolicyHandlerTest, CheckPolicySettings) {
237 base::ListValue list; 222 base::ListValue list;
238 policy::PolicyMap policy_map; 223 policy::PolicyMap policy_map;
239 policy::PolicyErrorMap errors; 224 policy::PolicyErrorMap errors;
240 ExtensionURLPatternListPolicyHandler handler( 225 ExtensionURLPatternListPolicyHandler handler(
241 policy::key::kExtensionInstallSources, kTestPref); 226 policy::key::kExtensionInstallSources, kTestPref);
242 227
243 policy_map.Set(policy::key::kExtensionInstallSources, 228 policy_map.Set(policy::key::kExtensionInstallSources,
244 policy::POLICY_LEVEL_MANDATORY, 229 policy::POLICY_LEVEL_MANDATORY,
245 policy::POLICY_SCOPE_USER, 230 policy::POLICY_SCOPE_USER,
246 policy::POLICY_SOURCE_CLOUD,
247 list.DeepCopy(), 231 list.DeepCopy(),
248 NULL); 232 NULL);
249 errors.Clear(); 233 errors.Clear();
250 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 234 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
251 EXPECT_TRUE(errors.empty()); 235 EXPECT_TRUE(errors.empty());
252 236
253 list.Append(new base::StringValue("http://*.google.com/*")); 237 list.Append(new base::StringValue("http://*.google.com/*"));
254 policy_map.Set(policy::key::kExtensionInstallSources, 238 policy_map.Set(policy::key::kExtensionInstallSources,
255 policy::POLICY_LEVEL_MANDATORY, 239 policy::POLICY_LEVEL_MANDATORY,
256 policy::POLICY_SCOPE_USER, 240 policy::POLICY_SCOPE_USER,
257 policy::POLICY_SOURCE_CLOUD,
258 list.DeepCopy(), 241 list.DeepCopy(),
259 NULL); 242 NULL);
260 errors.Clear(); 243 errors.Clear();
261 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 244 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
262 EXPECT_TRUE(errors.empty()); 245 EXPECT_TRUE(errors.empty());
263 246
264 list.Append(new base::StringValue("<all_urls>")); 247 list.Append(new base::StringValue("<all_urls>"));
265 policy_map.Set(policy::key::kExtensionInstallSources, 248 policy_map.Set(policy::key::kExtensionInstallSources,
266 policy::POLICY_LEVEL_MANDATORY, 249 policy::POLICY_LEVEL_MANDATORY,
267 policy::POLICY_SCOPE_USER, 250 policy::POLICY_SCOPE_USER,
268 policy::POLICY_SOURCE_CLOUD,
269 list.DeepCopy(), 251 list.DeepCopy(),
270 NULL); 252 NULL);
271 errors.Clear(); 253 errors.Clear();
272 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 254 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
273 EXPECT_TRUE(errors.empty()); 255 EXPECT_TRUE(errors.empty());
274 256
275 list.Append(new base::StringValue("invalid")); 257 list.Append(new base::StringValue("invalid"));
276 policy_map.Set(policy::key::kExtensionInstallSources, 258 policy_map.Set(policy::key::kExtensionInstallSources,
277 policy::POLICY_LEVEL_MANDATORY, 259 policy::POLICY_LEVEL_MANDATORY,
278 policy::POLICY_SCOPE_USER, 260 policy::POLICY_SCOPE_USER,
279 policy::POLICY_SOURCE_CLOUD,
280 list.DeepCopy(), 261 list.DeepCopy(),
281 NULL); 262 NULL);
282 errors.Clear(); 263 errors.Clear();
283 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 264 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
284 EXPECT_FALSE(errors.empty()); 265 EXPECT_FALSE(errors.empty());
285 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); 266 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty());
286 267
287 // URLPattern syntax has a different way to express 'all urls'. Though '*' 268 // URLPattern syntax has a different way to express 'all urls'. Though '*'
288 // would be compatible today, it would be brittle, so we disallow. 269 // would be compatible today, it would be brittle, so we disallow.
289 list.Append(new base::StringValue("*")); 270 list.Append(new base::StringValue("*"));
290 policy_map.Set(policy::key::kExtensionInstallSources, 271 policy_map.Set(policy::key::kExtensionInstallSources,
291 policy::POLICY_LEVEL_MANDATORY, 272 policy::POLICY_LEVEL_MANDATORY,
292 policy::POLICY_SCOPE_USER, 273 policy::POLICY_SCOPE_USER,
293 policy::POLICY_SOURCE_CLOUD,
294 list.DeepCopy(), 274 list.DeepCopy(),
295 NULL); 275 NULL);
296 errors.Clear(); 276 errors.Clear();
297 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 277 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
298 EXPECT_FALSE(errors.empty()); 278 EXPECT_FALSE(errors.empty());
299 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty()); 279 EXPECT_FALSE(errors.GetErrors(policy::key::kExtensionInstallSources).empty());
300 } 280 }
301 281
302 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) { 282 TEST(ExtensionURLPatternListPolicyHandlerTest, ApplyPolicySettings) {
303 base::ListValue list; 283 base::ListValue list;
304 policy::PolicyMap policy_map; 284 policy::PolicyMap policy_map;
305 PrefValueMap prefs; 285 PrefValueMap prefs;
306 base::Value* value = NULL; 286 base::Value* value = NULL;
307 ExtensionURLPatternListPolicyHandler handler( 287 ExtensionURLPatternListPolicyHandler handler(
308 policy::key::kExtensionInstallSources, kTestPref); 288 policy::key::kExtensionInstallSources, kTestPref);
309 289
310 list.Append(new base::StringValue("https://corp.monkey.net/*")); 290 list.Append(new base::StringValue("https://corp.monkey.net/*"));
311 policy_map.Set(policy::key::kExtensionInstallSources, 291 policy_map.Set(policy::key::kExtensionInstallSources,
312 policy::POLICY_LEVEL_MANDATORY, 292 policy::POLICY_LEVEL_MANDATORY,
313 policy::POLICY_SCOPE_USER, 293 policy::POLICY_SCOPE_USER,
314 policy::POLICY_SOURCE_CLOUD,
315 list.DeepCopy(), 294 list.DeepCopy(),
316 NULL); 295 NULL);
317 handler.ApplyPolicySettings(policy_map, &prefs); 296 handler.ApplyPolicySettings(policy_map, &prefs);
318 ASSERT_TRUE(prefs.GetValue(kTestPref, &value)); 297 ASSERT_TRUE(prefs.GetValue(kTestPref, &value));
319 EXPECT_TRUE(base::Value::Equals(&list, value)); 298 EXPECT_TRUE(base::Value::Equals(&list, value));
320 } 299 }
321 300
322 TEST(ExtensionSettingsPolicyHandlerTest, CheckPolicySettings) { 301 TEST(ExtensionSettingsPolicyHandlerTest, CheckPolicySettings) {
323 std::string error; 302 std::string error;
324 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError( 303 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError(
325 kTestManagementPolicy1, 304 kTestManagementPolicy1,
326 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); 305 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
327 ASSERT_TRUE(policy_value.get()) << error; 306 ASSERT_TRUE(policy_value.get()) << error;
328 307
329 policy::Schema chrome_schema = 308 policy::Schema chrome_schema =
330 policy::Schema::Wrap(policy::GetChromeSchemaData()); 309 policy::Schema::Wrap(policy::GetChromeSchemaData());
331 policy::PolicyMap policy_map; 310 policy::PolicyMap policy_map;
332 policy::PolicyErrorMap errors; 311 policy::PolicyErrorMap errors;
333 ExtensionSettingsPolicyHandler handler(chrome_schema); 312 ExtensionSettingsPolicyHandler handler(chrome_schema);
334 313
335 policy_map.Set(policy::key::kExtensionSettings, 314 policy_map.Set(policy::key::kExtensionSettings,
336 policy::POLICY_LEVEL_MANDATORY, 315 policy::POLICY_LEVEL_MANDATORY,
337 policy::POLICY_SCOPE_USER, 316 policy::POLICY_SCOPE_USER,
338 policy::POLICY_SOURCE_CLOUD,
339 policy_value.release(), 317 policy_value.release(),
340 NULL); 318 NULL);
341 // CheckPolicySettings() fails due to missing update URL. 319 // CheckPolicySettings() fails due to missing update URL.
342 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 320 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
343 EXPECT_FALSE(errors.empty()); 321 EXPECT_FALSE(errors.empty());
344 } 322 }
345 323
346 TEST(ExtensionSettingsPolicyHandlerTest, ApplyPolicySettings) { 324 TEST(ExtensionSettingsPolicyHandlerTest, ApplyPolicySettings) {
347 std::string error; 325 std::string error;
348 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError( 326 scoped_ptr<base::Value> policy_value = base::JSONReader::ReadAndReturnError(
349 kTestManagementPolicy2, 327 kTestManagementPolicy2,
350 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error); 328 base::JSONParserOptions::JSON_ALLOW_TRAILING_COMMAS, NULL, &error);
351 ASSERT_TRUE(policy_value.get()) << error; 329 ASSERT_TRUE(policy_value.get()) << error;
352 330
353 policy::Schema chrome_schema = 331 policy::Schema chrome_schema =
354 policy::Schema::Wrap(policy::GetChromeSchemaData()); 332 policy::Schema::Wrap(policy::GetChromeSchemaData());
355 policy::PolicyMap policy_map; 333 policy::PolicyMap policy_map;
356 policy::PolicyErrorMap errors; 334 policy::PolicyErrorMap errors;
357 PrefValueMap prefs; 335 PrefValueMap prefs;
358 ExtensionSettingsPolicyHandler handler(chrome_schema); 336 ExtensionSettingsPolicyHandler handler(chrome_schema);
359 337
360 policy_map.Set(policy::key::kExtensionSettings, 338 policy_map.Set(policy::key::kExtensionSettings,
361 policy::POLICY_LEVEL_MANDATORY, 339 policy::POLICY_LEVEL_MANDATORY,
362 policy::POLICY_SCOPE_USER, 340 policy::POLICY_SCOPE_USER,
363 policy::POLICY_SOURCE_CLOUD,
364 policy_value->DeepCopy(), 341 policy_value->DeepCopy(),
365 NULL); 342 NULL);
366 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 343 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
367 handler.ApplyPolicySettings(policy_map, &prefs); 344 handler.ApplyPolicySettings(policy_map, &prefs);
368 base::Value* value = NULL; 345 base::Value* value = NULL;
369 ASSERT_TRUE(prefs.GetValue(pref_names::kExtensionManagement, &value)); 346 ASSERT_TRUE(prefs.GetValue(pref_names::kExtensionManagement, &value));
370 EXPECT_TRUE(base::Value::Equals(policy_value.get(), value)); 347 EXPECT_TRUE(base::Value::Equals(policy_value.get(), value));
371 } 348 }
372 349
373 } // namespace extensions 350 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698