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

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

Issue 2809933003: Remove ListValue::Append(raw ptr) on Win (Closed)
Patch Set: More Win Created 3 years, 8 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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <userenv.h> 10 #include <userenv.h>
(...skipping 14 matching lines...) Expand all
25 #include "base/macros.h" 25 #include "base/macros.h"
26 #include "base/memory/ptr_util.h" 26 #include "base/memory/ptr_util.h"
27 #include "base/path_service.h" 27 #include "base/path_service.h"
28 #include "base/process/process_handle.h" 28 #include "base/process/process_handle.h"
29 #include "base/strings/string16.h" 29 #include "base/strings/string16.h"
30 #include "base/strings/string_number_conversions.h" 30 #include "base/strings/string_number_conversions.h"
31 #include "base/strings/string_util.h" 31 #include "base/strings/string_util.h"
32 #include "base/strings/stringprintf.h" 32 #include "base/strings/stringprintf.h"
33 #include "base/strings/utf_string_conversions.h" 33 #include "base/strings/utf_string_conversions.h"
34 #include "base/sys_byteorder.h" 34 #include "base/sys_byteorder.h"
35 #include "base/win/registry.h" 35 #include "base/win/registry.h"
jdoerrie 2017/04/13 13:49:49 #include "base/values.h"
vabr (Chromium) 2017/04/13 16:06:48 Done.
36 #include "base/win/win_util.h" 36 #include "base/win/win_util.h"
37 #include "components/policy/core/common/async_policy_provider.h" 37 #include "components/policy/core/common/async_policy_provider.h"
38 #include "components/policy/core/common/configuration_policy_provider_test.h" 38 #include "components/policy/core/common/configuration_policy_provider_test.h"
39 #include "components/policy/core/common/external_data_fetcher.h" 39 #include "components/policy/core/common/external_data_fetcher.h"
40 #include "components/policy/core/common/policy_bundle.h" 40 #include "components/policy/core/common/policy_bundle.h"
41 #include "components/policy/core/common/policy_map.h" 41 #include "components/policy/core/common/policy_map.h"
42 #include "components/policy/core/common/policy_types.h" 42 #include "components/policy/core/common/policy_types.h"
43 #include "components/policy/core/common/preg_parser.h" 43 #include "components/policy/core/common/preg_parser.h"
44 #include "components/policy/core/common/schema_map.h" 44 #include "components/policy/core/common/schema_map.h"
45 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 " \"dict\": { \"$ref\": \"MainType\" }" 900 " \"dict\": { \"$ref\": \"MainType\" }"
901 " }" 901 " }"
902 "}")); 902 "}"));
903 903
904 base::DictionaryValue policy; 904 base::DictionaryValue policy;
905 policy.Set("null", base::MakeUnique<base::Value>()); 905 policy.Set("null", base::MakeUnique<base::Value>());
906 policy.SetBoolean("bool", true); 906 policy.SetBoolean("bool", true);
907 policy.SetInteger("int", -123); 907 policy.SetInteger("int", -123);
908 policy.SetDouble("double", 456.78e9); 908 policy.SetDouble("double", 456.78e9);
909 base::ListValue list; 909 base::ListValue list;
910 list.Append(policy.DeepCopy()); 910 list.Append(base::MakeUnique<base::Value>(policy));
911 list.Append(policy.DeepCopy()); 911 list.Append(base::MakeUnique<base::Value>(policy));
912 policy.Set("list", list.DeepCopy()); 912 policy.Set("list", base::MakeUnique<base::Value>(list));
913 // Encode |policy| before adding the "dict" entry. 913 // Encode |policy| before adding the "dict" entry.
914 std::string encoded_dict; 914 std::string encoded_dict;
915 base::JSONWriter::Write(policy, &encoded_dict); 915 base::JSONWriter::Write(policy, &encoded_dict);
916 ASSERT_FALSE(encoded_dict.empty()); 916 ASSERT_FALSE(encoded_dict.empty());
917 policy.Set("dict", policy.DeepCopy()); 917 policy.Set("dict", base::MakeUnique<base::Value>(policy));
918 std::string encoded_list; 918 std::string encoded_list;
919 base::JSONWriter::Write(list, &encoded_list); 919 base::JSONWriter::Write(list, &encoded_list);
920 ASSERT_FALSE(encoded_list.empty()); 920 ASSERT_FALSE(encoded_list.empty());
921 base::DictionaryValue encoded_policy; 921 base::DictionaryValue encoded_policy;
922 encoded_policy.SetString("null", ""); 922 encoded_policy.SetString("null", "");
923 encoded_policy.SetString("bool", "1"); 923 encoded_policy.SetString("bool", "1");
924 encoded_policy.SetString("int", "-123"); 924 encoded_policy.SetString("int", "-123");
925 encoded_policy.SetString("double", "456.78e9"); 925 encoded_policy.SetString("double", "456.78e9");
926 encoded_policy.SetString("list", encoded_list); 926 encoded_policy.SetString("list", encoded_list);
927 encoded_policy.SetString("dict", encoded_dict); 927 encoded_policy.SetString("dict", encoded_dict);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 // Write some test values. 994 // Write some test values.
995 base::DictionaryValue policy; 995 base::DictionaryValue policy;
996 // These special values have a specific schema for them. 996 // These special values have a specific schema for them.
997 policy.SetInteger("special-int1", 123); 997 policy.SetInteger("special-int1", 123);
998 policy.SetString("special-int2", "-456"); 998 policy.SetString("special-int2", "-456");
999 // Other values default to be loaded as doubles. 999 // Other values default to be loaded as doubles.
1000 policy.SetInteger("double1", 789.0); 1000 policy.SetInteger("double1", 789.0);
1001 policy.SetString("double2", "123.456e7"); 1001 policy.SetString("double2", "123.456e7");
1002 policy.SetString("invalid", "omg"); 1002 policy.SetString("invalid", "omg");
1003 base::DictionaryValue all_policies; 1003 base::DictionaryValue all_policies;
1004 all_policies.Set("policy", policy.DeepCopy()); 1004 all_policies.Set("policy", base::MakeUnique<base::Value>(policy));
1005 1005
1006 const base::string16 kPathSuffix = 1006 const base::string16 kPathSuffix =
1007 kTestPolicyKey + base::ASCIIToUTF16("\\3rdparty\\extensions\\test"); 1007 kTestPolicyKey + base::ASCIIToUTF16("\\3rdparty\\extensions\\test");
1008 EXPECT_TRUE( 1008 EXPECT_TRUE(
1009 InstallValue(all_policies, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); 1009 InstallValue(all_policies, HKEY_CURRENT_USER, kPathSuffix, kMandatory));
1010 1010
1011 base::DictionaryValue expected_policy; 1011 base::DictionaryValue expected_policy;
1012 expected_policy.SetInteger("special-int1", 123); 1012 expected_policy.SetInteger("special-int1", 123);
1013 expected_policy.SetInteger("special-int2", -456); 1013 expected_policy.SetInteger("special-int2", -456);
1014 expected_policy.SetDouble("double1", 789.0); 1014 expected_policy.SetDouble("double1", 789.0);
1015 expected_policy.SetDouble("double2", 123.456e7); 1015 expected_policy.SetDouble("double2", 123.456e7);
1016 base::DictionaryValue expected_policies; 1016 base::DictionaryValue expected_policies;
1017 expected_policies.Set("policy", expected_policy.DeepCopy()); 1017 expected_policies.Set("policy",
1018 base::MakeUnique<base::Value>(expected_policy));
1018 PolicyBundle expected; 1019 PolicyBundle expected;
1019 expected.Get(ns).LoadFrom(&expected_policies, POLICY_LEVEL_MANDATORY, 1020 expected.Get(ns).LoadFrom(&expected_policies, POLICY_LEVEL_MANDATORY,
1020 POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM); 1021 POLICY_SCOPE_USER, POLICY_SOURCE_PLATFORM);
1021 EXPECT_TRUE(Matches(expected)); 1022 EXPECT_TRUE(Matches(expected));
1022 } 1023 }
1023 1024
1024 TEST_F(PolicyLoaderWinTest, AppliedPolicyNotPresent) { 1025 TEST_F(PolicyLoaderWinTest, AppliedPolicyNotPresent) {
1025 InstallRegistrySentinel(); 1026 InstallRegistrySentinel();
1026 gpo_list_ = NULL; 1027 gpo_list_ = NULL;
1027 gpo_list_status_ = ERROR_SUCCESS; 1028 gpo_list_status_ = ERROR_SUCCESS;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 expected.Get(ns_a).LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, 1186 expected.Get(ns_a).LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY,
1186 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM); 1187 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM);
1187 base::DictionaryValue expected_b; 1188 base::DictionaryValue expected_b;
1188 expected_b.SetInteger("policy 1", 2); 1189 expected_b.SetInteger("policy 1", 2);
1189 expected.Get(ns_b).LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, 1190 expected.Get(ns_b).LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY,
1190 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM); 1191 POLICY_SCOPE_MACHINE, POLICY_SOURCE_PLATFORM);
1191 EXPECT_TRUE(Matches(expected)); 1192 EXPECT_TRUE(Matches(expected));
1192 } 1193 }
1193 1194
1194 } // namespace policy 1195 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698