| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/string_util.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" | 8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" |
| 9 #include "chrome/browser/sync/engine/process_commit_response_command.h" | 9 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
| 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 11 #include "chrome/browser/sync/protocol/sync.pb.h" | 11 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 12 #include "chrome/browser/sync/sessions/sync_session.h" | 12 #include "chrome/browser/sync/sessions/sync_session.h" |
| 13 #include "chrome/browser/sync/syncable/directory_manager.h" | 13 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 14 #include "chrome/browser/sync/syncable/syncable.h" | 14 #include "chrome/browser/sync/syncable/syncable.h" |
| 15 #include "chrome/browser/sync/syncable/syncable_id.h" | 15 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 16 #include "chrome/test/sync/engine/syncer_command_test.h" | 16 #include "chrome/test/sync/engine/syncer_command_test.h" |
| 17 #include "chrome/test/sync/engine/test_id_factory.h" | 17 #include "chrome/test/sync/engine/test_id_factory.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root())); | 290 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root())); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // The first 25 children of the parent folder will be part of the commit | 293 // The first 25 children of the parent folder will be part of the commit |
| 294 // batch. | 294 // batch. |
| 295 int batch_size = 25; | 295 int batch_size = 25; |
| 296 int i = 0; | 296 int i = 0; |
| 297 for (; i < batch_size; ++i) { | 297 for (; i < batch_size; ++i) { |
| 298 // Alternate between new and old child items, just for kicks. | 298 // Alternate between new and old child items, just for kicks. |
| 299 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 299 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
| 300 CreateUnprocessedCommitResult(id, folder_id, StringPrintf("Item %d", i), | 300 CreateUnprocessedCommitResult( |
| 301 syncable::BOOKMARKS); | 301 id, folder_id, base::StringPrintf("Item %d", i), syncable::BOOKMARKS); |
| 302 } | 302 } |
| 303 // 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 |
| 304 // 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, |
| 305 // 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 |
| 306 // preserved. | 306 // preserved. |
| 307 for (; i < 2*batch_size; ++i) { | 307 for (; i < 2*batch_size; ++i) { |
| 308 // Alternate between new and old child items, just for kicks. | 308 // Alternate between new and old child items, just for kicks. |
| 309 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 309 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
| 310 CreateUnsyncedItem(id, folder_id, StringPrintf("Item %d", i), false, | 310 CreateUnsyncedItem(id, folder_id, base::StringPrintf("Item %d", i), |
| 311 syncable::BOOKMARKS, NULL); | 311 false, syncable::BOOKMARKS, NULL); |
| 312 } | 312 } |
| 313 | 313 |
| 314 // Process the commit response for the parent folder and the first | 314 // Process the commit response for the parent folder and the first |
| 315 // 25 items. This should apply the values indicated by | 315 // 25 items. This should apply the values indicated by |
| 316 // each CommitResponse_EntryResponse to the syncable Entries. All new | 316 // each CommitResponse_EntryResponse to the syncable Entries. All new |
| 317 // 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. |
| 318 command_.ExecuteImpl(session()); | 318 command_.ExecuteImpl(session()); |
| 319 | 319 |
| 320 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 320 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 321 ASSERT_TRUE(dir.good()); | 321 ASSERT_TRUE(dir.good()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 336 | 336 |
| 337 Id cid = dir->GetFirstChildId(&trans, new_fid); | 337 Id cid = dir->GetFirstChildId(&trans, new_fid); |
| 338 int child_count = 0; | 338 int child_count = 0; |
| 339 // Now loop over all the children of the parent folder, verifying | 339 // Now loop over all the children of the parent folder, verifying |
| 340 // that they are in their original order by checking to see that their | 340 // that they are in their original order by checking to see that their |
| 341 // names are still sequential. | 341 // names are still sequential. |
| 342 while (!cid.IsRoot()) { | 342 while (!cid.IsRoot()) { |
| 343 SCOPED_TRACE(::testing::Message("Examining item #") << child_count); | 343 SCOPED_TRACE(::testing::Message("Examining item #") << child_count); |
| 344 Entry c(&trans, syncable::GET_BY_ID, cid); | 344 Entry c(&trans, syncable::GET_BY_ID, cid); |
| 345 DCHECK(c.good()); | 345 DCHECK(c.good()); |
| 346 ASSERT_EQ(StringPrintf("Item %d", child_count), c.Get(NON_UNIQUE_NAME)); | 346 ASSERT_EQ(base::StringPrintf("Item %d", child_count), |
| 347 c.Get(NON_UNIQUE_NAME)); |
| 347 ASSERT_EQ(new_fid, c.Get(syncable::PARENT_ID)); | 348 ASSERT_EQ(new_fid, c.Get(syncable::PARENT_ID)); |
| 348 if (child_count < batch_size) { | 349 if (child_count < batch_size) { |
| 349 ASSERT_FALSE(c.Get(IS_UNSYNCED)) << "Item should be committed"; | 350 ASSERT_FALSE(c.Get(IS_UNSYNCED)) << "Item should be committed"; |
| 350 ASSERT_TRUE(cid.ServerKnows()); | 351 ASSERT_TRUE(cid.ServerKnows()); |
| 351 ASSERT_LT(0, c.Get(BASE_VERSION)); | 352 ASSERT_LT(0, c.Get(BASE_VERSION)); |
| 352 } else { | 353 } else { |
| 353 ASSERT_TRUE(c.Get(IS_UNSYNCED)) << "Item should be uncommitted"; | 354 ASSERT_TRUE(c.Get(IS_UNSYNCED)) << "Item should be uncommitted"; |
| 354 // We alternated between creates and edits; double check that these items | 355 // We alternated between creates and edits; double check that these items |
| 355 // have been preserved. | 356 // have been preserved. |
| 356 if (child_count % 4 < 2) { | 357 if (child_count % 4 < 2) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 430 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 430 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 431 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 431 } else { | 432 } else { |
| 432 EXPECT_TRUE(final_monitor_records.empty()) | 433 EXPECT_TRUE(final_monitor_records.empty()) |
| 433 << "Should not restore records after successful bookmark commit."; | 434 << "Should not restore records after successful bookmark commit."; |
| 434 } | 435 } |
| 435 } | 436 } |
| 436 | 437 |
| 437 | 438 |
| 438 } // namespace browser_sync | 439 } // namespace browser_sync |
| OLD | NEW |