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

Side by Side Diff: components/policy/core/common/configuration_policy_provider_test.cc

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Nits Created 3 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
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 "components/policy/core/common/configuration_policy_provider_test.h" 5 #include "components/policy/core/common/configuration_policy_provider_test.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 &expected_value)); 294 &expected_value));
295 } 295 }
296 296
297 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { 297 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) {
298 base::DictionaryValue expected_value; 298 base::DictionaryValue expected_value;
299 expected_value.SetBoolean("bool", true); 299 expected_value.SetBoolean("bool", true);
300 expected_value.SetDouble("double", 123.456); 300 expected_value.SetDouble("double", 123.456);
301 expected_value.SetInteger("int", 123); 301 expected_value.SetInteger("int", 123);
302 expected_value.SetString("string", "omg"); 302 expected_value.SetString("string", "omg");
303 303
304 base::ListValue* list = new base::ListValue(); 304 auto list = base::MakeUnique<base::ListValue>();
305 list->AppendString("first"); 305 list->AppendString("first");
306 list->AppendString("second"); 306 list->AppendString("second");
307 expected_value.Set("array", list); 307 expected_value.Set("array", std::move(list));
308 308
309 base::DictionaryValue* dict = new base::DictionaryValue(); 309 auto dict = base::MakeUnique<base::DictionaryValue>();
310 dict->SetString("sub", "value"); 310 dict->SetString("sub", "value");
311 list = new base::ListValue(); 311 list = base::MakeUnique<base::ListValue>();
312 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue()); 312 auto sub = base::MakeUnique<base::DictionaryValue>();
313 sub->SetInteger("aaa", 111); 313 sub->SetInteger("aaa", 111);
314 sub->SetInteger("bbb", 222); 314 sub->SetInteger("bbb", 222);
315 list->Append(std::move(sub)); 315 list->Append(std::move(sub));
316 sub.reset(new base::DictionaryValue()); 316 sub = base::MakeUnique<base::DictionaryValue>();
317 sub->SetString("ccc", "333"); 317 sub->SetString("ccc", "333");
318 sub->SetString("ddd", "444"); 318 sub->SetString("ddd", "444");
319 list->Append(std::move(sub)); 319 list->Append(std::move(sub));
320 dict->Set("sublist", list); 320 dict->Set("sublist", std::move(list));
321 expected_value.Set("dictionary", dict); 321 expected_value.Set("dictionary", std::move(dict));
322 322
323 CheckValue(test_keys::kKeyDictionary, 323 CheckValue(test_keys::kKeyDictionary,
324 expected_value, 324 expected_value,
325 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, 325 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy,
326 base::Unretained(test_harness_.get()), 326 base::Unretained(test_harness_.get()),
327 test_keys::kKeyDictionary, 327 test_keys::kKeyDictionary,
328 &expected_value)); 328 &expected_value));
329 } 329 }
330 330
331 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { 331 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 Configuration3rdPartyPolicyProviderTest:: 363 Configuration3rdPartyPolicyProviderTest::
364 ~Configuration3rdPartyPolicyProviderTest() {} 364 ~Configuration3rdPartyPolicyProviderTest() {}
365 365
366 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) { 366 TEST_P(Configuration3rdPartyPolicyProviderTest, Load3rdParty) {
367 base::DictionaryValue policy_dict; 367 base::DictionaryValue policy_dict;
368 policy_dict.SetBoolean("bool", true); 368 policy_dict.SetBoolean("bool", true);
369 policy_dict.SetDouble("double", 123.456); 369 policy_dict.SetDouble("double", 123.456);
370 policy_dict.SetInteger("int", 789); 370 policy_dict.SetInteger("int", 789);
371 policy_dict.SetString("string", "string value"); 371 policy_dict.SetString("string", "string value");
372 372
373 base::ListValue* list = new base::ListValue(); 373 auto list = base::MakeUnique<base::ListValue>();
374 for (int i = 0; i < 2; ++i) { 374 for (int i = 0; i < 2; ++i) {
375 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 375 auto dict = base::MakeUnique<base::DictionaryValue>();
376 dict->SetInteger("subdictindex", i); 376 dict->SetInteger("subdictindex", i);
377 dict->Set("subdict", policy_dict.DeepCopy()); 377 dict->Set("subdict", base::MakeUnique<base::Value>(policy_dict));
378 list->Append(std::move(dict)); 378 list->Append(std::move(dict));
379 } 379 }
380 policy_dict.Set("list", list); 380 policy_dict.Set("list", std::move(list));
381 policy_dict.Set("dict", policy_dict.DeepCopy()); 381 policy_dict.Set("dict", base::MakeUnique<base::Value>(policy_dict));
382 382
383 // Install these policies as a Chrome policy. 383 // Install these policies as a Chrome policy.
384 test_harness_->InstallDictionaryPolicy(test_keys::kKeyDictionary, 384 test_harness_->InstallDictionaryPolicy(test_keys::kKeyDictionary,
385 &policy_dict); 385 &policy_dict);
386 // Install them as 3rd party policies too. 386 // Install them as 3rd party policies too.
387 base::DictionaryValue policy_3rdparty; 387 base::DictionaryValue policy_3rdparty;
388 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 388 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
389 policy_dict.DeepCopy()); 389 base::MakeUnique<base::Value>(policy_dict));
390 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 390 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
391 policy_dict.DeepCopy()); 391 base::MakeUnique<base::Value>(policy_dict));
392 // Install invalid 3rd party policies that shouldn't be loaded. These also 392 // Install invalid 3rd party policies that shouldn't be loaded. These also
393 // help detecting memory leaks in the code paths that detect invalid input. 393 // help detecting memory leaks in the code paths that detect invalid input.
394 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); 394 policy_3rdparty.Set("invalid-domain.component",
395 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", 395 base::MakeUnique<base::Value>(policy_dict));
396 new base::Value("invalid-value")); 396 policy_3rdparty.SetString("extensions.cccccccccccccccccccccccccccccccc",
397 "invalid-value");
397 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); 398 test_harness_->Install3rdPartyPolicy(&policy_3rdparty);
398 399
399 provider_->RefreshPolicies(); 400 provider_->RefreshPolicies();
400 base::RunLoop().RunUntilIdle(); 401 base::RunLoop().RunUntilIdle();
401 402
402 PolicyMap expected_policy; 403 PolicyMap expected_policy;
403 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(), 404 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(),
404 test_harness_->policy_scope(), 405 test_harness_->policy_scope(),
405 test_harness_->policy_source(), 406 test_harness_->policy_source(),
406 policy_dict.CreateDeepCopy(), nullptr); 407 policy_dict.CreateDeepCopy(), nullptr);
407 PolicyBundle expected_bundle; 408 PolicyBundle expected_bundle;
408 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 409 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
409 .CopyFrom(expected_policy); 410 .CopyFrom(expected_policy);
410 expected_policy.Clear(); 411 expected_policy.Clear();
411 expected_policy.LoadFrom(&policy_dict, 412 expected_policy.LoadFrom(&policy_dict,
412 test_harness_->policy_level(), 413 test_harness_->policy_level(),
413 test_harness_->policy_scope(), 414 test_harness_->policy_scope(),
414 test_harness_->policy_source()); 415 test_harness_->policy_source());
415 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 416 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
416 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) 417 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
417 .CopyFrom(expected_policy); 418 .CopyFrom(expected_policy);
418 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 419 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
419 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 420 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
420 .CopyFrom(expected_policy); 421 .CopyFrom(expected_policy);
421 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 422 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
422 } 423 }
423 424
424 } // namespace policy 425 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/config_dir_policy_loader_unittest.cc ('k') | components/policy/core/common/schema_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698