OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/engine/process_commit_response_command.h" | 5 #include "sync/engine/process_commit_response_command.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "sync/internal_api/public/test/test_entry_factory.h" |
11 #include "sync/protocol/bookmark_specifics.pb.h" | 12 #include "sync/protocol/bookmark_specifics.pb.h" |
12 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
13 #include "sync/sessions/sync_session.h" | 14 #include "sync/sessions/sync_session.h" |
14 #include "sync/syncable/entry.h" | 15 #include "sync/syncable/entry.h" |
15 #include "sync/syncable/mutable_entry.h" | 16 #include "sync/syncable/mutable_entry.h" |
16 #include "sync/syncable/syncable_id.h" | 17 #include "sync/syncable/syncable_id.h" |
17 #include "sync/syncable/syncable_proto_util.h" | 18 #include "sync/syncable/syncable_proto_util.h" |
18 #include "sync/syncable/syncable_read_transaction.h" | 19 #include "sync/syncable/syncable_read_transaction.h" |
19 #include "sync/syncable/syncable_write_transaction.h" | 20 #include "sync/syncable/syncable_write_transaction.h" |
20 #include "sync/test/engine/fake_model_worker.h" | 21 #include "sync/test/engine/fake_model_worker.h" |
(...skipping 27 matching lines...) Expand all Loading... |
48 | 49 |
49 workers()->push_back( | 50 workers()->push_back( |
50 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 51 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
51 workers()->push_back( | 52 workers()->push_back( |
52 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 53 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
53 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; | 54 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; |
54 (*mutable_routing_info())[PREFERENCES] = GROUP_UI; | 55 (*mutable_routing_info())[PREFERENCES] = GROUP_UI; |
55 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; | 56 (*mutable_routing_info())[AUTOFILL] = GROUP_DB; |
56 | 57 |
57 SyncerCommandTest::SetUp(); | 58 SyncerCommandTest::SetUp(); |
| 59 |
| 60 test_entry_factory_.reset(new TestEntryFactory(directory())); |
58 } | 61 } |
59 | 62 |
60 protected: | 63 protected: |
61 | 64 |
62 ProcessCommitResponseCommandTest() | 65 ProcessCommitResponseCommandTest() |
63 : next_old_revision_(1), | 66 : next_new_revision_(4000), |
64 next_new_revision_(4000), | |
65 next_server_position_(10000) { | 67 next_server_position_(10000) { |
66 } | 68 } |
67 | 69 |
68 void CheckEntry(Entry* e, const std::string& name, | 70 void CheckEntry(Entry* e, const std::string& name, |
69 ModelType model_type, const Id& parent_id) { | 71 ModelType model_type, const Id& parent_id) { |
70 EXPECT_TRUE(e->good()); | 72 EXPECT_TRUE(e->good()); |
71 ASSERT_EQ(name, e->Get(NON_UNIQUE_NAME)); | 73 ASSERT_EQ(name, e->Get(NON_UNIQUE_NAME)); |
72 ASSERT_EQ(model_type, e->GetModelType()); | 74 ASSERT_EQ(model_type, e->GetModelType()); |
73 ASSERT_EQ(parent_id, e->Get(syncable::PARENT_ID)); | 75 ASSERT_EQ(parent_id, e->Get(syncable::PARENT_ID)); |
74 ASSERT_LT(0, e->Get(BASE_VERSION)) | 76 ASSERT_LT(0, e->Get(BASE_VERSION)) |
75 << "Item should have a valid (positive) server base revision"; | 77 << "Item should have a valid (positive) server base revision"; |
76 } | 78 } |
77 | 79 |
78 // Create an unsynced item in the database. If item_id is a local ID, it | 80 // Create a new unsynced item in the database, and synthesize a commit record |
79 // will be treated as a create-new. Otherwise, if it's a server ID, we'll | 81 // and a commit response for it in the syncer session. If item_id is a local |
80 // fake the server data so that it looks like it exists on the server. | 82 // ID, the item will be a create operation. Otherwise, it will be an edit. |
81 // Returns the methandle of the created item in |metahandle_out| if not NULL. | 83 // Returns the metahandle of the newly created item. |
82 void CreateUnsyncedItem(const Id& item_id, | 84 int CreateUnprocessedCommitResult( |
83 const Id& parent_id, | |
84 const string& name, | |
85 bool is_folder, | |
86 ModelType model_type, | |
87 int64* metahandle_out) { | |
88 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | |
89 Id predecessor_id; | |
90 ASSERT_TRUE( | |
91 directory()->GetLastChildIdForTest(&trans, parent_id, &predecessor_id)); | |
92 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); | |
93 ASSERT_TRUE(entry.good()); | |
94 entry.Put(syncable::ID, item_id); | |
95 entry.Put(syncable::BASE_VERSION, | |
96 item_id.ServerKnows() ? next_old_revision_++ : 0); | |
97 entry.Put(syncable::IS_UNSYNCED, true); | |
98 entry.Put(syncable::IS_DIR, is_folder); | |
99 entry.Put(syncable::IS_DEL, false); | |
100 entry.Put(syncable::PARENT_ID, parent_id); | |
101 entry.PutPredecessor(predecessor_id); | |
102 sync_pb::EntitySpecifics default_specifics; | |
103 AddDefaultFieldValue(model_type, &default_specifics); | |
104 entry.Put(syncable::SPECIFICS, default_specifics); | |
105 if (item_id.ServerKnows()) { | |
106 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); | |
107 entry.Put(syncable::SERVER_IS_DIR, is_folder); | |
108 entry.Put(syncable::SERVER_PARENT_ID, parent_id); | |
109 entry.Put(syncable::SERVER_IS_DEL, false); | |
110 } | |
111 if (metahandle_out) | |
112 *metahandle_out = entry.Get(syncable::META_HANDLE); | |
113 } | |
114 | |
115 // Create a new unsynced item in the database, and synthesize a commit | |
116 // record and a commit response for it in the syncer session. If item_id | |
117 // is a local ID, the item will be a create operation. Otherwise, it | |
118 // will be an edit. | |
119 void CreateUnprocessedCommitResult( | |
120 const Id& item_id, | 85 const Id& item_id, |
121 const Id& parent_id, | 86 const Id& parent_id, |
122 const string& name, | 87 const string& name, |
| 88 bool is_folder, |
123 ModelType model_type, | 89 ModelType model_type, |
124 sessions::OrderedCommitSet *commit_set, | 90 sessions::OrderedCommitSet *commit_set, |
125 sync_pb::ClientToServerMessage *commit, | 91 sync_pb::ClientToServerMessage *commit, |
126 sync_pb::ClientToServerResponse *response) { | 92 sync_pb::ClientToServerResponse *response) { |
127 bool is_folder = true; | |
128 int64 metahandle = 0; | 93 int64 metahandle = 0; |
129 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, | 94 test_entry_factory_->CreateUnsyncedItem(item_id, parent_id, name, |
130 &metahandle); | 95 is_folder, model_type, &metahandle); |
131 | 96 |
132 // ProcessCommitResponseCommand consumes commit_ids from the session | 97 // ProcessCommitResponseCommand consumes commit_ids from the session |
133 // state, so we need to update that. O(n^2) because it's a test. | 98 // state, so we need to update that. O(n^2) because it's a test. |
134 commit_set->AddCommitItem(metahandle, item_id, model_type); | 99 commit_set->AddCommitItem(metahandle, item_id, model_type); |
135 | 100 |
136 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 101 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
137 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); | 102 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); |
138 ASSERT_TRUE(entry.good()); | 103 EXPECT_TRUE(entry.good()); |
139 entry.Put(syncable::SYNCING, true); | 104 entry.Put(syncable::SYNCING, true); |
140 | 105 |
141 // Add to the commit message. | 106 // Add to the commit message. |
| 107 // TODO(sync): Use the real commit-building code to construct this. |
142 commit->set_message_contents(ClientToServerMessage::COMMIT); | 108 commit->set_message_contents(ClientToServerMessage::COMMIT); |
143 sync_pb::SyncEntity* entity = commit->mutable_commit()->add_entries(); | 109 sync_pb::SyncEntity* entity = commit->mutable_commit()->add_entries(); |
144 entity->set_non_unique_name(name); | 110 entity->set_non_unique_name(entry.Get(syncable::NON_UNIQUE_NAME)); |
145 entity->set_folder(is_folder); | 111 entity->set_folder(entry.Get(syncable::IS_DIR)); |
146 entity->set_parent_id_string(SyncableIdToProto(parent_id)); | 112 entity->set_parent_id_string( |
| 113 SyncableIdToProto(entry.Get(syncable::PARENT_ID))); |
147 entity->set_version(entry.Get(syncable::BASE_VERSION)); | 114 entity->set_version(entry.Get(syncable::BASE_VERSION)); |
148 entity->mutable_specifics()->CopyFrom(entry.Get(syncable::SPECIFICS)); | 115 entity->mutable_specifics()->CopyFrom(entry.Get(syncable::SPECIFICS)); |
149 entity->set_id_string(SyncableIdToProto(item_id)); | 116 entity->set_id_string(SyncableIdToProto(item_id)); |
150 | 117 |
| 118 if (!entry.Get(syncable::UNIQUE_CLIENT_TAG).empty()) { |
| 119 entity->set_client_defined_unique_tag( |
| 120 entry.Get(syncable::UNIQUE_CLIENT_TAG)); |
| 121 } |
| 122 |
151 // Add to the response message. | 123 // Add to the response message. |
152 response->set_error_code(sync_pb::SyncEnums::SUCCESS); | 124 response->set_error_code(sync_pb::SyncEnums::SUCCESS); |
153 sync_pb::CommitResponse_EntryResponse* entry_response = | 125 sync_pb::CommitResponse_EntryResponse* entry_response = |
154 response->mutable_commit()->add_entryresponse(); | 126 response->mutable_commit()->add_entryresponse(); |
155 entry_response->set_response_type(CommitResponse::SUCCESS); | 127 entry_response->set_response_type(CommitResponse::SUCCESS); |
156 entry_response->set_name("Garbage."); | 128 entry_response->set_name("Garbage."); |
157 entry_response->set_non_unique_name(entity->name()); | 129 entry_response->set_non_unique_name(entity->name()); |
158 if (item_id.ServerKnows()) | 130 if (item_id.ServerKnows()) |
159 entry_response->set_id_string(entity->id_string()); | 131 entry_response->set_id_string(entity->id_string()); |
160 else | 132 else |
161 entry_response->set_id_string(id_factory_.NewServerId().GetServerId()); | 133 entry_response->set_id_string(id_factory_.NewServerId().GetServerId()); |
162 entry_response->set_version(next_new_revision_++); | 134 entry_response->set_version(next_new_revision_++); |
163 entry_response->set_position_in_parent(next_server_position_++); | 135 entry_response->set_position_in_parent(next_server_position_++); |
164 | 136 |
165 // If the ID of our parent item committed earlier in the batch was | 137 // If the ID of our parent item committed earlier in the batch was |
166 // rewritten, rewrite it in the entry response. This matches | 138 // rewritten, rewrite it in the entry response. This matches |
167 // the server behavior. | 139 // the server behavior. |
168 entry_response->set_parent_id_string(entity->parent_id_string()); | 140 entry_response->set_parent_id_string(entity->parent_id_string()); |
169 for (int i = 0; i < commit->commit().entries_size(); ++i) { | 141 for (int i = 0; i < commit->commit().entries_size(); ++i) { |
170 if (commit->commit().entries(i).id_string() == | 142 if (commit->commit().entries(i).id_string() == |
171 entity->parent_id_string()) { | 143 entity->parent_id_string()) { |
172 entry_response->set_parent_id_string( | 144 entry_response->set_parent_id_string( |
173 response->commit().entryresponse(i).id_string()); | 145 response->commit().entryresponse(i).id_string()); |
174 } | 146 } |
175 } | 147 } |
| 148 |
| 149 return metahandle; |
176 } | 150 } |
177 | 151 |
178 void SetLastErrorCode(sync_pb::CommitResponse::ResponseType error_code, | 152 void SetLastErrorCode(sync_pb::CommitResponse::ResponseType error_code, |
179 sync_pb::ClientToServerResponse* response) { | 153 sync_pb::ClientToServerResponse* response) { |
180 sync_pb::CommitResponse_EntryResponse* entry_response = | 154 sync_pb::CommitResponse_EntryResponse* entry_response = |
181 response->mutable_commit()->mutable_entryresponse( | 155 response->mutable_commit()->mutable_entryresponse( |
182 response->mutable_commit()->entryresponse_size() - 1); | 156 response->mutable_commit()->entryresponse_size() - 1); |
183 entry_response->set_response_type(error_code); | 157 entry_response->set_response_type(error_code); |
184 } | 158 } |
185 | 159 |
186 TestIdFactory id_factory_; | 160 TestIdFactory id_factory_; |
| 161 scoped_ptr<TestEntryFactory> test_entry_factory_; |
187 private: | 162 private: |
188 int64 next_old_revision_; | |
189 int64 next_new_revision_; | 163 int64 next_new_revision_; |
190 int64 next_server_position_; | 164 int64 next_server_position_; |
191 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); | 165 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); |
192 }; | 166 }; |
193 | 167 |
194 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { | 168 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { |
195 sessions::OrderedCommitSet commit_set(session()->routing_info()); | 169 sessions::OrderedCommitSet commit_set(session()->routing_info()); |
196 sync_pb::ClientToServerMessage request; | 170 sync_pb::ClientToServerMessage request; |
197 sync_pb::ClientToServerResponse response; | 171 sync_pb::ClientToServerResponse response; |
198 | 172 |
199 Id bookmark_folder_id = id_factory_.NewLocalId(); | 173 Id bookmark_folder_id = id_factory_.NewLocalId(); |
200 Id bookmark_id1 = id_factory_.NewLocalId(); | 174 int bookmark_folder_handle = CreateUnprocessedCommitResult( |
201 Id bookmark_id2 = id_factory_.NewLocalId(); | 175 bookmark_folder_id, id_factory_.root(), "A bookmark folder", true, |
202 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId(); | 176 BOOKMARKS, &commit_set, &request, &response); |
203 Id autofill_id1 = id_factory_.NewLocalId(); | 177 int bookmark1_handle = CreateUnprocessedCommitResult( |
204 Id autofill_id2 = id_factory_.NewLocalId(); | 178 id_factory_.NewLocalId(), bookmark_folder_id, "bookmark 1", false, |
205 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(), | 179 BOOKMARKS, &commit_set, &request, &response); |
206 "A bookmark folder", BOOKMARKS, | 180 int bookmark2_handle = CreateUnprocessedCommitResult( |
207 &commit_set, &request, &response); | 181 id_factory_.NewLocalId(), bookmark_folder_id, "bookmark 2", false, |
208 CreateUnprocessedCommitResult(bookmark_id1, bookmark_folder_id, | 182 BOOKMARKS, &commit_set, &request, &response); |
209 "bookmark 1", BOOKMARKS, | 183 int pref1_handle = CreateUnprocessedCommitResult( |
210 &commit_set, &request, &response); | 184 id_factory_.NewLocalId(), id_factory_.root(), "Pref 1", false, |
211 CreateUnprocessedCommitResult(bookmark_id2, bookmark_folder_id, | 185 PREFERENCES, &commit_set, &request, &response); |
212 "bookmark 2", BOOKMARKS, | 186 int pref2_handle = CreateUnprocessedCommitResult( |
213 &commit_set, &request, &response); | 187 id_factory_.NewLocalId(), id_factory_.root(), "Pref 2", false, |
214 CreateUnprocessedCommitResult(pref_id1, id_factory_.root(), | 188 PREFERENCES, &commit_set, &request, &response); |
215 "Pref 1", PREFERENCES, | 189 int autofill1_handle = CreateUnprocessedCommitResult( |
216 &commit_set, &request, &response); | 190 id_factory_.NewLocalId(), id_factory_.root(), "Autofill 1", false, |
217 CreateUnprocessedCommitResult(pref_id2, id_factory_.root(), | 191 AUTOFILL, &commit_set, &request, &response); |
218 "Pref 2", PREFERENCES, | 192 int autofill2_handle = CreateUnprocessedCommitResult( |
219 &commit_set, &request, &response); | 193 id_factory_.NewLocalId(), id_factory_.root(), "Autofill 2", false, |
220 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), | 194 AUTOFILL, &commit_set, &request, &response); |
221 "Autofill 1", AUTOFILL, | |
222 &commit_set, &request, &response); | |
223 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), | |
224 "Autofill 2", AUTOFILL, | |
225 &commit_set, &request, &response); | |
226 | 195 |
227 ProcessCommitResponseCommand command(commit_set, request, response); | 196 ProcessCommitResponseCommand command(commit_set, request, response); |
228 ExpectGroupsToChange(command, GROUP_UI, GROUP_DB); | 197 ExpectGroupsToChange(command, GROUP_UI, GROUP_DB); |
229 command.ExecuteImpl(session()); | 198 command.ExecuteImpl(session()); |
230 | 199 |
231 syncable::ReadTransaction trans(FROM_HERE, directory()); | 200 syncable::ReadTransaction trans(FROM_HERE, directory()); |
232 Id new_fid; | 201 |
233 ASSERT_TRUE(directory()->GetFirstChildId( | 202 Entry b_folder(&trans, syncable::GET_BY_HANDLE, bookmark_folder_handle); |
234 &trans, id_factory_.root(), &new_fid)); | 203 ASSERT_TRUE(b_folder.good()); |
| 204 |
| 205 Id new_fid = b_folder.Get(syncable::ID); |
235 ASSERT_FALSE(new_fid.IsRoot()); | 206 ASSERT_FALSE(new_fid.IsRoot()); |
236 EXPECT_TRUE(new_fid.ServerKnows()); | 207 EXPECT_TRUE(new_fid.ServerKnows()); |
237 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); | 208 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); |
238 EXPECT_FALSE(new_fid == bookmark_folder_id); | 209 EXPECT_FALSE(new_fid == bookmark_folder_id); |
239 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); | 210 |
240 ASSERT_TRUE(b_folder.good()); | |
241 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) | 211 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) |
242 << "Name of bookmark folder should not change."; | 212 << "Name of bookmark folder should not change."; |
243 ASSERT_LT(0, b_folder.Get(BASE_VERSION)) | 213 ASSERT_LT(0, b_folder.Get(BASE_VERSION)) |
244 << "Bookmark folder should have a valid (positive) server base revision"; | 214 << "Bookmark folder should have a valid (positive) server base revision"; |
245 | 215 |
246 // Look at the two bookmarks in bookmark_folder. | 216 // Look at the two bookmarks in bookmark_folder. |
247 Id cid; | 217 Entry b1(&trans, syncable::GET_BY_HANDLE, bookmark1_handle); |
248 ASSERT_TRUE(directory()->GetFirstChildId(&trans, new_fid, &cid)); | 218 Entry b2(&trans, syncable::GET_BY_HANDLE, bookmark2_handle); |
249 Entry b1(&trans, syncable::GET_BY_ID, cid); | |
250 Entry b2(&trans, syncable::GET_BY_ID, b1.GetSuccessorId()); | |
251 CheckEntry(&b1, "bookmark 1", BOOKMARKS, new_fid); | 219 CheckEntry(&b1, "bookmark 1", BOOKMARKS, new_fid); |
252 CheckEntry(&b2, "bookmark 2", BOOKMARKS, new_fid); | 220 CheckEntry(&b2, "bookmark 2", BOOKMARKS, new_fid); |
253 ASSERT_TRUE(b2.GetSuccessorId().IsRoot()); | 221 ASSERT_TRUE(b2.GetSuccessorId().IsRoot()); |
254 | 222 |
255 // Look at the prefs and autofill items. | 223 // Look at the prefs and autofill items. |
256 Entry p1(&trans, syncable::GET_BY_ID, b_folder.GetSuccessorId()); | 224 Entry p1(&trans, syncable::GET_BY_HANDLE, pref1_handle); |
257 Entry p2(&trans, syncable::GET_BY_ID, p1.GetSuccessorId()); | 225 Entry p2(&trans, syncable::GET_BY_HANDLE, pref2_handle); |
258 CheckEntry(&p1, "Pref 1", PREFERENCES, id_factory_.root()); | 226 CheckEntry(&p1, "Pref 1", PREFERENCES, id_factory_.root()); |
259 CheckEntry(&p2, "Pref 2", PREFERENCES, id_factory_.root()); | 227 CheckEntry(&p2, "Pref 2", PREFERENCES, id_factory_.root()); |
260 | 228 |
261 Entry a1(&trans, syncable::GET_BY_ID, p2.GetSuccessorId()); | 229 Entry a1(&trans, syncable::GET_BY_HANDLE, autofill1_handle); |
262 Entry a2(&trans, syncable::GET_BY_ID, a1.GetSuccessorId()); | 230 Entry a2(&trans, syncable::GET_BY_HANDLE, autofill2_handle); |
263 CheckEntry(&a1, "Autofill 1", AUTOFILL, id_factory_.root()); | 231 CheckEntry(&a1, "Autofill 1", AUTOFILL, id_factory_.root()); |
264 CheckEntry(&a2, "Autofill 2", AUTOFILL, id_factory_.root()); | 232 CheckEntry(&a2, "Autofill 2", AUTOFILL, id_factory_.root()); |
265 ASSERT_TRUE(a2.GetSuccessorId().IsRoot()); | 233 ASSERT_TRUE(a2.GetSuccessorId().IsRoot()); |
266 } | 234 } |
267 | 235 |
268 // In this test, we test processing a commit response for a commit batch that | 236 // In this test, we test processing a commit response for a commit batch that |
269 // includes a newly created folder and some (but not all) of its children. | 237 // includes a newly created folder and some (but not all) of its children. |
270 // In particular, the folder has 50 children, which alternate between being | 238 // In particular, the folder has 50 children, which alternate between being |
271 // new items and preexisting items. This mixture of new and old is meant to | 239 // new items and preexisting items. This mixture of new and old is meant to |
272 // be a torture test of the code in ProcessCommitResponseCommand that changes | 240 // be a torture test of the code in ProcessCommitResponseCommand that changes |
273 // an item's ID from a local ID to a server-generated ID on the first commit. | 241 // an item's ID from a local ID to a server-generated ID on the first commit. |
274 // We commit only the first 25 children in the sibling order, leaving the | 242 // We commit only the first 25 children in the sibling order, leaving the |
275 // second 25 children as unsynced items. http://crbug.com/33081 describes | 243 // second 25 children as unsynced items. http://crbug.com/33081 describes |
276 // how this scenario used to fail, reversing the order for the second half | 244 // how this scenario used to fail, reversing the order for the second half |
277 // of the children. | 245 // of the children. |
278 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { | 246 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { |
279 sessions::OrderedCommitSet commit_set(session()->routing_info()); | 247 sessions::OrderedCommitSet commit_set(session()->routing_info()); |
280 sync_pb::ClientToServerMessage request; | 248 sync_pb::ClientToServerMessage request; |
281 sync_pb::ClientToServerResponse response; | 249 sync_pb::ClientToServerResponse response; |
282 | 250 |
283 // Create the parent folder, a new item whose ID will change on commit. | 251 // Create the parent folder, a new item whose ID will change on commit. |
284 Id folder_id = id_factory_.NewLocalId(); | 252 Id folder_id = id_factory_.NewLocalId(); |
285 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", | 253 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), |
286 BOOKMARKS, | 254 "A", true, BOOKMARKS, |
287 &commit_set, &request, &response); | 255 &commit_set, &request, &response); |
288 | 256 |
289 // Verify that the item is reachable. | 257 // Verify that the item is reachable. |
290 { | 258 { |
| 259 Id child_id; |
291 syncable::ReadTransaction trans(FROM_HERE, directory()); | 260 syncable::ReadTransaction trans(FROM_HERE, directory()); |
292 Id child_id; | 261 syncable::Entry root(&trans, syncable::GET_BY_ID, id_factory_.root()); |
| 262 ASSERT_TRUE(root.good()); |
293 ASSERT_TRUE(directory()->GetFirstChildId( | 263 ASSERT_TRUE(directory()->GetFirstChildId( |
294 &trans, id_factory_.root(), &child_id)); | 264 &trans, id_factory_.root(), &child_id)); |
295 ASSERT_EQ(folder_id, child_id); | 265 ASSERT_EQ(folder_id, child_id); |
296 } | 266 } |
297 | 267 |
298 // The first 25 children of the parent folder will be part of the commit | 268 // The first 25 children of the parent folder will be part of the commit |
299 // batch. | 269 // batch. |
300 int batch_size = 25; | 270 int batch_size = 25; |
301 int i = 0; | 271 int i = 0; |
302 for (; i < batch_size; ++i) { | 272 for (; i < batch_size; ++i) { |
303 // Alternate between new and old child items, just for kicks. | 273 // Alternate between new and old child items, just for kicks. |
304 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 274 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
305 CreateUnprocessedCommitResult( | 275 CreateUnprocessedCommitResult( |
306 id, folder_id, base::StringPrintf("Item %d", i), BOOKMARKS, | 276 id, folder_id, base::StringPrintf("Item %d", i), false, |
307 &commit_set, &request, &response); | 277 BOOKMARKS, &commit_set, &request, &response); |
308 } | 278 } |
309 // The second 25 children will be unsynced items but NOT part of the commit | 279 // The second 25 children will be unsynced items but NOT part of the commit |
310 // batch. When the ID of the parent folder changes during the commit, | 280 // batch. When the ID of the parent folder changes during the commit, |
311 // these items PARENT_ID should be updated, and their ordering should be | 281 // these items PARENT_ID should be updated, and their ordering should be |
312 // preserved. | 282 // preserved. |
313 for (; i < 2*batch_size; ++i) { | 283 for (; i < 2*batch_size; ++i) { |
314 // Alternate between new and old child items, just for kicks. | 284 // Alternate between new and old child items, just for kicks. |
315 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 285 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
316 CreateUnsyncedItem(id, folder_id, base::StringPrintf("Item %d", i), | 286 test_entry_factory_->CreateUnsyncedItem( |
317 false, BOOKMARKS, NULL); | 287 id, folder_id, base::StringPrintf("Item %d", i), |
| 288 false, BOOKMARKS, NULL); |
318 } | 289 } |
319 | 290 |
320 // Process the commit response for the parent folder and the first | 291 // Process the commit response for the parent folder and the first |
321 // 25 items. This should apply the values indicated by | 292 // 25 items. This should apply the values indicated by |
322 // each CommitResponse_EntryResponse to the syncable Entries. All new | 293 // each CommitResponse_EntryResponse to the syncable Entries. All new |
323 // items in the commit batch should have their IDs changed to server IDs. | 294 // items in the commit batch should have their IDs changed to server IDs. |
324 ProcessCommitResponseCommand command(commit_set, request, response); | 295 ProcessCommitResponseCommand command(commit_set, request, response); |
325 ExpectGroupToChange(command, GROUP_UI); | 296 ExpectGroupToChange(command, GROUP_UI); |
326 command.ExecuteImpl(session()); | 297 command.ExecuteImpl(session()); |
327 | 298 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 TEST_P(MixedResult, ExtensionActivity) { | 377 TEST_P(MixedResult, ExtensionActivity) { |
407 sessions::OrderedCommitSet commit_set(session()->routing_info()); | 378 sessions::OrderedCommitSet commit_set(session()->routing_info()); |
408 sync_pb::ClientToServerMessage request; | 379 sync_pb::ClientToServerMessage request; |
409 sync_pb::ClientToServerResponse response; | 380 sync_pb::ClientToServerResponse response; |
410 | 381 |
411 EXPECT_NE(routing_info().find(BOOKMARKS)->second, | 382 EXPECT_NE(routing_info().find(BOOKMARKS)->second, |
412 routing_info().find(AUTOFILL)->second) | 383 routing_info().find(AUTOFILL)->second) |
413 << "To not be lame, this test requires more than one active group."; | 384 << "To not be lame, this test requires more than one active group."; |
414 | 385 |
415 // Bookmark item setup. | 386 // Bookmark item setup. |
416 CreateUnprocessedCommitResult(id_factory_.NewServerId(), | 387 CreateUnprocessedCommitResult( |
417 id_factory_.root(), "Some bookmark", BOOKMARKS, | 388 id_factory_.NewServerId(), |
418 &commit_set, &request, &response); | 389 id_factory_.root(), "Some bookmark", false, |
| 390 BOOKMARKS, &commit_set, &request, &response); |
419 if (ShouldFailBookmarkCommit()) | 391 if (ShouldFailBookmarkCommit()) |
420 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); | 392 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); |
421 // Autofill item setup. | 393 // Autofill item setup. |
422 CreateUnprocessedCommitResult(id_factory_.NewServerId(), | 394 CreateUnprocessedCommitResult( |
423 id_factory_.root(), "Some autofill", AUTOFILL, | 395 id_factory_.NewServerId(), |
424 &commit_set, &request, &response); | 396 id_factory_.root(), "Some autofill", false, |
| 397 AUTOFILL, &commit_set, &request, &response); |
425 if (ShouldFailAutofillCommit()) | 398 if (ShouldFailAutofillCommit()) |
426 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); | 399 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); |
427 | 400 |
428 // Put some extensions activity in the session. | 401 // Put some extensions activity in the session. |
429 { | 402 { |
430 ExtensionsActivityMonitor::Records* records = | 403 ExtensionsActivityMonitor::Records* records = |
431 session()->mutable_extensions_activity(); | 404 session()->mutable_extensions_activity(); |
432 (*records)["ABC"].extension_id = "ABC"; | 405 (*records)["ABC"].extension_id = "ABC"; |
433 (*records)["ABC"].bookmark_write_count = 2049U; | 406 (*records)["ABC"].bookmark_write_count = 2049U; |
434 (*records)["xyz"].extension_id = "xyz"; | 407 (*records)["xyz"].extension_id = "xyz"; |
(...skipping 13 matching lines...) Expand all Loading... |
448 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 421 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
449 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 422 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
450 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 423 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
451 } else { | 424 } else { |
452 EXPECT_TRUE(final_monitor_records.empty()) | 425 EXPECT_TRUE(final_monitor_records.empty()) |
453 << "Should not restore records after successful bookmark commit."; | 426 << "Should not restore records after successful bookmark commit."; |
454 } | 427 } |
455 } | 428 } |
456 | 429 |
457 } // namespace syncer | 430 } // namespace syncer |
OLD | NEW |