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

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

Issue 10210009: sync: Loop committing items without downloading updates (v2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 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 | Annotate | Revision Log
« no previous file with comments | « sync/engine/syncer.cc ('k') | sync/internal_api/all_status.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // If this test starts failing, be aware other sort orders could be valid. 384 // If this test starts failing, be aware other sort orders could be valid.
385 for (size_t i = 0; i < expected_positions.size(); ++i) { 385 for (size_t i = 0; i < expected_positions.size(); ++i) {
386 EXPECT_EQ(1u, expected_positions.count(i)); 386 EXPECT_EQ(1u, expected_positions.count(i));
387 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]); 387 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]);
388 } 388 }
389 } 389 }
390 390
391 void DoTruncationTest(const vector<int64>& unsynced_handle_view, 391 void DoTruncationTest(const vector<int64>& unsynced_handle_view,
392 const vector<syncable::Id>& expected_id_order) { 392 const vector<syncable::Id>& expected_id_order) {
393 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { 393 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) {
394 StatusController* status = session_->mutable_status_controller();
395 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 394 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
396 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 395 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
397 396
398 ModelSafeRoutingInfo routes; 397 ModelSafeRoutingInfo routes;
399 GetModelSafeRoutingInfo(&routes); 398 GetModelSafeRoutingInfo(&routes);
400 GetCommitIdsCommand command(limit); 399 sessions::OrderedCommitSet output_set(routes);
400 GetCommitIdsCommand command(limit, &output_set);
401 std::set<int64> ready_unsynced_set; 401 std::set<int64> ready_unsynced_set;
402 command.FilterUnreadyEntries(&wtrans, syncable::ModelTypeSet(), 402 command.FilterUnreadyEntries(&wtrans, syncable::ModelTypeSet(),
403 syncable::ModelTypeSet(), false, 403 syncable::ModelTypeSet(), false,
404 unsynced_handle_view, &ready_unsynced_set); 404 unsynced_handle_view, &ready_unsynced_set);
405 command.BuildCommitIds(session_->write_transaction(), routes, 405 command.BuildCommitIds(session_->write_transaction(), routes,
406 ready_unsynced_set); 406 ready_unsynced_set);
407 syncable::Directory::UnsyncedMetaHandles ready_unsynced_vector(
408 ready_unsynced_set.begin(), ready_unsynced_set.end());
409 status->set_unsynced_handles(ready_unsynced_vector);
410 vector<syncable::Id> output =
411 command.ordered_commit_set_->GetAllCommitIds();
412 size_t truncated_size = std::min(limit, expected_id_order.size()); 407 size_t truncated_size = std::min(limit, expected_id_order.size());
413 ASSERT_EQ(truncated_size, output.size()); 408 ASSERT_EQ(truncated_size, output_set.Size());
414 for (size_t i = 0; i < truncated_size; ++i) { 409 for (size_t i = 0; i < truncated_size; ++i) {
415 ASSERT_EQ(expected_id_order[i], output[i]) 410 ASSERT_EQ(expected_id_order[i], output_set.GetCommitIdAt(i))
416 << "At index " << i << " with batch size limited to " << limit; 411 << "At index " << i << " with batch size limited to " << limit;
417 } 412 }
418 sessions::OrderedCommitSet::Projection proj; 413 sessions::OrderedCommitSet::Projection proj;
419 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); 414 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE);
420 ASSERT_EQ(truncated_size, proj.size()); 415 ASSERT_EQ(truncated_size, proj.size());
421 for (size_t i = 0; i < truncated_size; ++i) { 416 for (size_t i = 0; i < truncated_size; ++i) {
422 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); 417 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i);
423 syncable::Id projected = 418 syncable::Id projected = output_set.GetCommitIdAt(proj[i]);
424 command.ordered_commit_set_->GetCommitIdAt(proj[i]);
425 ASSERT_EQ(expected_id_order[proj[i]], projected); 419 ASSERT_EQ(expected_id_order[proj[i]], projected);
426 // Since this projection is the identity, the following holds. 420 // Since this projection is the identity, the following holds.
427 ASSERT_EQ(expected_id_order[i], projected); 421 ASSERT_EQ(expected_id_order[i], projected);
428 } 422 }
429 } 423 }
430 } 424 }
431 425
432 const StatusController& status() { 426 const StatusController& status() {
433 return session_->status_controller(); 427 return session_->status_controller();
434 } 428 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 C.Put(NON_UNIQUE_NAME, kEncryptedString); 721 C.Put(NON_UNIQUE_NAME, kEncryptedString);
728 // Unencrypted non_unique_name. 722 // Unencrypted non_unique_name.
729 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 723 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
730 ASSERT_TRUE(D.good()); 724 ASSERT_TRUE(D.good());
731 D.Put(IS_UNSYNCED, true); 725 D.Put(IS_UNSYNCED, true);
732 D.Put(SPECIFICS, encrypted_bookmark); 726 D.Put(SPECIFICS, encrypted_bookmark);
733 D.Put(NON_UNIQUE_NAME, "not encrypted"); 727 D.Put(NON_UNIQUE_NAME, "not encrypted");
734 } 728 }
735 SyncShareNudge(); 729 SyncShareNudge();
736 { 730 {
737 // We remove any unready entries from the status controller's unsynced
738 // handles, so this should remain 0 even though the entries didn't commit.
739 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
740 // Nothing should have commited due to bookmarks being encrypted and 731 // Nothing should have commited due to bookmarks being encrypted and
741 // the cryptographer having pending keys. A would have been resolved 732 // the cryptographer having pending keys. A would have been resolved
742 // as a simple conflict, but still be unsynced until the next sync cycle. 733 // as a simple conflict, but still be unsynced until the next sync cycle.
743 ReadTransaction rtrans(FROM_HERE, directory()); 734 ReadTransaction rtrans(FROM_HERE, directory());
744 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); 735 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans);
745 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); 736 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans);
746 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 737 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
747 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 738 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
748 739
749 // Resolve the pending keys. 740 // Resolve the pending keys.
750 cryptographer(&rtrans)->DecryptPendingKeys(other_params); 741 cryptographer(&rtrans)->DecryptPendingKeys(other_params);
751 } 742 }
752 SyncShareNudge(); 743 SyncShareNudge();
753 { 744 {
754 // 2 unsynced handles to reflect the items that committed succesfully.
755 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size());
756 // All properly encrypted and non-conflicting items should commit. "A" was 745 // All properly encrypted and non-conflicting items should commit. "A" was
757 // conflicting, but last sync cycle resolved it as simple conflict, so on 746 // conflicting, but last sync cycle resolved it as simple conflict, so on
758 // this sync cycle it committed succesfullly. 747 // this sync cycle it committed succesfullly.
759 ReadTransaction rtrans(FROM_HERE, directory()); 748 ReadTransaction rtrans(FROM_HERE, directory());
760 // Committed successfully. 749 // Committed successfully.
761 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 750 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
762 // Committed successfully. 751 // Committed successfully.
763 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 752 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
764 // Was not properly encrypted. 753 // Was not properly encrypted.
765 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 754 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
766 // Was not properly encrypted. 755 // Was not properly encrypted.
767 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 756 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
768 } 757 }
769 { 758 {
770 // Fix the remaining items. 759 // Fix the remaining items.
771 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 760 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
772 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 761 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
773 ASSERT_TRUE(C.good()); 762 ASSERT_TRUE(C.good());
774 C.Put(SPECIFICS, encrypted_bookmark); 763 C.Put(SPECIFICS, encrypted_bookmark);
775 C.Put(NON_UNIQUE_NAME, kEncryptedString); 764 C.Put(NON_UNIQUE_NAME, kEncryptedString);
776 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 765 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
777 ASSERT_TRUE(D.good()); 766 ASSERT_TRUE(D.good());
778 D.Put(SPECIFICS, encrypted_bookmark); 767 D.Put(SPECIFICS, encrypted_bookmark);
779 D.Put(NON_UNIQUE_NAME, kEncryptedString); 768 D.Put(NON_UNIQUE_NAME, kEncryptedString);
780 } 769 }
781 SyncShareNudge(); 770 SyncShareNudge();
782 { 771 {
783 // We attempted to commit two items. 772 const StatusController& status_controller = session_->status_controller();
784 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 773 // Expect success.
785 EXPECT_TRUE(session_->status_controller().did_commit_items()); 774 EXPECT_EQ(status_controller.last_post_commit_result(), SYNCER_OK);
786 // None should be unsynced anymore. 775 // None should be unsynced anymore.
787 ReadTransaction rtrans(FROM_HERE, directory()); 776 ReadTransaction rtrans(FROM_HERE, directory());
788 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 777 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
789 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 778 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
790 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); 779 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans);
791 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); 780 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans);
792 } 781 }
793 } 782 }
794 783
795 TEST_F(SyncerTest, EncryptionAwareConflicts) { 784 TEST_F(SyncerTest, EncryptionAwareConflicts) {
(...skipping 28 matching lines...) Expand all
824 cryptographer(&wtrans)->Update(*nigori); 813 cryptographer(&wtrans)->Update(*nigori);
825 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 814 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
826 } 815 }
827 816
828 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 817 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
829 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 818 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
830 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 819 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
831 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 820 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
832 SyncShareNudge(); 821 SyncShareNudge();
833 { 822 {
834 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
835 // Initial state. Everything is normal. 823 // Initial state. Everything is normal.
836 ReadTransaction rtrans(FROM_HERE, directory()); 824 ReadTransaction rtrans(FROM_HERE, directory());
837 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 825 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
838 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 826 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
839 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 827 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
840 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 828 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
841 } 829 }
842 830
843 // Server side encryption will not be applied due to undecryptable data. 831 // Server side encryption will not be applied due to undecryptable data.
844 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items. 832 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items.
845 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, 833 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0,
846 encrypted_bookmark); 834 encrypted_bookmark);
847 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, 835 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2,
848 encrypted_bookmark); 836 encrypted_bookmark);
849 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, 837 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1,
850 encrypted_bookmark); 838 encrypted_bookmark);
851 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, 839 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0,
852 encrypted_pref); 840 encrypted_pref);
853 SyncShareNudge(); 841 SyncShareNudge();
854 { 842 {
855 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
856 // All should be unapplied due to being undecryptable and have a valid 843 // All should be unapplied due to being undecryptable and have a valid
857 // BASE_SERVER_SPECIFICS. 844 // BASE_SERVER_SPECIFICS.
858 ReadTransaction rtrans(FROM_HERE, directory()); 845 ReadTransaction rtrans(FROM_HERE, directory());
859 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); 846 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans);
860 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); 847 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans);
861 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 848 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
862 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); 849 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans);
863 } 850 }
864 851
865 // Server side change that don't modify anything should not affect 852 // Server side change that don't modify anything should not affect
866 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). 853 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes).
867 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, 854 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0,
868 encrypted_bookmark); 855 encrypted_bookmark);
869 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, 856 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2,
870 encrypted_bookmark); 857 encrypted_bookmark);
871 // Item 3 doesn't change. 858 // Item 3 doesn't change.
872 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, 859 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0,
873 encrypted_pref); 860 encrypted_pref);
874 SyncShareNudge(); 861 SyncShareNudge();
875 { 862 {
876 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
877 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. 863 // Items 1, 2, and 4 should have newer server versions, 3 remains the same.
878 // All should remain unapplied due to be undecryptable. 864 // All should remain unapplied due to be undecryptable.
879 ReadTransaction rtrans(FROM_HERE, directory()); 865 ReadTransaction rtrans(FROM_HERE, directory());
880 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); 866 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans);
881 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 867 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
882 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 868 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
883 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 869 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
884 } 870 }
885 871
886 // Positional changes, parent changes, and specifics changes should reset 872 // Positional changes, parent changes, and specifics changes should reset
887 // BASE_SERVER_SPECIFICS. 873 // BASE_SERVER_SPECIFICS.
888 // Became unencrypted. 874 // Became unencrypted.
889 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark); 875 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark);
890 // Reordered to after item 2. 876 // Reordered to after item 2.
891 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, 877 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3,
892 encrypted_bookmark); 878 encrypted_bookmark);
893 SyncShareNudge(); 879 SyncShareNudge();
894 { 880 {
895 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
896 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. 881 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set.
897 // Items 1 is now unencrypted, so should have applied normally. 882 // Items 1 is now unencrypted, so should have applied normally.
898 ReadTransaction rtrans(FROM_HERE, directory()); 883 ReadTransaction rtrans(FROM_HERE, directory());
899 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); 884 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans);
900 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 885 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
901 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); 886 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans);
902 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 887 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
903 } 888 }
904 889
905 // Make local changes, which should remain unsynced for items 2, 3, 4. 890 // Make local changes, which should remain unsynced for items 2, 3, 4.
(...skipping 15 matching lines...) Expand all
921 C.Put(NON_UNIQUE_NAME, kEncryptedString); 906 C.Put(NON_UNIQUE_NAME, kEncryptedString);
922 C.Put(IS_UNSYNCED, true); 907 C.Put(IS_UNSYNCED, true);
923 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 908 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
924 ASSERT_TRUE(D.good()); 909 ASSERT_TRUE(D.good());
925 D.Put(SPECIFICS, modified_pref); 910 D.Put(SPECIFICS, modified_pref);
926 D.Put(NON_UNIQUE_NAME, kEncryptedString); 911 D.Put(NON_UNIQUE_NAME, kEncryptedString);
927 D.Put(IS_UNSYNCED, true); 912 D.Put(IS_UNSYNCED, true);
928 } 913 }
929 SyncShareNudge(); 914 SyncShareNudge();
930 { 915 {
931 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
932 // Item 1 remains unsynced due to there being pending keys. 916 // Item 1 remains unsynced due to there being pending keys.
933 // Items 2, 3, 4 should remain unsynced since they were not up to date. 917 // Items 2, 3, 4 should remain unsynced since they were not up to date.
934 ReadTransaction rtrans(FROM_HERE, directory()); 918 ReadTransaction rtrans(FROM_HERE, directory());
935 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); 919 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans);
936 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); 920 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans);
937 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); 921 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans);
938 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); 922 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans);
939 } 923 }
940 924
941 { 925 {
942 ReadTransaction rtrans(FROM_HERE, directory()); 926 ReadTransaction rtrans(FROM_HERE, directory());
943 // Resolve the pending keys. 927 // Resolve the pending keys.
944 cryptographer(&rtrans)->DecryptPendingKeys(key_params); 928 cryptographer(&rtrans)->DecryptPendingKeys(key_params);
945 } 929 }
946 // First cycle resolves conflicts, second cycle commits changes. 930 // First cycle resolves conflicts, second cycle commits changes.
947 SyncShareNudge(); 931 SyncShareNudge();
948 EXPECT_EQ(2, session_->status_controller().syncer_status(). 932 EXPECT_EQ(2, status().syncer_status().num_server_overwrites);
949 num_server_overwrites); 933 EXPECT_EQ(1, status().syncer_status().num_local_overwrites);
950 EXPECT_EQ(1, session_->status_controller().syncer_status(). 934 // We successfully commited item(s).
951 num_local_overwrites); 935 EXPECT_EQ(status().last_post_commit_result(), SYNCER_OK);
952 // We attempted to commit item 1.
953 EXPECT_EQ(1U, session_->status_controller().unsynced_handles().size());
954 EXPECT_TRUE(session_->status_controller().did_commit_items());
955 SyncShareNudge(); 936 SyncShareNudge();
956 { 937
957 // Everything should be resolved now. The local changes should have 938 // Everything should be resolved now. The local changes should have
958 // overwritten the server changes for 2 and 4, while the server changes 939 // overwritten the server changes for 2 and 4, while the server changes
959 // overwrote the local for entry 3. 940 // overwrote the local for entry 3.
960 // We attempted to commit two handles. 941 EXPECT_EQ(0, status().syncer_status().num_server_overwrites);
961 EXPECT_EQ(0, session_->status_controller().syncer_status(). 942 EXPECT_EQ(0, status().syncer_status().num_local_overwrites);
962 num_server_overwrites); 943 EXPECT_EQ(status().last_post_commit_result(), SYNCER_OK);
963 EXPECT_EQ(0, session_->status_controller().syncer_status(). 944 ReadTransaction rtrans(FROM_HERE, directory());
964 num_local_overwrites); 945 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
965 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 946 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
966 EXPECT_TRUE(session_->status_controller().did_commit_items()); 947 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
967 ReadTransaction rtrans(FROM_HERE, directory()); 948 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
968 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
969 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
970 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
971 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
972 }
973 } 949 }
974 950
975 #undef VERIFY_ENTRY 951 #undef VERIFY_ENTRY
976 952
977 // Receive an old nigori with old encryption keys and encrypted types. We should 953 // Receive an old nigori with old encryption keys and encrypted types. We should
978 // not revert our default key or encrypted types. 954 // not revert our default key or encrypted types.
979 TEST_F(SyncerTest, ReceiveOldNigori) { 955 TEST_F(SyncerTest, ReceiveOldNigori) {
980 KeyParams old_key = {"localhost", "dummy", "old"}; 956 KeyParams old_key = {"localhost", "dummy", "old"};
981 KeyParams current_key = {"localhost", "dummy", "cur"}; 957 KeyParams current_key = {"localhost", "dummy", "cur"};
982 958
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 parent.Put(syncable::BASE_VERSION, 1); 1167 parent.Put(syncable::BASE_VERSION, 1);
1192 parent.Put(syncable::ID, parent_id_); 1168 parent.Put(syncable::ID, parent_id_);
1193 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 1169 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete");
1194 ASSERT_TRUE(child.good()); 1170 ASSERT_TRUE(child.good());
1195 child.Put(syncable::ID, child_id_); 1171 child.Put(syncable::ID, child_id_);
1196 child.Put(syncable::BASE_VERSION, 1); 1172 child.Put(syncable::BASE_VERSION, 1);
1197 WriteTestDataToEntry(&wtrans, &child); 1173 WriteTestDataToEntry(&wtrans, &child);
1198 } 1174 }
1199 1175
1200 SyncShareNudge(); 1176 SyncShareNudge();
1201 EXPECT_EQ(2u, status().unsynced_handles().size());
1202 ASSERT_EQ(2u, mock_server_->committed_ids().size()); 1177 ASSERT_EQ(2u, mock_server_->committed_ids().size());
1203 // If this test starts failing, be aware other sort orders could be valid. 1178 // If this test starts failing, be aware other sort orders could be valid.
1204 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1179 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1205 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1180 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1206 { 1181 {
1207 ReadTransaction rt(FROM_HERE, directory()); 1182 ReadTransaction rt(FROM_HERE, directory());
1208 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1183 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1209 ASSERT_TRUE(entry.good()); 1184 ASSERT_TRUE(entry.good());
1210 VerifyTestDataInEntry(&rt, &entry); 1185 VerifyTestDataInEntry(&rt, &entry);
1211 } 1186 }
(...skipping 23 matching lines...) Expand all
1235 parent2.Put(syncable::IS_DIR, true); 1210 parent2.Put(syncable::IS_DIR, true);
1236 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); 1211 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics());
1237 parent2.Put(syncable::BASE_VERSION, 1); 1212 parent2.Put(syncable::BASE_VERSION, 1);
1238 parent2.Put(syncable::ID, pref_node_id); 1213 parent2.Put(syncable::ID, pref_node_id);
1239 } 1214 }
1240 1215
1241 directory()->PurgeEntriesWithTypeIn( 1216 directory()->PurgeEntriesWithTypeIn(
1242 syncable::ModelTypeSet(syncable::PREFERENCES)); 1217 syncable::ModelTypeSet(syncable::PREFERENCES));
1243 1218
1244 SyncShareNudge(); 1219 SyncShareNudge();
1245 EXPECT_EQ(2U, status().unsynced_handles().size());
1246 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 1220 ASSERT_EQ(2U, mock_server_->committed_ids().size());
1247 // If this test starts failing, be aware other sort orders could be valid. 1221 // If this test starts failing, be aware other sort orders could be valid.
1248 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1222 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1249 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1223 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1250 { 1224 {
1251 ReadTransaction rt(FROM_HERE, directory()); 1225 ReadTransaction rt(FROM_HERE, directory());
1252 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1226 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1253 ASSERT_TRUE(entry.good()); 1227 ASSERT_TRUE(entry.good());
1254 VerifyTestDataInEntry(&rt, &entry); 1228 VerifyTestDataInEntry(&rt, &entry);
1255 } 1229 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 grandchild.Put(syncable::IS_UNSYNCED, true); 1448 grandchild.Put(syncable::IS_UNSYNCED, true);
1475 grandchild.Put(syncable::IS_DEL, true); 1449 grandchild.Put(syncable::IS_DEL, true);
1476 grandchild.Put(syncable::IS_DIR, false); 1450 grandchild.Put(syncable::IS_DIR, false);
1477 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1451 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1478 grandchild.Put(syncable::BASE_VERSION, 1); 1452 grandchild.Put(syncable::BASE_VERSION, 1);
1479 grandchild.Put(syncable::MTIME, now_minus_2h); 1453 grandchild.Put(syncable::MTIME, now_minus_2h);
1480 } 1454 }
1481 } 1455 }
1482 1456
1483 SyncShareNudge(); 1457 SyncShareNudge();
1484 EXPECT_EQ(6u, session_->status_controller().unsynced_handles().size());
1485 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1458 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1486 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. 1459 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set.
1487 // It will treat these like moves. 1460 // It will treat these like moves.
1488 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); 1461 vector<syncable::Id> commit_ids(mock_server_->committed_ids());
1489 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); 1462 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]);
1490 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); 1463 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]);
1491 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); 1464 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]);
1492 // We don't guarantee the delete orders in this test, only that they occur 1465 // We don't guarantee the delete orders in this test, only that they occur
1493 // at the end. 1466 // at the end.
1494 std::sort(commit_ids.begin() + 3, commit_ids.end()); 1467 std::sort(commit_ids.begin() + 3, commit_ids.end());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); 1515 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B");
1543 ASSERT_TRUE(child.good()); 1516 ASSERT_TRUE(child.good());
1544 child.Put(syncable::IS_UNSYNCED, true); 1517 child.Put(syncable::IS_UNSYNCED, true);
1545 child.Put(syncable::IS_DIR, true); 1518 child.Put(syncable::IS_DIR, true);
1546 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1519 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1547 child.Put(syncable::ID, ids_.FromNumber(105)); 1520 child.Put(syncable::ID, ids_.FromNumber(105));
1548 child.Put(syncable::BASE_VERSION, 1); 1521 child.Put(syncable::BASE_VERSION, 1);
1549 } 1522 }
1550 1523
1551 SyncShareNudge(); 1524 SyncShareNudge();
1552 EXPECT_EQ(6u, session_->status_controller().unsynced_handles().size());
1553 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1525 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1554 // If this test starts failing, be aware other sort orders could be valid. 1526 // If this test starts failing, be aware other sort orders could be valid.
1555 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1527 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1556 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1528 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1557 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); 1529 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]);
1558 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); 1530 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]);
1559 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); 1531 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]);
1560 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); 1532 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]);
1561 } 1533 }
1562 1534
(...skipping 18 matching lines...) Expand all
1581 child2.Put(syncable::IS_UNSYNCED, true); 1553 child2.Put(syncable::IS_UNSYNCED, true);
1582 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1554 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1583 child2.Put(syncable::ID, child2_id); 1555 child2.Put(syncable::ID, child2_id);
1584 1556
1585 parent.Put(syncable::BASE_VERSION, 1); 1557 parent.Put(syncable::BASE_VERSION, 1);
1586 child1.Put(syncable::BASE_VERSION, 1); 1558 child1.Put(syncable::BASE_VERSION, 1);
1587 child2.Put(syncable::BASE_VERSION, 1); 1559 child2.Put(syncable::BASE_VERSION, 1);
1588 } 1560 }
1589 1561
1590 SyncShareNudge(); 1562 SyncShareNudge();
1591 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1592 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1563 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1593 // If this test starts failing, be aware other sort orders could be valid. 1564 // If this test starts failing, be aware other sort orders could be valid.
1594 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1565 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1595 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1566 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1596 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); 1567 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]);
1597 } 1568 }
1598 1569
1599 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { 1570 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) {
1600 string parent1_name = "1"; 1571 string parent1_name = "1";
1601 string parent2_name = "A"; 1572 string parent2_name = "A";
(...skipping 25 matching lines...) Expand all
1627 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); 1598 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name);
1628 ASSERT_TRUE(child.good()); 1599 ASSERT_TRUE(child.good());
1629 child.Put(syncable::IS_UNSYNCED, true); 1600 child.Put(syncable::IS_UNSYNCED, true);
1630 child.Put(syncable::IS_DIR, true); 1601 child.Put(syncable::IS_DIR, true);
1631 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1602 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1632 child.Put(syncable::ID, child_id); 1603 child.Put(syncable::ID, child_id);
1633 child.Put(syncable::BASE_VERSION, 1); 1604 child.Put(syncable::BASE_VERSION, 1);
1634 } 1605 }
1635 1606
1636 SyncShareNudge(); 1607 SyncShareNudge();
1637 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1638 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1608 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1639 // If this test starts failing, be aware other sort orders could be valid. 1609 // If this test starts failing, be aware other sort orders could be valid.
1640 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1610 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1641 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]); 1611 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]);
1642 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]); 1612 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]);
1643 { 1613 {
1644 ReadTransaction rtrans(FROM_HERE, directory()); 1614 ReadTransaction rtrans(FROM_HERE, directory());
1645 // Check that things committed correctly. 1615 // Check that things committed correctly.
1646 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); 1616 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_);
1647 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name); 1617 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name); 1668 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name);
1699 ASSERT_TRUE(child.good()); 1669 ASSERT_TRUE(child.good());
1700 child.Put(syncable::IS_UNSYNCED, true); 1670 child.Put(syncable::IS_UNSYNCED, true);
1701 child.Put(syncable::IS_DIR, true); 1671 child.Put(syncable::IS_DIR, true);
1702 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1672 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1703 child.Put(syncable::ID, child_local_id); 1673 child.Put(syncable::ID, child_local_id);
1704 meta_handle_b = child.Get(syncable::META_HANDLE); 1674 meta_handle_b = child.Get(syncable::META_HANDLE);
1705 } 1675 }
1706 1676
1707 SyncShareNudge(); 1677 SyncShareNudge();
1708 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1709 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1678 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1710 // If this test starts failing, be aware other sort orders could be valid. 1679 // If this test starts failing, be aware other sort orders could be valid.
1711 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1680 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1712 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]); 1681 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]);
1713 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]); 1682 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]);
1714 { 1683 {
1715 ReadTransaction rtrans(FROM_HERE, directory()); 1684 ReadTransaction rtrans(FROM_HERE, directory());
1716 1685
1717 Entry parent(&rtrans, syncable::GET_BY_ID, 1686 Entry parent(&rtrans, syncable::GET_BY_ID,
1718 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); 1687 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name));
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 "bob"); 2294 "bob");
2326 ASSERT_TRUE(entry.good()); 2295 ASSERT_TRUE(entry.good());
2327 entry.Put(syncable::IS_DIR, true); 2296 entry.Put(syncable::IS_DIR, true);
2328 entry.Put(syncable::IS_UNSYNCED, true); 2297 entry.Put(syncable::IS_UNSYNCED, true);
2329 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2298 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2330 } 2299 }
2331 2300
2332 mock_server_->SetMidCommitCallback( 2301 mock_server_->SetMidCommitCallback(
2333 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2302 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2334 base::Unretained(this))); 2303 base::Unretained(this)));
2335 syncer_->SyncShare(session_.get(), BUILD_COMMIT_REQUEST, SYNCER_END); 2304 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END);
2336 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2305 // We loop until no unsynced handles remain, so we will commit both ids.
2306 EXPECT_EQ(2u, mock_server_->committed_ids().size());
2337 { 2307 {
2338 ReadTransaction trans(FROM_HERE, directory()); 2308 ReadTransaction trans(FROM_HERE, directory());
2339 Entry parent_entry(&trans, syncable::GET_BY_ID, 2309 Entry parent_entry(&trans, syncable::GET_BY_ID,
2340 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2310 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2341 ASSERT_TRUE(parent_entry.good()); 2311 ASSERT_TRUE(parent_entry.good());
2342 2312
2343 Id child_id = 2313 Id child_id =
2344 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 2314 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
2345 Entry child(&trans, syncable::GET_BY_ID, child_id); 2315 Entry child(&trans, syncable::GET_BY_ID, child_id);
2346 ASSERT_TRUE(child.good()); 2316 ASSERT_TRUE(child.good());
2347 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); 2317 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID));
2348 } 2318 }
2349 } 2319 }
2350 2320
2351 TEST_F(SyncerTest, NegativeIDInUpdate) { 2321 TEST_F(SyncerTest, NegativeIDInUpdate) {
2352 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); 2322 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40);
2353 SyncShareNudge(); 2323 SyncShareNudge();
2354 // The negative id would make us CHECK! 2324 // The negative id would make us CHECK!
2355 } 2325 }
2356 2326
2357 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2327 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2358 int64 metahandle_fred; 2328 int64 metahandle_fred;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); 2654 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME));
2685 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2655 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
2686 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); 2656 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096));
2687 ASSERT_TRUE(id3.good()); 2657 ASSERT_TRUE(id3.good());
2688 EXPECT_TRUE("bob" == id3.Get(NON_UNIQUE_NAME)); 2658 EXPECT_TRUE("bob" == id3.Get(NON_UNIQUE_NAME));
2689 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); 2659 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID));
2690 } 2660 }
2691 saw_syncer_event_ = false; 2661 saw_syncer_event_ = false;
2692 } 2662 }
2693 2663
2694 TEST_F(SyncerTest, CommitManyItemsInOneGo) { 2664 // Committing more than kDefaultMaxCommitBatchSize items requires that
2695 uint32 max_batches = 3; 2665 // we post more than one commit command to the server. This test makes
2696 uint32 items_to_commit = kDefaultMaxCommitBatchSize * max_batches; 2666 // sure that scenario works as expected.
2667 TEST_F(SyncerTest, CommitManyItemsInOneGo_Success) {
2668 uint32 num_batches = 3;
2669 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2697 { 2670 {
2698 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2671 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2699 for (uint32 i = 0; i < items_to_commit; i++) { 2672 for (uint32 i = 0; i < items_to_commit; i++) {
2700 string nameutf8 = base::StringPrintf("%d", i); 2673 string nameutf8 = base::StringPrintf("%d", i);
2701 string name(nameutf8.begin(), nameutf8.end()); 2674 string name(nameutf8.begin(), nameutf8.end());
2702 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2675 MutableEntry e(&trans, CREATE, trans.root_id(), name);
2703 e.Put(IS_UNSYNCED, true); 2676 e.Put(IS_UNSYNCED, true);
2704 e.Put(IS_DIR, true); 2677 e.Put(IS_DIR, true);
2705 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2678 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2706 } 2679 }
2707 } 2680 }
2708 uint32 num_loops = 0; 2681 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2709 while (SyncShareNudge()) { 2682
2710 num_loops++; 2683 EXPECT_FALSE(SyncShareNudge());
2711 ASSERT_LT(num_loops, max_batches * 2); 2684 EXPECT_EQ(num_batches, mock_server_->commit_messages().size());
2685 EXPECT_EQ(0, directory()->unsynced_entity_count());
2686 }
2687
2688 // Test that a single failure to contact the server will cause us to exit the
2689 // commit loop immediately.
2690 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) {
2691 uint32 num_batches = 3;
2692 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2693 {
2694 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2695 for (uint32 i = 0; i < items_to_commit; i++) {
2696 string nameutf8 = base::StringPrintf("%d", i);
2697 string name(nameutf8.begin(), nameutf8.end());
2698 MutableEntry e(&trans, CREATE, trans.root_id(), name);
2699 e.Put(IS_UNSYNCED, true);
2700 e.Put(IS_DIR, true);
2701 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2702 }
2712 } 2703 }
2713 EXPECT_GE(mock_server_->commit_messages().size(), max_batches); 2704 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2705
2706 // The second commit should fail. It will be preceded by one successful
2707 // GetUpdate and one succesful commit.
2708 mock_server_->FailNthPostBufferToPathCall(3);
2709 SyncShareNudge();
2710
2711 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2712 EXPECT_FALSE(session_->Succeeded());
2713 EXPECT_EQ(SYNC_SERVER_ERROR,
2714 session_->status_controller().error().last_post_commit_result);
2715 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize,
2716 directory()->unsynced_entity_count());
2717 }
2718
2719 // Test that a single conflict response from the server will cause us to exit
2720 // the commit loop immediately.
2721 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) {
2722 uint32 num_batches = 2;
2723 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2724 {
2725 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2726 for (uint32 i = 0; i < items_to_commit; i++) {
2727 string nameutf8 = base::StringPrintf("%d", i);
2728 string name(nameutf8.begin(), nameutf8.end());
2729 MutableEntry e(&trans, CREATE, trans.root_id(), name);
2730 e.Put(IS_UNSYNCED, true);
2731 e.Put(IS_DIR, true);
2732 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2733 }
2734 }
2735 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2736
2737 // Return a CONFLICT response for the first item.
2738 mock_server_->set_conflict_n_commits(1);
2739 SyncShareNudge();
2740
2741 // We should stop looping at the first sign of trouble.
2742 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2743 EXPECT_FALSE(session_->Succeeded());
2744 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1),
2745 directory()->unsynced_entity_count());
2714 } 2746 }
2715 2747
2716 TEST_F(SyncerTest, HugeConflict) { 2748 TEST_F(SyncerTest, HugeConflict) {
2717 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 2749 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
2718 2750
2719 syncable::Id parent_id = ids_.NewServerId(); 2751 syncable::Id parent_id = ids_.NewServerId();
2720 syncable::Id last_id = parent_id; 2752 syncable::Id last_id = parent_id;
2721 vector<syncable::Id> tree_ids; 2753 vector<syncable::Id> tree_ids;
2722 2754
2723 // Create a lot of updates for which the parent does not exist yet. 2755 // Create a lot of updates for which the parent does not exist yet.
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after
4259 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4291 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4260 ExpectSyncedAndCreated(); 4292 ExpectSyncedAndCreated();
4261 4293
4262 // Delete, begin committing the delete, then undelete while committing. 4294 // Delete, begin committing the delete, then undelete while committing.
4263 Delete(); 4295 Delete();
4264 ExpectUnsyncedDeletion(); 4296 ExpectUnsyncedDeletion();
4265 mock_server_->SetMidCommitCallback( 4297 mock_server_->SetMidCommitCallback(
4266 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this))); 4298 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this)));
4267 SyncShareNudge(); 4299 SyncShareNudge();
4268 4300
4269 // The item ought to exist as an unsynced undeletion (meaning, 4301 // We will continue to commit until all nodes are synced, so we expect
4270 // we think that the next commit ought to be a recreation commit). 4302 // that both the delete and following undelete were committed. We haven't
4303 // downloaded any updates, though, so the SERVER fields will be the same
4304 // as they were at the start of the cycle.
4271 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4305 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4272 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4306 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4273 ExpectUnsyncedUndeletion(); 4307
4308 // Server fields lag behind.
4309 EXPECT_FALSE(Get(metahandle_, SERVER_IS_DEL));
4310
4311 // We have committed the second (undelete) update.
4312 EXPECT_FALSE(Get(metahandle_, IS_DEL));
4313 EXPECT_FALSE(Get(metahandle_, IS_UNSYNCED));
4314 EXPECT_FALSE(Get(metahandle_, IS_UNAPPLIED_UPDATE));
4274 4315
4275 // Now, encounter a GetUpdates corresponding to the deletion from 4316 // Now, encounter a GetUpdates corresponding to the deletion from
4276 // the server. The undeletion should prevail again and be committed. 4317 // the server. The undeletion should prevail again and be committed.
4277 // None of this should trigger any conflict detection -- it is perfectly 4318 // None of this should trigger any conflict detection -- it is perfectly
4278 // normal to recieve updates from our own commits. 4319 // normal to recieve updates from our own commits.
4279 mock_server_->SetMidCommitCallback(base::Closure()); 4320 mock_server_->SetMidCommitCallback(base::Closure());
4280 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); 4321 mock_server_->AddUpdateFromLastCommit();
4281 SyncShareNudge(); 4322 SyncShareNudge();
4282 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4323 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4283 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4324 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4284 ExpectSyncedAndCreated(); 4325 ExpectSyncedAndCreated();
4285 } 4326 }
4286 4327
4287 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { 4328 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) {
4288 Create(); 4329 Create();
4289 ExpectUnsyncedCreation(); 4330 ExpectUnsyncedCreation();
4290 SyncShareNudge(); 4331 SyncShareNudge();
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
4764 4805
4765 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4806 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4766 Add(mid_id_); 4807 Add(mid_id_);
4767 Add(low_id_); 4808 Add(low_id_);
4768 Add(high_id_); 4809 Add(high_id_);
4769 SyncShareNudge(); 4810 SyncShareNudge();
4770 ExpectLocalOrderIsByServerId(); 4811 ExpectLocalOrderIsByServerId();
4771 } 4812 }
4772 4813
4773 } // namespace browser_sync 4814 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/syncer.cc ('k') | sync/internal_api/all_status.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698