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

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, remove class, modify loop exit 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
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 size_t unsynced_item_count;
401 GetCommitIdsCommand command(limit, &output_set, &unsynced_item_count);
401 std::set<int64> ready_unsynced_set; 402 std::set<int64> ready_unsynced_set;
402 command.FilterUnreadyEntries(&wtrans, syncable::ModelTypeSet(), 403 command.FilterUnreadyEntries(&wtrans, syncable::ModelTypeSet(),
403 syncable::ModelTypeSet(), false, 404 syncable::ModelTypeSet(), false,
404 unsynced_handle_view, &ready_unsynced_set); 405 unsynced_handle_view, &ready_unsynced_set);
405 command.BuildCommitIds(session_->write_transaction(), routes, 406 command.BuildCommitIds(session_->write_transaction(), routes,
406 ready_unsynced_set); 407 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()); 408 size_t truncated_size = std::min(limit, expected_id_order.size());
413 ASSERT_EQ(truncated_size, output.size()); 409 ASSERT_EQ(truncated_size, output_set.Size());
414 for (size_t i = 0; i < truncated_size; ++i) { 410 for (size_t i = 0; i < truncated_size; ++i) {
415 ASSERT_EQ(expected_id_order[i], output[i]) 411 ASSERT_EQ(expected_id_order[i], output_set.GetCommitIdAt(i))
416 << "At index " << i << " with batch size limited to " << limit; 412 << "At index " << i << " with batch size limited to " << limit;
417 } 413 }
418 sessions::OrderedCommitSet::Projection proj; 414 sessions::OrderedCommitSet::Projection proj;
419 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); 415 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE);
420 ASSERT_EQ(truncated_size, proj.size()); 416 ASSERT_EQ(truncated_size, proj.size());
421 for (size_t i = 0; i < truncated_size; ++i) { 417 for (size_t i = 0; i < truncated_size; ++i) {
422 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); 418 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i);
423 syncable::Id projected = 419 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); 420 ASSERT_EQ(expected_id_order[proj[i]], projected);
426 // Since this projection is the identity, the following holds. 421 // Since this projection is the identity, the following holds.
427 ASSERT_EQ(expected_id_order[i], projected); 422 ASSERT_EQ(expected_id_order[i], projected);
428 } 423 }
429 } 424 }
430 } 425 }
431 426
432 const StatusController& status() { 427 const StatusController& status() {
433 return session_->status_controller(); 428 return session_->status_controller();
434 } 429 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 C.Put(NON_UNIQUE_NAME, kEncryptedString); 722 C.Put(NON_UNIQUE_NAME, kEncryptedString);
728 // Unencrypted non_unique_name. 723 // Unencrypted non_unique_name.
729 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 724 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
730 ASSERT_TRUE(D.good()); 725 ASSERT_TRUE(D.good());
731 D.Put(IS_UNSYNCED, true); 726 D.Put(IS_UNSYNCED, true);
732 D.Put(SPECIFICS, encrypted_bookmark); 727 D.Put(SPECIFICS, encrypted_bookmark);
733 D.Put(NON_UNIQUE_NAME, "not encrypted"); 728 D.Put(NON_UNIQUE_NAME, "not encrypted");
734 } 729 }
735 SyncShareNudge(); 730 SyncShareNudge();
736 { 731 {
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 732 // Nothing should have commited due to bookmarks being encrypted and
741 // the cryptographer having pending keys. A would have been resolved 733 // the cryptographer having pending keys. A would have been resolved
742 // as a simple conflict, but still be unsynced until the next sync cycle. 734 // as a simple conflict, but still be unsynced until the next sync cycle.
743 ReadTransaction rtrans(FROM_HERE, directory()); 735 ReadTransaction rtrans(FROM_HERE, directory());
744 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); 736 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans);
745 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); 737 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans);
746 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 738 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
747 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 739 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
748 740
749 // Resolve the pending keys. 741 // Resolve the pending keys.
750 cryptographer(&rtrans)->DecryptPendingKeys(other_params); 742 cryptographer(&rtrans)->DecryptPendingKeys(other_params);
751 } 743 }
752 SyncShareNudge(); 744 SyncShareNudge();
753 { 745 {
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 746 // All properly encrypted and non-conflicting items should commit. "A" was
757 // conflicting, but last sync cycle resolved it as simple conflict, so on 747 // conflicting, but last sync cycle resolved it as simple conflict, so on
758 // this sync cycle it committed succesfullly. 748 // this sync cycle it committed succesfullly.
759 ReadTransaction rtrans(FROM_HERE, directory()); 749 ReadTransaction rtrans(FROM_HERE, directory());
760 // Committed successfully. 750 // Committed successfully.
761 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 751 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
762 // Committed successfully. 752 // Committed successfully.
763 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 753 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
764 // Was not properly encrypted. 754 // Was not properly encrypted.
765 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 755 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
766 // Was not properly encrypted. 756 // Was not properly encrypted.
767 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 757 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
768 } 758 }
769 { 759 {
770 // Fix the remaining items. 760 // Fix the remaining items.
771 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 761 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
772 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 762 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
773 ASSERT_TRUE(C.good()); 763 ASSERT_TRUE(C.good());
774 C.Put(SPECIFICS, encrypted_bookmark); 764 C.Put(SPECIFICS, encrypted_bookmark);
775 C.Put(NON_UNIQUE_NAME, kEncryptedString); 765 C.Put(NON_UNIQUE_NAME, kEncryptedString);
776 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 766 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
777 ASSERT_TRUE(D.good()); 767 ASSERT_TRUE(D.good());
778 D.Put(SPECIFICS, encrypted_bookmark); 768 D.Put(SPECIFICS, encrypted_bookmark);
779 D.Put(NON_UNIQUE_NAME, kEncryptedString); 769 D.Put(NON_UNIQUE_NAME, kEncryptedString);
780 } 770 }
781 SyncShareNudge(); 771 SyncShareNudge();
782 { 772 {
783 // We attempted to commit two items. 773 const StatusController& status_controller = session_->status_controller();
784 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 774 // Expect success.
785 EXPECT_TRUE(session_->status_controller().did_commit_items()); 775 EXPECT_EQ(status_controller.last_post_commit_result(), SYNCER_OK);
786 // None should be unsynced anymore. 776 // None should be unsynced anymore.
787 ReadTransaction rtrans(FROM_HERE, directory()); 777 ReadTransaction rtrans(FROM_HERE, directory());
788 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 778 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
789 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 779 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
790 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); 780 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans);
791 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); 781 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans);
792 } 782 }
793 } 783 }
794 784
795 TEST_F(SyncerTest, EncryptionAwareConflicts) { 785 TEST_F(SyncerTest, EncryptionAwareConflicts) {
(...skipping 28 matching lines...) Expand all
824 cryptographer(&wtrans)->Update(*nigori); 814 cryptographer(&wtrans)->Update(*nigori);
825 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 815 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
826 } 816 }
827 817
828 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 818 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
829 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 819 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
830 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 820 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
831 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 821 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
832 SyncShareNudge(); 822 SyncShareNudge();
833 { 823 {
834 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
835 // Initial state. Everything is normal. 824 // Initial state. Everything is normal.
836 ReadTransaction rtrans(FROM_HERE, directory()); 825 ReadTransaction rtrans(FROM_HERE, directory());
837 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 826 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
838 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 827 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
839 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 828 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
840 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 829 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
841 } 830 }
842 831
843 // Server side encryption will not be applied due to undecryptable data. 832 // 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. 833 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items.
845 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, 834 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0,
846 encrypted_bookmark); 835 encrypted_bookmark);
847 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, 836 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2,
848 encrypted_bookmark); 837 encrypted_bookmark);
849 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, 838 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1,
850 encrypted_bookmark); 839 encrypted_bookmark);
851 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, 840 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0,
852 encrypted_pref); 841 encrypted_pref);
853 SyncShareNudge(); 842 SyncShareNudge();
854 { 843 {
855 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
856 // All should be unapplied due to being undecryptable and have a valid 844 // All should be unapplied due to being undecryptable and have a valid
857 // BASE_SERVER_SPECIFICS. 845 // BASE_SERVER_SPECIFICS.
858 ReadTransaction rtrans(FROM_HERE, directory()); 846 ReadTransaction rtrans(FROM_HERE, directory());
859 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); 847 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans);
860 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); 848 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans);
861 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 849 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
862 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); 850 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans);
863 } 851 }
864 852
865 // Server side change that don't modify anything should not affect 853 // Server side change that don't modify anything should not affect
866 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). 854 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes).
867 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, 855 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0,
868 encrypted_bookmark); 856 encrypted_bookmark);
869 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, 857 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2,
870 encrypted_bookmark); 858 encrypted_bookmark);
871 // Item 3 doesn't change. 859 // Item 3 doesn't change.
872 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, 860 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0,
873 encrypted_pref); 861 encrypted_pref);
874 SyncShareNudge(); 862 SyncShareNudge();
875 { 863 {
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. 864 // Items 1, 2, and 4 should have newer server versions, 3 remains the same.
878 // All should remain unapplied due to be undecryptable. 865 // All should remain unapplied due to be undecryptable.
879 ReadTransaction rtrans(FROM_HERE, directory()); 866 ReadTransaction rtrans(FROM_HERE, directory());
880 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); 867 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans);
881 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 868 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
882 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 869 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
883 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 870 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
884 } 871 }
885 872
886 // Positional changes, parent changes, and specifics changes should reset 873 // Positional changes, parent changes, and specifics changes should reset
887 // BASE_SERVER_SPECIFICS. 874 // BASE_SERVER_SPECIFICS.
888 // Became unencrypted. 875 // Became unencrypted.
889 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark); 876 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark);
890 // Reordered to after item 2. 877 // Reordered to after item 2.
891 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, 878 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3,
892 encrypted_bookmark); 879 encrypted_bookmark);
893 SyncShareNudge(); 880 SyncShareNudge();
894 { 881 {
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. 882 // 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. 883 // Items 1 is now unencrypted, so should have applied normally.
898 ReadTransaction rtrans(FROM_HERE, directory()); 884 ReadTransaction rtrans(FROM_HERE, directory());
899 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); 885 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans);
900 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 886 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
901 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); 887 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans);
902 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 888 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
903 } 889 }
904 890
905 // Make local changes, which should remain unsynced for items 2, 3, 4. 891 // 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); 907 C.Put(NON_UNIQUE_NAME, kEncryptedString);
922 C.Put(IS_UNSYNCED, true); 908 C.Put(IS_UNSYNCED, true);
923 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 909 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
924 ASSERT_TRUE(D.good()); 910 ASSERT_TRUE(D.good());
925 D.Put(SPECIFICS, modified_pref); 911 D.Put(SPECIFICS, modified_pref);
926 D.Put(NON_UNIQUE_NAME, kEncryptedString); 912 D.Put(NON_UNIQUE_NAME, kEncryptedString);
927 D.Put(IS_UNSYNCED, true); 913 D.Put(IS_UNSYNCED, true);
928 } 914 }
929 SyncShareNudge(); 915 SyncShareNudge();
930 { 916 {
931 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
932 // Item 1 remains unsynced due to there being pending keys. 917 // 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. 918 // Items 2, 3, 4 should remain unsynced since they were not up to date.
934 ReadTransaction rtrans(FROM_HERE, directory()); 919 ReadTransaction rtrans(FROM_HERE, directory());
935 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); 920 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans);
936 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); 921 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans);
937 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); 922 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans);
938 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); 923 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans);
939 } 924 }
940 925
941 { 926 {
942 ReadTransaction rtrans(FROM_HERE, directory()); 927 ReadTransaction rtrans(FROM_HERE, directory());
943 // Resolve the pending keys. 928 // Resolve the pending keys.
944 cryptographer(&rtrans)->DecryptPendingKeys(key_params); 929 cryptographer(&rtrans)->DecryptPendingKeys(key_params);
945 } 930 }
946 // First cycle resolves conflicts, second cycle commits changes. 931 // First cycle resolves conflicts, second cycle commits changes.
947 SyncShareNudge(); 932 SyncShareNudge();
948 EXPECT_EQ(2, session_->status_controller().syncer_status(). 933 EXPECT_EQ(2, status().syncer_status().num_server_overwrites);
949 num_server_overwrites); 934 EXPECT_EQ(1, status().syncer_status().num_local_overwrites);
950 EXPECT_EQ(1, session_->status_controller().syncer_status(). 935 // We successfully commited item(s).
951 num_local_overwrites); 936 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(); 937 SyncShareNudge();
956 { 938
957 // Everything should be resolved now. The local changes should have 939 // Everything should be resolved now. The local changes should have
958 // overwritten the server changes for 2 and 4, while the server changes 940 // overwritten the server changes for 2 and 4, while the server changes
959 // overwrote the local for entry 3. 941 // overwrote the local for entry 3.
960 // We attempted to commit two handles. 942 EXPECT_EQ(0, status().syncer_status().num_server_overwrites);
961 EXPECT_EQ(0, session_->status_controller().syncer_status(). 943 EXPECT_EQ(0, status().syncer_status().num_local_overwrites);
962 num_server_overwrites); 944 EXPECT_EQ(status().last_post_commit_result(), SYNCER_OK);
963 EXPECT_EQ(0, session_->status_controller().syncer_status(). 945 ReadTransaction rtrans(FROM_HERE, directory());
964 num_local_overwrites); 946 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
965 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 947 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
966 EXPECT_TRUE(session_->status_controller().did_commit_items()); 948 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
967 ReadTransaction rtrans(FROM_HERE, directory()); 949 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 } 950 }
974 951
975 #undef VERIFY_ENTRY 952 #undef VERIFY_ENTRY
976 953
977 // Receive an old nigori with old encryption keys and encrypted types. We should 954 // Receive an old nigori with old encryption keys and encrypted types. We should
978 // not revert our default key or encrypted types. 955 // not revert our default key or encrypted types.
979 TEST_F(SyncerTest, ReceiveOldNigori) { 956 TEST_F(SyncerTest, ReceiveOldNigori) {
980 KeyParams old_key = {"localhost", "dummy", "old"}; 957 KeyParams old_key = {"localhost", "dummy", "old"};
981 KeyParams current_key = {"localhost", "dummy", "cur"}; 958 KeyParams current_key = {"localhost", "dummy", "cur"};
982 959
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 parent.Put(syncable::BASE_VERSION, 1); 1168 parent.Put(syncable::BASE_VERSION, 1);
1192 parent.Put(syncable::ID, parent_id_); 1169 parent.Put(syncable::ID, parent_id_);
1193 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 1170 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete");
1194 ASSERT_TRUE(child.good()); 1171 ASSERT_TRUE(child.good());
1195 child.Put(syncable::ID, child_id_); 1172 child.Put(syncable::ID, child_id_);
1196 child.Put(syncable::BASE_VERSION, 1); 1173 child.Put(syncable::BASE_VERSION, 1);
1197 WriteTestDataToEntry(&wtrans, &child); 1174 WriteTestDataToEntry(&wtrans, &child);
1198 } 1175 }
1199 1176
1200 SyncShareNudge(); 1177 SyncShareNudge();
1201 EXPECT_EQ(2u, status().unsynced_handles().size());
1202 ASSERT_EQ(2u, mock_server_->committed_ids().size()); 1178 ASSERT_EQ(2u, mock_server_->committed_ids().size());
1203 // If this test starts failing, be aware other sort orders could be valid. 1179 // If this test starts failing, be aware other sort orders could be valid.
1204 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1180 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1205 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1181 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1206 { 1182 {
1207 ReadTransaction rt(FROM_HERE, directory()); 1183 ReadTransaction rt(FROM_HERE, directory());
1208 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1184 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1209 ASSERT_TRUE(entry.good()); 1185 ASSERT_TRUE(entry.good());
1210 VerifyTestDataInEntry(&rt, &entry); 1186 VerifyTestDataInEntry(&rt, &entry);
1211 } 1187 }
(...skipping 23 matching lines...) Expand all
1235 parent2.Put(syncable::IS_DIR, true); 1211 parent2.Put(syncable::IS_DIR, true);
1236 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); 1212 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics());
1237 parent2.Put(syncable::BASE_VERSION, 1); 1213 parent2.Put(syncable::BASE_VERSION, 1);
1238 parent2.Put(syncable::ID, pref_node_id); 1214 parent2.Put(syncable::ID, pref_node_id);
1239 } 1215 }
1240 1216
1241 directory()->PurgeEntriesWithTypeIn( 1217 directory()->PurgeEntriesWithTypeIn(
1242 syncable::ModelTypeSet(syncable::PREFERENCES)); 1218 syncable::ModelTypeSet(syncable::PREFERENCES));
1243 1219
1244 SyncShareNudge(); 1220 SyncShareNudge();
1245 EXPECT_EQ(2U, status().unsynced_handles().size());
1246 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 1221 ASSERT_EQ(2U, mock_server_->committed_ids().size());
1247 // If this test starts failing, be aware other sort orders could be valid. 1222 // If this test starts failing, be aware other sort orders could be valid.
1248 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1223 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1249 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1224 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1250 { 1225 {
1251 ReadTransaction rt(FROM_HERE, directory()); 1226 ReadTransaction rt(FROM_HERE, directory());
1252 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1227 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1253 ASSERT_TRUE(entry.good()); 1228 ASSERT_TRUE(entry.good());
1254 VerifyTestDataInEntry(&rt, &entry); 1229 VerifyTestDataInEntry(&rt, &entry);
1255 } 1230 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 grandchild.Put(syncable::ID, ids_.FromNumber(105)); 1449 grandchild.Put(syncable::ID, ids_.FromNumber(105));
1475 grandchild.Put(syncable::IS_DEL, true); 1450 grandchild.Put(syncable::IS_DEL, true);
1476 grandchild.Put(syncable::IS_DIR, false); 1451 grandchild.Put(syncable::IS_DIR, false);
1477 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1452 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1478 grandchild.Put(syncable::BASE_VERSION, 1); 1453 grandchild.Put(syncable::BASE_VERSION, 1);
1479 grandchild.Put(syncable::MTIME, now_minus_2h); 1454 grandchild.Put(syncable::MTIME, now_minus_2h);
1480 } 1455 }
1481 } 1456 }
1482 1457
1483 SyncShareNudge(); 1458 SyncShareNudge();
1484 EXPECT_EQ(6u, session_->status_controller().unsynced_handles().size());
1485 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1459 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1486 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. 1460 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set.
1487 // It will treat these like moves. 1461 // It will treat these like moves.
1488 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); 1462 vector<syncable::Id> commit_ids(mock_server_->committed_ids());
1489 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); 1463 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]);
1490 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); 1464 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]);
1491 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); 1465 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]);
1492 // We don't guarantee the delete orders in this test, only that they occur 1466 // We don't guarantee the delete orders in this test, only that they occur
1493 // at the end. 1467 // at the end.
1494 std::sort(commit_ids.begin() + 3, commit_ids.end()); 1468 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"); 1516 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B");
1543 ASSERT_TRUE(child.good()); 1517 ASSERT_TRUE(child.good());
1544 child.Put(syncable::IS_UNSYNCED, true); 1518 child.Put(syncable::IS_UNSYNCED, true);
1545 child.Put(syncable::IS_DIR, true); 1519 child.Put(syncable::IS_DIR, true);
1546 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1520 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1547 child.Put(syncable::ID, ids_.FromNumber(105)); 1521 child.Put(syncable::ID, ids_.FromNumber(105));
1548 child.Put(syncable::BASE_VERSION, 1); 1522 child.Put(syncable::BASE_VERSION, 1);
1549 } 1523 }
1550 1524
1551 SyncShareNudge(); 1525 SyncShareNudge();
1552 EXPECT_EQ(6u, session_->status_controller().unsynced_handles().size());
1553 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1526 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1554 // If this test starts failing, be aware other sort orders could be valid. 1527 // If this test starts failing, be aware other sort orders could be valid.
1555 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1528 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1556 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1529 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1557 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); 1530 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]);
1558 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); 1531 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]);
1559 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); 1532 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]);
1560 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); 1533 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]);
1561 } 1534 }
1562 1535
(...skipping 18 matching lines...) Expand all
1581 child2.Put(syncable::IS_UNSYNCED, true); 1554 child2.Put(syncable::IS_UNSYNCED, true);
1582 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1555 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1583 child2.Put(syncable::ID, child2_id); 1556 child2.Put(syncable::ID, child2_id);
1584 1557
1585 parent.Put(syncable::BASE_VERSION, 1); 1558 parent.Put(syncable::BASE_VERSION, 1);
1586 child1.Put(syncable::BASE_VERSION, 1); 1559 child1.Put(syncable::BASE_VERSION, 1);
1587 child2.Put(syncable::BASE_VERSION, 1); 1560 child2.Put(syncable::BASE_VERSION, 1);
1588 } 1561 }
1589 1562
1590 SyncShareNudge(); 1563 SyncShareNudge();
1591 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1592 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1564 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1593 // If this test starts failing, be aware other sort orders could be valid. 1565 // If this test starts failing, be aware other sort orders could be valid.
1594 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1566 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1595 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1567 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1596 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); 1568 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]);
1597 } 1569 }
1598 1570
1599 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { 1571 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) {
1600 string parent1_name = "1"; 1572 string parent1_name = "1";
1601 string parent2_name = "A"; 1573 string parent2_name = "A";
(...skipping 25 matching lines...) Expand all
1627 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); 1599 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name);
1628 ASSERT_TRUE(child.good()); 1600 ASSERT_TRUE(child.good());
1629 child.Put(syncable::IS_UNSYNCED, true); 1601 child.Put(syncable::IS_UNSYNCED, true);
1630 child.Put(syncable::IS_DIR, true); 1602 child.Put(syncable::IS_DIR, true);
1631 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1603 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1632 child.Put(syncable::ID, child_id); 1604 child.Put(syncable::ID, child_id);
1633 child.Put(syncable::BASE_VERSION, 1); 1605 child.Put(syncable::BASE_VERSION, 1);
1634 } 1606 }
1635 1607
1636 SyncShareNudge(); 1608 SyncShareNudge();
1637 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1638 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1609 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1639 // If this test starts failing, be aware other sort orders could be valid. 1610 // If this test starts failing, be aware other sort orders could be valid.
1640 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1611 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1641 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]); 1612 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]);
1642 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]); 1613 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]);
1643 { 1614 {
1644 ReadTransaction rtrans(FROM_HERE, directory()); 1615 ReadTransaction rtrans(FROM_HERE, directory());
1645 // Check that things committed correctly. 1616 // Check that things committed correctly.
1646 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); 1617 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_);
1647 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name); 1618 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); 1669 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name);
1699 ASSERT_TRUE(child.good()); 1670 ASSERT_TRUE(child.good());
1700 child.Put(syncable::IS_UNSYNCED, true); 1671 child.Put(syncable::IS_UNSYNCED, true);
1701 child.Put(syncable::IS_DIR, true); 1672 child.Put(syncable::IS_DIR, true);
1702 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1673 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1703 child.Put(syncable::ID, child_local_id); 1674 child.Put(syncable::ID, child_local_id);
1704 meta_handle_b = child.Get(syncable::META_HANDLE); 1675 meta_handle_b = child.Get(syncable::META_HANDLE);
1705 } 1676 }
1706 1677
1707 SyncShareNudge(); 1678 SyncShareNudge();
1708 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1709 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1679 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1710 // If this test starts failing, be aware other sort orders could be valid. 1680 // If this test starts failing, be aware other sort orders could be valid.
1711 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1681 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1712 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]); 1682 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]);
1713 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]); 1683 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]);
1714 { 1684 {
1715 ReadTransaction rtrans(FROM_HERE, directory()); 1685 ReadTransaction rtrans(FROM_HERE, directory());
1716 1686
1717 Entry parent(&rtrans, syncable::GET_BY_ID, 1687 Entry parent(&rtrans, syncable::GET_BY_ID,
1718 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); 1688 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name));
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 "bob"); 2295 "bob");
2326 ASSERT_TRUE(entry.good()); 2296 ASSERT_TRUE(entry.good());
2327 entry.Put(syncable::IS_DIR, true); 2297 entry.Put(syncable::IS_DIR, true);
2328 entry.Put(syncable::IS_UNSYNCED, true); 2298 entry.Put(syncable::IS_UNSYNCED, true);
2329 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2299 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2330 } 2300 }
2331 2301
2332 mock_server_->SetMidCommitCallback( 2302 mock_server_->SetMidCommitCallback(
2333 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2303 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2334 base::Unretained(this))); 2304 base::Unretained(this)));
2335 syncer_->SyncShare(session_.get(), BUILD_COMMIT_REQUEST, SYNCER_END); 2305 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END);
2336 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2306 // We loop until no unsynced handles remain, so we will commit both ids.
2307 EXPECT_EQ(2u, mock_server_->committed_ids().size());
2337 { 2308 {
2338 ReadTransaction trans(FROM_HERE, directory()); 2309 ReadTransaction trans(FROM_HERE, directory());
2339 Entry parent_entry(&trans, syncable::GET_BY_ID, 2310 Entry parent_entry(&trans, syncable::GET_BY_ID,
2340 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2311 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2341 ASSERT_TRUE(parent_entry.good()); 2312 ASSERT_TRUE(parent_entry.good());
2342 2313
2343 Id child_id = 2314 Id child_id =
2344 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 2315 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
2345 Entry child(&trans, syncable::GET_BY_ID, child_id); 2316 Entry child(&trans, syncable::GET_BY_ID, child_id);
2346 ASSERT_TRUE(child.good()); 2317 ASSERT_TRUE(child.good());
2347 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); 2318 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID));
2348 } 2319 }
2349 } 2320 }
2350 2321
2351 TEST_F(SyncerTest, NegativeIDInUpdate) { 2322 TEST_F(SyncerTest, NegativeIDInUpdate) {
2352 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); 2323 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40);
2353 SyncShareNudge(); 2324 SyncShareNudge();
2354 // The negative id would make us CHECK! 2325 // The negative id would make us CHECK!
2355 } 2326 }
2356 2327
2357 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2328 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2358 int64 metahandle_fred; 2329 int64 metahandle_fred;
(...skipping 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after
4254 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4225 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4255 ExpectSyncedAndCreated(); 4226 ExpectSyncedAndCreated();
4256 4227
4257 // Delete, begin committing the delete, then undelete while committing. 4228 // Delete, begin committing the delete, then undelete while committing.
4258 Delete(); 4229 Delete();
4259 ExpectUnsyncedDeletion(); 4230 ExpectUnsyncedDeletion();
4260 mock_server_->SetMidCommitCallback( 4231 mock_server_->SetMidCommitCallback(
4261 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this))); 4232 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this)));
4262 SyncShareNudge(); 4233 SyncShareNudge();
4263 4234
4264 // The item ought to exist as an unsynced undeletion (meaning, 4235 // We will continue to commit until all nodes are synced, so we expect
4265 // we think that the next commit ought to be a recreation commit). 4236 // that both the delete and following undelete were committed. We haven't
4237 // downloaded any updates, though, so the SERVER fields will be the same
4238 // as they were at the start of the cycle.
4266 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4239 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4267 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4240 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4268 ExpectUnsyncedUndeletion(); 4241
4242 // Server fields lag behind.
4243 EXPECT_FALSE(Get(metahandle_, SERVER_IS_DEL));
4244
4245 // We have committed the second (undelete) update.
4246 EXPECT_FALSE(Get(metahandle_, IS_DEL));
4247 EXPECT_FALSE(Get(metahandle_, IS_UNSYNCED));
4248 EXPECT_FALSE(Get(metahandle_, IS_UNAPPLIED_UPDATE));
4269 4249
4270 // Now, encounter a GetUpdates corresponding to the deletion from 4250 // Now, encounter a GetUpdates corresponding to the deletion from
4271 // the server. The undeletion should prevail again and be committed. 4251 // the server. The undeletion should prevail again and be committed.
4272 // None of this should trigger any conflict detection -- it is perfectly 4252 // None of this should trigger any conflict detection -- it is perfectly
4273 // normal to recieve updates from our own commits. 4253 // normal to recieve updates from our own commits.
4274 mock_server_->SetMidCommitCallback(base::Closure()); 4254 mock_server_->SetMidCommitCallback(base::Closure());
4275 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); 4255 mock_server_->AddUpdateFromLastCommit();
4276 SyncShareNudge(); 4256 SyncShareNudge();
4277 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4257 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4278 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4258 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4279 ExpectSyncedAndCreated(); 4259 ExpectSyncedAndCreated();
4280 } 4260 }
4281 4261
4282 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { 4262 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) {
4283 Create(); 4263 Create();
4284 ExpectUnsyncedCreation(); 4264 ExpectUnsyncedCreation();
4285 SyncShareNudge(); 4265 SyncShareNudge();
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
4759 4739
4760 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4740 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4761 Add(mid_id_); 4741 Add(mid_id_);
4762 Add(low_id_); 4742 Add(low_id_);
4763 Add(high_id_); 4743 Add(high_id_);
4764 SyncShareNudge(); 4744 SyncShareNudge();
4765 ExpectLocalOrderIsByServerId(); 4745 ExpectLocalOrderIsByServerId();
4766 } 4746 }
4767 4747
4768 } // namespace browser_sync 4748 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698