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

Side by Side Diff: components/policy/core/common/registry_dict_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: rebase 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
« no previous file with comments | « components/policy/core/common/registry_dict_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/registry_dict_win.h" 5 #include "components/policy/core/common/registry_dict_win.h"
6 6
7 #include <string>
8
7 #include "base/values.h" 9 #include "base/values.h"
8 #include "components/json_schema/json_schema_constants.h" 10 #include "components/policy/core/common/schema.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace schema = json_schema_constants;
12
13 namespace policy { 13 namespace policy {
14 namespace { 14 namespace {
15 15
16 TEST(RegistryDictTest, SetAndGetValue) { 16 TEST(RegistryDictTest, SetAndGetValue) {
17 RegistryDict test_dict; 17 RegistryDict test_dict;
18 18
19 base::FundamentalValue int_value(42); 19 base::FundamentalValue int_value(42);
20 base::StringValue string_value("fortytwo"); 20 base::StringValue string_value("fortytwo");
21 21
22 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy())); 22 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy()));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three"))); 180 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three")));
181 EXPECT_FALSE(dict_a.GetValue("one")); 181 EXPECT_FALSE(dict_a.GetValue("one"));
182 EXPECT_FALSE(dict_a.GetKey("two")); 182 EXPECT_FALSE(dict_a.GetKey("two"));
183 } 183 }
184 184
185 TEST(RegistryDictTest, ConvertToJSON) { 185 TEST(RegistryDictTest, ConvertToJSON) {
186 RegistryDict test_dict; 186 RegistryDict test_dict;
187 187
188 base::FundamentalValue int_value(42); 188 base::FundamentalValue int_value(42);
189 base::StringValue string_value("fortytwo"); 189 base::StringValue string_value("fortytwo");
190 base::StringValue string_zero("0");
191 base::StringValue string_dict("{ \"key\": [ \"value\" ] }");
190 192
191 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy())); 193 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy()));
192 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 194 scoped_ptr<RegistryDict> subdict(new RegistryDict());
193 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy())); 195 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy()));
194 test_dict.SetKey("three", subdict.Pass()); 196 test_dict.SetKey("three", subdict.Pass());
195 scoped_ptr<RegistryDict> list(new RegistryDict()); 197 scoped_ptr<RegistryDict> list(new RegistryDict());
196 list->SetValue("1", make_scoped_ptr(string_value.DeepCopy())); 198 list->SetValue("1", make_scoped_ptr(string_value.DeepCopy()));
197 test_dict.SetKey("four", list.Pass()); 199 test_dict.SetKey("dict-to-list", list.Pass());
200 test_dict.SetValue("int-to-bool", make_scoped_ptr(int_value.DeepCopy()));
201 test_dict.SetValue("int-to-double", make_scoped_ptr(int_value.DeepCopy()));
202 test_dict.SetValue("string-to-bool", make_scoped_ptr(string_zero.DeepCopy()));
203 test_dict.SetValue("string-to-double",
204 make_scoped_ptr(string_zero.DeepCopy()));
205 test_dict.SetValue("string-to-int", make_scoped_ptr(string_zero.DeepCopy()));
206 test_dict.SetValue("string-to-dict", make_scoped_ptr(string_dict.DeepCopy()));
198 207
199 base::DictionaryValue schema; 208 std::string error;
200 scoped_ptr<base::DictionaryValue> list_schema(new base::DictionaryValue()); 209 Schema schema = Schema::Parse(
201 list_schema->SetString(schema::kType, schema::kArray); 210 "{"
202 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); 211 " \"type\": \"object\","
203 properties->Set("four", list_schema.release()); 212 " \"properties\": {"
204 schema.SetString(schema::kType, schema::kObject); 213 " \"dict-to-list\": {"
205 schema.Set(schema::kProperties, properties.release()); 214 " \"type\": \"array\","
215 " \"items\": { \"type\": \"string\" }"
216 " },"
217 " \"int-to-bool\": { \"type\": \"boolean\" },"
218 " \"int-to-double\": { \"type\": \"number\" },"
219 " \"string-to-bool\": { \"type\": \"boolean\" },"
220 " \"string-to-double\": { \"type\": \"number\" },"
221 " \"string-to-int\": { \"type\": \"integer\" },"
222 " \"string-to-dict\": { \"type\": \"object\" }"
223 " }"
224 "}", &error);
225 ASSERT_TRUE(schema.valid()) << error;
206 226
207 scoped_ptr<base::Value> actual(test_dict.ConvertToJSON(&schema)); 227 scoped_ptr<base::Value> actual(test_dict.ConvertToJSON(schema));
208 228
209 base::DictionaryValue expected; 229 base::DictionaryValue expected;
210 expected.Set("one", int_value.DeepCopy()); 230 expected.Set("one", int_value.DeepCopy());
211 scoped_ptr<base::DictionaryValue> expected_subdict( 231 scoped_ptr<base::DictionaryValue> expected_subdict(
212 new base::DictionaryValue()); 232 new base::DictionaryValue());
213 expected_subdict->Set("two", string_value.DeepCopy()); 233 expected_subdict->Set("two", string_value.DeepCopy());
214 expected.Set("three", expected_subdict.release()); 234 expected.Set("three", expected_subdict.release());
215 scoped_ptr<base::ListValue> expected_list(new base::ListValue()); 235 scoped_ptr<base::ListValue> expected_list(new base::ListValue());
216 expected_list->Append(string_value.DeepCopy()); 236 expected_list->Append(string_value.DeepCopy());
217 expected.Set("four", expected_list.release()); 237 expected.Set("dict-to-list", expected_list.release());
238 expected.Set("int-to-bool", new base::FundamentalValue(true));
239 expected.Set("int-to-double", new base::FundamentalValue(42.0));
240 expected.Set("string-to-bool", new base::FundamentalValue(false));
241 expected.Set("string-to-double", new base::FundamentalValue(0.0));
242 expected.Set("string-to-int", new base::FundamentalValue((int) 0));
243 expected_list.reset(new base::ListValue());
244 expected_list->Append(new base::StringValue("value"));
245 expected_subdict.reset(new base::DictionaryValue());
246 expected_subdict->Set("key", expected_list.release());
247 expected.Set("string-to-dict", expected_subdict.release());
218 248
219 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); 249 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected));
220 } 250 }
221 251
222 TEST(RegistryDictTest, KeyValueNameClashes) { 252 TEST(RegistryDictTest, KeyValueNameClashes) {
223 RegistryDict test_dict; 253 RegistryDict test_dict;
224 254
225 base::FundamentalValue int_value(42); 255 base::FundamentalValue int_value(42);
226 base::StringValue string_value("fortytwo"); 256 base::StringValue string_value("fortytwo");
227 257
228 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy())); 258 test_dict.SetValue("one", make_scoped_ptr(int_value.DeepCopy()));
229 scoped_ptr<RegistryDict> subdict(new RegistryDict()); 259 scoped_ptr<RegistryDict> subdict(new RegistryDict());
230 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy())); 260 subdict->SetValue("two", make_scoped_ptr(string_value.DeepCopy()));
231 test_dict.SetKey("one", subdict.Pass()); 261 test_dict.SetKey("one", subdict.Pass());
232 262
233 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); 263 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one")));
234 RegistryDict* actual_subdict = test_dict.GetKey("one"); 264 RegistryDict* actual_subdict = test_dict.GetKey("one");
235 ASSERT_TRUE(actual_subdict); 265 ASSERT_TRUE(actual_subdict);
236 EXPECT_TRUE(base::Value::Equals(&string_value, 266 EXPECT_TRUE(base::Value::Equals(&string_value,
237 actual_subdict->GetValue("two"))); 267 actual_subdict->GetValue("two")));
238 } 268 }
239 269
240 } // namespace 270 } // namespace
241 } // namespace policy 271 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/registry_dict_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698