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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 EXPECT_TRUE(errors.empty()); | 72 EXPECT_TRUE(errors.empty()); |
73 | 73 |
74 list.AppendString("invalid"); | 74 list.AppendString("invalid"); |
75 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 75 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, |
76 POLICY_SCOPE_USER, list.DeepCopy(), NULL); | 76 POLICY_SCOPE_USER, list.DeepCopy(), NULL); |
77 errors.Clear(); | 77 errors.Clear(); |
78 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 78 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
79 EXPECT_FALSE(errors.empty()); | 79 EXPECT_FALSE(errors.empty()); |
80 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty()); | 80 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty()); |
81 | 81 |
82 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, | 82 policy_map.Set(kTestPolicy, |
| 83 POLICY_LEVEL_MANDATORY, |
83 POLICY_SCOPE_USER, | 84 POLICY_SCOPE_USER, |
84 base::Value::CreateStringValue("no list"), NULL); | 85 new base::StringValue("no list"), |
| 86 NULL); |
85 errors.Clear(); | 87 errors.Clear(); |
86 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 88 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
87 EXPECT_FALSE(errors.empty()); | 89 EXPECT_FALSE(errors.empty()); |
88 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty()); | 90 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty()); |
89 } | 91 } |
90 | 92 |
91 TEST(StringMappingListPolicyHandlerTest, ApplyPolicySettings) { | 93 TEST(StringMappingListPolicyHandlerTest, ApplyPolicySettings) { |
92 base::ListValue list; | 94 base::ListValue list; |
93 base::ListValue expected; | 95 base::ListValue expected; |
94 PolicyMap policy_map; | 96 PolicyMap policy_map; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 POLICY_SCOPE_USER, | 175 POLICY_SCOPE_USER, |
174 new base::FundamentalValue(15), | 176 new base::FundamentalValue(15), |
175 NULL); | 177 NULL); |
176 errors.Clear(); | 178 errors.Clear(); |
177 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 179 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
178 EXPECT_FALSE(errors.empty()); | 180 EXPECT_FALSE(errors.empty()); |
179 | 181 |
180 // Check that an entirely invalid value is rejected and yields an error | 182 // Check that an entirely invalid value is rejected and yields an error |
181 // message. | 183 // message. |
182 policy_map.Set(kTestPolicy, | 184 policy_map.Set(kTestPolicy, |
183 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 185 POLICY_LEVEL_MANDATORY, |
184 base::Value::CreateStringValue("invalid"), NULL); | 186 POLICY_SCOPE_USER, |
| 187 new base::StringValue("invalid"), |
| 188 NULL); |
185 errors.Clear(); | 189 errors.Clear(); |
186 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 190 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
187 EXPECT_FALSE(errors.empty()); | 191 EXPECT_FALSE(errors.empty()); |
188 } | 192 } |
189 | 193 |
190 TEST(IntRangePolicyHandler, CheckPolicySettingsDontClamp) { | 194 TEST(IntRangePolicyHandler, CheckPolicySettingsDontClamp) { |
191 PolicyMap policy_map; | 195 PolicyMap policy_map; |
192 PolicyErrorMap errors; | 196 PolicyErrorMap errors; |
193 | 197 |
194 // This tests needs to modify an int policy. The exact policy used and its | 198 // This tests needs to modify an int policy. The exact policy used and its |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 POLICY_LEVEL_MANDATORY, | 242 POLICY_LEVEL_MANDATORY, |
239 POLICY_SCOPE_USER, | 243 POLICY_SCOPE_USER, |
240 new base::FundamentalValue(15), | 244 new base::FundamentalValue(15), |
241 NULL); | 245 NULL); |
242 errors.Clear(); | 246 errors.Clear(); |
243 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 247 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
244 EXPECT_FALSE(errors.empty()); | 248 EXPECT_FALSE(errors.empty()); |
245 | 249 |
246 // Check that an entirely invalid value is rejected and yields an error | 250 // Check that an entirely invalid value is rejected and yields an error |
247 // message. | 251 // message. |
248 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 252 policy_map.Set(kTestPolicy, |
249 base::Value::CreateStringValue("invalid"), NULL); | 253 POLICY_LEVEL_MANDATORY, |
| 254 POLICY_SCOPE_USER, |
| 255 new base::StringValue("invalid"), |
| 256 NULL); |
250 errors.Clear(); | 257 errors.Clear(); |
251 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 258 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
252 EXPECT_FALSE(errors.empty()); | 259 EXPECT_FALSE(errors.empty()); |
253 } | 260 } |
254 | 261 |
255 TEST(IntRangePolicyHandler, ApplyPolicySettingsClamp) { | 262 TEST(IntRangePolicyHandler, ApplyPolicySettingsClamp) { |
256 PolicyMap policy_map; | 263 PolicyMap policy_map; |
257 PrefValueMap prefs; | 264 PrefValueMap prefs; |
258 scoped_ptr<base::Value> expected; | 265 scoped_ptr<base::Value> expected; |
259 const base::Value* value; | 266 const base::Value* value; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 POLICY_LEVEL_MANDATORY, | 425 POLICY_LEVEL_MANDATORY, |
419 POLICY_SCOPE_USER, | 426 POLICY_SCOPE_USER, |
420 new base::FundamentalValue(15), | 427 new base::FundamentalValue(15), |
421 NULL); | 428 NULL); |
422 errors.Clear(); | 429 errors.Clear(); |
423 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); | 430 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); |
424 EXPECT_FALSE(errors.empty()); | 431 EXPECT_FALSE(errors.empty()); |
425 | 432 |
426 // Check that an entirely invalid value is rejected and yields an error | 433 // Check that an entirely invalid value is rejected and yields an error |
427 // message. | 434 // message. |
428 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 435 policy_map.Set(kTestPolicy, |
429 base::Value::CreateStringValue("invalid"), NULL); | 436 POLICY_LEVEL_MANDATORY, |
| 437 POLICY_SCOPE_USER, |
| 438 new base::StringValue("invalid"), |
| 439 NULL); |
430 errors.Clear(); | 440 errors.Clear(); |
431 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 441 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
432 EXPECT_FALSE(errors.empty()); | 442 EXPECT_FALSE(errors.empty()); |
433 } | 443 } |
434 | 444 |
435 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsDontClamp) { | 445 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsDontClamp) { |
436 PolicyMap policy_map; | 446 PolicyMap policy_map; |
437 PolicyErrorMap errors; | 447 PolicyErrorMap errors; |
438 | 448 |
439 // This tests needs to modify an int policy. The exact policy used and its | 449 // This tests needs to modify an int policy. The exact policy used and its |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 POLICY_LEVEL_MANDATORY, | 494 POLICY_LEVEL_MANDATORY, |
485 POLICY_SCOPE_USER, | 495 POLICY_SCOPE_USER, |
486 new base::FundamentalValue(15), | 496 new base::FundamentalValue(15), |
487 NULL); | 497 NULL); |
488 errors.Clear(); | 498 errors.Clear(); |
489 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 499 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
490 EXPECT_FALSE(errors.empty()); | 500 EXPECT_FALSE(errors.empty()); |
491 | 501 |
492 // Check that an entirely invalid value is rejected and yields an error | 502 // Check that an entirely invalid value is rejected and yields an error |
493 // message. | 503 // message. |
494 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 504 policy_map.Set(kTestPolicy, |
495 base::Value::CreateStringValue("invalid"), NULL); | 505 POLICY_LEVEL_MANDATORY, |
| 506 POLICY_SCOPE_USER, |
| 507 new base::StringValue("invalid"), |
| 508 NULL); |
496 errors.Clear(); | 509 errors.Clear(); |
497 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); | 510 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); |
498 EXPECT_FALSE(errors.empty()); | 511 EXPECT_FALSE(errors.empty()); |
499 } | 512 } |
500 | 513 |
501 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsClamp) { | 514 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsClamp) { |
502 PolicyMap policy_map; | 515 PolicyMap policy_map; |
503 PrefValueMap prefs; | 516 PrefValueMap prefs; |
504 scoped_ptr<base::Value> expected; | 517 scoped_ptr<base::Value> expected; |
505 const base::Value* value; | 518 const base::Value* value; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); | 810 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); |
798 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); | 811 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); |
799 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); | 812 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); |
800 | 813 |
801 EXPECT_FALSE( | 814 EXPECT_FALSE( |
802 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); | 815 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); |
803 EXPECT_FALSE(errors.empty()); | 816 EXPECT_FALSE(errors.empty()); |
804 } | 817 } |
805 | 818 |
806 } // namespace policy | 819 } // namespace policy |
OLD | NEW |