OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/api/sync_change.h" | 5 #include "sync/api/sync_change.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 | 9 |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "sync/api/attachments/attachment_id.h" | 13 #include "sync/api/attachments/attachment_id.h" |
14 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test
.h" | 14 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test
.h" |
15 #include "sync/protocol/preference_specifics.pb.h" | 15 #include "sync/protocol/preference_specifics.pb.h" |
16 #include "sync/protocol/proto_value_conversions.h" | 16 #include "sync/protocol/proto_value_conversions.h" |
17 #include "sync/protocol/sync.pb.h" | 17 #include "sync/protocol/sync.pb.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
(...skipping 27 matching lines...) Expand all Loading... |
47 pref_specifics->set_name("test"); | 47 pref_specifics->set_name("test"); |
48 std::string tag = "client_tag"; | 48 std::string tag = "client_tag"; |
49 std::string title = "client_title"; | 49 std::string title = "client_title"; |
50 SyncChange e(FROM_HERE, | 50 SyncChange e(FROM_HERE, |
51 change_type, | 51 change_type, |
52 SyncData::CreateLocalData(tag, title, specifics)); | 52 SyncData::CreateLocalData(tag, title, specifics)); |
53 EXPECT_EQ(change_type, e.change_type()); | 53 EXPECT_EQ(change_type, e.change_type()); |
54 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag()); | 54 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag()); |
55 EXPECT_EQ(title, e.sync_data().GetTitle()); | 55 EXPECT_EQ(title, e.sync_data().GetTitle()); |
56 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); | 56 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); |
57 scoped_ptr<base::DictionaryValue> ref_spec(EntitySpecificsToValue(specifics)); | 57 std::unique_ptr<base::DictionaryValue> ref_spec( |
58 scoped_ptr<base::DictionaryValue> e_spec(EntitySpecificsToValue( | 58 EntitySpecificsToValue(specifics)); |
59 e.sync_data().GetSpecifics())); | 59 std::unique_ptr<base::DictionaryValue> e_spec( |
| 60 EntitySpecificsToValue(e.sync_data().GetSpecifics())); |
60 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); | 61 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); |
61 } | 62 } |
62 | 63 |
63 TEST_F(SyncChangeTest, LocalAdd) { | 64 TEST_F(SyncChangeTest, LocalAdd) { |
64 SyncChange::SyncChangeType change_type = SyncChange::ACTION_ADD; | 65 SyncChange::SyncChangeType change_type = SyncChange::ACTION_ADD; |
65 sync_pb::EntitySpecifics specifics; | 66 sync_pb::EntitySpecifics specifics; |
66 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); | 67 sync_pb::PreferenceSpecifics* pref_specifics = specifics.mutable_preference(); |
67 pref_specifics->set_name("test"); | 68 pref_specifics->set_name("test"); |
68 std::string tag = "client_tag"; | 69 std::string tag = "client_tag"; |
69 std::string title = "client_title"; | 70 std::string title = "client_title"; |
70 SyncChange e(FROM_HERE, | 71 SyncChange e(FROM_HERE, |
71 change_type, | 72 change_type, |
72 SyncData::CreateLocalData(tag, title, specifics)); | 73 SyncData::CreateLocalData(tag, title, specifics)); |
73 EXPECT_EQ(change_type, e.change_type()); | 74 EXPECT_EQ(change_type, e.change_type()); |
74 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag()); | 75 EXPECT_EQ(tag, SyncDataLocal(e.sync_data()).GetTag()); |
75 EXPECT_EQ(title, e.sync_data().GetTitle()); | 76 EXPECT_EQ(title, e.sync_data().GetTitle()); |
76 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); | 77 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); |
77 scoped_ptr<base::DictionaryValue> ref_spec(EntitySpecificsToValue(specifics)); | 78 std::unique_ptr<base::DictionaryValue> ref_spec( |
78 scoped_ptr<base::DictionaryValue> e_spec(EntitySpecificsToValue( | 79 EntitySpecificsToValue(specifics)); |
79 e.sync_data().GetSpecifics())); | 80 std::unique_ptr<base::DictionaryValue> e_spec( |
| 81 EntitySpecificsToValue(e.sync_data().GetSpecifics())); |
80 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); | 82 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); |
81 } | 83 } |
82 | 84 |
83 TEST_F(SyncChangeTest, SyncerChanges) { | 85 TEST_F(SyncChangeTest, SyncerChanges) { |
84 SyncChangeList change_list; | 86 SyncChangeList change_list; |
85 | 87 |
86 // Create an update. | 88 // Create an update. |
87 sync_pb::EntitySpecifics update_specifics; | 89 sync_pb::EntitySpecifics update_specifics; |
88 sync_pb::PreferenceSpecifics* pref_specifics = | 90 sync_pb::PreferenceSpecifics* pref_specifics = |
89 update_specifics.mutable_preference(); | 91 update_specifics.mutable_preference(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 base::Time(), | 127 base::Time(), |
126 syncer::AttachmentIdList(), | 128 syncer::AttachmentIdList(), |
127 syncer::AttachmentServiceProxyForTest::Create()))); | 129 syncer::AttachmentServiceProxyForTest::Create()))); |
128 | 130 |
129 ASSERT_EQ(3U, change_list.size()); | 131 ASSERT_EQ(3U, change_list.size()); |
130 | 132 |
131 // Verify update. | 133 // Verify update. |
132 SyncChange e = change_list[0]; | 134 SyncChange e = change_list[0]; |
133 EXPECT_EQ(SyncChange::ACTION_UPDATE, e.change_type()); | 135 EXPECT_EQ(SyncChange::ACTION_UPDATE, e.change_type()); |
134 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); | 136 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); |
135 scoped_ptr<base::DictionaryValue> ref_spec(EntitySpecificsToValue( | 137 std::unique_ptr<base::DictionaryValue> ref_spec( |
136 update_specifics)); | 138 EntitySpecificsToValue(update_specifics)); |
137 scoped_ptr<base::DictionaryValue> e_spec(EntitySpecificsToValue( | 139 std::unique_ptr<base::DictionaryValue> e_spec( |
138 e.sync_data().GetSpecifics())); | 140 EntitySpecificsToValue(e.sync_data().GetSpecifics())); |
139 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); | 141 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); |
140 | 142 |
141 // Verify add. | 143 // Verify add. |
142 e = change_list[1]; | 144 e = change_list[1]; |
143 EXPECT_EQ(SyncChange::ACTION_ADD, e.change_type()); | 145 EXPECT_EQ(SyncChange::ACTION_ADD, e.change_type()); |
144 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); | 146 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); |
145 ref_spec = EntitySpecificsToValue(add_specifics); | 147 ref_spec = EntitySpecificsToValue(add_specifics); |
146 e_spec = EntitySpecificsToValue(e.sync_data().GetSpecifics()); | 148 e_spec = EntitySpecificsToValue(e.sync_data().GetSpecifics()); |
147 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); | 149 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); |
148 | 150 |
149 // Verify delete. | 151 // Verify delete. |
150 e = change_list[2]; | 152 e = change_list[2]; |
151 EXPECT_EQ(SyncChange::ACTION_DELETE, e.change_type()); | 153 EXPECT_EQ(SyncChange::ACTION_DELETE, e.change_type()); |
152 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); | 154 EXPECT_EQ(PREFERENCES, e.sync_data().GetDataType()); |
153 ref_spec = EntitySpecificsToValue(delete_specifics); | 155 ref_spec = EntitySpecificsToValue(delete_specifics); |
154 e_spec = EntitySpecificsToValue(e.sync_data().GetSpecifics()); | 156 e_spec = EntitySpecificsToValue(e.sync_data().GetSpecifics()); |
155 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); | 157 EXPECT_TRUE(ref_spec->Equals(e_spec.get())); |
156 } | 158 } |
157 | 159 |
158 } // namespace | 160 } // namespace |
159 | 161 |
160 } // namespace syncer | 162 } // namespace syncer |
OLD | NEW |