Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: sync/syncable/syncable_unittest.cc

Issue 11863011: Revert 176340 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/syncable/mutable_entry.cc ('k') | sync/test/engine/test_syncable_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles); 139 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles);
140 EXPECT_TRUE(child_handles.empty()); 140 EXPECT_TRUE(child_handles.empty());
141 141
142 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles); 142 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles);
143 EXPECT_TRUE(child_handles.empty()); 143 EXPECT_TRUE(child_handles.empty());
144 } 144 }
145 145
146 // Test creating a new meta entry. 146 // Test creating a new meta entry.
147 { 147 {
148 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); 148 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
149 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); 149 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
150 ASSERT_TRUE(me.good()); 150 ASSERT_TRUE(me.good());
151 me.Put(ID, id); 151 me.Put(ID, id);
152 me.Put(BASE_VERSION, 1); 152 me.Put(BASE_VERSION, 1);
153 written_metahandle = me.Get(META_HANDLE); 153 written_metahandle = me.Get(META_HANDLE);
154 } 154 }
155 155
156 // Test GetChildHandles* after something is now in the DB. 156 // Test GetChildHandles* after something is now in the DB.
157 // Also check that GET_BY_ID works. 157 // Also check that GET_BY_ID works.
158 { 158 {
159 ReadTransaction rtrans(FROM_HERE, &dir); 159 ReadTransaction rtrans(FROM_HERE, &dir);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 ASSERT_FALSE(e.good()); // Hasn't been written yet. 231 ASSERT_FALSE(e.good()); // Hasn't been written yet.
232 232
233 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id())); 233 EXPECT_FALSE(dir.HasChildren(&rtrans, rtrans.root_id()));
234 Id child_id; 234 Id child_id;
235 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id(), &child_id)); 235 EXPECT_TRUE(dir.GetFirstChildId(&rtrans, rtrans.root_id(), &child_id));
236 EXPECT_TRUE(child_id.IsRoot()); 236 EXPECT_TRUE(child_id.IsRoot());
237 } 237 }
238 238
239 { 239 {
240 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); 240 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
241 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); 241 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
242 ASSERT_TRUE(me.good()); 242 ASSERT_TRUE(me.good());
243 me.Put(ID, id); 243 me.Put(ID, id);
244 me.Put(BASE_VERSION, 1); 244 me.Put(BASE_VERSION, 1);
245 written_metahandle = me.Get(META_HANDLE); 245 written_metahandle = me.Get(META_HANDLE);
246 } 246 }
247 247
248 // Test children ops after something is now in the DB. 248 // Test children ops after something is now in the DB.
249 { 249 {
250 ReadTransaction rtrans(FROM_HERE, &dir); 250 ReadTransaction rtrans(FROM_HERE, &dir);
251 Entry e(&rtrans, GET_BY_ID, id); 251 Entry e(&rtrans, GET_BY_ID, id);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 { 293 {
294 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), 294 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_),
295 &handler_, 295 &handler_,
296 NULL, 296 NULL,
297 NULL, 297 NULL,
298 NULL); 298 NULL);
299 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, 299 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_,
300 NullTransactionObserver())); 300 NullTransactionObserver()));
301 { 301 {
302 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); 302 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
303 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), name); 303 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
304 ASSERT_TRUE(me.good()); 304 ASSERT_TRUE(me.good());
305 me.Put(ID, id); 305 me.Put(ID, id);
306 me.Put(BASE_VERSION, 1); 306 me.Put(BASE_VERSION, 1);
307 me.Put(UNIQUE_CLIENT_TAG, tag); 307 me.Put(UNIQUE_CLIENT_TAG, tag);
308 written_metahandle = me.Get(META_HANDLE); 308 written_metahandle = me.Get(META_HANDLE);
309 } 309 }
310 dir.SaveChanges(); 310 dir.SaveChanges();
311 } 311 }
312 312
313 // The DB was closed. Now reopen it. This will cause index regeneration. 313 // The DB was closed. Now reopen it. This will cause index regeneration.
(...skipping 25 matching lines...) Expand all
339 { 339 {
340 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_), 340 Directory dir(new OnDiskDirectoryBackingStore(kIndexTestName, db_path_),
341 &handler_, 341 &handler_,
342 NULL, 342 NULL,
343 NULL, 343 NULL,
344 NULL); 344 NULL);
345 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_, 345 ASSERT_EQ(OPENED, dir.Open(kIndexTestName, &delegate_,
346 NullTransactionObserver())); 346 NullTransactionObserver()));
347 { 347 {
348 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); 348 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
349 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "deleted"); 349 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "deleted");
350 ASSERT_TRUE(me.good()); 350 ASSERT_TRUE(me.good());
351 me.Put(ID, id); 351 me.Put(ID, id);
352 me.Put(BASE_VERSION, 1); 352 me.Put(BASE_VERSION, 1);
353 me.Put(UNIQUE_CLIENT_TAG, tag); 353 me.Put(UNIQUE_CLIENT_TAG, tag);
354 me.Put(IS_DEL, true); 354 me.Put(IS_DEL, true);
355 me.Put(IS_UNSYNCED, true); // Or it might be purged. 355 me.Put(IS_UNSYNCED, true); // Or it might be purged.
356 } 356 }
357 dir.SaveChanges(); 357 dir.SaveChanges();
358 } 358 }
359 359
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 EXPECT_FALSE(e.good()); // Hasn't been written yet. 394 EXPECT_FALSE(e.good()); // Hasn't been written yet.
395 395
396 scoped_ptr<DictionaryValue> value(e.ToValue(NULL)); 396 scoped_ptr<DictionaryValue> value(e.ToValue(NULL));
397 ExpectDictBooleanValue(false, *value, "good"); 397 ExpectDictBooleanValue(false, *value, "good");
398 EXPECT_EQ(1u, value->size()); 398 EXPECT_EQ(1u, value->size());
399 } 399 }
400 400
401 // Test creating a new meta entry. 401 // Test creating a new meta entry.
402 { 402 {
403 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir); 403 WriteTransaction wtrans(FROM_HERE, UNITTEST, &dir);
404 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "new"); 404 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), "new");
405 ASSERT_TRUE(me.good()); 405 ASSERT_TRUE(me.good());
406 me.Put(ID, id); 406 me.Put(ID, id);
407 me.Put(BASE_VERSION, 1); 407 me.Put(BASE_VERSION, 1);
408 408
409 scoped_ptr<DictionaryValue> value(me.ToValue(NULL)); 409 scoped_ptr<DictionaryValue> value(me.ToValue(NULL));
410 ExpectDictBooleanValue(true, *value, "good"); 410 ExpectDictBooleanValue(true, *value, "good");
411 EXPECT_TRUE(value->HasKey("kernel")); 411 EXPECT_TRUE(value->HasKey("kernel"));
412 ExpectDictStringValue("Bookmarks", *value, "modelType"); 412 ExpectDictStringValue("Unspecified", *value, "modelType");
413 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty"); 413 ExpectDictBooleanValue(true, *value, "existsOnClientBecauseNameIsNonEmpty");
414 ExpectDictBooleanValue(false, *value, "isRoot"); 414 ExpectDictBooleanValue(false, *value, "isRoot");
415 } 415 }
416 416
417 dir.SaveChanges(); 417 dir.SaveChanges();
418 } 418 }
419 419
420 // A test fixture for syncable::Directory. Uses an in-memory database to keep 420 // A test fixture for syncable::Directory. Uses an in-memory database to keep
421 // the unit tests fast. 421 // the unit tests fast.
422 class SyncableDirectoryTest : public testing::Test { 422 class SyncableDirectoryTest : public testing::Test {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 void CreateEntry(const std::string& entryname) { 497 void CreateEntry(const std::string& entryname) {
498 CreateEntry(entryname, TestIdFactory::FromNumber(-99)); 498 CreateEntry(entryname, TestIdFactory::FromNumber(-99));
499 } 499 }
500 500
501 // Creates an empty entry and sets the ID field to id. 501 // Creates an empty entry and sets the ID field to id.
502 void CreateEntry(const std::string& entryname, const int id) { 502 void CreateEntry(const std::string& entryname, const int id) {
503 CreateEntry(entryname, TestIdFactory::FromNumber(id)); 503 CreateEntry(entryname, TestIdFactory::FromNumber(id));
504 } 504 }
505 void CreateEntry(const std::string& entryname, Id id) { 505 void CreateEntry(const std::string& entryname, Id id) {
506 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); 506 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get());
507 MutableEntry me(&wtrans, CREATE, BOOKMARKS, wtrans.root_id(), entryname); 507 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), entryname);
508 ASSERT_TRUE(me.good()); 508 ASSERT_TRUE(me.good());
509 me.Put(ID, id); 509 me.Put(ID, id);
510 me.Put(IS_UNSYNCED, true); 510 me.Put(IS_UNSYNCED, true);
511 } 511 }
512 512
513 void ValidateEntry(BaseTransaction* trans, 513 void ValidateEntry(BaseTransaction* trans,
514 int64 id, 514 int64 id,
515 bool check_name, 515 bool check_name,
516 const std::string& name, 516 const std::string& name,
517 int64 base_version, 517 int64 base_version,
(...skipping 19 matching lines...) Expand all
537 DirOpenResult ReloadDirImpl(); 537 DirOpenResult ReloadDirImpl();
538 }; 538 };
539 539
540 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) { 540 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsMetahandlesToPurge) {
541 const int metas_to_create = 50; 541 const int metas_to_create = 50;
542 MetahandleSet expected_purges; 542 MetahandleSet expected_purges;
543 MetahandleSet all_handles; 543 MetahandleSet all_handles;
544 { 544 {
545 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 545 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
546 for (int i = 0; i < metas_to_create; i++) { 546 for (int i = 0; i < metas_to_create; i++) {
547 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); 547 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
548 e.Put(IS_UNSYNCED, true); 548 e.Put(IS_UNSYNCED, true);
549 sync_pb::EntitySpecifics specs; 549 sync_pb::EntitySpecifics specs;
550 if (i % 2 == 0) { 550 if (i % 2 == 0) {
551 AddDefaultFieldValue(BOOKMARKS, &specs); 551 AddDefaultFieldValue(BOOKMARKS, &specs);
552 expected_purges.insert(e.Get(META_HANDLE)); 552 expected_purges.insert(e.Get(META_HANDLE));
553 all_handles.insert(e.Get(META_HANDLE)); 553 all_handles.insert(e.Get(META_HANDLE));
554 } else { 554 } else {
555 AddDefaultFieldValue(PREFERENCES, &specs); 555 AddDefaultFieldValue(PREFERENCES, &specs);
556 all_handles.insert(e.Get(META_HANDLE)); 556 all_handles.insert(e.Get(META_HANDLE));
557 } 557 }
(...skipping 20 matching lines...) Expand all
578 dir_->TakeSnapshotForSaveChanges(&snapshot2); 578 dir_->TakeSnapshotForSaveChanges(&snapshot2);
579 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge); 579 EXPECT_TRUE(all_handles == snapshot2.metahandles_to_purge);
580 } 580 }
581 581
582 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) { 582 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest) {
583 const int metahandles_to_create = 100; 583 const int metahandles_to_create = 100;
584 std::vector<int64> expected_dirty_metahandles; 584 std::vector<int64> expected_dirty_metahandles;
585 { 585 {
586 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 586 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
587 for (int i = 0; i < metahandles_to_create; i++) { 587 for (int i = 0; i < metahandles_to_create; i++) {
588 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); 588 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
589 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); 589 expected_dirty_metahandles.push_back(e.Get(META_HANDLE));
590 e.Put(IS_UNSYNCED, true); 590 e.Put(IS_UNSYNCED, true);
591 } 591 }
592 } 592 }
593 // Fake SaveChanges() and make sure we got what we expected. 593 // Fake SaveChanges() and make sure we got what we expected.
594 { 594 {
595 Directory::SaveChangesSnapshot snapshot; 595 Directory::SaveChangesSnapshot snapshot;
596 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); 596 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
597 dir_->TakeSnapshotForSaveChanges(&snapshot); 597 dir_->TakeSnapshotForSaveChanges(&snapshot);
598 // Make sure there's an entry for each new metahandle. Make sure all 598 // Make sure there's an entry for each new metahandle. Make sure all
(...skipping 10 matching lines...) Expand all
609 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 609 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
610 std::vector<int64> new_dirty_metahandles; 610 std::vector<int64> new_dirty_metahandles;
611 for (std::vector<int64>::const_iterator i = 611 for (std::vector<int64>::const_iterator i =
612 expected_dirty_metahandles.begin(); 612 expected_dirty_metahandles.begin();
613 i != expected_dirty_metahandles.end(); ++i) { 613 i != expected_dirty_metahandles.end(); ++i) {
614 // Change existing entries to directories to dirty them. 614 // Change existing entries to directories to dirty them.
615 MutableEntry e1(&trans, GET_BY_HANDLE, *i); 615 MutableEntry e1(&trans, GET_BY_HANDLE, *i);
616 e1.Put(IS_DIR, true); 616 e1.Put(IS_DIR, true);
617 e1.Put(IS_UNSYNCED, true); 617 e1.Put(IS_UNSYNCED, true);
618 // Add new entries 618 // Add new entries
619 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); 619 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar");
620 e2.Put(IS_UNSYNCED, true); 620 e2.Put(IS_UNSYNCED, true);
621 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); 621 new_dirty_metahandles.push_back(e2.Get(META_HANDLE));
622 } 622 }
623 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), 623 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(),
624 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); 624 new_dirty_metahandles.begin(), new_dirty_metahandles.end());
625 } 625 }
626 // Fake SaveChanges() and make sure we got what we expected. 626 // Fake SaveChanges() and make sure we got what we expected.
627 { 627 {
628 Directory::SaveChangesSnapshot snapshot; 628 Directory::SaveChangesSnapshot snapshot;
629 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex); 629 base::AutoLock scoped_lock(dir_->kernel_->save_changes_mutex);
(...skipping 11 matching lines...) Expand all
641 641
642 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { 642 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) {
643 const int metahandles_to_create = 100; 643 const int metahandles_to_create = 100;
644 644
645 // half of 2 * metahandles_to_create 645 // half of 2 * metahandles_to_create
646 const unsigned int number_changed = 100u; 646 const unsigned int number_changed = 100u;
647 std::vector<int64> expected_dirty_metahandles; 647 std::vector<int64> expected_dirty_metahandles;
648 { 648 {
649 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 649 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
650 for (int i = 0; i < metahandles_to_create; i++) { 650 for (int i = 0; i < metahandles_to_create; i++) {
651 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), "foo"); 651 MutableEntry e(&trans, CREATE, trans.root_id(), "foo");
652 expected_dirty_metahandles.push_back(e.Get(META_HANDLE)); 652 expected_dirty_metahandles.push_back(e.Get(META_HANDLE));
653 e.Put(IS_UNSYNCED, true); 653 e.Put(IS_UNSYNCED, true);
654 } 654 }
655 } 655 }
656 dir_->SaveChanges(); 656 dir_->SaveChanges();
657 // Put a new value with existing transactions as well as adding new ones. 657 // Put a new value with existing transactions as well as adding new ones.
658 { 658 {
659 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 659 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
660 std::vector<int64> new_dirty_metahandles; 660 std::vector<int64> new_dirty_metahandles;
661 for (std::vector<int64>::const_iterator i = 661 for (std::vector<int64>::const_iterator i =
662 expected_dirty_metahandles.begin(); 662 expected_dirty_metahandles.begin();
663 i != expected_dirty_metahandles.end(); ++i) { 663 i != expected_dirty_metahandles.end(); ++i) {
664 // Change existing entries to directories to dirty them. 664 // Change existing entries to directories to dirty them.
665 MutableEntry e1(&trans, GET_BY_HANDLE, *i); 665 MutableEntry e1(&trans, GET_BY_HANDLE, *i);
666 ASSERT_TRUE(e1.good()); 666 ASSERT_TRUE(e1.good());
667 e1.Put(IS_DIR, true); 667 e1.Put(IS_DIR, true);
668 e1.Put(IS_UNSYNCED, true); 668 e1.Put(IS_UNSYNCED, true);
669 // Add new entries 669 // Add new entries
670 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), "bar"); 670 MutableEntry e2(&trans, CREATE, trans.root_id(), "bar");
671 e2.Put(IS_UNSYNCED, true); 671 e2.Put(IS_UNSYNCED, true);
672 new_dirty_metahandles.push_back(e2.Get(META_HANDLE)); 672 new_dirty_metahandles.push_back(e2.Get(META_HANDLE));
673 } 673 }
674 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(), 674 expected_dirty_metahandles.insert(expected_dirty_metahandles.end(),
675 new_dirty_metahandles.begin(), new_dirty_metahandles.end()); 675 new_dirty_metahandles.begin(), new_dirty_metahandles.end());
676 } 676 }
677 dir_->SaveChanges(); 677 dir_->SaveChanges();
678 // Don't make any changes whatsoever and ensure nothing comes back. 678 // Don't make any changes whatsoever and ensure nothing comes back.
679 { 679 {
680 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 680 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) { 864 TEST_F(SyncableDirectoryTest, TestBasicLookupValidID) {
865 CreateEntry("rtc"); 865 CreateEntry("rtc");
866 ReadTransaction rtrans(FROM_HERE, dir_.get()); 866 ReadTransaction rtrans(FROM_HERE, dir_.get());
867 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99)); 867 Entry e(&rtrans, GET_BY_ID, TestIdFactory::FromNumber(-99));
868 ASSERT_TRUE(e.good()); 868 ASSERT_TRUE(e.good());
869 } 869 }
870 870
871 TEST_F(SyncableDirectoryTest, TestDelete) { 871 TEST_F(SyncableDirectoryTest, TestDelete) {
872 std::string name = "peanut butter jelly time"; 872 std::string name = "peanut butter jelly time";
873 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 873 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
874 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 874 MutableEntry e1(&trans, CREATE, trans.root_id(), name);
875 ASSERT_TRUE(e1.good()); 875 ASSERT_TRUE(e1.good());
876 ASSERT_TRUE(e1.Put(IS_DEL, true)); 876 ASSERT_TRUE(e1.Put(IS_DEL, true));
877 MutableEntry e2(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 877 MutableEntry e2(&trans, CREATE, trans.root_id(), name);
878 ASSERT_TRUE(e2.good()); 878 ASSERT_TRUE(e2.good());
879 ASSERT_TRUE(e2.Put(IS_DEL, true)); 879 ASSERT_TRUE(e2.Put(IS_DEL, true));
880 MutableEntry e3(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 880 MutableEntry e3(&trans, CREATE, trans.root_id(), name);
881 ASSERT_TRUE(e3.good()); 881 ASSERT_TRUE(e3.good());
882 ASSERT_TRUE(e3.Put(IS_DEL, true)); 882 ASSERT_TRUE(e3.Put(IS_DEL, true));
883 883
884 ASSERT_TRUE(e1.Put(IS_DEL, false)); 884 ASSERT_TRUE(e1.Put(IS_DEL, false));
885 ASSERT_TRUE(e2.Put(IS_DEL, false)); 885 ASSERT_TRUE(e2.Put(IS_DEL, false));
886 ASSERT_TRUE(e3.Put(IS_DEL, false)); 886 ASSERT_TRUE(e3.Put(IS_DEL, false));
887 887
888 ASSERT_TRUE(e1.Put(IS_DEL, true)); 888 ASSERT_TRUE(e1.Put(IS_DEL, true));
889 ASSERT_TRUE(e2.Put(IS_DEL, true)); 889 ASSERT_TRUE(e2.Put(IS_DEL, true));
890 ASSERT_TRUE(e3.Put(IS_DEL, true)); 890 ASSERT_TRUE(e3.Put(IS_DEL, true));
891 } 891 }
892 892
893 TEST_F(SyncableDirectoryTest, TestGetUnsynced) { 893 TEST_F(SyncableDirectoryTest, TestGetUnsynced) {
894 Directory::UnsyncedMetaHandles handles; 894 Directory::UnsyncedMetaHandles handles;
895 int64 handle1, handle2; 895 int64 handle1, handle2;
896 { 896 {
897 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 897 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
898 898
899 dir_->GetUnsyncedMetaHandles(&trans, &handles); 899 dir_->GetUnsyncedMetaHandles(&trans, &handles);
900 ASSERT_TRUE(0 == handles.size()); 900 ASSERT_TRUE(0 == handles.size());
901 901
902 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); 902 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba");
903 ASSERT_TRUE(e1.good()); 903 ASSERT_TRUE(e1.good());
904 handle1 = e1.Get(META_HANDLE); 904 handle1 = e1.Get(META_HANDLE);
905 e1.Put(BASE_VERSION, 1); 905 e1.Put(BASE_VERSION, 1);
906 e1.Put(IS_DIR, true); 906 e1.Put(IS_DIR, true);
907 e1.Put(ID, TestIdFactory::FromNumber(101)); 907 e1.Put(ID, TestIdFactory::FromNumber(101));
908 908
909 MutableEntry e2(&trans, CREATE, BOOKMARKS, e1.Get(ID), "bread"); 909 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread");
910 ASSERT_TRUE(e2.good()); 910 ASSERT_TRUE(e2.good());
911 handle2 = e2.Get(META_HANDLE); 911 handle2 = e2.Get(META_HANDLE);
912 e2.Put(BASE_VERSION, 1); 912 e2.Put(BASE_VERSION, 1);
913 e2.Put(ID, TestIdFactory::FromNumber(102)); 913 e2.Put(ID, TestIdFactory::FromNumber(102));
914 } 914 }
915 dir_->SaveChanges(); 915 dir_->SaveChanges();
916 { 916 {
917 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 917 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
918 918
919 dir_->GetUnsyncedMetaHandles(&trans, &handles); 919 dir_->GetUnsyncedMetaHandles(&trans, &handles);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) { 964 TEST_F(SyncableDirectoryTest, TestGetUnappliedUpdates) {
965 std::vector<int64> handles; 965 std::vector<int64> handles;
966 int64 handle1, handle2; 966 int64 handle1, handle2;
967 const FullModelTypeSet all_types = FullModelTypeSet::All(); 967 const FullModelTypeSet all_types = FullModelTypeSet::All();
968 { 968 {
969 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 969 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
970 970
971 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles); 971 dir_->GetUnappliedUpdateMetaHandles(&trans, all_types, &handles);
972 ASSERT_TRUE(0 == handles.size()); 972 ASSERT_TRUE(0 == handles.size());
973 973
974 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "abba"); 974 MutableEntry e1(&trans, CREATE, trans.root_id(), "abba");
975 ASSERT_TRUE(e1.good()); 975 ASSERT_TRUE(e1.good());
976 handle1 = e1.Get(META_HANDLE); 976 handle1 = e1.Get(META_HANDLE);
977 e1.Put(IS_UNAPPLIED_UPDATE, false); 977 e1.Put(IS_UNAPPLIED_UPDATE, false);
978 e1.Put(BASE_VERSION, 1); 978 e1.Put(BASE_VERSION, 1);
979 e1.Put(ID, TestIdFactory::FromNumber(101)); 979 e1.Put(ID, TestIdFactory::FromNumber(101));
980 e1.Put(IS_DIR, true); 980 e1.Put(IS_DIR, true);
981 981
982 MutableEntry e2(&trans, CREATE, BOOKMARKS, e1.Get(ID), "bread"); 982 MutableEntry e2(&trans, CREATE, e1.Get(ID), "bread");
983 ASSERT_TRUE(e2.good()); 983 ASSERT_TRUE(e2.good());
984 handle2 = e2.Get(META_HANDLE); 984 handle2 = e2.Get(META_HANDLE);
985 e2.Put(IS_UNAPPLIED_UPDATE, false); 985 e2.Put(IS_UNAPPLIED_UPDATE, false);
986 e2.Put(BASE_VERSION, 1); 986 e2.Put(BASE_VERSION, 1);
987 e2.Put(ID, TestIdFactory::FromNumber(102)); 987 e2.Put(ID, TestIdFactory::FromNumber(102));
988 } 988 }
989 dir_->SaveChanges(); 989 dir_->SaveChanges();
990 { 990 {
991 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 991 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
992 992
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 } 1033 }
1034 } 1034 }
1035 1035
1036 1036
1037 TEST_F(SyncableDirectoryTest, DeleteBug_531383) { 1037 TEST_F(SyncableDirectoryTest, DeleteBug_531383) {
1038 // Try to evoke a check failure... 1038 // Try to evoke a check failure...
1039 TestIdFactory id_factory; 1039 TestIdFactory id_factory;
1040 int64 grandchild_handle; 1040 int64 grandchild_handle;
1041 { 1041 {
1042 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); 1042 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get());
1043 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, id_factory.root(), "Bob"); 1043 MutableEntry parent(&wtrans, CREATE, id_factory.root(), "Bob");
1044 ASSERT_TRUE(parent.good()); 1044 ASSERT_TRUE(parent.good());
1045 parent.Put(IS_DIR, true); 1045 parent.Put(IS_DIR, true);
1046 parent.Put(ID, id_factory.NewServerId()); 1046 parent.Put(ID, id_factory.NewServerId());
1047 parent.Put(BASE_VERSION, 1); 1047 parent.Put(BASE_VERSION, 1);
1048 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "Bob"); 1048 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob");
1049 ASSERT_TRUE(child.good()); 1049 ASSERT_TRUE(child.good());
1050 child.Put(IS_DIR, true); 1050 child.Put(IS_DIR, true);
1051 child.Put(ID, id_factory.NewServerId()); 1051 child.Put(ID, id_factory.NewServerId());
1052 child.Put(BASE_VERSION, 1); 1052 child.Put(BASE_VERSION, 1);
1053 MutableEntry grandchild(&wtrans, CREATE, BOOKMARKS, child.Get(ID), "Bob"); 1053 MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob");
1054 ASSERT_TRUE(grandchild.good()); 1054 ASSERT_TRUE(grandchild.good());
1055 grandchild.Put(ID, id_factory.NewServerId()); 1055 grandchild.Put(ID, id_factory.NewServerId());
1056 grandchild.Put(BASE_VERSION, 1); 1056 grandchild.Put(BASE_VERSION, 1);
1057 ASSERT_TRUE(grandchild.Put(IS_DEL, true)); 1057 ASSERT_TRUE(grandchild.Put(IS_DEL, true));
1058 MutableEntry twin(&wtrans, CREATE, BOOKMARKS, child.Get(ID), "Bob"); 1058 MutableEntry twin(&wtrans, CREATE, child.Get(ID), "Bob");
1059 ASSERT_TRUE(twin.good()); 1059 ASSERT_TRUE(twin.good());
1060 ASSERT_TRUE(twin.Put(IS_DEL, true)); 1060 ASSERT_TRUE(twin.Put(IS_DEL, true));
1061 ASSERT_TRUE(grandchild.Put(IS_DEL, false)); 1061 ASSERT_TRUE(grandchild.Put(IS_DEL, false));
1062 1062
1063 grandchild_handle = grandchild.Get(META_HANDLE); 1063 grandchild_handle = grandchild.Get(META_HANDLE);
1064 } 1064 }
1065 dir_->SaveChanges(); 1065 dir_->SaveChanges();
1066 { 1066 {
1067 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); 1067 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get());
1068 MutableEntry grandchild(&wtrans, GET_BY_HANDLE, grandchild_handle); 1068 MutableEntry grandchild(&wtrans, GET_BY_HANDLE, grandchild_handle);
1069 grandchild.Put(IS_DEL, true); // Used to CHECK fail here. 1069 grandchild.Put(IS_DEL, true); // Used to CHECK fail here.
1070 } 1070 }
1071 } 1071 }
1072 1072
1073 static inline bool IsLegalNewParent(const Entry& a, const Entry& b) { 1073 static inline bool IsLegalNewParent(const Entry& a, const Entry& b) {
1074 return IsLegalNewParent(a.trans(), a.Get(ID), b.Get(ID)); 1074 return IsLegalNewParent(a.trans(), a.Get(ID), b.Get(ID));
1075 } 1075 }
1076 1076
1077 TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) { 1077 TEST_F(SyncableDirectoryTest, TestIsLegalNewParent) {
1078 TestIdFactory id_factory; 1078 TestIdFactory id_factory;
1079 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); 1079 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get());
1080 Entry root(&wtrans, GET_BY_ID, id_factory.root()); 1080 Entry root(&wtrans, GET_BY_ID, id_factory.root());
1081 ASSERT_TRUE(root.good()); 1081 ASSERT_TRUE(root.good());
1082 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root.Get(ID), "Bob"); 1082 MutableEntry parent(&wtrans, CREATE, root.Get(ID), "Bob");
1083 ASSERT_TRUE(parent.good()); 1083 ASSERT_TRUE(parent.good());
1084 parent.Put(IS_DIR, true); 1084 parent.Put(IS_DIR, true);
1085 parent.Put(ID, id_factory.NewServerId()); 1085 parent.Put(ID, id_factory.NewServerId());
1086 parent.Put(BASE_VERSION, 1); 1086 parent.Put(BASE_VERSION, 1);
1087 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.Get(ID), "Bob"); 1087 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "Bob");
1088 ASSERT_TRUE(child.good()); 1088 ASSERT_TRUE(child.good());
1089 child.Put(IS_DIR, true); 1089 child.Put(IS_DIR, true);
1090 child.Put(ID, id_factory.NewServerId()); 1090 child.Put(ID, id_factory.NewServerId());
1091 child.Put(BASE_VERSION, 1); 1091 child.Put(BASE_VERSION, 1);
1092 MutableEntry grandchild(&wtrans, CREATE, BOOKMARKS, child.Get(ID), "Bob"); 1092 MutableEntry grandchild(&wtrans, CREATE, child.Get(ID), "Bob");
1093 ASSERT_TRUE(grandchild.good()); 1093 ASSERT_TRUE(grandchild.good());
1094 grandchild.Put(ID, id_factory.NewServerId()); 1094 grandchild.Put(ID, id_factory.NewServerId());
1095 grandchild.Put(BASE_VERSION, 1); 1095 grandchild.Put(BASE_VERSION, 1);
1096 1096
1097 MutableEntry parent2(&wtrans, CREATE, BOOKMARKS, root.Get(ID), "Pete"); 1097 MutableEntry parent2(&wtrans, CREATE, root.Get(ID), "Pete");
1098 ASSERT_TRUE(parent2.good()); 1098 ASSERT_TRUE(parent2.good());
1099 parent2.Put(IS_DIR, true); 1099 parent2.Put(IS_DIR, true);
1100 parent2.Put(ID, id_factory.NewServerId()); 1100 parent2.Put(ID, id_factory.NewServerId());
1101 parent2.Put(BASE_VERSION, 1); 1101 parent2.Put(BASE_VERSION, 1);
1102 MutableEntry child2(&wtrans, CREATE, BOOKMARKS, parent2.Get(ID), "Pete"); 1102 MutableEntry child2(&wtrans, CREATE, parent2.Get(ID), "Pete");
1103 ASSERT_TRUE(child2.good()); 1103 ASSERT_TRUE(child2.good());
1104 child2.Put(IS_DIR, true); 1104 child2.Put(IS_DIR, true);
1105 child2.Put(ID, id_factory.NewServerId()); 1105 child2.Put(ID, id_factory.NewServerId());
1106 child2.Put(BASE_VERSION, 1); 1106 child2.Put(BASE_VERSION, 1);
1107 MutableEntry grandchild2(&wtrans, CREATE, BOOKMARKS, child2.Get(ID), "Pete"); 1107 MutableEntry grandchild2(&wtrans, CREATE, child2.Get(ID), "Pete");
1108 ASSERT_TRUE(grandchild2.good()); 1108 ASSERT_TRUE(grandchild2.good());
1109 grandchild2.Put(ID, id_factory.NewServerId()); 1109 grandchild2.Put(ID, id_factory.NewServerId());
1110 grandchild2.Put(BASE_VERSION, 1); 1110 grandchild2.Put(BASE_VERSION, 1);
1111 // resulting tree 1111 // resulting tree
1112 // root 1112 // root
1113 // / | 1113 // / |
1114 // parent parent2 1114 // parent parent2
1115 // | | 1115 // | |
1116 // child child2 1116 // child child2
1117 // | | 1117 // | |
(...skipping 11 matching lines...) Expand all
1129 1129
1130 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) { 1130 TEST_F(SyncableDirectoryTest, TestEntryIsInFolder) {
1131 // Create a subdir and an entry. 1131 // Create a subdir and an entry.
1132 int64 entry_handle; 1132 int64 entry_handle;
1133 syncable::Id folder_id; 1133 syncable::Id folder_id;
1134 syncable::Id entry_id; 1134 syncable::Id entry_id;
1135 std::string entry_name = "entry"; 1135 std::string entry_name = "entry";
1136 1136
1137 { 1137 {
1138 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1138 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1139 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "folder"); 1139 MutableEntry folder(&trans, CREATE, trans.root_id(), "folder");
1140 ASSERT_TRUE(folder.good()); 1140 ASSERT_TRUE(folder.good());
1141 EXPECT_TRUE(folder.Put(IS_DIR, true)); 1141 EXPECT_TRUE(folder.Put(IS_DIR, true));
1142 EXPECT_TRUE(folder.Put(IS_UNSYNCED, true)); 1142 EXPECT_TRUE(folder.Put(IS_UNSYNCED, true));
1143 folder_id = folder.Get(ID); 1143 folder_id = folder.Get(ID);
1144 1144
1145 MutableEntry entry(&trans, CREATE, BOOKMARKS, folder.Get(ID), entry_name); 1145 MutableEntry entry(&trans, CREATE, folder.Get(ID), entry_name);
1146 ASSERT_TRUE(entry.good()); 1146 ASSERT_TRUE(entry.good());
1147 entry_handle = entry.Get(META_HANDLE); 1147 entry_handle = entry.Get(META_HANDLE);
1148 entry.Put(IS_UNSYNCED, true); 1148 entry.Put(IS_UNSYNCED, true);
1149 entry_id = entry.Get(ID); 1149 entry_id = entry.Get(ID);
1150 } 1150 }
1151 1151
1152 // Make sure we can find the entry in the folder. 1152 // Make sure we can find the entry in the folder.
1153 { 1153 {
1154 ReadTransaction trans(FROM_HERE, dir_.get()); 1154 ReadTransaction trans(FROM_HERE, dir_.get());
1155 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), entry_name)); 1155 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), entry_name));
1156 EXPECT_EQ(1, CountEntriesWithName(&trans, folder_id, entry_name)); 1156 EXPECT_EQ(1, CountEntriesWithName(&trans, folder_id, entry_name));
1157 1157
1158 Entry entry(&trans, GET_BY_ID, entry_id); 1158 Entry entry(&trans, GET_BY_ID, entry_id);
1159 ASSERT_TRUE(entry.good()); 1159 ASSERT_TRUE(entry.good());
1160 EXPECT_EQ(entry_handle, entry.Get(META_HANDLE)); 1160 EXPECT_EQ(entry_handle, entry.Get(META_HANDLE));
1161 EXPECT_TRUE(entry.Get(NON_UNIQUE_NAME) == entry_name); 1161 EXPECT_TRUE(entry.Get(NON_UNIQUE_NAME) == entry_name);
1162 EXPECT_TRUE(entry.Get(PARENT_ID) == folder_id); 1162 EXPECT_TRUE(entry.Get(PARENT_ID) == folder_id);
1163 } 1163 }
1164 } 1164 }
1165 1165
1166 TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) { 1166 TEST_F(SyncableDirectoryTest, TestParentIdIndexUpdate) {
1167 std::string child_name = "child"; 1167 std::string child_name = "child";
1168 1168
1169 WriteTransaction wt(FROM_HERE, UNITTEST, dir_.get()); 1169 WriteTransaction wt(FROM_HERE, UNITTEST, dir_.get());
1170 MutableEntry parent_folder(&wt, CREATE, BOOKMARKS, wt.root_id(), "folder1"); 1170 MutableEntry parent_folder(&wt, CREATE, wt.root_id(), "folder1");
1171 parent_folder.Put(IS_UNSYNCED, true); 1171 parent_folder.Put(IS_UNSYNCED, true);
1172 EXPECT_TRUE(parent_folder.Put(IS_DIR, true)); 1172 EXPECT_TRUE(parent_folder.Put(IS_DIR, true));
1173 1173
1174 MutableEntry parent_folder2(&wt, CREATE, BOOKMARKS, wt.root_id(), "folder2"); 1174 MutableEntry parent_folder2(&wt, CREATE, wt.root_id(), "folder2");
1175 parent_folder2.Put(IS_UNSYNCED, true); 1175 parent_folder2.Put(IS_UNSYNCED, true);
1176 EXPECT_TRUE(parent_folder2.Put(IS_DIR, true)); 1176 EXPECT_TRUE(parent_folder2.Put(IS_DIR, true));
1177 1177
1178 MutableEntry child(&wt, CREATE, BOOKMARKS, parent_folder.Get(ID), child_name); 1178 MutableEntry child(&wt, CREATE, parent_folder.Get(ID), child_name);
1179 EXPECT_TRUE(child.Put(IS_DIR, true)); 1179 EXPECT_TRUE(child.Put(IS_DIR, true));
1180 child.Put(IS_UNSYNCED, true); 1180 child.Put(IS_UNSYNCED, true);
1181 1181
1182 ASSERT_TRUE(child.good()); 1182 ASSERT_TRUE(child.good());
1183 1183
1184 EXPECT_EQ(0, CountEntriesWithName(&wt, wt.root_id(), child_name)); 1184 EXPECT_EQ(0, CountEntriesWithName(&wt, wt.root_id(), child_name));
1185 EXPECT_EQ(parent_folder.Get(ID), child.Get(PARENT_ID)); 1185 EXPECT_EQ(parent_folder.Get(ID), child.Get(PARENT_ID));
1186 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); 1186 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name));
1187 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); 1187 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name));
1188 child.Put(PARENT_ID, parent_folder2.Get(ID)); 1188 child.Put(PARENT_ID, parent_folder2.Get(ID));
1189 EXPECT_EQ(parent_folder2.Get(ID), child.Get(PARENT_ID)); 1189 EXPECT_EQ(parent_folder2.Get(ID), child.Get(PARENT_ID));
1190 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name)); 1190 EXPECT_EQ(0, CountEntriesWithName(&wt, parent_folder.Get(ID), child_name));
1191 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name)); 1191 EXPECT_EQ(1, CountEntriesWithName(&wt, parent_folder2.Get(ID), child_name));
1192 } 1192 }
1193 1193
1194 TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) { 1194 TEST_F(SyncableDirectoryTest, TestNoReindexDeletedItems) {
1195 std::string folder_name = "folder"; 1195 std::string folder_name = "folder";
1196 std::string new_name = "new_name"; 1196 std::string new_name = "new_name";
1197 1197
1198 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1198 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1199 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), folder_name); 1199 MutableEntry folder(&trans, CREATE, trans.root_id(), folder_name);
1200 ASSERT_TRUE(folder.good()); 1200 ASSERT_TRUE(folder.good());
1201 ASSERT_TRUE(folder.Put(IS_DIR, true)); 1201 ASSERT_TRUE(folder.Put(IS_DIR, true));
1202 ASSERT_TRUE(folder.Put(IS_DEL, true)); 1202 ASSERT_TRUE(folder.Put(IS_DEL, true));
1203 1203
1204 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); 1204 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name));
1205 1205
1206 MutableEntry deleted(&trans, GET_BY_ID, folder.Get(ID)); 1206 MutableEntry deleted(&trans, GET_BY_ID, folder.Get(ID));
1207 ASSERT_TRUE(deleted.good()); 1207 ASSERT_TRUE(deleted.good());
1208 ASSERT_TRUE(deleted.Put(PARENT_ID, trans.root_id())); 1208 ASSERT_TRUE(deleted.Put(PARENT_ID, trans.root_id()));
1209 ASSERT_TRUE(deleted.Put(NON_UNIQUE_NAME, new_name)); 1209 ASSERT_TRUE(deleted.Put(NON_UNIQUE_NAME, new_name));
1210 1210
1211 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name)); 1211 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), folder_name));
1212 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), new_name)); 1212 EXPECT_EQ(0, CountEntriesWithName(&trans, trans.root_id(), new_name));
1213 } 1213 }
1214 1214
1215 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) { 1215 TEST_F(SyncableDirectoryTest, TestCaseChangeRename) {
1216 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1216 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1217 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "CaseChange"); 1217 MutableEntry folder(&trans, CREATE, trans.root_id(), "CaseChange");
1218 ASSERT_TRUE(folder.good()); 1218 ASSERT_TRUE(folder.good());
1219 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id())); 1219 EXPECT_TRUE(folder.Put(PARENT_ID, trans.root_id()));
1220 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE")); 1220 EXPECT_TRUE(folder.Put(NON_UNIQUE_NAME, "CASECHANGE"));
1221 EXPECT_TRUE(folder.Put(IS_DEL, true)); 1221 EXPECT_TRUE(folder.Put(IS_DEL, true));
1222 } 1222 }
1223 1223
1224 // Create items of each model type, and check that GetModelType and 1224 // Create items of each model type, and check that GetModelType and
1225 // GetServerModelType return the right value. 1225 // GetServerModelType return the right value.
1226 TEST_F(SyncableDirectoryTest, GetModelType) { 1226 TEST_F(SyncableDirectoryTest, GetModelType) {
1227 TestIdFactory id_factory; 1227 TestIdFactory id_factory;
1228 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) { 1228 for (int i = 0; i < MODEL_TYPE_COUNT; ++i) {
1229 ModelType datatype = ModelTypeFromInt(i); 1229 ModelType datatype = ModelTypeFromInt(i);
1230 SCOPED_TRACE(testing::Message("Testing model type ") << datatype); 1230 SCOPED_TRACE(testing::Message("Testing model type ") << datatype);
1231 switch (datatype) { 1231 switch (datatype) {
1232 case UNSPECIFIED: 1232 case UNSPECIFIED:
1233 case TOP_LEVEL_FOLDER: 1233 case TOP_LEVEL_FOLDER:
1234 continue; // Datatype isn't a function of Specifics. 1234 continue; // Datatype isn't a function of Specifics.
1235 default: 1235 default:
1236 break; 1236 break;
1237 } 1237 }
1238 sync_pb::EntitySpecifics specifics; 1238 sync_pb::EntitySpecifics specifics;
1239 AddDefaultFieldValue(datatype, &specifics); 1239 AddDefaultFieldValue(datatype, &specifics);
1240 1240
1241 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1241 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1242 1242
1243 MutableEntry folder(&trans, CREATE, BOOKMARKS, trans.root_id(), "Folder"); 1243 MutableEntry folder(&trans, CREATE, trans.root_id(), "Folder");
1244 ASSERT_TRUE(folder.good()); 1244 ASSERT_TRUE(folder.good());
1245 folder.Put(ID, id_factory.NewServerId()); 1245 folder.Put(ID, id_factory.NewServerId());
1246 folder.Put(SPECIFICS, specifics); 1246 folder.Put(SPECIFICS, specifics);
1247 folder.Put(BASE_VERSION, 1); 1247 folder.Put(BASE_VERSION, 1);
1248 folder.Put(IS_DIR, true); 1248 folder.Put(IS_DIR, true);
1249 folder.Put(IS_DEL, false); 1249 folder.Put(IS_DEL, false);
1250 ASSERT_EQ(datatype, folder.GetModelType()); 1250 ASSERT_EQ(datatype, folder.GetModelType());
1251 1251
1252 MutableEntry item(&trans, CREATE, BOOKMARKS, trans.root_id(), "Item"); 1252 MutableEntry item(&trans, CREATE, trans.root_id(), "Item");
1253 ASSERT_TRUE(item.good()); 1253 ASSERT_TRUE(item.good());
1254 item.Put(ID, id_factory.NewServerId()); 1254 item.Put(ID, id_factory.NewServerId());
1255 item.Put(SPECIFICS, specifics); 1255 item.Put(SPECIFICS, specifics);
1256 item.Put(BASE_VERSION, 1); 1256 item.Put(BASE_VERSION, 1);
1257 item.Put(IS_DIR, false); 1257 item.Put(IS_DIR, false);
1258 item.Put(IS_DEL, false); 1258 item.Put(IS_DEL, false);
1259 ASSERT_EQ(datatype, item.GetModelType()); 1259 ASSERT_EQ(datatype, item.GetModelType());
1260 1260
1261 // It's critical that deletion records retain their datatype, so that 1261 // It's critical that deletion records retain their datatype, so that
1262 // they can be dispatched to the appropriate change processor. 1262 // they can be dispatched to the appropriate change processor.
1263 MutableEntry deleted_item( 1263 MutableEntry deleted_item(&trans, CREATE, trans.root_id(), "Deleted Item");
1264 &trans, CREATE, BOOKMARKS, trans.root_id(), "Deleted Item");
1265 ASSERT_TRUE(item.good()); 1264 ASSERT_TRUE(item.good());
1266 deleted_item.Put(ID, id_factory.NewServerId()); 1265 deleted_item.Put(ID, id_factory.NewServerId());
1267 deleted_item.Put(SPECIFICS, specifics); 1266 deleted_item.Put(SPECIFICS, specifics);
1268 deleted_item.Put(BASE_VERSION, 1); 1267 deleted_item.Put(BASE_VERSION, 1);
1269 deleted_item.Put(IS_DIR, false); 1268 deleted_item.Put(IS_DIR, false);
1270 deleted_item.Put(IS_DEL, true); 1269 deleted_item.Put(IS_DEL, true);
1271 ASSERT_EQ(datatype, deleted_item.GetModelType()); 1270 ASSERT_EQ(datatype, deleted_item.GetModelType());
1272 1271
1273 MutableEntry server_folder(&trans, CREATE_NEW_UPDATE_ITEM, 1272 MutableEntry server_folder(&trans, CREATE_NEW_UPDATE_ITEM,
1274 id_factory.NewServerId()); 1273 id_factory.NewServerId());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 // a more common variant of the 'DeletedAndUnsyncedChild' scenario tested below. 1308 // a more common variant of the 'DeletedAndUnsyncedChild' scenario tested below.
1310 TEST_F(SyncableDirectoryTest, ChangeEntryIDAndUpdateChildren_ParentAndChild) { 1309 TEST_F(SyncableDirectoryTest, ChangeEntryIDAndUpdateChildren_ParentAndChild) {
1311 TestIdFactory id_factory; 1310 TestIdFactory id_factory;
1312 Id orig_parent_id; 1311 Id orig_parent_id;
1313 Id orig_child_id; 1312 Id orig_child_id;
1314 1313
1315 { 1314 {
1316 // Create two client-side items, a parent and child. 1315 // Create two client-side items, a parent and child.
1317 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1316 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1318 1317
1319 MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); 1318 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent");
1320 parent.Put(IS_DIR, true); 1319 parent.Put(IS_DIR, true);
1321 parent.Put(IS_UNSYNCED, true); 1320 parent.Put(IS_UNSYNCED, true);
1322 1321
1323 MutableEntry child(&trans, CREATE, BOOKMARKS, parent.Get(ID), "child"); 1322 MutableEntry child(&trans, CREATE, parent.Get(ID), "child");
1324 child.Put(IS_UNSYNCED, true); 1323 child.Put(IS_UNSYNCED, true);
1325 1324
1326 orig_parent_id = parent.Get(ID); 1325 orig_parent_id = parent.Get(ID);
1327 orig_child_id = child.Get(ID); 1326 orig_child_id = child.Get(ID);
1328 } 1327 }
1329 1328
1330 { 1329 {
1331 // Simulate what happens after committing two items. Their IDs will be 1330 // Simulate what happens after committing two items. Their IDs will be
1332 // replaced with server IDs. The child is renamed first, then the parent. 1331 // replaced with server IDs. The child is renamed first, then the parent.
1333 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1332 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
(...skipping 23 matching lines...) Expand all
1357 TEST_F(SyncableDirectoryTest, 1356 TEST_F(SyncableDirectoryTest,
1358 ChangeEntryIDAndUpdateChildren_DeletedAndUnsyncedChild) { 1357 ChangeEntryIDAndUpdateChildren_DeletedAndUnsyncedChild) {
1359 TestIdFactory id_factory; 1358 TestIdFactory id_factory;
1360 Id orig_parent_id; 1359 Id orig_parent_id;
1361 Id orig_child_id; 1360 Id orig_child_id;
1362 1361
1363 { 1362 {
1364 // Create two client-side items, a parent and child. 1363 // Create two client-side items, a parent and child.
1365 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1364 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1366 1365
1367 MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); 1366 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent");
1368 parent.Put(IS_DIR, true); 1367 parent.Put(IS_DIR, true);
1369 parent.Put(IS_UNSYNCED, true); 1368 parent.Put(IS_UNSYNCED, true);
1370 1369
1371 MutableEntry child(&trans, CREATE, BOOKMARKS, parent.Get(ID), "child"); 1370 MutableEntry child(&trans, CREATE, parent.Get(ID), "child");
1372 child.Put(IS_UNSYNCED, true); 1371 child.Put(IS_UNSYNCED, true);
1373 1372
1374 orig_parent_id = parent.Get(ID); 1373 orig_parent_id = parent.Get(ID);
1375 orig_child_id = child.Get(ID); 1374 orig_child_id = child.Get(ID);
1376 } 1375 }
1377 1376
1378 { 1377 {
1379 // Delete the child. 1378 // Delete the child.
1380 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1379 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1381 1380
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 Id zombie_id = id_factory.NewLocalId(); 1439 Id zombie_id = id_factory.NewLocalId();
1441 1440
1442 // We're about to do some bad things. Tell the directory verification 1441 // We're about to do some bad things. Tell the directory verification
1443 // routines to look the other way. 1442 // routines to look the other way.
1444 dir_->SetInvariantCheckLevel(OFF); 1443 dir_->SetInvariantCheckLevel(OFF);
1445 1444
1446 { 1445 {
1447 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1446 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1448 1447
1449 // Create an uncommitted tombstone entry. 1448 // Create an uncommitted tombstone entry.
1450 MutableEntry server_knows(&trans, CREATE, BOOKMARKS, id_factory.root(), 1449 MutableEntry server_knows(&trans, CREATE, id_factory.root(),
1451 "server_knows"); 1450 "server_knows");
1452 server_knows.Put(ID, server_knows_id); 1451 server_knows.Put(ID, server_knows_id);
1453 server_knows.Put(IS_UNSYNCED, true); 1452 server_knows.Put(IS_UNSYNCED, true);
1454 server_knows.Put(IS_DEL, true); 1453 server_knows.Put(IS_DEL, true);
1455 server_knows.Put(BASE_VERSION, 5); 1454 server_knows.Put(BASE_VERSION, 5);
1456 server_knows.Put(SERVER_VERSION, 4); 1455 server_knows.Put(SERVER_VERSION, 4);
1457 1456
1458 // Create a valid update entry. 1457 // Create a valid update entry.
1459 MutableEntry not_is_del( 1458 MutableEntry not_is_del(&trans, CREATE, id_factory.root(), "not_is_del");
1460 &trans, CREATE, BOOKMARKS, id_factory.root(), "not_is_del");
1461 not_is_del.Put(ID, not_is_del_id); 1459 not_is_del.Put(ID, not_is_del_id);
1462 not_is_del.Put(IS_DEL, false); 1460 not_is_del.Put(IS_DEL, false);
1463 not_is_del.Put(IS_UNSYNCED, true); 1461 not_is_del.Put(IS_UNSYNCED, true);
1464 1462
1465 // Create a tombstone which should never be sent to the server because the 1463 // Create a tombstone which should never be sent to the server because the
1466 // server never knew about the item's existence. 1464 // server never knew about the item's existence.
1467 // 1465 //
1468 // New clients should never put entries into this state. We work around 1466 // New clients should never put entries into this state. We work around
1469 // this by setting IS_DEL before setting IS_UNSYNCED, something which the 1467 // this by setting IS_DEL before setting IS_UNSYNCED, something which the
1470 // client should never do in practice. 1468 // client should never do in practice.
1471 MutableEntry zombie(&trans, CREATE, BOOKMARKS, id_factory.root(), "zombie"); 1469 MutableEntry zombie(&trans, CREATE, id_factory.root(), "zombie");
1472 zombie.Put(ID, zombie_id); 1470 zombie.Put(ID, zombie_id);
1473 zombie.Put(IS_DEL, true); 1471 zombie.Put(IS_DEL, true);
1474 zombie.Put(IS_UNSYNCED, true); 1472 zombie.Put(IS_UNSYNCED, true);
1475 } 1473 }
1476 1474
1477 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir()); 1475 ASSERT_EQ(OPENED, SimulateSaveAndReloadDir());
1478 1476
1479 { 1477 {
1480 ReadTransaction trans(FROM_HERE, dir_.get()); 1478 ReadTransaction trans(FROM_HERE, dir_.get());
1481 1479
(...skipping 15 matching lines...) Expand all
1497 TEST_F(SyncableDirectoryTest, OrdinalWithNullSurvivesSaveAndReload) { 1495 TEST_F(SyncableDirectoryTest, OrdinalWithNullSurvivesSaveAndReload) {
1498 TestIdFactory id_factory; 1496 TestIdFactory id_factory;
1499 Id null_child_id; 1497 Id null_child_id;
1500 const char null_cstr[] = "\0null\0test"; 1498 const char null_cstr[] = "\0null\0test";
1501 std::string null_str(null_cstr, arraysize(null_cstr) - 1); 1499 std::string null_str(null_cstr, arraysize(null_cstr) - 1);
1502 NodeOrdinal null_ord = NodeOrdinal(null_str); 1500 NodeOrdinal null_ord = NodeOrdinal(null_str);
1503 1501
1504 { 1502 {
1505 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1503 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1506 1504
1507 MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); 1505 MutableEntry parent(&trans, CREATE, id_factory.root(), "parent");
1508 parent.Put(IS_DIR, true); 1506 parent.Put(IS_DIR, true);
1509 parent.Put(IS_UNSYNCED, true); 1507 parent.Put(IS_UNSYNCED, true);
1510 1508
1511 MutableEntry child(&trans, CREATE, BOOKMARKS, parent.Get(ID), "child"); 1509 MutableEntry child(&trans, CREATE, parent.Get(ID), "child");
1512 child.Put(IS_UNSYNCED, true); 1510 child.Put(IS_UNSYNCED, true);
1513 child.Put(SERVER_ORDINAL_IN_PARENT, null_ord); 1511 child.Put(SERVER_ORDINAL_IN_PARENT, null_ord);
1514 1512
1515 null_child_id = child.Get(ID); 1513 null_child_id = child.Get(ID);
1516 } 1514 }
1517 1515
1518 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir()); 1516 EXPECT_EQ(OPENED, SimulateSaveAndReloadDir());
1519 1517
1520 { 1518 {
1521 ReadTransaction trans(FROM_HERE, dir_.get()); 1519 ReadTransaction trans(FROM_HERE, dir_.get());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1683 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1686 1684
1687 // Make it look like these types have completed initial sync. 1685 // Make it look like these types have completed initial sync.
1688 CreateTypeRoot(&trans, dir_.get(), BOOKMARKS); 1686 CreateTypeRoot(&trans, dir_.get(), BOOKMARKS);
1689 CreateTypeRoot(&trans, dir_.get(), PREFERENCES); 1687 CreateTypeRoot(&trans, dir_.get(), PREFERENCES);
1690 CreateTypeRoot(&trans, dir_.get(), AUTOFILL); 1688 CreateTypeRoot(&trans, dir_.get(), AUTOFILL);
1691 1689
1692 // Add more nodes for this type. Technically, they should be placed under 1690 // Add more nodes for this type. Technically, they should be placed under
1693 // the proper type root nodes but the assertions in this test won't notice 1691 // the proper type root nodes but the assertions in this test won't notice
1694 // if their parent isn't quite right. 1692 // if their parent isn't quite right.
1695 MutableEntry item1(&trans, CREATE, BOOKMARKS, trans.root_id(), "Item"); 1693 MutableEntry item1(&trans, CREATE, trans.root_id(), "Item");
1696 ASSERT_TRUE(item1.good()); 1694 ASSERT_TRUE(item1.good());
1695 item1.Put(SPECIFICS, bookmark_specs);
1697 item1.Put(SERVER_SPECIFICS, bookmark_specs); 1696 item1.Put(SERVER_SPECIFICS, bookmark_specs);
1698 item1.Put(IS_UNSYNCED, true); 1697 item1.Put(IS_UNSYNCED, true);
1699 1698
1700 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM, 1699 MutableEntry item2(&trans, CREATE_NEW_UPDATE_ITEM,
1701 id_factory.NewServerId()); 1700 id_factory.NewServerId());
1702 ASSERT_TRUE(item2.good()); 1701 ASSERT_TRUE(item2.good());
1703 item2.Put(SERVER_SPECIFICS, bookmark_specs); 1702 item2.Put(SERVER_SPECIFICS, bookmark_specs);
1704 item2.Put(IS_UNAPPLIED_UPDATE, true); 1703 item2.Put(IS_UNAPPLIED_UPDATE, true);
1705 1704
1706 MutableEntry item3(&trans, CREATE, PREFERENCES, 1705 MutableEntry item3(&trans, CREATE, trans.root_id(), "Item");
1707 trans.root_id(), "Item");
1708 ASSERT_TRUE(item3.good()); 1706 ASSERT_TRUE(item3.good());
1709 item3.Put(SPECIFICS, preference_specs); 1707 item3.Put(SPECIFICS, preference_specs);
1710 item3.Put(SERVER_SPECIFICS, preference_specs); 1708 item3.Put(SERVER_SPECIFICS, preference_specs);
1711 item3.Put(IS_UNSYNCED, true); 1709 item3.Put(IS_UNSYNCED, true);
1712 1710
1713 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM, 1711 MutableEntry item4(&trans, CREATE_NEW_UPDATE_ITEM,
1714 id_factory.NewServerId()); 1712 id_factory.NewServerId());
1715 ASSERT_TRUE(item4.good()); 1713 ASSERT_TRUE(item4.good());
1716 item4.Put(SERVER_SPECIFICS, preference_specs); 1714 item4.Put(SERVER_SPECIFICS, preference_specs);
1717 item4.Put(IS_UNAPPLIED_UPDATE, true); 1715 item4.Put(IS_UNAPPLIED_UPDATE, true);
1718 1716
1719 MutableEntry item5(&trans, CREATE, AUTOFILL, 1717 MutableEntry item5(&trans, CREATE, trans.root_id(), "Item");
1720 trans.root_id(), "Item");
1721 ASSERT_TRUE(item5.good()); 1718 ASSERT_TRUE(item5.good());
1722 item5.Put(SPECIFICS, autofill_specs); 1719 item5.Put(SPECIFICS, autofill_specs);
1723 item5.Put(SERVER_SPECIFICS, autofill_specs); 1720 item5.Put(SERVER_SPECIFICS, autofill_specs);
1724 item5.Put(IS_UNSYNCED, true); 1721 item5.Put(IS_UNSYNCED, true);
1725 1722
1726 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM, 1723 MutableEntry item6(&trans, CREATE_NEW_UPDATE_ITEM,
1727 id_factory.NewServerId()); 1724 id_factory.NewServerId());
1728 ASSERT_TRUE(item6.good()); 1725 ASSERT_TRUE(item6.good());
1729 item6.Put(SERVER_SPECIFICS, autofill_specs); 1726 item6.Put(SERVER_SPECIFICS, autofill_specs);
1730 item6.Put(IS_UNAPPLIED_UPDATE, true); 1727 item6.Put(IS_UNAPPLIED_UPDATE, true);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 TEST_F(OnDiskSyncableDirectoryTest, 1784 TEST_F(OnDiskSyncableDirectoryTest,
1788 TestSimpleFieldsPreservedDuringSaveChanges) { 1785 TestSimpleFieldsPreservedDuringSaveChanges) {
1789 Id update_id = TestIdFactory::FromNumber(1); 1786 Id update_id = TestIdFactory::FromNumber(1);
1790 Id create_id; 1787 Id create_id;
1791 EntryKernel create_pre_save, update_pre_save; 1788 EntryKernel create_pre_save, update_pre_save;
1792 EntryKernel create_post_save, update_post_save; 1789 EntryKernel create_post_save, update_post_save;
1793 std::string create_name = "Create"; 1790 std::string create_name = "Create";
1794 1791
1795 { 1792 {
1796 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1793 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1797 MutableEntry create( 1794 MutableEntry create(&trans, CREATE, trans.root_id(), create_name);
1798 &trans, CREATE, BOOKMARKS, trans.root_id(), create_name);
1799 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id); 1795 MutableEntry update(&trans, CREATE_NEW_UPDATE_ITEM, update_id);
1800 create.Put(IS_UNSYNCED, true); 1796 create.Put(IS_UNSYNCED, true);
1801 update.Put(IS_UNAPPLIED_UPDATE, true); 1797 update.Put(IS_UNAPPLIED_UPDATE, true);
1802 sync_pb::EntitySpecifics specifics; 1798 sync_pb::EntitySpecifics specifics;
1803 specifics.mutable_bookmark()->set_favicon("PNG"); 1799 specifics.mutable_bookmark()->set_favicon("PNG");
1804 specifics.mutable_bookmark()->set_url("http://nowhere"); 1800 specifics.mutable_bookmark()->set_url("http://nowhere");
1805 create.Put(SPECIFICS, specifics); 1801 create.Put(SPECIFICS, specifics);
1806 update.Put(SPECIFICS, specifics); 1802 update.Put(SPECIFICS, specifics);
1807 create_pre_save = create.GetKernelCopy(); 1803 create_pre_save = create.GetKernelCopy();
1808 update_pre_save = update.GetKernelCopy(); 1804 update_pre_save = update.GetKernelCopy();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 << "Blob field #" << i << " changed during save/load"; 1884 << "Blob field #" << i << " changed during save/load";
1889 } 1885 }
1890 } 1886 }
1891 1887
1892 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) { 1888 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailure) {
1893 int64 handle1 = 0; 1889 int64 handle1 = 0;
1894 // Set up an item using a regular, saveable directory. 1890 // Set up an item using a regular, saveable directory.
1895 { 1891 {
1896 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1892 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1897 1893
1898 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "aguilera"); 1894 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera");
1899 ASSERT_TRUE(e1.good()); 1895 ASSERT_TRUE(e1.good());
1900 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1896 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1901 handle1 = e1.Get(META_HANDLE); 1897 handle1 = e1.Get(META_HANDLE);
1902 e1.Put(BASE_VERSION, 1); 1898 e1.Put(BASE_VERSION, 1);
1903 e1.Put(IS_DIR, true); 1899 e1.Put(IS_DIR, true);
1904 e1.Put(ID, TestIdFactory::FromNumber(101)); 1900 e1.Put(ID, TestIdFactory::FromNumber(101));
1905 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1901 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1906 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1902 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1907 } 1903 }
1908 ASSERT_TRUE(dir_->SaveChanges()); 1904 ASSERT_TRUE(dir_->SaveChanges());
(...skipping 25 matching lines...) Expand all
1934 ASSERT_TRUE(aguilera.good()); 1930 ASSERT_TRUE(aguilera.good());
1935 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 1931 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
1936 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "overwritten"); 1932 EXPECT_EQ(aguilera.Get(NON_UNIQUE_NAME), "overwritten");
1937 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty()); 1933 EXPECT_FALSE(aguilera.GetKernelCopy().is_dirty());
1938 EXPECT_FALSE(IsInDirtyMetahandles(handle1)); 1934 EXPECT_FALSE(IsInDirtyMetahandles(handle1));
1939 aguilera.Put(NON_UNIQUE_NAME, "christina"); 1935 aguilera.Put(NON_UNIQUE_NAME, "christina");
1940 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty()); 1936 EXPECT_TRUE(aguilera.GetKernelCopy().is_dirty());
1941 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1937 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1942 1938
1943 // New item. 1939 // New item.
1944 MutableEntry kids_on_block( 1940 MutableEntry kids_on_block(&trans, CREATE, trans.root_id(), "kids");
1945 &trans, CREATE, BOOKMARKS, trans.root_id(), "kids");
1946 ASSERT_TRUE(kids_on_block.good()); 1941 ASSERT_TRUE(kids_on_block.good());
1947 handle2 = kids_on_block.Get(META_HANDLE); 1942 handle2 = kids_on_block.Get(META_HANDLE);
1948 kids_on_block.Put(BASE_VERSION, 1); 1943 kids_on_block.Put(BASE_VERSION, 1);
1949 kids_on_block.Put(IS_DIR, true); 1944 kids_on_block.Put(IS_DIR, true);
1950 kids_on_block.Put(ID, TestIdFactory::FromNumber(102)); 1945 kids_on_block.Put(ID, TestIdFactory::FromNumber(102));
1951 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty()); 1946 EXPECT_TRUE(kids_on_block.GetKernelCopy().is_dirty());
1952 EXPECT_TRUE(IsInDirtyMetahandles(handle2)); 1947 EXPECT_TRUE(IsInDirtyMetahandles(handle2));
1953 } 1948 }
1954 1949
1955 // We are using an unsaveable directory, so this can't succeed. However, 1950 // We are using an unsaveable directory, so this can't succeed. However,
(...skipping 14 matching lines...) Expand all
1970 EXPECT_TRUE(IsInDirtyMetahandles(handle1)); 1965 EXPECT_TRUE(IsInDirtyMetahandles(handle1));
1971 } 1966 }
1972 } 1967 }
1973 1968
1974 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailureWithPurge) { 1969 TEST_F(OnDiskSyncableDirectoryTest, TestSaveChangesFailureWithPurge) {
1975 int64 handle1 = 0; 1970 int64 handle1 = 0;
1976 // Set up an item using a regular, saveable directory. 1971 // Set up an item using a regular, saveable directory.
1977 { 1972 {
1978 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get()); 1973 WriteTransaction trans(FROM_HERE, UNITTEST, dir_.get());
1979 1974
1980 MutableEntry e1(&trans, CREATE, BOOKMARKS, trans.root_id(), "aguilera"); 1975 MutableEntry e1(&trans, CREATE, trans.root_id(), "aguilera");
1981 ASSERT_TRUE(e1.good()); 1976 ASSERT_TRUE(e1.good());
1982 EXPECT_TRUE(e1.GetKernelCopy().is_dirty()); 1977 EXPECT_TRUE(e1.GetKernelCopy().is_dirty());
1983 handle1 = e1.Get(META_HANDLE); 1978 handle1 = e1.Get(META_HANDLE);
1984 e1.Put(BASE_VERSION, 1); 1979 e1.Put(BASE_VERSION, 1);
1985 e1.Put(IS_DIR, true); 1980 e1.Put(IS_DIR, true);
1986 e1.Put(ID, TestIdFactory::FromNumber(101)); 1981 e1.Put(ID, TestIdFactory::FromNumber(101));
1987 sync_pb::EntitySpecifics bookmark_specs; 1982 sync_pb::EntitySpecifics bookmark_specs;
1988 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs); 1983 AddDefaultFieldValue(BOOKMARKS, &bookmark_specs);
1989 e1.Put(SPECIFICS, bookmark_specs); 1984 e1.Put(SPECIFICS, bookmark_specs);
1990 e1.Put(SERVER_SPECIFICS, bookmark_specs); 1985 e1.Put(SERVER_SPECIFICS, bookmark_specs);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 if (rand_action < 4 && !path_name.empty()) { 2109 if (rand_action < 4 && !path_name.empty()) {
2115 ReadTransaction trans(FROM_HERE, dir_); 2110 ReadTransaction trans(FROM_HERE, dir_);
2116 CHECK(1 == CountEntriesWithName(&trans, trans.root_id(), path_name)); 2111 CHECK(1 == CountEntriesWithName(&trans, trans.root_id(), path_name));
2117 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 2112 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
2118 rand() % 10)); 2113 rand() % 10));
2119 } else { 2114 } else {
2120 std::string unique_name = 2115 std::string unique_name =
2121 base::StringPrintf("%d.%d", thread_number_, entry_count++); 2116 base::StringPrintf("%d.%d", thread_number_, entry_count++);
2122 path_name.assign(unique_name.begin(), unique_name.end()); 2117 path_name.assign(unique_name.begin(), unique_name.end());
2123 WriteTransaction trans(FROM_HERE, UNITTEST, dir_); 2118 WriteTransaction trans(FROM_HERE, UNITTEST, dir_);
2124 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), path_name); 2119 MutableEntry e(&trans, CREATE, trans.root_id(), path_name);
2125 CHECK(e.good()); 2120 CHECK(e.good());
2126 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds( 2121 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
2127 rand() % 20)); 2122 rand() % 20));
2128 e.Put(IS_UNSYNCED, true); 2123 e.Put(IS_UNSYNCED, true);
2129 if (e.Put(ID, TestIdFactory::FromNumber(rand())) && 2124 if (e.Put(ID, TestIdFactory::FromNumber(rand())) &&
2130 e.Get(ID).ServerKnows() && !e.Get(ID).IsRoot()) { 2125 e.Get(ID).ServerKnows() && !e.Get(ID).IsRoot()) {
2131 e.Put(BASE_VERSION, 1); 2126 e.Put(BASE_VERSION, 1);
2132 } 2127 }
2133 } 2128 }
2134 } 2129 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 2166
2172 class SyncableClientTagTest : public SyncableDirectoryTest { 2167 class SyncableClientTagTest : public SyncableDirectoryTest {
2173 public: 2168 public:
2174 static const int kBaseVersion = 1; 2169 static const int kBaseVersion = 1;
2175 const char* test_name_; 2170 const char* test_name_;
2176 const char* test_tag_; 2171 const char* test_tag_;
2177 2172
2178 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {} 2173 SyncableClientTagTest() : test_name_("test_name"), test_tag_("dietcoke") {}
2179 2174
2180 bool CreateWithDefaultTag(Id id, bool deleted) { 2175 bool CreateWithDefaultTag(Id id, bool deleted) {
2176 return CreateWithTag(test_tag_, id, deleted);
2177 }
2178
2179 // Attempt to create an entry with a default tag.
2180 bool CreateWithTag(const char* tag, Id id, bool deleted) {
2181 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); 2181 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get());
2182 MutableEntry me(&wtrans, CREATE, PREFERENCES, 2182 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), test_name_);
2183 wtrans.root_id(), test_name_);
2184 CHECK(me.good()); 2183 CHECK(me.good());
2185 me.Put(ID, id); 2184 me.Put(ID, id);
2186 if (id.ServerKnows()) { 2185 if (id.ServerKnows()) {
2187 me.Put(BASE_VERSION, kBaseVersion); 2186 me.Put(BASE_VERSION, kBaseVersion);
2188 } 2187 }
2189 me.Put(IS_UNSYNCED, true); 2188 me.Put(IS_UNSYNCED, true);
2190 me.Put(IS_DEL, deleted); 2189 me.Put(IS_DEL, deleted);
2191 me.Put(IS_DIR, false); 2190 me.Put(IS_DIR, false);
2192 return me.Put(UNIQUE_CLIENT_TAG, test_tag_); 2191 return me.Put(UNIQUE_CLIENT_TAG, tag);
2193 } 2192 }
2194 2193
2195 // Verify an entry exists with the default tag. 2194 // Verify an entry exists with the default tag.
2196 void VerifyTag(Id id, bool deleted) { 2195 void VerifyTag(Id id, bool deleted) {
2197 // Should still be present and valid in the client tag index. 2196 // Should still be present and valid in the client tag index.
2198 ReadTransaction trans(FROM_HERE, dir_.get()); 2197 ReadTransaction trans(FROM_HERE, dir_.get());
2199 Entry me(&trans, GET_BY_CLIENT_TAG, test_tag_); 2198 Entry me(&trans, GET_BY_CLIENT_TAG, test_tag_);
2200 CHECK(me.good()); 2199 CHECK(me.good());
2201 EXPECT_EQ(me.Get(ID), id); 2200 EXPECT_EQ(me.Get(ID), id);
2202 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), test_tag_); 2201 EXPECT_EQ(me.Get(UNIQUE_CLIENT_TAG), test_tag_);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2260 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 2259 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
2261 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 2260 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
2262 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 2261 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
2263 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 2262 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
2264 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 2263 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
2265 } 2264 }
2266 2265
2267 } // namespace 2266 } // namespace
2268 } // namespace syncable 2267 } // namespace syncable
2269 } // namespace syncer 2268 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/mutable_entry.cc ('k') | sync/test/engine/test_syncable_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698