OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "extensions/browser/value_store/value_store_change.h" | 9 #include "extensions/browser/value_store/value_store_change.h" |
10 #include "extensions/common/value_builder.h" | 10 #include "extensions/common/value_builder.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 EXPECT_TRUE(change.new_value()->Equals(expected.get())); | 54 EXPECT_TRUE(change.new_value()->Equals(expected.get())); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 TEST(ValueStoreChangeTest, ToJson) { | 58 TEST(ValueStoreChangeTest, ToJson) { |
59 // Create a mildly complicated structure that has dots in it. | 59 // Create a mildly complicated structure that has dots in it. |
60 scoped_ptr<base::DictionaryValue> value = | 60 scoped_ptr<base::DictionaryValue> value = |
61 DictionaryBuilder() | 61 DictionaryBuilder() |
62 .Set("key", "value") | 62 .Set("key", "value") |
63 .Set("key.with.dots", "value.with.dots") | 63 .Set("key.with.dots", "value.with.dots") |
64 .Set("tricked", std::move(DictionaryBuilder().Set("you", "nodots"))) | 64 .Set("tricked", DictionaryBuilder().Set("you", "nodots").Build()) |
65 .Set("tricked.you", "with.dots") | 65 .Set("tricked.you", "with.dots") |
66 .Build(); | 66 .Build(); |
67 | 67 |
68 ValueStoreChangeList change_list; | 68 ValueStoreChangeList change_list; |
69 change_list.push_back( | 69 change_list.push_back( |
70 ValueStoreChange("key", value->DeepCopy(), value->DeepCopy())); | 70 ValueStoreChange("key", value->DeepCopy(), value->DeepCopy())); |
71 change_list.push_back( | 71 change_list.push_back( |
72 ValueStoreChange("key.with.dots", value->DeepCopy(), value->DeepCopy())); | 72 ValueStoreChange("key.with.dots", value->DeepCopy(), value->DeepCopy())); |
73 | 73 |
74 std::string json = ValueStoreChange::ToJson(change_list); | 74 std::string json = ValueStoreChange::ToJson(change_list); |
75 scoped_ptr<base::Value> from_json(base::JSONReader::Read(json)); | 75 scoped_ptr<base::Value> from_json(base::JSONReader::Read(json)); |
76 ASSERT_TRUE(from_json.get()); | 76 ASSERT_TRUE(from_json.get()); |
77 | 77 |
78 DictionaryBuilder v1(*value); | 78 DictionaryBuilder v1(*value); |
79 DictionaryBuilder v2(*value); | 79 DictionaryBuilder v2(*value); |
80 DictionaryBuilder v3(*value); | 80 DictionaryBuilder v3(*value); |
81 DictionaryBuilder v4(*value); | 81 DictionaryBuilder v4(*value); |
82 scoped_ptr<base::DictionaryValue> expected_from_json = | 82 scoped_ptr<base::DictionaryValue> expected_from_json = |
83 DictionaryBuilder() | 83 DictionaryBuilder() |
84 .Set("key", std::move(DictionaryBuilder() | 84 .Set("key", DictionaryBuilder() |
85 .Set("oldValue", std::move(v1)) | 85 .Set("oldValue", v1.Build()) |
86 .Set("newValue", std::move(v2)))) | 86 .Set("newValue", v2.Build()) |
87 .Set("key.with.dots", std::move(DictionaryBuilder() | 87 .Build()) |
88 .Set("oldValue", std::move(v3)) | 88 .Set("key.with.dots", DictionaryBuilder() |
89 .Set("newValue", std::move(v4)))) | 89 .Set("oldValue", v3.Build()) |
| 90 .Set("newValue", v4.Build()) |
| 91 .Build()) |
90 .Build(); | 92 .Build(); |
91 | 93 |
92 EXPECT_TRUE(from_json->Equals(expected_from_json.get())); | 94 EXPECT_TRUE(from_json->Equals(expected_from_json.get())); |
93 } | 95 } |
94 | 96 |
95 } // namespace | 97 } // namespace |
OLD | NEW |