| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "sync/engine/process_commit_response_command.h" | 9 #include "sync/engine/process_commit_response_command.h" |
| 10 #include "sync/sessions/sync_session.h" | 10 #include "sync/sessions/sync_session.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 mutable_routing_info()->clear(); | 40 mutable_routing_info()->clear(); |
| 41 | 41 |
| 42 workers()->push_back( | 42 workers()->push_back( |
| 43 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 43 make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 44 workers()->push_back( | 44 workers()->push_back( |
| 45 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 45 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 46 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI; | 46 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI; |
| 47 (*mutable_routing_info())[syncable::PREFERENCES] = GROUP_UI; | 47 (*mutable_routing_info())[syncable::PREFERENCES] = GROUP_UI; |
| 48 (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_DB; | 48 (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_DB; |
| 49 | 49 |
| 50 commit_set_.reset(new sessions::OrderedCommitSet(routing_info())); | |
| 51 SyncerCommandTest::SetUp(); | 50 SyncerCommandTest::SetUp(); |
| 52 // Need to explicitly use this-> to avoid obscure template | |
| 53 // warning. | |
| 54 this->ExpectNoGroupsToChange(command_); | |
| 55 } | 51 } |
| 56 | 52 |
| 57 protected: | 53 protected: |
| 58 | 54 |
| 59 ProcessCommitResponseCommandTest() | 55 ProcessCommitResponseCommandTest() |
| 60 : next_old_revision_(1), | 56 : next_old_revision_(1), |
| 61 next_new_revision_(4000), | 57 next_new_revision_(4000), |
| 62 next_server_position_(10000) { | 58 next_server_position_(10000) { |
| 63 } | 59 } |
| 64 | 60 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 entry.Put(syncable::SERVER_IS_DEL, false); | 102 entry.Put(syncable::SERVER_IS_DEL, false); |
| 107 } | 103 } |
| 108 if (metahandle_out) | 104 if (metahandle_out) |
| 109 *metahandle_out = entry.Get(syncable::META_HANDLE); | 105 *metahandle_out = entry.Get(syncable::META_HANDLE); |
| 110 } | 106 } |
| 111 | 107 |
| 112 // Create a new unsynced item in the database, and synthesize a commit | 108 // Create a new unsynced item in the database, and synthesize a commit |
| 113 // record and a commit response for it in the syncer session. If item_id | 109 // record and a commit response for it in the syncer session. If item_id |
| 114 // is a local ID, the item will be a create operation. Otherwise, it | 110 // is a local ID, the item will be a create operation. Otherwise, it |
| 115 // will be an edit. | 111 // will be an edit. |
| 116 void CreateUnprocessedCommitResult(const Id& item_id, | 112 void CreateUnprocessedCommitResult( |
| 117 const Id& parent_id, | 113 const Id& item_id, |
| 118 const string& name, | 114 const Id& parent_id, |
| 119 syncable::ModelType model_type) { | 115 const string& name, |
| 120 sessions::StatusController* sync_state = | 116 syncable::ModelType model_type, |
| 121 session()->mutable_status_controller(); | 117 sessions::OrderedCommitSet *commit_set, |
| 118 browser_sync::ClientToServerMessage *commit, |
| 119 browser_sync::ClientToServerResponse *response) { |
| 122 bool is_folder = true; | 120 bool is_folder = true; |
| 123 int64 metahandle = 0; | 121 int64 metahandle = 0; |
| 124 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, | 122 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, |
| 125 &metahandle); | 123 &metahandle); |
| 126 | 124 |
| 127 // ProcessCommitResponseCommand consumes commit_ids from the session | 125 // ProcessCommitResponseCommand consumes commit_ids from the session |
| 128 // state, so we need to update that. O(n^2) because it's a test. | 126 // state, so we need to update that. O(n^2) because it's a test. |
| 129 commit_set_->AddCommitItem(metahandle, item_id, model_type); | 127 commit_set->AddCommitItem(metahandle, item_id, model_type); |
| 130 sync_state->set_commit_set(*commit_set_.get()); | |
| 131 | 128 |
| 132 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 129 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
| 133 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); | 130 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); |
| 134 ASSERT_TRUE(entry.good()); | 131 ASSERT_TRUE(entry.good()); |
| 135 entry.Put(syncable::SYNCING, true); | 132 entry.Put(syncable::SYNCING, true); |
| 136 | 133 |
| 137 // ProcessCommitResponseCommand looks at both the commit message as well | 134 // Add to the commit message. |
| 138 // as the commit response, so we need to synthesize both here. | |
| 139 sync_pb::ClientToServerMessage* commit = | |
| 140 sync_state->mutable_commit_message(); | |
| 141 commit->set_message_contents(ClientToServerMessage::COMMIT); | 135 commit->set_message_contents(ClientToServerMessage::COMMIT); |
| 142 SyncEntity* entity = static_cast<SyncEntity*>( | 136 SyncEntity* entity = static_cast<SyncEntity*>( |
| 143 commit->mutable_commit()->add_entries()); | 137 commit->mutable_commit()->add_entries()); |
| 144 entity->set_non_unique_name(name); | 138 entity->set_non_unique_name(name); |
| 145 entity->set_folder(is_folder); | 139 entity->set_folder(is_folder); |
| 146 entity->set_parent_id(parent_id); | 140 entity->set_parent_id(parent_id); |
| 147 entity->set_version(entry.Get(syncable::BASE_VERSION)); | 141 entity->set_version(entry.Get(syncable::BASE_VERSION)); |
| 148 entity->mutable_specifics()->CopyFrom(entry.Get(syncable::SPECIFICS)); | 142 entity->mutable_specifics()->CopyFrom(entry.Get(syncable::SPECIFICS)); |
| 149 entity->set_id(item_id); | 143 entity->set_id(item_id); |
| 150 | 144 |
| 151 sync_pb::ClientToServerResponse* response = | 145 // Add to the response message. |
| 152 sync_state->mutable_commit_response(); | |
| 153 response->set_error_code(sync_pb::SyncEnums::SUCCESS); | 146 response->set_error_code(sync_pb::SyncEnums::SUCCESS); |
| 154 sync_pb::CommitResponse_EntryResponse* entry_response = | 147 sync_pb::CommitResponse_EntryResponse* entry_response = |
| 155 response->mutable_commit()->add_entryresponse(); | 148 response->mutable_commit()->add_entryresponse(); |
| 156 entry_response->set_response_type(CommitResponse::SUCCESS); | 149 entry_response->set_response_type(CommitResponse::SUCCESS); |
| 157 entry_response->set_name("Garbage."); | 150 entry_response->set_name("Garbage."); |
| 158 entry_response->set_non_unique_name(entity->name()); | 151 entry_response->set_non_unique_name(entity->name()); |
| 159 if (item_id.ServerKnows()) | 152 if (item_id.ServerKnows()) |
| 160 entry_response->set_id_string(entity->id_string()); | 153 entry_response->set_id_string(entity->id_string()); |
| 161 else | 154 else |
| 162 entry_response->set_id_string(id_factory_.NewServerId().GetServerId()); | 155 entry_response->set_id_string(id_factory_.NewServerId().GetServerId()); |
| 163 entry_response->set_version(next_new_revision_++); | 156 entry_response->set_version(next_new_revision_++); |
| 164 entry_response->set_position_in_parent(next_server_position_++); | 157 entry_response->set_position_in_parent(next_server_position_++); |
| 165 | 158 |
| 166 // If the ID of our parent item committed earlier in the batch was | 159 // If the ID of our parent item committed earlier in the batch was |
| 167 // rewritten, rewrite it in the entry response. This matches | 160 // rewritten, rewrite it in the entry response. This matches |
| 168 // the server behavior. | 161 // the server behavior. |
| 169 entry_response->set_parent_id_string(entity->parent_id_string()); | 162 entry_response->set_parent_id_string(entity->parent_id_string()); |
| 170 for (int i = 0; i < commit->commit().entries_size(); ++i) { | 163 for (int i = 0; i < commit->commit().entries_size(); ++i) { |
| 171 if (commit->commit().entries(i).id_string() == | 164 if (commit->commit().entries(i).id_string() == |
| 172 entity->parent_id_string()) { | 165 entity->parent_id_string()) { |
| 173 entry_response->set_parent_id_string( | 166 entry_response->set_parent_id_string( |
| 174 response->commit().entryresponse(i).id_string()); | 167 response->commit().entryresponse(i).id_string()); |
| 175 } | 168 } |
| 176 } | 169 } |
| 177 } | 170 } |
| 178 | 171 |
| 179 void SetLastErrorCode(CommitResponse::ResponseType error_code) { | 172 void SetLastErrorCode(CommitResponse::ResponseType error_code, |
| 180 sessions::StatusController* sync_state = | 173 sync_pb::ClientToServerResponse* response) { |
| 181 session()->mutable_status_controller(); | |
| 182 sync_pb::ClientToServerResponse* response = | |
| 183 sync_state->mutable_commit_response(); | |
| 184 sync_pb::CommitResponse_EntryResponse* entry_response = | 174 sync_pb::CommitResponse_EntryResponse* entry_response = |
| 185 response->mutable_commit()->mutable_entryresponse( | 175 response->mutable_commit()->mutable_entryresponse( |
| 186 response->mutable_commit()->entryresponse_size() - 1); | 176 response->mutable_commit()->entryresponse_size() - 1); |
| 187 entry_response->set_response_type(error_code); | 177 entry_response->set_response_type(error_code); |
| 188 } | 178 } |
| 189 | 179 |
| 190 ProcessCommitResponseCommand command_; | |
| 191 TestIdFactory id_factory_; | 180 TestIdFactory id_factory_; |
| 192 scoped_ptr<sessions::OrderedCommitSet> commit_set_; | |
| 193 private: | 181 private: |
| 194 int64 next_old_revision_; | 182 int64 next_old_revision_; |
| 195 int64 next_new_revision_; | 183 int64 next_new_revision_; |
| 196 int64 next_server_position_; | 184 int64 next_server_position_; |
| 197 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); | 185 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); |
| 198 }; | 186 }; |
| 199 | 187 |
| 200 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { | 188 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { |
| 189 sessions::OrderedCommitSet commit_set(session()->routing_info()); |
| 190 browser_sync::ClientToServerMessage request; |
| 191 browser_sync::ClientToServerResponse response; |
| 192 |
| 201 Id bookmark_folder_id = id_factory_.NewLocalId(); | 193 Id bookmark_folder_id = id_factory_.NewLocalId(); |
| 202 Id bookmark_id1 = id_factory_.NewLocalId(); | 194 Id bookmark_id1 = id_factory_.NewLocalId(); |
| 203 Id bookmark_id2 = id_factory_.NewLocalId(); | 195 Id bookmark_id2 = id_factory_.NewLocalId(); |
| 204 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId(); | 196 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId(); |
| 205 Id autofill_id1 = id_factory_.NewLocalId(); | 197 Id autofill_id1 = id_factory_.NewLocalId(); |
| 206 Id autofill_id2 = id_factory_.NewLocalId(); | 198 Id autofill_id2 = id_factory_.NewLocalId(); |
| 207 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(), | 199 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(), |
| 208 "A bookmark folder", syncable::BOOKMARKS); | 200 "A bookmark folder", syncable::BOOKMARKS, |
| 201 &commit_set, &request, &response); |
| 209 CreateUnprocessedCommitResult(bookmark_id1, bookmark_folder_id, | 202 CreateUnprocessedCommitResult(bookmark_id1, bookmark_folder_id, |
| 210 "bookmark 1", syncable::BOOKMARKS); | 203 "bookmark 1", syncable::BOOKMARKS, |
| 204 &commit_set, &request, &response); |
| 211 CreateUnprocessedCommitResult(bookmark_id2, bookmark_folder_id, | 205 CreateUnprocessedCommitResult(bookmark_id2, bookmark_folder_id, |
| 212 "bookmark 2", syncable::BOOKMARKS); | 206 "bookmark 2", syncable::BOOKMARKS, |
| 207 &commit_set, &request, &response); |
| 213 CreateUnprocessedCommitResult(pref_id1, id_factory_.root(), | 208 CreateUnprocessedCommitResult(pref_id1, id_factory_.root(), |
| 214 "Pref 1", syncable::PREFERENCES); | 209 "Pref 1", syncable::PREFERENCES, |
| 210 &commit_set, &request, &response); |
| 215 CreateUnprocessedCommitResult(pref_id2, id_factory_.root(), | 211 CreateUnprocessedCommitResult(pref_id2, id_factory_.root(), |
| 216 "Pref 2", syncable::PREFERENCES); | 212 "Pref 2", syncable::PREFERENCES, |
| 213 &commit_set, &request, &response); |
| 217 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), | 214 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), |
| 218 "Autofill 1", syncable::AUTOFILL); | 215 "Autofill 1", syncable::AUTOFILL, |
| 216 &commit_set, &request, &response); |
| 219 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), | 217 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), |
| 220 "Autofill 2", syncable::AUTOFILL); | 218 "Autofill 2", syncable::AUTOFILL, |
| 219 &commit_set, &request, &response); |
| 221 | 220 |
| 222 ExpectGroupsToChange(command_, GROUP_UI, GROUP_DB); | 221 ProcessCommitResponseCommand command(commit_set, request, response); |
| 223 command_.ExecuteImpl(session()); | 222 ExpectGroupsToChange(command, GROUP_UI, GROUP_DB); |
| 223 command.ExecuteImpl(session()); |
| 224 | 224 |
| 225 ReadTransaction trans(FROM_HERE, directory()); | 225 ReadTransaction trans(FROM_HERE, directory()); |
| 226 Id new_fid; | 226 Id new_fid; |
| 227 ASSERT_TRUE(directory()->GetFirstChildId( | 227 ASSERT_TRUE(directory()->GetFirstChildId( |
| 228 &trans, id_factory_.root(), &new_fid)); | 228 &trans, id_factory_.root(), &new_fid)); |
| 229 ASSERT_FALSE(new_fid.IsRoot()); | 229 ASSERT_FALSE(new_fid.IsRoot()); |
| 230 EXPECT_TRUE(new_fid.ServerKnows()); | 230 EXPECT_TRUE(new_fid.ServerKnows()); |
| 231 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); | 231 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); |
| 232 EXPECT_FALSE(new_fid == bookmark_folder_id); | 232 EXPECT_FALSE(new_fid == bookmark_folder_id); |
| 233 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); | 233 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 263 // includes a newly created folder and some (but not all) of its children. | 263 // includes a newly created folder and some (but not all) of its children. |
| 264 // In particular, the folder has 50 children, which alternate between being | 264 // In particular, the folder has 50 children, which alternate between being |
| 265 // new items and preexisting items. This mixture of new and old is meant to | 265 // new items and preexisting items. This mixture of new and old is meant to |
| 266 // be a torture test of the code in ProcessCommitResponseCommand that changes | 266 // be a torture test of the code in ProcessCommitResponseCommand that changes |
| 267 // an item's ID from a local ID to a server-generated ID on the first commit. | 267 // an item's ID from a local ID to a server-generated ID on the first commit. |
| 268 // We commit only the first 25 children in the sibling order, leaving the | 268 // We commit only the first 25 children in the sibling order, leaving the |
| 269 // second 25 children as unsynced items. http://crbug.com/33081 describes | 269 // second 25 children as unsynced items. http://crbug.com/33081 describes |
| 270 // how this scenario used to fail, reversing the order for the second half | 270 // how this scenario used to fail, reversing the order for the second half |
| 271 // of the children. | 271 // of the children. |
| 272 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { | 272 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { |
| 273 sessions::OrderedCommitSet commit_set(session()->routing_info()); |
| 274 browser_sync::ClientToServerMessage request; |
| 275 browser_sync::ClientToServerResponse response; |
| 276 |
| 273 // Create the parent folder, a new item whose ID will change on commit. | 277 // Create the parent folder, a new item whose ID will change on commit. |
| 274 Id folder_id = id_factory_.NewLocalId(); | 278 Id folder_id = id_factory_.NewLocalId(); |
| 275 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", | 279 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", |
| 276 syncable::BOOKMARKS); | 280 syncable::BOOKMARKS, |
| 281 &commit_set, &request, &response); |
| 277 | 282 |
| 278 // Verify that the item is reachable. | 283 // Verify that the item is reachable. |
| 279 { | 284 { |
| 280 ReadTransaction trans(FROM_HERE, directory()); | 285 ReadTransaction trans(FROM_HERE, directory()); |
| 281 Id child_id; | 286 Id child_id; |
| 282 ASSERT_TRUE(directory()->GetFirstChildId( | 287 ASSERT_TRUE(directory()->GetFirstChildId( |
| 283 &trans, id_factory_.root(), &child_id)); | 288 &trans, id_factory_.root(), &child_id)); |
| 284 ASSERT_EQ(folder_id, child_id); | 289 ASSERT_EQ(folder_id, child_id); |
| 285 } | 290 } |
| 286 | 291 |
| 287 // The first 25 children of the parent folder will be part of the commit | 292 // The first 25 children of the parent folder will be part of the commit |
| 288 // batch. | 293 // batch. |
| 289 int batch_size = 25; | 294 int batch_size = 25; |
| 290 int i = 0; | 295 int i = 0; |
| 291 for (; i < batch_size; ++i) { | 296 for (; i < batch_size; ++i) { |
| 292 // Alternate between new and old child items, just for kicks. | 297 // Alternate between new and old child items, just for kicks. |
| 293 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 298 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
| 294 CreateUnprocessedCommitResult( | 299 CreateUnprocessedCommitResult( |
| 295 id, folder_id, base::StringPrintf("Item %d", i), syncable::BOOKMARKS); | 300 id, folder_id, base::StringPrintf("Item %d", i), syncable::BOOKMARKS, |
| 301 &commit_set, &request, &response); |
| 296 } | 302 } |
| 297 // The second 25 children will be unsynced items but NOT part of the commit | 303 // The second 25 children will be unsynced items but NOT part of the commit |
| 298 // batch. When the ID of the parent folder changes during the commit, | 304 // batch. When the ID of the parent folder changes during the commit, |
| 299 // these items PARENT_ID should be updated, and their ordering should be | 305 // these items PARENT_ID should be updated, and their ordering should be |
| 300 // preserved. | 306 // preserved. |
| 301 for (; i < 2*batch_size; ++i) { | 307 for (; i < 2*batch_size; ++i) { |
| 302 // Alternate between new and old child items, just for kicks. | 308 // Alternate between new and old child items, just for kicks. |
| 303 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 309 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
| 304 CreateUnsyncedItem(id, folder_id, base::StringPrintf("Item %d", i), | 310 CreateUnsyncedItem(id, folder_id, base::StringPrintf("Item %d", i), |
| 305 false, syncable::BOOKMARKS, NULL); | 311 false, syncable::BOOKMARKS, NULL); |
| 306 } | 312 } |
| 307 | 313 |
| 308 // Process the commit response for the parent folder and the first | 314 // Process the commit response for the parent folder and the first |
| 309 // 25 items. This should apply the values indicated by | 315 // 25 items. This should apply the values indicated by |
| 310 // each CommitResponse_EntryResponse to the syncable Entries. All new | 316 // each CommitResponse_EntryResponse to the syncable Entries. All new |
| 311 // items in the commit batch should have their IDs changed to server IDs. | 317 // items in the commit batch should have their IDs changed to server IDs. |
| 312 ExpectGroupToChange(command_, GROUP_UI); | 318 ProcessCommitResponseCommand command(commit_set, request, response); |
| 313 command_.ExecuteImpl(session()); | 319 ExpectGroupToChange(command, GROUP_UI); |
| 320 command.ExecuteImpl(session()); |
| 314 | 321 |
| 315 ReadTransaction trans(FROM_HERE, directory()); | 322 ReadTransaction trans(FROM_HERE, directory()); |
| 316 // Lookup the parent folder by finding a child of the root. We can't use | 323 // Lookup the parent folder by finding a child of the root. We can't use |
| 317 // folder_id here, because it changed during the commit. | 324 // folder_id here, because it changed during the commit. |
| 318 Id new_fid; | 325 Id new_fid; |
| 319 ASSERT_TRUE(directory()->GetFirstChildId( | 326 ASSERT_TRUE(directory()->GetFirstChildId( |
| 320 &trans, id_factory_.root(), &new_fid)); | 327 &trans, id_factory_.root(), &new_fid)); |
| 321 ASSERT_FALSE(new_fid.IsRoot()); | 328 ASSERT_FALSE(new_fid.IsRoot()); |
| 322 EXPECT_TRUE(new_fid.ServerKnows()); | 329 EXPECT_TRUE(new_fid.ServerKnows()); |
| 323 EXPECT_FALSE(folder_id.ServerKnows()); | 330 EXPECT_FALSE(folder_id.ServerKnows()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 } | 391 } |
| 385 }; | 392 }; |
| 386 INSTANTIATE_TEST_CASE_P(ProcessCommitResponse, | 393 INSTANTIATE_TEST_CASE_P(ProcessCommitResponse, |
| 387 MixedResult, | 394 MixedResult, |
| 388 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); | 395 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT)); |
| 389 | 396 |
| 390 // This test commits 2 items (one bookmark, one autofill) and validates what | 397 // This test commits 2 items (one bookmark, one autofill) and validates what |
| 391 // happens to the extensions activity records. Commits could fail or succeed, | 398 // happens to the extensions activity records. Commits could fail or succeed, |
| 392 // depending on the test parameter. | 399 // depending on the test parameter. |
| 393 TEST_P(MixedResult, ExtensionActivity) { | 400 TEST_P(MixedResult, ExtensionActivity) { |
| 401 sessions::OrderedCommitSet commit_set(session()->routing_info()); |
| 402 browser_sync::ClientToServerMessage request; |
| 403 browser_sync::ClientToServerResponse response; |
| 404 |
| 394 EXPECT_NE(routing_info().find(syncable::BOOKMARKS)->second, | 405 EXPECT_NE(routing_info().find(syncable::BOOKMARKS)->second, |
| 395 routing_info().find(syncable::AUTOFILL)->second) | 406 routing_info().find(syncable::AUTOFILL)->second) |
| 396 << "To not be lame, this test requires more than one active group."; | 407 << "To not be lame, this test requires more than one active group."; |
| 397 | 408 |
| 398 // Bookmark item setup. | 409 // Bookmark item setup. |
| 399 CreateUnprocessedCommitResult(id_factory_.NewServerId(), | 410 CreateUnprocessedCommitResult(id_factory_.NewServerId(), |
| 400 id_factory_.root(), "Some bookmark", syncable::BOOKMARKS); | 411 id_factory_.root(), "Some bookmark", syncable::BOOKMARKS, |
| 412 &commit_set, &request, &response); |
| 401 if (ShouldFailBookmarkCommit()) | 413 if (ShouldFailBookmarkCommit()) |
| 402 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR); | 414 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); |
| 403 // Autofill item setup. | 415 // Autofill item setup. |
| 404 CreateUnprocessedCommitResult(id_factory_.NewServerId(), | 416 CreateUnprocessedCommitResult(id_factory_.NewServerId(), |
| 405 id_factory_.root(), "Some autofill", syncable::AUTOFILL); | 417 id_factory_.root(), "Some autofill", syncable::AUTOFILL, |
| 418 &commit_set, &request, &response); |
| 406 if (ShouldFailAutofillCommit()) | 419 if (ShouldFailAutofillCommit()) |
| 407 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR); | 420 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR, &response); |
| 408 | 421 |
| 409 // Put some extensions activity in the session. | 422 // Put some extensions activity in the session. |
| 410 { | 423 { |
| 411 ExtensionsActivityMonitor::Records* records = | 424 ExtensionsActivityMonitor::Records* records = |
| 412 session()->mutable_extensions_activity(); | 425 session()->mutable_extensions_activity(); |
| 413 (*records)["ABC"].extension_id = "ABC"; | 426 (*records)["ABC"].extension_id = "ABC"; |
| 414 (*records)["ABC"].bookmark_write_count = 2049U; | 427 (*records)["ABC"].bookmark_write_count = 2049U; |
| 415 (*records)["xyz"].extension_id = "xyz"; | 428 (*records)["xyz"].extension_id = "xyz"; |
| 416 (*records)["xyz"].bookmark_write_count = 4U; | 429 (*records)["xyz"].bookmark_write_count = 4U; |
| 417 } | 430 } |
| 418 ExpectGroupsToChange(command_, GROUP_UI, GROUP_DB); | 431 ProcessCommitResponseCommand command(commit_set, request, response); |
| 419 command_.ExecuteImpl(session()); | 432 command.ExecuteImpl(session()); |
| 433 ExpectGroupsToChange(command, GROUP_UI, GROUP_DB); |
| 420 | 434 |
| 421 ExtensionsActivityMonitor::Records final_monitor_records; | 435 ExtensionsActivityMonitor::Records final_monitor_records; |
| 422 context()->extensions_monitor()->GetAndClearRecords(&final_monitor_records); | 436 context()->extensions_monitor()->GetAndClearRecords(&final_monitor_records); |
| 423 | 437 |
| 424 if (ShouldFailBookmarkCommit()) { | 438 if (ShouldFailBookmarkCommit()) { |
| 425 ASSERT_EQ(2U, final_monitor_records.size()) | 439 ASSERT_EQ(2U, final_monitor_records.size()) |
| 426 << "Should restore records after unsuccessful bookmark commit."; | 440 << "Should restore records after unsuccessful bookmark commit."; |
| 427 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); | 441 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); |
| 428 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 442 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
| 429 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 443 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 430 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 444 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 431 } else { | 445 } else { |
| 432 EXPECT_TRUE(final_monitor_records.empty()) | 446 EXPECT_TRUE(final_monitor_records.empty()) |
| 433 << "Should not restore records after successful bookmark commit."; | 447 << "Should not restore records after successful bookmark commit."; |
| 434 } | 448 } |
| 435 } | 449 } |
| 436 | 450 |
| 437 } // namespace browser_sync | 451 } // namespace browser_sync |
| OLD | NEW |