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