| OLD | NEW |
| 1 // Copyright (c) 2011 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/location.h" | 7 #include "base/location.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" | 9 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" |
| 10 #include "chrome/browser/sync/engine/process_commit_response_command.h" | 10 #include "chrome/browser/sync/engine/process_commit_response_command.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // 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. |
| 86 void CreateUnsyncedItem(const Id& item_id, | 86 void CreateUnsyncedItem(const Id& item_id, |
| 87 const Id& parent_id, | 87 const Id& parent_id, |
| 88 const string& name, | 88 const string& name, |
| 89 bool is_folder, | 89 bool is_folder, |
| 90 syncable::ModelType model_type, | 90 syncable::ModelType model_type, |
| 91 int64* metahandle_out) { | 91 int64* metahandle_out) { |
| 92 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 92 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 93 ASSERT_TRUE(dir.good()); | 93 ASSERT_TRUE(dir.good()); |
| 94 WriteTransaction trans(FROM_HERE, UNITTEST, dir); | 94 WriteTransaction trans(FROM_HERE, UNITTEST, dir); |
| 95 Id predecessor_id = dir->GetLastChildId(&trans, parent_id); | 95 Id predecessor_id; |
| 96 ASSERT_TRUE( |
| 97 dir->GetLastChildIdForTest(&trans, parent_id, &predecessor_id)); |
| 96 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); | 98 MutableEntry entry(&trans, syncable::CREATE, parent_id, name); |
| 97 ASSERT_TRUE(entry.good()); | 99 ASSERT_TRUE(entry.good()); |
| 98 entry.Put(syncable::ID, item_id); | 100 entry.Put(syncable::ID, item_id); |
| 99 entry.Put(syncable::BASE_VERSION, | 101 entry.Put(syncable::BASE_VERSION, |
| 100 item_id.ServerKnows() ? next_old_revision_++ : 0); | 102 item_id.ServerKnows() ? next_old_revision_++ : 0); |
| 101 entry.Put(syncable::IS_UNSYNCED, true); | 103 entry.Put(syncable::IS_UNSYNCED, true); |
| 102 entry.Put(syncable::IS_DIR, is_folder); | 104 entry.Put(syncable::IS_DIR, is_folder); |
| 103 entry.Put(syncable::IS_DEL, false); | 105 entry.Put(syncable::IS_DEL, false); |
| 104 entry.Put(syncable::PARENT_ID, parent_id); | 106 entry.Put(syncable::PARENT_ID, parent_id); |
| 105 entry.PutPredecessor(predecessor_id); | 107 entry.PutPredecessor(predecessor_id); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), | 229 CreateUnprocessedCommitResult(autofill_id1, id_factory_.root(), |
| 228 "Autofill 1", syncable::AUTOFILL); | 230 "Autofill 1", syncable::AUTOFILL); |
| 229 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), | 231 CreateUnprocessedCommitResult(autofill_id2, id_factory_.root(), |
| 230 "Autofill 2", syncable::AUTOFILL); | 232 "Autofill 2", syncable::AUTOFILL); |
| 231 | 233 |
| 232 command_.ExecuteImpl(session()); | 234 command_.ExecuteImpl(session()); |
| 233 | 235 |
| 234 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 236 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 235 ASSERT_TRUE(dir.good()); | 237 ASSERT_TRUE(dir.good()); |
| 236 ReadTransaction trans(FROM_HERE, dir); | 238 ReadTransaction trans(FROM_HERE, dir); |
| 237 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); | 239 Id new_fid; |
| 240 ASSERT_TRUE(dir->GetFirstChildId(&trans, id_factory_.root(), &new_fid)); |
| 238 ASSERT_FALSE(new_fid.IsRoot()); | 241 ASSERT_FALSE(new_fid.IsRoot()); |
| 239 EXPECT_TRUE(new_fid.ServerKnows()); | 242 EXPECT_TRUE(new_fid.ServerKnows()); |
| 240 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); | 243 EXPECT_FALSE(bookmark_folder_id.ServerKnows()); |
| 241 EXPECT_FALSE(new_fid == bookmark_folder_id); | 244 EXPECT_FALSE(new_fid == bookmark_folder_id); |
| 242 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); | 245 Entry b_folder(&trans, syncable::GET_BY_ID, new_fid); |
| 243 ASSERT_TRUE(b_folder.good()); | 246 ASSERT_TRUE(b_folder.good()); |
| 244 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) | 247 ASSERT_EQ("A bookmark folder", b_folder.Get(NON_UNIQUE_NAME)) |
| 245 << "Name of bookmark folder should not change."; | 248 << "Name of bookmark folder should not change."; |
| 246 ASSERT_LT(0, b_folder.Get(BASE_VERSION)) | 249 ASSERT_LT(0, b_folder.Get(BASE_VERSION)) |
| 247 << "Bookmark folder should have a valid (positive) server base revision"; | 250 << "Bookmark folder should have a valid (positive) server base revision"; |
| 248 | 251 |
| 249 // Look at the two bookmarks in bookmark_folder. | 252 // Look at the two bookmarks in bookmark_folder. |
| 250 Id cid = dir->GetFirstChildId(&trans, new_fid); | 253 Id cid; |
| 254 ASSERT_TRUE(dir->GetFirstChildId(&trans, new_fid, &cid)); |
| 251 Entry b1(&trans, syncable::GET_BY_ID, cid); | 255 Entry b1(&trans, syncable::GET_BY_ID, cid); |
| 252 Entry b2(&trans, syncable::GET_BY_ID, b1.Get(syncable::NEXT_ID)); | 256 Entry b2(&trans, syncable::GET_BY_ID, b1.Get(syncable::NEXT_ID)); |
| 253 CheckEntry(&b1, "bookmark 1", syncable::BOOKMARKS, new_fid); | 257 CheckEntry(&b1, "bookmark 1", syncable::BOOKMARKS, new_fid); |
| 254 CheckEntry(&b2, "bookmark 2", syncable::BOOKMARKS, new_fid); | 258 CheckEntry(&b2, "bookmark 2", syncable::BOOKMARKS, new_fid); |
| 255 ASSERT_TRUE(b2.Get(syncable::NEXT_ID).IsRoot()); | 259 ASSERT_TRUE(b2.Get(syncable::NEXT_ID).IsRoot()); |
| 256 | 260 |
| 257 // Look at the prefs and autofill items. | 261 // Look at the prefs and autofill items. |
| 258 Entry p1(&trans, syncable::GET_BY_ID, b_folder.Get(syncable::NEXT_ID)); | 262 Entry p1(&trans, syncable::GET_BY_ID, b_folder.Get(syncable::NEXT_ID)); |
| 259 Entry p2(&trans, syncable::GET_BY_ID, p1.Get(syncable::NEXT_ID)); | 263 Entry p2(&trans, syncable::GET_BY_ID, p1.Get(syncable::NEXT_ID)); |
| 260 CheckEntry(&p1, "Pref 1", syncable::PREFERENCES, id_factory_.root()); | 264 CheckEntry(&p1, "Pref 1", syncable::PREFERENCES, id_factory_.root()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 281 // Create the parent folder, a new item whose ID will change on commit. | 285 // Create the parent folder, a new item whose ID will change on commit. |
| 282 Id folder_id = id_factory_.NewLocalId(); | 286 Id folder_id = id_factory_.NewLocalId(); |
| 283 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", | 287 CreateUnprocessedCommitResult(folder_id, id_factory_.root(), "A", |
| 284 syncable::BOOKMARKS); | 288 syncable::BOOKMARKS); |
| 285 | 289 |
| 286 // Verify that the item is reachable. | 290 // Verify that the item is reachable. |
| 287 { | 291 { |
| 288 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 292 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 289 ASSERT_TRUE(dir.good()); | 293 ASSERT_TRUE(dir.good()); |
| 290 ReadTransaction trans(FROM_HERE, dir); | 294 ReadTransaction trans(FROM_HERE, dir); |
| 291 ASSERT_EQ(folder_id, dir->GetFirstChildId(&trans, id_factory_.root())); | 295 Id child_id; |
| 296 ASSERT_TRUE(dir->GetFirstChildId(&trans, id_factory_.root(), &child_id)); |
| 297 ASSERT_EQ(folder_id, child_id); |
| 292 } | 298 } |
| 293 | 299 |
| 294 // The first 25 children of the parent folder will be part of the commit | 300 // The first 25 children of the parent folder will be part of the commit |
| 295 // batch. | 301 // batch. |
| 296 int batch_size = 25; | 302 int batch_size = 25; |
| 297 int i = 0; | 303 int i = 0; |
| 298 for (; i < batch_size; ++i) { | 304 for (; i < batch_size; ++i) { |
| 299 // Alternate between new and old child items, just for kicks. | 305 // Alternate between new and old child items, just for kicks. |
| 300 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); | 306 Id id = (i % 4 < 2) ? id_factory_.NewLocalId() : id_factory_.NewServerId(); |
| 301 CreateUnprocessedCommitResult( | 307 CreateUnprocessedCommitResult( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 316 // 25 items. This should apply the values indicated by | 322 // 25 items. This should apply the values indicated by |
| 317 // each CommitResponse_EntryResponse to the syncable Entries. All new | 323 // each CommitResponse_EntryResponse to the syncable Entries. All new |
| 318 // items in the commit batch should have their IDs changed to server IDs. | 324 // items in the commit batch should have their IDs changed to server IDs. |
| 319 command_.ExecuteImpl(session()); | 325 command_.ExecuteImpl(session()); |
| 320 | 326 |
| 321 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); | 327 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); |
| 322 ASSERT_TRUE(dir.good()); | 328 ASSERT_TRUE(dir.good()); |
| 323 ReadTransaction trans(FROM_HERE, dir); | 329 ReadTransaction trans(FROM_HERE, dir); |
| 324 // Lookup the parent folder by finding a child of the root. We can't use | 330 // Lookup the parent folder by finding a child of the root. We can't use |
| 325 // folder_id here, because it changed during the commit. | 331 // folder_id here, because it changed during the commit. |
| 326 Id new_fid = dir->GetFirstChildId(&trans, id_factory_.root()); | 332 Id new_fid; |
| 333 ASSERT_TRUE(dir->GetFirstChildId(&trans, id_factory_.root(), &new_fid)); |
| 327 ASSERT_FALSE(new_fid.IsRoot()); | 334 ASSERT_FALSE(new_fid.IsRoot()); |
| 328 EXPECT_TRUE(new_fid.ServerKnows()); | 335 EXPECT_TRUE(new_fid.ServerKnows()); |
| 329 EXPECT_FALSE(folder_id.ServerKnows()); | 336 EXPECT_FALSE(folder_id.ServerKnows()); |
| 330 EXPECT_TRUE(new_fid != folder_id); | 337 EXPECT_TRUE(new_fid != folder_id); |
| 331 Entry parent(&trans, syncable::GET_BY_ID, new_fid); | 338 Entry parent(&trans, syncable::GET_BY_ID, new_fid); |
| 332 ASSERT_TRUE(parent.good()); | 339 ASSERT_TRUE(parent.good()); |
| 333 ASSERT_EQ("A", parent.Get(NON_UNIQUE_NAME)) | 340 ASSERT_EQ("A", parent.Get(NON_UNIQUE_NAME)) |
| 334 << "Name of parent folder should not change."; | 341 << "Name of parent folder should not change."; |
| 335 ASSERT_LT(0, parent.Get(BASE_VERSION)) | 342 ASSERT_LT(0, parent.Get(BASE_VERSION)) |
| 336 << "Parent should have a valid (positive) server base revision"; | 343 << "Parent should have a valid (positive) server base revision"; |
| 337 | 344 |
| 338 Id cid = dir->GetFirstChildId(&trans, new_fid); | 345 Id cid; |
| 346 ASSERT_TRUE(dir->GetFirstChildId(&trans, new_fid, &cid)); |
| 339 int child_count = 0; | 347 int child_count = 0; |
| 340 // Now loop over all the children of the parent folder, verifying | 348 // Now loop over all the children of the parent folder, verifying |
| 341 // that they are in their original order by checking to see that their | 349 // that they are in their original order by checking to see that their |
| 342 // names are still sequential. | 350 // names are still sequential. |
| 343 while (!cid.IsRoot()) { | 351 while (!cid.IsRoot()) { |
| 344 SCOPED_TRACE(::testing::Message("Examining item #") << child_count); | 352 SCOPED_TRACE(::testing::Message("Examining item #") << child_count); |
| 345 Entry c(&trans, syncable::GET_BY_ID, cid); | 353 Entry c(&trans, syncable::GET_BY_ID, cid); |
| 346 DCHECK(c.good()); | 354 DCHECK(c.good()); |
| 347 ASSERT_EQ(base::StringPrintf("Item %d", child_count), | 355 ASSERT_EQ(base::StringPrintf("Item %d", child_count), |
| 348 c.Get(NON_UNIQUE_NAME)); | 356 c.Get(NON_UNIQUE_NAME)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 439 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
| 432 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 440 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
| 433 } else { | 441 } else { |
| 434 EXPECT_TRUE(final_monitor_records.empty()) | 442 EXPECT_TRUE(final_monitor_records.empty()) |
| 435 << "Should not restore records after successful bookmark commit."; | 443 << "Should not restore records after successful bookmark commit."; |
| 436 } | 444 } |
| 437 } | 445 } |
| 438 | 446 |
| 439 | 447 |
| 440 } // namespace browser_sync | 448 } // namespace browser_sync |
| OLD | NEW |