OLD | NEW |
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.h" | 5 #include "components/policy/core/common/registry_dict.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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 " \"string-to-int\": { \"type\": \"integer\" }," | 223 " \"string-to-int\": { \"type\": \"integer\" }," |
224 " \"string-to-dict\": { \"type\": \"object\" }" | 224 " \"string-to-dict\": { \"type\": \"object\" }" |
225 " }" | 225 " }" |
226 "}", | 226 "}", |
227 &error); | 227 &error); |
228 ASSERT_TRUE(schema.valid()) << error; | 228 ASSERT_TRUE(schema.valid()) << error; |
229 | 229 |
230 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); | 230 std::unique_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); |
231 | 231 |
232 base::DictionaryValue expected; | 232 base::DictionaryValue expected; |
233 expected.Set("one", int_value.CreateDeepCopy()); | 233 expected.Set("one", base::MakeUnique<base::Value>(int_value)); |
234 std::unique_ptr<base::DictionaryValue> expected_subdict( | 234 auto expected_subdict = base::MakeUnique<base::DictionaryValue>(); |
235 new base::DictionaryValue()); | 235 expected_subdict->Set("two", base::MakeUnique<base::Value>(string_value)); |
236 expected_subdict->Set("two", string_value.CreateDeepCopy()); | |
237 expected.Set("three", std::move(expected_subdict)); | 236 expected.Set("three", std::move(expected_subdict)); |
238 std::unique_ptr<base::ListValue> expected_list(new base::ListValue()); | 237 auto expected_list = base::MakeUnique<base::ListValue>(); |
239 expected_list->Append(string_value.CreateDeepCopy()); | 238 expected_list->Append(base::MakeUnique<base::Value>(string_value)); |
240 expected.Set("dict-to-list", std::move(expected_list)); | 239 expected.Set("dict-to-list", std::move(expected_list)); |
241 expected.Set("int-to-bool", new base::Value(true)); | 240 expected.SetBoolean("int-to-bool", true); |
242 expected.Set("int-to-double", new base::Value(42.0)); | 241 expected.SetDouble("int-to-double", 42.0); |
243 expected.Set("string-to-bool", new base::Value(false)); | 242 expected.SetBoolean("string-to-bool", false); |
244 expected.Set("string-to-double", new base::Value(0.0)); | 243 expected.SetDouble("string-to-double", 0.0); |
245 expected.Set("string-to-int", new base::Value(static_cast<int>(0))); | 244 expected.SetInteger("string-to-int", static_cast<int>(0)); |
246 expected_list.reset(new base::ListValue()); | 245 expected_list = base::MakeUnique<base::ListValue>(); |
247 expected_list->Append(base::MakeUnique<base::Value>("value")); | 246 expected_list->Append(base::MakeUnique<base::Value>("value")); |
248 expected_subdict.reset(new base::DictionaryValue()); | 247 expected_subdict = base::MakeUnique<base::DictionaryValue>(); |
249 expected_subdict->Set("key", std::move(expected_list)); | 248 expected_subdict->Set("key", std::move(expected_list)); |
250 expected.Set("string-to-dict", std::move(expected_subdict)); | 249 expected.Set("string-to-dict", std::move(expected_subdict)); |
251 | 250 |
252 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); | 251 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); |
253 } | 252 } |
254 | 253 |
255 TEST(RegistryDictTest, NonSequentialConvertToJSON) { | 254 TEST(RegistryDictTest, NonSequentialConvertToJSON) { |
256 RegistryDict test_dict; | 255 RegistryDict test_dict; |
257 | 256 |
258 std::unique_ptr<RegistryDict> list(new RegistryDict()); | 257 std::unique_ptr<RegistryDict> list(new RegistryDict()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 | 301 |
303 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); | 302 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); |
304 RegistryDict* actual_subdict = test_dict.GetKey("one"); | 303 RegistryDict* actual_subdict = test_dict.GetKey("one"); |
305 ASSERT_TRUE(actual_subdict); | 304 ASSERT_TRUE(actual_subdict); |
306 EXPECT_TRUE(base::Value::Equals(&string_value, | 305 EXPECT_TRUE(base::Value::Equals(&string_value, |
307 actual_subdict->GetValue("two"))); | 306 actual_subdict->GetValue("two"))); |
308 } | 307 } |
309 | 308 |
310 } // namespace | 309 } // namespace |
311 } // namespace policy | 310 } // namespace policy |
OLD | NEW |