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

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

Issue 10038041: sync: Loop committing items without downloading updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // If this test starts failing, be aware other sort orders could be valid. 364 // If this test starts failing, be aware other sort orders could be valid.
365 for (size_t i = 0; i < expected_positions.size(); ++i) { 365 for (size_t i = 0; i < expected_positions.size(); ++i) {
366 EXPECT_EQ(1u, expected_positions.count(i)); 366 EXPECT_EQ(1u, expected_positions.count(i));
367 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]); 367 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]);
368 } 368 }
369 } 369 }
370 370
371 void DoTruncationTest(const vector<int64>& unsynced_handle_view, 371 void DoTruncationTest(const vector<int64>& unsynced_handle_view,
372 const vector<syncable::Id>& expected_id_order) { 372 const vector<syncable::Id>& expected_id_order) {
373 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) { 373 for (size_t limit = expected_id_order.size() + 2; limit > 0; --limit) {
374 StatusController* status = session_->mutable_status_controller();
375 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 374 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
376 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans); 375 ScopedSetSessionWriteTransaction set_trans(session_.get(), &wtrans);
377 376
378 ModelSafeRoutingInfo routes; 377 ModelSafeRoutingInfo routes;
379 GetModelSafeRoutingInfo(&routes); 378 GetModelSafeRoutingInfo(&routes);
380 GetCommitIdsCommand command(limit); 379 sessions::OrderedCommitSet output_set(routes);
380 GetCommitIdsCommand command(limit, &output_set);
381 std::set<int64> ready_unsynced_set; 381 std::set<int64> ready_unsynced_set;
382 command.FilterUnreadyEntries(&wtrans, syncable::ModelTypeSet(), 382 command.FilterUnreadyEntries(&wtrans, syncable::ModelTypeSet(),
383 syncable::ModelTypeSet(), false, 383 syncable::ModelTypeSet(), false,
384 unsynced_handle_view, &ready_unsynced_set); 384 unsynced_handle_view, &ready_unsynced_set);
385 command.BuildCommitIds(session_->write_transaction(), routes, 385 command.BuildCommitIds(session_->write_transaction(), routes,
386 ready_unsynced_set); 386 ready_unsynced_set);
387 syncable::Directory::UnsyncedMetaHandles ready_unsynced_vector( 387 syncable::Directory::UnsyncedMetaHandles ready_unsynced_vector(
388 ready_unsynced_set.begin(), ready_unsynced_set.end()); 388 ready_unsynced_set.begin(), ready_unsynced_set.end());
389 status->set_unsynced_handles(ready_unsynced_vector);
390 vector<syncable::Id> output =
391 command.ordered_commit_set_->GetAllCommitIds();
392 size_t truncated_size = std::min(limit, expected_id_order.size()); 389 size_t truncated_size = std::min(limit, expected_id_order.size());
393 ASSERT_EQ(truncated_size, output.size()); 390 ASSERT_EQ(truncated_size, output_set.Size());
394 for (size_t i = 0; i < truncated_size; ++i) { 391 for (size_t i = 0; i < truncated_size; ++i) {
395 ASSERT_EQ(expected_id_order[i], output[i]) 392 ASSERT_EQ(expected_id_order[i], output_set.GetCommitIdAt(i))
396 << "At index " << i << " with batch size limited to " << limit; 393 << "At index " << i << " with batch size limited to " << limit;
397 } 394 }
398 sessions::OrderedCommitSet::Projection proj; 395 sessions::OrderedCommitSet::Projection proj;
399 proj = command.ordered_commit_set_->GetCommitIdProjection(GROUP_PASSIVE); 396 proj = output_set.GetCommitIdProjection(GROUP_PASSIVE);
400 ASSERT_EQ(truncated_size, proj.size()); 397 ASSERT_EQ(truncated_size, proj.size());
401 for (size_t i = 0; i < truncated_size; ++i) { 398 for (size_t i = 0; i < truncated_size; ++i) {
402 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i); 399 SCOPED_TRACE(::testing::Message("Projection mismatch with i = ") << i);
403 syncable::Id projected = 400 syncable::Id projected = output_set.GetCommitIdAt(proj[i]);
404 command.ordered_commit_set_->GetCommitIdAt(proj[i]);
405 ASSERT_EQ(expected_id_order[proj[i]], projected); 401 ASSERT_EQ(expected_id_order[proj[i]], projected);
406 // Since this projection is the identity, the following holds. 402 // Since this projection is the identity, the following holds.
407 ASSERT_EQ(expected_id_order[i], projected); 403 ASSERT_EQ(expected_id_order[i], projected);
408 } 404 }
409 } 405 }
410 } 406 }
411 407
412 Directory* directory() { 408 Directory* directory() {
413 return dir_maker_.directory(); 409 return dir_maker_.directory();
414 } 410 }
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 C.Put(NON_UNIQUE_NAME, kEncryptedString); 699 C.Put(NON_UNIQUE_NAME, kEncryptedString);
704 // Unencrypted non_unique_name. 700 // Unencrypted non_unique_name.
705 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 701 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
706 ASSERT_TRUE(D.good()); 702 ASSERT_TRUE(D.good());
707 D.Put(IS_UNSYNCED, true); 703 D.Put(IS_UNSYNCED, true);
708 D.Put(SPECIFICS, encrypted_bookmark); 704 D.Put(SPECIFICS, encrypted_bookmark);
709 D.Put(NON_UNIQUE_NAME, "not encrypted"); 705 D.Put(NON_UNIQUE_NAME, "not encrypted");
710 } 706 }
711 SyncShareAsDelegate(); 707 SyncShareAsDelegate();
712 { 708 {
713 // We remove any unready entries from the status controller's unsynced
714 // handles, so this should remain 0 even though the entries didn't commit.
715 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
716 // Nothing should have commited due to bookmarks being encrypted and 709 // Nothing should have commited due to bookmarks being encrypted and
717 // the cryptographer having pending keys. A would have been resolved 710 // the cryptographer having pending keys. A would have been resolved
718 // as a simple conflict, but still be unsynced until the next sync cycle. 711 // as a simple conflict, but still be unsynced until the next sync cycle.
719 ReadTransaction rtrans(FROM_HERE, directory()); 712 ReadTransaction rtrans(FROM_HERE, directory());
720 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); 713 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans);
721 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); 714 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans);
722 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 715 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
723 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 716 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
724 717
725 // Resolve the pending keys. 718 // Resolve the pending keys.
726 cryptographer(&rtrans)->DecryptPendingKeys(other_params); 719 cryptographer(&rtrans)->DecryptPendingKeys(other_params);
727 } 720 }
728 SyncShareAsDelegate(); 721 SyncShareAsDelegate();
729 { 722 {
730 // 2 unsynced handles to reflect the items that committed succesfully.
731 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size());
732 // All properly encrypted and non-conflicting items should commit. "A" was 723 // All properly encrypted and non-conflicting items should commit. "A" was
733 // conflicting, but last sync cycle resolved it as simple conflict, so on 724 // conflicting, but last sync cycle resolved it as simple conflict, so on
734 // this sync cycle it committed succesfullly. 725 // this sync cycle it committed succesfullly.
735 ReadTransaction rtrans(FROM_HERE, directory()); 726 ReadTransaction rtrans(FROM_HERE, directory());
736 // Committed successfully. 727 // Committed successfully.
737 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 728 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
738 // Committed successfully. 729 // Committed successfully.
739 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 730 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
740 // Was not properly encrypted. 731 // Was not properly encrypted.
741 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 732 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
742 // Was not properly encrypted. 733 // Was not properly encrypted.
743 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 734 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
744 } 735 }
745 { 736 {
746 // Fix the remaining items. 737 // Fix the remaining items.
747 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 738 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
748 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 739 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
749 ASSERT_TRUE(C.good()); 740 ASSERT_TRUE(C.good());
750 C.Put(SPECIFICS, encrypted_bookmark); 741 C.Put(SPECIFICS, encrypted_bookmark);
751 C.Put(NON_UNIQUE_NAME, kEncryptedString); 742 C.Put(NON_UNIQUE_NAME, kEncryptedString);
752 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 743 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
753 ASSERT_TRUE(D.good()); 744 ASSERT_TRUE(D.good());
754 D.Put(SPECIFICS, encrypted_bookmark); 745 D.Put(SPECIFICS, encrypted_bookmark);
755 D.Put(NON_UNIQUE_NAME, kEncryptedString); 746 D.Put(NON_UNIQUE_NAME, kEncryptedString);
756 } 747 }
757 SyncShareAsDelegate(); 748 SyncShareAsDelegate();
758 { 749 {
759 // We attempted to commit two items. 750 const StatusController& status_controller = session_->status_controller();
760 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 751 // Expect success.
761 EXPECT_TRUE(session_->status_controller().did_commit_items()); 752 EXPECT_EQ(status_controller.last_post_commit_result(), SYNCER_OK);
762 // None should be unsynced anymore. 753 // None should be unsynced anymore.
763 ReadTransaction rtrans(FROM_HERE, directory()); 754 ReadTransaction rtrans(FROM_HERE, directory());
764 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 755 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
765 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 756 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
766 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); 757 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans);
767 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); 758 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans);
768 } 759 }
769 } 760 }
770 761
771 TEST_F(SyncerTest, EncryptionAwareConflicts) { 762 TEST_F(SyncerTest, EncryptionAwareConflicts) {
(...skipping 28 matching lines...) Expand all
800 cryptographer(&wtrans)->Update(*nigori); 791 cryptographer(&wtrans)->Update(*nigori);
801 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 792 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
802 } 793 }
803 794
804 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 795 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
805 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 796 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
806 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 797 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
807 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 798 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
808 SyncShareAsDelegate(); 799 SyncShareAsDelegate();
809 { 800 {
810 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
811 // Initial state. Everything is normal. 801 // Initial state. Everything is normal.
812 ReadTransaction rtrans(FROM_HERE, directory()); 802 ReadTransaction rtrans(FROM_HERE, directory());
813 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 803 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
814 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 804 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
815 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 805 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
816 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 806 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
817 } 807 }
818 808
819 // Server side encryption will not be applied due to undecryptable data. 809 // Server side encryption will not be applied due to undecryptable data.
820 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items. 810 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items.
821 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, 811 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0,
822 encrypted_bookmark); 812 encrypted_bookmark);
823 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, 813 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2,
824 encrypted_bookmark); 814 encrypted_bookmark);
825 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, 815 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1,
826 encrypted_bookmark); 816 encrypted_bookmark);
827 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, 817 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0,
828 encrypted_pref); 818 encrypted_pref);
829 SyncShareAsDelegate(); 819 SyncShareAsDelegate();
830 { 820 {
831 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
832 // All should be unapplied due to being undecryptable and have a valid 821 // All should be unapplied due to being undecryptable and have a valid
833 // BASE_SERVER_SPECIFICS. 822 // BASE_SERVER_SPECIFICS.
834 ReadTransaction rtrans(FROM_HERE, directory()); 823 ReadTransaction rtrans(FROM_HERE, directory());
835 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); 824 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans);
836 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); 825 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans);
837 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 826 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
838 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); 827 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans);
839 } 828 }
840 829
841 // Server side change that don't modify anything should not affect 830 // Server side change that don't modify anything should not affect
842 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). 831 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes).
843 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, 832 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0,
844 encrypted_bookmark); 833 encrypted_bookmark);
845 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, 834 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2,
846 encrypted_bookmark); 835 encrypted_bookmark);
847 // Item 3 doesn't change. 836 // Item 3 doesn't change.
848 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, 837 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0,
849 encrypted_pref); 838 encrypted_pref);
850 SyncShareAsDelegate(); 839 SyncShareAsDelegate();
851 { 840 {
852 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
853 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. 841 // Items 1, 2, and 4 should have newer server versions, 3 remains the same.
854 // All should remain unapplied due to be undecryptable. 842 // All should remain unapplied due to be undecryptable.
855 ReadTransaction rtrans(FROM_HERE, directory()); 843 ReadTransaction rtrans(FROM_HERE, directory());
856 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); 844 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans);
857 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 845 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
858 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 846 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
859 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 847 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
860 } 848 }
861 849
862 // Positional changes, parent changes, and specifics changes should reset 850 // Positional changes, parent changes, and specifics changes should reset
863 // BASE_SERVER_SPECIFICS. 851 // BASE_SERVER_SPECIFICS.
864 // Became unencrypted. 852 // Became unencrypted.
865 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark); 853 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark);
866 // Reordered to after item 2. 854 // Reordered to after item 2.
867 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, 855 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3,
868 encrypted_bookmark); 856 encrypted_bookmark);
869 SyncShareAsDelegate(); 857 SyncShareAsDelegate();
870 { 858 {
871 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
872 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. 859 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set.
873 // Items 1 is now unencrypted, so should have applied normally. 860 // Items 1 is now unencrypted, so should have applied normally.
874 ReadTransaction rtrans(FROM_HERE, directory()); 861 ReadTransaction rtrans(FROM_HERE, directory());
875 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); 862 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans);
876 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 863 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
877 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); 864 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans);
878 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 865 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
879 } 866 }
880 867
881 // Make local changes, which should remain unsynced for items 2, 3, 4. 868 // Make local changes, which should remain unsynced for items 2, 3, 4.
(...skipping 15 matching lines...) Expand all
897 C.Put(NON_UNIQUE_NAME, kEncryptedString); 884 C.Put(NON_UNIQUE_NAME, kEncryptedString);
898 C.Put(IS_UNSYNCED, true); 885 C.Put(IS_UNSYNCED, true);
899 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 886 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
900 ASSERT_TRUE(D.good()); 887 ASSERT_TRUE(D.good());
901 D.Put(SPECIFICS, modified_pref); 888 D.Put(SPECIFICS, modified_pref);
902 D.Put(NON_UNIQUE_NAME, kEncryptedString); 889 D.Put(NON_UNIQUE_NAME, kEncryptedString);
903 D.Put(IS_UNSYNCED, true); 890 D.Put(IS_UNSYNCED, true);
904 } 891 }
905 SyncShareAsDelegate(); 892 SyncShareAsDelegate();
906 { 893 {
907 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
908 // Item 1 remains unsynced due to there being pending keys. 894 // Item 1 remains unsynced due to there being pending keys.
909 // Items 2, 3, 4 should remain unsynced since they were not up to date. 895 // Items 2, 3, 4 should remain unsynced since they were not up to date.
910 ReadTransaction rtrans(FROM_HERE, directory()); 896 ReadTransaction rtrans(FROM_HERE, directory());
911 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); 897 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans);
912 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); 898 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans);
913 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); 899 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans);
914 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); 900 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans);
915 } 901 }
916 902
917 { 903 {
918 ReadTransaction rtrans(FROM_HERE, directory()); 904 ReadTransaction rtrans(FROM_HERE, directory());
919 // Resolve the pending keys. 905 // Resolve the pending keys.
920 cryptographer(&rtrans)->DecryptPendingKeys(key_params); 906 cryptographer(&rtrans)->DecryptPendingKeys(key_params);
921 } 907 }
922 // First cycle resolves conflicts, second cycle commits changes. 908 // First cycle resolves conflicts, second cycle commits changes.
923 SyncShareAsDelegate(); 909 SyncShareAsDelegate();
924 EXPECT_EQ(2, session_->status_controller().syncer_status(). 910 {
925 num_server_overwrites); 911 const StatusController& status_controller = session_->status_controller();
926 EXPECT_EQ(1, session_->status_controller().syncer_status(). 912 EXPECT_EQ(2, status_controller.syncer_status().num_server_overwrites);
927 num_local_overwrites); 913 EXPECT_EQ(1, status_controller.syncer_status().num_local_overwrites);
928 // We attempted to commit item 1. 914 EXPECT_EQ(status_controller.last_post_commit_result(), SYNCER_OK);
929 EXPECT_EQ(1U, session_->status_controller().unsynced_handles().size()); 915 }
930 EXPECT_TRUE(session_->status_controller().did_commit_items()); 916
931 SyncShareAsDelegate(); 917 SyncShareAsDelegate();
932 { 918 {
933 // Everything should be resolved now. The local changes should have 919 // Everything should be resolved now. The local changes should have
934 // overwritten the server changes for 2 and 4, while the server changes 920 // overwritten the server changes for 2 and 4, while the server changes
935 // overwrote the local for entry 3. 921 // overwrote the local for entry 3.
936 // We attempted to commit two handles. 922 const StatusController& status_controller = session_->status_controller();
937 EXPECT_EQ(0, session_->status_controller().syncer_status(). 923 EXPECT_EQ(0, status_controller.syncer_status().num_server_overwrites);
938 num_server_overwrites); 924 EXPECT_EQ(0, status_controller.syncer_status().num_local_overwrites);
939 EXPECT_EQ(0, session_->status_controller().syncer_status(). 925 EXPECT_EQ(status_controller.last_post_commit_result(), SYNCER_OK);
940 num_local_overwrites);
941 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size());
942 EXPECT_TRUE(session_->status_controller().did_commit_items());
943 ReadTransaction rtrans(FROM_HERE, directory()); 926 ReadTransaction rtrans(FROM_HERE, directory());
944 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); 927 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans);
945 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 928 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
946 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); 929 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans);
947 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); 930 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans);
948 } 931 }
949 } 932 }
950 933
951 #undef VERIFY_ENTRY 934 #undef VERIFY_ENTRY
952 935
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1149 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1167 parent.Put(syncable::BASE_VERSION, 1); 1150 parent.Put(syncable::BASE_VERSION, 1);
1168 parent.Put(syncable::ID, parent_id_); 1151 parent.Put(syncable::ID, parent_id_);
1169 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete"); 1152 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete");
1170 ASSERT_TRUE(child.good()); 1153 ASSERT_TRUE(child.good());
1171 child.Put(syncable::ID, child_id_); 1154 child.Put(syncable::ID, child_id_);
1172 child.Put(syncable::BASE_VERSION, 1); 1155 child.Put(syncable::BASE_VERSION, 1);
1173 WriteTestDataToEntry(&wtrans, &child); 1156 WriteTestDataToEntry(&wtrans, &child);
1174 } 1157 }
1175 1158
1176 const StatusController& status = session_->status_controller();
1177 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1159 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1178 EXPECT_EQ(2u, status.unsynced_handles().size());
1179 ASSERT_EQ(2u, mock_server_->committed_ids().size()); 1160 ASSERT_EQ(2u, mock_server_->committed_ids().size());
1180 // If this test starts failing, be aware other sort orders could be valid. 1161 // If this test starts failing, be aware other sort orders could be valid.
1181 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1162 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1182 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1163 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1183 { 1164 {
1184 ReadTransaction rt(FROM_HERE, directory()); 1165 ReadTransaction rt(FROM_HERE, directory());
1185 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1166 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1186 ASSERT_TRUE(entry.good()); 1167 ASSERT_TRUE(entry.good());
1187 VerifyTestDataInEntry(&rt, &entry); 1168 VerifyTestDataInEntry(&rt, &entry);
1188 } 1169 }
(...skipping 22 matching lines...) Expand all
1211 parent2.Put(syncable::IS_UNSYNCED, true); 1192 parent2.Put(syncable::IS_UNSYNCED, true);
1212 parent2.Put(syncable::IS_DIR, true); 1193 parent2.Put(syncable::IS_DIR, true);
1213 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics()); 1194 parent2.Put(syncable::SPECIFICS, DefaultPreferencesSpecifics());
1214 parent2.Put(syncable::BASE_VERSION, 1); 1195 parent2.Put(syncable::BASE_VERSION, 1);
1215 parent2.Put(syncable::ID, pref_node_id); 1196 parent2.Put(syncable::ID, pref_node_id);
1216 } 1197 }
1217 1198
1218 directory()->PurgeEntriesWithTypeIn( 1199 directory()->PurgeEntriesWithTypeIn(
1219 syncable::ModelTypeSet(syncable::PREFERENCES)); 1200 syncable::ModelTypeSet(syncable::PREFERENCES));
1220 1201
1221 const StatusController& status = session_->status_controller();
1222 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1202 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1223 EXPECT_EQ(2U, status.unsynced_handles().size());
1224 ASSERT_EQ(2U, mock_server_->committed_ids().size()); 1203 ASSERT_EQ(2U, mock_server_->committed_ids().size());
1225 // If this test starts failing, be aware other sort orders could be valid. 1204 // If this test starts failing, be aware other sort orders could be valid.
1226 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1205 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1227 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1206 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1228 { 1207 {
1229 ReadTransaction rt(FROM_HERE, directory()); 1208 ReadTransaction rt(FROM_HERE, directory());
1230 Entry entry(&rt, syncable::GET_BY_ID, child_id_); 1209 Entry entry(&rt, syncable::GET_BY_ID, child_id_);
1231 ASSERT_TRUE(entry.good()); 1210 ASSERT_TRUE(entry.good());
1232 VerifyTestDataInEntry(&rt, &entry); 1211 VerifyTestDataInEntry(&rt, &entry);
1233 } 1212 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 grandchild.Put(syncable::ID, ids_.FromNumber(105)); 1431 grandchild.Put(syncable::ID, ids_.FromNumber(105));
1453 grandchild.Put(syncable::IS_DEL, true); 1432 grandchild.Put(syncable::IS_DEL, true);
1454 grandchild.Put(syncable::IS_DIR, false); 1433 grandchild.Put(syncable::IS_DIR, false);
1455 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1434 grandchild.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1456 grandchild.Put(syncable::BASE_VERSION, 1); 1435 grandchild.Put(syncable::BASE_VERSION, 1);
1457 grandchild.Put(syncable::MTIME, now_minus_2h); 1436 grandchild.Put(syncable::MTIME, now_minus_2h);
1458 } 1437 }
1459 } 1438 }
1460 1439
1461 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1440 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1462 EXPECT_EQ(6u, session_->status_controller().unsynced_handles().size());
1463 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1441 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1464 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set. 1442 // This test will NOT unroll deletes because SERVER_PARENT_ID is not set.
1465 // It will treat these like moves. 1443 // It will treat these like moves.
1466 vector<syncable::Id> commit_ids(mock_server_->committed_ids()); 1444 vector<syncable::Id> commit_ids(mock_server_->committed_ids());
1467 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]); 1445 EXPECT_TRUE(ids_.FromNumber(100) == commit_ids[0]);
1468 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]); 1446 EXPECT_TRUE(ids_.FromNumber(101) == commit_ids[1]);
1469 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]); 1447 EXPECT_TRUE(ids_.FromNumber(102) == commit_ids[2]);
1470 // We don't guarantee the delete orders in this test, only that they occur 1448 // We don't guarantee the delete orders in this test, only that they occur
1471 // at the end. 1449 // at the end.
1472 std::sort(commit_ids.begin() + 3, commit_ids.end()); 1450 std::sort(commit_ids.begin() + 3, commit_ids.end());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B"); 1498 MutableEntry child(&wtrans, syncable::CREATE, child_id_, "B");
1521 ASSERT_TRUE(child.good()); 1499 ASSERT_TRUE(child.good());
1522 child.Put(syncable::IS_UNSYNCED, true); 1500 child.Put(syncable::IS_UNSYNCED, true);
1523 child.Put(syncable::IS_DIR, true); 1501 child.Put(syncable::IS_DIR, true);
1524 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1502 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1525 child.Put(syncable::ID, ids_.FromNumber(105)); 1503 child.Put(syncable::ID, ids_.FromNumber(105));
1526 child.Put(syncable::BASE_VERSION, 1); 1504 child.Put(syncable::BASE_VERSION, 1);
1527 } 1505 }
1528 1506
1529 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1507 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1530 EXPECT_EQ(6u, session_->status_controller().unsynced_handles().size());
1531 ASSERT_EQ(6u, mock_server_->committed_ids().size()); 1508 ASSERT_EQ(6u, mock_server_->committed_ids().size());
1532 // If this test starts failing, be aware other sort orders could be valid. 1509 // If this test starts failing, be aware other sort orders could be valid.
1533 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1510 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1534 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1511 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1535 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]); 1512 EXPECT_TRUE(ids_.FromNumber(102) == mock_server_->committed_ids()[2]);
1536 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]); 1513 EXPECT_TRUE(ids_.FromNumber(-103) == mock_server_->committed_ids()[3]);
1537 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]); 1514 EXPECT_TRUE(ids_.FromNumber(-104) == mock_server_->committed_ids()[4]);
1538 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]); 1515 EXPECT_TRUE(ids_.FromNumber(105) == mock_server_->committed_ids()[5]);
1539 } 1516 }
1540 1517
(...skipping 18 matching lines...) Expand all
1559 child2.Put(syncable::IS_UNSYNCED, true); 1536 child2.Put(syncable::IS_UNSYNCED, true);
1560 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1537 child2.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1561 child2.Put(syncable::ID, child2_id); 1538 child2.Put(syncable::ID, child2_id);
1562 1539
1563 parent.Put(syncable::BASE_VERSION, 1); 1540 parent.Put(syncable::BASE_VERSION, 1);
1564 child1.Put(syncable::BASE_VERSION, 1); 1541 child1.Put(syncable::BASE_VERSION, 1);
1565 child2.Put(syncable::BASE_VERSION, 1); 1542 child2.Put(syncable::BASE_VERSION, 1);
1566 } 1543 }
1567 1544
1568 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1545 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1569 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1570 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1546 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1571 // If this test starts failing, be aware other sort orders could be valid. 1547 // If this test starts failing, be aware other sort orders could be valid.
1572 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1548 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1573 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]); 1549 EXPECT_TRUE(child_id_ == mock_server_->committed_ids()[1]);
1574 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]); 1550 EXPECT_TRUE(child2_id == mock_server_->committed_ids()[2]);
1575 } 1551 }
1576 1552
1577 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) { 1553 TEST_F(SyncerTest, TestCommitListOrderingAndNewParent) {
1578 string parent1_name = "1"; 1554 string parent1_name = "1";
1579 string parent2_name = "A"; 1555 string parent2_name = "A";
(...skipping 25 matching lines...) Expand all
1605 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name); 1581 MutableEntry child(&wtrans, syncable::CREATE, parent2_id, child_name);
1606 ASSERT_TRUE(child.good()); 1582 ASSERT_TRUE(child.good());
1607 child.Put(syncable::IS_UNSYNCED, true); 1583 child.Put(syncable::IS_UNSYNCED, true);
1608 child.Put(syncable::IS_DIR, true); 1584 child.Put(syncable::IS_DIR, true);
1609 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1585 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1610 child.Put(syncable::ID, child_id); 1586 child.Put(syncable::ID, child_id);
1611 child.Put(syncable::BASE_VERSION, 1); 1587 child.Put(syncable::BASE_VERSION, 1);
1612 } 1588 }
1613 1589
1614 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1590 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1615 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1616 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1591 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1617 // If this test starts failing, be aware other sort orders could be valid. 1592 // If this test starts failing, be aware other sort orders could be valid.
1618 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1593 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1619 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]); 1594 EXPECT_TRUE(parent2_id == mock_server_->committed_ids()[1]);
1620 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]); 1595 EXPECT_TRUE(child_id == mock_server_->committed_ids()[2]);
1621 { 1596 {
1622 ReadTransaction rtrans(FROM_HERE, directory()); 1597 ReadTransaction rtrans(FROM_HERE, directory());
1623 // Check that things committed correctly. 1598 // Check that things committed correctly.
1624 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_); 1599 Entry entry_1(&rtrans, syncable::GET_BY_ID, parent_id_);
1625 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name); 1600 EXPECT_EQ(entry_1.Get(NON_UNIQUE_NAME), parent1_name);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name); 1651 MutableEntry child(&wtrans, syncable::CREATE, parent2_local_id, child_name);
1677 ASSERT_TRUE(child.good()); 1652 ASSERT_TRUE(child.good());
1678 child.Put(syncable::IS_UNSYNCED, true); 1653 child.Put(syncable::IS_UNSYNCED, true);
1679 child.Put(syncable::IS_DIR, true); 1654 child.Put(syncable::IS_DIR, true);
1680 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 1655 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
1681 child.Put(syncable::ID, child_local_id); 1656 child.Put(syncable::ID, child_local_id);
1682 meta_handle_b = child.Get(syncable::META_HANDLE); 1657 meta_handle_b = child.Get(syncable::META_HANDLE);
1683 } 1658 }
1684 1659
1685 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 1660 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
1686 EXPECT_EQ(3u, session_->status_controller().unsynced_handles().size());
1687 ASSERT_EQ(3u, mock_server_->committed_ids().size()); 1661 ASSERT_EQ(3u, mock_server_->committed_ids().size());
1688 // If this test starts failing, be aware other sort orders could be valid. 1662 // If this test starts failing, be aware other sort orders could be valid.
1689 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]); 1663 EXPECT_TRUE(parent_id_ == mock_server_->committed_ids()[0]);
1690 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]); 1664 EXPECT_TRUE(parent2_local_id == mock_server_->committed_ids()[1]);
1691 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]); 1665 EXPECT_TRUE(child_local_id == mock_server_->committed_ids()[2]);
1692 { 1666 {
1693 ReadTransaction rtrans(FROM_HERE, directory()); 1667 ReadTransaction rtrans(FROM_HERE, directory());
1694 1668
1695 Entry parent(&rtrans, syncable::GET_BY_ID, 1669 Entry parent(&rtrans, syncable::GET_BY_ID,
1696 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name)); 1670 GetOnlyEntryWithName(&rtrans, rtrans.root_id(), parent_name));
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 "bob"); 2275 "bob");
2302 ASSERT_TRUE(entry.good()); 2276 ASSERT_TRUE(entry.good());
2303 entry.Put(syncable::IS_DIR, true); 2277 entry.Put(syncable::IS_DIR, true);
2304 entry.Put(syncable::IS_UNSYNCED, true); 2278 entry.Put(syncable::IS_UNSYNCED, true);
2305 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2279 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2306 } 2280 }
2307 2281
2308 mock_server_->SetMidCommitCallback( 2282 mock_server_->SetMidCommitCallback(
2309 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2283 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2310 base::Unretained(this))); 2284 base::Unretained(this)));
2311 syncer_->SyncShare(session_.get(), BUILD_COMMIT_REQUEST, SYNCER_END); 2285 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END);
2312 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2286 // We loop until no unsynced handles remain, so we will commit both ids.
2287 EXPECT_EQ(2u, mock_server_->committed_ids().size());
2313 { 2288 {
2314 ReadTransaction trans(FROM_HERE, directory()); 2289 ReadTransaction trans(FROM_HERE, directory());
2315 Entry parent_entry(&trans, syncable::GET_BY_ID, 2290 Entry parent_entry(&trans, syncable::GET_BY_ID,
2316 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2291 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2317 ASSERT_TRUE(parent_entry.good()); 2292 ASSERT_TRUE(parent_entry.good());
2318 2293
2319 Id child_id = 2294 Id child_id =
2320 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 2295 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
2321 Entry child(&trans, syncable::GET_BY_ID, child_id); 2296 Entry child(&trans, syncable::GET_BY_ID, child_id);
2322 ASSERT_TRUE(child.good()); 2297 ASSERT_TRUE(child.good());
2323 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); 2298 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID));
2324 } 2299 }
2325 } 2300 }
2326 2301
2327 TEST_F(SyncerTest, NegativeIDInUpdate) { 2302 TEST_F(SyncerTest, NegativeIDInUpdate) {
2328 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); 2303 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40);
2329 SyncShareAsDelegate(); 2304 SyncShareAsDelegate();
2330 // The negative id would make us CHECK! 2305 // The negative id would make us CHECK!
2331 } 2306 }
2332 2307
2333 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2308 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2334 int64 metahandle_fred; 2309 int64 metahandle_fred;
(...skipping 1773 matching lines...) Expand 10 before | Expand all | Expand 10 after
4108 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4083 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4109 ExpectSyncedAndCreated(); 4084 ExpectSyncedAndCreated();
4110 4085
4111 // Delete, begin committing the delete, then undelete while committing. 4086 // Delete, begin committing the delete, then undelete while committing.
4112 Delete(); 4087 Delete();
4113 ExpectUnsyncedDeletion(); 4088 ExpectUnsyncedDeletion();
4114 mock_server_->SetMidCommitCallback( 4089 mock_server_->SetMidCommitCallback(
4115 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this))); 4090 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this)));
4116 SyncShareAsDelegate(); 4091 SyncShareAsDelegate();
4117 4092
4118 // The item ought to exist as an unsynced undeletion (meaning, 4093 // We will continue to commit until all nodes are synced, so we expect
4119 // we think that the next commit ought to be a recreation commit). 4094 // that both the delete and following undelete were committed. We haven't
4095 // downloaded any updates, though, so the SERVER fields will be the same
4096 // as they were at the start of the cycle.
4120 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4097 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4121 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4098 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4122 ExpectUnsyncedUndeletion(); 4099
4100 // Server fields lag behind.
4101 EXPECT_FALSE(Get(metahandle_, SERVER_IS_DEL));
4102
4103 // We have committed the second (undelete) update.
4104 EXPECT_FALSE(Get(metahandle_, IS_DEL));
4105 EXPECT_FALSE(Get(metahandle_, IS_UNSYNCED));
4106 EXPECT_FALSE(Get(metahandle_, IS_UNAPPLIED_UPDATE));
4123 4107
4124 // Now, encounter a GetUpdates corresponding to the deletion from 4108 // Now, encounter a GetUpdates corresponding to the deletion from
4125 // the server. The undeletion should prevail again and be committed. 4109 // the server. The undeletion should prevail again and be committed.
4126 // None of this should trigger any conflict detection -- it is perfectly 4110 // None of this should trigger any conflict detection -- it is perfectly
4127 // normal to recieve updates from our own commits. 4111 // normal to recieve updates from our own commits.
4128 mock_server_->SetMidCommitCallback(base::Closure()); 4112 mock_server_->SetMidCommitCallback(base::Closure());
4129 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); 4113 mock_server_->AddUpdateFromLastCommit();
4130 SyncShareAsDelegate(); 4114 SyncShareAsDelegate();
4131 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4115 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4132 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4116 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4133 ExpectSyncedAndCreated(); 4117 ExpectSyncedAndCreated();
4134 } 4118 }
4135 4119
4136 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { 4120 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) {
4137 Create(); 4121 Create();
4138 ExpectUnsyncedCreation(); 4122 ExpectUnsyncedCreation();
4139 SyncShareAsDelegate(); 4123 SyncShareAsDelegate();
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
4613 4597
4614 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4598 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4615 Add(mid_id_); 4599 Add(mid_id_);
4616 Add(low_id_); 4600 Add(low_id_);
4617 Add(high_id_); 4601 Add(high_id_);
4618 SyncShareAsDelegate(); 4602 SyncShareAsDelegate();
4619 ExpectLocalOrderIsByServerId(); 4603 ExpectLocalOrderIsByServerId();
4620 } 4604 }
4621 4605
4622 } // namespace browser_sync 4606 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698