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

Side by Side Diff: components/policy/core/browser/configuration_policy_handler_unittest.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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 (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 "components/policy/core/browser/configuration_policy_handler.h" 5 #include "components/policy/core/browser/configuration_policy_handler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 list.AppendString("invalid"); 79 list.AppendString("invalid");
80 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 80 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
81 POLICY_SOURCE_CLOUD, list.CreateDeepCopy(), nullptr); 81 POLICY_SOURCE_CLOUD, list.CreateDeepCopy(), nullptr);
82 errors.Clear(); 82 errors.Clear();
83 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 83 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
84 EXPECT_FALSE(errors.empty()); 84 EXPECT_FALSE(errors.empty());
85 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty()); 85 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty());
86 86
87 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 87 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
88 POLICY_SOURCE_CLOUD, 88 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("no list"),
89 base::MakeUnique<base::StringValue>("no list"), NULL); 89 NULL);
90 errors.Clear(); 90 errors.Clear();
91 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 91 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
92 EXPECT_FALSE(errors.empty()); 92 EXPECT_FALSE(errors.empty());
93 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty()); 93 EXPECT_FALSE(errors.GetErrors(kTestPolicy).empty());
94 } 94 }
95 95
96 TEST(StringMappingListPolicyHandlerTest, ApplyPolicySettings) { 96 TEST(StringMappingListPolicyHandlerTest, ApplyPolicySettings) {
97 base::ListValue list; 97 base::ListValue list;
98 base::ListValue expected; 98 base::ListValue expected;
99 PolicyMap policy_map; 99 PolicyMap policy_map;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 168 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
169 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15), 169 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15),
170 nullptr); 170 nullptr);
171 errors.Clear(); 171 errors.Clear();
172 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 172 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
173 EXPECT_FALSE(errors.empty()); 173 EXPECT_FALSE(errors.empty());
174 174
175 // Check that an entirely invalid value is rejected and yields an error 175 // Check that an entirely invalid value is rejected and yields an error
176 // message. 176 // message.
177 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 177 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
178 POLICY_SOURCE_CLOUD, 178 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("invalid"),
179 base::MakeUnique<base::StringValue>("invalid"), nullptr); 179 nullptr);
180 errors.Clear(); 180 errors.Clear();
181 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 181 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
182 EXPECT_FALSE(errors.empty()); 182 EXPECT_FALSE(errors.empty());
183 } 183 }
184 184
185 TEST(IntRangePolicyHandler, CheckPolicySettingsDontClamp) { 185 TEST(IntRangePolicyHandler, CheckPolicySettingsDontClamp) {
186 PolicyMap policy_map; 186 PolicyMap policy_map;
187 PolicyErrorMap errors; 187 PolicyErrorMap errors;
188 188
189 // This tests needs to modify an int policy. The exact policy used and its 189 // This tests needs to modify an int policy. The exact policy used and its
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 224 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
225 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15), 225 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15),
226 nullptr); 226 nullptr);
227 errors.Clear(); 227 errors.Clear();
228 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 228 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
229 EXPECT_FALSE(errors.empty()); 229 EXPECT_FALSE(errors.empty());
230 230
231 // Check that an entirely invalid value is rejected and yields an error 231 // Check that an entirely invalid value is rejected and yields an error
232 // message. 232 // message.
233 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 233 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
234 POLICY_SOURCE_CLOUD, 234 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("invalid"),
235 base::MakeUnique<base::StringValue>("invalid"), nullptr); 235 nullptr);
236 errors.Clear(); 236 errors.Clear();
237 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 237 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
238 EXPECT_FALSE(errors.empty()); 238 EXPECT_FALSE(errors.empty());
239 } 239 }
240 240
241 TEST(IntRangePolicyHandler, ApplyPolicySettingsClamp) { 241 TEST(IntRangePolicyHandler, ApplyPolicySettingsClamp) {
242 PolicyMap policy_map; 242 PolicyMap policy_map;
243 PrefValueMap prefs; 243 PrefValueMap prefs;
244 std::unique_ptr<base::Value> expected; 244 std::unique_ptr<base::Value> expected;
245 const base::Value* value; 245 const base::Value* value;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 379 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
380 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15), 380 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15),
381 nullptr); 381 nullptr);
382 errors.Clear(); 382 errors.Clear();
383 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); 383 EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors));
384 EXPECT_FALSE(errors.empty()); 384 EXPECT_FALSE(errors.empty());
385 385
386 // Check that an entirely invalid value is rejected and yields an error 386 // Check that an entirely invalid value is rejected and yields an error
387 // message. 387 // message.
388 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 388 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
389 POLICY_SOURCE_CLOUD, 389 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("invalid"),
390 base::MakeUnique<base::StringValue>("invalid"), nullptr); 390 nullptr);
391 errors.Clear(); 391 errors.Clear();
392 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 392 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
393 EXPECT_FALSE(errors.empty()); 393 EXPECT_FALSE(errors.empty());
394 } 394 }
395 395
396 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsDontClamp) { 396 TEST(IntPercentageToDoublePolicyHandler, CheckPolicySettingsDontClamp) {
397 PolicyMap policy_map; 397 PolicyMap policy_map;
398 PolicyErrorMap errors; 398 PolicyErrorMap errors;
399 399
400 // This tests needs to modify an int policy. The exact policy used and its 400 // This tests needs to modify an int policy. The exact policy used and its
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 436 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
437 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15), 437 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>(15),
438 nullptr); 438 nullptr);
439 errors.Clear(); 439 errors.Clear();
440 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 440 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
441 EXPECT_FALSE(errors.empty()); 441 EXPECT_FALSE(errors.empty());
442 442
443 // Check that an entirely invalid value is rejected and yields an error 443 // Check that an entirely invalid value is rejected and yields an error
444 // message. 444 // message.
445 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 445 policy_map.Set(kTestPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
446 POLICY_SOURCE_CLOUD, 446 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("invalid"),
447 base::MakeUnique<base::StringValue>("invalid"), nullptr); 447 nullptr);
448 errors.Clear(); 448 errors.Clear();
449 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); 449 EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors));
450 EXPECT_FALSE(errors.empty()); 450 EXPECT_FALSE(errors.empty());
451 } 451 }
452 452
453 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsClamp) { 453 TEST(IntPercentageToDoublePolicyHandler, ApplyPolicySettingsClamp) {
454 PolicyMap policy_map; 454 PolicyMap policy_map;
455 PrefValueMap prefs; 455 PrefValueMap prefs;
456 std::unique_ptr<base::Value> expected; 456 std::unique_ptr<base::Value> expected;
457 const base::Value* value; 457 const base::Value* value;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); 737 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs);
738 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); 738 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref));
739 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); 739 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref));
740 740
741 EXPECT_FALSE( 741 EXPECT_FALSE(
742 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); 742 handler_none.CheckPolicySettings(policy_map_recommended, &errors));
743 EXPECT_FALSE(errors.empty()); 743 EXPECT_FALSE(errors.empty());
744 } 744 }
745 745
746 } // namespace policy 746 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698