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

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

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy_loader_win.h" 5 #include "components/policy/core/common/policy_loader_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <userenv.h> 8 #include <userenv.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 std::string name(base::IntToString(index++)); 395 std::string name(base::IntToString(index++));
396 key.WriteValue(UTF8ToUTF16(name).c_str(), 396 key.WriteValue(UTF8ToUTF16(name).c_str(),
397 UTF8ToUTF16(element_value).c_str()); 397 UTF8ToUTF16(element_value).c_str());
398 } 398 }
399 } 399 }
400 400
401 void RegistryTestHarness::InstallDictionaryPolicy( 401 void RegistryTestHarness::InstallDictionaryPolicy(
402 const std::string& policy_name, 402 const std::string& policy_name,
403 const base::DictionaryValue* policy_value) { 403 const base::DictionaryValue* policy_value) {
404 std::string json; 404 std::string json;
405 base::JSONWriter::Write(policy_value, &json); 405 base::JSONWriter::Write(*policy_value, &json);
406 RegKey key(hive_, kTestPolicyKey, KEY_ALL_ACCESS); 406 RegKey key(hive_, kTestPolicyKey, KEY_ALL_ACCESS);
407 ASSERT_TRUE(key.Valid()); 407 ASSERT_TRUE(key.Valid());
408 key.WriteValue(UTF8ToUTF16(policy_name).c_str(), 408 key.WriteValue(UTF8ToUTF16(policy_name).c_str(),
409 UTF8ToUTF16(json).c_str()); 409 UTF8ToUTF16(json).c_str());
410 } 410 }
411 411
412 void RegistryTestHarness::Install3rdPartyPolicy( 412 void RegistryTestHarness::Install3rdPartyPolicy(
413 const base::DictionaryValue* policies) { 413 const base::DictionaryValue* policies) {
414 // The first level entries are domains, and the second level entries map 414 // The first level entries are domains, and the second level entries map
415 // components to their policy. 415 // components to their policy.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 void PRegTestHarness::InstallStringListPolicy( 499 void PRegTestHarness::InstallStringListPolicy(
500 const std::string& policy_name, 500 const std::string& policy_name,
501 const base::ListValue* policy_value) { 501 const base::ListValue* policy_value) {
502 AppendPolicyToPRegFile(kTestPolicyKey, policy_name, policy_value); 502 AppendPolicyToPRegFile(kTestPolicyKey, policy_name, policy_value);
503 } 503 }
504 504
505 void PRegTestHarness::InstallDictionaryPolicy( 505 void PRegTestHarness::InstallDictionaryPolicy(
506 const std::string& policy_name, 506 const std::string& policy_name,
507 const base::DictionaryValue* policy_value) { 507 const base::DictionaryValue* policy_value) {
508 std::string json; 508 std::string json;
509 base::JSONWriter::Write(policy_value, &json); 509 base::JSONWriter::Write(*policy_value, &json);
510 AppendStringToPRegFile(kTestPolicyKey, policy_name, json); 510 AppendStringToPRegFile(kTestPolicyKey, policy_name, json);
511 } 511 }
512 512
513 void PRegTestHarness::Install3rdPartyPolicy( 513 void PRegTestHarness::Install3rdPartyPolicy(
514 const base::DictionaryValue* policies) { 514 const base::DictionaryValue* policies) {
515 // The first level entries are domains, and the second level entries map 515 // The first level entries are domains, and the second level entries map
516 // components to their policy. 516 // components to their policy.
517 const base::string16 kPathPrefix = 517 const base::string16 kPathPrefix =
518 base::string16(kTestPolicyKey) + kPathSep + kThirdParty + kPathSep; 518 base::string16(kTestPolicyKey) + kPathSep + kThirdParty + kPathSep;
519 for (base::DictionaryValue::Iterator domain(*policies); 519 for (base::DictionaryValue::Iterator domain(*policies);
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 policy.Set("null", base::Value::CreateNullValue()); 903 policy.Set("null", base::Value::CreateNullValue());
904 policy.SetBoolean("bool", true); 904 policy.SetBoolean("bool", true);
905 policy.SetInteger("int", -123); 905 policy.SetInteger("int", -123);
906 policy.SetDouble("double", 456.78e9); 906 policy.SetDouble("double", 456.78e9);
907 base::ListValue list; 907 base::ListValue list;
908 list.Append(policy.DeepCopy()); 908 list.Append(policy.DeepCopy());
909 list.Append(policy.DeepCopy()); 909 list.Append(policy.DeepCopy());
910 policy.Set("list", list.DeepCopy()); 910 policy.Set("list", list.DeepCopy());
911 // Encode |policy| before adding the "dict" entry. 911 // Encode |policy| before adding the "dict" entry.
912 std::string encoded_dict; 912 std::string encoded_dict;
913 base::JSONWriter::Write(&policy, &encoded_dict); 913 base::JSONWriter::Write(policy, &encoded_dict);
914 ASSERT_FALSE(encoded_dict.empty()); 914 ASSERT_FALSE(encoded_dict.empty());
915 policy.Set("dict", policy.DeepCopy()); 915 policy.Set("dict", policy.DeepCopy());
916 std::string encoded_list; 916 std::string encoded_list;
917 base::JSONWriter::Write(&list, &encoded_list); 917 base::JSONWriter::Write(list, &encoded_list);
918 ASSERT_FALSE(encoded_list.empty()); 918 ASSERT_FALSE(encoded_list.empty());
919 base::DictionaryValue encoded_policy; 919 base::DictionaryValue encoded_policy;
920 encoded_policy.SetString("null", ""); 920 encoded_policy.SetString("null", "");
921 encoded_policy.SetString("bool", "1"); 921 encoded_policy.SetString("bool", "1");
922 encoded_policy.SetString("int", "-123"); 922 encoded_policy.SetString("int", "-123");
923 encoded_policy.SetString("double", "456.78e9"); 923 encoded_policy.SetString("double", "456.78e9");
924 encoded_policy.SetString("list", encoded_list); 924 encoded_policy.SetString("list", encoded_list);
925 encoded_policy.SetString("dict", encoded_dict); 925 encoded_policy.SetString("dict", encoded_dict);
926 926
927 const base::string16 kPathSuffix = 927 const base::string16 kPathSuffix =
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 PolicyMap& expected_policy = expected.Get(ns); 1219 PolicyMap& expected_policy = expected.Get(ns);
1220 expected_policy.Set("alternative_browser_path", 1220 expected_policy.Set("alternative_browser_path",
1221 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 1221 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
1222 new base::StringValue("c:\\legacy\\browser.exe"), NULL); 1222 new base::StringValue("c:\\legacy\\browser.exe"), NULL);
1223 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 1223 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
1224 list.DeepCopy(), NULL); 1224 list.DeepCopy(), NULL);
1225 EXPECT_TRUE(Matches(expected)); 1225 EXPECT_TRUE(Matches(expected));
1226 } 1226 }
1227 1227
1228 } // namespace policy 1228 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_loader_win.cc ('k') | components/policy/core/common/policy_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698