| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/tracked.h" |
| 8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" | 9 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" |
| 9 #include "chrome/browser/sync/engine/process_commit_response_command.h" | 10 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
| 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 11 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 11 #include "chrome/browser/sync/protocol/sync.pb.h" | 12 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 12 #include "chrome/browser/sync/sessions/sync_session.h" | 13 #include "chrome/browser/sync/sessions/sync_session.h" |
| 13 #include "chrome/browser/sync/syncable/directory_manager.h" | 14 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 14 #include "chrome/browser/sync/syncable/syncable.h" | 15 #include "chrome/browser/sync/syncable/syncable.h" |
| 15 #include "chrome/browser/sync/syncable/syncable_id.h" | 16 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 16 #include "chrome/test/sync/engine/syncer_command_test.h" | 17 #include "chrome/test/sync/engine/syncer_command_test.h" |
| 17 #include "chrome/test/sync/engine/test_id_factory.h" | 18 #include "chrome/test/sync/engine/test_id_factory.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // fake the server data so that it looks like it exists on the server. | 84 // fake the server data so that it looks like it exists on the server. |
| 84 // Returns the methandle of the created item in |metahandle_out| if not NULL. | 85 // Returns the methandle of the created item in |metahandle_out| if not NULL. |
| 85 void CreateUnsyncedItem(const Id& item_id, | 86 void CreateUnsyncedItem(const Id& item_id, |
| 86 const Id& parent_id, | 87 const Id& parent_id, |
| 87 const string& name, | 88 const string& name, |
| 88 bool is_folder, | 89 bool is_folder, |
| 89 syncable::ModelType model_type, | 90 syncable::ModelType model_type, |
| 90 int64* metahandle_out) { | 91 int64* metahandle_out) { |
| 91 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 92 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 92 ASSERT_TRUE(dir.good()); | 93 ASSERT_TRUE(dir.good()); |
| 93 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 94 WriteTransaction trans(dir, UNITTEST, FROM_HERE); |
| 94 Id predecessor_id = dir->GetLastChildId(&trans, parent_id); | 95 Id predecessor_id = dir->GetLastChildId(&trans, parent_id); |
| 95 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); | 96 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); |
| 96 ASSERT_TRUE(entry.good()); | 97 ASSERT_TRUE(entry.good()); |
| 97 entry.Put(syncable::ID, item_id); | 98 entry.Put(syncable::ID, item_id); |
| 98 entry.Put(syncable::BASE_VERSION, | 99 entry.Put(syncable::BASE_VERSION, |
| 99 item_id.ServerKnows() ? next_old_revision_++ : 0); | 100 item_id.ServerKnows() ? next_old_revision_++ : 0); |
| 100 entry.Put(syncable::IS_UNSYNCED, true); | 101 entry.Put(syncable::IS_UNSYNCED, true); |
| 101 entry.Put(syncable::IS_DIR, is_folder); | 102 entry.Put(syncable::IS_DIR, is_folder); |
| 102 entry.Put(syncable::IS_DEL, false); | 103 entry.Put(syncable::IS_DEL, false); |
| 103 entry.Put(syncable::PARENT_ID, parent_id); | 104 entry.Put(syncable::PARENT_ID, parent_id); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 129 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, | 130 CreateUnsyncedItem(item_id, parent_id, name, is_folder, model_type, |
| 130 &metahandle); | 131 &metahandle); |
| 131 | 132 |
| 132 // ProcessCommitResponseCommand consumes commit_ids from the session | 133 // ProcessCommitResponseCommand consumes commit_ids from the session |
| 133 // state, so we need to update that. O(n^2) because it's a test. | 134 // state, so we need to update that. O(n^2) because it's a test. |
| 134 commit_set_->AddCommitItem(metahandle, item_id, model_type); | 135 commit_set_->AddCommitItem(metahandle, item_id, model_type); |
| 135 sync_state->set_commit_set(*commit_set_.get()); | 136 sync_state->set_commit_set(*commit_set_.get()); |
| 136 | 137 |
| 137 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 138 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 138 ASSERT_TRUE(dir.good()); | 139 ASSERT_TRUE(dir.good()); |
| 139 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 140 WriteTransaction trans(dir, UNITTEST, FROM_HERE); |
| 140 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); | 141 MutableEntry entry(&trans, syncable::GET_BY_ID, item_id); |
| 141 ASSERT_TRUE(entry.good()); | 142 ASSERT_TRUE(entry.good()); |
| 142 entry.Put(syncable::SYNCING, true); | 143 entry.Put(syncable::SYNCING, true); |
| 143 | 144 |
| 144 // ProcessCommitResponseCommand looks at both the commit message as well | 145 // ProcessCommitResponseCommand looks at both the commit message as well |
| 145 // as the commit response, so we need to synthesize both here. | 146 // as the commit response, so we need to synthesize both here. |
| 146 sync_pb::ClientToServerMessage* commit = | 147 sync_pb::ClientToServerMessage* commit = |
| 147 sync_state->mutable_commit_message(); | 148 sync_state->mutable_commit_message(); |
| 148 commit->set_message_contents(ClientToServerMessage::COMMIT); | 149 commit->set_message_contents(ClientToServerMessage::COMMIT); |
| 149 SyncEntity* entity = static_cast<SyncEntity*>( | 150 SyncEntity* entity = static_cast<SyncEntity*>( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 "Pref 2", syncable::PREFERENCES); | 226 "Pref 2", syncable::PREFERENCES); |
| 226 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), | 227 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), |
| 227 "Autofill 1", syncable::AUTOFILL); | 228 "Autofill 1", syncable::AUTOFILL); |
| 228 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), | 229 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), |
| 229 "Autofill 2", syncable::AUTOFILL); | 230 "Autofill 2", syncable::AUTOFILL); |
| 230 | 231 |
| 231 command_.ExecuteImpl(session()); | 232 command_.ExecuteImpl(session()); |
| 232 | 233 |
| 233 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 234 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 234 ASSERT_TRUE(dir.good()); | 235 ASSERT_TRUE(dir.good()); |
| 235 ReadTransaction trans(dir, __FILE__, __LINE__); | 236 ReadTransaction trans(dir, FROM_HERE); |
| 236 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); | 237 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); |
| 237 ASSERT_FALSE(new_fid.IsRoot()); | 238 ASSERT_FALSE(new_fid.IsRoot()); |
| 238 EXPECT_TRUE(new_fid.ServerKnows()); | 239 EXPECT_TRUE(new_fid.ServerKnows()); |
| 239 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); | 240 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); |
| 240 EXPECT_FALSE(new_fid == bookmark_folder_id); | 241 EXPECT_FALSE(new_fid == bookmark_folder_id); |
| 241 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); | 242 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); |
| 242 ASSERT_TRUE(b_folder.good()); | 243 ASSERT_TRUE(b_folder.good()); |
| 243 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) | 244 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) |
| 244 << "Name of bookmark folder should not change."; | 245 << "Name of bookmark folder should not change."; |
| 245 ASSERT_LT(0, b_folder.Get(BASE_VERSION)) | 246 ASSERT_LT(0, b_folder.Get(BASE_VERSION)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { | 280 TEST_F(ProcessCommitResponseCommandTest, NewFolderCommitKeepsChildOrder) { |
| 280 // Create the parent folder, a new item whose ID will change on commit. | 281 // Create the parent folder, a new item whose ID will change on commit. |
| 281 Id folder_id = id_factory_.NewLocalId(); | 282 Id folder_id = id_factory_.NewLocalId(); |
| 282 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", | 283 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", |
| 283 syncable::BOOKMARKS); | 284 syncable::BOOKMARKS); |
| 284 | 285 |
| 285 // Verify that the item is reachable. | 286 // Verify that the item is reachable. |
| 286 { | 287 { |
| 287 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 288 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 288 ASSERT_TRUE(dir.good()); | 289 ASSERT_TRUE(dir.good()); |
| 289 ReadTransaction trans(dir, __FILE__, __LINE__); | 290 ReadTransaction trans(dir, FROM_HERE); |
| 290 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root())); | 291 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root())); |
| 291 } | 292 } |
| 292 | 293 |
| 293 // The first 25 children of the parent folder will be part of the commit | 294 // The first 25 children of the parent folder will be part of the commit |
| 294 // batch. | 295 // batch. |
| 295 int batch_size = 25; | 296 int batch_size = 25; |
| 296 int i = 0; | 297 int i = 0; |
| 297 for (; i < batch_size; ++i) { | 298 for (; i < batch_size; ++i) { |
| 298 // Alternate between new and old child items, just for kicks. | 299 // Alternate between new and old child items, just for kicks. |
| 299 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 300 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 312 } | 313 } |
| 313 | 314 |
| 314 // Process the commit response for the parent folder and the first | 315 // Process the commit response for the parent folder and the first |
| 315 // 25 items. This should apply the values indicated by | 316 // 25 items. This should apply the values indicated by |
| 316 // each CommitResponse_EntryResponse to the syncable Entries. All new | 317 // each CommitResponse_EntryResponse to the syncable Entries. All new |
| 317 // items in the commit batch should have their IDs changed to server IDs. | 318 // items in the commit batch should have their IDs changed to server IDs. |
| 318 command_.ExecuteImpl(session()); | 319 command_.ExecuteImpl(session()); |
| 319 | 320 |
| 320 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 321 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 321 ASSERT_TRUE(dir.good()); | 322 ASSERT_TRUE(dir.good()); |
| 322 ReadTransaction trans(dir, __FILE__, __LINE__); | 323 ReadTransaction trans(dir, FROM_HERE); |
| 323 // Lookup the parent folder by finding a child of the root. We can't use | 324 // Lookup the parent folder by finding a child of the root. We can't use |
| 324 // folder_id here, because it changed during the commit. | 325 // folder_id here, because it changed during the commit. |
| 325 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); | 326 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); |
| 326 ASSERT_FALSE(new_fid.IsRoot()); | 327 ASSERT_FALSE(new_fid.IsRoot()); |
| 327 EXPECT_TRUE(new_fid.ServerKnows()); | 328 EXPECT_TRUE(new_fid.ServerKnows()); |
| 328 EXPECT_FALSE(folder_id.ServerKnows()); | 329 EXPECT_FALSE(folder_id.ServerKnows()); |
| 329 EXPECT_TRUE(new_fid != folder_id); | 330 EXPECT_TRUE(new_fid != folder_id); |
| 330 Entry parent(&trans, syncable::GET_BY_ID, new_fid); | 331 Entry parent(&trans, syncable::GET_BY_ID, new_fid); |
| 331 ASSERT_TRUE(parent.good()); | 332 ASSERT_TRUE(parent.good()); |
| 332 ASSERT_EQ("A", parent.Get(NON_UNIQUE_NAME)) | 333 ASSERT_EQ("A", parent.Get(NON_UNIQUE_NAME)) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 431 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 431 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 432 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 432 } else { | 433 } else { |
| 433 EXPECT_TRUE(final_monitor_records.empty()) | 434 EXPECT_TRUE(final_monitor_records.empty()) |
| 434 << "Should not restore records after successful bookmark commit."; | 435 << "Should not restore records after successful bookmark commit."; |
| 435 } | 436 } |
| 436 } | 437 } |
| 437 | 438 |
| 438 | 439 |
| 439 } // namespace browser_sync | 440 } // namespace browser_sync |
| OLD | NEW |