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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 1144443004: Revert of [Sync] Refactoring polling to be reliable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « sync/engine/syncer.cc ('k') | sync/internal_api/js_sync_manager_observer_unittest.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 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 void OnActionableError(const SyncProtocolError& error) override {} 250 void OnActionableError(const SyncProtocolError& error) override {}
251 void OnRetryTimeChanged(base::Time retry_time) override {} 251 void OnRetryTimeChanged(base::Time retry_time) override {}
252 void OnThrottledTypesChanged(ModelTypeSet throttled_types) override {} 252 void OnThrottledTypesChanged(ModelTypeSet throttled_types) override {}
253 void OnMigrationRequested(ModelTypeSet types) override {} 253 void OnMigrationRequested(ModelTypeSet types) override {}
254 254
255 void ResetSession() { 255 void ResetSession() {
256 session_.reset(SyncSession::Build(context_.get(), this)); 256 session_.reset(SyncSession::Build(context_.get(), this));
257 } 257 }
258 258
259 bool SyncShareNudge() { 259 void SyncShareNudge() {
260 ResetSession(); 260 ResetSession();
261 261
262 // Pretend we've seen a local change, to make the nudge_tracker look normal. 262 // Pretend we've seen a local change, to make the nudge_tracker look normal.
263 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 263 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
264 264
265 return syncer_->NormalSyncShare(context_->GetEnabledTypes(), 265 EXPECT_TRUE(syncer_->NormalSyncShare(context_->GetEnabledTypes(),
266 &nudge_tracker_, session_.get()); 266 &nudge_tracker_, session_.get()));
267 } 267 }
268 268
269 bool SyncShareConfigure() { 269 void SyncShareConfigure() {
270 ResetSession(); 270 ResetSession();
271 return syncer_->ConfigureSyncShare( 271 EXPECT_TRUE(syncer_->ConfigureSyncShare(
272 context_->GetEnabledTypes(), 272 context_->GetEnabledTypes(),
273 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, 273 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
274 session_.get()); 274 session_.get()));
275 } 275 }
276 276
277 void SetUp() override { 277 void SetUp() override {
278 dir_maker_.SetUp(); 278 dir_maker_.SetUp();
279 mock_server_.reset(new MockConnectionManager(directory(), 279 mock_server_.reset(new MockConnectionManager(directory(),
280 &cancelation_signal_)); 280 &cancelation_signal_));
281 debug_info_getter_.reset(new MockDebugInfoGetter); 281 debug_info_getter_.reset(new MockDebugInfoGetter);
282 EnableDatatype(BOOKMARKS); 282 EnableDatatype(BOOKMARKS);
283 EnableDatatype(NIGORI); 283 EnableDatatype(NIGORI);
284 EnableDatatype(PREFERENCES); 284 EnableDatatype(PREFERENCES);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 case MOVED_FROM_ROOT: 462 case MOVED_FROM_ROOT:
463 entry.PutServerParentId(trans.root_id()); 463 entry.PutServerParentId(trans.root_id());
464 break; 464 break;
465 default: 465 default:
466 FAIL() << "Bad value in CommitOrderingTest list"; 466 FAIL() << "Bad value in CommitOrderingTest list";
467 } 467 }
468 } 468 }
469 test++; 469 test++;
470 } 470 }
471 } 471 }
472 EXPECT_TRUE(SyncShareNudge()); 472 SyncShareNudge();
473 ASSERT_TRUE(expected_positions.size() == 473 ASSERT_TRUE(expected_positions.size() ==
474 mock_server_->committed_ids().size()); 474 mock_server_->committed_ids().size());
475 // If this test starts failing, be aware other sort orders could be valid. 475 // If this test starts failing, be aware other sort orders could be valid.
476 for (size_t i = 0; i < expected_positions.size(); ++i) { 476 for (size_t i = 0; i < expected_positions.size(); ++i) {
477 SCOPED_TRACE(i); 477 SCOPED_TRACE(i);
478 EXPECT_EQ(1u, expected_positions.count(i)); 478 EXPECT_EQ(1u, expected_positions.count(i));
479 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]); 479 EXPECT_EQ(expected_positions[i], mock_server_->committed_ids()[i]);
480 } 480 }
481 } 481 }
482 482
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 // regression for a very old bug. 621 // regression for a very old bug.
622 } 622 }
623 623
624 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { 624 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
625 const ModelTypeSet throttled_types(BOOKMARKS); 625 const ModelTypeSet throttled_types(BOOKMARKS);
626 sync_pb::EntitySpecifics bookmark_data; 626 sync_pb::EntitySpecifics bookmark_data;
627 AddDefaultFieldValue(BOOKMARKS, &bookmark_data); 627 AddDefaultFieldValue(BOOKMARKS, &bookmark_data);
628 628
629 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 629 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
630 foreign_cache_guid(), "-1"); 630 foreign_cache_guid(), "-1");
631 EXPECT_TRUE(SyncShareNudge()); 631 SyncShareNudge();
632 632
633 { 633 {
634 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 634 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
635 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 635 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
636 ASSERT_TRUE(A.good()); 636 ASSERT_TRUE(A.good());
637 A.PutIsUnsynced(true); 637 A.PutIsUnsynced(true);
638 A.PutSpecifics(bookmark_data); 638 A.PutSpecifics(bookmark_data);
639 A.PutNonUniqueName("bookmark"); 639 A.PutNonUniqueName("bookmark");
640 } 640 }
641 641
642 // Now sync without enabling bookmarks. 642 // Now sync without enabling bookmarks.
643 mock_server_->ExpectGetUpdatesRequestTypes( 643 mock_server_->ExpectGetUpdatesRequestTypes(
644 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); 644 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)));
645 ResetSession(); 645 ResetSession();
646 syncer_->NormalSyncShare( 646 syncer_->NormalSyncShare(
647 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), 647 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)),
648 &nudge_tracker_, session_.get()); 648 &nudge_tracker_, session_.get());
649 649
650 { 650 {
651 // Nothing should have been committed as bookmarks is throttled. 651 // Nothing should have been committed as bookmarks is throttled.
652 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 652 syncable::ReadTransaction rtrans(FROM_HERE, directory());
653 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 653 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
654 ASSERT_TRUE(entryA.good()); 654 ASSERT_TRUE(entryA.good());
655 EXPECT_TRUE(entryA.GetIsUnsynced()); 655 EXPECT_TRUE(entryA.GetIsUnsynced());
656 } 656 }
657 657
658 // Sync again with bookmarks enabled. 658 // Sync again with bookmarks enabled.
659 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes()); 659 mock_server_->ExpectGetUpdatesRequestTypes(context_->GetEnabledTypes());
660 EXPECT_TRUE(SyncShareNudge()); 660 SyncShareNudge();
661 { 661 {
662 // It should have been committed. 662 // It should have been committed.
663 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 663 syncable::ReadTransaction rtrans(FROM_HERE, directory());
664 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 664 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
665 ASSERT_TRUE(entryA.good()); 665 ASSERT_TRUE(entryA.good());
666 EXPECT_FALSE(entryA.GetIsUnsynced()); 666 EXPECT_FALSE(entryA.GetIsUnsynced());
667 } 667 }
668 } 668 }
669 669
670 // We use a macro so we can preserve the error location. 670 // We use a macro so we can preserve the error location.
(...skipping 23 matching lines...) Expand all
694 bookmark.mutable_bookmark()->set_title("title"); 694 bookmark.mutable_bookmark()->set_title("title");
695 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark); 695 AddDefaultFieldValue(BOOKMARKS, &encrypted_bookmark);
696 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 696 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
697 foreign_cache_guid(), "-1"); 697 foreign_cache_guid(), "-1");
698 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, 698 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10,
699 foreign_cache_guid(), "-2"); 699 foreign_cache_guid(), "-2");
700 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10, 700 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10,
701 foreign_cache_guid(), "-3"); 701 foreign_cache_guid(), "-3");
702 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10, 702 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10,
703 foreign_cache_guid(), "-4"); 703 foreign_cache_guid(), "-4");
704 EXPECT_TRUE(SyncShareNudge()); 704 SyncShareNudge();
705 // Server side change will put A in conflict. 705 // Server side change will put A in conflict.
706 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20, 706 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20,
707 foreign_cache_guid(), "-1"); 707 foreign_cache_guid(), "-1");
708 { 708 {
709 // Mark bookmarks as encrypted and set the cryptographer to have pending 709 // Mark bookmarks as encrypted and set the cryptographer to have pending
710 // keys. 710 // keys.
711 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 711 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
712 Cryptographer other_cryptographer(&encryptor_); 712 Cryptographer other_cryptographer(&encryptor_);
713 other_cryptographer.AddKey(other_params); 713 other_cryptographer.AddKey(other_params);
714 sync_pb::EntitySpecifics specifics; 714 sync_pb::EntitySpecifics specifics;
(...skipping 23 matching lines...) Expand all
738 ASSERT_TRUE(C.good()); 738 ASSERT_TRUE(C.good());
739 C.PutIsUnsynced(true); 739 C.PutIsUnsynced(true);
740 C.PutNonUniqueName(kEncryptedString); 740 C.PutNonUniqueName(kEncryptedString);
741 // Unencrypted non_unique_name. 741 // Unencrypted non_unique_name.
742 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 742 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
743 ASSERT_TRUE(D.good()); 743 ASSERT_TRUE(D.good());
744 D.PutIsUnsynced(true); 744 D.PutIsUnsynced(true);
745 D.PutSpecifics(encrypted_bookmark); 745 D.PutSpecifics(encrypted_bookmark);
746 D.PutNonUniqueName("not encrypted"); 746 D.PutNonUniqueName("not encrypted");
747 } 747 }
748 EXPECT_TRUE(SyncShareNudge()); 748 SyncShareNudge();
749 { 749 {
750 // Nothing should have commited due to bookmarks being encrypted and 750 // Nothing should have commited due to bookmarks being encrypted and
751 // the cryptographer having pending keys. A would have been resolved 751 // the cryptographer having pending keys. A would have been resolved
752 // as a simple conflict, but still be unsynced until the next sync cycle. 752 // as a simple conflict, but still be unsynced until the next sync cycle.
753 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 753 syncable::ReadTransaction rtrans(FROM_HERE, directory());
754 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); 754 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans);
755 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); 755 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans);
756 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 756 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
757 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 757 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
758 758
759 // Resolve the pending keys. 759 // Resolve the pending keys.
760 GetCryptographer(&rtrans)->DecryptPendingKeys(other_params); 760 GetCryptographer(&rtrans)->DecryptPendingKeys(other_params);
761 } 761 }
762 EXPECT_TRUE(SyncShareNudge()); 762 SyncShareNudge();
763 { 763 {
764 // All properly encrypted and non-conflicting items should commit. "A" was 764 // All properly encrypted and non-conflicting items should commit. "A" was
765 // conflicting, but last sync cycle resolved it as simple conflict, so on 765 // conflicting, but last sync cycle resolved it as simple conflict, so on
766 // this sync cycle it committed succesfullly. 766 // this sync cycle it committed succesfullly.
767 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 767 syncable::ReadTransaction rtrans(FROM_HERE, directory());
768 // Committed successfully. 768 // Committed successfully.
769 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 769 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
770 // Committed successfully. 770 // Committed successfully.
771 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 771 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
772 // Was not properly encrypted. 772 // Was not properly encrypted.
773 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 773 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
774 // Was not properly encrypted. 774 // Was not properly encrypted.
775 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 775 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
776 } 776 }
777 { 777 {
778 // Fix the remaining items. 778 // Fix the remaining items.
779 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 779 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
780 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 780 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
781 ASSERT_TRUE(C.good()); 781 ASSERT_TRUE(C.good());
782 C.PutSpecifics(encrypted_bookmark); 782 C.PutSpecifics(encrypted_bookmark);
783 C.PutNonUniqueName(kEncryptedString); 783 C.PutNonUniqueName(kEncryptedString);
784 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 784 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
785 ASSERT_TRUE(D.good()); 785 ASSERT_TRUE(D.good());
786 D.PutSpecifics(encrypted_bookmark); 786 D.PutSpecifics(encrypted_bookmark);
787 D.PutNonUniqueName(kEncryptedString); 787 D.PutNonUniqueName(kEncryptedString);
788 } 788 }
789 EXPECT_TRUE(SyncShareNudge()); 789 SyncShareNudge();
790 { 790 {
791 const StatusController& status_controller = session_->status_controller(); 791 const StatusController& status_controller = session_->status_controller();
792 // Expect success. 792 // Expect success.
793 EXPECT_EQ(status_controller.model_neutral_state().commit_result, SYNCER_OK); 793 EXPECT_EQ(status_controller.model_neutral_state().commit_result, SYNCER_OK);
794 // None should be unsynced anymore. 794 // None should be unsynced anymore.
795 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 795 syncable::ReadTransaction rtrans(FROM_HERE, directory());
796 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 796 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
797 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 797 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
798 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); 798 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans);
799 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); 799 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans);
800 } 800 }
801 } 801 }
802 802
803 TEST_F(SyncerTest, GetUpdatesPartialThrottled) { 803 TEST_F(SyncerTest, GetUpdatesPartialThrottled) {
804 sync_pb::EntitySpecifics bookmark, pref; 804 sync_pb::EntitySpecifics bookmark, pref;
805 bookmark.mutable_bookmark()->set_title("title"); 805 bookmark.mutable_bookmark()->set_title("title");
806 pref.mutable_preference()->set_name("name"); 806 pref.mutable_preference()->set_name("name");
807 AddDefaultFieldValue(BOOKMARKS, &bookmark); 807 AddDefaultFieldValue(BOOKMARKS, &bookmark);
808 AddDefaultFieldValue(PREFERENCES, &pref); 808 AddDefaultFieldValue(PREFERENCES, &pref);
809 809
810 // Normal sync, all the data types should get synced. 810 // Normal sync, all the data types should get synced.
811 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark, 811 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark,
812 foreign_cache_guid(), "-1"); 812 foreign_cache_guid(), "-1");
813 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark, 813 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark,
814 foreign_cache_guid(), "-2"); 814 foreign_cache_guid(), "-2");
815 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark, 815 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark,
816 foreign_cache_guid(), "-3"); 816 foreign_cache_guid(), "-3");
817 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 817 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
818 818
819 EXPECT_TRUE(SyncShareNudge()); 819 SyncShareNudge();
820 { 820 {
821 // Initial state. Everything is normal. 821 // Initial state. Everything is normal.
822 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 822 syncable::ReadTransaction rtrans(FROM_HERE, directory());
823 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 823 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
824 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 824 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
825 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 825 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
826 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 826 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
827 } 827 }
828 828
829 // Set BOOKMARKS throttled but PREFERENCES not, 829 // Set BOOKMARKS throttled but PREFERENCES not,
(...skipping 13 matching lines...) Expand all
843 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 843 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
844 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 844 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
845 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 845 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
846 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 846 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
847 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 847 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
848 A.PutIsUnsynced(true); 848 A.PutIsUnsynced(true);
849 B.PutIsUnsynced(true); 849 B.PutIsUnsynced(true);
850 C.PutIsUnsynced(true); 850 C.PutIsUnsynced(true);
851 D.PutIsUnsynced(true); 851 D.PutIsUnsynced(true);
852 } 852 }
853 EXPECT_TRUE(SyncShareNudge()); 853 SyncShareNudge();
854 { 854 {
855 // BOOKMARKS throttled. 855 // BOOKMARKS throttled.
856 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 856 syncable::ReadTransaction rtrans(FROM_HERE, directory());
857 VERIFY_ENTRY(1, false, true, false, 0, 10, 10, ids_, &rtrans); 857 VERIFY_ENTRY(1, false, true, false, 0, 10, 10, ids_, &rtrans);
858 VERIFY_ENTRY(2, false, true, false, 1, 10, 10, ids_, &rtrans); 858 VERIFY_ENTRY(2, false, true, false, 1, 10, 10, ids_, &rtrans);
859 VERIFY_ENTRY(3, false, true, false, 1, 10, 10, ids_, &rtrans); 859 VERIFY_ENTRY(3, false, true, false, 1, 10, 10, ids_, &rtrans);
860 VERIFY_ENTRY(4, false, false, false, 0, 21, 21, ids_, &rtrans); 860 VERIFY_ENTRY(4, false, false, false, 0, 21, 21, ids_, &rtrans);
861 } 861 }
862 862
863 // Unthrottled BOOKMARKS, then BOOKMARKS should get synced now. 863 // Unthrottled BOOKMARKS, then BOOKMARKS should get synced now.
864 mock_server_->set_partial_throttling(false); 864 mock_server_->set_partial_throttling(false);
865 865
866 mock_server_->AddUpdateSpecifics(1, 0, "E", 30, 30, true, 0, bookmark, 866 mock_server_->AddUpdateSpecifics(1, 0, "E", 30, 30, true, 0, bookmark,
867 foreign_cache_guid(), "-1"); 867 foreign_cache_guid(), "-1");
868 mock_server_->AddUpdateSpecifics(2, 1, "F", 30, 30, false, 2, bookmark, 868 mock_server_->AddUpdateSpecifics(2, 1, "F", 30, 30, false, 2, bookmark,
869 foreign_cache_guid(), "-2"); 869 foreign_cache_guid(), "-2");
870 mock_server_->AddUpdateSpecifics(3, 1, "G", 30, 30, false, 1, bookmark, 870 mock_server_->AddUpdateSpecifics(3, 1, "G", 30, 30, false, 1, bookmark,
871 foreign_cache_guid(), "-3"); 871 foreign_cache_guid(), "-3");
872 mock_server_->AddUpdateSpecifics(4, 0, "H", 30, 30, false, 0, pref); 872 mock_server_->AddUpdateSpecifics(4, 0, "H", 30, 30, false, 0, pref);
873 EXPECT_TRUE(SyncShareNudge()); 873 SyncShareNudge();
874 { 874 {
875 // BOOKMARKS unthrottled. 875 // BOOKMARKS unthrottled.
876 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 876 syncable::ReadTransaction rtrans(FROM_HERE, directory());
877 VERIFY_ENTRY(1, false, false, false, 0, 31, 31, ids_, &rtrans); 877 VERIFY_ENTRY(1, false, false, false, 0, 31, 31, ids_, &rtrans);
878 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 878 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
879 VERIFY_ENTRY(3, false, false, false, 1, 31, 31, ids_, &rtrans); 879 VERIFY_ENTRY(3, false, false, false, 1, 31, 31, ids_, &rtrans);
880 VERIFY_ENTRY(4, false, false, false, 0, 30, 30, ids_, &rtrans); 880 VERIFY_ENTRY(4, false, false, false, 0, 30, 30, ids_, &rtrans);
881 } 881 }
882 } 882 }
883 883
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 UniquePosition pos2; 1018 UniquePosition pos2;
1019 UniquePosition pos3; 1019 UniquePosition pos3;
1020 1020
1021 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark, 1021 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark,
1022 foreign_cache_guid(), "-1"); 1022 foreign_cache_guid(), "-1");
1023 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark, 1023 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark,
1024 foreign_cache_guid(), "-2"); 1024 foreign_cache_guid(), "-2");
1025 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark, 1025 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark,
1026 foreign_cache_guid(), "-3"); 1026 foreign_cache_guid(), "-3");
1027 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 1027 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
1028 EXPECT_TRUE(SyncShareNudge()); 1028 SyncShareNudge();
1029 { 1029 {
1030 // Initial state. Everything is normal. 1030 // Initial state. Everything is normal.
1031 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1031 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1032 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 1032 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
1033 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 1033 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
1034 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 1034 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
1035 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 1035 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
1036 1036
1037 Entry entry1(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 1037 Entry entry1(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
1038 ASSERT_TRUE(entry1.GetUniquePosition().Equals( 1038 ASSERT_TRUE(entry1.GetUniquePosition().Equals(
(...skipping 12 matching lines...) Expand all
1051 foreign_cache_guid(), "-1"); 1051 foreign_cache_guid(), "-1");
1052 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, 1052 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2,
1053 encrypted_bookmark, 1053 encrypted_bookmark,
1054 foreign_cache_guid(), "-2"); 1054 foreign_cache_guid(), "-2");
1055 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, 1055 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1,
1056 encrypted_bookmark, 1056 encrypted_bookmark,
1057 foreign_cache_guid(), "-3"); 1057 foreign_cache_guid(), "-3");
1058 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, 1058 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0,
1059 encrypted_pref, 1059 encrypted_pref,
1060 foreign_cache_guid(), "-4"); 1060 foreign_cache_guid(), "-4");
1061 EXPECT_TRUE(SyncShareNudge()); 1061 SyncShareNudge();
1062 { 1062 {
1063 // All should be unapplied due to being undecryptable and have a valid 1063 // All should be unapplied due to being undecryptable and have a valid
1064 // BASE_SERVER_SPECIFICS. 1064 // BASE_SERVER_SPECIFICS.
1065 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1065 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1066 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); 1066 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans);
1067 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); 1067 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans);
1068 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 1068 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
1069 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); 1069 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans);
1070 } 1070 }
1071 1071
1072 // Server side change that don't modify anything should not affect 1072 // Server side change that don't modify anything should not affect
1073 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). 1073 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes).
1074 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, 1074 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0,
1075 encrypted_bookmark, 1075 encrypted_bookmark,
1076 foreign_cache_guid(), "-1"); 1076 foreign_cache_guid(), "-1");
1077 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, 1077 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2,
1078 encrypted_bookmark, 1078 encrypted_bookmark,
1079 foreign_cache_guid(), "-2"); 1079 foreign_cache_guid(), "-2");
1080 // Item 3 doesn't change. 1080 // Item 3 doesn't change.
1081 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, 1081 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0,
1082 encrypted_pref, 1082 encrypted_pref,
1083 foreign_cache_guid(), "-4"); 1083 foreign_cache_guid(), "-4");
1084 EXPECT_TRUE(SyncShareNudge()); 1084 SyncShareNudge();
1085 { 1085 {
1086 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. 1086 // Items 1, 2, and 4 should have newer server versions, 3 remains the same.
1087 // All should remain unapplied due to be undecryptable. 1087 // All should remain unapplied due to be undecryptable.
1088 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1088 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1089 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); 1089 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans);
1090 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 1090 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
1091 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 1091 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
1092 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 1092 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
1093 } 1093 }
1094 1094
1095 // Positional changes, parent changes, and specifics changes should reset 1095 // Positional changes, parent changes, and specifics changes should reset
1096 // BASE_SERVER_SPECIFICS. 1096 // BASE_SERVER_SPECIFICS.
1097 // Became unencrypted. 1097 // Became unencrypted.
1098 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark, 1098 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark,
1099 foreign_cache_guid(), "-1"); 1099 foreign_cache_guid(), "-1");
1100 // Reordered to after item 2. 1100 // Reordered to after item 2.
1101 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, 1101 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3,
1102 encrypted_bookmark, 1102 encrypted_bookmark,
1103 foreign_cache_guid(), "-3"); 1103 foreign_cache_guid(), "-3");
1104 EXPECT_TRUE(SyncShareNudge()); 1104 SyncShareNudge();
1105 { 1105 {
1106 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. 1106 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set.
1107 // Items 1 is now unencrypted, so should have applied normally. 1107 // Items 1 is now unencrypted, so should have applied normally.
1108 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1108 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1109 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); 1109 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans);
1110 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 1110 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
1111 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); 1111 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans);
1112 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 1112 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
1113 } 1113 }
1114 1114
(...skipping 14 matching lines...) Expand all
1129 ASSERT_TRUE(C.good()); 1129 ASSERT_TRUE(C.good());
1130 C.PutSpecifics(modified_bookmark); 1130 C.PutSpecifics(modified_bookmark);
1131 C.PutNonUniqueName(kEncryptedString); 1131 C.PutNonUniqueName(kEncryptedString);
1132 C.PutIsUnsynced(true); 1132 C.PutIsUnsynced(true);
1133 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 1133 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
1134 ASSERT_TRUE(D.good()); 1134 ASSERT_TRUE(D.good());
1135 D.PutSpecifics(modified_pref); 1135 D.PutSpecifics(modified_pref);
1136 D.PutNonUniqueName(kEncryptedString); 1136 D.PutNonUniqueName(kEncryptedString);
1137 D.PutIsUnsynced(true); 1137 D.PutIsUnsynced(true);
1138 } 1138 }
1139 EXPECT_TRUE(SyncShareNudge()); 1139 SyncShareNudge();
1140 { 1140 {
1141 // Item 1 remains unsynced due to there being pending keys. 1141 // Item 1 remains unsynced due to there being pending keys.
1142 // Items 2, 3, 4 should remain unsynced since they were not up to date. 1142 // Items 2, 3, 4 should remain unsynced since they were not up to date.
1143 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1143 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1144 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); 1144 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans);
1145 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); 1145 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans);
1146 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); 1146 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans);
1147 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); 1147 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans);
1148 } 1148 }
1149 1149
1150 { 1150 {
1151 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1151 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1152 // Resolve the pending keys. 1152 // Resolve the pending keys.
1153 GetCryptographer(&rtrans)->DecryptPendingKeys(key_params); 1153 GetCryptographer(&rtrans)->DecryptPendingKeys(key_params);
1154 } 1154 }
1155 // First cycle resolves conflicts, second cycle commits changes. 1155 // First cycle resolves conflicts, second cycle commits changes.
1156 EXPECT_TRUE(SyncShareNudge()); 1156 SyncShareNudge();
1157 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_server_overwrites); 1157 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_server_overwrites);
1158 EXPECT_EQ(1, GetUpdateCounters(PREFERENCES).num_server_overwrites); 1158 EXPECT_EQ(1, GetUpdateCounters(PREFERENCES).num_server_overwrites);
1159 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_local_overwrites); 1159 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_local_overwrites);
1160 1160
1161 // We successfully commited item(s). 1161 // We successfully commited item(s).
1162 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_attempted); 1162 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_attempted);
1163 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_success); 1163 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_success);
1164 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_attempted); 1164 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_attempted);
1165 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_success); 1165 EXPECT_EQ(1, GetCommitCounters(PREFERENCES).num_commits_success);
1166 1166
1167 EXPECT_TRUE(SyncShareNudge()); 1167 SyncShareNudge();
1168 1168
1169 // Everything should be resolved now. The local changes should have 1169 // Everything should be resolved now. The local changes should have
1170 // overwritten the server changes for 2 and 4, while the server changes 1170 // overwritten the server changes for 2 and 4, while the server changes
1171 // overwrote the local for entry 3. 1171 // overwrote the local for entry 3.
1172 // 1172 //
1173 // Expect there will be no new overwrites. 1173 // Expect there will be no new overwrites.
1174 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_server_overwrites); 1174 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_server_overwrites);
1175 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_local_overwrites); 1175 EXPECT_EQ(1, GetUpdateCounters(BOOKMARKS).num_local_overwrites);
1176 1176
1177 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_success); 1177 EXPECT_EQ(2, GetCommitCounters(BOOKMARKS).num_commits_success);
(...skipping 18 matching lines...) Expand all
1196 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1196 parent.PutSpecifics(DefaultBookmarkSpecifics());
1197 parent.PutBaseVersion(1); 1197 parent.PutBaseVersion(1);
1198 parent.PutId(parent_id_); 1198 parent.PutId(parent_id_);
1199 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete"); 1199 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete");
1200 ASSERT_TRUE(child.good()); 1200 ASSERT_TRUE(child.good());
1201 child.PutId(child_id_); 1201 child.PutId(child_id_);
1202 child.PutBaseVersion(1); 1202 child.PutBaseVersion(1);
1203 WriteTestDataToEntry(&wtrans, &child); 1203 WriteTestDataToEntry(&wtrans, &child);
1204 } 1204 }
1205 1205
1206 EXPECT_TRUE(SyncShareNudge()); 1206 SyncShareNudge();
1207 ASSERT_EQ(2u, mock_server_->committed_ids().size()); 1207 ASSERT_EQ(2u, mock_server_->committed_ids().size());
1208 // If this test starts failing, be aware other sort orders could be valid. 1208 // If this test starts failing, be aware other sort orders could be valid.
1209 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1209 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1210 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1210 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1211 { 1211 {
1212 syncable::ReadTransaction rt(FROM_HERE, directory()); 1212 syncable::ReadTransaction rt(FROM_HERE, directory());
1213 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1213 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1214 ASSERT_TRUE(entry.good()); 1214 ASSERT_TRUE(entry.good());
1215 VerifyTestDataInEntry(&rt, &entry); 1215 VerifyTestDataInEntry(&rt, &entry);
1216 } 1216 }
(...skipping 27 matching lines...) Expand all
1244 parent2.PutIsDir(true); 1244 parent2.PutIsDir(true);
1245 parent2.PutSpecifics(DefaultPreferencesSpecifics()); 1245 parent2.PutSpecifics(DefaultPreferencesSpecifics());
1246 parent2.PutBaseVersion(1); 1246 parent2.PutBaseVersion(1);
1247 parent2.PutId(pref_node_id); 1247 parent2.PutId(pref_node_id);
1248 } 1248 }
1249 1249
1250 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES), 1250 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(PREFERENCES),
1251 ModelTypeSet(), 1251 ModelTypeSet(),
1252 ModelTypeSet()); 1252 ModelTypeSet());
1253 1253
1254 EXPECT_TRUE(SyncShareNudge()); 1254 SyncShareNudge();
1255 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 1255 ASSERT_EQ(2U, mock_server_->committed_ids().size());
1256 // If this test starts failing, be aware other sort orders could be valid. 1256 // If this test starts failing, be aware other sort orders could be valid.
1257 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1257 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1258 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1258 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1259 { 1259 {
1260 syncable::ReadTransaction rt(FROM_HERE, directory()); 1260 syncable::ReadTransaction rt(FROM_HERE, directory());
1261 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1261 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1262 ASSERT_TRUE(entry.good()); 1262 ASSERT_TRUE(entry.good());
1263 VerifyTestDataInEntry(&rt, &entry); 1263 VerifyTestDataInEntry(&rt, &entry);
1264 } 1264 }
(...skipping 17 matching lines...) Expand all
1282 parent.PutIsDir(true); 1282 parent.PutIsDir(true);
1283 parent.PutSpecifics(DefaultBookmarkSpecifics()); 1283 parent.PutSpecifics(DefaultBookmarkSpecifics());
1284 parent.PutBaseVersion(1); 1284 parent.PutBaseVersion(1);
1285 parent.PutId(parent_id_); 1285 parent.PutId(parent_id_);
1286 } 1286 }
1287 1287
1288 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(BOOKMARKS), 1288 directory()->PurgeEntriesWithTypeIn(ModelTypeSet(BOOKMARKS),
1289 ModelTypeSet(), 1289 ModelTypeSet(),
1290 ModelTypeSet()); 1290 ModelTypeSet());
1291 1291
1292 EXPECT_TRUE(SyncShareNudge()); 1292 SyncShareNudge();
1293 directory()->SaveChanges(); 1293 directory()->SaveChanges();
1294 { 1294 {
1295 syncable::ReadTransaction rt(FROM_HERE, directory()); 1295 syncable::ReadTransaction rt(FROM_HERE, directory());
1296 Entry entry(&rt, syncable::GET_BY_ID, parent_id_); 1296 Entry entry(&rt, syncable::GET_BY_ID, parent_id_);
1297 ASSERT_FALSE(entry.good()); 1297 ASSERT_FALSE(entry.good());
1298 } 1298 }
1299 } 1299 }
1300 1300
1301 TEST_F(SyncerTest, TestPurgeWithJournal) { 1301 TEST_F(SyncerTest, TestPurgeWithJournal) {
1302 { 1302 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 EXPECT_EQ(parent_id_, (*journal_entries.begin())->ref(syncable::ID)); 1341 EXPECT_EQ(parent_id_, (*journal_entries.begin())->ref(syncable::ID));
1342 EXPECT_EQ(child_id_, (*journal_entries.rbegin())->ref(syncable::ID)); 1342 EXPECT_EQ(child_id_, (*journal_entries.rbegin())->ref(syncable::ID));
1343 } 1343 }
1344 } 1344 }
1345 1345
1346 TEST_F(SyncerTest, ResetVersions) { 1346 TEST_F(SyncerTest, ResetVersions) {
1347 // Download some pref items. 1347 // Download some pref items.
1348 mock_server_->AddUpdatePref("id1", "", "tag1", 20, 20); 1348 mock_server_->AddUpdatePref("id1", "", "tag1", 20, 20);
1349 mock_server_->AddUpdatePref("id2", "", "tag2", 30, 30); 1349 mock_server_->AddUpdatePref("id2", "", "tag2", 30, 30);
1350 mock_server_->AddUpdatePref("id3", "", "tag3", 40, 40); 1350 mock_server_->AddUpdatePref("id3", "", "tag3", 40, 40);
1351 EXPECT_TRUE(SyncShareNudge()); 1351 SyncShareNudge();
1352 1352
1353 { 1353 {
1354 // Modify one of the preferences locally, mark another one as unapplied, 1354 // Modify one of the preferences locally, mark another one as unapplied,
1355 // and create another unsynced preference. 1355 // and create another unsynced preference.
1356 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1356 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1357 MutableEntry entry(&wtrans, GET_BY_CLIENT_TAG, "tag1"); 1357 MutableEntry entry(&wtrans, GET_BY_CLIENT_TAG, "tag1");
1358 entry.PutIsUnsynced(true); 1358 entry.PutIsUnsynced(true);
1359 1359
1360 MutableEntry entry2(&wtrans, GET_BY_CLIENT_TAG, "tag2"); 1360 MutableEntry entry2(&wtrans, GET_BY_CLIENT_TAG, "tag2");
1361 entry2.PutIsUnappliedUpdate(true); 1361 entry2.PutIsUnappliedUpdate(true);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 grandchild.PutId(ids_.FromNumber(105)); 1596 grandchild.PutId(ids_.FromNumber(105));
1597 grandchild.PutIsUnsynced(true); 1597 grandchild.PutIsUnsynced(true);
1598 grandchild.PutIsDel(true); 1598 grandchild.PutIsDel(true);
1599 grandchild.PutIsDir(false); 1599 grandchild.PutIsDir(false);
1600 grandchild.PutSpecifics(DefaultBookmarkSpecifics()); 1600 grandchild.PutSpecifics(DefaultBookmarkSpecifics());
1601 grandchild.PutBaseVersion(1); 1601 grandchild.PutBaseVersion(1);
1602 grandchild.PutMtime(now_minus_2h); 1602 grandchild.PutMtime(now_minus_2h);
1603 } 1603 }
1604 } 1604 }
1605 1605
1606 EXPECT_TRUE(SyncShareNudge()); 1606 SyncShareNudge();
1607 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1607 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1608 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. 1608 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set.
1609 // It will treat these like moves. 1609 // It will treat these like moves.
1610 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); 1610 vector<syncable::Id> commit_ids(mock_server_->committed_ids());
1611 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); 1611 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]);
1612 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); 1612 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]);
1613 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); 1613 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]);
1614 // We don't guarantee the delete orders in this test, only that they occur 1614 // We don't guarantee the delete orders in this test, only that they occur
1615 // at the end. 1615 // at the end.
1616 std::sort(commit_ids.begin() + 3, commit_ids.end()); 1616 std::sort(commit_ids.begin() + 3, commit_ids.end());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 parent.PutId(ids_.FromNumber(-104)); 1666 parent.PutId(ids_.FromNumber(-104));
1667 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, "B"); 1667 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent2_id, "B");
1668 ASSERT_TRUE(child.good()); 1668 ASSERT_TRUE(child.good());
1669 child.PutIsUnsynced(true); 1669 child.PutIsUnsynced(true);
1670 child.PutIsDir(true); 1670 child.PutIsDir(true);
1671 child.PutSpecifics(DefaultBookmarkSpecifics()); 1671 child.PutSpecifics(DefaultBookmarkSpecifics());
1672 child.PutId(ids_.FromNumber(105)); 1672 child.PutId(ids_.FromNumber(105));
1673 child.PutBaseVersion(1); 1673 child.PutBaseVersion(1);
1674 } 1674 }
1675 1675
1676 EXPECT_TRUE(SyncShareNudge()); 1676 SyncShareNudge();
1677 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1677 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1678 1678
1679 // This strange iteration and std::count() usage is to allow the order to 1679 // This strange iteration and std::count() usage is to allow the order to
1680 // vary. All we really care about is that parent1_id and parent2_id are the 1680 // vary. All we really care about is that parent1_id and parent2_id are the
1681 // first two IDs, and that the children make up the next four. Other than 1681 // first two IDs, and that the children make up the next four. Other than
1682 // that, ordering doesn't matter. 1682 // that, ordering doesn't matter.
1683 1683
1684 vector<syncable::Id>::const_iterator i = 1684 vector<syncable::Id>::const_iterator i =
1685 mock_server_->committed_ids().begin(); 1685 mock_server_->committed_ids().begin();
1686 vector<syncable::Id>::const_iterator parents_begin = i; 1686 vector<syncable::Id>::const_iterator parents_begin = i;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 ASSERT_TRUE(child2.good()); 1720 ASSERT_TRUE(child2.good());
1721 child2.PutIsUnsynced(true); 1721 child2.PutIsUnsynced(true);
1722 child2.PutSpecifics(DefaultBookmarkSpecifics()); 1722 child2.PutSpecifics(DefaultBookmarkSpecifics());
1723 child2.PutId(child2_id); 1723 child2.PutId(child2_id);
1724 1724
1725 parent.PutBaseVersion(1); 1725 parent.PutBaseVersion(1);
1726 child1.PutBaseVersion(1); 1726 child1.PutBaseVersion(1);
1727 child2.PutBaseVersion(1); 1727 child2.PutBaseVersion(1);
1728 } 1728 }
1729 1729
1730 EXPECT_TRUE(SyncShareNudge()); 1730 SyncShareNudge();
1731 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1731 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1732 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1732 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1733 // There are two possible valid orderings. 1733 // There are two possible valid orderings.
1734 if (child2_id == mock_server_->committed_ids()[1]) { 1734 if (child2_id == mock_server_->committed_ids()[1]) {
1735 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[1]); 1735 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[1]);
1736 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[2]); 1736 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[2]);
1737 } else { 1737 } else {
1738 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1738 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1739 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); 1739 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]);
1740 } 1740 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 MutableEntry child( 1772 MutableEntry child(
1773 &wtrans, CREATE, BOOKMARKS, parent2_id, child_name); 1773 &wtrans, CREATE, BOOKMARKS, parent2_id, child_name);
1774 ASSERT_TRUE(child.good()); 1774 ASSERT_TRUE(child.good());
1775 child.PutIsUnsynced(true); 1775 child.PutIsUnsynced(true);
1776 child.PutIsDir(true); 1776 child.PutIsDir(true);
1777 child.PutSpecifics(DefaultBookmarkSpecifics()); 1777 child.PutSpecifics(DefaultBookmarkSpecifics());
1778 child.PutId(child_id); 1778 child.PutId(child_id);
1779 child.PutBaseVersion(1); 1779 child.PutBaseVersion(1);
1780 } 1780 }
1781 1781
1782 EXPECT_TRUE(SyncShareNudge()); 1782 SyncShareNudge();
1783 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1783 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1784 // If this test starts failing, be aware other sort orders could be valid. 1784 // If this test starts failing, be aware other sort orders could be valid.
1785 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1785 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1786 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]); 1786 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]);
1787 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]); 1787 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]);
1788 { 1788 {
1789 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1789 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1790 // Check that things committed correctly. 1790 // Check that things committed correctly.
1791 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); 1791 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_);
1792 EXPECT_EQ(entry_1.GetNonUniqueName(), parent1_name); 1792 EXPECT_EQ(entry_1.GetNonUniqueName(), parent1_name);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 MutableEntry child( 1843 MutableEntry child(
1844 &wtrans, CREATE, BOOKMARKS, parent2_local_id, child_name); 1844 &wtrans, CREATE, BOOKMARKS, parent2_local_id, child_name);
1845 ASSERT_TRUE(child.good()); 1845 ASSERT_TRUE(child.good());
1846 child.PutIsUnsynced(true); 1846 child.PutIsUnsynced(true);
1847 child.PutIsDir(true); 1847 child.PutIsDir(true);
1848 child.PutSpecifics(DefaultBookmarkSpecifics()); 1848 child.PutSpecifics(DefaultBookmarkSpecifics());
1849 child.PutId(child_local_id); 1849 child.PutId(child_local_id);
1850 meta_handle_b = child.GetMetahandle(); 1850 meta_handle_b = child.GetMetahandle();
1851 } 1851 }
1852 1852
1853 EXPECT_TRUE(SyncShareNudge()); 1853 SyncShareNudge();
1854 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1854 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1855 // If this test starts failing, be aware other sort orders could be valid. 1855 // If this test starts failing, be aware other sort orders could be valid.
1856 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1856 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1857 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]); 1857 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]);
1858 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]); 1858 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]);
1859 { 1859 {
1860 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 1860 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1861 1861
1862 Entry parent(&rtrans, syncable::GET_BY_ID, 1862 Entry parent(&rtrans, syncable::GET_BY_ID,
1863 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); 1863 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name));
(...skipping 17 matching lines...) Expand all
1881 } 1881 }
1882 } 1882 }
1883 1883
1884 TEST_F(SyncerTest, UpdateWithZeroLengthName) { 1884 TEST_F(SyncerTest, UpdateWithZeroLengthName) {
1885 // One illegal update 1885 // One illegal update
1886 mock_server_->AddUpdateDirectory( 1886 mock_server_->AddUpdateDirectory(
1887 1, 0, std::string(), 1, 10, foreign_cache_guid(), "-1"); 1887 1, 0, std::string(), 1, 10, foreign_cache_guid(), "-1");
1888 // And one legal one that we're going to delete. 1888 // And one legal one that we're going to delete.
1889 mock_server_->AddUpdateDirectory(2, 0, "FOO", 1, 10, 1889 mock_server_->AddUpdateDirectory(2, 0, "FOO", 1, 10,
1890 foreign_cache_guid(), "-2"); 1890 foreign_cache_guid(), "-2");
1891 EXPECT_TRUE(SyncShareNudge()); 1891 SyncShareNudge();
1892 // Delete the legal one. The new update has a null name. 1892 // Delete the legal one. The new update has a null name.
1893 mock_server_->AddUpdateDirectory( 1893 mock_server_->AddUpdateDirectory(
1894 2, 0, std::string(), 2, 20, foreign_cache_guid(), "-2"); 1894 2, 0, std::string(), 2, 20, foreign_cache_guid(), "-2");
1895 mock_server_->SetLastUpdateDeleted(); 1895 mock_server_->SetLastUpdateDeleted();
1896 EXPECT_TRUE(SyncShareNudge()); 1896 SyncShareNudge();
1897 } 1897 }
1898 1898
1899 TEST_F(SyncerTest, TestBasicUpdate) { 1899 TEST_F(SyncerTest, TestBasicUpdate) {
1900 string id = "some_id"; 1900 string id = "some_id";
1901 string parent_id = "0"; 1901 string parent_id = "0";
1902 string name = "in_root"; 1902 string name = "in_root";
1903 int64 version = 10; 1903 int64 version = 10;
1904 int64 timestamp = 10; 1904 int64 timestamp = 10;
1905 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp, 1905 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp,
1906 foreign_cache_guid(), "-1"); 1906 foreign_cache_guid(), "-1");
1907 1907
1908 EXPECT_TRUE(SyncShareNudge()); 1908 SyncShareNudge();
1909 { 1909 {
1910 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1910 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1911 Entry entry(&trans, GET_BY_ID, 1911 Entry entry(&trans, GET_BY_ID,
1912 syncable::Id::CreateFromServerId("some_id")); 1912 syncable::Id::CreateFromServerId("some_id"));
1913 ASSERT_TRUE(entry.good()); 1913 ASSERT_TRUE(entry.good());
1914 EXPECT_TRUE(entry.GetIsDir()); 1914 EXPECT_TRUE(entry.GetIsDir());
1915 EXPECT_TRUE(entry.GetServerVersion()== version); 1915 EXPECT_TRUE(entry.GetServerVersion()== version);
1916 EXPECT_TRUE(entry.GetBaseVersion()== version); 1916 EXPECT_TRUE(entry.GetBaseVersion()== version);
1917 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 1917 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
1918 EXPECT_FALSE(entry.GetIsUnsynced()); 1918 EXPECT_FALSE(entry.GetIsUnsynced());
(...skipping 13 matching lines...) Expand all
1932 foreign_cache_guid(), "-2"); 1932 foreign_cache_guid(), "-2");
1933 1933
1934 // Unknown parent: should never be applied. "-80" is a legal server ID, 1934 // Unknown parent: should never be applied. "-80" is a legal server ID,
1935 // because any string sent by the server is a legal server ID in the sync 1935 // because any string sent by the server is a legal server ID in the sync
1936 // protocol, but it's not the ID of any item known to the client. This 1936 // protocol, but it's not the ID of any item known to the client. This
1937 // update should succeed validation, but be stuck in the unapplied state 1937 // update should succeed validation, but be stuck in the unapplied state
1938 // until an item with the server ID "-80" arrives. 1938 // until an item with the server ID "-80" arrives.
1939 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10, 1939 mock_server_->AddUpdateDirectory(3, -80, "bad_parent", 10, 10,
1940 foreign_cache_guid(), "-3"); 1940 foreign_cache_guid(), "-3");
1941 1941
1942 EXPECT_TRUE(SyncShareNudge()); 1942 SyncShareNudge();
1943 1943
1944 // Id 3 should be in conflict now. 1944 // Id 3 should be in conflict now.
1945 EXPECT_EQ( 1945 EXPECT_EQ(
1946 1, 1946 1,
1947 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); 1947 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures);
1948 1948
1949 // The only request in that loop should have been a GetUpdate. 1949 // The only request in that loop should have been a GetUpdate.
1950 // At that point, we didn't know whether or not we had conflicts. 1950 // At that point, we didn't know whether or not we had conflicts.
1951 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 1951 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
1952 VerifyHierarchyConflictsUnspecified(mock_server_->last_request()); 1952 VerifyHierarchyConflictsUnspecified(mock_server_->last_request());
1953 1953
1954 // These entries will be used in the second set of updates. 1954 // These entries will be used in the second set of updates.
1955 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10, 1955 mock_server_->AddUpdateDirectory(4, 0, "newer_version", 20, 10,
1956 foreign_cache_guid(), "-4"); 1956 foreign_cache_guid(), "-4");
1957 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10, 1957 mock_server_->AddUpdateDirectory(5, 0, "circular1", 10, 10,
1958 foreign_cache_guid(), "-5"); 1958 foreign_cache_guid(), "-5");
1959 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10, 1959 mock_server_->AddUpdateDirectory(6, 5, "circular2", 10, 10,
1960 foreign_cache_guid(), "-6"); 1960 foreign_cache_guid(), "-6");
1961 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10, 1961 mock_server_->AddUpdateDirectory(9, 3, "bad_parent_child", 10, 10,
1962 foreign_cache_guid(), "-9"); 1962 foreign_cache_guid(), "-9");
1963 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10, 1963 mock_server_->AddUpdateDirectory(100, 9, "bad_parent_child2", 10, 10,
1964 foreign_cache_guid(), "-100"); 1964 foreign_cache_guid(), "-100");
1965 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10, 1965 mock_server_->AddUpdateDirectory(10, 0, "dir_to_bookmark", 10, 10,
1966 foreign_cache_guid(), "-10"); 1966 foreign_cache_guid(), "-10");
1967 1967
1968 EXPECT_TRUE(SyncShareNudge()); 1968 SyncShareNudge();
1969 // The three items with an unresolved parent should be unapplied (3, 9, 100). 1969 // The three items with an unresolved parent should be unapplied (3, 9, 100).
1970 // The name clash should also still be in conflict. 1970 // The name clash should also still be in conflict.
1971 EXPECT_EQ( 1971 EXPECT_EQ(
1972 3, 1972 3,
1973 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures); 1973 GetUpdateCounters(BOOKMARKS).num_hierarchy_conflict_application_failures);
1974 1974
1975 // This time around, we knew that there were conflicts. 1975 // This time around, we knew that there were conflicts.
1976 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 1976 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
1977 VerifyHierarchyConflictsReported(mock_server_->last_request()); 1977 VerifyHierarchyConflictsReported(mock_server_->last_request());
1978 1978
(...skipping 25 matching lines...) Expand all
2004 mock_server_->AddUpdateDirectory(1, 0, "new_name", 20, 20, 2004 mock_server_->AddUpdateDirectory(1, 0, "new_name", 20, 20,
2005 foreign_cache_guid(), "-1"); 2005 foreign_cache_guid(), "-1");
2006 2006
2007 // Moving 5 under 6 will create a cycle: a conflict. 2007 // Moving 5 under 6 will create a cycle: a conflict.
2008 mock_server_->AddUpdateDirectory(5, 6, "circular3", 20, 20, 2008 mock_server_->AddUpdateDirectory(5, 6, "circular3", 20, 20,
2009 foreign_cache_guid(), "-5"); 2009 foreign_cache_guid(), "-5");
2010 2010
2011 // Flip the is_dir bit: should fail verify & be dropped. 2011 // Flip the is_dir bit: should fail verify & be dropped.
2012 mock_server_->AddUpdateBookmark(10, 0, "dir_to_bookmark", 20, 20, 2012 mock_server_->AddUpdateBookmark(10, 0, "dir_to_bookmark", 20, 20,
2013 foreign_cache_guid(), "-10"); 2013 foreign_cache_guid(), "-10");
2014 EXPECT_TRUE(SyncShareNudge()); 2014 SyncShareNudge();
2015 2015
2016 // Version number older than last known: should fail verify & be dropped. 2016 // Version number older than last known: should fail verify & be dropped.
2017 mock_server_->AddUpdateDirectory(4, 0, "old_version", 10, 10, 2017 mock_server_->AddUpdateDirectory(4, 0, "old_version", 10, 10,
2018 foreign_cache_guid(), "-4"); 2018 foreign_cache_guid(), "-4");
2019 EXPECT_TRUE(SyncShareNudge()); 2019 SyncShareNudge();
2020 { 2020 {
2021 syncable::ReadTransaction trans(FROM_HERE, directory()); 2021 syncable::ReadTransaction trans(FROM_HERE, directory());
2022 2022
2023 Entry still_a_dir(&trans, GET_BY_ID, ids_.FromNumber(10)); 2023 Entry still_a_dir(&trans, GET_BY_ID, ids_.FromNumber(10));
2024 ASSERT_TRUE(still_a_dir.good()); 2024 ASSERT_TRUE(still_a_dir.good());
2025 EXPECT_FALSE(still_a_dir.GetIsUnappliedUpdate()); 2025 EXPECT_FALSE(still_a_dir.GetIsUnappliedUpdate());
2026 EXPECT_EQ(10u, still_a_dir.GetBaseVersion()); 2026 EXPECT_EQ(10u, still_a_dir.GetBaseVersion());
2027 EXPECT_EQ(10u, still_a_dir.GetServerVersion()); 2027 EXPECT_EQ(10u, still_a_dir.GetServerVersion());
2028 EXPECT_TRUE(still_a_dir.GetIsDir()); 2028 EXPECT_TRUE(still_a_dir.GetIsDir());
2029 2029
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 // The following update should cause the folder to both apply the update, as 2130 // The following update should cause the folder to both apply the update, as
2131 // well as reassociate the id. 2131 // well as reassociate the id.
2132 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, 2132 mock_server_->AddUpdateDirectory(new_folder_id, root_id_,
2133 "new_folder", new_version, timestamp, 2133 "new_folder", new_version, timestamp,
2134 local_cache_guid(), folder_id.GetServerId()); 2134 local_cache_guid(), folder_id.GetServerId());
2135 2135
2136 // We don't want it accidentally committed, just the update applied. 2136 // We don't want it accidentally committed, just the update applied.
2137 mock_server_->set_conflict_all_commits(true); 2137 mock_server_->set_conflict_all_commits(true);
2138 2138
2139 // Alright! Apply that update! 2139 // Alright! Apply that update!
2140 EXPECT_FALSE(SyncShareNudge()); 2140 SyncShareNudge();
2141 { 2141 {
2142 // The folder's ID should have been updated. 2142 // The folder's ID should have been updated.
2143 syncable::ReadTransaction trans(FROM_HERE, directory()); 2143 syncable::ReadTransaction trans(FROM_HERE, directory());
2144 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); 2144 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder);
2145 ASSERT_TRUE(folder.good()); 2145 ASSERT_TRUE(folder.good());
2146 EXPECT_EQ("new_folder", folder.GetNonUniqueName()); 2146 EXPECT_EQ("new_folder", folder.GetNonUniqueName());
2147 EXPECT_TRUE(new_version == folder.GetBaseVersion()); 2147 EXPECT_TRUE(new_version == folder.GetBaseVersion());
2148 EXPECT_TRUE(new_folder_id == folder.GetId()); 2148 EXPECT_TRUE(new_folder_id == folder.GetId());
2149 EXPECT_TRUE(folder.GetId().ServerKnows()); 2149 EXPECT_TRUE(folder.GetId().ServerKnows());
2150 EXPECT_EQ(trans.root_id(), folder.GetParentId()); 2150 EXPECT_EQ(trans.root_id(), folder.GetParentId());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 2195
2196 // Generate an update from the server with a relevant ID reassignment. 2196 // Generate an update from the server with a relevant ID reassignment.
2197 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, 2197 mock_server_->AddUpdateBookmark(new_entry_id, root_id_,
2198 "new_entry", new_version, timestamp, 2198 "new_entry", new_version, timestamp,
2199 local_cache_guid(), entry_id.GetServerId()); 2199 local_cache_guid(), entry_id.GetServerId());
2200 2200
2201 // We don't want it accidentally committed, just the update applied. 2201 // We don't want it accidentally committed, just the update applied.
2202 mock_server_->set_conflict_all_commits(true); 2202 mock_server_->set_conflict_all_commits(true);
2203 2203
2204 // Alright! Apply that update! 2204 // Alright! Apply that update!
2205 EXPECT_TRUE(SyncShareNudge()); 2205 SyncShareNudge();
2206 { 2206 {
2207 syncable::ReadTransaction trans(FROM_HERE, directory()); 2207 syncable::ReadTransaction trans(FROM_HERE, directory());
2208 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 2208 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
2209 ASSERT_TRUE(entry.good()); 2209 ASSERT_TRUE(entry.good());
2210 EXPECT_TRUE(new_version == entry.GetBaseVersion()); 2210 EXPECT_TRUE(new_version == entry.GetBaseVersion());
2211 EXPECT_TRUE(new_entry_id == entry.GetId()); 2211 EXPECT_TRUE(new_entry_id == entry.GetId());
2212 EXPECT_EQ("new_entry", entry.GetNonUniqueName()); 2212 EXPECT_EQ("new_entry", entry.GetNonUniqueName());
2213 } 2213 }
2214 } 2214 }
2215 2215
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 { 2256 {
2257 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2257 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2258 Id new_entry_id = GetOnlyEntryWithName( 2258 Id new_entry_id = GetOnlyEntryWithName(
2259 &trans, trans.root_id(), "new_entry"); 2259 &trans, trans.root_id(), "new_entry");
2260 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); 2260 MutableEntry entry(&trans, GET_BY_ID, new_entry_id);
2261 ASSERT_TRUE(entry.good()); 2261 ASSERT_TRUE(entry.good());
2262 entry.PutIsDel(true); 2262 entry.PutIsDel(true);
2263 } 2263 }
2264 2264
2265 // Just don't CHECK fail in sync, have the update split. 2265 // Just don't CHECK fail in sync, have the update split.
2266 EXPECT_TRUE(SyncShareNudge()); 2266 SyncShareNudge();
2267 { 2267 {
2268 syncable::ReadTransaction trans(FROM_HERE, directory()); 2268 syncable::ReadTransaction trans(FROM_HERE, directory());
2269 Id new_entry_id = GetOnlyEntryWithName( 2269 Id new_entry_id = GetOnlyEntryWithName(
2270 &trans, trans.root_id(), "new_entry"); 2270 &trans, trans.root_id(), "new_entry");
2271 Entry entry(&trans, GET_BY_ID, new_entry_id); 2271 Entry entry(&trans, GET_BY_ID, new_entry_id);
2272 ASSERT_TRUE(entry.good()); 2272 ASSERT_TRUE(entry.good());
2273 EXPECT_FALSE(entry.GetIsDel()); 2273 EXPECT_FALSE(entry.GetIsDel());
2274 2274
2275 Entry old_entry(&trans, GET_BY_ID, entry_id); 2275 Entry old_entry(&trans, GET_BY_ID, entry_id);
2276 ASSERT_TRUE(old_entry.good()); 2276 ASSERT_TRUE(old_entry.good());
2277 EXPECT_TRUE(old_entry.GetIsDel()); 2277 EXPECT_TRUE(old_entry.GetIsDel());
2278 } 2278 }
2279 } 2279 }
2280 2280
2281 // TODO(chron): Add more unsanitized name tests. 2281 // TODO(chron): Add more unsanitized name tests.
2282 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) { 2282 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) {
2283 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10, 2283 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10,
2284 foreign_cache_guid(), "-1"); 2284 foreign_cache_guid(), "-1");
2285 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10, 2285 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10,
2286 foreign_cache_guid(), "-2"); 2286 foreign_cache_guid(), "-2");
2287 mock_server_->set_conflict_all_commits(true); 2287 mock_server_->set_conflict_all_commits(true);
2288 EXPECT_TRUE(SyncShareNudge()); 2288 SyncShareNudge();
2289 { 2289 {
2290 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2290 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2291 2291
2292 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2292 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2293 ASSERT_TRUE(A.good()); 2293 ASSERT_TRUE(A.good());
2294 A.PutIsUnsynced(true); 2294 A.PutIsUnsynced(true);
2295 A.PutIsUnappliedUpdate(true); 2295 A.PutIsUnappliedUpdate(true);
2296 A.PutServerVersion(20); 2296 A.PutServerVersion(20);
2297 2297
2298 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2298 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2299 ASSERT_TRUE(B.good()); 2299 ASSERT_TRUE(B.good());
2300 B.PutIsUnappliedUpdate(true); 2300 B.PutIsUnappliedUpdate(true);
2301 B.PutServerVersion(20); 2301 B.PutServerVersion(20);
2302 } 2302 }
2303 EXPECT_TRUE(SyncShareNudge()); 2303 SyncShareNudge();
2304 saw_syncer_event_ = false; 2304 saw_syncer_event_ = false;
2305 mock_server_->set_conflict_all_commits(false); 2305 mock_server_->set_conflict_all_commits(false);
2306 2306
2307 { 2307 {
2308 syncable::ReadTransaction trans(FROM_HERE, directory()); 2308 syncable::ReadTransaction trans(FROM_HERE, directory());
2309 2309
2310 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1)); 2310 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1));
2311 ASSERT_TRUE(A.good()); 2311 ASSERT_TRUE(A.good());
2312 EXPECT_TRUE(A.GetIsUnsynced()== false); 2312 EXPECT_TRUE(A.GetIsUnsynced()== false);
2313 EXPECT_TRUE(A.GetIsUnappliedUpdate()== false); 2313 EXPECT_TRUE(A.GetIsUnappliedUpdate()== false);
2314 EXPECT_TRUE(A.GetServerVersion()== 20); 2314 EXPECT_TRUE(A.GetServerVersion()== 20);
2315 2315
2316 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 2316 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
2317 ASSERT_TRUE(B.good()); 2317 ASSERT_TRUE(B.good());
2318 EXPECT_TRUE(B.GetIsUnsynced()== false); 2318 EXPECT_TRUE(B.GetIsUnsynced()== false);
2319 EXPECT_TRUE(B.GetIsUnappliedUpdate()== false); 2319 EXPECT_TRUE(B.GetIsUnappliedUpdate()== false);
2320 EXPECT_TRUE(B.GetServerVersion()== 20); 2320 EXPECT_TRUE(B.GetServerVersion()== 20);
2321 } 2321 }
2322 } 2322 }
2323 2323
2324 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) { 2324 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) {
2325 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 2325 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
2326 foreign_cache_guid(), "-1"); 2326 foreign_cache_guid(), "-1");
2327 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, 2327 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10,
2328 foreign_cache_guid(), "-2"); 2328 foreign_cache_guid(), "-2");
2329 mock_server_->set_conflict_all_commits(true); 2329 mock_server_->set_conflict_all_commits(true);
2330 EXPECT_TRUE(SyncShareNudge()); 2330 SyncShareNudge();
2331 { 2331 {
2332 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2332 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2333 2333
2334 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2334 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2335 ASSERT_TRUE(A.good()); 2335 ASSERT_TRUE(A.good());
2336 A.PutIsUnsynced(true); 2336 A.PutIsUnsynced(true);
2337 A.PutIsUnappliedUpdate(true); 2337 A.PutIsUnappliedUpdate(true);
2338 A.PutServerVersion(20); 2338 A.PutServerVersion(20);
2339 2339
2340 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2340 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2341 ASSERT_TRUE(B.good()); 2341 ASSERT_TRUE(B.good());
2342 B.PutIsUnappliedUpdate(true); 2342 B.PutIsUnappliedUpdate(true);
2343 B.PutServerVersion(20); 2343 B.PutServerVersion(20);
2344 } 2344 }
2345 EXPECT_TRUE(SyncShareNudge()); 2345 SyncShareNudge();
2346 saw_syncer_event_ = false; 2346 saw_syncer_event_ = false;
2347 mock_server_->set_conflict_all_commits(false); 2347 mock_server_->set_conflict_all_commits(false);
2348 2348
2349 { 2349 {
2350 syncable::ReadTransaction trans(FROM_HERE, directory()); 2350 syncable::ReadTransaction trans(FROM_HERE, directory());
2351 2351
2352 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1)); 2352 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1));
2353 ASSERT_TRUE(A.good()); 2353 ASSERT_TRUE(A.good());
2354 EXPECT_TRUE(A.GetIsUnsynced()== false); 2354 EXPECT_TRUE(A.GetIsUnsynced()== false);
2355 EXPECT_TRUE(A.GetIsUnappliedUpdate()== false); 2355 EXPECT_TRUE(A.GetIsUnappliedUpdate()== false);
(...skipping 11 matching lines...) Expand all
2367 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10, 2367 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10,
2368 foreign_cache_guid(), "-4"); 2368 foreign_cache_guid(), "-4");
2369 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10, 2369 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10,
2370 foreign_cache_guid(), "-3"); 2370 foreign_cache_guid(), "-3");
2371 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10, 2371 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10,
2372 foreign_cache_guid(), "-5"); 2372 foreign_cache_guid(), "-5");
2373 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10, 2373 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10,
2374 foreign_cache_guid(), "-2"); 2374 foreign_cache_guid(), "-2");
2375 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10, 2375 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10,
2376 foreign_cache_guid(), "-1"); 2376 foreign_cache_guid(), "-1");
2377 EXPECT_TRUE(SyncShareNudge()); 2377 SyncShareNudge();
2378 syncable::ReadTransaction trans(FROM_HERE, directory()); 2378 syncable::ReadTransaction trans(FROM_HERE, directory());
2379 2379
2380 Id child_id = GetOnlyEntryWithName( 2380 Id child_id = GetOnlyEntryWithName(
2381 &trans, ids_.FromNumber(4), "gggchild"); 2381 &trans, ids_.FromNumber(4), "gggchild");
2382 Entry child(&trans, GET_BY_ID, child_id); 2382 Entry child(&trans, GET_BY_ID, child_id);
2383 ASSERT_TRUE(child.good()); 2383 ASSERT_TRUE(child.good());
2384 } 2384 }
2385 2385
2386 class EntryCreatedInNewFolderTest : public SyncerTest { 2386 class EntryCreatedInNewFolderTest : public SyncerTest {
2387 public: 2387 public:
(...skipping 21 matching lines...) Expand all
2409 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2409 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2410 ASSERT_TRUE(entry.good()); 2410 ASSERT_TRUE(entry.good());
2411 entry.PutIsDir(true); 2411 entry.PutIsDir(true);
2412 entry.PutIsUnsynced(true); 2412 entry.PutIsUnsynced(true);
2413 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2413 entry.PutSpecifics(DefaultBookmarkSpecifics());
2414 } 2414 }
2415 2415
2416 mock_server_->SetMidCommitCallback( 2416 mock_server_->SetMidCommitCallback(
2417 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2417 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2418 base::Unretained(this))); 2418 base::Unretained(this)));
2419 EXPECT_TRUE(SyncShareNudge()); 2419 SyncShareNudge();
2420 // We loop until no unsynced handles remain, so we will commit both ids. 2420 // We loop until no unsynced handles remain, so we will commit both ids.
2421 EXPECT_EQ(2u, mock_server_->committed_ids().size()); 2421 EXPECT_EQ(2u, mock_server_->committed_ids().size());
2422 { 2422 {
2423 syncable::ReadTransaction trans(FROM_HERE, directory()); 2423 syncable::ReadTransaction trans(FROM_HERE, directory());
2424 Entry parent_entry(&trans, syncable::GET_BY_ID, 2424 Entry parent_entry(&trans, syncable::GET_BY_ID,
2425 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2425 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2426 ASSERT_TRUE(parent_entry.good()); 2426 ASSERT_TRUE(parent_entry.good());
2427 2427
2428 Id child_id = 2428 Id child_id =
2429 GetOnlyEntryWithName(&trans, parent_entry.GetId(), "bob"); 2429 GetOnlyEntryWithName(&trans, parent_entry.GetId(), "bob");
2430 Entry child(&trans, syncable::GET_BY_ID, child_id); 2430 Entry child(&trans, syncable::GET_BY_ID, child_id);
2431 ASSERT_TRUE(child.good()); 2431 ASSERT_TRUE(child.good());
2432 EXPECT_EQ(parent_entry.GetId(), child.GetParentId()); 2432 EXPECT_EQ(parent_entry.GetId(), child.GetParentId());
2433 } 2433 }
2434 } 2434 }
2435 2435
2436 TEST_F(SyncerTest, NegativeIDInUpdate) { 2436 TEST_F(SyncerTest, NegativeIDInUpdate) {
2437 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40, 2437 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40,
2438 foreign_cache_guid(), "-100"); 2438 foreign_cache_guid(), "-100");
2439 EXPECT_TRUE(SyncShareNudge()); 2439 SyncShareNudge();
2440 // The negative id would make us CHECK! 2440 // The negative id would make us CHECK!
2441 } 2441 }
2442 2442
2443 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2443 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2444 int64 metahandle_fred; 2444 int64 metahandle_fred;
2445 syncable::Id orig_id; 2445 syncable::Id orig_id;
2446 { 2446 {
2447 // Create an item. 2447 // Create an item.
2448 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2448 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2449 MutableEntry fred_match(&trans, CREATE, BOOKMARKS, trans.root_id(), 2449 MutableEntry fred_match(&trans, CREATE, BOOKMARKS, trans.root_id(),
2450 "fred_match"); 2450 "fred_match");
2451 ASSERT_TRUE(fred_match.good()); 2451 ASSERT_TRUE(fred_match.good());
2452 metahandle_fred = fred_match.GetMetahandle(); 2452 metahandle_fred = fred_match.GetMetahandle();
2453 orig_id = fred_match.GetId(); 2453 orig_id = fred_match.GetId();
2454 WriteTestDataToEntry(&trans, &fred_match); 2454 WriteTestDataToEntry(&trans, &fred_match);
2455 } 2455 }
2456 // Commit it. 2456 // Commit it.
2457 EXPECT_TRUE(SyncShareNudge()); 2457 SyncShareNudge();
2458 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2458 EXPECT_EQ(1u, mock_server_->committed_ids().size());
2459 mock_server_->set_conflict_all_commits(true); 2459 mock_server_->set_conflict_all_commits(true);
2460 syncable::Id fred_match_id; 2460 syncable::Id fred_match_id;
2461 { 2461 {
2462 // Now receive a change from outside. 2462 // Now receive a change from outside.
2463 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2463 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2464 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred); 2464 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred);
2465 ASSERT_TRUE(fred_match.good()); 2465 ASSERT_TRUE(fred_match.good());
2466 EXPECT_TRUE(fred_match.GetId().ServerKnows()); 2466 EXPECT_TRUE(fred_match.GetId().ServerKnows());
2467 fred_match_id = fred_match.GetId(); 2467 fred_match_id = fred_match.GetId();
2468 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(), 2468 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(),
2469 "fred_match", 40, 40, local_cache_guid(), orig_id.GetServerId()); 2469 "fred_match", 40, 40, local_cache_guid(), orig_id.GetServerId());
2470 } 2470 }
2471 // Run the syncer. 2471 // Run the syncer.
2472 for (int i = 0 ; i < 30 ; ++i) { 2472 for (int i = 0 ; i < 30 ; ++i) {
2473 EXPECT_TRUE(SyncShareNudge()); 2473 SyncShareNudge();
2474 } 2474 }
2475 } 2475 }
2476 2476
2477 /** 2477 /**
2478 * In the event that we have a double changed entry, that is changed on both 2478 * In the event that we have a double changed entry, that is changed on both
2479 * the client and the server, the conflict resolver should just drop one of 2479 * the client and the server, the conflict resolver should just drop one of
2480 * them and accept the other. 2480 * them and accept the other.
2481 */ 2481 */
2482 2482
2483 TEST_F(SyncerTest, DoublyChangedWithResolver) { 2483 TEST_F(SyncerTest, DoublyChangedWithResolver) {
2484 syncable::Id local_id; 2484 syncable::Id local_id;
2485 { 2485 {
2486 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2486 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2487 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); 2487 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder");
2488 ASSERT_TRUE(parent.good()); 2488 ASSERT_TRUE(parent.good());
2489 parent.PutIsDir(true); 2489 parent.PutIsDir(true);
2490 parent.PutId(parent_id_); 2490 parent.PutId(parent_id_);
2491 parent.PutBaseVersion(5); 2491 parent.PutBaseVersion(5);
2492 parent.PutSpecifics(DefaultBookmarkSpecifics()); 2492 parent.PutSpecifics(DefaultBookmarkSpecifics());
2493 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete.htm"); 2493 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent_id_, "Pete.htm");
2494 ASSERT_TRUE(child.good()); 2494 ASSERT_TRUE(child.good());
2495 local_id = child.GetId(); 2495 local_id = child.GetId();
2496 child.PutId(child_id_); 2496 child.PutId(child_id_);
2497 child.PutBaseVersion(10); 2497 child.PutBaseVersion(10);
2498 WriteTestDataToEntry(&wtrans, &child); 2498 WriteTestDataToEntry(&wtrans, &child);
2499 } 2499 }
2500 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10, 2500 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10,
2501 local_cache_guid(), local_id.GetServerId()); 2501 local_cache_guid(), local_id.GetServerId());
2502 mock_server_->set_conflict_all_commits(true); 2502 mock_server_->set_conflict_all_commits(true);
2503 EXPECT_FALSE(SyncShareNudge()); 2503 SyncShareNudge();
2504 syncable::Directory::Metahandles children; 2504 syncable::Directory::Metahandles children;
2505 { 2505 {
2506 syncable::ReadTransaction trans(FROM_HERE, directory()); 2506 syncable::ReadTransaction trans(FROM_HERE, directory());
2507 directory()->GetChildHandlesById(&trans, parent_id_, &children); 2507 directory()->GetChildHandlesById(&trans, parent_id_, &children);
2508 // We expect the conflict resolver to preserve the local entry. 2508 // We expect the conflict resolver to preserve the local entry.
2509 Entry child(&trans, syncable::GET_BY_ID, child_id_); 2509 Entry child(&trans, syncable::GET_BY_ID, child_id_);
2510 ASSERT_TRUE(child.good()); 2510 ASSERT_TRUE(child.good());
2511 EXPECT_TRUE(child.GetIsUnsynced()); 2511 EXPECT_TRUE(child.GetIsUnsynced());
2512 EXPECT_FALSE(child.GetIsUnappliedUpdate()); 2512 EXPECT_FALSE(child.GetIsUnappliedUpdate());
2513 EXPECT_TRUE(child.GetSpecifics().has_bookmark()); 2513 EXPECT_TRUE(child.GetSpecifics().has_bookmark());
(...skipping 17 matching lines...) Expand all
2531 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, root_id_, "Pete"); 2531 MutableEntry entry(&wtrans, CREATE, BOOKMARKS, root_id_, "Pete");
2532 ASSERT_TRUE(entry.good()); 2532 ASSERT_TRUE(entry.good());
2533 EXPECT_FALSE(entry.GetId().ServerKnows()); 2533 EXPECT_FALSE(entry.GetId().ServerKnows());
2534 local_id = entry.GetId(); 2534 local_id = entry.GetId();
2535 entry.PutIsDir(true); 2535 entry.PutIsDir(true);
2536 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2536 entry.PutSpecifics(DefaultBookmarkSpecifics());
2537 entry.PutIsUnsynced(true); 2537 entry.PutIsUnsynced(true);
2538 entry.PutMtime(test_time); 2538 entry.PutMtime(test_time);
2539 entry_metahandle = entry.GetMetahandle(); 2539 entry_metahandle = entry.GetMetahandle();
2540 } 2540 }
2541 EXPECT_TRUE(SyncShareNudge()); 2541 SyncShareNudge();
2542 syncable::Id id; 2542 syncable::Id id;
2543 int64 version; 2543 int64 version;
2544 { 2544 {
2545 syncable::ReadTransaction trans(FROM_HERE, directory()); 2545 syncable::ReadTransaction trans(FROM_HERE, directory());
2546 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle); 2546 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle);
2547 ASSERT_TRUE(entry.good()); 2547 ASSERT_TRUE(entry.good());
2548 id = entry.GetId(); 2548 id = entry.GetId();
2549 EXPECT_TRUE(id.ServerKnows()); 2549 EXPECT_TRUE(id.ServerKnows());
2550 version = entry.GetBaseVersion(); 2550 version = entry.GetBaseVersion();
2551 } 2551 }
2552 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 2552 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
2553 update->set_originator_cache_guid(local_cache_guid()); 2553 update->set_originator_cache_guid(local_cache_guid());
2554 update->set_originator_client_item_id(local_id.GetServerId()); 2554 update->set_originator_client_item_id(local_id.GetServerId());
2555 EXPECT_EQ("Pete", update->name()); 2555 EXPECT_EQ("Pete", update->name());
2556 EXPECT_EQ(id.GetServerId(), update->id_string()); 2556 EXPECT_EQ(id.GetServerId(), update->id_string());
2557 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string()); 2557 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string());
2558 EXPECT_EQ(version, update->version()); 2558 EXPECT_EQ(version, update->version());
2559 EXPECT_TRUE(SyncShareNudge()); 2559 SyncShareNudge();
2560 { 2560 {
2561 syncable::ReadTransaction trans(FROM_HERE, directory()); 2561 syncable::ReadTransaction trans(FROM_HERE, directory());
2562 Entry entry(&trans, syncable::GET_BY_ID, id); 2562 Entry entry(&trans, syncable::GET_BY_ID, id);
2563 ASSERT_TRUE(entry.good()); 2563 ASSERT_TRUE(entry.good());
2564 EXPECT_TRUE(entry.GetMtime()== test_time); 2564 EXPECT_TRUE(entry.GetMtime()== test_time);
2565 } 2565 }
2566 } 2566 }
2567 2567
2568 TEST_F(SyncerTest, ParentAndChildBothMatch) { 2568 TEST_F(SyncerTest, ParentAndChildBothMatch) {
2569 // Disable PREFERENCES which is enabled at the setup step to avoid 2569 // Disable PREFERENCES which is enabled at the setup step to avoid
(...skipping 27 matching lines...) Expand all
2597 child.PutSpecifics(DefaultBookmarkSpecifics()); 2597 child.PutSpecifics(DefaultBookmarkSpecifics());
2598 WriteTestDataToEntry(&wtrans, &child); 2598 WriteTestDataToEntry(&wtrans, &child);
2599 } 2599 }
2600 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10, 2600 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10,
2601 local_cache_guid(), 2601 local_cache_guid(),
2602 parent_local_id.GetServerId()); 2602 parent_local_id.GetServerId());
2603 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10, 2603 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10,
2604 local_cache_guid(), 2604 local_cache_guid(),
2605 child_local_id.GetServerId()); 2605 child_local_id.GetServerId());
2606 mock_server_->set_conflict_all_commits(true); 2606 mock_server_->set_conflict_all_commits(true);
2607 EXPECT_TRUE(SyncShareNudge()); 2607 SyncShareNudge();
2608 EXPECT_TRUE(SyncShareNudge()); 2608 SyncShareNudge();
2609 EXPECT_TRUE(SyncShareNudge()); 2609 SyncShareNudge();
2610 { 2610 {
2611 syncable::ReadTransaction trans(FROM_HERE, directory()); 2611 syncable::ReadTransaction trans(FROM_HERE, directory());
2612 Directory::Metahandles children; 2612 Directory::Metahandles children;
2613 directory()->GetChildHandlesById(&trans, root_id_, &children); 2613 directory()->GetChildHandlesById(&trans, root_id_, &children);
2614 EXPECT_EQ(1u, children.size()); 2614 EXPECT_EQ(1u, children.size());
2615 directory()->GetChildHandlesById(&trans, parent_id, &children); 2615 directory()->GetChildHandlesById(&trans, parent_id, &children);
2616 EXPECT_EQ(1u, children.size()); 2616 EXPECT_EQ(1u, children.size());
2617 std::vector<int64> unapplied; 2617 std::vector<int64> unapplied;
2618 directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied); 2618 directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied);
2619 EXPECT_EQ(0u, unapplied.size()); 2619 EXPECT_EQ(0u, unapplied.size());
2620 syncable::Directory::Metahandles unsynced; 2620 syncable::Directory::Metahandles unsynced;
2621 directory()->GetUnsyncedMetaHandles(&trans, &unsynced); 2621 directory()->GetUnsyncedMetaHandles(&trans, &unsynced);
2622 EXPECT_EQ(0u, unsynced.size()); 2622 EXPECT_EQ(0u, unsynced.size());
2623 saw_syncer_event_ = false; 2623 saw_syncer_event_ = false;
2624 } 2624 }
2625 } 2625 }
2626 2626
2627 TEST_F(SyncerTest, CommittingNewDeleted) { 2627 TEST_F(SyncerTest, CommittingNewDeleted) {
2628 { 2628 {
2629 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2629 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2630 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2630 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2631 entry.PutIsUnsynced(true); 2631 entry.PutIsUnsynced(true);
2632 entry.PutIsDel(true); 2632 entry.PutIsDel(true);
2633 } 2633 }
2634 EXPECT_TRUE(SyncShareNudge()); 2634 SyncShareNudge();
2635 EXPECT_EQ(0u, mock_server_->committed_ids().size()); 2635 EXPECT_EQ(0u, mock_server_->committed_ids().size());
2636 } 2636 }
2637 2637
2638 // Original problem synopsis: 2638 // Original problem synopsis:
2639 // Check failed: entry->GetBaseVersion()<= entry->GetServerVersion() 2639 // Check failed: entry->GetBaseVersion()<= entry->GetServerVersion()
2640 // Client creates entry, client finishes committing entry. Between 2640 // Client creates entry, client finishes committing entry. Between
2641 // commit and getting update back, we delete the entry. 2641 // commit and getting update back, we delete the entry.
2642 // We get the update for the entry, but the local one was modified 2642 // We get the update for the entry, but the local one was modified
2643 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. 2643 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set.
2644 // We commit deletion and get a new version number. 2644 // We commit deletion and get a new version number.
2645 // We apply unapplied updates again before we get the update about the deletion. 2645 // We apply unapplied updates again before we get the update about the deletion.
2646 // This means we have an unapplied update where server_version < base_version. 2646 // This means we have an unapplied update where server_version < base_version.
2647 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) { 2647 TEST_F(SyncerTest, UnappliedUpdateDuringCommit) {
2648 // This test is a little fake. 2648 // This test is a little fake.
2649 { 2649 {
2650 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2650 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2651 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2651 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2652 entry.PutId(ids_.FromNumber(20)); 2652 entry.PutId(ids_.FromNumber(20));
2653 entry.PutBaseVersion(1); 2653 entry.PutBaseVersion(1);
2654 entry.PutServerVersion(1); 2654 entry.PutServerVersion(1);
2655 entry.PutServerParentId(ids_.FromNumber(9999)); // Bad parent. 2655 entry.PutServerParentId(ids_.FromNumber(9999)); // Bad parent.
2656 entry.PutIsUnsynced(true); 2656 entry.PutIsUnsynced(true);
2657 entry.PutIsUnappliedUpdate(true); 2657 entry.PutIsUnappliedUpdate(true);
2658 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2658 entry.PutSpecifics(DefaultBookmarkSpecifics());
2659 entry.PutServerSpecifics(DefaultBookmarkSpecifics()); 2659 entry.PutServerSpecifics(DefaultBookmarkSpecifics());
2660 entry.PutIsDel(false); 2660 entry.PutIsDel(false);
2661 } 2661 }
2662 EXPECT_TRUE(SyncShareNudge()); 2662 SyncShareNudge();
2663 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems()); 2663 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems());
2664 saw_syncer_event_ = false; 2664 saw_syncer_event_ = false;
2665 } 2665 }
2666 2666
2667 // Original problem synopsis: 2667 // Original problem synopsis:
2668 // Illegal parent 2668 // Illegal parent
2669 // Unexpected error during sync if we: 2669 // Unexpected error during sync if we:
2670 // make a new folder bob 2670 // make a new folder bob
2671 // wait for sync 2671 // wait for sync
2672 // make a new folder fred 2672 // make a new folder fred
2673 // move bob into fred 2673 // move bob into fred
2674 // remove bob 2674 // remove bob
2675 // remove fred 2675 // remove fred
2676 // if no syncing occured midway, bob will have an illegal parent 2676 // if no syncing occured midway, bob will have an illegal parent
2677 TEST_F(SyncerTest, DeletingEntryInFolder) { 2677 TEST_F(SyncerTest, DeletingEntryInFolder) {
2678 // This test is a little fake. 2678 // This test is a little fake.
2679 int64 existing_metahandle; 2679 int64 existing_metahandle;
2680 { 2680 {
2681 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2681 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2682 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing"); 2682 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing");
2683 ASSERT_TRUE(entry.good()); 2683 ASSERT_TRUE(entry.good());
2684 entry.PutIsDir(true); 2684 entry.PutIsDir(true);
2685 entry.PutSpecifics(DefaultBookmarkSpecifics()); 2685 entry.PutSpecifics(DefaultBookmarkSpecifics());
2686 entry.PutIsUnsynced(true); 2686 entry.PutIsUnsynced(true);
2687 existing_metahandle = entry.GetMetahandle(); 2687 existing_metahandle = entry.GetMetahandle();
2688 } 2688 }
2689 EXPECT_TRUE(SyncShareNudge()); 2689 SyncShareNudge();
2690 { 2690 {
2691 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2691 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2692 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new"); 2692 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new");
2693 ASSERT_TRUE(newfolder.good()); 2693 ASSERT_TRUE(newfolder.good());
2694 newfolder.PutIsDir(true); 2694 newfolder.PutIsDir(true);
2695 newfolder.PutSpecifics(DefaultBookmarkSpecifics()); 2695 newfolder.PutSpecifics(DefaultBookmarkSpecifics());
2696 newfolder.PutIsUnsynced(true); 2696 newfolder.PutIsUnsynced(true);
2697 2697
2698 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); 2698 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle);
2699 ASSERT_TRUE(existing.good()); 2699 ASSERT_TRUE(existing.good());
2700 existing.PutParentId(newfolder.GetId()); 2700 existing.PutParentId(newfolder.GetId());
2701 existing.PutIsUnsynced(true); 2701 existing.PutIsUnsynced(true);
2702 EXPECT_TRUE(existing.GetId().ServerKnows()); 2702 EXPECT_TRUE(existing.GetId().ServerKnows());
2703 2703
2704 newfolder.PutIsDel(true); 2704 newfolder.PutIsDel(true);
2705 existing.PutIsDel(true); 2705 existing.PutIsDel(true);
2706 } 2706 }
2707 EXPECT_TRUE(SyncShareNudge()); 2707 SyncShareNudge();
2708 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict); 2708 EXPECT_EQ(0, GetCommitCounters(BOOKMARKS).num_commits_conflict);
2709 } 2709 }
2710 2710
2711 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2711 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2712 int64 newfolder_metahandle; 2712 int64 newfolder_metahandle;
2713 2713
2714 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, 2714 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10,
2715 foreign_cache_guid(), "-1"); 2715 foreign_cache_guid(), "-1");
2716 EXPECT_TRUE(SyncShareNudge()); 2716 SyncShareNudge();
2717 { 2717 {
2718 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2718 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2719 MutableEntry newfolder( 2719 MutableEntry newfolder(
2720 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local"); 2720 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local");
2721 ASSERT_TRUE(newfolder.good()); 2721 ASSERT_TRUE(newfolder.good());
2722 newfolder.PutIsUnsynced(true); 2722 newfolder.PutIsUnsynced(true);
2723 newfolder.PutIsDir(true); 2723 newfolder.PutIsDir(true);
2724 newfolder.PutSpecifics(DefaultBookmarkSpecifics()); 2724 newfolder.PutSpecifics(DefaultBookmarkSpecifics());
2725 newfolder_metahandle = newfolder.GetMetahandle(); 2725 newfolder_metahandle = newfolder.GetMetahandle();
2726 } 2726 }
2727 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, 2727 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20,
2728 foreign_cache_guid(), "-1"); 2728 foreign_cache_guid(), "-1");
2729 mock_server_->SetLastUpdateDeleted(); 2729 mock_server_->SetLastUpdateDeleted();
2730 SyncShareConfigure(); 2730 SyncShareConfigure();
2731 { 2731 {
2732 syncable::ReadTransaction trans(FROM_HERE, directory()); 2732 syncable::ReadTransaction trans(FROM_HERE, directory());
2733 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); 2733 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle);
2734 ASSERT_TRUE(entry.good()); 2734 ASSERT_TRUE(entry.good());
2735 } 2735 }
2736 } 2736 }
2737 2737
2738 TEST_F(SyncerTest, FolderSwapUpdate) { 2738 TEST_F(SyncerTest, FolderSwapUpdate) {
2739 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, 2739 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10,
2740 foreign_cache_guid(), "-7801"); 2740 foreign_cache_guid(), "-7801");
2741 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10, 2741 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10,
2742 foreign_cache_guid(), "-1024"); 2742 foreign_cache_guid(), "-1024");
2743 EXPECT_TRUE(SyncShareNudge()); 2743 SyncShareNudge();
2744 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20, 2744 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20,
2745 foreign_cache_guid(), "-1024"); 2745 foreign_cache_guid(), "-1024");
2746 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20, 2746 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20,
2747 foreign_cache_guid(), "-7801"); 2747 foreign_cache_guid(), "-7801");
2748 EXPECT_TRUE(SyncShareNudge()); 2748 SyncShareNudge();
2749 { 2749 {
2750 syncable::ReadTransaction trans(FROM_HERE, directory()); 2750 syncable::ReadTransaction trans(FROM_HERE, directory());
2751 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2751 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2752 ASSERT_TRUE(id1.good()); 2752 ASSERT_TRUE(id1.good());
2753 EXPECT_TRUE("fred" == id1.GetNonUniqueName()); 2753 EXPECT_TRUE("fred" == id1.GetNonUniqueName());
2754 EXPECT_TRUE(root_id_ == id1.GetParentId()); 2754 EXPECT_TRUE(root_id_ == id1.GetParentId());
2755 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2755 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2756 ASSERT_TRUE(id2.good()); 2756 ASSERT_TRUE(id2.good());
2757 EXPECT_TRUE("bob" == id2.GetNonUniqueName()); 2757 EXPECT_TRUE("bob" == id2.GetNonUniqueName());
2758 EXPECT_TRUE(root_id_ == id2.GetParentId()); 2758 EXPECT_TRUE(root_id_ == id2.GetParentId());
2759 } 2759 }
2760 saw_syncer_event_ = false; 2760 saw_syncer_event_ = false;
2761 } 2761 }
2762 2762
2763 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { 2763 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) {
2764 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, 2764 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10,
2765 foreign_cache_guid(), "-7801"); 2765 foreign_cache_guid(), "-7801");
2766 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10, 2766 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10,
2767 foreign_cache_guid(), "-1024"); 2767 foreign_cache_guid(), "-1024");
2768 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10, 2768 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10,
2769 foreign_cache_guid(), "-4096"); 2769 foreign_cache_guid(), "-4096");
2770 EXPECT_TRUE(SyncShareNudge()); 2770 SyncShareNudge();
2771 { 2771 {
2772 syncable::ReadTransaction trans(FROM_HERE, directory()); 2772 syncable::ReadTransaction trans(FROM_HERE, directory());
2773 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2773 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2774 ASSERT_TRUE(id1.good()); 2774 ASSERT_TRUE(id1.good());
2775 EXPECT_TRUE("bob" == id1.GetNonUniqueName()); 2775 EXPECT_TRUE("bob" == id1.GetNonUniqueName());
2776 EXPECT_TRUE(root_id_ == id1.GetParentId()); 2776 EXPECT_TRUE(root_id_ == id1.GetParentId());
2777 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2777 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2778 ASSERT_TRUE(id2.good()); 2778 ASSERT_TRUE(id2.good());
2779 EXPECT_TRUE("fred" == id2.GetNonUniqueName()); 2779 EXPECT_TRUE("fred" == id2.GetNonUniqueName());
2780 EXPECT_TRUE(root_id_ == id2.GetParentId()); 2780 EXPECT_TRUE(root_id_ == id2.GetParentId());
2781 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); 2781 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096));
2782 ASSERT_TRUE(id3.good()); 2782 ASSERT_TRUE(id3.good());
2783 EXPECT_TRUE("alice" == id3.GetNonUniqueName()); 2783 EXPECT_TRUE("alice" == id3.GetNonUniqueName());
2784 EXPECT_TRUE(root_id_ == id3.GetParentId()); 2784 EXPECT_TRUE(root_id_ == id3.GetParentId());
2785 } 2785 }
2786 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20, 2786 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20,
2787 foreign_cache_guid(), "-1024"); 2787 foreign_cache_guid(), "-1024");
2788 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20, 2788 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20,
2789 foreign_cache_guid(), "-7801"); 2789 foreign_cache_guid(), "-7801");
2790 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20, 2790 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20,
2791 foreign_cache_guid(), "-4096"); 2791 foreign_cache_guid(), "-4096");
2792 EXPECT_TRUE(SyncShareNudge()); 2792 SyncShareNudge();
2793 { 2793 {
2794 syncable::ReadTransaction trans(FROM_HERE, directory()); 2794 syncable::ReadTransaction trans(FROM_HERE, directory());
2795 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2795 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2796 ASSERT_TRUE(id1.good()); 2796 ASSERT_TRUE(id1.good());
2797 EXPECT_TRUE("fred" == id1.GetNonUniqueName()); 2797 EXPECT_TRUE("fred" == id1.GetNonUniqueName());
2798 EXPECT_TRUE(root_id_ == id1.GetParentId()); 2798 EXPECT_TRUE(root_id_ == id1.GetParentId());
2799 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2799 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2800 ASSERT_TRUE(id2.good()); 2800 ASSERT_TRUE(id2.good());
2801 EXPECT_TRUE("bob" == id2.GetNonUniqueName()); 2801 EXPECT_TRUE("bob" == id2.GetNonUniqueName());
2802 EXPECT_TRUE(root_id_ == id2.GetParentId()); 2802 EXPECT_TRUE(root_id_ == id2.GetParentId());
(...skipping 17 matching lines...) Expand all
2820 string nameutf8 = base::StringPrintf("%d", i); 2820 string nameutf8 = base::StringPrintf("%d", i);
2821 string name(nameutf8.begin(), nameutf8.end()); 2821 string name(nameutf8.begin(), nameutf8.end());
2822 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 2822 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
2823 e.PutIsUnsynced(true); 2823 e.PutIsUnsynced(true);
2824 e.PutIsDir(true); 2824 e.PutIsDir(true);
2825 e.PutSpecifics(DefaultBookmarkSpecifics()); 2825 e.PutSpecifics(DefaultBookmarkSpecifics());
2826 } 2826 }
2827 } 2827 }
2828 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2828 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2829 2829
2830 EXPECT_TRUE(SyncShareNudge()); 2830 SyncShareNudge();
2831 EXPECT_EQ(num_batches, mock_server_->commit_messages().size()); 2831 EXPECT_EQ(num_batches, mock_server_->commit_messages().size());
2832 EXPECT_EQ(0, directory()->unsynced_entity_count()); 2832 EXPECT_EQ(0, directory()->unsynced_entity_count());
2833 } 2833 }
2834 2834
2835 // Test that a single failure to contact the server will cause us to exit the 2835 // Test that a single failure to contact the server will cause us to exit the
2836 // commit loop immediately. 2836 // commit loop immediately.
2837 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { 2837 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) {
2838 uint32 num_batches = 3; 2838 uint32 num_batches = 3;
2839 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 2839 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2840 { 2840 {
2841 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2841 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2842 for (uint32 i = 0; i < items_to_commit; i++) { 2842 for (uint32 i = 0; i < items_to_commit; i++) {
2843 string nameutf8 = base::StringPrintf("%d", i); 2843 string nameutf8 = base::StringPrintf("%d", i);
2844 string name(nameutf8.begin(), nameutf8.end()); 2844 string name(nameutf8.begin(), nameutf8.end());
2845 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 2845 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
2846 e.PutIsUnsynced(true); 2846 e.PutIsUnsynced(true);
2847 e.PutIsDir(true); 2847 e.PutIsDir(true);
2848 e.PutSpecifics(DefaultBookmarkSpecifics()); 2848 e.PutSpecifics(DefaultBookmarkSpecifics());
2849 } 2849 }
2850 } 2850 }
2851 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2851 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2852 2852
2853 // The second commit should fail. It will be preceded by one successful 2853 // The second commit should fail. It will be preceded by one successful
2854 // GetUpdate and one succesful commit. 2854 // GetUpdate and one succesful commit.
2855 mock_server_->FailNthPostBufferToPathCall(3); 2855 mock_server_->FailNthPostBufferToPathCall(3);
2856 EXPECT_FALSE(SyncShareNudge()); 2856 SyncShareNudge();
2857 2857
2858 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 2858 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2859 EXPECT_EQ(SYNC_SERVER_ERROR, 2859 EXPECT_EQ(SYNC_SERVER_ERROR,
2860 session_->status_controller().model_neutral_state().commit_result); 2860 session_->status_controller().model_neutral_state().commit_result);
2861 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, 2861 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize,
2862 directory()->unsynced_entity_count()); 2862 directory()->unsynced_entity_count());
2863 } 2863 }
2864 2864
2865 // Test that a single conflict response from the server will cause us to exit 2865 // Test that a single conflict response from the server will cause us to exit
2866 // the commit loop immediately. 2866 // the commit loop immediately.
2867 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { 2867 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) {
2868 uint32 num_batches = 2; 2868 uint32 num_batches = 2;
2869 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 2869 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2870 { 2870 {
2871 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2871 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2872 for (uint32 i = 0; i < items_to_commit; i++) { 2872 for (uint32 i = 0; i < items_to_commit; i++) {
2873 string nameutf8 = base::StringPrintf("%d", i); 2873 string nameutf8 = base::StringPrintf("%d", i);
2874 string name(nameutf8.begin(), nameutf8.end()); 2874 string name(nameutf8.begin(), nameutf8.end());
2875 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name); 2875 MutableEntry e(&trans, CREATE, BOOKMARKS, trans.root_id(), name);
2876 e.PutIsUnsynced(true); 2876 e.PutIsUnsynced(true);
2877 e.PutIsDir(true); 2877 e.PutIsDir(true);
2878 e.PutSpecifics(DefaultBookmarkSpecifics()); 2878 e.PutSpecifics(DefaultBookmarkSpecifics());
2879 } 2879 }
2880 } 2880 }
2881 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2881 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2882 2882
2883 // Return a CONFLICT response for the first item. 2883 // Return a CONFLICT response for the first item.
2884 mock_server_->set_conflict_n_commits(1); 2884 mock_server_->set_conflict_n_commits(1);
2885 EXPECT_FALSE(SyncShareNudge()); 2885 SyncShareNudge();
2886 2886
2887 // We should stop looping at the first sign of trouble. 2887 // We should stop looping at the first sign of trouble.
2888 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 2888 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2889 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), 2889 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1),
2890 directory()->unsynced_entity_count()); 2890 directory()->unsynced_entity_count());
2891 } 2891 }
2892 2892
2893 // Tests that sending debug info events works. 2893 // Tests that sending debug info events works.
2894 TEST_F(SyncerTest, SendDebugInfoEventsOnGetUpdates_HappyCase) { 2894 TEST_F(SyncerTest, SendDebugInfoEventsOnGetUpdates_HappyCase) {
2895 debug_info_getter_->AddDebugEvent(); 2895 debug_info_getter_->AddDebugEvent();
2896 debug_info_getter_->AddDebugEvent(); 2896 debug_info_getter_->AddDebugEvent();
2897 2897
2898 EXPECT_TRUE(SyncShareNudge()); 2898 SyncShareNudge();
2899 2899
2900 // Verify we received one GetUpdates request with two debug info events. 2900 // Verify we received one GetUpdates request with two debug info events.
2901 EXPECT_EQ(1U, mock_server_->requests().size()); 2901 EXPECT_EQ(1U, mock_server_->requests().size());
2902 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2902 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2903 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); 2903 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size());
2904 2904
2905 EXPECT_TRUE(SyncShareNudge()); 2905 SyncShareNudge();
2906 2906
2907 // See that we received another GetUpdates request, but that it contains no 2907 // See that we received another GetUpdates request, but that it contains no
2908 // debug info events. 2908 // debug info events.
2909 EXPECT_EQ(2U, mock_server_->requests().size()); 2909 EXPECT_EQ(2U, mock_server_->requests().size());
2910 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2910 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2911 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); 2911 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size());
2912 2912
2913 debug_info_getter_->AddDebugEvent(); 2913 debug_info_getter_->AddDebugEvent();
2914 2914
2915 EXPECT_TRUE(SyncShareNudge()); 2915 SyncShareNudge();
2916 2916
2917 // See that we received another GetUpdates request and it contains one debug 2917 // See that we received another GetUpdates request and it contains one debug
2918 // info event. 2918 // info event.
2919 EXPECT_EQ(3U, mock_server_->requests().size()); 2919 EXPECT_EQ(3U, mock_server_->requests().size());
2920 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2920 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2921 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); 2921 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size());
2922 } 2922 }
2923 2923
2924 // Tests that debug info events are dropped on server error. 2924 // Tests that debug info events are dropped on server error.
2925 TEST_F(SyncerTest, SendDebugInfoEventsOnGetUpdates_PostFailsDontDrop) { 2925 TEST_F(SyncerTest, SendDebugInfoEventsOnGetUpdates_PostFailsDontDrop) {
2926 debug_info_getter_->AddDebugEvent(); 2926 debug_info_getter_->AddDebugEvent();
2927 debug_info_getter_->AddDebugEvent(); 2927 debug_info_getter_->AddDebugEvent();
2928 2928
2929 mock_server_->FailNextPostBufferToPathCall(); 2929 mock_server_->FailNextPostBufferToPathCall();
2930 EXPECT_FALSE(SyncShareNudge()); 2930 SyncShareNudge();
2931 2931
2932 // Verify we attempted to send one GetUpdates request with two debug info 2932 // Verify we attempted to send one GetUpdates request with two debug info
2933 // events. 2933 // events.
2934 EXPECT_EQ(1U, mock_server_->requests().size()); 2934 EXPECT_EQ(1U, mock_server_->requests().size());
2935 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2935 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2936 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); 2936 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size());
2937 2937
2938 EXPECT_TRUE(SyncShareNudge()); 2938 SyncShareNudge();
2939 2939
2940 // See that the client resent the two debug info events. 2940 // See that the client resent the two debug info events.
2941 EXPECT_EQ(2U, mock_server_->requests().size()); 2941 EXPECT_EQ(2U, mock_server_->requests().size());
2942 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2942 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2943 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size()); 2943 EXPECT_EQ(2, mock_server_->last_request().debug_info().events_size());
2944 2944
2945 // The previous send was successful so this next one shouldn't generate any 2945 // The previous send was successful so this next one shouldn't generate any
2946 // debug info events. 2946 // debug info events.
2947 EXPECT_TRUE(SyncShareNudge()); 2947 SyncShareNudge();
2948 EXPECT_EQ(3U, mock_server_->requests().size()); 2948 EXPECT_EQ(3U, mock_server_->requests().size());
2949 ASSERT_TRUE(mock_server_->last_request().has_get_updates()); 2949 ASSERT_TRUE(mock_server_->last_request().has_get_updates());
2950 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); 2950 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size());
2951 } 2951 }
2952 2952
2953 // Tests that commit failure with conflict will trigger GetUpdates for next 2953 // Tests that commit failure with conflict will trigger GetUpdates for next
2954 // cycle of sync 2954 // sycle of sync
2955 TEST_F(SyncerTest, CommitFailureWithConflict) { 2955 TEST_F(SyncerTest, CommitFailureWithConflict) {
2956 ConfigureNoGetUpdatesRequired(); 2956 ConfigureNoGetUpdatesRequired();
2957 CreateUnsyncedDirectory("X", "id_X"); 2957 CreateUnsyncedDirectory("X", "id_X");
2958 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); 2958 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
2959 2959
2960 EXPECT_TRUE(SyncShareNudge()); 2960 SyncShareNudge();
2961 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); 2961 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
2962 2962
2963 CreateUnsyncedDirectory("Y", "id_Y"); 2963 CreateUnsyncedDirectory("Y", "id_Y");
2964 mock_server_->set_conflict_n_commits(1); 2964 mock_server_->set_conflict_n_commits(1);
2965 EXPECT_FALSE(SyncShareNudge()); 2965 SyncShareNudge();
2966 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired()); 2966 EXPECT_TRUE(nudge_tracker_.IsGetUpdatesRequired());
2967 2967
2968 nudge_tracker_.RecordSuccessfulSyncCycle(); 2968 nudge_tracker_.RecordSuccessfulSyncCycle();
2969 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired()); 2969 EXPECT_FALSE(nudge_tracker_.IsGetUpdatesRequired());
2970 } 2970 }
2971 2971
2972 // Tests that sending debug info events on Commit works. 2972 // Tests that sending debug info events on Commit works.
2973 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_HappyCase) { 2973 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_HappyCase) {
2974 // Make sure GetUpdate isn't call as it would "steal" debug info events before 2974 // Make sure GetUpdate isn't call as it would "steal" debug info events before
2975 // Commit has a chance to send them. 2975 // Commit has a chance to send them.
2976 ConfigureNoGetUpdatesRequired(); 2976 ConfigureNoGetUpdatesRequired();
2977 2977
2978 // Generate a debug info event and trigger a commit. 2978 // Generate a debug info event and trigger a commit.
2979 debug_info_getter_->AddDebugEvent(); 2979 debug_info_getter_->AddDebugEvent();
2980 CreateUnsyncedDirectory("X", "id_X"); 2980 CreateUnsyncedDirectory("X", "id_X");
2981 EXPECT_TRUE(SyncShareNudge()); 2981 SyncShareNudge();
2982 2982
2983 // Verify that the last request received is a Commit and that it contains a 2983 // Verify that the last request received is a Commit and that it contains a
2984 // debug info event. 2984 // debug info event.
2985 EXPECT_EQ(1U, mock_server_->requests().size()); 2985 EXPECT_EQ(1U, mock_server_->requests().size());
2986 ASSERT_TRUE(mock_server_->last_request().has_commit()); 2986 ASSERT_TRUE(mock_server_->last_request().has_commit());
2987 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); 2987 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size());
2988 2988
2989 // Generate another commit, but no debug info event. 2989 // Generate another commit, but no debug info event.
2990 CreateUnsyncedDirectory("Y", "id_Y"); 2990 CreateUnsyncedDirectory("Y", "id_Y");
2991 EXPECT_TRUE(SyncShareNudge()); 2991 SyncShareNudge();
2992 2992
2993 // See that it was received and contains no debug info events. 2993 // See that it was received and contains no debug info events.
2994 EXPECT_EQ(2U, mock_server_->requests().size()); 2994 EXPECT_EQ(2U, mock_server_->requests().size());
2995 ASSERT_TRUE(mock_server_->last_request().has_commit()); 2995 ASSERT_TRUE(mock_server_->last_request().has_commit());
2996 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); 2996 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size());
2997 } 2997 }
2998 2998
2999 // Tests that debug info events are not dropped on server error. 2999 // Tests that debug info events are not dropped on server error.
3000 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_PostFailsDontDrop) { 3000 TEST_F(SyncerTest, SendDebugInfoEventsOnCommit_PostFailsDontDrop) {
3001 // Make sure GetUpdate isn't call as it would "steal" debug info events before 3001 // Make sure GetUpdate isn't call as it would "steal" debug info events before
3002 // Commit has a chance to send them. 3002 // Commit has a chance to send them.
3003 ConfigureNoGetUpdatesRequired(); 3003 ConfigureNoGetUpdatesRequired();
3004 3004
3005 mock_server_->FailNextPostBufferToPathCall(); 3005 mock_server_->FailNextPostBufferToPathCall();
3006 3006
3007 // Generate a debug info event and trigger a commit. 3007 // Generate a debug info event and trigger a commit.
3008 debug_info_getter_->AddDebugEvent(); 3008 debug_info_getter_->AddDebugEvent();
3009 CreateUnsyncedDirectory("X", "id_X"); 3009 CreateUnsyncedDirectory("X", "id_X");
3010 EXPECT_FALSE(SyncShareNudge()); 3010 SyncShareNudge();
3011 3011
3012 // Verify that the last request sent is a Commit and that it contains a debug 3012 // Verify that the last request sent is a Commit and that it contains a debug
3013 // info event. 3013 // info event.
3014 EXPECT_EQ(1U, mock_server_->requests().size()); 3014 EXPECT_EQ(1U, mock_server_->requests().size());
3015 ASSERT_TRUE(mock_server_->last_request().has_commit()); 3015 ASSERT_TRUE(mock_server_->last_request().has_commit());
3016 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); 3016 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size());
3017 3017
3018 // Try again. 3018 // Try again.
3019 EXPECT_TRUE(SyncShareNudge()); 3019 SyncShareNudge();
3020 3020
3021 // Verify that we've received another Commit and that it contains a debug info 3021 // Verify that we've received another Commit and that it contains a debug info
3022 // event (just like the previous one). 3022 // event (just like the previous one).
3023 EXPECT_EQ(2U, mock_server_->requests().size()); 3023 EXPECT_EQ(2U, mock_server_->requests().size());
3024 ASSERT_TRUE(mock_server_->last_request().has_commit()); 3024 ASSERT_TRUE(mock_server_->last_request().has_commit());
3025 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size()); 3025 EXPECT_EQ(1, mock_server_->last_request().debug_info().events_size());
3026 3026
3027 // Generate another commit and try again. 3027 // Generate another commit and try again.
3028 CreateUnsyncedDirectory("Y", "id_Y"); 3028 CreateUnsyncedDirectory("Y", "id_Y");
3029 EXPECT_TRUE(SyncShareNudge()); 3029 SyncShareNudge();
3030 3030
3031 // See that it was received and contains no debug info events. 3031 // See that it was received and contains no debug info events.
3032 EXPECT_EQ(3U, mock_server_->requests().size()); 3032 EXPECT_EQ(3U, mock_server_->requests().size());
3033 ASSERT_TRUE(mock_server_->last_request().has_commit()); 3033 ASSERT_TRUE(mock_server_->last_request().has_commit());
3034 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size()); 3034 EXPECT_EQ(0, mock_server_->last_request().debug_info().events_size());
3035 } 3035 }
3036 3036
3037 TEST_F(SyncerTest, HugeConflict) { 3037 TEST_F(SyncerTest, HugeConflict) {
3038 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 3038 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
3039 3039
3040 syncable::Id parent_id = ids_.NewServerId(); 3040 syncable::Id parent_id = ids_.NewServerId();
3041 syncable::Id last_id = parent_id; 3041 syncable::Id last_id = parent_id;
3042 vector<syncable::Id> tree_ids; 3042 vector<syncable::Id> tree_ids;
3043 3043
3044 // Create a lot of updates for which the parent does not exist yet. 3044 // Create a lot of updates for which the parent does not exist yet.
3045 // Generate a huge deep tree which should all fail to apply at first. 3045 // Generate a huge deep tree which should all fail to apply at first.
3046 { 3046 {
3047 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3047 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3048 for (int i = 0; i < item_count ; i++) { 3048 for (int i = 0; i < item_count ; i++) {
3049 syncable::Id next_id = ids_.NewServerId(); 3049 syncable::Id next_id = ids_.NewServerId();
3050 syncable::Id local_id = ids_.NewLocalId(); 3050 syncable::Id local_id = ids_.NewLocalId();
3051 tree_ids.push_back(next_id); 3051 tree_ids.push_back(next_id);
3052 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20, 3052 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20,
3053 foreign_cache_guid(), 3053 foreign_cache_guid(),
3054 local_id.GetServerId()); 3054 local_id.GetServerId());
3055 last_id = next_id; 3055 last_id = next_id;
3056 } 3056 }
3057 } 3057 }
3058 EXPECT_TRUE(SyncShareNudge()); 3058 SyncShareNudge();
3059 3059
3060 // Check they're in the expected conflict state. 3060 // Check they're in the expected conflict state.
3061 { 3061 {
3062 syncable::ReadTransaction trans(FROM_HERE, directory()); 3062 syncable::ReadTransaction trans(FROM_HERE, directory());
3063 for (int i = 0; i < item_count; i++) { 3063 for (int i = 0; i < item_count; i++) {
3064 Entry e(&trans, GET_BY_ID, tree_ids[i]); 3064 Entry e(&trans, GET_BY_ID, tree_ids[i]);
3065 // They should all exist but none should be applied. 3065 // They should all exist but none should be applied.
3066 ASSERT_TRUE(e.good()); 3066 ASSERT_TRUE(e.good());
3067 EXPECT_TRUE(e.GetIsDel()); 3067 EXPECT_TRUE(e.GetIsDel());
3068 EXPECT_TRUE(e.GetIsUnappliedUpdate()); 3068 EXPECT_TRUE(e.GetIsUnappliedUpdate());
3069 } 3069 }
3070 } 3070 }
3071 3071
3072 // Add the missing parent directory. 3072 // Add the missing parent directory.
3073 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(), 3073 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(),
3074 "BOB", 2, 20, foreign_cache_guid(), "-3500"); 3074 "BOB", 2, 20, foreign_cache_guid(), "-3500");
3075 EXPECT_TRUE(SyncShareNudge()); 3075 SyncShareNudge();
3076 3076
3077 // Now they should all be OK. 3077 // Now they should all be OK.
3078 { 3078 {
3079 syncable::ReadTransaction trans(FROM_HERE, directory()); 3079 syncable::ReadTransaction trans(FROM_HERE, directory());
3080 for (int i = 0; i < item_count; i++) { 3080 for (int i = 0; i < item_count; i++) {
3081 Entry e(&trans, GET_BY_ID, tree_ids[i]); 3081 Entry e(&trans, GET_BY_ID, tree_ids[i]);
3082 ASSERT_TRUE(e.good()); 3082 ASSERT_TRUE(e.good());
3083 EXPECT_FALSE(e.GetIsDel()); 3083 EXPECT_FALSE(e.GetIsDel());
3084 EXPECT_FALSE(e.GetIsUnappliedUpdate()); 3084 EXPECT_FALSE(e.GetIsUnappliedUpdate());
3085 } 3085 }
3086 } 3086 }
3087 } 3087 }
3088 3088
3089 TEST_F(SyncerTest, DontCrashOnCaseChange) { 3089 TEST_F(SyncerTest, DontCrashOnCaseChange) {
3090 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, 3090 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10,
3091 foreign_cache_guid(), "-1"); 3091 foreign_cache_guid(), "-1");
3092 EXPECT_TRUE(SyncShareNudge()); 3092 SyncShareNudge();
3093 { 3093 {
3094 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3094 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3095 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1)); 3095 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1));
3096 ASSERT_TRUE(e.good()); 3096 ASSERT_TRUE(e.good());
3097 e.PutIsUnsynced(true); 3097 e.PutIsUnsynced(true);
3098 } 3098 }
3099 mock_server_->set_conflict_all_commits(true); 3099 mock_server_->set_conflict_all_commits(true);
3100 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20, 3100 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20,
3101 foreign_cache_guid(), "-1"); 3101 foreign_cache_guid(), "-1");
3102 EXPECT_FALSE(SyncShareNudge()); // USED TO CAUSE AN ASSERT 3102 SyncShareNudge(); // USED TO CAUSE AN ASSERT
3103 saw_syncer_event_ = false; 3103 saw_syncer_event_ = false;
3104 } 3104 }
3105 3105
3106 TEST_F(SyncerTest, UnsyncedItemAndUpdate) { 3106 TEST_F(SyncerTest, UnsyncedItemAndUpdate) {
3107 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, 3107 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10,
3108 foreign_cache_guid(), "-1"); 3108 foreign_cache_guid(), "-1");
3109 EXPECT_TRUE(SyncShareNudge()); 3109 SyncShareNudge();
3110 mock_server_->set_conflict_all_commits(true); 3110 mock_server_->set_conflict_all_commits(true);
3111 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20, 3111 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20,
3112 foreign_cache_guid(), "-2"); 3112 foreign_cache_guid(), "-2");
3113 EXPECT_TRUE(SyncShareNudge()); // USED TO CAUSE AN ASSERT 3113 SyncShareNudge(); // USED TO CAUSE AN ASSERT
3114 saw_syncer_event_ = false; 3114 saw_syncer_event_ = false;
3115 } 3115 }
3116 3116
3117 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { 3117 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) {
3118 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, 3118 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10,
3119 foreign_cache_guid(), "-1"); 3119 foreign_cache_guid(), "-1");
3120 EXPECT_TRUE(SyncShareNudge()); 3120 SyncShareNudge();
3121 int64 local_folder_handle; 3121 int64 local_folder_handle;
3122 syncable::Id local_folder_id; 3122 syncable::Id local_folder_id;
3123 { 3123 {
3124 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3124 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3125 MutableEntry new_entry( 3125 MutableEntry new_entry(
3126 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm"); 3126 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm");
3127 ASSERT_TRUE(new_entry.good()); 3127 ASSERT_TRUE(new_entry.good());
3128 local_folder_id = new_entry.GetId(); 3128 local_folder_id = new_entry.GetId();
3129 local_folder_handle = new_entry.GetMetahandle(); 3129 local_folder_handle = new_entry.GetMetahandle();
3130 new_entry.PutIsUnsynced(true); 3130 new_entry.PutIsUnsynced(true);
3131 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); 3131 new_entry.PutSpecifics(DefaultBookmarkSpecifics());
3132 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3132 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3133 ASSERT_TRUE(old.good()); 3133 ASSERT_TRUE(old.good());
3134 WriteTestDataToEntry(&wtrans, &old); 3134 WriteTestDataToEntry(&wtrans, &old);
3135 } 3135 }
3136 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, 3136 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20,
3137 foreign_cache_guid(), "-1"); 3137 foreign_cache_guid(), "-1");
3138 mock_server_->set_conflict_all_commits(true); 3138 mock_server_->set_conflict_all_commits(true);
3139 EXPECT_FALSE(SyncShareNudge()); 3139 SyncShareNudge();
3140 saw_syncer_event_ = false; 3140 saw_syncer_event_ = false;
3141 { 3141 {
3142 // Update #20 should have been dropped in favor of the local version. 3142 // Update #20 should have been dropped in favor of the local version.
3143 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3143 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3144 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3144 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3145 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3145 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3146 ASSERT_TRUE(server.good()); 3146 ASSERT_TRUE(server.good());
3147 ASSERT_TRUE(local.good()); 3147 ASSERT_TRUE(local.good());
3148 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle()); 3148 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle());
3149 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3149 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3150 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3150 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3151 EXPECT_TRUE(server.GetIsUnsynced()); 3151 EXPECT_TRUE(server.GetIsUnsynced());
3152 EXPECT_TRUE(local.GetIsUnsynced()); 3152 EXPECT_TRUE(local.GetIsUnsynced());
3153 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); 3153 EXPECT_EQ("Foo.htm", server.GetNonUniqueName());
3154 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3154 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3155 } 3155 }
3156 // Allow local changes to commit. 3156 // Allow local changes to commit.
3157 mock_server_->set_conflict_all_commits(false); 3157 mock_server_->set_conflict_all_commits(false);
3158 EXPECT_TRUE(SyncShareNudge()); 3158 SyncShareNudge();
3159 saw_syncer_event_ = false; 3159 saw_syncer_event_ = false;
3160 3160
3161 // Now add a server change to make the two names equal. There should 3161 // Now add a server change to make the two names equal. There should
3162 // be no conflict with that, since names are not unique. 3162 // be no conflict with that, since names are not unique.
3163 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, 3163 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30,
3164 foreign_cache_guid(), "-1"); 3164 foreign_cache_guid(), "-1");
3165 EXPECT_TRUE(SyncShareNudge()); 3165 SyncShareNudge();
3166 saw_syncer_event_ = false; 3166 saw_syncer_event_ = false;
3167 { 3167 {
3168 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3168 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3169 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3169 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3170 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3170 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3171 ASSERT_TRUE(server.good()); 3171 ASSERT_TRUE(server.good());
3172 ASSERT_TRUE(local.good()); 3172 ASSERT_TRUE(local.good());
3173 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle()); 3173 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle());
3174 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3174 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3175 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3175 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3176 EXPECT_FALSE(server.GetIsUnsynced()); 3176 EXPECT_FALSE(server.GetIsUnsynced());
3177 EXPECT_FALSE(local.GetIsUnsynced()); 3177 EXPECT_FALSE(local.GetIsUnsynced());
3178 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); 3178 EXPECT_EQ("Bar.htm", server.GetNonUniqueName());
3179 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3179 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3180 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 3180 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
3181 server.GetSpecifics().bookmark().url()); 3181 server.GetSpecifics().bookmark().url());
3182 } 3182 }
3183 } 3183 }
3184 3184
3185 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. 3185 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol.
3186 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { 3186 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) {
3187 mock_server_->set_use_legacy_bookmarks_protocol(true); 3187 mock_server_->set_use_legacy_bookmarks_protocol(true);
3188 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10, 3188 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10,
3189 foreign_cache_guid(), "-1"); 3189 foreign_cache_guid(), "-1");
3190 EXPECT_TRUE(SyncShareNudge()); 3190 SyncShareNudge();
3191 int64 local_folder_handle; 3191 int64 local_folder_handle;
3192 syncable::Id local_folder_id; 3192 syncable::Id local_folder_id;
3193 { 3193 {
3194 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3194 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3195 MutableEntry new_entry( 3195 MutableEntry new_entry(
3196 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm"); 3196 &wtrans, CREATE, BOOKMARKS, wtrans.root_id(), "Bar.htm");
3197 ASSERT_TRUE(new_entry.good()); 3197 ASSERT_TRUE(new_entry.good());
3198 local_folder_id = new_entry.GetId(); 3198 local_folder_id = new_entry.GetId();
3199 local_folder_handle = new_entry.GetMetahandle(); 3199 local_folder_handle = new_entry.GetMetahandle();
3200 new_entry.PutIsUnsynced(true); 3200 new_entry.PutIsUnsynced(true);
3201 new_entry.PutSpecifics(DefaultBookmarkSpecifics()); 3201 new_entry.PutSpecifics(DefaultBookmarkSpecifics());
3202 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3202 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3203 ASSERT_TRUE(old.good()); 3203 ASSERT_TRUE(old.good());
3204 WriteTestDataToEntry(&wtrans, &old); 3204 WriteTestDataToEntry(&wtrans, &old);
3205 } 3205 }
3206 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20, 3206 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20,
3207 foreign_cache_guid(), "-1"); 3207 foreign_cache_guid(), "-1");
3208 mock_server_->set_conflict_all_commits(true); 3208 mock_server_->set_conflict_all_commits(true);
3209 EXPECT_FALSE(SyncShareNudge()); 3209 SyncShareNudge();
3210 saw_syncer_event_ = false; 3210 saw_syncer_event_ = false;
3211 { 3211 {
3212 // Update #20 should have been dropped in favor of the local version. 3212 // Update #20 should have been dropped in favor of the local version.
3213 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3213 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3214 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3214 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3215 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3215 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3216 ASSERT_TRUE(server.good()); 3216 ASSERT_TRUE(server.good());
3217 ASSERT_TRUE(local.good()); 3217 ASSERT_TRUE(local.good());
3218 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle()); 3218 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle());
3219 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3219 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3220 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3220 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3221 EXPECT_TRUE(server.GetIsUnsynced()); 3221 EXPECT_TRUE(server.GetIsUnsynced());
3222 EXPECT_TRUE(local.GetIsUnsynced()); 3222 EXPECT_TRUE(local.GetIsUnsynced());
3223 EXPECT_EQ("Foo.htm", server.GetNonUniqueName()); 3223 EXPECT_EQ("Foo.htm", server.GetNonUniqueName());
3224 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3224 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3225 } 3225 }
3226 // Allow local changes to commit. 3226 // Allow local changes to commit.
3227 mock_server_->set_conflict_all_commits(false); 3227 mock_server_->set_conflict_all_commits(false);
3228 EXPECT_TRUE(SyncShareNudge()); 3228 SyncShareNudge();
3229 saw_syncer_event_ = false; 3229 saw_syncer_event_ = false;
3230 3230
3231 // Now add a server change to make the two names equal. There should 3231 // Now add a server change to make the two names equal. There should
3232 // be no conflict with that, since names are not unique. 3232 // be no conflict with that, since names are not unique.
3233 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30, 3233 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30,
3234 foreign_cache_guid(), "-1"); 3234 foreign_cache_guid(), "-1");
3235 EXPECT_TRUE(SyncShareNudge()); 3235 SyncShareNudge();
3236 saw_syncer_event_ = false; 3236 saw_syncer_event_ = false;
3237 { 3237 {
3238 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3238 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3239 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3239 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3240 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 3240 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
3241 ASSERT_TRUE(server.good()); 3241 ASSERT_TRUE(server.good());
3242 ASSERT_TRUE(local.good()); 3242 ASSERT_TRUE(local.good());
3243 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle()); 3243 EXPECT_TRUE(local.GetMetahandle()!= server.GetMetahandle());
3244 EXPECT_FALSE(server.GetIsUnappliedUpdate()); 3244 EXPECT_FALSE(server.GetIsUnappliedUpdate());
3245 EXPECT_FALSE(local.GetIsUnappliedUpdate()); 3245 EXPECT_FALSE(local.GetIsUnappliedUpdate());
3246 EXPECT_FALSE(server.GetIsUnsynced()); 3246 EXPECT_FALSE(server.GetIsUnsynced());
3247 EXPECT_FALSE(local.GetIsUnsynced()); 3247 EXPECT_FALSE(local.GetIsUnsynced());
3248 EXPECT_EQ("Bar.htm", server.GetNonUniqueName()); 3248 EXPECT_EQ("Bar.htm", server.GetNonUniqueName());
3249 EXPECT_EQ("Bar.htm", local.GetNonUniqueName()); 3249 EXPECT_EQ("Bar.htm", local.GetNonUniqueName());
3250 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 3250 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
3251 server.GetSpecifics().bookmark().url()); 3251 server.GetSpecifics().bookmark().url());
3252 } 3252 }
3253 } 3253 }
3254 3254
3255 // Circular links should be resolved by the server. 3255 // Circular links should be resolved by the server.
3256 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { 3256 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) {
3257 // we don't currently resolve this. This test ensures we don't. 3257 // we don't currently resolve this. This test ensures we don't.
3258 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 3258 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
3259 foreign_cache_guid(), "-1"); 3259 foreign_cache_guid(), "-1");
3260 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, 3260 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10,
3261 foreign_cache_guid(), "-2"); 3261 foreign_cache_guid(), "-2");
3262 EXPECT_TRUE(SyncShareNudge()); 3262 SyncShareNudge();
3263 { 3263 {
3264 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3264 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3265 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3265 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3266 ASSERT_TRUE(A.good()); 3266 ASSERT_TRUE(A.good());
3267 A.PutIsUnsynced(true); 3267 A.PutIsUnsynced(true);
3268 A.PutParentId(ids_.FromNumber(2)); 3268 A.PutParentId(ids_.FromNumber(2));
3269 A.PutNonUniqueName("B"); 3269 A.PutNonUniqueName("B");
3270 } 3270 }
3271 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20, 3271 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20,
3272 foreign_cache_guid(), "-2"); 3272 foreign_cache_guid(), "-2");
3273 mock_server_->set_conflict_all_commits(true); 3273 mock_server_->set_conflict_all_commits(true);
3274 EXPECT_FALSE(SyncShareNudge()); 3274 SyncShareNudge();
3275 saw_syncer_event_ = false; 3275 saw_syncer_event_ = false;
3276 { 3276 {
3277 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3277 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3278 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3278 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3279 ASSERT_TRUE(A.good()); 3279 ASSERT_TRUE(A.good());
3280 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 3280 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
3281 ASSERT_TRUE(B.good()); 3281 ASSERT_TRUE(B.good());
3282 EXPECT_TRUE(A.GetNonUniqueName()== "B"); 3282 EXPECT_TRUE(A.GetNonUniqueName()== "B");
3283 EXPECT_TRUE(B.GetNonUniqueName()== "B"); 3283 EXPECT_TRUE(B.GetNonUniqueName()== "B");
3284 } 3284 }
3285 } 3285 }
3286 3286
3287 TEST_F(SyncerTest, SwapEntryNames) { 3287 TEST_F(SyncerTest, SwapEntryNames) {
3288 // Simple transaction test. 3288 // Simple transaction test.
3289 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 3289 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
3290 foreign_cache_guid(), "-1"); 3290 foreign_cache_guid(), "-1");
3291 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10, 3291 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10,
3292 foreign_cache_guid(), "-2"); 3292 foreign_cache_guid(), "-2");
3293 mock_server_->set_conflict_all_commits(true); 3293 mock_server_->set_conflict_all_commits(true);
3294 EXPECT_TRUE(SyncShareNudge()); 3294 SyncShareNudge();
3295 { 3295 {
3296 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3296 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3297 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 3297 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
3298 ASSERT_TRUE(A.good()); 3298 ASSERT_TRUE(A.good());
3299 A.PutIsUnsynced(true); 3299 A.PutIsUnsynced(true);
3300 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 3300 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
3301 ASSERT_TRUE(B.good()); 3301 ASSERT_TRUE(B.good());
3302 B.PutIsUnsynced(true); 3302 B.PutIsUnsynced(true);
3303 A.PutNonUniqueName("C"); 3303 A.PutNonUniqueName("C");
3304 B.PutNonUniqueName("A"); 3304 B.PutNonUniqueName("A");
3305 A.PutNonUniqueName("B"); 3305 A.PutNonUniqueName("B");
3306 } 3306 }
3307 EXPECT_FALSE(SyncShareNudge()); 3307 SyncShareNudge();
3308 saw_syncer_event_ = false; 3308 saw_syncer_event_ = false;
3309 } 3309 }
3310 3310
3311 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { 3311 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) {
3312 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10, 3312 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10,
3313 foreign_cache_guid(), "-1"); 3313 foreign_cache_guid(), "-1");
3314 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10, 3314 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10,
3315 foreign_cache_guid(), "-2"); 3315 foreign_cache_guid(), "-2");
3316 mock_server_->set_conflict_all_commits(true); 3316 mock_server_->set_conflict_all_commits(true);
3317 EXPECT_TRUE(SyncShareNudge()); 3317 SyncShareNudge();
3318 { 3318 {
3319 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3319 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3320 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 3320 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2));
3321 ASSERT_TRUE(B.good()); 3321 ASSERT_TRUE(B.good());
3322 WriteTestDataToEntry(&trans, &B); 3322 WriteTestDataToEntry(&trans, &B);
3323 B.PutIsDel(true); 3323 B.PutIsDel(true);
3324 } 3324 }
3325 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11, 3325 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11,
3326 foreign_cache_guid(), "-2"); 3326 foreign_cache_guid(), "-2");
3327 mock_server_->SetLastUpdateDeleted(); 3327 mock_server_->SetLastUpdateDeleted();
3328 EXPECT_TRUE(SyncShareNudge()); 3328 SyncShareNudge();
3329 { 3329 {
3330 syncable::ReadTransaction trans(FROM_HERE, directory()); 3330 syncable::ReadTransaction trans(FROM_HERE, directory());
3331 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 3331 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
3332 ASSERT_TRUE(B.good()); 3332 ASSERT_TRUE(B.good());
3333 EXPECT_FALSE(B.GetIsUnsynced()); 3333 EXPECT_FALSE(B.GetIsUnsynced());
3334 EXPECT_FALSE(B.GetIsUnappliedUpdate()); 3334 EXPECT_FALSE(B.GetIsUnappliedUpdate());
3335 } 3335 }
3336 saw_syncer_event_ = false; 3336 saw_syncer_event_ = false;
3337 } 3337 }
3338 3338
3339 // When we undelete an entity as a result of conflict resolution, we reuse the 3339 // When we undelete an entity as a result of conflict resolution, we reuse the
3340 // existing server id and preserve the old version, simply updating the server 3340 // existing server id and preserve the old version, simply updating the server
3341 // version with the new non-deleted entity. 3341 // version with the new non-deleted entity.
3342 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { 3342 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) {
3343 int64 bob_metahandle; 3343 int64 bob_metahandle;
3344 3344
3345 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10, 3345 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10,
3346 foreign_cache_guid(), "-1"); 3346 foreign_cache_guid(), "-1");
3347 EXPECT_TRUE(SyncShareNudge()); 3347 SyncShareNudge();
3348 { 3348 {
3349 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3349 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3350 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3350 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3351 ASSERT_TRUE(bob.good()); 3351 ASSERT_TRUE(bob.good());
3352 bob_metahandle = bob.GetMetahandle(); 3352 bob_metahandle = bob.GetMetahandle();
3353 WriteTestDataToEntry(&trans, &bob); 3353 WriteTestDataToEntry(&trans, &bob);
3354 } 3354 }
3355 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10, 3355 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10,
3356 foreign_cache_guid(), "-1"); 3356 foreign_cache_guid(), "-1");
3357 mock_server_->SetLastUpdateDeleted(); 3357 mock_server_->SetLastUpdateDeleted();
3358 mock_server_->set_conflict_all_commits(true); 3358 mock_server_->set_conflict_all_commits(true);
3359 EXPECT_FALSE(SyncShareNudge()); 3359 SyncShareNudge();
3360 EXPECT_FALSE(SyncShareNudge()); 3360 SyncShareNudge();
3361 { 3361 {
3362 syncable::ReadTransaction trans(FROM_HERE, directory()); 3362 syncable::ReadTransaction trans(FROM_HERE, directory());
3363 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle); 3363 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle);
3364 ASSERT_TRUE(bob.good()); 3364 ASSERT_TRUE(bob.good());
3365 EXPECT_TRUE(bob.GetIsUnsynced()); 3365 EXPECT_TRUE(bob.GetIsUnsynced());
3366 EXPECT_TRUE(bob.GetId().ServerKnows()); 3366 EXPECT_TRUE(bob.GetId().ServerKnows());
3367 EXPECT_FALSE(bob.GetIsUnappliedUpdate()); 3367 EXPECT_FALSE(bob.GetIsUnappliedUpdate());
3368 EXPECT_FALSE(bob.GetIsDel()); 3368 EXPECT_FALSE(bob.GetIsDel());
3369 EXPECT_EQ(2, bob.GetServerVersion()); 3369 EXPECT_EQ(2, bob.GetServerVersion());
3370 EXPECT_EQ(2, bob.GetBaseVersion()); 3370 EXPECT_EQ(2, bob.GetBaseVersion());
(...skipping 15 matching lines...) Expand all
3386 ASSERT_TRUE(folder2.good()); 3386 ASSERT_TRUE(folder2.good());
3387 folder2.PutIsUnsynced(false); 3387 folder2.PutIsUnsynced(false);
3388 folder2.PutIsDir(true); 3388 folder2.PutIsDir(true);
3389 folder2.PutSpecifics(DefaultBookmarkSpecifics()); 3389 folder2.PutSpecifics(DefaultBookmarkSpecifics());
3390 folder2.PutBaseVersion(3); 3390 folder2.PutBaseVersion(3);
3391 folder2.PutId(syncable::Id::CreateFromServerId("mock_server:10000")); 3391 folder2.PutId(syncable::Id::CreateFromServerId("mock_server:10000"));
3392 } 3392 }
3393 mock_server_->set_next_new_id(10000); 3393 mock_server_->set_next_new_id(10000);
3394 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 3394 EXPECT_EQ(1u, directory()->unsynced_entity_count());
3395 // we get back a bad id in here (should never happen). 3395 // we get back a bad id in here (should never happen).
3396 EXPECT_FALSE(SyncShareNudge()); 3396 SyncShareNudge();
3397 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 3397 EXPECT_EQ(1u, directory()->unsynced_entity_count());
3398 EXPECT_TRUE(SyncShareNudge()); // another bad id in here. 3398 SyncShareNudge(); // another bad id in here.
3399 EXPECT_EQ(0u, directory()->unsynced_entity_count()); 3399 EXPECT_EQ(0u, directory()->unsynced_entity_count());
3400 saw_syncer_event_ = false; 3400 saw_syncer_event_ = false;
3401 } 3401 }
3402 3402
3403 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) { 3403 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) {
3404 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, 3404 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10,
3405 foreign_cache_guid(), "-1"); 3405 foreign_cache_guid(), "-1");
3406 EXPECT_TRUE(SyncShareNudge()); 3406 SyncShareNudge();
3407 { 3407 {
3408 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3408 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3409 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3409 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3410 ASSERT_TRUE(bob.good()); 3410 ASSERT_TRUE(bob.good());
3411 // This is valid, because the parent could have gone away a long time ago. 3411 // This is valid, because the parent could have gone away a long time ago.
3412 bob.PutParentId(ids_.FromNumber(54)); 3412 bob.PutParentId(ids_.FromNumber(54));
3413 bob.PutIsDel(true); 3413 bob.PutIsDel(true);
3414 bob.PutIsUnsynced(true); 3414 bob.PutIsUnsynced(true);
3415 } 3415 }
3416 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10, 3416 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10,
3417 foreign_cache_guid(), "-2"); 3417 foreign_cache_guid(), "-2");
3418 EXPECT_TRUE(SyncShareNudge()); 3418 SyncShareNudge();
3419 EXPECT_TRUE(SyncShareNudge()); 3419 SyncShareNudge();
3420 } 3420 }
3421 3421
3422 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { 3422 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) {
3423 syncable::Id local_id; 3423 syncable::Id local_id;
3424 { 3424 {
3425 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3425 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3426 3426
3427 MutableEntry local_deleted( 3427 MutableEntry local_deleted(
3428 &trans, CREATE, BOOKMARKS, trans.root_id(), "name"); 3428 &trans, CREATE, BOOKMARKS, trans.root_id(), "name");
3429 local_id = local_deleted.GetId(); 3429 local_id = local_deleted.GetId();
3430 local_deleted.PutId(ids_.FromNumber(1)); 3430 local_deleted.PutId(ids_.FromNumber(1));
3431 local_deleted.PutBaseVersion(1); 3431 local_deleted.PutBaseVersion(1);
3432 local_deleted.PutIsDel(true); 3432 local_deleted.PutIsDel(true);
3433 local_deleted.PutIsDir(false); 3433 local_deleted.PutIsDir(false);
3434 local_deleted.PutIsUnsynced(true); 3434 local_deleted.PutIsUnsynced(true);
3435 local_deleted.PutSpecifics(DefaultBookmarkSpecifics()); 3435 local_deleted.PutSpecifics(DefaultBookmarkSpecifics());
3436 } 3436 }
3437 3437
3438 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10, 3438 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10,
3439 local_cache_guid(), 3439 local_cache_guid(),
3440 local_id.GetServerId()); 3440 local_id.GetServerId());
3441 3441
3442 // We don't care about actually committing, just the resolution. 3442 // We don't care about actually committing, just the resolution.
3443 mock_server_->set_conflict_all_commits(true); 3443 mock_server_->set_conflict_all_commits(true);
3444 EXPECT_FALSE(SyncShareNudge()); 3444 SyncShareNudge();
3445 3445
3446 { 3446 {
3447 syncable::ReadTransaction trans(FROM_HERE, directory()); 3447 syncable::ReadTransaction trans(FROM_HERE, directory());
3448 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); 3448 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1));
3449 EXPECT_TRUE(local_deleted.GetBaseVersion()== 10); 3449 EXPECT_TRUE(local_deleted.GetBaseVersion()== 10);
3450 EXPECT_TRUE(local_deleted.GetIsUnappliedUpdate()== false); 3450 EXPECT_TRUE(local_deleted.GetIsUnappliedUpdate()== false);
3451 EXPECT_TRUE(local_deleted.GetIsUnsynced()== true); 3451 EXPECT_TRUE(local_deleted.GetIsUnsynced()== true);
3452 EXPECT_TRUE(local_deleted.GetIsDel()== true); 3452 EXPECT_TRUE(local_deleted.GetIsDel()== true);
3453 EXPECT_TRUE(local_deleted.GetIsDir()== false); 3453 EXPECT_TRUE(local_deleted.GetIsDir()== false);
3454 } 3454 }
(...skipping 18 matching lines...) Expand all
3473 3473
3474 // Server update: entry-type object (not a container), revision 10. 3474 // Server update: entry-type object (not a container), revision 10.
3475 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10, 3475 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10,
3476 local_cache_guid(), 3476 local_cache_guid(),
3477 ids_.FromNumber(1).GetServerId()); 3477 ids_.FromNumber(1).GetServerId());
3478 3478
3479 // Don't attempt to commit. 3479 // Don't attempt to commit.
3480 mock_server_->set_conflict_all_commits(true); 3480 mock_server_->set_conflict_all_commits(true);
3481 3481
3482 // The syncer should not attempt to apply the invalid update. 3482 // The syncer should not attempt to apply the invalid update.
3483 EXPECT_FALSE(SyncShareNudge()); 3483 SyncShareNudge();
3484 3484
3485 { 3485 {
3486 syncable::ReadTransaction trans(FROM_HERE, directory()); 3486 syncable::ReadTransaction trans(FROM_HERE, directory());
3487 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); 3487 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1));
3488 EXPECT_TRUE(local_deleted.GetBaseVersion()== 1); 3488 EXPECT_TRUE(local_deleted.GetBaseVersion()== 1);
3489 EXPECT_TRUE(local_deleted.GetIsUnappliedUpdate()== false); 3489 EXPECT_TRUE(local_deleted.GetIsUnappliedUpdate()== false);
3490 EXPECT_TRUE(local_deleted.GetIsUnsynced()== true); 3490 EXPECT_TRUE(local_deleted.GetIsUnsynced()== true);
3491 EXPECT_TRUE(local_deleted.GetIsDel()== true); 3491 EXPECT_TRUE(local_deleted.GetIsDel()== true);
3492 EXPECT_TRUE(local_deleted.GetIsDir()== true); 3492 EXPECT_TRUE(local_deleted.GetIsDir()== true);
3493 } 3493 }
3494 } 3494 }
3495 3495
3496 // Bug Synopsis: 3496 // Bug Synopsis:
3497 // Merge conflict resolution will merge a new local entry with another entry 3497 // Merge conflict resolution will merge a new local entry with another entry
3498 // that needs updates, resulting in CHECK. 3498 // that needs updates, resulting in CHECK.
3499 TEST_F(SyncerTest, MergingExistingItems) { 3499 TEST_F(SyncerTest, MergingExistingItems) {
3500 mock_server_->set_conflict_all_commits(true); 3500 mock_server_->set_conflict_all_commits(true);
3501 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, 3501 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10,
3502 local_cache_guid(), "-1"); 3502 local_cache_guid(), "-1");
3503 EXPECT_TRUE(SyncShareNudge()); 3503 SyncShareNudge();
3504 { 3504 {
3505 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3505 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3506 MutableEntry entry( 3506 MutableEntry entry(
3507 &trans, CREATE, BOOKMARKS, trans.root_id(), "Copy of base"); 3507 &trans, CREATE, BOOKMARKS, trans.root_id(), "Copy of base");
3508 WriteTestDataToEntry(&trans, &entry); 3508 WriteTestDataToEntry(&trans, &entry);
3509 } 3509 }
3510 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, 3510 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50,
3511 local_cache_guid(), "-1"); 3511 local_cache_guid(), "-1");
3512 EXPECT_FALSE(SyncShareNudge()); 3512 SyncShareNudge();
3513 } 3513 }
3514 3514
3515 // In this test a long changelog contains a child at the start of the changelog 3515 // In this test a long changelog contains a child at the start of the changelog
3516 // and a parent at the end. While these updates are in progress the client would 3516 // and a parent at the end. While these updates are in progress the client would
3517 // appear stuck. 3517 // appear stuck.
3518 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) { 3518 TEST_F(SyncerTest, LongChangelistWithApplicationConflict) {
3519 const int depth = 400; 3519 const int depth = 400;
3520 syncable::Id folder_id = ids_.FromNumber(1); 3520 syncable::Id folder_id = ids_.FromNumber(1);
3521 3521
3522 // First we an item in a folder in the root. However the folder won't come 3522 // First we an item in a folder in the root. However the folder won't come
3523 // till much later. 3523 // till much later.
3524 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999); 3524 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999);
3525 mock_server_->AddUpdateDirectory(stuck_entry_id, 3525 mock_server_->AddUpdateDirectory(stuck_entry_id,
3526 folder_id, "stuck", 1, 1, 3526 folder_id, "stuck", 1, 1,
3527 foreign_cache_guid(), "-99999"); 3527 foreign_cache_guid(), "-99999");
3528 mock_server_->SetChangesRemaining(depth - 1); 3528 mock_server_->SetChangesRemaining(depth - 1);
3529 EXPECT_TRUE(SyncShareNudge()); 3529 SyncShareNudge();
3530 3530
3531 // Buffer up a very long series of downloads. 3531 // Buffer up a very long series of downloads.
3532 // We should never be stuck (conflict resolution shouldn't 3532 // We should never be stuck (conflict resolution shouldn't
3533 // kick in so long as we're making forward progress). 3533 // kick in so long as we're making forward progress).
3534 for (int i = 0; i < depth; i++) { 3534 for (int i = 0; i < depth; i++) {
3535 mock_server_->NextUpdateBatch(); 3535 mock_server_->NextUpdateBatch();
3536 mock_server_->SetNewTimestamp(i + 1); 3536 mock_server_->SetNewTimestamp(i + 1);
3537 mock_server_->SetChangesRemaining(depth - i); 3537 mock_server_->SetChangesRemaining(depth - i);
3538 } 3538 }
3539 3539
3540 EXPECT_TRUE(SyncShareNudge()); 3540 SyncShareNudge();
3541 3541
3542 // Ensure our folder hasn't somehow applied. 3542 // Ensure our folder hasn't somehow applied.
3543 { 3543 {
3544 syncable::ReadTransaction trans(FROM_HERE, directory()); 3544 syncable::ReadTransaction trans(FROM_HERE, directory());
3545 Entry child(&trans, GET_BY_ID, stuck_entry_id); 3545 Entry child(&trans, GET_BY_ID, stuck_entry_id);
3546 EXPECT_TRUE(child.good()); 3546 EXPECT_TRUE(child.good());
3547 EXPECT_TRUE(child.GetIsUnappliedUpdate()); 3547 EXPECT_TRUE(child.GetIsUnappliedUpdate());
3548 EXPECT_TRUE(child.GetIsDel()); 3548 EXPECT_TRUE(child.GetIsDel());
3549 EXPECT_FALSE(child.GetIsUnsynced()); 3549 EXPECT_FALSE(child.GetIsUnsynced());
3550 } 3550 }
3551 3551
3552 // And finally the folder. 3552 // And finally the folder.
3553 mock_server_->AddUpdateDirectory(folder_id, 3553 mock_server_->AddUpdateDirectory(folder_id,
3554 TestIdFactory::root(), "folder", 1, 1, 3554 TestIdFactory::root(), "folder", 1, 1,
3555 foreign_cache_guid(), "-1"); 3555 foreign_cache_guid(), "-1");
3556 mock_server_->SetChangesRemaining(0); 3556 mock_server_->SetChangesRemaining(0);
3557 EXPECT_TRUE(SyncShareNudge()); 3557 SyncShareNudge();
3558 EXPECT_TRUE(SyncShareNudge()); 3558 SyncShareNudge();
3559 // Check that everything is as expected after the commit. 3559 // Check that everything is as expected after the commit.
3560 { 3560 {
3561 syncable::ReadTransaction trans(FROM_HERE, directory()); 3561 syncable::ReadTransaction trans(FROM_HERE, directory());
3562 Entry entry(&trans, GET_BY_ID, folder_id); 3562 Entry entry(&trans, GET_BY_ID, folder_id);
3563 ASSERT_TRUE(entry.good()); 3563 ASSERT_TRUE(entry.good());
3564 Entry child(&trans, GET_BY_ID, stuck_entry_id); 3564 Entry child(&trans, GET_BY_ID, stuck_entry_id);
3565 EXPECT_EQ(entry.GetId(), child.GetParentId()); 3565 EXPECT_EQ(entry.GetId(), child.GetParentId());
3566 EXPECT_EQ("stuck", child.GetNonUniqueName()); 3566 EXPECT_EQ("stuck", child.GetNonUniqueName());
3567 EXPECT_TRUE(child.good()); 3567 EXPECT_TRUE(child.good());
3568 } 3568 }
3569 } 3569 }
3570 3570
3571 TEST_F(SyncerTest, DontMergeTwoExistingItems) { 3571 TEST_F(SyncerTest, DontMergeTwoExistingItems) {
3572 mock_server_->set_conflict_all_commits(true); 3572 mock_server_->set_conflict_all_commits(true);
3573 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10, 3573 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10,
3574 foreign_cache_guid(), "-1"); 3574 foreign_cache_guid(), "-1");
3575 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10, 3575 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10,
3576 foreign_cache_guid(), "-2"); 3576 foreign_cache_guid(), "-2");
3577 EXPECT_TRUE(SyncShareNudge()); 3577 SyncShareNudge();
3578 { 3578 {
3579 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3579 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3580 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3580 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3581 ASSERT_TRUE(entry.good()); 3581 ASSERT_TRUE(entry.good());
3582 entry.PutNonUniqueName("Copy of base"); 3582 entry.PutNonUniqueName("Copy of base");
3583 entry.PutIsUnsynced(true); 3583 entry.PutIsUnsynced(true);
3584 } 3584 }
3585 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50, 3585 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50,
3586 foreign_cache_guid(), "-1"); 3586 foreign_cache_guid(), "-1");
3587 EXPECT_FALSE(SyncShareNudge()); 3587 SyncShareNudge();
3588 { 3588 {
3589 syncable::ReadTransaction trans(FROM_HERE, directory()); 3589 syncable::ReadTransaction trans(FROM_HERE, directory());
3590 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); 3590 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1));
3591 EXPECT_FALSE(entry1.GetIsUnappliedUpdate()); 3591 EXPECT_FALSE(entry1.GetIsUnappliedUpdate());
3592 EXPECT_FALSE(entry1.GetIsUnsynced()); 3592 EXPECT_FALSE(entry1.GetIsUnsynced());
3593 EXPECT_FALSE(entry1.GetIsDel()); 3593 EXPECT_FALSE(entry1.GetIsDel());
3594 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2)); 3594 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2));
3595 EXPECT_FALSE(entry2.GetIsUnappliedUpdate()); 3595 EXPECT_FALSE(entry2.GetIsUnappliedUpdate());
3596 EXPECT_TRUE(entry2.GetIsUnsynced()); 3596 EXPECT_TRUE(entry2.GetIsUnsynced());
3597 EXPECT_FALSE(entry2.GetIsDel()); 3597 EXPECT_FALSE(entry2.GetIsDel());
3598 EXPECT_EQ(entry1.GetNonUniqueName(), entry2.GetNonUniqueName()); 3598 EXPECT_EQ(entry1.GetNonUniqueName(), entry2.GetNonUniqueName());
3599 } 3599 }
3600 } 3600 }
3601 3601
3602 TEST_F(SyncerTest, TestUndeleteUpdate) { 3602 TEST_F(SyncerTest, TestUndeleteUpdate) {
3603 mock_server_->set_conflict_all_commits(true); 3603 mock_server_->set_conflict_all_commits(true);
3604 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, 3604 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1,
3605 foreign_cache_guid(), "-1"); 3605 foreign_cache_guid(), "-1");
3606 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2, 3606 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2,
3607 foreign_cache_guid(), "-2"); 3607 foreign_cache_guid(), "-2");
3608 EXPECT_TRUE(SyncShareNudge()); 3608 SyncShareNudge();
3609 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3, 3609 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3,
3610 foreign_cache_guid(), "-2"); 3610 foreign_cache_guid(), "-2");
3611 mock_server_->SetLastUpdateDeleted(); 3611 mock_server_->SetLastUpdateDeleted();
3612 EXPECT_TRUE(SyncShareNudge()); 3612 SyncShareNudge();
3613 3613
3614 int64 metahandle; 3614 int64 metahandle;
3615 { 3615 {
3616 syncable::ReadTransaction trans(FROM_HERE, directory()); 3616 syncable::ReadTransaction trans(FROM_HERE, directory());
3617 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3617 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3618 ASSERT_TRUE(entry.good()); 3618 ASSERT_TRUE(entry.good());
3619 EXPECT_TRUE(entry.GetIsDel()); 3619 EXPECT_TRUE(entry.GetIsDel());
3620 metahandle = entry.GetMetahandle(); 3620 metahandle = entry.GetMetahandle();
3621 } 3621 }
3622 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4, 3622 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4,
3623 foreign_cache_guid(), "-1"); 3623 foreign_cache_guid(), "-1");
3624 mock_server_->SetLastUpdateDeleted(); 3624 mock_server_->SetLastUpdateDeleted();
3625 EXPECT_TRUE(SyncShareNudge()); 3625 SyncShareNudge();
3626 // This used to be rejected as it's an undeletion. Now, it results in moving 3626 // This used to be rejected as it's an undeletion. Now, it results in moving
3627 // the delete path aside. 3627 // the delete path aside.
3628 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5, 3628 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5,
3629 foreign_cache_guid(), "-2"); 3629 foreign_cache_guid(), "-2");
3630 EXPECT_TRUE(SyncShareNudge()); 3630 SyncShareNudge();
3631 { 3631 {
3632 syncable::ReadTransaction trans(FROM_HERE, directory()); 3632 syncable::ReadTransaction trans(FROM_HERE, directory());
3633 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3633 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3634 ASSERT_TRUE(entry.good()); 3634 ASSERT_TRUE(entry.good());
3635 EXPECT_TRUE(entry.GetIsDel()); 3635 EXPECT_TRUE(entry.GetIsDel());
3636 EXPECT_FALSE(entry.GetServerIsDel()); 3636 EXPECT_FALSE(entry.GetServerIsDel());
3637 EXPECT_TRUE(entry.GetIsUnappliedUpdate()); 3637 EXPECT_TRUE(entry.GetIsUnappliedUpdate());
3638 EXPECT_NE(entry.GetMetahandle(), metahandle); 3638 EXPECT_NE(entry.GetMetahandle(), metahandle);
3639 } 3639 }
3640 } 3640 }
3641 3641
3642 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) { 3642 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) {
3643 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1, 3643 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1,
3644 foreign_cache_guid(), "-1"); 3644 foreign_cache_guid(), "-1");
3645 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2, 3645 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2,
3646 foreign_cache_guid(), "-2"); 3646 foreign_cache_guid(), "-2");
3647 EXPECT_TRUE(SyncShareNudge()); 3647 SyncShareNudge();
3648 { 3648 {
3649 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3649 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3650 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3650 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3651 ASSERT_TRUE(entry.good()); 3651 ASSERT_TRUE(entry.good());
3652 entry.PutParentId(ids_.FromNumber(1)); 3652 entry.PutParentId(ids_.FromNumber(1));
3653 EXPECT_TRUE(entry.PutIsUnsynced(true)); 3653 EXPECT_TRUE(entry.PutIsUnsynced(true));
3654 } 3654 }
3655 EXPECT_TRUE(SyncShareNudge()); 3655 SyncShareNudge();
3656 // We use the same sync ts as before so our times match up. 3656 // We use the same sync ts as before so our times match up.
3657 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2, 3657 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2,
3658 foreign_cache_guid(), "-2"); 3658 foreign_cache_guid(), "-2");
3659 EXPECT_TRUE(SyncShareNudge()); 3659 SyncShareNudge();
3660 } 3660 }
3661 3661
3662 // Don't crash when this occurs. 3662 // Don't crash when this occurs.
3663 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) { 3663 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) {
3664 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10, 3664 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10,
3665 foreign_cache_guid(), "-1"); 3665 foreign_cache_guid(), "-1");
3666 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10, 3666 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10,
3667 foreign_cache_guid(), "-2"); 3667 foreign_cache_guid(), "-2");
3668 // Used to cause a CHECK 3668 // Used to cause a CHECK
3669 EXPECT_TRUE(SyncShareNudge()); 3669 SyncShareNudge();
3670 { 3670 {
3671 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 3671 syncable::ReadTransaction rtrans(FROM_HERE, directory());
3672 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 3672 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
3673 ASSERT_TRUE(good_entry.good()); 3673 ASSERT_TRUE(good_entry.good());
3674 EXPECT_FALSE(good_entry.GetIsUnappliedUpdate()); 3674 EXPECT_FALSE(good_entry.GetIsUnappliedUpdate());
3675 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); 3675 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2));
3676 ASSERT_TRUE(bad_parent.good()); 3676 ASSERT_TRUE(bad_parent.good());
3677 EXPECT_TRUE(bad_parent.GetIsUnappliedUpdate()); 3677 EXPECT_TRUE(bad_parent.GetIsUnappliedUpdate());
3678 } 3678 }
3679 } 3679 }
3680 3680
3681 TEST_F(SyncerTest, DirectoryUpdateTest) { 3681 TEST_F(SyncerTest, DirectoryUpdateTest) {
3682 Id in_root_id = ids_.NewServerId(); 3682 Id in_root_id = ids_.NewServerId();
3683 Id in_in_root_id = ids_.NewServerId(); 3683 Id in_in_root_id = ids_.NewServerId();
3684 3684
3685 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), 3685 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(),
3686 "in_root_name", 2, 2, 3686 "in_root_name", 2, 2,
3687 foreign_cache_guid(), "-1"); 3687 foreign_cache_guid(), "-1");
3688 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, 3688 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id,
3689 "in_in_root_name", 3, 3, 3689 "in_in_root_name", 3, 3,
3690 foreign_cache_guid(), "-2"); 3690 foreign_cache_guid(), "-2");
3691 EXPECT_TRUE(SyncShareNudge()); 3691 SyncShareNudge();
3692 { 3692 {
3693 syncable::ReadTransaction trans(FROM_HERE, directory()); 3693 syncable::ReadTransaction trans(FROM_HERE, directory());
3694 Entry in_root(&trans, GET_BY_ID, in_root_id); 3694 Entry in_root(&trans, GET_BY_ID, in_root_id);
3695 ASSERT_TRUE(in_root.good()); 3695 ASSERT_TRUE(in_root.good());
3696 EXPECT_EQ("in_root_name", in_root.GetNonUniqueName()); 3696 EXPECT_EQ("in_root_name", in_root.GetNonUniqueName());
3697 EXPECT_EQ(TestIdFactory::root(), in_root.GetParentId()); 3697 EXPECT_EQ(TestIdFactory::root(), in_root.GetParentId());
3698 3698
3699 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); 3699 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id);
3700 ASSERT_TRUE(in_in_root.good()); 3700 ASSERT_TRUE(in_in_root.good());
3701 EXPECT_EQ("in_in_root_name", in_in_root.GetNonUniqueName()); 3701 EXPECT_EQ("in_in_root_name", in_in_root.GetNonUniqueName());
(...skipping 17 matching lines...) Expand all
3719 foo_metahandle = parent.GetMetahandle(); 3719 foo_metahandle = parent.GetMetahandle();
3720 3720
3721 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "bar"); 3721 MutableEntry child(&wtrans, CREATE, BOOKMARKS, parent.GetId(), "bar");
3722 ASSERT_TRUE(child.good()); 3722 ASSERT_TRUE(child.good());
3723 child.PutIsUnsynced(true); 3723 child.PutIsUnsynced(true);
3724 child.PutIsDir(true); 3724 child.PutIsDir(true);
3725 child.PutSpecifics(DefaultBookmarkSpecifics()); 3725 child.PutSpecifics(DefaultBookmarkSpecifics());
3726 bar_metahandle = child.GetMetahandle(); 3726 bar_metahandle = child.GetMetahandle();
3727 in_dir_id = parent.GetId(); 3727 in_dir_id = parent.GetId();
3728 } 3728 }
3729 EXPECT_TRUE(SyncShareNudge()); 3729 SyncShareNudge();
3730 { 3730 {
3731 syncable::ReadTransaction trans(FROM_HERE, directory()); 3731 syncable::ReadTransaction trans(FROM_HERE, directory());
3732 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id); 3732 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id);
3733 ASSERT_FALSE(fail_by_old_id_entry.good()); 3733 ASSERT_FALSE(fail_by_old_id_entry.good());
3734 3734
3735 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle); 3735 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle);
3736 ASSERT_TRUE(foo_entry.good()); 3736 ASSERT_TRUE(foo_entry.good());
3737 EXPECT_EQ("foo", foo_entry.GetNonUniqueName()); 3737 EXPECT_EQ("foo", foo_entry.GetNonUniqueName());
3738 EXPECT_NE(foo_entry.GetId(), in_root_id); 3738 EXPECT_NE(foo_entry.GetId(), in_root_id);
3739 3739
(...skipping 14 matching lines...) Expand all
3754 command->set_sessions_commit_delay_seconds(3141); 3754 command->set_sessions_commit_delay_seconds(3141);
3755 sync_pb::CustomNudgeDelay* bookmark_delay = 3755 sync_pb::CustomNudgeDelay* bookmark_delay =
3756 command->add_custom_nudge_delays(); 3756 command->add_custom_nudge_delays();
3757 bookmark_delay->set_datatype_id( 3757 bookmark_delay->set_datatype_id(
3758 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); 3758 GetSpecificsFieldNumberFromModelType(BOOKMARKS));
3759 bookmark_delay->set_delay_ms(950); 3759 bookmark_delay->set_delay_ms(950);
3760 command->set_client_invalidation_hint_buffer_size(11); 3760 command->set_client_invalidation_hint_buffer_size(11);
3761 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1, 3761 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1,
3762 foreign_cache_guid(), "-1"); 3762 foreign_cache_guid(), "-1");
3763 mock_server_->SetGUClientCommand(command); 3763 mock_server_->SetGUClientCommand(command);
3764 EXPECT_TRUE(SyncShareNudge()); 3764 SyncShareNudge();
3765 3765
3766 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_); 3766 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_);
3767 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_); 3767 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_);
3768 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_); 3768 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_);
3769 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_); 3769 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_);
3770 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); 3770 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_);
3771 3771
3772 command = new ClientCommand(); 3772 command = new ClientCommand();
3773 command->set_set_sync_poll_interval(180); 3773 command->set_set_sync_poll_interval(180);
3774 command->set_set_sync_long_poll_interval(190); 3774 command->set_set_sync_long_poll_interval(190);
3775 command->set_sessions_commit_delay_seconds(2718); 3775 command->set_sessions_commit_delay_seconds(2718);
3776 bookmark_delay = command->add_custom_nudge_delays(); 3776 bookmark_delay = command->add_custom_nudge_delays();
3777 bookmark_delay->set_datatype_id( 3777 bookmark_delay->set_datatype_id(
3778 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); 3778 GetSpecificsFieldNumberFromModelType(BOOKMARKS));
3779 bookmark_delay->set_delay_ms(1050); 3779 bookmark_delay->set_delay_ms(1050);
3780 command->set_client_invalidation_hint_buffer_size(9); 3780 command->set_client_invalidation_hint_buffer_size(9);
3781 mock_server_->AddUpdateDirectory( 3781 mock_server_->AddUpdateDirectory(
3782 1, 0, "in_root", 1, 1, foreign_cache_guid(), "-1"); 3782 1, 0, "in_root", 1, 1, foreign_cache_guid(), "-1");
3783 mock_server_->SetGUClientCommand(command); 3783 mock_server_->SetGUClientCommand(command);
3784 EXPECT_TRUE(SyncShareNudge()); 3784 SyncShareNudge();
3785 3785
3786 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_); 3786 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_);
3787 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_); 3787 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_);
3788 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); 3788 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_);
3789 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); 3789 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_);
3790 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); 3790 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_);
3791 } 3791 }
3792 3792
3793 TEST_F(SyncerTest, TestClientCommandDuringCommit) { 3793 TEST_F(SyncerTest, TestClientCommandDuringCommit) {
3794 using sync_pb::ClientCommand; 3794 using sync_pb::ClientCommand;
3795 3795
3796 ClientCommand* command = new ClientCommand(); 3796 ClientCommand* command = new ClientCommand();
3797 command->set_set_sync_poll_interval(8); 3797 command->set_set_sync_poll_interval(8);
3798 command->set_set_sync_long_poll_interval(800); 3798 command->set_set_sync_long_poll_interval(800);
3799 command->set_sessions_commit_delay_seconds(3141); 3799 command->set_sessions_commit_delay_seconds(3141);
3800 sync_pb::CustomNudgeDelay* bookmark_delay = 3800 sync_pb::CustomNudgeDelay* bookmark_delay =
3801 command->add_custom_nudge_delays(); 3801 command->add_custom_nudge_delays();
3802 bookmark_delay->set_datatype_id( 3802 bookmark_delay->set_datatype_id(
3803 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); 3803 GetSpecificsFieldNumberFromModelType(BOOKMARKS));
3804 bookmark_delay->set_delay_ms(950); 3804 bookmark_delay->set_delay_ms(950);
3805 command->set_client_invalidation_hint_buffer_size(11); 3805 command->set_client_invalidation_hint_buffer_size(11);
3806 CreateUnsyncedDirectory("X", "id_X"); 3806 CreateUnsyncedDirectory("X", "id_X");
3807 mock_server_->SetCommitClientCommand(command); 3807 mock_server_->SetCommitClientCommand(command);
3808 EXPECT_TRUE(SyncShareNudge()); 3808 SyncShareNudge();
3809 3809
3810 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_); 3810 EXPECT_EQ(TimeDelta::FromSeconds(8), last_short_poll_interval_received_);
3811 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_); 3811 EXPECT_EQ(TimeDelta::FromSeconds(800), last_long_poll_interval_received_);
3812 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_); 3812 EXPECT_EQ(TimeDelta::FromSeconds(3141), last_sessions_commit_delay_);
3813 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_); 3813 EXPECT_EQ(TimeDelta::FromMilliseconds(950), last_bookmarks_commit_delay_);
3814 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_); 3814 EXPECT_EQ(11, last_client_invalidation_hint_buffer_size_);
3815 3815
3816 command = new ClientCommand(); 3816 command = new ClientCommand();
3817 command->set_set_sync_poll_interval(180); 3817 command->set_set_sync_poll_interval(180);
3818 command->set_set_sync_long_poll_interval(190); 3818 command->set_set_sync_long_poll_interval(190);
3819 command->set_sessions_commit_delay_seconds(2718); 3819 command->set_sessions_commit_delay_seconds(2718);
3820 bookmark_delay = command->add_custom_nudge_delays(); 3820 bookmark_delay = command->add_custom_nudge_delays();
3821 bookmark_delay->set_datatype_id( 3821 bookmark_delay->set_datatype_id(
3822 GetSpecificsFieldNumberFromModelType(BOOKMARKS)); 3822 GetSpecificsFieldNumberFromModelType(BOOKMARKS));
3823 bookmark_delay->set_delay_ms(1050); 3823 bookmark_delay->set_delay_ms(1050);
3824 command->set_client_invalidation_hint_buffer_size(9); 3824 command->set_client_invalidation_hint_buffer_size(9);
3825 CreateUnsyncedDirectory("Y", "id_Y"); 3825 CreateUnsyncedDirectory("Y", "id_Y");
3826 mock_server_->SetCommitClientCommand(command); 3826 mock_server_->SetCommitClientCommand(command);
3827 EXPECT_TRUE(SyncShareNudge()); 3827 SyncShareNudge();
3828 3828
3829 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_); 3829 EXPECT_EQ(TimeDelta::FromSeconds(180), last_short_poll_interval_received_);
3830 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_); 3830 EXPECT_EQ(TimeDelta::FromSeconds(190), last_long_poll_interval_received_);
3831 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_); 3831 EXPECT_EQ(TimeDelta::FromSeconds(2718), last_sessions_commit_delay_);
3832 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_); 3832 EXPECT_EQ(TimeDelta::FromMilliseconds(1050), last_bookmarks_commit_delay_);
3833 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_); 3833 EXPECT_EQ(9, last_client_invalidation_hint_buffer_size_);
3834 } 3834 }
3835 3835
3836 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { 3836 TEST_F(SyncerTest, EnsureWeSendUpOldParent) {
3837 syncable::Id folder_one_id = ids_.FromNumber(1); 3837 syncable::Id folder_one_id = ids_.FromNumber(1);
3838 syncable::Id folder_two_id = ids_.FromNumber(2); 3838 syncable::Id folder_two_id = ids_.FromNumber(2);
3839 3839
3840 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), 3840 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(),
3841 "folder_one", 1, 1, foreign_cache_guid(), "-1"); 3841 "folder_one", 1, 1, foreign_cache_guid(), "-1");
3842 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), 3842 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(),
3843 "folder_two", 1, 1, foreign_cache_guid(), "-2"); 3843 "folder_two", 1, 1, foreign_cache_guid(), "-2");
3844 EXPECT_TRUE(SyncShareNudge()); 3844 SyncShareNudge();
3845 { 3845 {
3846 // A moved entry should send an "old parent." 3846 // A moved entry should send an "old parent."
3847 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3847 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3848 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); 3848 MutableEntry entry(&trans, GET_BY_ID, folder_one_id);
3849 ASSERT_TRUE(entry.good()); 3849 ASSERT_TRUE(entry.good());
3850 entry.PutParentId(folder_two_id); 3850 entry.PutParentId(folder_two_id);
3851 entry.PutIsUnsynced(true); 3851 entry.PutIsUnsynced(true);
3852 // A new entry should send no "old parent." 3852 // A new entry should send no "old parent."
3853 MutableEntry create( 3853 MutableEntry create(
3854 &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder"); 3854 &trans, CREATE, BOOKMARKS, trans.root_id(), "new_folder");
3855 create.PutIsUnsynced(true); 3855 create.PutIsUnsynced(true);
3856 create.PutSpecifics(DefaultBookmarkSpecifics()); 3856 create.PutSpecifics(DefaultBookmarkSpecifics());
3857 } 3857 }
3858 EXPECT_TRUE(SyncShareNudge()); 3858 SyncShareNudge();
3859 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); 3859 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit();
3860 ASSERT_EQ(2, commit.entries_size()); 3860 ASSERT_EQ(2, commit.entries_size());
3861 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); 3861 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2");
3862 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); 3862 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0");
3863 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); 3863 EXPECT_FALSE(commit.entries(1).has_old_parent_id());
3864 } 3864 }
3865 3865
3866 TEST_F(SyncerTest, Test64BitVersionSupport) { 3866 TEST_F(SyncerTest, Test64BitVersionSupport) {
3867 int64 really_big_int = std::numeric_limits<int64>::max() - 12; 3867 int64 really_big_int = std::numeric_limits<int64>::max() - 12;
3868 const string name("ringo's dang orang ran rings around my o-ring"); 3868 const string name("ringo's dang orang ran rings around my o-ring");
(...skipping 15 matching lines...) Expand all
3884 ASSERT_TRUE(entry.good()); 3884 ASSERT_TRUE(entry.good());
3885 EXPECT_TRUE(really_big_int == entry.GetBaseVersion()); 3885 EXPECT_TRUE(really_big_int == entry.GetBaseVersion());
3886 } 3886 }
3887 3887
3888 TEST_F(SyncerTest, TestSimpleUndelete) { 3888 TEST_F(SyncerTest, TestSimpleUndelete) {
3889 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 3889 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
3890 mock_server_->set_conflict_all_commits(true); 3890 mock_server_->set_conflict_all_commits(true);
3891 // Let there be an entry from the server. 3891 // Let there be an entry from the server.
3892 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, 3892 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10,
3893 foreign_cache_guid(), "-1"); 3893 foreign_cache_guid(), "-1");
3894 EXPECT_TRUE(SyncShareNudge()); 3894 SyncShareNudge();
3895 // Check it out and delete it. 3895 // Check it out and delete it.
3896 { 3896 {
3897 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3897 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3898 MutableEntry entry(&wtrans, GET_BY_ID, id); 3898 MutableEntry entry(&wtrans, GET_BY_ID, id);
3899 ASSERT_TRUE(entry.good()); 3899 ASSERT_TRUE(entry.good());
3900 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3900 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3901 EXPECT_FALSE(entry.GetIsUnsynced()); 3901 EXPECT_FALSE(entry.GetIsUnsynced());
3902 EXPECT_FALSE(entry.GetIsDel()); 3902 EXPECT_FALSE(entry.GetIsDel());
3903 // Delete it locally. 3903 // Delete it locally.
3904 entry.PutIsDel(true); 3904 entry.PutIsDel(true);
3905 } 3905 }
3906 EXPECT_TRUE(SyncShareNudge()); 3906 SyncShareNudge();
3907 // Confirm we see IS_DEL and not SERVER_IS_DEL. 3907 // Confirm we see IS_DEL and not SERVER_IS_DEL.
3908 { 3908 {
3909 syncable::ReadTransaction trans(FROM_HERE, directory()); 3909 syncable::ReadTransaction trans(FROM_HERE, directory());
3910 Entry entry(&trans, GET_BY_ID, id); 3910 Entry entry(&trans, GET_BY_ID, id);
3911 ASSERT_TRUE(entry.good()); 3911 ASSERT_TRUE(entry.good());
3912 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3912 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3913 EXPECT_FALSE(entry.GetIsUnsynced()); 3913 EXPECT_FALSE(entry.GetIsUnsynced());
3914 EXPECT_TRUE(entry.GetIsDel()); 3914 EXPECT_TRUE(entry.GetIsDel());
3915 EXPECT_FALSE(entry.GetServerIsDel()); 3915 EXPECT_FALSE(entry.GetServerIsDel());
3916 } 3916 }
3917 EXPECT_TRUE(SyncShareNudge()); 3917 SyncShareNudge();
3918 // Update from server confirming deletion. 3918 // Update from server confirming deletion.
3919 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11, 3919 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11,
3920 foreign_cache_guid(), "-1"); 3920 foreign_cache_guid(), "-1");
3921 mock_server_->SetLastUpdateDeleted(); 3921 mock_server_->SetLastUpdateDeleted();
3922 EXPECT_TRUE(SyncShareNudge()); 3922 SyncShareNudge();
3923 // IS_DEL AND SERVER_IS_DEL now both true. 3923 // IS_DEL AND SERVER_IS_DEL now both true.
3924 { 3924 {
3925 syncable::ReadTransaction trans(FROM_HERE, directory()); 3925 syncable::ReadTransaction trans(FROM_HERE, directory());
3926 Entry entry(&trans, GET_BY_ID, id); 3926 Entry entry(&trans, GET_BY_ID, id);
3927 ASSERT_TRUE(entry.good()); 3927 ASSERT_TRUE(entry.good());
3928 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3928 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3929 EXPECT_FALSE(entry.GetIsUnsynced()); 3929 EXPECT_FALSE(entry.GetIsUnsynced());
3930 EXPECT_TRUE(entry.GetIsDel()); 3930 EXPECT_TRUE(entry.GetIsDel());
3931 EXPECT_TRUE(entry.GetServerIsDel()); 3931 EXPECT_TRUE(entry.GetServerIsDel());
3932 } 3932 }
3933 // Undelete from server. 3933 // Undelete from server.
3934 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12, 3934 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12,
3935 foreign_cache_guid(), "-1"); 3935 foreign_cache_guid(), "-1");
3936 EXPECT_TRUE(SyncShareNudge()); 3936 SyncShareNudge();
3937 // IS_DEL and SERVER_IS_DEL now both false. 3937 // IS_DEL and SERVER_IS_DEL now both false.
3938 { 3938 {
3939 syncable::ReadTransaction trans(FROM_HERE, directory()); 3939 syncable::ReadTransaction trans(FROM_HERE, directory());
3940 Entry entry(&trans, GET_BY_ID, id); 3940 Entry entry(&trans, GET_BY_ID, id);
3941 ASSERT_TRUE(entry.good()); 3941 ASSERT_TRUE(entry.good());
3942 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3942 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3943 EXPECT_FALSE(entry.GetIsUnsynced()); 3943 EXPECT_FALSE(entry.GetIsUnsynced());
3944 EXPECT_FALSE(entry.GetIsDel()); 3944 EXPECT_FALSE(entry.GetIsDel());
3945 EXPECT_FALSE(entry.GetServerIsDel()); 3945 EXPECT_FALSE(entry.GetServerIsDel());
3946 } 3946 }
3947 } 3947 }
3948 3948
3949 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) { 3949 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) {
3950 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 3950 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
3951 // Let there be a entry, from the server. 3951 // Let there be a entry, from the server.
3952 mock_server_->set_conflict_all_commits(true); 3952 mock_server_->set_conflict_all_commits(true);
3953 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10, 3953 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10,
3954 foreign_cache_guid(), "-1"); 3954 foreign_cache_guid(), "-1");
3955 EXPECT_TRUE(SyncShareNudge()); 3955 SyncShareNudge();
3956 // Check it out and delete it. 3956 // Check it out and delete it.
3957 { 3957 {
3958 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3958 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3959 MutableEntry entry(&wtrans, GET_BY_ID, id); 3959 MutableEntry entry(&wtrans, GET_BY_ID, id);
3960 ASSERT_TRUE(entry.good()); 3960 ASSERT_TRUE(entry.good());
3961 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3961 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3962 EXPECT_FALSE(entry.GetIsUnsynced()); 3962 EXPECT_FALSE(entry.GetIsUnsynced());
3963 EXPECT_FALSE(entry.GetIsDel()); 3963 EXPECT_FALSE(entry.GetIsDel());
3964 // Delete it locally. 3964 // Delete it locally.
3965 entry.PutIsDel(true); 3965 entry.PutIsDel(true);
3966 } 3966 }
3967 EXPECT_TRUE(SyncShareNudge()); 3967 SyncShareNudge();
3968 // Confirm we see IS_DEL and not SERVER_IS_DEL. 3968 // Confirm we see IS_DEL and not SERVER_IS_DEL.
3969 { 3969 {
3970 syncable::ReadTransaction trans(FROM_HERE, directory()); 3970 syncable::ReadTransaction trans(FROM_HERE, directory());
3971 Entry entry(&trans, GET_BY_ID, id); 3971 Entry entry(&trans, GET_BY_ID, id);
3972 ASSERT_TRUE(entry.good()); 3972 ASSERT_TRUE(entry.good());
3973 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3973 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3974 EXPECT_FALSE(entry.GetIsUnsynced()); 3974 EXPECT_FALSE(entry.GetIsUnsynced());
3975 EXPECT_TRUE(entry.GetIsDel()); 3975 EXPECT_TRUE(entry.GetIsDel());
3976 EXPECT_FALSE(entry.GetServerIsDel()); 3976 EXPECT_FALSE(entry.GetServerIsDel());
3977 } 3977 }
3978 EXPECT_TRUE(SyncShareNudge()); 3978 SyncShareNudge();
3979 // Say we do not get an update from server confirming deletion. Undelete 3979 // Say we do not get an update from server confirming deletion. Undelete
3980 // from server 3980 // from server
3981 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12, 3981 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12,
3982 foreign_cache_guid(), "-1"); 3982 foreign_cache_guid(), "-1");
3983 EXPECT_TRUE(SyncShareNudge()); 3983 SyncShareNudge();
3984 // IS_DEL and SERVER_IS_DEL now both false. 3984 // IS_DEL and SERVER_IS_DEL now both false.
3985 { 3985 {
3986 syncable::ReadTransaction trans(FROM_HERE, directory()); 3986 syncable::ReadTransaction trans(FROM_HERE, directory());
3987 Entry entry(&trans, GET_BY_ID, id); 3987 Entry entry(&trans, GET_BY_ID, id);
3988 ASSERT_TRUE(entry.good()); 3988 ASSERT_TRUE(entry.good());
3989 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 3989 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
3990 EXPECT_FALSE(entry.GetIsUnsynced()); 3990 EXPECT_FALSE(entry.GetIsUnsynced());
3991 EXPECT_FALSE(entry.GetIsDel()); 3991 EXPECT_FALSE(entry.GetIsDel());
3992 EXPECT_FALSE(entry.GetServerIsDel()); 3992 EXPECT_FALSE(entry.GetServerIsDel());
3993 } 3993 }
3994 } 3994 }
3995 3995
3996 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) { 3996 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) {
3997 Id id1 = ids_.MakeServer("first"), id2 = ids_.MakeServer("second"); 3997 Id id1 = ids_.MakeServer("first"), id2 = ids_.MakeServer("second");
3998 Id root = TestIdFactory::root(); 3998 Id root = TestIdFactory::root();
3999 // Duplicate! expect path clashing! 3999 // Duplicate! expect path clashing!
4000 mock_server_->set_conflict_all_commits(true); 4000 mock_server_->set_conflict_all_commits(true);
4001 mock_server_->AddUpdateBookmark(id1, root, "foo", 1, 10, 4001 mock_server_->AddUpdateBookmark(id1, root, "foo", 1, 10,
4002 foreign_cache_guid(), "-1"); 4002 foreign_cache_guid(), "-1");
4003 mock_server_->AddUpdateBookmark(id2, root, "foo", 1, 10, 4003 mock_server_->AddUpdateBookmark(id2, root, "foo", 1, 10,
4004 foreign_cache_guid(), "-2"); 4004 foreign_cache_guid(), "-2");
4005 EXPECT_TRUE(SyncShareNudge()); 4005 SyncShareNudge();
4006 mock_server_->AddUpdateBookmark(id2, root, "foo2", 2, 20, 4006 mock_server_->AddUpdateBookmark(id2, root, "foo2", 2, 20,
4007 foreign_cache_guid(), "-2"); 4007 foreign_cache_guid(), "-2");
4008 EXPECT_TRUE(SyncShareNudge()); // Now just don't explode. 4008 SyncShareNudge(); // Now just don't explode.
4009 } 4009 }
4010 4010
4011 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) { 4011 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) {
4012 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10, 4012 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10,
4013 foreign_cache_guid(), "-1"); 4013 foreign_cache_guid(), "-1");
4014 mock_server_->SetLastUpdateClientTag("permfolder"); 4014 mock_server_->SetLastUpdateClientTag("permfolder");
4015 4015
4016 EXPECT_TRUE(SyncShareNudge()); 4016 SyncShareNudge();
4017 4017
4018 { 4018 {
4019 syncable::ReadTransaction trans(FROM_HERE, directory()); 4019 syncable::ReadTransaction trans(FROM_HERE, directory());
4020 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4020 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4021 ASSERT_TRUE(perm_folder.good()); 4021 ASSERT_TRUE(perm_folder.good());
4022 EXPECT_FALSE(perm_folder.GetIsDel()); 4022 EXPECT_FALSE(perm_folder.GetIsDel());
4023 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); 4023 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate());
4024 EXPECT_FALSE(perm_folder.GetIsUnsynced()); 4024 EXPECT_FALSE(perm_folder.GetIsUnsynced());
4025 EXPECT_EQ(perm_folder.GetUniqueClientTag(), "permfolder"); 4025 EXPECT_EQ(perm_folder.GetUniqueClientTag(), "permfolder");
4026 EXPECT_EQ(perm_folder.GetNonUniqueName(), "permitem1"); 4026 EXPECT_EQ(perm_folder.GetNonUniqueName(), "permitem1");
4027 } 4027 }
4028 4028
4029 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100, 4029 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100,
4030 foreign_cache_guid(), "-1"); 4030 foreign_cache_guid(), "-1");
4031 mock_server_->SetLastUpdateClientTag("permfolder"); 4031 mock_server_->SetLastUpdateClientTag("permfolder");
4032 EXPECT_TRUE(SyncShareNudge()); 4032 SyncShareNudge();
4033 4033
4034 { 4034 {
4035 syncable::ReadTransaction trans(FROM_HERE, directory()); 4035 syncable::ReadTransaction trans(FROM_HERE, directory());
4036 4036
4037 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4037 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4038 ASSERT_TRUE(perm_folder.good()); 4038 ASSERT_TRUE(perm_folder.good());
4039 EXPECT_FALSE(perm_folder.GetIsDel()); 4039 EXPECT_FALSE(perm_folder.GetIsDel());
4040 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); 4040 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate());
4041 EXPECT_FALSE(perm_folder.GetIsUnsynced()); 4041 EXPECT_FALSE(perm_folder.GetIsUnsynced());
4042 EXPECT_EQ(perm_folder.GetUniqueClientTag(), "permfolder"); 4042 EXPECT_EQ(perm_folder.GetUniqueClientTag(), "permfolder");
4043 EXPECT_EQ(perm_folder.GetNonUniqueName(), "permitem_renamed"); 4043 EXPECT_EQ(perm_folder.GetNonUniqueName(), "permitem_renamed");
4044 } 4044 }
4045 } 4045 }
4046 4046
4047 TEST_F(SyncerTest, ClientTagIllegalUpdateIgnored) { 4047 TEST_F(SyncerTest, ClientTagIllegalUpdateIgnored) {
4048 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10, 4048 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10,
4049 foreign_cache_guid(), "-1"); 4049 foreign_cache_guid(), "-1");
4050 mock_server_->SetLastUpdateClientTag("permfolder"); 4050 mock_server_->SetLastUpdateClientTag("permfolder");
4051 4051
4052 EXPECT_TRUE(SyncShareNudge()); 4052 SyncShareNudge();
4053 4053
4054 { 4054 {
4055 syncable::ReadTransaction trans(FROM_HERE, directory()); 4055 syncable::ReadTransaction trans(FROM_HERE, directory());
4056 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 4056 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
4057 ASSERT_TRUE(perm_folder.good()); 4057 ASSERT_TRUE(perm_folder.good());
4058 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate()); 4058 EXPECT_FALSE(perm_folder.GetIsUnappliedUpdate());
4059 EXPECT_FALSE(perm_folder.GetIsUnsynced()); 4059 EXPECT_FALSE(perm_folder.GetIsUnsynced());
4060 EXPECT_EQ(perm_folder.GetUniqueClientTag(), "permfolder"); 4060 EXPECT_EQ(perm_folder.GetUniqueClientTag(), "permfolder");
4061 EXPECT_TRUE(perm_folder.GetNonUniqueName()== "permitem1"); 4061 EXPECT_TRUE(perm_folder.GetNonUniqueName()== "permitem1");
4062 EXPECT_TRUE(perm_folder.GetId().ServerKnows()); 4062 EXPECT_TRUE(perm_folder.GetId().ServerKnows());
4063 } 4063 }
4064 4064
4065 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100, 4065 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100,
4066 foreign_cache_guid(), "-1"); 4066 foreign_cache_guid(), "-1");
4067 mock_server_->SetLastUpdateClientTag("wrongtag"); 4067 mock_server_->SetLastUpdateClientTag("wrongtag");
4068 EXPECT_TRUE(SyncShareNudge()); 4068 SyncShareNudge();
4069 4069
4070 { 4070 {
4071 syncable::ReadTransaction trans(FROM_HERE, directory()); 4071 syncable::ReadTransaction trans(FROM_HERE, directory());
4072 4072
4073 // This update is rejected because it has the same ID, but a 4073 // This update is rejected because it has the same ID, but a
4074 // different tag than one that is already on the client. 4074 // different tag than one that is already on the client.
4075 // The client has a ServerKnows ID, which cannot be overwritten. 4075 // The client has a ServerKnows ID, which cannot be overwritten.
4076 Entry rejected_update(&trans, GET_BY_CLIENT_TAG, "wrongtag"); 4076 Entry rejected_update(&trans, GET_BY_CLIENT_TAG, "wrongtag");
4077 EXPECT_FALSE(rejected_update.good()); 4077 EXPECT_FALSE(rejected_update.good());
4078 4078
(...skipping 19 matching lines...) Expand all
4098 EXPECT_FALSE(pref.GetId().ServerKnows()); 4098 EXPECT_FALSE(pref.GetId().ServerKnows());
4099 original_metahandle = pref.GetMetahandle(); 4099 original_metahandle = pref.GetMetahandle();
4100 } 4100 }
4101 4101
4102 syncable::Id server_id = TestIdFactory::MakeServer("id"); 4102 syncable::Id server_id = TestIdFactory::MakeServer("id");
4103 mock_server_->AddUpdatePref(server_id.GetServerId(), 4103 mock_server_->AddUpdatePref(server_id.GetServerId(),
4104 ids_.root().GetServerId(), 4104 ids_.root().GetServerId(),
4105 "tag", 10, 100); 4105 "tag", 10, 100);
4106 mock_server_->set_conflict_all_commits(true); 4106 mock_server_->set_conflict_all_commits(true);
4107 4107
4108 EXPECT_FALSE(SyncShareNudge()); 4108 SyncShareNudge();
4109 // This should cause client tag reunion, preserving the metahandle. 4109 // This should cause client tag reunion, preserving the metahandle.
4110 { 4110 {
4111 syncable::ReadTransaction trans(FROM_HERE, directory()); 4111 syncable::ReadTransaction trans(FROM_HERE, directory());
4112 4112
4113 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); 4113 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag");
4114 ASSERT_TRUE(pref.good()); 4114 ASSERT_TRUE(pref.good());
4115 EXPECT_FALSE(pref.GetIsDel()); 4115 EXPECT_FALSE(pref.GetIsDel());
4116 EXPECT_FALSE(pref.GetIsUnappliedUpdate()); 4116 EXPECT_FALSE(pref.GetIsUnappliedUpdate());
4117 EXPECT_TRUE(pref.GetIsUnsynced()); 4117 EXPECT_TRUE(pref.GetIsUnsynced());
4118 EXPECT_EQ(10, pref.GetBaseVersion()); 4118 EXPECT_EQ(10, pref.GetBaseVersion());
4119 // Entry should have been given the new ID while preserving the 4119 // Entry should have been given the new ID while preserving the
4120 // metahandle; client should have won the conflict resolution. 4120 // metahandle; client should have won the conflict resolution.
4121 EXPECT_EQ(original_metahandle, pref.GetMetahandle()); 4121 EXPECT_EQ(original_metahandle, pref.GetMetahandle());
4122 EXPECT_EQ("tag", pref.GetUniqueClientTag()); 4122 EXPECT_EQ("tag", pref.GetUniqueClientTag());
4123 EXPECT_TRUE(pref.GetId().ServerKnows()); 4123 EXPECT_TRUE(pref.GetId().ServerKnows());
4124 } 4124 }
4125 4125
4126 mock_server_->set_conflict_all_commits(false); 4126 mock_server_->set_conflict_all_commits(false);
4127 EXPECT_TRUE(SyncShareNudge()); 4127 SyncShareNudge();
4128 4128
4129 // The resolved entry ought to commit cleanly. 4129 // The resolved entry ought to commit cleanly.
4130 { 4130 {
4131 syncable::ReadTransaction trans(FROM_HERE, directory()); 4131 syncable::ReadTransaction trans(FROM_HERE, directory());
4132 4132
4133 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); 4133 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag");
4134 ASSERT_TRUE(pref.good()); 4134 ASSERT_TRUE(pref.good());
4135 EXPECT_FALSE(pref.GetIsDel()); 4135 EXPECT_FALSE(pref.GetIsDel());
4136 EXPECT_FALSE(pref.GetIsUnappliedUpdate()); 4136 EXPECT_FALSE(pref.GetIsUnappliedUpdate());
4137 EXPECT_FALSE(pref.GetIsUnsynced()); 4137 EXPECT_FALSE(pref.GetIsUnsynced());
(...skipping 22 matching lines...) Expand all
4160 // helps us clean up those entries). 4160 // helps us clean up those entries).
4161 pref.PutIsDel(true); 4161 pref.PutIsDel(true);
4162 } 4162 }
4163 4163
4164 // Prepare an update with the same unique client tag. 4164 // Prepare an update with the same unique client tag.
4165 syncable::Id server_id = TestIdFactory::MakeServer("id"); 4165 syncable::Id server_id = TestIdFactory::MakeServer("id");
4166 mock_server_->AddUpdatePref(server_id.GetServerId(), 4166 mock_server_->AddUpdatePref(server_id.GetServerId(),
4167 ids_.root().GetServerId(), 4167 ids_.root().GetServerId(),
4168 "tag", 10, 100); 4168 "tag", 10, 100);
4169 4169
4170 EXPECT_TRUE(SyncShareNudge()); 4170 SyncShareNudge();
4171 // The local entry will be overwritten. 4171 // The local entry will be overwritten.
4172 { 4172 {
4173 syncable::ReadTransaction trans(FROM_HERE, directory()); 4173 syncable::ReadTransaction trans(FROM_HERE, directory());
4174 4174
4175 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag"); 4175 Entry pref(&trans, GET_BY_CLIENT_TAG, "tag");
4176 ASSERT_TRUE(pref.good()); 4176 ASSERT_TRUE(pref.good());
4177 ASSERT_TRUE(pref.GetId().ServerKnows()); 4177 ASSERT_TRUE(pref.GetId().ServerKnows());
4178 EXPECT_FALSE(pref.GetIsDel()); 4178 EXPECT_FALSE(pref.GetIsDel());
4179 EXPECT_FALSE(pref.GetIsUnappliedUpdate()); 4179 EXPECT_FALSE(pref.GetIsUnappliedUpdate());
4180 EXPECT_FALSE(pref.GetIsUnsynced()); 4180 EXPECT_FALSE(pref.GetIsUnsynced());
4181 EXPECT_EQ(pref.GetBaseVersion(), 10); 4181 EXPECT_EQ(pref.GetBaseVersion(), 10);
4182 EXPECT_EQ(pref.GetUniqueClientTag(), "tag"); 4182 EXPECT_EQ(pref.GetUniqueClientTag(), "tag");
4183 } 4183 }
4184 } 4184 }
4185 4185
4186 TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) { 4186 TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) {
4187 // This test is written assuming that ID comparison 4187 // This test is written assuming that ID comparison
4188 // will work out in a particular way. 4188 // will work out in a particular way.
4189 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(2)); 4189 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(2));
4190 EXPECT_TRUE(ids_.FromNumber(3) < ids_.FromNumber(4)); 4190 EXPECT_TRUE(ids_.FromNumber(3) < ids_.FromNumber(4));
4191 4191
4192 syncable::Id id1 = TestIdFactory::MakeServer("1"); 4192 syncable::Id id1 = TestIdFactory::MakeServer("1");
4193 mock_server_->AddUpdatePref(id1.GetServerId(), "", "tag1", 10, 100); 4193 mock_server_->AddUpdatePref(id1.GetServerId(), "", "tag1", 10, 100);
4194 4194
4195 syncable::Id id4 = TestIdFactory::MakeServer("4"); 4195 syncable::Id id4 = TestIdFactory::MakeServer("4");
4196 mock_server_->AddUpdatePref(id4.GetServerId(), "", "tag2", 11, 110); 4196 mock_server_->AddUpdatePref(id4.GetServerId(), "", "tag2", 11, 110);
4197 4197
4198 mock_server_->set_conflict_all_commits(true); 4198 mock_server_->set_conflict_all_commits(true);
4199 4199
4200 EXPECT_TRUE(SyncShareNudge()); 4200 SyncShareNudge();
4201 int64 tag1_metahandle = syncable::kInvalidMetaHandle; 4201 int64 tag1_metahandle = syncable::kInvalidMetaHandle;
4202 int64 tag2_metahandle = syncable::kInvalidMetaHandle; 4202 int64 tag2_metahandle = syncable::kInvalidMetaHandle;
4203 // This should cause client tag overwrite. 4203 // This should cause client tag overwrite.
4204 { 4204 {
4205 syncable::ReadTransaction trans(FROM_HERE, directory()); 4205 syncable::ReadTransaction trans(FROM_HERE, directory());
4206 4206
4207 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); 4207 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1");
4208 ASSERT_TRUE(tag1.good()); 4208 ASSERT_TRUE(tag1.good());
4209 ASSERT_TRUE(tag1.GetId().ServerKnows()); 4209 ASSERT_TRUE(tag1.GetId().ServerKnows());
4210 ASSERT_TRUE(id1 == tag1.GetId()); 4210 ASSERT_TRUE(id1 == tag1.GetId());
(...skipping 21 matching lines...) Expand all
4232 4232
4233 syncable::Directory::Metahandles children; 4233 syncable::Directory::Metahandles children;
4234 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); 4234 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children);
4235 ASSERT_EQ(2U, children.size()); 4235 ASSERT_EQ(2U, children.size());
4236 } 4236 }
4237 4237
4238 syncable::Id id2 = TestIdFactory::MakeServer("2"); 4238 syncable::Id id2 = TestIdFactory::MakeServer("2");
4239 mock_server_->AddUpdatePref(id2.GetServerId(), "", "tag1", 12, 120); 4239 mock_server_->AddUpdatePref(id2.GetServerId(), "", "tag1", 12, 120);
4240 syncable::Id id3 = TestIdFactory::MakeServer("3"); 4240 syncable::Id id3 = TestIdFactory::MakeServer("3");
4241 mock_server_->AddUpdatePref(id3.GetServerId(), "", "tag2", 13, 130); 4241 mock_server_->AddUpdatePref(id3.GetServerId(), "", "tag2", 13, 130);
4242 EXPECT_TRUE(SyncShareNudge()); 4242 SyncShareNudge();
4243 4243
4244 { 4244 {
4245 syncable::ReadTransaction trans(FROM_HERE, directory()); 4245 syncable::ReadTransaction trans(FROM_HERE, directory());
4246 4246
4247 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); 4247 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1");
4248 ASSERT_TRUE(tag1.good()); 4248 ASSERT_TRUE(tag1.good());
4249 ASSERT_TRUE(tag1.GetId().ServerKnows()); 4249 ASSERT_TRUE(tag1.GetId().ServerKnows());
4250 ASSERT_EQ(id1, tag1.GetId()) 4250 ASSERT_EQ(id1, tag1.GetId())
4251 << "ID 1 should be kept, since it was less than ID 2."; 4251 << "ID 1 should be kept, since it was less than ID 2.";
4252 EXPECT_FALSE(tag1.GetIsDel()); 4252 EXPECT_FALSE(tag1.GetIsDel());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
4308 mock_server_->AddUpdatePref(ids_.FromNumber(202).GetServerId(), "", "tag c", 4308 mock_server_->AddUpdatePref(ids_.FromNumber(202).GetServerId(), "", "tag c",
4309 19, 190); 4309 19, 190);
4310 mock_server_->AddUpdatePref(ids_.FromNumber(204).GetServerId(), "", "tag c", 4310 mock_server_->AddUpdatePref(ids_.FromNumber(204).GetServerId(), "", "tag c",
4311 20, 200); 4311 20, 200);
4312 // Least ID: winner. 4312 // Least ID: winner.
4313 mock_server_->AddUpdatePref(ids_.FromNumber(201).GetServerId(), "", "tag c", 4313 mock_server_->AddUpdatePref(ids_.FromNumber(201).GetServerId(), "", "tag c",
4314 21, 210); 4314 21, 210);
4315 4315
4316 mock_server_->set_conflict_all_commits(true); 4316 mock_server_->set_conflict_all_commits(true);
4317 4317
4318 EXPECT_TRUE(SyncShareNudge()); 4318 SyncShareNudge();
4319 // This should cause client tag overwrite. 4319 // This should cause client tag overwrite.
4320 { 4320 {
4321 syncable::ReadTransaction trans(FROM_HERE, directory()); 4321 syncable::ReadTransaction trans(FROM_HERE, directory());
4322 4322
4323 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a"); 4323 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a");
4324 ASSERT_TRUE(tag_a.good()); 4324 ASSERT_TRUE(tag_a.good());
4325 EXPECT_TRUE(tag_a.GetId().ServerKnows()); 4325 EXPECT_TRUE(tag_a.GetId().ServerKnows());
4326 EXPECT_EQ(ids_.FromNumber(1), tag_a.GetId()); 4326 EXPECT_EQ(ids_.FromNumber(1), tag_a.GetId());
4327 EXPECT_FALSE(tag_a.GetIsDel()); 4327 EXPECT_FALSE(tag_a.GetIsDel());
4328 EXPECT_FALSE(tag_a.GetIsUnappliedUpdate()); 4328 EXPECT_FALSE(tag_a.GetIsUnappliedUpdate());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4360 ASSERT_EQ(3U, children.size()); 4360 ASSERT_EQ(3U, children.size());
4361 } 4361 }
4362 } 4362 }
4363 4363
4364 // This verifies transition to implicit permanent folders. 4364 // This verifies transition to implicit permanent folders.
4365 TEST_F(SyncerTest, EntryWithParentIdUpdatedWithEntryWithoutParentId) { 4365 TEST_F(SyncerTest, EntryWithParentIdUpdatedWithEntryWithoutParentId) {
4366 // Make sure SPECIFICS root exists so that we can get its parent ID. 4366 // Make sure SPECIFICS root exists so that we can get its parent ID.
4367 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, 4367 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1,
4368 DefaultPreferencesSpecifics()); 4368 DefaultPreferencesSpecifics());
4369 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); 4369 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES));
4370 EXPECT_TRUE(SyncShareNudge()); 4370 SyncShareNudge();
4371 4371
4372 Id pref_root_id; 4372 Id pref_root_id;
4373 { 4373 {
4374 // Preferences type root should have been created by the update above. 4374 // Preferences type root should have been created by the update above.
4375 // We need it in order to get its ID. 4375 // We need it in order to get its ID.
4376 syncable::ReadTransaction trans(FROM_HERE, directory()); 4376 syncable::ReadTransaction trans(FROM_HERE, directory());
4377 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); 4377 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES);
4378 ASSERT_TRUE(pref_root.good()); 4378 ASSERT_TRUE(pref_root.good());
4379 pref_root_id = pref_root.GetId(); 4379 pref_root_id = pref_root.GetId();
4380 } 4380 }
4381 4381
4382 // Add a preference item with explicit parent ID. 4382 // Add a preference item with explicit parent ID.
4383 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), 4383 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(),
4384 ids_.FromNumber(1).GetServerId(), "tag", 1, 10); 4384 ids_.FromNumber(1).GetServerId(), "tag", 1, 10);
4385 4385
4386 EXPECT_TRUE(SyncShareNudge()); 4386 SyncShareNudge();
4387 4387
4388 { 4388 {
4389 syncable::ReadTransaction trans(FROM_HERE, directory()); 4389 syncable::ReadTransaction trans(FROM_HERE, directory());
4390 Entry pref_entry(&trans, GET_BY_CLIENT_TAG, "tag"); 4390 Entry pref_entry(&trans, GET_BY_CLIENT_TAG, "tag");
4391 ASSERT_TRUE(pref_entry.good()); 4391 ASSERT_TRUE(pref_entry.good());
4392 ASSERT_EQ(pref_root_id, pref_entry.GetParentId()); 4392 ASSERT_EQ(pref_root_id, pref_entry.GetParentId());
4393 } 4393 }
4394 4394
4395 // Make another update where the same item get updated, this time 4395 // Make another update where the same item get updated, this time
4396 // with implicit parent ID. 4396 // with implicit parent ID.
4397 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), "", "tag", 2, 4397 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), "", "tag", 2,
4398 20); 4398 20);
4399 4399
4400 EXPECT_TRUE(SyncShareNudge()); 4400 SyncShareNudge();
4401 4401
4402 { 4402 {
4403 syncable::ReadTransaction trans(FROM_HERE, directory()); 4403 syncable::ReadTransaction trans(FROM_HERE, directory());
4404 Entry pref_entry(&trans, GET_BY_CLIENT_TAG, "tag"); 4404 Entry pref_entry(&trans, GET_BY_CLIENT_TAG, "tag");
4405 ASSERT_TRUE(pref_entry.good()); 4405 ASSERT_TRUE(pref_entry.good());
4406 ASSERT_TRUE(pref_entry.GetParentId().IsNull()); 4406 ASSERT_TRUE(pref_entry.GetParentId().IsNull());
4407 4407
4408 // Verify that there is still one node under the type root. 4408 // Verify that there is still one node under the type root.
4409 syncable::Directory::Metahandles children; 4409 syncable::Directory::Metahandles children;
4410 directory()->GetChildHandlesById(&trans, pref_root_id, &children); 4410 directory()->GetChildHandlesById(&trans, pref_root_id, &children);
(...skipping 20 matching lines...) Expand all
4431 EXPECT_FALSE(tag_bob.good()); 4431 EXPECT_FALSE(tag_bob.good());
4432 } 4432 }
4433 4433
4434 // Now download some tagged items as updates. 4434 // Now download some tagged items as updates.
4435 mock_server_->AddUpdateDirectory( 4435 mock_server_->AddUpdateDirectory(
4436 1, 0, "update1", 1, 10, std::string(), std::string()); 4436 1, 0, "update1", 1, 10, std::string(), std::string());
4437 mock_server_->SetLastUpdateServerTag("alpha"); 4437 mock_server_->SetLastUpdateServerTag("alpha");
4438 mock_server_->AddUpdateDirectory( 4438 mock_server_->AddUpdateDirectory(
4439 2, 0, "update2", 2, 20, std::string(), std::string()); 4439 2, 0, "update2", 2, 20, std::string(), std::string());
4440 mock_server_->SetLastUpdateServerTag("bob"); 4440 mock_server_->SetLastUpdateServerTag("bob");
4441 EXPECT_TRUE(SyncShareNudge()); 4441 SyncShareNudge();
4442 4442
4443 { 4443 {
4444 syncable::ReadTransaction trans(FROM_HERE, directory()); 4444 syncable::ReadTransaction trans(FROM_HERE, directory());
4445 4445
4446 // The new items should be applied as new entries, and we should be able 4446 // The new items should be applied as new entries, and we should be able
4447 // to look them up by their tag values. 4447 // to look them up by their tag values.
4448 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); 4448 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha");
4449 ASSERT_TRUE(tag_alpha.good()); 4449 ASSERT_TRUE(tag_alpha.good());
4450 ASSERT_TRUE(!tag_alpha.GetIsDel()); 4450 ASSERT_TRUE(!tag_alpha.GetIsDel());
4451 ASSERT_TRUE(tag_alpha.GetUniqueServerTag()== "alpha"); 4451 ASSERT_TRUE(tag_alpha.GetUniqueServerTag()== "alpha");
(...skipping 10 matching lines...) Expand all
4462 ASSERT_TRUE(hurdle.GetUniqueServerTag().empty()); 4462 ASSERT_TRUE(hurdle.GetUniqueServerTag().empty());
4463 ASSERT_TRUE(hurdle.GetNonUniqueName()== "bob"); 4463 ASSERT_TRUE(hurdle.GetNonUniqueName()== "bob");
4464 } 4464 }
4465 } 4465 }
4466 4466
4467 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) { 4467 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) {
4468 // The expectations of this test happen in the MockConnectionManager's 4468 // The expectations of this test happen in the MockConnectionManager's
4469 // GetUpdates handler. EnableDatatype sets the expectation value from our 4469 // GetUpdates handler. EnableDatatype sets the expectation value from our
4470 // set of enabled/disabled datatypes. 4470 // set of enabled/disabled datatypes.
4471 EnableDatatype(BOOKMARKS); 4471 EnableDatatype(BOOKMARKS);
4472 EXPECT_TRUE(SyncShareNudge()); 4472 SyncShareNudge();
4473 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4473 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4474 4474
4475 EnableDatatype(AUTOFILL); 4475 EnableDatatype(AUTOFILL);
4476 EXPECT_TRUE(SyncShareNudge()); 4476 SyncShareNudge();
4477 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4477 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4478 4478
4479 EnableDatatype(PREFERENCES); 4479 EnableDatatype(PREFERENCES);
4480 EXPECT_TRUE(SyncShareNudge()); 4480 SyncShareNudge();
4481 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4481 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4482 4482
4483 DisableDatatype(BOOKMARKS); 4483 DisableDatatype(BOOKMARKS);
4484 EXPECT_TRUE(SyncShareNudge()); 4484 SyncShareNudge();
4485 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4485 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4486 4486
4487 DisableDatatype(AUTOFILL); 4487 DisableDatatype(AUTOFILL);
4488 EXPECT_TRUE(SyncShareNudge()); 4488 SyncShareNudge();
4489 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4489 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4490 4490
4491 DisableDatatype(PREFERENCES); 4491 DisableDatatype(PREFERENCES);
4492 EnableDatatype(AUTOFILL); 4492 EnableDatatype(AUTOFILL);
4493 EXPECT_TRUE(SyncShareNudge()); 4493 SyncShareNudge();
4494 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4494 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4495 } 4495 }
4496 4496
4497 // A typical scenario: server and client each have one update for the other. 4497 // A typical scenario: server and client each have one update for the other.
4498 // This is the "happy path" alternative to UpdateFailsThenDontCommit. 4498 // This is the "happy path" alternative to UpdateFailsThenDontCommit.
4499 TEST_F(SyncerTest, UpdateThenCommit) { 4499 TEST_F(SyncerTest, UpdateThenCommit) {
4500 syncable::Id to_receive = ids_.NewServerId(); 4500 syncable::Id to_receive = ids_.NewServerId();
4501 syncable::Id to_commit = ids_.NewLocalId(); 4501 syncable::Id to_commit = ids_.NewLocalId();
4502 4502
4503 mock_server_->AddUpdateDirectory(to_receive, ids_.root(), "x", 1, 10, 4503 mock_server_->AddUpdateDirectory(to_receive, ids_.root(), "x", 1, 10,
4504 foreign_cache_guid(), "-1"); 4504 foreign_cache_guid(), "-1");
4505 int64 commit_handle = CreateUnsyncedDirectory("y", to_commit); 4505 int64 commit_handle = CreateUnsyncedDirectory("y", to_commit);
4506 EXPECT_TRUE(SyncShareNudge()); 4506 SyncShareNudge();
4507 4507
4508 // The sync cycle should have included a GetUpdate, then a commit. By the 4508 // The sync cycle should have included a GetUpdate, then a commit. By the
4509 // time the commit happened, we should have known for sure that there were no 4509 // time the commit happened, we should have known for sure that there were no
4510 // hierarchy conflicts, and reported this fact to the server. 4510 // hierarchy conflicts, and reported this fact to the server.
4511 ASSERT_TRUE(mock_server_->last_request().has_commit()); 4511 ASSERT_TRUE(mock_server_->last_request().has_commit());
4512 VerifyNoHierarchyConflictsReported(mock_server_->last_request()); 4512 VerifyNoHierarchyConflictsReported(mock_server_->last_request());
4513 4513
4514 syncable::ReadTransaction trans(FROM_HERE, directory()); 4514 syncable::ReadTransaction trans(FROM_HERE, directory());
4515 4515
4516 Entry received(&trans, GET_BY_ID, to_receive); 4516 Entry received(&trans, GET_BY_ID, to_receive);
(...skipping 11 matching lines...) Expand all
4528 // We should not attempt to commit anything unless we successfully downloaded 4528 // We should not attempt to commit anything unless we successfully downloaded
4529 // updates, otherwise we risk causing a server-side conflict. 4529 // updates, otherwise we risk causing a server-side conflict.
4530 TEST_F(SyncerTest, UpdateFailsThenDontCommit) { 4530 TEST_F(SyncerTest, UpdateFailsThenDontCommit) {
4531 syncable::Id to_receive = ids_.NewServerId(); 4531 syncable::Id to_receive = ids_.NewServerId();
4532 syncable::Id to_commit = ids_.NewLocalId(); 4532 syncable::Id to_commit = ids_.NewLocalId();
4533 4533
4534 mock_server_->AddUpdateDirectory(to_receive, ids_.root(), "x", 1, 10, 4534 mock_server_->AddUpdateDirectory(to_receive, ids_.root(), "x", 1, 10,
4535 foreign_cache_guid(), "-1"); 4535 foreign_cache_guid(), "-1");
4536 int64 commit_handle = CreateUnsyncedDirectory("y", to_commit); 4536 int64 commit_handle = CreateUnsyncedDirectory("y", to_commit);
4537 mock_server_->FailNextPostBufferToPathCall(); 4537 mock_server_->FailNextPostBufferToPathCall();
4538 EXPECT_FALSE(SyncShareNudge()); 4538 SyncShareNudge();
4539 4539
4540 syncable::ReadTransaction trans(FROM_HERE, directory()); 4540 syncable::ReadTransaction trans(FROM_HERE, directory());
4541 4541
4542 // We did not receive this update. 4542 // We did not receive this update.
4543 Entry received(&trans, GET_BY_ID, to_receive); 4543 Entry received(&trans, GET_BY_ID, to_receive);
4544 ASSERT_FALSE(received.good()); 4544 ASSERT_FALSE(received.good());
4545 4545
4546 // And our local update remains unapplied. 4546 // And our local update remains unapplied.
4547 Entry committed(&trans, GET_BY_HANDLE, commit_handle); 4547 Entry committed(&trans, GET_BY_HANDLE, commit_handle);
4548 ASSERT_TRUE(committed.good()); 4548 ASSERT_TRUE(committed.good());
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 } 4812 }
4813 4813
4814 protected: 4814 protected:
4815 syncable::Id local_id_; 4815 syncable::Id local_id_;
4816 int64 metahandle_; 4816 int64 metahandle_;
4817 }; 4817 };
4818 4818
4819 TEST_F(SyncerBookmarksTest, CreateSyncThenDeleteSync) { 4819 TEST_F(SyncerBookmarksTest, CreateSyncThenDeleteSync) {
4820 Create(); 4820 Create();
4821 ExpectUnsyncedCreation(); 4821 ExpectUnsyncedCreation();
4822 EXPECT_TRUE(SyncShareNudge()); 4822 SyncShareNudge();
4823 ExpectSyncedAndCreated(); 4823 ExpectSyncedAndCreated();
4824 Delete(); 4824 Delete();
4825 ExpectUnsyncedDeletion(); 4825 ExpectUnsyncedDeletion();
4826 EXPECT_TRUE(SyncShareNudge()); 4826 SyncShareNudge();
4827 ExpectSyncedAndDeleted(); 4827 ExpectSyncedAndDeleted();
4828 } 4828 }
4829 4829
4830 TEST_F(SyncerBookmarksTest, CreateThenDeleteBeforeSync) { 4830 TEST_F(SyncerBookmarksTest, CreateThenDeleteBeforeSync) {
4831 Create(); 4831 Create();
4832 ExpectUnsyncedCreation(); 4832 ExpectUnsyncedCreation();
4833 Delete(); 4833 Delete();
4834 4834
4835 // Deleting before the initial commit should result in not needing to send 4835 // Deleting before the initial commit should result in not needing to send
4836 // the delete to the server. It will still be in an unsynced state, but with 4836 // the delete to the server. It will still be in an unsynced state, but with
4837 // IS_UNSYNCED set to false. 4837 // IS_UNSYNCED set to false.
4838 { 4838 {
4839 syncable::ReadTransaction trans(FROM_HERE, directory()); 4839 syncable::ReadTransaction trans(FROM_HERE, directory());
4840 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 4840 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
4841 4841
4842 EXPECT_EQ(metahandle_, entry.GetMetahandle()); 4842 EXPECT_EQ(metahandle_, entry.GetMetahandle());
4843 EXPECT_TRUE(entry.GetIsDel()); 4843 EXPECT_TRUE(entry.GetIsDel());
4844 EXPECT_FALSE(entry.GetServerIsDel()); 4844 EXPECT_FALSE(entry.GetServerIsDel());
4845 EXPECT_FALSE(entry.GetIsUnsynced()); 4845 EXPECT_FALSE(entry.GetIsUnsynced());
4846 EXPECT_FALSE(entry.GetIsUnappliedUpdate()); 4846 EXPECT_FALSE(entry.GetIsUnappliedUpdate());
4847 EXPECT_EQ(entry.GetBaseVersion(), -1); 4847 EXPECT_EQ(entry.GetBaseVersion(), -1);
4848 EXPECT_EQ(entry.GetServerVersion(), 0); 4848 EXPECT_EQ(entry.GetServerVersion(), 0);
4849 } 4849 }
4850 } 4850 }
4851 4851
4852 TEST_F(SyncerBookmarksTest, LocalDeleteRemoteChangeConflict) { 4852 TEST_F(SyncerBookmarksTest, LocalDeleteRemoteChangeConflict) {
4853 Create(); 4853 Create();
4854 ExpectUnsyncedCreation(); 4854 ExpectUnsyncedCreation();
4855 EXPECT_TRUE(SyncShareNudge()); 4855 SyncShareNudge();
4856 ExpectSyncedAndCreated(); 4856 ExpectSyncedAndCreated();
4857 Delete(); 4857 Delete();
4858 ExpectUnsyncedDeletion(); 4858 ExpectUnsyncedDeletion();
4859 4859
4860 // Trigger a getupdates that modifies the bookmark. The update should be 4860 // Trigger a getupdates that modifies the bookmark. The update should be
4861 // clobbered by the local delete. 4861 // clobbered by the local delete.
4862 mock_server_->AddUpdateBookmark(GetServerId(), Id::GetRoot(), "dummy", 10, 10, 4862 mock_server_->AddUpdateBookmark(GetServerId(), Id::GetRoot(), "dummy", 10, 10,
4863 local_cache_guid(), local_id_.GetServerId()); 4863 local_cache_guid(), local_id_.GetServerId());
4864 4864
4865 EXPECT_TRUE(SyncShareNudge()); 4865 SyncShareNudge();
4866 ExpectSyncedAndDeleted(); 4866 ExpectSyncedAndDeleted();
4867 } 4867 }
4868 4868
4869 TEST_F(SyncerBookmarksTest, CreateThenDeleteDuringCommit) { 4869 TEST_F(SyncerBookmarksTest, CreateThenDeleteDuringCommit) {
4870 Create(); 4870 Create();
4871 ExpectUnsyncedCreation(); 4871 ExpectUnsyncedCreation();
4872 4872
4873 // In the middle of the initial creation commit, perform a deletion. 4873 // In the middle of the initial creation commit, perform a deletion.
4874 // This should trigger performing two consecutive commit cycles, resulting 4874 // This should trigger performing two consecutive commit cycles, resulting
4875 // in the bookmark being both deleted and synced. 4875 // in the bookmark being both deleted and synced.
4876 mock_server_->SetMidCommitCallback( 4876 mock_server_->SetMidCommitCallback(
4877 base::Bind(&SyncerBookmarksTest::Delete, base::Unretained(this))); 4877 base::Bind(&SyncerBookmarksTest::Delete, base::Unretained(this)));
4878 4878
4879 EXPECT_TRUE(SyncShareNudge()); 4879 SyncShareNudge();
4880 ExpectSyncedAndDeleted(); 4880 ExpectSyncedAndDeleted();
4881 } 4881 }
4882 4882
4883 TEST_F(SyncerBookmarksTest, CreateThenUpdateAndDeleteDuringCommit) { 4883 TEST_F(SyncerBookmarksTest, CreateThenUpdateAndDeleteDuringCommit) {
4884 Create(); 4884 Create();
4885 ExpectUnsyncedCreation(); 4885 ExpectUnsyncedCreation();
4886 4886
4887 // In the middle of the initial creation commit, perform an updated followed 4887 // In the middle of the initial creation commit, perform an updated followed
4888 // by a deletion. This should trigger performing two consecutive commit 4888 // by a deletion. This should trigger performing two consecutive commit
4889 // cycles, resulting in the bookmark being both deleted and synced. 4889 // cycles, resulting in the bookmark being both deleted and synced.
4890 mock_server_->SetMidCommitCallback(base::Bind( 4890 mock_server_->SetMidCommitCallback(base::Bind(
4891 &SyncerBookmarksTest::UpdateAndDelete, base::Unretained(this))); 4891 &SyncerBookmarksTest::UpdateAndDelete, base::Unretained(this)));
4892 4892
4893 EXPECT_TRUE(SyncShareNudge()); 4893 SyncShareNudge();
4894 ExpectSyncedAndDeleted(); 4894 ExpectSyncedAndDeleted();
4895 } 4895 }
4896 4896
4897 // Test what happens if a client deletes, then recreates, an object very 4897 // Test what happens if a client deletes, then recreates, an object very
4898 // quickly. It is possible that the deletion gets sent as a commit, and 4898 // quickly. It is possible that the deletion gets sent as a commit, and
4899 // the undelete happens during the commit request. The principle here 4899 // the undelete happens during the commit request. The principle here
4900 // is that with a single committing client, conflicts should never 4900 // is that with a single committing client, conflicts should never
4901 // be encountered, and a client encountering its past actions during 4901 // be encountered, and a client encountering its past actions during
4902 // getupdates should never feed back to override later actions. 4902 // getupdates should never feed back to override later actions.
4903 // 4903 //
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
5050 5050
5051 protected: 5051 protected:
5052 const std::string client_tag_; 5052 const std::string client_tag_;
5053 syncable::Id local_id_; 5053 syncable::Id local_id_;
5054 int64 metahandle_; 5054 int64 metahandle_;
5055 }; 5055 };
5056 5056
5057 TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) { 5057 TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) {
5058 Create(); 5058 Create();
5059 ExpectUnsyncedCreation(); 5059 ExpectUnsyncedCreation();
5060 EXPECT_TRUE(SyncShareNudge()); 5060 SyncShareNudge();
5061 5061
5062 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5062 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5063 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5063 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5064 ExpectSyncedAndCreated(); 5064 ExpectSyncedAndCreated();
5065 5065
5066 // Delete, begin committing the delete, then undelete while committing. 5066 // Delete, begin committing the delete, then undelete while committing.
5067 Delete(); 5067 Delete();
5068 ExpectUnsyncedDeletion(); 5068 ExpectUnsyncedDeletion();
5069 mock_server_->SetMidCommitCallback( 5069 mock_server_->SetMidCommitCallback(
5070 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this))); 5070 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this)));
5071 EXPECT_TRUE(SyncShareNudge()); 5071 SyncShareNudge();
5072 5072
5073 // We will continue to commit until all nodes are synced, so we expect 5073 // We will continue to commit until all nodes are synced, so we expect
5074 // that both the delete and following undelete were committed. We haven't 5074 // that both the delete and following undelete were committed. We haven't
5075 // downloaded any updates, though, so the SERVER fields will be the same 5075 // downloaded any updates, though, so the SERVER fields will be the same
5076 // as they were at the start of the cycle. 5076 // as they were at the start of the cycle.
5077 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5077 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5078 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5078 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5079 5079
5080 { 5080 {
5081 syncable::ReadTransaction trans(FROM_HERE, directory()); 5081 syncable::ReadTransaction trans(FROM_HERE, directory());
(...skipping 10 matching lines...) Expand all
5092 5092
5093 // Now, encounter a GetUpdates corresponding to the deletion from 5093 // Now, encounter a GetUpdates corresponding to the deletion from
5094 // the server. The undeletion should prevail again and be committed. 5094 // the server. The undeletion should prevail again and be committed.
5095 // None of this should trigger any conflict detection -- it is perfectly 5095 // None of this should trigger any conflict detection -- it is perfectly
5096 // normal to recieve updates from our own commits. 5096 // normal to recieve updates from our own commits.
5097 mock_server_->SetMidCommitCallback(base::Closure()); 5097 mock_server_->SetMidCommitCallback(base::Closure());
5098 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 5098 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
5099 update->set_originator_cache_guid(local_cache_guid()); 5099 update->set_originator_cache_guid(local_cache_guid());
5100 update->set_originator_client_item_id(local_id_.GetServerId()); 5100 update->set_originator_client_item_id(local_id_.GetServerId());
5101 5101
5102 EXPECT_TRUE(SyncShareNudge()); 5102 SyncShareNudge();
5103 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5103 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5104 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5104 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5105 ExpectSyncedAndCreated(); 5105 ExpectSyncedAndCreated();
5106 } 5106 }
5107 5107
5108 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { 5108 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) {
5109 Create(); 5109 Create();
5110 ExpectUnsyncedCreation(); 5110 ExpectUnsyncedCreation();
5111 EXPECT_TRUE(SyncShareNudge()); 5111 SyncShareNudge();
5112 5112
5113 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5113 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5114 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5114 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5115 ExpectSyncedAndCreated(); 5115 ExpectSyncedAndCreated();
5116 5116
5117 // Delete and undelete, then sync to pick up the result. 5117 // Delete and undelete, then sync to pick up the result.
5118 Delete(); 5118 Delete();
5119 ExpectUnsyncedDeletion(); 5119 ExpectUnsyncedDeletion();
5120 Undelete(); 5120 Undelete();
5121 ExpectUnsyncedEdit(); // Edit, not undelete: server thinks it exists. 5121 ExpectUnsyncedEdit(); // Edit, not undelete: server thinks it exists.
5122 EXPECT_TRUE(SyncShareNudge()); 5122 SyncShareNudge();
5123 5123
5124 // The item ought to have committed successfully. 5124 // The item ought to have committed successfully.
5125 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5125 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5126 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5126 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5127 ExpectSyncedAndCreated(); 5127 ExpectSyncedAndCreated();
5128 { 5128 {
5129 syncable::ReadTransaction trans(FROM_HERE, directory()); 5129 syncable::ReadTransaction trans(FROM_HERE, directory());
5130 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 5130 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
5131 EXPECT_EQ(2, entry.GetBaseVersion()); 5131 EXPECT_EQ(2, entry.GetBaseVersion());
5132 } 5132 }
5133 5133
5134 // Now, encounter a GetUpdates corresponding to the just-committed 5134 // Now, encounter a GetUpdates corresponding to the just-committed
5135 // update. 5135 // update.
5136 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 5136 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
5137 update->set_originator_cache_guid(local_cache_guid()); 5137 update->set_originator_cache_guid(local_cache_guid());
5138 update->set_originator_client_item_id(local_id_.GetServerId()); 5138 update->set_originator_client_item_id(local_id_.GetServerId());
5139 EXPECT_TRUE(SyncShareNudge()); 5139 SyncShareNudge();
5140 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5140 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5141 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5141 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5142 ExpectSyncedAndCreated(); 5142 ExpectSyncedAndCreated();
5143 } 5143 }
5144 5144
5145 TEST_F(SyncerUndeletionTest, UndeleteAfterCommitButBeforeGetUpdates) { 5145 TEST_F(SyncerUndeletionTest, UndeleteAfterCommitButBeforeGetUpdates) {
5146 Create(); 5146 Create();
5147 ExpectUnsyncedCreation(); 5147 ExpectUnsyncedCreation();
5148 EXPECT_TRUE(SyncShareNudge()); 5148 SyncShareNudge();
5149 5149
5150 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5150 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5151 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5151 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5152 ExpectSyncedAndCreated(); 5152 ExpectSyncedAndCreated();
5153 5153
5154 // Delete and commit. 5154 // Delete and commit.
5155 Delete(); 5155 Delete();
5156 ExpectUnsyncedDeletion(); 5156 ExpectUnsyncedDeletion();
5157 EXPECT_TRUE(SyncShareNudge()); 5157 SyncShareNudge();
5158 5158
5159 // The item ought to have committed successfully. 5159 // The item ought to have committed successfully.
5160 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5160 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5161 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5161 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5162 ExpectSyncedAndDeleted(); 5162 ExpectSyncedAndDeleted();
5163 5163
5164 // Before the GetUpdates, the item is locally undeleted. 5164 // Before the GetUpdates, the item is locally undeleted.
5165 Undelete(); 5165 Undelete();
5166 ExpectUnsyncedUndeletion(); 5166 ExpectUnsyncedUndeletion();
5167 5167
5168 // Now, encounter a GetUpdates corresponding to the just-committed 5168 // Now, encounter a GetUpdates corresponding to the just-committed
5169 // deletion update. The undeletion should prevail. 5169 // deletion update. The undeletion should prevail.
5170 mock_server_->AddUpdateFromLastCommit(); 5170 mock_server_->AddUpdateFromLastCommit();
5171 EXPECT_TRUE(SyncShareNudge()); 5171 SyncShareNudge();
5172 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5172 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5173 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5173 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5174 ExpectSyncedAndCreated(); 5174 ExpectSyncedAndCreated();
5175 } 5175 }
5176 5176
5177 TEST_F(SyncerUndeletionTest, UndeleteAfterDeleteAndGetUpdates) { 5177 TEST_F(SyncerUndeletionTest, UndeleteAfterDeleteAndGetUpdates) {
5178 Create(); 5178 Create();
5179 ExpectUnsyncedCreation(); 5179 ExpectUnsyncedCreation();
5180 EXPECT_TRUE(SyncShareNudge()); 5180 SyncShareNudge();
5181 5181
5182 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5182 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5183 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5183 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5184 ExpectSyncedAndCreated(); 5184 ExpectSyncedAndCreated();
5185 5185
5186 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 5186 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
5187 update->set_originator_cache_guid(local_cache_guid()); 5187 update->set_originator_cache_guid(local_cache_guid());
5188 update->set_originator_client_item_id(local_id_.GetServerId()); 5188 update->set_originator_client_item_id(local_id_.GetServerId());
5189 EXPECT_TRUE(SyncShareNudge()); 5189 SyncShareNudge();
5190 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5190 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5191 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5191 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5192 ExpectSyncedAndCreated(); 5192 ExpectSyncedAndCreated();
5193 5193
5194 // Delete and commit. 5194 // Delete and commit.
5195 Delete(); 5195 Delete();
5196 ExpectUnsyncedDeletion(); 5196 ExpectUnsyncedDeletion();
5197 EXPECT_TRUE(SyncShareNudge()); 5197 SyncShareNudge();
5198 5198
5199 // The item ought to have committed successfully. 5199 // The item ought to have committed successfully.
5200 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5200 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5201 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5201 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5202 ExpectSyncedAndDeleted(); 5202 ExpectSyncedAndDeleted();
5203 5203
5204 // Now, encounter a GetUpdates corresponding to the just-committed 5204 // Now, encounter a GetUpdates corresponding to the just-committed
5205 // deletion update. Should be consistent. 5205 // deletion update. Should be consistent.
5206 mock_server_->AddUpdateFromLastCommit(); 5206 mock_server_->AddUpdateFromLastCommit();
5207 EXPECT_TRUE(SyncShareNudge()); 5207 SyncShareNudge();
5208 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5208 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5209 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5209 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5210 ExpectSyncedAndDeleted(); 5210 ExpectSyncedAndDeleted();
5211 5211
5212 // After the GetUpdates, the item is locally undeleted. 5212 // After the GetUpdates, the item is locally undeleted.
5213 Undelete(); 5213 Undelete();
5214 ExpectUnsyncedUndeletion(); 5214 ExpectUnsyncedUndeletion();
5215 5215
5216 // Now, encounter a GetUpdates corresponding to the just-committed 5216 // Now, encounter a GetUpdates corresponding to the just-committed
5217 // deletion update. The undeletion should prevail. 5217 // deletion update. The undeletion should prevail.
5218 EXPECT_TRUE(SyncShareNudge()); 5218 SyncShareNudge();
5219 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5219 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5220 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5220 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5221 ExpectSyncedAndCreated(); 5221 ExpectSyncedAndCreated();
5222 } 5222 }
5223 5223
5224 // Test processing of undeletion GetUpdateses. 5224 // Test processing of undeletion GetUpdateses.
5225 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletes) { 5225 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletes) {
5226 Create(); 5226 Create();
5227 ExpectUnsyncedCreation(); 5227 ExpectUnsyncedCreation();
5228 EXPECT_TRUE(SyncShareNudge()); 5228 SyncShareNudge();
5229 5229
5230 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5230 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5231 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5231 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5232 ExpectSyncedAndCreated(); 5232 ExpectSyncedAndCreated();
5233 5233
5234 // Add a delete from the server. 5234 // Add a delete from the server.
5235 sync_pb::SyncEntity* update1 = mock_server_->AddUpdateFromLastCommit(); 5235 sync_pb::SyncEntity* update1 = mock_server_->AddUpdateFromLastCommit();
5236 update1->set_originator_cache_guid(local_cache_guid()); 5236 update1->set_originator_cache_guid(local_cache_guid());
5237 update1->set_originator_client_item_id(local_id_.GetServerId()); 5237 update1->set_originator_client_item_id(local_id_.GetServerId());
5238 EXPECT_TRUE(SyncShareNudge()); 5238 SyncShareNudge();
5239 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5239 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5240 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5240 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5241 ExpectSyncedAndCreated(); 5241 ExpectSyncedAndCreated();
5242 5242
5243 // Some other client deletes the item. 5243 // Some other client deletes the item.
5244 { 5244 {
5245 syncable::ReadTransaction trans(FROM_HERE, directory()); 5245 syncable::ReadTransaction trans(FROM_HERE, directory());
5246 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 5246 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
5247 mock_server_->AddUpdateTombstone(entry.GetId(), PREFERENCES); 5247 mock_server_->AddUpdateTombstone(entry.GetId(), PREFERENCES);
5248 } 5248 }
5249 EXPECT_TRUE(SyncShareNudge()); 5249 SyncShareNudge();
5250 5250
5251 // The update ought to have applied successfully. 5251 // The update ought to have applied successfully.
5252 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5252 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5253 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5253 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5254 ExpectSyncedAndDeleted(); 5254 ExpectSyncedAndDeleted();
5255 5255
5256 // Undelete it locally. 5256 // Undelete it locally.
5257 Undelete(); 5257 Undelete();
5258 ExpectUnsyncedUndeletion(); 5258 ExpectUnsyncedUndeletion();
5259 EXPECT_TRUE(SyncShareNudge()); 5259 SyncShareNudge();
5260 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5260 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5261 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5261 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5262 ExpectSyncedAndCreated(); 5262 ExpectSyncedAndCreated();
5263 5263
5264 // Now, encounter a GetUpdates corresponding to the just-committed 5264 // Now, encounter a GetUpdates corresponding to the just-committed
5265 // deletion update. The undeletion should prevail. 5265 // deletion update. The undeletion should prevail.
5266 sync_pb::SyncEntity* update2 = mock_server_->AddUpdateFromLastCommit(); 5266 sync_pb::SyncEntity* update2 = mock_server_->AddUpdateFromLastCommit();
5267 update2->set_originator_cache_guid(local_cache_guid()); 5267 update2->set_originator_cache_guid(local_cache_guid());
5268 update2->set_originator_client_item_id(local_id_.GetServerId()); 5268 update2->set_originator_client_item_id(local_id_.GetServerId());
5269 EXPECT_TRUE(SyncShareNudge()); 5269 SyncShareNudge();
5270 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5270 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5271 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5271 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5272 ExpectSyncedAndCreated(); 5272 ExpectSyncedAndCreated();
5273 } 5273 }
5274 5274
5275 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletesImmediately) { 5275 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletesImmediately) {
5276 Create(); 5276 Create();
5277 ExpectUnsyncedCreation(); 5277 ExpectUnsyncedCreation();
5278 EXPECT_TRUE(SyncShareNudge()); 5278 SyncShareNudge();
5279 5279
5280 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5280 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5281 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5281 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5282 ExpectSyncedAndCreated(); 5282 ExpectSyncedAndCreated();
5283 5283
5284 // Some other client deletes the item before we get a chance 5284 // Some other client deletes the item before we get a chance
5285 // to GetUpdates our original request. 5285 // to GetUpdates our original request.
5286 { 5286 {
5287 syncable::ReadTransaction trans(FROM_HERE, directory()); 5287 syncable::ReadTransaction trans(FROM_HERE, directory());
5288 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 5288 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
5289 mock_server_->AddUpdateTombstone(entry.GetId(), PREFERENCES); 5289 mock_server_->AddUpdateTombstone(entry.GetId(), PREFERENCES);
5290 } 5290 }
5291 EXPECT_TRUE(SyncShareNudge()); 5291 SyncShareNudge();
5292 5292
5293 // The update ought to have applied successfully. 5293 // The update ought to have applied successfully.
5294 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5294 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5295 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5295 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5296 ExpectSyncedAndDeleted(); 5296 ExpectSyncedAndDeleted();
5297 5297
5298 // Undelete it locally. 5298 // Undelete it locally.
5299 Undelete(); 5299 Undelete();
5300 ExpectUnsyncedUndeletion(); 5300 ExpectUnsyncedUndeletion();
5301 EXPECT_TRUE(SyncShareNudge()); 5301 SyncShareNudge();
5302 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5302 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5303 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5303 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5304 ExpectSyncedAndCreated(); 5304 ExpectSyncedAndCreated();
5305 5305
5306 // Now, encounter a GetUpdates corresponding to the just-committed 5306 // Now, encounter a GetUpdates corresponding to the just-committed
5307 // deletion update. The undeletion should prevail. 5307 // deletion update. The undeletion should prevail.
5308 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 5308 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
5309 update->set_originator_cache_guid(local_cache_guid()); 5309 update->set_originator_cache_guid(local_cache_guid());
5310 update->set_originator_client_item_id(local_id_.GetServerId()); 5310 update->set_originator_client_item_id(local_id_.GetServerId());
5311 EXPECT_TRUE(SyncShareNudge()); 5311 SyncShareNudge();
5312 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5312 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5313 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5313 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5314 ExpectSyncedAndCreated(); 5314 ExpectSyncedAndCreated();
5315 } 5315 }
5316 5316
5317 TEST_F(SyncerUndeletionTest, OtherClientUndeletes) { 5317 TEST_F(SyncerUndeletionTest, OtherClientUndeletes) {
5318 Create(); 5318 Create();
5319 ExpectUnsyncedCreation(); 5319 ExpectUnsyncedCreation();
5320 EXPECT_TRUE(SyncShareNudge()); 5320 SyncShareNudge();
5321 5321
5322 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5322 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5323 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5323 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5324 ExpectSyncedAndCreated(); 5324 ExpectSyncedAndCreated();
5325 5325
5326 // Get the updates of our just-committed entry. 5326 // Get the updates of our just-committed entry.
5327 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 5327 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
5328 update->set_originator_cache_guid(local_cache_guid()); 5328 update->set_originator_cache_guid(local_cache_guid());
5329 update->set_originator_client_item_id(local_id_.GetServerId()); 5329 update->set_originator_client_item_id(local_id_.GetServerId());
5330 EXPECT_TRUE(SyncShareNudge()); 5330 SyncShareNudge();
5331 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5331 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5332 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5332 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5333 ExpectSyncedAndCreated(); 5333 ExpectSyncedAndCreated();
5334 5334
5335 // We delete the item. 5335 // We delete the item.
5336 Delete(); 5336 Delete();
5337 ExpectUnsyncedDeletion(); 5337 ExpectUnsyncedDeletion();
5338 EXPECT_TRUE(SyncShareNudge()); 5338 SyncShareNudge();
5339 5339
5340 // The update ought to have applied successfully. 5340 // The update ought to have applied successfully.
5341 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5341 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5342 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5342 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5343 ExpectSyncedAndDeleted(); 5343 ExpectSyncedAndDeleted();
5344 5344
5345 // Now, encounter a GetUpdates corresponding to the just-committed 5345 // Now, encounter a GetUpdates corresponding to the just-committed
5346 // deletion update. 5346 // deletion update.
5347 mock_server_->AddUpdateFromLastCommit(); 5347 mock_server_->AddUpdateFromLastCommit();
5348 EXPECT_TRUE(SyncShareNudge()); 5348 SyncShareNudge();
5349 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5349 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5350 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5350 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5351 ExpectSyncedAndDeleted(); 5351 ExpectSyncedAndDeleted();
5352 5352
5353 // Some other client undeletes the item. 5353 // Some other client undeletes the item.
5354 { 5354 {
5355 syncable::ReadTransaction trans(FROM_HERE, directory()); 5355 syncable::ReadTransaction trans(FROM_HERE, directory());
5356 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 5356 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
5357 mock_server_->AddUpdatePref( 5357 mock_server_->AddUpdatePref(
5358 entry.GetId().GetServerId(), 5358 entry.GetId().GetServerId(),
5359 entry.GetParentId().GetServerId(), 5359 entry.GetParentId().GetServerId(),
5360 client_tag_, 100, 1000); 5360 client_tag_, 100, 1000);
5361 } 5361 }
5362 mock_server_->SetLastUpdateClientTag(client_tag_); 5362 mock_server_->SetLastUpdateClientTag(client_tag_);
5363 EXPECT_TRUE(SyncShareNudge()); 5363 SyncShareNudge();
5364 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5364 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5365 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5365 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5366 ExpectSyncedAndCreated(); 5366 ExpectSyncedAndCreated();
5367 } 5367 }
5368 5368
5369 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) { 5369 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) {
5370 Create(); 5370 Create();
5371 ExpectUnsyncedCreation(); 5371 ExpectUnsyncedCreation();
5372 EXPECT_TRUE(SyncShareNudge()); 5372 SyncShareNudge();
5373 5373
5374 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5374 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5375 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5375 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5376 ExpectSyncedAndCreated(); 5376 ExpectSyncedAndCreated();
5377 5377
5378 // Get the updates of our just-committed entry. 5378 // Get the updates of our just-committed entry.
5379 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 5379 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
5380 update->set_originator_cache_guid(local_cache_guid()); 5380 update->set_originator_cache_guid(local_cache_guid());
5381 { 5381 {
5382 syncable::ReadTransaction trans(FROM_HERE, directory()); 5382 syncable::ReadTransaction trans(FROM_HERE, directory());
5383 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 5383 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
5384 update->set_originator_client_item_id(local_id_.GetServerId()); 5384 update->set_originator_client_item_id(local_id_.GetServerId());
5385 } 5385 }
5386 EXPECT_TRUE(SyncShareNudge()); 5386 SyncShareNudge();
5387 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5387 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5388 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5388 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5389 ExpectSyncedAndCreated(); 5389 ExpectSyncedAndCreated();
5390 5390
5391 // We delete the item. 5391 // We delete the item.
5392 Delete(); 5392 Delete();
5393 ExpectUnsyncedDeletion(); 5393 ExpectUnsyncedDeletion();
5394 EXPECT_TRUE(SyncShareNudge()); 5394 SyncShareNudge();
5395 5395
5396 // The update ought to have applied successfully. 5396 // The update ought to have applied successfully.
5397 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5397 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5398 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5398 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5399 ExpectSyncedAndDeleted(); 5399 ExpectSyncedAndDeleted();
5400 5400
5401 // Some other client undeletes before we see the update from our 5401 // Some other client undeletes before we see the update from our
5402 // commit. 5402 // commit.
5403 { 5403 {
5404 syncable::ReadTransaction trans(FROM_HERE, directory()); 5404 syncable::ReadTransaction trans(FROM_HERE, directory());
5405 Entry entry(&trans, GET_BY_HANDLE, metahandle_); 5405 Entry entry(&trans, GET_BY_HANDLE, metahandle_);
5406 mock_server_->AddUpdatePref( 5406 mock_server_->AddUpdatePref(
5407 entry.GetId().GetServerId(), 5407 entry.GetId().GetServerId(),
5408 entry.GetParentId().GetServerId(), 5408 entry.GetParentId().GetServerId(),
5409 client_tag_, 100, 1000); 5409 client_tag_, 100, 1000);
5410 } 5410 }
5411 mock_server_->SetLastUpdateClientTag(client_tag_); 5411 mock_server_->SetLastUpdateClientTag(client_tag_);
5412 EXPECT_TRUE(SyncShareNudge()); 5412 SyncShareNudge();
5413 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 5413 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
5414 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 5414 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
5415 ExpectSyncedAndCreated(); 5415 ExpectSyncedAndCreated();
5416 } 5416 }
5417 5417
5418 enum { 5418 enum {
5419 TEST_PARAM_BOOKMARK_ENABLE_BIT, 5419 TEST_PARAM_BOOKMARK_ENABLE_BIT,
5420 TEST_PARAM_AUTOFILL_ENABLE_BIT, 5420 TEST_PARAM_AUTOFILL_ENABLE_BIT,
5421 TEST_PARAM_BIT_COUNT 5421 TEST_PARAM_BIT_COUNT
5422 }; 5422 };
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5463 // Put some extenions activity records into the monitor. 5463 // Put some extenions activity records into the monitor.
5464 { 5464 {
5465 ExtensionsActivity::Records records; 5465 ExtensionsActivity::Records records;
5466 records["ABC"].extension_id = "ABC"; 5466 records["ABC"].extension_id = "ABC";
5467 records["ABC"].bookmark_write_count = 2049U; 5467 records["ABC"].bookmark_write_count = 2049U;
5468 records["xyz"].extension_id = "xyz"; 5468 records["xyz"].extension_id = "xyz";
5469 records["xyz"].bookmark_write_count = 4U; 5469 records["xyz"].bookmark_write_count = 4U;
5470 context_->extensions_activity()->PutRecords(records); 5470 context_->extensions_activity()->PutRecords(records);
5471 } 5471 }
5472 5472
5473 EXPECT_EQ(!ShouldFailBookmarkCommit() && !ShouldFailAutofillCommit(), 5473 SyncShareNudge();
5474 SyncShareNudge());
5475 5474
5476 ExtensionsActivity::Records final_monitor_records; 5475 ExtensionsActivity::Records final_monitor_records;
5477 context_->extensions_activity()->GetAndClearRecords(&final_monitor_records); 5476 context_->extensions_activity()->GetAndClearRecords(&final_monitor_records);
5478 if (ShouldFailBookmarkCommit()) { 5477 if (ShouldFailBookmarkCommit()) {
5479 ASSERT_EQ(2U, final_monitor_records.size()) 5478 ASSERT_EQ(2U, final_monitor_records.size())
5480 << "Should restore records after unsuccessful bookmark commit."; 5479 << "Should restore records after unsuccessful bookmark commit.";
5481 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id); 5480 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id);
5482 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 5481 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
5483 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 5482 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
5484 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 5483 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
5485 } else { 5484 } else {
5486 EXPECT_TRUE(final_monitor_records.empty()) 5485 EXPECT_TRUE(final_monitor_records.empty())
5487 << "Should not restore records after successful bookmark commit."; 5486 << "Should not restore records after successful bookmark commit.";
5488 } 5487 }
5489 } 5488 }
5490 5489
5491 } // namespace syncer 5490 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer.cc ('k') | sync/internal_api/js_sync_manager_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698