Chromium Code Reviews| 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_win.h" | 5 #include "components/policy/core/common/registry_dict_win.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | |
| 8 | 9 |
| 9 #include "base/values.h" | 10 #include "base/values.h" |
| 10 #include "components/policy/core/common/schema.h" | 11 #include "components/policy/core/common/schema.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace policy { | 14 namespace policy { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 TEST(RegistryDictTest, SetAndGetValue) { | 17 TEST(RegistryDictTest, SetAndGetValue) { |
| 17 RegistryDict test_dict; | 18 RegistryDict test_dict; |
| 18 | 19 |
| 19 base::FundamentalValue int_value(42); | 20 base::FundamentalValue int_value(42); |
| 20 base::StringValue string_value("fortytwo"); | 21 base::StringValue string_value("fortytwo"); |
| 21 | 22 |
| 22 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); | 23 test_dict.SetValue("one", int_value.CreateDeepCopy()); |
|
dcheng
2016/03/02 01:59:58
Strictly speaking, not directly related, but since
| |
| 23 EXPECT_EQ(1u, test_dict.values().size()); | 24 EXPECT_EQ(1u, test_dict.values().size()); |
| 24 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); | 25 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); |
| 25 EXPECT_FALSE(test_dict.GetValue("two")); | 26 EXPECT_FALSE(test_dict.GetValue("two")); |
| 26 | 27 |
| 27 test_dict.SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy())); | 28 test_dict.SetValue("two", string_value.CreateDeepCopy()); |
| 28 EXPECT_EQ(2u, test_dict.values().size()); | 29 EXPECT_EQ(2u, test_dict.values().size()); |
| 29 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); | 30 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); |
| 30 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two"))); | 31 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two"))); |
| 31 | 32 |
| 32 scoped_ptr<base::Value> one(test_dict.RemoveValue("one")); | 33 scoped_ptr<base::Value> one(test_dict.RemoveValue("one")); |
| 33 EXPECT_EQ(1u, test_dict.values().size()); | 34 EXPECT_EQ(1u, test_dict.values().size()); |
| 34 EXPECT_TRUE(base::Value::Equals(&int_value, one.get())); | 35 EXPECT_TRUE(base::Value::Equals(&int_value, one.get())); |
| 35 EXPECT_FALSE(test_dict.GetValue("one")); | 36 EXPECT_FALSE(test_dict.GetValue("one")); |
| 36 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two"))); | 37 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("two"))); |
| 37 | 38 |
| 38 test_dict.ClearValues(); | 39 test_dict.ClearValues(); |
| 39 EXPECT_FALSE(test_dict.GetValue("one")); | 40 EXPECT_FALSE(test_dict.GetValue("one")); |
| 40 EXPECT_FALSE(test_dict.GetValue("two")); | 41 EXPECT_FALSE(test_dict.GetValue("two")); |
| 41 EXPECT_TRUE(test_dict.values().empty()); | 42 EXPECT_TRUE(test_dict.values().empty()); |
| 42 } | 43 } |
| 43 | 44 |
| 44 TEST(RegistryDictTest, CaseInsensitiveButPreservingValueNames) { | 45 TEST(RegistryDictTest, CaseInsensitiveButPreservingValueNames) { |
| 45 RegistryDict test_dict; | 46 RegistryDict test_dict; |
| 46 | 47 |
| 47 base::FundamentalValue int_value(42); | 48 base::FundamentalValue int_value(42); |
| 48 base::StringValue string_value("fortytwo"); | 49 base::StringValue string_value("fortytwo"); |
| 49 | 50 |
| 50 test_dict.SetValue("One", scoped_ptr<base::Value>(int_value.DeepCopy())); | 51 test_dict.SetValue("One", int_value.CreateDeepCopy()); |
| 51 EXPECT_EQ(1u, test_dict.values().size()); | 52 EXPECT_EQ(1u, test_dict.values().size()); |
| 52 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("oNe"))); | 53 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("oNe"))); |
| 53 | 54 |
| 54 RegistryDict::ValueMap::const_iterator entry = test_dict.values().begin(); | 55 RegistryDict::ValueMap::const_iterator entry = test_dict.values().begin(); |
| 55 ASSERT_NE(entry, test_dict.values().end()); | 56 ASSERT_NE(entry, test_dict.values().end()); |
| 56 EXPECT_EQ("One", entry->first); | 57 EXPECT_EQ("One", entry->first); |
| 57 | 58 |
| 58 test_dict.SetValue("ONE", scoped_ptr<base::Value>(string_value.DeepCopy())); | 59 test_dict.SetValue("ONE", string_value.CreateDeepCopy()); |
| 59 EXPECT_EQ(1u, test_dict.values().size()); | 60 EXPECT_EQ(1u, test_dict.values().size()); |
| 60 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("one"))); | 61 EXPECT_TRUE(base::Value::Equals(&string_value, test_dict.GetValue("one"))); |
| 61 | 62 |
| 62 scoped_ptr<base::Value> removed_value(test_dict.RemoveValue("onE")); | 63 scoped_ptr<base::Value> removed_value(test_dict.RemoveValue("onE")); |
| 63 EXPECT_TRUE(base::Value::Equals(&string_value, removed_value.get())); | 64 EXPECT_TRUE(base::Value::Equals(&string_value, removed_value.get())); |
| 64 EXPECT_TRUE(test_dict.values().empty()); | 65 EXPECT_TRUE(test_dict.values().empty()); |
| 65 } | 66 } |
| 66 | 67 |
| 67 TEST(RegistryDictTest, SetAndGetKeys) { | 68 TEST(RegistryDictTest, SetAndGetKeys) { |
| 68 RegistryDict test_dict; | 69 RegistryDict test_dict; |
| 69 | 70 |
| 70 base::FundamentalValue int_value(42); | 71 base::FundamentalValue int_value(42); |
| 71 base::StringValue string_value("fortytwo"); | 72 base::StringValue string_value("fortytwo"); |
| 72 | 73 |
| 73 scoped_ptr<RegistryDict> subdict(new RegistryDict()); | 74 scoped_ptr<RegistryDict> subdict(new RegistryDict()); |
| 74 subdict->SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); | 75 subdict->SetValue("one", int_value.CreateDeepCopy()); |
| 75 test_dict.SetKey("two", subdict.Pass()); | 76 test_dict.SetKey("two", std::move(subdict)); |
| 76 EXPECT_EQ(1u, test_dict.keys().size()); | 77 EXPECT_EQ(1u, test_dict.keys().size()); |
| 77 RegistryDict* actual_subdict = test_dict.GetKey("two"); | 78 RegistryDict* actual_subdict = test_dict.GetKey("two"); |
| 78 ASSERT_TRUE(actual_subdict); | 79 ASSERT_TRUE(actual_subdict); |
| 79 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one"))); | 80 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one"))); |
| 80 | 81 |
| 81 subdict.reset(new RegistryDict()); | 82 subdict.reset(new RegistryDict()); |
| 82 subdict->SetValue("three", scoped_ptr<base::Value>(string_value.DeepCopy())); | 83 subdict->SetValue("three", string_value.CreateDeepCopy()); |
| 83 test_dict.SetKey("four", subdict.Pass()); | 84 test_dict.SetKey("four", std::move(subdict)); |
| 84 EXPECT_EQ(2u, test_dict.keys().size()); | 85 EXPECT_EQ(2u, test_dict.keys().size()); |
| 85 actual_subdict = test_dict.GetKey("two"); | 86 actual_subdict = test_dict.GetKey("two"); |
| 86 ASSERT_TRUE(actual_subdict); | 87 ASSERT_TRUE(actual_subdict); |
| 87 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one"))); | 88 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("one"))); |
| 88 actual_subdict = test_dict.GetKey("four"); | 89 actual_subdict = test_dict.GetKey("four"); |
| 89 ASSERT_TRUE(actual_subdict); | 90 ASSERT_TRUE(actual_subdict); |
| 90 EXPECT_TRUE(base::Value::Equals(&string_value, | 91 EXPECT_TRUE(base::Value::Equals(&string_value, |
| 91 actual_subdict->GetValue("three"))); | 92 actual_subdict->GetValue("three"))); |
| 92 | 93 |
| 93 test_dict.ClearKeys(); | 94 test_dict.ClearKeys(); |
| 94 EXPECT_FALSE(test_dict.GetKey("one")); | 95 EXPECT_FALSE(test_dict.GetKey("one")); |
| 95 EXPECT_FALSE(test_dict.GetKey("three")); | 96 EXPECT_FALSE(test_dict.GetKey("three")); |
| 96 EXPECT_TRUE(test_dict.keys().empty()); | 97 EXPECT_TRUE(test_dict.keys().empty()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 TEST(RegistryDictTest, CaseInsensitiveButPreservingKeyNames) { | 100 TEST(RegistryDictTest, CaseInsensitiveButPreservingKeyNames) { |
| 100 RegistryDict test_dict; | 101 RegistryDict test_dict; |
| 101 | 102 |
| 102 base::FundamentalValue int_value(42); | 103 base::FundamentalValue int_value(42); |
| 103 | 104 |
| 104 test_dict.SetKey("One", make_scoped_ptr(new RegistryDict()).Pass()); | 105 test_dict.SetKey("One", make_scoped_ptr(new RegistryDict())); |
| 105 EXPECT_EQ(1u, test_dict.keys().size()); | 106 EXPECT_EQ(1u, test_dict.keys().size()); |
| 106 RegistryDict* actual_subdict = test_dict.GetKey("One"); | 107 RegistryDict* actual_subdict = test_dict.GetKey("One"); |
| 107 ASSERT_TRUE(actual_subdict); | 108 ASSERT_TRUE(actual_subdict); |
| 108 EXPECT_TRUE(actual_subdict->values().empty()); | 109 EXPECT_TRUE(actual_subdict->values().empty()); |
| 109 | 110 |
| 110 RegistryDict::KeyMap::const_iterator entry = test_dict.keys().begin(); | 111 RegistryDict::KeyMap::const_iterator entry = test_dict.keys().begin(); |
| 111 ASSERT_NE(entry, test_dict.keys().end()); | 112 ASSERT_NE(entry, test_dict.keys().end()); |
| 112 EXPECT_EQ("One", entry->first); | 113 EXPECT_EQ("One", entry->first); |
| 113 | 114 |
| 114 scoped_ptr<RegistryDict> subdict(new RegistryDict()); | 115 scoped_ptr<RegistryDict> subdict(new RegistryDict()); |
| 115 subdict->SetValue("two", scoped_ptr<base::Value>(int_value.DeepCopy())); | 116 subdict->SetValue("two", int_value.CreateDeepCopy()); |
| 116 test_dict.SetKey("ONE", subdict.Pass()); | 117 test_dict.SetKey("ONE", std::move(subdict)); |
| 117 EXPECT_EQ(1u, test_dict.keys().size()); | 118 EXPECT_EQ(1u, test_dict.keys().size()); |
| 118 actual_subdict = test_dict.GetKey("One"); | 119 actual_subdict = test_dict.GetKey("One"); |
| 119 ASSERT_TRUE(actual_subdict); | 120 ASSERT_TRUE(actual_subdict); |
| 120 EXPECT_TRUE(base::Value::Equals(&int_value, | 121 EXPECT_TRUE(base::Value::Equals(&int_value, |
| 121 actual_subdict->GetValue("two"))); | 122 actual_subdict->GetValue("two"))); |
| 122 | 123 |
| 123 scoped_ptr<RegistryDict> removed_key(test_dict.RemoveKey("one")); | 124 scoped_ptr<RegistryDict> removed_key(test_dict.RemoveKey("one")); |
| 124 ASSERT_TRUE(removed_key); | 125 ASSERT_TRUE(removed_key); |
| 125 EXPECT_TRUE(base::Value::Equals(&int_value, | 126 EXPECT_TRUE(base::Value::Equals(&int_value, |
| 126 removed_key->GetValue("two"))); | 127 removed_key->GetValue("two"))); |
| 127 EXPECT_TRUE(test_dict.keys().empty()); | 128 EXPECT_TRUE(test_dict.keys().empty()); |
| 128 } | 129 } |
| 129 | 130 |
| 130 TEST(RegistryDictTest, Merge) { | 131 TEST(RegistryDictTest, Merge) { |
| 131 RegistryDict dict_a; | 132 RegistryDict dict_a; |
| 132 RegistryDict dict_b; | 133 RegistryDict dict_b; |
| 133 | 134 |
| 134 base::FundamentalValue int_value(42); | 135 base::FundamentalValue int_value(42); |
| 135 base::StringValue string_value("fortytwo"); | 136 base::StringValue string_value("fortytwo"); |
| 136 | 137 |
| 137 dict_a.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); | 138 dict_a.SetValue("one", int_value.CreateDeepCopy()); |
| 138 scoped_ptr<RegistryDict> subdict(new RegistryDict()); | 139 scoped_ptr<RegistryDict> subdict(new RegistryDict()); |
| 139 subdict->SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy())); | 140 subdict->SetValue("two", string_value.CreateDeepCopy()); |
| 140 dict_a.SetKey("three", subdict.Pass()); | 141 dict_a.SetKey("three", std::move(subdict)); |
| 141 | 142 |
| 142 dict_b.SetValue("four", scoped_ptr<base::Value>(string_value.DeepCopy())); | 143 dict_b.SetValue("four", string_value.CreateDeepCopy()); |
| 143 subdict.reset(new RegistryDict()); | 144 subdict.reset(new RegistryDict()); |
| 144 subdict->SetValue("two", scoped_ptr<base::Value>(int_value.DeepCopy())); | 145 subdict->SetValue("two", int_value.CreateDeepCopy()); |
| 145 dict_b.SetKey("three", subdict.Pass()); | 146 dict_b.SetKey("three", std::move(subdict)); |
| 146 subdict.reset(new RegistryDict()); | 147 subdict.reset(new RegistryDict()); |
| 147 subdict->SetValue("five", scoped_ptr<base::Value>(int_value.DeepCopy())); | 148 subdict->SetValue("five", int_value.CreateDeepCopy()); |
| 148 dict_b.SetKey("six", subdict.Pass()); | 149 dict_b.SetKey("six", std::move(subdict)); |
| 149 | 150 |
| 150 dict_a.Merge(dict_b); | 151 dict_a.Merge(dict_b); |
| 151 | 152 |
| 152 EXPECT_TRUE(base::Value::Equals(&int_value, dict_a.GetValue("one"))); | 153 EXPECT_TRUE(base::Value::Equals(&int_value, dict_a.GetValue("one"))); |
| 153 EXPECT_TRUE(base::Value::Equals(&string_value, dict_b.GetValue("four"))); | 154 EXPECT_TRUE(base::Value::Equals(&string_value, dict_b.GetValue("four"))); |
| 154 RegistryDict* actual_subdict = dict_a.GetKey("three"); | 155 RegistryDict* actual_subdict = dict_a.GetKey("three"); |
| 155 ASSERT_TRUE(actual_subdict); | 156 ASSERT_TRUE(actual_subdict); |
| 156 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("two"))); | 157 EXPECT_TRUE(base::Value::Equals(&int_value, actual_subdict->GetValue("two"))); |
| 157 actual_subdict = dict_a.GetKey("six"); | 158 actual_subdict = dict_a.GetKey("six"); |
| 158 ASSERT_TRUE(actual_subdict); | 159 ASSERT_TRUE(actual_subdict); |
| 159 EXPECT_TRUE(base::Value::Equals(&int_value, | 160 EXPECT_TRUE(base::Value::Equals(&int_value, |
| 160 actual_subdict->GetValue("five"))); | 161 actual_subdict->GetValue("five"))); |
| 161 } | 162 } |
| 162 | 163 |
| 163 TEST(RegistryDictTest, Swap) { | 164 TEST(RegistryDictTest, Swap) { |
| 164 RegistryDict dict_a; | 165 RegistryDict dict_a; |
| 165 RegistryDict dict_b; | 166 RegistryDict dict_b; |
| 166 | 167 |
| 167 base::FundamentalValue int_value(42); | 168 base::FundamentalValue int_value(42); |
| 168 base::StringValue string_value("fortytwo"); | 169 base::StringValue string_value("fortytwo"); |
| 169 | 170 |
| 170 dict_a.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); | 171 dict_a.SetValue("one", int_value.CreateDeepCopy()); |
| 171 dict_a.SetKey("two", make_scoped_ptr(new RegistryDict()).Pass()); | 172 dict_a.SetKey("two", make_scoped_ptr(new RegistryDict())); |
| 172 dict_b.SetValue("three", scoped_ptr<base::Value>(string_value.DeepCopy())); | 173 dict_b.SetValue("three", string_value.CreateDeepCopy()); |
| 173 | 174 |
| 174 dict_a.Swap(&dict_b); | 175 dict_a.Swap(&dict_b); |
| 175 | 176 |
| 176 EXPECT_TRUE(base::Value::Equals(&int_value, dict_b.GetValue("one"))); | 177 EXPECT_TRUE(base::Value::Equals(&int_value, dict_b.GetValue("one"))); |
| 177 EXPECT_TRUE(dict_b.GetKey("two")); | 178 EXPECT_TRUE(dict_b.GetKey("two")); |
| 178 EXPECT_FALSE(dict_b.GetValue("two")); | 179 EXPECT_FALSE(dict_b.GetValue("two")); |
| 179 | 180 |
| 180 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three"))); | 181 EXPECT_TRUE(base::Value::Equals(&string_value, dict_a.GetValue("three"))); |
| 181 EXPECT_FALSE(dict_a.GetValue("one")); | 182 EXPECT_FALSE(dict_a.GetValue("one")); |
| 182 EXPECT_FALSE(dict_a.GetKey("two")); | 183 EXPECT_FALSE(dict_a.GetKey("two")); |
| 183 } | 184 } |
| 184 | 185 |
| 185 TEST(RegistryDictTest, ConvertToJSON) { | 186 TEST(RegistryDictTest, ConvertToJSON) { |
| 186 RegistryDict test_dict; | 187 RegistryDict test_dict; |
| 187 | 188 |
| 188 base::FundamentalValue int_value(42); | 189 base::FundamentalValue int_value(42); |
| 189 base::StringValue string_value("fortytwo"); | 190 base::StringValue string_value("fortytwo"); |
| 190 base::StringValue string_zero("0"); | 191 base::StringValue string_zero("0"); |
| 191 base::StringValue string_dict("{ \"key\": [ \"value\" ] }"); | 192 base::StringValue string_dict("{ \"key\": [ \"value\" ] }"); |
| 192 | 193 |
| 193 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); | 194 test_dict.SetValue("one", int_value.CreateDeepCopy()); |
| 194 scoped_ptr<RegistryDict> subdict(new RegistryDict()); | 195 scoped_ptr<RegistryDict> subdict(new RegistryDict()); |
| 195 subdict->SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy())); | 196 subdict->SetValue("two", string_value.CreateDeepCopy()); |
| 196 test_dict.SetKey("three", subdict.Pass()); | 197 test_dict.SetKey("three", std::move(subdict)); |
| 197 scoped_ptr<RegistryDict> list(new RegistryDict()); | 198 scoped_ptr<RegistryDict> list(new RegistryDict()); |
| 198 list->SetValue("1", scoped_ptr<base::Value>(string_value.DeepCopy())); | 199 list->SetValue("1", string_value.CreateDeepCopy()); |
| 199 test_dict.SetKey("dict-to-list", list.Pass()); | 200 test_dict.SetKey("dict-to-list", std::move(list)); |
| 200 test_dict.SetValue("int-to-bool", | 201 test_dict.SetValue("int-to-bool", int_value.CreateDeepCopy()); |
| 201 scoped_ptr<base::Value>(int_value.DeepCopy())); | 202 test_dict.SetValue("int-to-double", int_value.CreateDeepCopy()); |
| 202 test_dict.SetValue("int-to-double", | 203 test_dict.SetValue("string-to-bool", string_zero.CreateDeepCopy()); |
| 203 scoped_ptr<base::Value>(int_value.DeepCopy())); | 204 test_dict.SetValue("string-to-double", string_zero.CreateDeepCopy()); |
| 204 test_dict.SetValue("string-to-bool", | 205 test_dict.SetValue("string-to-int", string_zero.CreateDeepCopy()); |
| 205 scoped_ptr<base::Value>(string_zero.DeepCopy())); | 206 test_dict.SetValue("string-to-dict", string_dict.CreateDeepCopy()); |
| 206 test_dict.SetValue("string-to-double", | |
| 207 scoped_ptr<base::Value>(string_zero.DeepCopy())); | |
| 208 test_dict.SetValue("string-to-int", | |
| 209 scoped_ptr<base::Value>(string_zero.DeepCopy())); | |
| 210 test_dict.SetValue("string-to-dict", | |
| 211 scoped_ptr<base::Value>(string_dict.DeepCopy())); | |
| 212 | 207 |
| 213 std::string error; | 208 std::string error; |
| 214 Schema schema = Schema::Parse( | 209 Schema schema = Schema::Parse( |
| 215 "{" | 210 "{" |
| 216 " \"type\": \"object\"," | 211 " \"type\": \"object\"," |
| 217 " \"properties\": {" | 212 " \"properties\": {" |
| 218 " \"dict-to-list\": {" | 213 " \"dict-to-list\": {" |
| 219 " \"type\": \"array\"," | 214 " \"type\": \"array\"," |
| 220 " \"items\": { \"type\": \"string\" }" | 215 " \"items\": { \"type\": \"string\" }" |
| 221 " }," | 216 " }," |
| 222 " \"int-to-bool\": { \"type\": \"boolean\" }," | 217 " \"int-to-bool\": { \"type\": \"boolean\" }," |
| 223 " \"int-to-double\": { \"type\": \"number\" }," | 218 " \"int-to-double\": { \"type\": \"number\" }," |
| 224 " \"string-to-bool\": { \"type\": \"boolean\" }," | 219 " \"string-to-bool\": { \"type\": \"boolean\" }," |
| 225 " \"string-to-double\": { \"type\": \"number\" }," | 220 " \"string-to-double\": { \"type\": \"number\" }," |
| 226 " \"string-to-int\": { \"type\": \"integer\" }," | 221 " \"string-to-int\": { \"type\": \"integer\" }," |
| 227 " \"string-to-dict\": { \"type\": \"object\" }" | 222 " \"string-to-dict\": { \"type\": \"object\" }" |
| 228 " }" | 223 " }" |
| 229 "}", &error); | 224 "}", &error); |
| 230 ASSERT_TRUE(schema.valid()) << error; | 225 ASSERT_TRUE(schema.valid()) << error; |
| 231 | 226 |
| 232 scoped_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); | 227 scoped_ptr<base::Value> actual(test_dict.ConvertToJSON(schema)); |
| 233 | 228 |
| 234 base::DictionaryValue expected; | 229 base::DictionaryValue expected; |
| 235 expected.Set("one", int_value.DeepCopy()); | 230 expected.Set("one", int_value.CreateDeepCopy()); |
| 236 scoped_ptr<base::DictionaryValue> expected_subdict( | 231 scoped_ptr<base::DictionaryValue> expected_subdict( |
| 237 new base::DictionaryValue()); | 232 new base::DictionaryValue()); |
| 238 expected_subdict->Set("two", string_value.DeepCopy()); | 233 expected_subdict->Set("two", string_value.CreateDeepCopy()); |
| 239 expected.Set("three", expected_subdict.release()); | 234 expected.Set("three", std::move(expected_subdict)); |
| 240 scoped_ptr<base::ListValue> expected_list(new base::ListValue()); | 235 scoped_ptr<base::ListValue> expected_list(new base::ListValue()); |
| 241 expected_list->Append(string_value.DeepCopy()); | 236 expected_list->Append(string_value.CreateDeepCopy()); |
| 242 expected.Set("dict-to-list", expected_list.release()); | 237 expected.Set("dict-to-list", std::move(expected_list)); |
| 243 expected.Set("int-to-bool", new base::FundamentalValue(true)); | 238 expected.Set("int-to-bool", new base::FundamentalValue(true)); |
| 244 expected.Set("int-to-double", new base::FundamentalValue(42.0)); | 239 expected.Set("int-to-double", new base::FundamentalValue(42.0)); |
| 245 expected.Set("string-to-bool", new base::FundamentalValue(false)); | 240 expected.Set("string-to-bool", new base::FundamentalValue(false)); |
| 246 expected.Set("string-to-double", new base::FundamentalValue(0.0)); | 241 expected.Set("string-to-double", new base::FundamentalValue(0.0)); |
| 247 expected.Set("string-to-int", | 242 expected.Set("string-to-int", |
| 248 new base::FundamentalValue(static_cast<int>(0))); | 243 new base::FundamentalValue(static_cast<int>(0))); |
| 249 expected_list.reset(new base::ListValue()); | 244 expected_list.reset(new base::ListValue()); |
| 250 expected_list->Append(new base::StringValue("value")); | 245 expected_list->Append(new base::StringValue("value")); |
| 251 expected_subdict.reset(new base::DictionaryValue()); | 246 expected_subdict.reset(new base::DictionaryValue()); |
| 252 expected_subdict->Set("key", expected_list.release()); | 247 expected_subdict->Set("key", std::move(expected_list)); |
| 253 expected.Set("string-to-dict", expected_subdict.release()); | 248 expected.Set("string-to-dict", std::move(expected_subdict)); |
| 254 | 249 |
| 255 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); | 250 EXPECT_TRUE(base::Value::Equals(actual.get(), &expected)); |
| 256 } | 251 } |
| 257 | 252 |
| 258 TEST(RegistryDictTest, KeyValueNameClashes) { | 253 TEST(RegistryDictTest, KeyValueNameClashes) { |
| 259 RegistryDict test_dict; | 254 RegistryDict test_dict; |
| 260 | 255 |
| 261 base::FundamentalValue int_value(42); | 256 base::FundamentalValue int_value(42); |
| 262 base::StringValue string_value("fortytwo"); | 257 base::StringValue string_value("fortytwo"); |
| 263 | 258 |
| 264 test_dict.SetValue("one", scoped_ptr<base::Value>(int_value.DeepCopy())); | 259 test_dict.SetValue("one", int_value.CreateDeepCopy()); |
| 265 scoped_ptr<RegistryDict> subdict(new RegistryDict()); | 260 scoped_ptr<RegistryDict> subdict(new RegistryDict()); |
| 266 subdict->SetValue("two", scoped_ptr<base::Value>(string_value.DeepCopy())); | 261 subdict->SetValue("two", string_value.CreateDeepCopy()); |
| 267 test_dict.SetKey("one", subdict.Pass()); | 262 test_dict.SetKey("one", std::move(subdict)); |
| 268 | 263 |
| 269 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); | 264 EXPECT_TRUE(base::Value::Equals(&int_value, test_dict.GetValue("one"))); |
| 270 RegistryDict* actual_subdict = test_dict.GetKey("one"); | 265 RegistryDict* actual_subdict = test_dict.GetKey("one"); |
| 271 ASSERT_TRUE(actual_subdict); | 266 ASSERT_TRUE(actual_subdict); |
| 272 EXPECT_TRUE(base::Value::Equals(&string_value, | 267 EXPECT_TRUE(base::Value::Equals(&string_value, |
| 273 actual_subdict->GetValue("two"))); | 268 actual_subdict->GetValue("two"))); |
| 274 } | 269 } |
| 275 | 270 |
| 276 } // namespace | 271 } // namespace |
| 277 } // namespace policy | 272 } // namespace policy |
| OLD | NEW |