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

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

Issue 2478503002: Enable non-sequential entries when loading registry lists. (Closed)
Patch Set: Validate that the key is numerical. Created 4 years, 1 month 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> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 " \"type\": \"array\"," 215 " \"type\": \"array\","
216 " \"items\": { \"type\": \"string\" }" 216 " \"items\": { \"type\": \"string\" }"
217 " }," 217 " },"
218 " \"int-to-bool\": { \"type\": \"boolean\" }," 218 " \"int-to-bool\": { \"type\": \"boolean\" },"
219 " \"int-to-double\": { \"type\": \"number\" }," 219 " \"int-to-double\": { \"type\": \"number\" },"
220 " \"string-to-bool\": { \"type\": \"boolean\" }," 220 " \"string-to-bool\": { \"type\": \"boolean\" },"
221 " \"string-to-double\": { \"type\": \"number\" }," 221 " \"string-to-double\": { \"type\": \"number\" },"
222 " \"string-to-int\": { \"type\": \"integer\" }," 222 " \"string-to-int\": { \"type\": \"integer\" },"
223 " \"string-to-dict\": { \"type\": \"object\" }" 223 " \"string-to-dict\": { \"type\": \"object\" }"
224 " }" 224 " }"
225 "}", &error); 225 "}",
226 &error);
226 ASSERT_TRUE(schema.valid()) << error; 227 ASSERT_TRUE(schema.valid()) << error;
227 228
228 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); 229 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema));
229 230
230 base::DictionaryValue expected; 231 base::DictionaryValue expected;
231 expected.Set("one", int_value.CreateDeepCopy()); 232 expected.Set("one", int_value.CreateDeepCopy());
232 std::unique_ptr<base::DictionaryValue> expected_subdict( 233 std::unique_ptr<base::DictionaryValue> expected_subdict(
233 new base::DictionaryValue()); 234 new base::DictionaryValue());
234 expected_subdict->Set("two", string_value.CreateDeepCopy()); 235 expected_subdict->Set("two", string_value.CreateDeepCopy());
235 expected.Set("three", std::move(expected_subdict)); 236 expected.Set("three", std::move(expected_subdict));
236 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); 237 std::unique_ptr<base::ListValue> expected_list(new base::ListValue());
237 expected_list->Append(string_value.CreateDeepCopy()); 238 expected_list->Append(string_value.CreateDeepCopy());
238 expected.Set("dict-to-list", std::move(expected_list)); 239 expected.Set("dict-to-list", std::move(expected_list));
239 expected.Set("int-to-bool", new base::FundamentalValue(true)); 240 expected.Set("int-to-bool", new base::FundamentalValue(true));
240 expected.Set("int-to-double", new base::FundamentalValue(42.0)); 241 expected.Set("int-to-double", new base::FundamentalValue(42.0));
241 expected.Set("string-to-bool", new base::FundamentalValue(false)); 242 expected.Set("string-to-bool", new base::FundamentalValue(false));
242 expected.Set("string-to-double", new base::FundamentalValue(0.0)); 243 expected.Set("string-to-double", new base::FundamentalValue(0.0));
243 expected.Set("string-to-int", 244 expected.Set("string-to-int",
244 new base::FundamentalValue(static_cast<int>(0))); 245 new base::FundamentalValue(static_cast<int>(0)));
245 expected_list.reset(new base::ListValue()); 246 expected_list.reset(new base::ListValue());
246 expected_list->Append(new base::StringValue("value")); 247 expected_list->Append(new base::StringValue("value"));
247 expected_subdict.reset(new base::DictionaryValue()); 248 expected_subdict.reset(new base::DictionaryValue());
248 expected_subdict->Set("key", std::move(expected_list)); 249 expected_subdict->Set("key", std::move(expected_list));
249 expected.Set("string-to-dict", std::move(expected_subdict)); 250 expected.Set("string-to-dict", std::move(expected_subdict));
250 251
251 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); 252 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected));
252 } 253 }
253 254
255 TEST(RegistryDictTest, NonSequentialConvertToJSON) {
256 RegistryDict test_dict;
257
258 std::unique_ptr<RegistryDict> list(new RegistryDict());
259 list->SetValue("1", base::StringValue("1").CreateDeepCopy());
260 list->SetValue("2", base::StringValue("2").CreateDeepCopy());
261 list->SetValue("THREE", base::StringValue("3").CreateDeepCopy());
262 list->SetValue("4", base::StringValue("4").CreateDeepCopy());
263 test_dict.SetKey("dict-to-list", std::move(list));
264
265 std::string error;
266 Schema schema = Schema::Parse(
267 "{"
268 " \"type\": \"object\","
269 " \"properties\": {"
270 " \"dict-to-list\": {"
271 " \"type\": \"array\","
272 " \"items\": { \"type\": \"string\" }"
273 " }"
274 " }"
275 "}",
276 &error);
277 ASSERT_TRUE(schema.valid()) << error;
278
279 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema));
280
281 base::DictionaryValue expected;
282 std::unique_ptr<base::ListValue> expected_list(new base::ListValue());
283 expected_list->Append(base::StringValue("1").CreateDeepCopy());
284 expected_list->Append(base::StringValue("2").CreateDeepCopy());
285 expected_list->Append(base::StringValue("4").CreateDeepCopy());
286 expected.Set("dict-to-list", std::move(expected_list));
287
288 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected));
289 }
290
254 TEST(RegistryDictTest, KeyValueNameClashes) { 291 TEST(RegistryDictTest, KeyValueNameClashes) {
255 RegistryDict test_dict; 292 RegistryDict test_dict;
256 293
257 base::FundamentalValue int_value(42); 294 base::FundamentalValue int_value(42);
258 base::StringValue string_value("fortytwo"); 295 base::StringValue string_value("fortytwo");
259 296
260 test_dict.SetValue("one", int_value.CreateDeepCopy()); 297 test_dict.SetValue("one", int_value.CreateDeepCopy());
261 std::unique_ptr<RegistryDict> subdict(new RegistryDict()); 298 std::unique_ptr<RegistryDict> subdict(new RegistryDict());
262 subdict->SetValue("two", string_value.CreateDeepCopy()); 299 subdict->SetValue("two", string_value.CreateDeepCopy());
263 test_dict.SetKey("one", std::move(subdict)); 300 test_dict.SetKey("one", std::move(subdict));
264 301
265 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); 302 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one")));
266 RegistryDict* actual_subdict = test_dict.GetKey("one"); 303 RegistryDict* actual_subdict = test_dict.GetKey("one");
267 ASSERT_TRUE(actual_subdict); 304 ASSERT_TRUE(actual_subdict);
268 EXPECT_TRUE(base::Value::Equals(&string_value, 305 EXPECT_TRUE(base::Value::Equals(&string_value,
269 actual_subdict->GetValue("two"))); 306 actual_subdict->GetValue("two")));
270 } 307 }
271 308
272 } // namespace 309 } // namespace
273 } // namespace policy 310 } // 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