OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_value_map.h" | 9 #include "base/prefs/pref_value_map.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 TEST(IntRangePolicyHandler, CheckPolicySettingsClamp) { | 124 TEST(IntRangePolicyHandler, CheckPolicySettingsClamp) { |
125 PolicyMap policy_map; | 125 PolicyMap policy_map; |
126 PolicyErrorMap errors; | 126 PolicyErrorMap errors; |
127 | 127 |
128 // This tests needs to modify an int policy. The exact policy used and its | 128 // This tests needs to modify an int policy. The exact policy used and its |
129 // semantics outside the test are irrelevant. | 129 // semantics outside the test are irrelevant. |
130 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, true); | 130 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, true); |
131 | 131 |
132 // Check that values lying in the accepted range are not rejected. | 132 // Check that values lying in the accepted range are not rejected. |
133 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 133 policy_map.Set(kTestPolicy, |
134 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 134 POLICY_LEVEL_MANDATORY, |
| 135 POLICY_SCOPE_USER, |
| 136 new base::FundamentalValue(0), |
| 137 NULL); |
135 errors.Clear(); | 138 errors.Clear(); |
136 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 139 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
137 EXPECT_TRUE(errors.empty()); | 140 EXPECT_TRUE(errors.empty()); |
138 | 141 |
139 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 142 policy_map.Set(kTestPolicy, |
140 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 143 POLICY_LEVEL_MANDATORY, |
| 144 POLICY_SCOPE_USER, |
| 145 new base::FundamentalValue(5), |
| 146 NULL); |
141 errors.Clear(); | 147 errors.Clear(); |
142 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 148 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
143 EXPECT_TRUE(errors.empty()); | 149 EXPECT_TRUE(errors.empty()); |
144 | 150 |
145 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 151 policy_map.Set(kTestPolicy, |
146 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 152 POLICY_LEVEL_MANDATORY, |
| 153 POLICY_SCOPE_USER, |
| 154 new base::FundamentalValue(10), |
| 155 NULL); |
147 errors.Clear(); | 156 errors.Clear(); |
148 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 157 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
149 EXPECT_TRUE(errors.empty()); | 158 EXPECT_TRUE(errors.empty()); |
150 | 159 |
151 // Check that values lying outside the accepted range are not rejected | 160 // Check that values lying outside the accepted range are not rejected |
152 // (because clamping is enabled) but do yield a warning message. | 161 // (because clamping is enabled) but do yield a warning message. |
153 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 162 policy_map.Set(kTestPolicy, |
154 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(-5), NULL); | 163 POLICY_LEVEL_MANDATORY, |
| 164 POLICY_SCOPE_USER, |
| 165 new base::FundamentalValue(-5), |
| 166 NULL); |
155 errors.Clear(); | 167 errors.Clear(); |
156 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 168 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
157 EXPECT_FALSE(errors.empty()); | 169 EXPECT_FALSE(errors.empty()); |
158 | 170 |
159 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 171 policy_map.Set(kTestPolicy, |
160 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(15), NULL); | 172 POLICY_LEVEL_MANDATORY, |
| 173 POLICY_SCOPE_USER, |
| 174 new base::FundamentalValue(15), |
| 175 NULL); |
161 errors.Clear(); | 176 errors.Clear(); |
162 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 177 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
163 EXPECT_FALSE(errors.empty()); | 178 EXPECT_FALSE(errors.empty()); |
164 | 179 |
165 // Check that an entirely invalid value is rejected and yields an error | 180 // Check that an entirely invalid value is rejected and yields an error |
166 // message. | 181 // message. |
167 policy_map.Set(kTestPolicy, | 182 policy_map.Set(kTestPolicy, |
168 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 183 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
169 base::Value::CreateStringValue("invalid"), NULL); | 184 base::Value::CreateStringValue("invalid"), NULL); |
170 errors.Clear(); | 185 errors.Clear(); |
171 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 186 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
172 EXPECT_FALSE(errors.empty()); | 187 EXPECT_FALSE(errors.empty()); |
173 } | 188 } |
174 | 189 |
175 TEST(IntRangePolicyHandler, CheckPolicySettingsDontClamp) { | 190 TEST(IntRangePolicyHandler, CheckPolicySettingsDontClamp) { |
176 PolicyMap policy_map; | 191 PolicyMap policy_map; |
177 PolicyErrorMap errors; | 192 PolicyErrorMap errors; |
178 | 193 |
179 // This tests needs to modify an int policy. The exact policy used and its | 194 // This tests needs to modify an int policy. The exact policy used and its |
180 // semantics outside the test are irrelevant. | 195 // semantics outside the test are irrelevant. |
181 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, false); | 196 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, false); |
182 | 197 |
183 // Check that values lying in the accepted range are not rejected. | 198 // Check that values lying in the accepted range are not rejected. |
184 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 199 policy_map.Set(kTestPolicy, |
185 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 200 POLICY_LEVEL_MANDATORY, |
| 201 POLICY_SCOPE_USER, |
| 202 new base::FundamentalValue(0), |
| 203 NULL); |
186 errors.Clear(); | 204 errors.Clear(); |
187 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 205 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
188 EXPECT_TRUE(errors.empty()); | 206 EXPECT_TRUE(errors.empty()); |
189 | 207 |
190 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 208 policy_map.Set(kTestPolicy, |
191 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 209 POLICY_LEVEL_MANDATORY, |
| 210 POLICY_SCOPE_USER, |
| 211 new base::FundamentalValue(5), |
| 212 NULL); |
192 errors.Clear(); | 213 errors.Clear(); |
193 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 214 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
194 EXPECT_TRUE(errors.empty()); | 215 EXPECT_TRUE(errors.empty()); |
195 | 216 |
196 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 217 policy_map.Set(kTestPolicy, |
197 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 218 POLICY_LEVEL_MANDATORY, |
| 219 POLICY_SCOPE_USER, |
| 220 new base::FundamentalValue(10), |
| 221 NULL); |
198 errors.Clear(); | 222 errors.Clear(); |
199 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 223 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
200 EXPECT_TRUE(errors.empty()); | 224 EXPECT_TRUE(errors.empty()); |
201 | 225 |
202 // Check that values lying outside the accepted range are rejected and yield | 226 // Check that values lying outside the accepted range are rejected and yield |
203 // an error message. | 227 // an error message. |
204 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 228 policy_map.Set(kTestPolicy, |
205 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(-5), NULL); | 229 POLICY_LEVEL_MANDATORY, |
| 230 POLICY_SCOPE_USER, |
| 231 new base::FundamentalValue(-5), |
| 232 NULL); |
206 errors.Clear(); | 233 errors.Clear(); |
207 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 234 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
208 EXPECT_FALSE(errors.empty()); | 235 EXPECT_FALSE(errors.empty()); |
209 | 236 |
210 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 237 policy_map.Set(kTestPolicy, |
211 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(15), NULL); | 238 POLICY_LEVEL_MANDATORY, |
| 239 POLICY_SCOPE_USER, |
| 240 new base::FundamentalValue(15), |
| 241 NULL); |
212 errors.Clear(); | 242 errors.Clear(); |
213 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 243 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
214 EXPECT_FALSE(errors.empty()); | 244 EXPECT_FALSE(errors.empty()); |
215 | 245 |
216 // Check that an entirely invalid value is rejected and yields an error | 246 // Check that an entirely invalid value is rejected and yields an error |
217 // message. | 247 // message. |
218 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 248 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
219 base::Value::CreateStringValue("invalid"), NULL); | 249 base::Value::CreateStringValue("invalid"), NULL); |
220 errors.Clear(); | 250 errors.Clear(); |
221 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 251 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
222 EXPECT_FALSE(errors.empty()); | 252 EXPECT_FALSE(errors.empty()); |
223 } | 253 } |
224 | 254 |
225 TEST(IntRangePolicyHandler, ApplyPolicySettingsClamp) { | 255 TEST(IntRangePolicyHandler, ApplyPolicySettingsClamp) { |
226 PolicyMap policy_map; | 256 PolicyMap policy_map; |
227 PrefValueMap prefs; | 257 PrefValueMap prefs; |
228 scoped_ptr<base::Value> expected; | 258 scoped_ptr<base::Value> expected; |
229 const base::Value* value; | 259 const base::Value* value; |
230 | 260 |
231 // This tests needs to modify an int policy. The exact policy used and its | 261 // This tests needs to modify an int policy. The exact policy used and its |
232 // semantics outside the test are irrelevant. | 262 // semantics outside the test are irrelevant. |
233 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, true); | 263 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, true); |
234 | 264 |
235 // Check that values lying in the accepted range are written to the pref. | 265 // Check that values lying in the accepted range are written to the pref. |
236 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 266 policy_map.Set(kTestPolicy, |
237 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 267 POLICY_LEVEL_MANDATORY, |
| 268 POLICY_SCOPE_USER, |
| 269 new base::FundamentalValue(0), |
| 270 NULL); |
238 prefs.Clear(); | 271 prefs.Clear(); |
239 handler.ApplyPolicySettings(policy_map, &prefs); | 272 handler.ApplyPolicySettings(policy_map, &prefs); |
240 expected.reset(base::Value::CreateIntegerValue(0)); | 273 expected.reset(new base::FundamentalValue(0)); |
241 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 274 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
242 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 275 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
243 | 276 |
244 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 277 policy_map.Set(kTestPolicy, |
245 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 278 POLICY_LEVEL_MANDATORY, |
| 279 POLICY_SCOPE_USER, |
| 280 new base::FundamentalValue(5), |
| 281 NULL); |
246 prefs.Clear(); | 282 prefs.Clear(); |
247 handler.ApplyPolicySettings(policy_map, &prefs); | 283 handler.ApplyPolicySettings(policy_map, &prefs); |
248 expected.reset(base::Value::CreateIntegerValue(5)); | 284 expected.reset(new base::FundamentalValue(5)); |
249 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 285 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
250 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 286 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
251 | 287 |
252 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 288 policy_map.Set(kTestPolicy, |
253 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 289 POLICY_LEVEL_MANDATORY, |
| 290 POLICY_SCOPE_USER, |
| 291 new base::FundamentalValue(10), |
| 292 NULL); |
254 prefs.Clear(); | 293 prefs.Clear(); |
255 handler.ApplyPolicySettings(policy_map, &prefs); | 294 handler.ApplyPolicySettings(policy_map, &prefs); |
256 expected.reset(base::Value::CreateIntegerValue(10)); | 295 expected.reset(new base::FundamentalValue(10)); |
257 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 296 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
258 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 297 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
259 | 298 |
260 // Check that values lying outside the accepted range are clamped and written | 299 // Check that values lying outside the accepted range are clamped and written |
261 // to the pref. | 300 // to the pref. |
262 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 301 policy_map.Set(kTestPolicy, |
263 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(-5), NULL); | 302 POLICY_LEVEL_MANDATORY, |
| 303 POLICY_SCOPE_USER, |
| 304 new base::FundamentalValue(-5), |
| 305 NULL); |
264 prefs.Clear(); | 306 prefs.Clear(); |
265 handler.ApplyPolicySettings(policy_map, &prefs); | 307 handler.ApplyPolicySettings(policy_map, &prefs); |
266 expected.reset(base::Value::CreateIntegerValue(0)); | 308 expected.reset(new base::FundamentalValue(0)); |
267 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 309 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
268 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 310 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
269 | 311 |
270 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 312 policy_map.Set(kTestPolicy, |
271 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(15), NULL); | 313 POLICY_LEVEL_MANDATORY, |
| 314 POLICY_SCOPE_USER, |
| 315 new base::FundamentalValue(15), |
| 316 NULL); |
272 prefs.Clear(); | 317 prefs.Clear(); |
273 handler.ApplyPolicySettings(policy_map, &prefs); | 318 handler.ApplyPolicySettings(policy_map, &prefs); |
274 expected.reset(base::Value::CreateIntegerValue(10)); | 319 expected.reset(new base::FundamentalValue(10)); |
275 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 320 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
276 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 321 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
277 } | 322 } |
278 | 323 |
279 TEST(IntRangePolicyHandler, ApplyPolicySettingsDontClamp) { | 324 TEST(IntRangePolicyHandler, ApplyPolicySettingsDontClamp) { |
280 PolicyMap policy_map; | 325 PolicyMap policy_map; |
281 PrefValueMap prefs; | 326 PrefValueMap prefs; |
282 scoped_ptr<base::Value> expected; | 327 scoped_ptr<base::Value> expected; |
283 const base::Value* value; | 328 const base::Value* value; |
284 | 329 |
285 // This tests needs to modify an int policy. The exact policy used and its | 330 // This tests needs to modify an int policy. The exact policy used and its |
286 // semantics outside the test are irrelevant. | 331 // semantics outside the test are irrelevant. |
287 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, true); | 332 IntRangePolicyHandler handler(kTestPolicy, kTestPref, 0, 10, true); |
288 | 333 |
289 // Check that values lying in the accepted range are written to the pref. | 334 // Check that values lying in the accepted range are written to the pref. |
290 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 335 policy_map.Set(kTestPolicy, |
291 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 336 POLICY_LEVEL_MANDATORY, |
| 337 POLICY_SCOPE_USER, |
| 338 new base::FundamentalValue(0), |
| 339 NULL); |
292 prefs.Clear(); | 340 prefs.Clear(); |
293 handler.ApplyPolicySettings(policy_map, &prefs); | 341 handler.ApplyPolicySettings(policy_map, &prefs); |
294 expected.reset(base::Value::CreateIntegerValue(0)); | 342 expected.reset(new base::FundamentalValue(0)); |
295 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 343 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
296 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 344 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
297 | 345 |
298 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 346 policy_map.Set(kTestPolicy, |
299 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 347 POLICY_LEVEL_MANDATORY, |
| 348 POLICY_SCOPE_USER, |
| 349 new base::FundamentalValue(5), |
| 350 NULL); |
300 prefs.Clear(); | 351 prefs.Clear(); |
301 handler.ApplyPolicySettings(policy_map, &prefs); | 352 handler.ApplyPolicySettings(policy_map, &prefs); |
302 expected.reset(base::Value::CreateIntegerValue(5)); | 353 expected.reset(new base::FundamentalValue(5)); |
303 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 354 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
304 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 355 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
305 | 356 |
306 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 357 policy_map.Set(kTestPolicy, |
307 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 358 POLICY_LEVEL_MANDATORY, |
| 359 POLICY_SCOPE_USER, |
| 360 new base::FundamentalValue(10), |
| 361 NULL); |
308 prefs.Clear(); | 362 prefs.Clear(); |
309 handler.ApplyPolicySettings(policy_map, &prefs); | 363 handler.ApplyPolicySettings(policy_map, &prefs); |
310 expected.reset(base::Value::CreateIntegerValue(10)); | 364 expected.reset(new base::FundamentalValue(10)); |
311 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 365 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
312 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 366 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
313 } | 367 } |
314 | 368 |
315 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsClamp) { | 369 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsClamp) { |
316 PolicyMap policy_map; | 370 PolicyMap policy_map; |
317 PolicyErrorMap errors; | 371 PolicyErrorMap errors; |
318 | 372 |
319 // This tests needs to modify an int policy. The exact policy used and its | 373 // This tests needs to modify an int policy. The exact policy used and its |
320 // semantics outside the test are irrelevant. | 374 // semantics outside the test are irrelevant. |
321 IntPercentageToDoublePolicyHandler handler( | 375 IntPercentageToDoublePolicyHandler handler( |
322 kTestPolicy, kTestPref, 0, 10, true); | 376 kTestPolicy, kTestPref, 0, 10, true); |
323 | 377 |
324 // Check that values lying in the accepted range are not rejected. | 378 // Check that values lying in the accepted range are not rejected. |
325 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 379 policy_map.Set(kTestPolicy, |
326 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 380 POLICY_LEVEL_MANDATORY, |
| 381 POLICY_SCOPE_USER, |
| 382 new base::FundamentalValue(0), |
| 383 NULL); |
327 errors.Clear(); | 384 errors.Clear(); |
328 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 385 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
329 EXPECT_TRUE(errors.empty()); | 386 EXPECT_TRUE(errors.empty()); |
330 | 387 |
331 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 388 policy_map.Set(kTestPolicy, |
332 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 389 POLICY_LEVEL_MANDATORY, |
| 390 POLICY_SCOPE_USER, |
| 391 new base::FundamentalValue(5), |
| 392 NULL); |
333 errors.Clear(); | 393 errors.Clear(); |
334 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 394 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
335 EXPECT_TRUE(errors.empty()); | 395 EXPECT_TRUE(errors.empty()); |
336 | 396 |
337 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 397 policy_map.Set(kTestPolicy, |
338 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 398 POLICY_LEVEL_MANDATORY, |
| 399 POLICY_SCOPE_USER, |
| 400 new base::FundamentalValue(10), |
| 401 NULL); |
339 errors.Clear(); | 402 errors.Clear(); |
340 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 403 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
341 EXPECT_TRUE(errors.empty()); | 404 EXPECT_TRUE(errors.empty()); |
342 | 405 |
343 // Check that values lying outside the accepted range are not rejected | 406 // Check that values lying outside the accepted range are not rejected |
344 // (because clamping is enabled) but do yield a warning message. | 407 // (because clamping is enabled) but do yield a warning message. |
345 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 408 policy_map.Set(kTestPolicy, |
346 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(-5), NULL); | 409 POLICY_LEVEL_MANDATORY, |
| 410 POLICY_SCOPE_USER, |
| 411 new base::FundamentalValue(-5), |
| 412 NULL); |
347 errors.Clear(); | 413 errors.Clear(); |
348 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 414 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
349 EXPECT_FALSE(errors.empty()); | 415 EXPECT_FALSE(errors.empty()); |
350 | 416 |
351 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 417 policy_map.Set(kTestPolicy, |
352 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(15), NULL); | 418 POLICY_LEVEL_MANDATORY, |
| 419 POLICY_SCOPE_USER, |
| 420 new base::FundamentalValue(15), |
| 421 NULL); |
353 errors.Clear(); | 422 errors.Clear(); |
354 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 423 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
355 EXPECT_FALSE(errors.empty()); | 424 EXPECT_FALSE(errors.empty()); |
356 | 425 |
357 // Check that an entirely invalid value is rejected and yields an error | 426 // Check that an entirely invalid value is rejected and yields an error |
358 // message. | 427 // message. |
359 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 428 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
360 base::Value::CreateStringValue("invalid"), NULL); | 429 base::Value::CreateStringValue("invalid"), NULL); |
361 errors.Clear(); | 430 errors.Clear(); |
362 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 431 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
363 EXPECT_FALSE(errors.empty()); | 432 EXPECT_FALSE(errors.empty()); |
364 } | 433 } |
365 | 434 |
366 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsDontClamp) { | 435 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsDontClamp) { |
367 PolicyMap policy_map; | 436 PolicyMap policy_map; |
368 PolicyErrorMap errors; | 437 PolicyErrorMap errors; |
369 | 438 |
370 // This tests needs to modify an int policy. The exact policy used and its | 439 // This tests needs to modify an int policy. The exact policy used and its |
371 // semantics outside the test are irrelevant. | 440 // semantics outside the test are irrelevant. |
372 IntPercentageToDoublePolicyHandler handler( | 441 IntPercentageToDoublePolicyHandler handler( |
373 kTestPolicy, kTestPref, 0, 10, false); | 442 kTestPolicy, kTestPref, 0, 10, false); |
374 | 443 |
375 // Check that values lying in the accepted range are not rejected. | 444 // Check that values lying in the accepted range are not rejected. |
376 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 445 policy_map.Set(kTestPolicy, |
377 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 446 POLICY_LEVEL_MANDATORY, |
| 447 POLICY_SCOPE_USER, |
| 448 new base::FundamentalValue(0), |
| 449 NULL); |
378 errors.Clear(); | 450 errors.Clear(); |
379 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 451 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
380 EXPECT_TRUE(errors.empty()); | 452 EXPECT_TRUE(errors.empty()); |
381 | 453 |
382 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 454 policy_map.Set(kTestPolicy, |
383 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 455 POLICY_LEVEL_MANDATORY, |
| 456 POLICY_SCOPE_USER, |
| 457 new base::FundamentalValue(5), |
| 458 NULL); |
384 errors.Clear(); | 459 errors.Clear(); |
385 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 460 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
386 EXPECT_TRUE(errors.empty()); | 461 EXPECT_TRUE(errors.empty()); |
387 | 462 |
388 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 463 policy_map.Set(kTestPolicy, |
389 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 464 POLICY_LEVEL_MANDATORY, |
| 465 POLICY_SCOPE_USER, |
| 466 new base::FundamentalValue(10), |
| 467 NULL); |
390 errors.Clear(); | 468 errors.Clear(); |
391 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 469 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
392 EXPECT_TRUE(errors.empty()); | 470 EXPECT_TRUE(errors.empty()); |
393 | 471 |
394 // Check that values lying outside the accepted range are rejected and yield | 472 // Check that values lying outside the accepted range are rejected and yield |
395 // an error message. | 473 // an error message. |
396 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 474 policy_map.Set(kTestPolicy, |
397 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(-5), NULL); | 475 POLICY_LEVEL_MANDATORY, |
| 476 POLICY_SCOPE_USER, |
| 477 new base::FundamentalValue(-5), |
| 478 NULL); |
398 errors.Clear(); | 479 errors.Clear(); |
399 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 480 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
400 EXPECT_FALSE(errors.empty()); | 481 EXPECT_FALSE(errors.empty()); |
401 | 482 |
402 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 483 policy_map.Set(kTestPolicy, |
403 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(15), NULL); | 484 POLICY_LEVEL_MANDATORY, |
| 485 POLICY_SCOPE_USER, |
| 486 new base::FundamentalValue(15), |
| 487 NULL); |
404 errors.Clear(); | 488 errors.Clear(); |
405 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 489 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
406 EXPECT_FALSE(errors.empty()); | 490 EXPECT_FALSE(errors.empty()); |
407 | 491 |
408 // Check that an entirely invalid value is rejected and yields an error | 492 // Check that an entirely invalid value is rejected and yields an error |
409 // message. | 493 // message. |
410 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 494 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
411 base::Value::CreateStringValue("invalid"), NULL); | 495 base::Value::CreateStringValue("invalid"), NULL); |
412 errors.Clear(); | 496 errors.Clear(); |
413 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 497 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
414 EXPECT_FALSE(errors.empty()); | 498 EXPECT_FALSE(errors.empty()); |
415 } | 499 } |
416 | 500 |
417 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsClamp) { | 501 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsClamp) { |
418 PolicyMap policy_map; | 502 PolicyMap policy_map; |
419 PrefValueMap prefs; | 503 PrefValueMap prefs; |
420 scoped_ptr<base::Value> expected; | 504 scoped_ptr<base::Value> expected; |
421 const base::Value* value; | 505 const base::Value* value; |
422 | 506 |
423 // This tests needs to modify an int policy. The exact policy used and its | 507 // This tests needs to modify an int policy. The exact policy used and its |
424 // semantics outside the test are irrelevant. | 508 // semantics outside the test are irrelevant. |
425 IntPercentageToDoublePolicyHandler handler( | 509 IntPercentageToDoublePolicyHandler handler( |
426 kTestPolicy, kTestPref, 0, 10, true); | 510 kTestPolicy, kTestPref, 0, 10, true); |
427 | 511 |
428 // Check that values lying in the accepted range are written to the pref. | 512 // Check that values lying in the accepted range are written to the pref. |
429 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 513 policy_map.Set(kTestPolicy, |
430 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 514 POLICY_LEVEL_MANDATORY, |
| 515 POLICY_SCOPE_USER, |
| 516 new base::FundamentalValue(0), |
| 517 NULL); |
431 prefs.Clear(); | 518 prefs.Clear(); |
432 handler.ApplyPolicySettings(policy_map, &prefs); | 519 handler.ApplyPolicySettings(policy_map, &prefs); |
433 expected.reset(base::Value::CreateDoubleValue(0.0)); | 520 expected.reset(base::Value::CreateDoubleValue(0.0)); |
434 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 521 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
435 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 522 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
436 | 523 |
437 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 524 policy_map.Set(kTestPolicy, |
438 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 525 POLICY_LEVEL_MANDATORY, |
| 526 POLICY_SCOPE_USER, |
| 527 new base::FundamentalValue(5), |
| 528 NULL); |
439 prefs.Clear(); | 529 prefs.Clear(); |
440 handler.ApplyPolicySettings(policy_map, &prefs); | 530 handler.ApplyPolicySettings(policy_map, &prefs); |
441 expected.reset(base::Value::CreateDoubleValue(0.05)); | 531 expected.reset(base::Value::CreateDoubleValue(0.05)); |
442 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 532 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
443 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 533 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
444 | 534 |
445 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 535 policy_map.Set(kTestPolicy, |
446 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 536 POLICY_LEVEL_MANDATORY, |
| 537 POLICY_SCOPE_USER, |
| 538 new base::FundamentalValue(10), |
| 539 NULL); |
447 prefs.Clear(); | 540 prefs.Clear(); |
448 handler.ApplyPolicySettings(policy_map, &prefs); | 541 handler.ApplyPolicySettings(policy_map, &prefs); |
449 expected.reset(base::Value::CreateDoubleValue(0.1)); | 542 expected.reset(base::Value::CreateDoubleValue(0.1)); |
450 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 543 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
451 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 544 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
452 | 545 |
453 // Check that values lying outside the accepted range are clamped and written | 546 // Check that values lying outside the accepted range are clamped and written |
454 // to the pref. | 547 // to the pref. |
455 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 548 policy_map.Set(kTestPolicy, |
456 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(-5), NULL); | 549 POLICY_LEVEL_MANDATORY, |
| 550 POLICY_SCOPE_USER, |
| 551 new base::FundamentalValue(-5), |
| 552 NULL); |
457 prefs.Clear(); | 553 prefs.Clear(); |
458 handler.ApplyPolicySettings(policy_map, &prefs); | 554 handler.ApplyPolicySettings(policy_map, &prefs); |
459 expected.reset(base::Value::CreateDoubleValue(0.0)); | 555 expected.reset(base::Value::CreateDoubleValue(0.0)); |
460 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 556 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
461 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 557 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
462 | 558 |
463 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 559 policy_map.Set(kTestPolicy, |
464 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(15), NULL); | 560 POLICY_LEVEL_MANDATORY, |
| 561 POLICY_SCOPE_USER, |
| 562 new base::FundamentalValue(15), |
| 563 NULL); |
465 prefs.Clear(); | 564 prefs.Clear(); |
466 handler.ApplyPolicySettings(policy_map, &prefs); | 565 handler.ApplyPolicySettings(policy_map, &prefs); |
467 expected.reset(base::Value::CreateDoubleValue(0.1)); | 566 expected.reset(base::Value::CreateDoubleValue(0.1)); |
468 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 567 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
469 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 568 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
470 } | 569 } |
471 | 570 |
472 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsDontClamp) { | 571 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsDontClamp) { |
473 PolicyMap policy_map; | 572 PolicyMap policy_map; |
474 PrefValueMap prefs; | 573 PrefValueMap prefs; |
475 scoped_ptr<base::Value> expected; | 574 scoped_ptr<base::Value> expected; |
476 const base::Value* value; | 575 const base::Value* value; |
477 | 576 |
478 // This tests needs to modify an int policy. The exact policy used and its | 577 // This tests needs to modify an int policy. The exact policy used and its |
479 // semantics outside the test are irrelevant. | 578 // semantics outside the test are irrelevant. |
480 IntPercentageToDoublePolicyHandler handler( | 579 IntPercentageToDoublePolicyHandler handler( |
481 kTestPolicy, kTestPref, 0, 10, true); | 580 kTestPolicy, kTestPref, 0, 10, true); |
482 | 581 |
483 // Check that values lying in the accepted range are written to the pref. | 582 // Check that values lying in the accepted range are written to the pref. |
484 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 583 policy_map.Set(kTestPolicy, |
485 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(0), NULL); | 584 POLICY_LEVEL_MANDATORY, |
| 585 POLICY_SCOPE_USER, |
| 586 new base::FundamentalValue(0), |
| 587 NULL); |
486 prefs.Clear(); | 588 prefs.Clear(); |
487 handler.ApplyPolicySettings(policy_map, &prefs); | 589 handler.ApplyPolicySettings(policy_map, &prefs); |
488 expected.reset(base::Value::CreateDoubleValue(0.0)); | 590 expected.reset(base::Value::CreateDoubleValue(0.0)); |
489 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 591 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
490 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 592 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
491 | 593 |
492 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 594 policy_map.Set(kTestPolicy, |
493 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(5), NULL); | 595 POLICY_LEVEL_MANDATORY, |
| 596 POLICY_SCOPE_USER, |
| 597 new base::FundamentalValue(5), |
| 598 NULL); |
494 prefs.Clear(); | 599 prefs.Clear(); |
495 handler.ApplyPolicySettings(policy_map, &prefs); | 600 handler.ApplyPolicySettings(policy_map, &prefs); |
496 expected.reset(base::Value::CreateDoubleValue(0.05)); | 601 expected.reset(base::Value::CreateDoubleValue(0.05)); |
497 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 602 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
498 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 603 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
499 | 604 |
500 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 605 policy_map.Set(kTestPolicy, |
501 POLICY_SCOPE_USER, base::Value::CreateIntegerValue(10), NULL); | 606 POLICY_LEVEL_MANDATORY, |
| 607 POLICY_SCOPE_USER, |
| 608 new base::FundamentalValue(10), |
| 609 NULL); |
502 prefs.Clear(); | 610 prefs.Clear(); |
503 handler.ApplyPolicySettings(policy_map, &prefs); | 611 handler.ApplyPolicySettings(policy_map, &prefs); |
504 expected.reset(base::Value::CreateDoubleValue(0.1)); | 612 expected.reset(base::Value::CreateDoubleValue(0.1)); |
505 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); | 613 EXPECT_TRUE(prefs.GetValue(kTestPref, &value)); |
506 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); | 614 EXPECT_TRUE(base::Value::Equals(expected.get(), value)); |
507 } | 615 } |
508 | 616 |
509 TEST(SchemaValidatingPolicyHandlerTest, CheckAndGetValue) { | 617 TEST(SchemaValidatingPolicyHandlerTest, CheckAndGetValue) { |
510 std::string error; | 618 std::string error; |
511 static const char kSchemaJson[] = | 619 static const char kSchemaJson[] = |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); | 797 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); |
690 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); | 798 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); |
691 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); | 799 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); |
692 | 800 |
693 EXPECT_FALSE( | 801 EXPECT_FALSE( |
694 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); | 802 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); |
695 EXPECT_FALSE(errors.empty()); | 803 EXPECT_FALSE(errors.empty()); |
696 } | 804 } |
697 | 805 |
698 } // namespace policy | 806 } // namespace policy |
OLD | NEW |