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