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

Side by Side Diff: chrome/browser/policy/policy_loader_win_unittest.cc

Issue 102493002: Use schemas bundled in extensions to convert policies loaded on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added bug url Created 7 years 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 "chrome/browser/policy/policy_loader_win.h" 5 #include "chrome/browser/policy/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 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 InstallValue(encoded_policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); 1037 InstallValue(encoded_policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory));
1038 1038
1039 PolicyBundle expected; 1039 PolicyBundle expected;
1040 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "int")) 1040 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "int"))
1041 .LoadFrom(&policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); 1041 .LoadFrom(&policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
1042 EXPECT_TRUE(Matches(expected)); 1042 EXPECT_TRUE(Matches(expected));
1043 } 1043 }
1044 1044
1045 TEST_F(PolicyLoaderWinTest, DefaultPropertySchemaType) { 1045 TEST_F(PolicyLoaderWinTest, DefaultPropertySchemaType) {
1046 // Build a schema for an "object" with a default schema for its properties. 1046 // Build a schema for an "object" with a default schema for its properties.
1047 // Note that the top-level object can't have "additionalProperties", so
1048 // a "policy" property is used instead.
1047 base::DictionaryValue default_schema; 1049 base::DictionaryValue default_schema;
1048 default_schema.SetString(schema::kType, "number"); 1050 default_schema.SetString(schema::kType, "number");
1049 base::DictionaryValue integer_schema; 1051 base::DictionaryValue integer_schema;
1050 integer_schema.SetString(schema::kType, "integer"); 1052 integer_schema.SetString(schema::kType, "integer");
1051 base::DictionaryValue properties; 1053 base::DictionaryValue policy_properties;
1052 properties.Set("special-int1", integer_schema.DeepCopy()); 1054 policy_properties.Set("special-int1", integer_schema.DeepCopy());
1053 properties.Set("special-int2", integer_schema.DeepCopy()); 1055 policy_properties.Set("special-int2", integer_schema.DeepCopy());
1056 base::DictionaryValue policy_schema;
1057 policy_schema.SetString(schema::kType, "object");
1058 policy_schema.Set(schema::kProperties, policy_properties.DeepCopy());
1059 policy_schema.Set(schema::kAdditionalProperties, default_schema.DeepCopy());
1060 base::DictionaryValue schema_properties;
1061 schema_properties.Set("policy", policy_schema.DeepCopy());
1054 base::DictionaryValue schema; 1062 base::DictionaryValue schema;
1055 schema.SetString(schema::kType, "object"); 1063 schema.SetString(schema::kType, "object");
1056 schema.Set(schema::kProperties, properties.DeepCopy()); 1064 schema.Set(schema::kProperties, schema_properties.DeepCopy());
1057 schema.Set(schema::kAdditionalProperties, default_schema.DeepCopy());
1058 1065
1059 const string16 kPathSuffix = 1066 const string16 kPathSuffix =
1060 kTestPolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\test"); 1067 kTestPolicyKey + ASCIIToUTF16("\\3rdparty\\extensions\\test");
1061 EXPECT_TRUE(WriteSchema(schema, HKEY_CURRENT_USER, kPathSuffix, kSchema)); 1068 EXPECT_TRUE(WriteSchema(schema, HKEY_CURRENT_USER, kPathSuffix, kSchema));
1062 1069
1063 // Write some test values. 1070 // Write some test values.
1064 base::DictionaryValue policy; 1071 base::DictionaryValue policy;
1065 // These special values have a specific schema for them. 1072 // These special values have a specific schema for them.
1066 policy.SetInteger("special-int1", 123); 1073 policy.SetInteger("special-int1", 123);
1067 policy.SetString("special-int2", "-456"); 1074 policy.SetString("special-int2", "-456");
1068 // Other values default to be loaded as doubles. 1075 // Other values default to be loaded as doubles.
1069 policy.SetInteger("double1", 789.0); 1076 policy.SetInteger("double1", 789.0);
1070 policy.SetString("double2", "123.456e7"); 1077 policy.SetString("double2", "123.456e7");
1071 policy.SetString("invalid", "omg"); 1078 policy.SetString("invalid", "omg");
1072 EXPECT_TRUE(InstallValue(policy, HKEY_CURRENT_USER, kPathSuffix, kMandatory)); 1079 base::DictionaryValue all_policies;
1080 all_policies.Set("policy", policy.DeepCopy());
1081 EXPECT_TRUE(
1082 InstallValue(all_policies, HKEY_CURRENT_USER, kPathSuffix, kMandatory));
1073 1083
1074 base::DictionaryValue expected_policy; 1084 base::DictionaryValue expected_policy;
1075 expected_policy.SetInteger("special-int1", 123); 1085 expected_policy.SetInteger("special-int1", 123);
1076 expected_policy.SetInteger("special-int2", -456); 1086 expected_policy.SetInteger("special-int2", -456);
1077 expected_policy.SetDouble("double1", 789.0); 1087 expected_policy.SetDouble("double1", 789.0);
1078 expected_policy.SetDouble("double2", 123.456e7); 1088 expected_policy.SetDouble("double2", 123.456e7);
1079 expected_policy.Set("invalid", base::Value::CreateNullValue()); 1089 expected_policy.Set("invalid", base::Value::CreateNullValue());
1090 base::DictionaryValue expected_policies;
1091 expected_policies.Set("policy", expected_policy.DeepCopy());
1080 PolicyBundle expected; 1092 PolicyBundle expected;
1081 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "test")) 1093 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, "test"))
1082 .LoadFrom(&expected_policy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); 1094 .LoadFrom(&expected_policies, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
1083 EXPECT_TRUE(Matches(expected)); 1095 EXPECT_TRUE(Matches(expected));
1084 } 1096 }
1085 1097
1086 TEST_F(PolicyLoaderWinTest, AppliedPolicyNotPresent) { 1098 TEST_F(PolicyLoaderWinTest, AppliedPolicyNotPresent) {
1087 InstallRegistrySentinel(); 1099 InstallRegistrySentinel();
1088 gpo_list_ = NULL; 1100 gpo_list_ = NULL;
1089 gpo_list_status_ = ERROR_SUCCESS; 1101 gpo_list_status_ = ERROR_SUCCESS;
1090 1102
1091 PolicyBundle empty; 1103 PolicyBundle empty;
1092 EXPECT_TRUE(Matches(empty)); 1104 EXPECT_TRUE(Matches(empty));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); 1221 .LoadFrom(&expected_a, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
1210 base::DictionaryValue expected_b; 1222 base::DictionaryValue expected_b;
1211 expected_b.SetInteger("policy 1", 2); 1223 expected_b.SetInteger("policy 1", 2);
1212 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 1224 expected.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
1213 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 1225 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
1214 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); 1226 .LoadFrom(&expected_b, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
1215 EXPECT_TRUE(Matches(expected)); 1227 EXPECT_TRUE(Matches(expected));
1216 } 1228 }
1217 1229
1218 } // namespace policy 1230 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698