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

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

Issue 10006046: Abort sync cycles when download step fails (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Retry on migration done responses 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
« no previous file with comments | « sync/engine/syncer.cc ('k') | sync/sessions/status_controller.h » ('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 15 matching lines...) Expand all
26 #include "sync/engine/get_commit_ids_command.h" 26 #include "sync/engine/get_commit_ids_command.h"
27 #include "sync/engine/model_safe_worker.h" 27 #include "sync/engine/model_safe_worker.h"
28 #include "sync/engine/net/server_connection_manager.h" 28 #include "sync/engine/net/server_connection_manager.h"
29 #include "sync/engine/nigori_util.h" 29 #include "sync/engine/nigori_util.h"
30 #include "sync/engine/process_updates_command.h" 30 #include "sync/engine/process_updates_command.h"
31 #include "sync/engine/syncer.h" 31 #include "sync/engine/syncer.h"
32 #include "sync/engine/syncer_proto_util.h" 32 #include "sync/engine/syncer_proto_util.h"
33 #include "sync/engine/syncer_util.h" 33 #include "sync/engine/syncer_util.h"
34 #include "sync/engine/syncproto.h" 34 #include "sync/engine/syncproto.h"
35 #include "sync/engine/traffic_recorder.h" 35 #include "sync/engine/traffic_recorder.h"
36 #include "sync/engine/sync_scheduler.h"
36 #include "sync/protocol/bookmark_specifics.pb.h" 37 #include "sync/protocol/bookmark_specifics.pb.h"
37 #include "sync/protocol/nigori_specifics.pb.h" 38 #include "sync/protocol/nigori_specifics.pb.h"
38 #include "sync/protocol/preference_specifics.pb.h" 39 #include "sync/protocol/preference_specifics.pb.h"
39 #include "sync/protocol/sync.pb.h" 40 #include "sync/protocol/sync.pb.h"
40 #include "sync/sessions/sync_session_context.h" 41 #include "sync/sessions/sync_session_context.h"
41 #include "sync/syncable/model_type.h" 42 #include "sync/syncable/model_type.h"
42 #include "sync/syncable/syncable.h" 43 #include "sync/syncable/syncable.h"
43 #include "sync/test/engine/fake_model_worker.h" 44 #include "sync/test/engine/fake_model_worker.h"
44 #include "sync/test/engine/mock_connection_manager.h" 45 #include "sync/test/engine/mock_connection_manager.h"
45 #include "sync/test/engine/test_directory_setter_upper.h" 46 #include "sync/test/engine/test_directory_setter_upper.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 std::vector<ModelSafeWorker*> workers; 180 std::vector<ModelSafeWorker*> workers;
180 GetModelSafeRoutingInfo(&info); 181 GetModelSafeRoutingInfo(&info);
181 GetWorkers(&workers); 182 GetWorkers(&workers);
182 syncable::ModelTypePayloadMap types = 183 syncable::ModelTypePayloadMap types =
183 syncable::ModelTypePayloadMapFromRoutingInfo(info, std::string()); 184 syncable::ModelTypePayloadMapFromRoutingInfo(info, std::string());
184 return new SyncSession(context_.get(), this, 185 return new SyncSession(context_.get(), this,
185 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), 186 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types),
186 info, workers); 187 info, workers);
187 } 188 }
188 189
189 bool SyncShareAsDelegate() { 190 bool SyncShareAsDelegate(
191 SyncScheduler::SyncSessionJob::SyncSessionJobPurpose purpose) {
192 SyncerStep start;
193 SyncerStep end;
194 SyncScheduler::SetSyncerStepsForPurpose(purpose, &start, &end);
195
190 session_.reset(MakeSession()); 196 session_.reset(MakeSession());
191 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 197 syncer_->SyncShare(session_.get(), start, end);
192 return session_->HasMoreToSync(); 198 return session_->HasMoreToSync();
193 } 199 }
194 200
201 bool SyncShareNudge() {
202 session_.reset(MakeSession());
203 return SyncShareAsDelegate(SyncScheduler::SyncSessionJob::NUDGE);
204 }
205
206 bool SyncShareConfigure() {
207 session_.reset(MakeSession());
208 return SyncShareAsDelegate(SyncScheduler::SyncSessionJob::CONFIGURATION);
209 }
210
195 void LoopSyncShare() { 211 void LoopSyncShare() {
196 bool should_loop = false; 212 bool should_loop = false;
197 int loop_iterations = 0; 213 int loop_iterations = 0;
198 do { 214 do {
199 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; 215 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix";
200 should_loop = SyncShareAsDelegate(); 216 should_loop = SyncShareNudge();
201 } while (should_loop); 217 } while (should_loop);
202 } 218 }
203 219
204 virtual void SetUp() { 220 virtual void SetUp() {
205 dir_maker_.SetUp(); 221 dir_maker_.SetUp();
206 mock_server_.reset(new MockConnectionManager(directory())); 222 mock_server_.reset(new MockConnectionManager(directory()));
207 EnableDatatype(syncable::BOOKMARKS); 223 EnableDatatype(syncable::BOOKMARKS);
208 EnableDatatype(syncable::NIGORI); 224 EnableDatatype(syncable::NIGORI);
209 EnableDatatype(syncable::PREFERENCES); 225 EnableDatatype(syncable::PREFERENCES);
210 EnableDatatype(syncable::NIGORI); 226 EnableDatatype(syncable::NIGORI);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // TODO(sync): When we can dynamically connect and disconnect the mock 551 // TODO(sync): When we can dynamically connect and disconnect the mock
536 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a 552 // ServerConnectionManager test disconnected GetUnsyncedEntries here. It's a
537 // regression for a very old bug. 553 // regression for a very old bug.
538 } 554 }
539 555
540 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) { 556 TEST_F(SyncerTest, GetCommitIdsCommandTruncates) {
541 syncable::Id root = ids_.root(); 557 syncable::Id root = ids_.root();
542 // Create two server entries. 558 // Create two server entries.
543 mock_server_->AddUpdateDirectory(ids_.MakeServer("x"), root, "X", 10, 10); 559 mock_server_->AddUpdateDirectory(ids_.MakeServer("x"), root, "X", 10, 10);
544 mock_server_->AddUpdateDirectory(ids_.MakeServer("w"), root, "W", 10, 10); 560 mock_server_->AddUpdateDirectory(ids_.MakeServer("w"), root, "W", 10, 10);
545 SyncShareAsDelegate(); 561 SyncShareNudge();
546 562
547 // Create some new client entries. 563 // Create some new client entries.
548 CreateUnsyncedDirectory("C", ids_.MakeLocal("c")); 564 CreateUnsyncedDirectory("C", ids_.MakeLocal("c"));
549 CreateUnsyncedDirectory("B", ids_.MakeLocal("b")); 565 CreateUnsyncedDirectory("B", ids_.MakeLocal("b"));
550 CreateUnsyncedDirectory("D", ids_.MakeLocal("d")); 566 CreateUnsyncedDirectory("D", ids_.MakeLocal("d"));
551 CreateUnsyncedDirectory("E", ids_.MakeLocal("e")); 567 CreateUnsyncedDirectory("E", ids_.MakeLocal("e"));
552 CreateUnsyncedDirectory("J", ids_.MakeLocal("j")); 568 CreateUnsyncedDirectory("J", ids_.MakeLocal("j"));
553 569
554 { 570 {
555 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 571 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 expected_order.push_back(ids_.MakeLocal("e")); 605 expected_order.push_back(ids_.MakeLocal("e"));
590 DoTruncationTest(unsynced_handle_view, expected_order); 606 DoTruncationTest(unsynced_handle_view, expected_order);
591 } 607 }
592 608
593 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { 609 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
594 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS); 610 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS);
595 sync_pb::EntitySpecifics bookmark_data; 611 sync_pb::EntitySpecifics bookmark_data;
596 AddDefaultFieldValue(syncable::BOOKMARKS, &bookmark_data); 612 AddDefaultFieldValue(syncable::BOOKMARKS, &bookmark_data);
597 613
598 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 614 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
599 SyncShareAsDelegate(); 615 SyncShareNudge();
600 616
601 { 617 {
602 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 618 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
603 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 619 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
604 ASSERT_TRUE(A.good()); 620 ASSERT_TRUE(A.good());
605 A.Put(IS_UNSYNCED, true); 621 A.Put(IS_UNSYNCED, true);
606 A.Put(SPECIFICS, bookmark_data); 622 A.Put(SPECIFICS, bookmark_data);
607 A.Put(NON_UNIQUE_NAME, "bookmark"); 623 A.Put(NON_UNIQUE_NAME, "bookmark");
608 } 624 }
609 625
610 // Now set the throttled types. 626 // Now set the throttled types.
611 context_->SetUnthrottleTime( 627 context_->SetUnthrottleTime(
612 throttled_types, 628 throttled_types,
613 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200)); 629 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1200));
614 SyncShareAsDelegate(); 630 SyncShareNudge();
615 631
616 { 632 {
617 // Nothing should have been committed as bookmarks is throttled. 633 // Nothing should have been committed as bookmarks is throttled.
618 ReadTransaction rtrans(FROM_HERE, directory()); 634 ReadTransaction rtrans(FROM_HERE, directory());
619 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 635 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
620 ASSERT_TRUE(entryA.good()); 636 ASSERT_TRUE(entryA.good());
621 EXPECT_TRUE(entryA.Get(IS_UNSYNCED)); 637 EXPECT_TRUE(entryA.Get(IS_UNSYNCED));
622 } 638 }
623 639
624 // Now unthrottle. 640 // Now unthrottle.
625 context_->SetUnthrottleTime( 641 context_->SetUnthrottleTime(
626 throttled_types, 642 throttled_types,
627 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200)); 643 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1200));
628 SyncShareAsDelegate(); 644 SyncShareNudge();
629 { 645 {
630 // It should have been committed. 646 // It should have been committed.
631 ReadTransaction rtrans(FROM_HERE, directory()); 647 ReadTransaction rtrans(FROM_HERE, directory());
632 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 648 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
633 ASSERT_TRUE(entryA.good()); 649 ASSERT_TRUE(entryA.good());
634 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); 650 EXPECT_FALSE(entryA.Get(IS_UNSYNCED));
635 } 651 }
636 } 652 }
637 653
638 // We use a macro so we can preserve the error location. 654 // We use a macro so we can preserve the error location.
(...skipping 19 matching lines...) Expand all
658 KeyParams key_params = {"localhost", "dummy", "foobar"}; 674 KeyParams key_params = {"localhost", "dummy", "foobar"};
659 KeyParams other_params = {"localhost", "dummy", "foobar2"}; 675 KeyParams other_params = {"localhost", "dummy", "foobar2"};
660 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; 676 sync_pb::EntitySpecifics bookmark, encrypted_bookmark;
661 bookmark.mutable_bookmark()->set_url("url"); 677 bookmark.mutable_bookmark()->set_url("url");
662 bookmark.mutable_bookmark()->set_title("title"); 678 bookmark.mutable_bookmark()->set_title("title");
663 AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark); 679 AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark);
664 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 680 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
665 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 681 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
666 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); 682 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10);
667 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); 683 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10);
668 SyncShareAsDelegate(); 684 SyncShareNudge();
669 // Server side change will put A in conflict. 685 // Server side change will put A in conflict.
670 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); 686 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20);
671 { 687 {
672 // Mark bookmarks as encrypted and set the cryptographer to have pending 688 // Mark bookmarks as encrypted and set the cryptographer to have pending
673 // keys. 689 // keys.
674 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 690 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
675 browser_sync::Cryptographer other_cryptographer(&encryptor_); 691 browser_sync::Cryptographer other_cryptographer(&encryptor_);
676 other_cryptographer.AddKey(other_params); 692 other_cryptographer.AddKey(other_params);
677 sync_pb::EntitySpecifics specifics; 693 sync_pb::EntitySpecifics specifics;
678 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 694 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
(...skipping 22 matching lines...) Expand all
701 ASSERT_TRUE(C.good()); 717 ASSERT_TRUE(C.good());
702 C.Put(IS_UNSYNCED, true); 718 C.Put(IS_UNSYNCED, true);
703 C.Put(NON_UNIQUE_NAME, kEncryptedString); 719 C.Put(NON_UNIQUE_NAME, kEncryptedString);
704 // Unencrypted non_unique_name. 720 // Unencrypted non_unique_name.
705 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 721 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
706 ASSERT_TRUE(D.good()); 722 ASSERT_TRUE(D.good());
707 D.Put(IS_UNSYNCED, true); 723 D.Put(IS_UNSYNCED, true);
708 D.Put(SPECIFICS, encrypted_bookmark); 724 D.Put(SPECIFICS, encrypted_bookmark);
709 D.Put(NON_UNIQUE_NAME, "not encrypted"); 725 D.Put(NON_UNIQUE_NAME, "not encrypted");
710 } 726 }
711 SyncShareAsDelegate(); 727 SyncShareNudge();
712 { 728 {
713 // We remove any unready entries from the status controller's unsynced 729 // 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. 730 // handles, so this should remain 0 even though the entries didn't commit.
715 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); 731 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
716 // Nothing should have commited due to bookmarks being encrypted and 732 // Nothing should have commited due to bookmarks being encrypted and
717 // the cryptographer having pending keys. A would have been resolved 733 // the cryptographer having pending keys. A would have been resolved
718 // 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.
719 ReadTransaction rtrans(FROM_HERE, directory()); 735 ReadTransaction rtrans(FROM_HERE, directory());
720 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); 736 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans);
721 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); 737 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans);
722 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 738 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
723 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 739 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
724 740
725 // Resolve the pending keys. 741 // Resolve the pending keys.
726 cryptographer(&rtrans)->DecryptPendingKeys(other_params); 742 cryptographer(&rtrans)->DecryptPendingKeys(other_params);
727 } 743 }
728 SyncShareAsDelegate(); 744 SyncShareNudge();
729 { 745 {
730 // 2 unsynced handles to reflect the items that committed succesfully. 746 // 2 unsynced handles to reflect the items that committed succesfully.
731 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 747 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size());
732 // All properly encrypted and non-conflicting items should commit. "A" was 748 // All properly encrypted and non-conflicting items should commit. "A" was
733 // conflicting, but last sync cycle resolved it as simple conflict, so on 749 // conflicting, but last sync cycle resolved it as simple conflict, so on
734 // this sync cycle it committed succesfullly. 750 // this sync cycle it committed succesfullly.
735 ReadTransaction rtrans(FROM_HERE, directory()); 751 ReadTransaction rtrans(FROM_HERE, directory());
736 // Committed successfully. 752 // Committed successfully.
737 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 753 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
738 // Committed successfully. 754 // Committed successfully.
739 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 755 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
740 // Was not properly encrypted. 756 // Was not properly encrypted.
741 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); 757 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans);
742 // Was not properly encrypted. 758 // Was not properly encrypted.
743 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); 759 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans);
744 } 760 }
745 { 761 {
746 // Fix the remaining items. 762 // Fix the remaining items.
747 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 763 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
748 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); 764 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
749 ASSERT_TRUE(C.good()); 765 ASSERT_TRUE(C.good());
750 C.Put(SPECIFICS, encrypted_bookmark); 766 C.Put(SPECIFICS, encrypted_bookmark);
751 C.Put(NON_UNIQUE_NAME, kEncryptedString); 767 C.Put(NON_UNIQUE_NAME, kEncryptedString);
752 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 768 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
753 ASSERT_TRUE(D.good()); 769 ASSERT_TRUE(D.good());
754 D.Put(SPECIFICS, encrypted_bookmark); 770 D.Put(SPECIFICS, encrypted_bookmark);
755 D.Put(NON_UNIQUE_NAME, kEncryptedString); 771 D.Put(NON_UNIQUE_NAME, kEncryptedString);
756 } 772 }
757 SyncShareAsDelegate(); 773 SyncShareNudge();
758 { 774 {
759 // We attempted to commit two items. 775 // We attempted to commit two items.
760 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 776 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size());
761 EXPECT_TRUE(session_->status_controller().did_commit_items()); 777 EXPECT_TRUE(session_->status_controller().did_commit_items());
762 // None should be unsynced anymore. 778 // None should be unsynced anymore.
763 ReadTransaction rtrans(FROM_HERE, directory()); 779 ReadTransaction rtrans(FROM_HERE, directory());
764 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); 780 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans);
765 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); 781 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans);
766 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); 782 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans);
767 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); 783 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans);
(...skipping 30 matching lines...) Expand all
798 nigori->set_encrypt_bookmarks(true); 814 nigori->set_encrypt_bookmarks(true);
799 nigori->set_encrypt_preferences(true); 815 nigori->set_encrypt_preferences(true);
800 cryptographer(&wtrans)->Update(*nigori); 816 cryptographer(&wtrans)->Update(*nigori);
801 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 817 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
802 } 818 }
803 819
804 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 820 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
805 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 821 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
806 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 822 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
807 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); 823 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
808 SyncShareAsDelegate(); 824 SyncShareNudge();
809 { 825 {
810 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); 826 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
811 // Initial state. Everything is normal. 827 // Initial state. Everything is normal.
812 ReadTransaction rtrans(FROM_HERE, directory()); 828 ReadTransaction rtrans(FROM_HERE, directory());
813 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 829 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
814 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 830 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
815 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 831 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
816 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 832 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
817 } 833 }
818 834
819 // Server side encryption will not be applied due to undecryptable data. 835 // 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. 836 // At this point, BASE_SERVER_SPECIFICS should be filled for all four items.
821 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, 837 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0,
822 encrypted_bookmark); 838 encrypted_bookmark);
823 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, 839 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2,
824 encrypted_bookmark); 840 encrypted_bookmark);
825 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, 841 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1,
826 encrypted_bookmark); 842 encrypted_bookmark);
827 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, 843 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0,
828 encrypted_pref); 844 encrypted_pref);
829 SyncShareAsDelegate(); 845 SyncShareNudge();
830 { 846 {
831 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); 847 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
832 // All should be unapplied due to being undecryptable and have a valid 848 // All should be unapplied due to being undecryptable and have a valid
833 // BASE_SERVER_SPECIFICS. 849 // BASE_SERVER_SPECIFICS.
834 ReadTransaction rtrans(FROM_HERE, directory()); 850 ReadTransaction rtrans(FROM_HERE, directory());
835 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); 851 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans);
836 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); 852 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans);
837 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 853 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
838 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); 854 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans);
839 } 855 }
840 856
841 // Server side change that don't modify anything should not affect 857 // Server side change that don't modify anything should not affect
842 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes). 858 // BASE_SERVER_SPECIFICS (such as name changes and mtime changes).
843 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, 859 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0,
844 encrypted_bookmark); 860 encrypted_bookmark);
845 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, 861 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2,
846 encrypted_bookmark); 862 encrypted_bookmark);
847 // Item 3 doesn't change. 863 // Item 3 doesn't change.
848 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, 864 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0,
849 encrypted_pref); 865 encrypted_pref);
850 SyncShareAsDelegate(); 866 SyncShareNudge();
851 { 867 {
852 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); 868 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
853 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. 869 // Items 1, 2, and 4 should have newer server versions, 3 remains the same.
854 // All should remain unapplied due to be undecryptable. 870 // All should remain unapplied due to be undecryptable.
855 ReadTransaction rtrans(FROM_HERE, directory()); 871 ReadTransaction rtrans(FROM_HERE, directory());
856 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); 872 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans);
857 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 873 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
858 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); 874 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans);
859 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 875 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
860 } 876 }
861 877
862 // Positional changes, parent changes, and specifics changes should reset 878 // Positional changes, parent changes, and specifics changes should reset
863 // BASE_SERVER_SPECIFICS. 879 // BASE_SERVER_SPECIFICS.
864 // Became unencrypted. 880 // Became unencrypted.
865 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark); 881 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark);
866 // Reordered to after item 2. 882 // Reordered to after item 2.
867 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, 883 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3,
868 encrypted_bookmark); 884 encrypted_bookmark);
869 SyncShareAsDelegate(); 885 SyncShareNudge();
870 { 886 {
871 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); 887 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
872 // Items 2 and 4 should be the only ones with BASE_SERVER_SPECIFICS set. 888 // 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. 889 // Items 1 is now unencrypted, so should have applied normally.
874 ReadTransaction rtrans(FROM_HERE, directory()); 890 ReadTransaction rtrans(FROM_HERE, directory());
875 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); 891 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans);
876 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); 892 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans);
877 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); 893 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans);
878 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); 894 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans);
879 } 895 }
(...skipping 15 matching lines...) Expand all
895 ASSERT_TRUE(C.good()); 911 ASSERT_TRUE(C.good());
896 C.Put(SPECIFICS, modified_bookmark); 912 C.Put(SPECIFICS, modified_bookmark);
897 C.Put(NON_UNIQUE_NAME, kEncryptedString); 913 C.Put(NON_UNIQUE_NAME, kEncryptedString);
898 C.Put(IS_UNSYNCED, true); 914 C.Put(IS_UNSYNCED, true);
899 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); 915 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
900 ASSERT_TRUE(D.good()); 916 ASSERT_TRUE(D.good());
901 D.Put(SPECIFICS, modified_pref); 917 D.Put(SPECIFICS, modified_pref);
902 D.Put(NON_UNIQUE_NAME, kEncryptedString); 918 D.Put(NON_UNIQUE_NAME, kEncryptedString);
903 D.Put(IS_UNSYNCED, true); 919 D.Put(IS_UNSYNCED, true);
904 } 920 }
905 SyncShareAsDelegate(); 921 SyncShareNudge();
906 { 922 {
907 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); 923 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size());
908 // Item 1 remains unsynced due to there being pending keys. 924 // 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. 925 // Items 2, 3, 4 should remain unsynced since they were not up to date.
910 ReadTransaction rtrans(FROM_HERE, directory()); 926 ReadTransaction rtrans(FROM_HERE, directory());
911 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); 927 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans);
912 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); 928 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans);
913 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); 929 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans);
914 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); 930 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans);
915 } 931 }
916 932
917 { 933 {
918 ReadTransaction rtrans(FROM_HERE, directory()); 934 ReadTransaction rtrans(FROM_HERE, directory());
919 // Resolve the pending keys. 935 // Resolve the pending keys.
920 cryptographer(&rtrans)->DecryptPendingKeys(key_params); 936 cryptographer(&rtrans)->DecryptPendingKeys(key_params);
921 } 937 }
922 // First cycle resolves conflicts, second cycle commits changes. 938 // First cycle resolves conflicts, second cycle commits changes.
923 SyncShareAsDelegate(); 939 SyncShareNudge();
924 EXPECT_EQ(2, session_->status_controller().syncer_status(). 940 EXPECT_EQ(2, session_->status_controller().syncer_status().
925 num_server_overwrites); 941 num_server_overwrites);
926 EXPECT_EQ(1, session_->status_controller().syncer_status(). 942 EXPECT_EQ(1, session_->status_controller().syncer_status().
927 num_local_overwrites); 943 num_local_overwrites);
928 // We attempted to commit item 1. 944 // We attempted to commit item 1.
929 EXPECT_EQ(1U, session_->status_controller().unsynced_handles().size()); 945 EXPECT_EQ(1U, session_->status_controller().unsynced_handles().size());
930 EXPECT_TRUE(session_->status_controller().did_commit_items()); 946 EXPECT_TRUE(session_->status_controller().did_commit_items());
931 SyncShareAsDelegate(); 947 SyncShareNudge();
932 { 948 {
933 // Everything should be resolved now. The local changes should have 949 // Everything should be resolved now. The local changes should have
934 // overwritten the server changes for 2 and 4, while the server changes 950 // overwritten the server changes for 2 and 4, while the server changes
935 // overwrote the local for entry 3. 951 // overwrote the local for entry 3.
936 // We attempted to commit two handles. 952 // We attempted to commit two handles.
937 EXPECT_EQ(0, session_->status_controller().syncer_status(). 953 EXPECT_EQ(0, session_->status_controller().syncer_status().
938 num_server_overwrites); 954 num_server_overwrites);
939 EXPECT_EQ(0, session_->status_controller().syncer_status(). 955 EXPECT_EQ(0, session_->status_controller().syncer_status().
940 num_local_overwrites); 956 num_local_overwrites);
941 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); 957 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size());
(...skipping 24 matching lines...) Expand all
966 other_encrypted_specifics.mutable_encrypted()); 982 other_encrypted_specifics.mutable_encrypted());
967 sync_pb::EntitySpecifics our_encrypted_specifics; 983 sync_pb::EntitySpecifics our_encrypted_specifics;
968 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); 984 our_encrypted_specifics.mutable_bookmark()->set_title("title2");
969 syncable::ModelTypeSet encrypted_types = syncable::ModelTypeSet::All(); 985 syncable::ModelTypeSet encrypted_types = syncable::ModelTypeSet::All();
970 986
971 987
972 // Receive the initial nigori node. 988 // Receive the initial nigori node.
973 sync_pb::EntitySpecifics initial_nigori_specifics; 989 sync_pb::EntitySpecifics initial_nigori_specifics;
974 initial_nigori_specifics.mutable_nigori(); 990 initial_nigori_specifics.mutable_nigori();
975 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); 991 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics);
976 SyncShareAsDelegate(); 992 SyncShareNudge();
977 993
978 { 994 {
979 // Set up the current nigori node (containing both keys and encrypt 995 // Set up the current nigori node (containing both keys and encrypt
980 // everything). 996 // everything).
981 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 997 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
982 sync_pb::EntitySpecifics specifics; 998 sync_pb::EntitySpecifics specifics;
983 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 999 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
984 cryptographer(&wtrans)->AddKey(old_key); 1000 cryptographer(&wtrans)->AddKey(old_key);
985 cryptographer(&wtrans)->AddKey(current_key); 1001 cryptographer(&wtrans)->AddKey(current_key);
986 cryptographer(&wtrans)->Encrypt( 1002 cryptographer(&wtrans)->Encrypt(
987 our_encrypted_specifics, 1003 our_encrypted_specifics,
988 our_encrypted_specifics.mutable_encrypted()); 1004 our_encrypted_specifics.mutable_encrypted());
989 cryptographer(&wtrans)->GetKeys( 1005 cryptographer(&wtrans)->GetKeys(
990 nigori->mutable_encrypted()); 1006 nigori->mutable_encrypted());
991 cryptographer(&wtrans)->set_encrypt_everything(); 1007 cryptographer(&wtrans)->set_encrypt_everything();
992 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1008 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
993 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1009 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
994 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1010 syncable::ModelTypeToRootTag(syncable::NIGORI));
995 ASSERT_TRUE(nigori_entry.good()); 1011 ASSERT_TRUE(nigori_entry.good());
996 nigori_entry.Put(SPECIFICS, specifics); 1012 nigori_entry.Put(SPECIFICS, specifics);
997 nigori_entry.Put(IS_UNSYNCED, true); 1013 nigori_entry.Put(IS_UNSYNCED, true);
998 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1014 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
999 EXPECT_TRUE(encrypted_types.Equals( 1015 EXPECT_TRUE(encrypted_types.Equals(
1000 cryptographer(&wtrans)->GetEncryptedTypes())); 1016 cryptographer(&wtrans)->GetEncryptedTypes()));
1001 } 1017 }
1002 1018
1003 SyncShareAsDelegate(); // Commit it. 1019 SyncShareNudge(); // Commit it.
1004 1020
1005 // Now set up the old nigori node and add it as a server update. 1021 // Now set up the old nigori node and add it as a server update.
1006 sync_pb::EntitySpecifics old_nigori_specifics; 1022 sync_pb::EntitySpecifics old_nigori_specifics;
1007 sync_pb::NigoriSpecifics *old_nigori = old_nigori_specifics.mutable_nigori(); 1023 sync_pb::NigoriSpecifics *old_nigori = old_nigori_specifics.mutable_nigori();
1008 other_cryptographer.GetKeys(old_nigori->mutable_encrypted()); 1024 other_cryptographer.GetKeys(old_nigori->mutable_encrypted());
1009 other_cryptographer.UpdateNigoriFromEncryptedTypes(old_nigori); 1025 other_cryptographer.UpdateNigoriFromEncryptedTypes(old_nigori);
1010 mock_server_->SetNigori(1, 30, 30, old_nigori_specifics); 1026 mock_server_->SetNigori(1, 30, 30, old_nigori_specifics);
1011 1027
1012 SyncShareAsDelegate(); // Download the old nigori and apply it. 1028 SyncShareNudge(); // Download the old nigori and apply it.
1013 1029
1014 { 1030 {
1015 // Ensure everything is committed and stable now. The cryptographer 1031 // Ensure everything is committed and stable now. The cryptographer
1016 // should be able to decrypt both sets of keys and still be encrypting with 1032 // should be able to decrypt both sets of keys and still be encrypting with
1017 // the newest, and the encrypted types should be the most recent 1033 // the newest, and the encrypted types should be the most recent
1018 ReadTransaction trans(FROM_HERE, directory()); 1034 ReadTransaction trans(FROM_HERE, directory());
1019 Entry nigori_entry(&trans, GET_BY_SERVER_TAG, 1035 Entry nigori_entry(&trans, GET_BY_SERVER_TAG,
1020 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1036 syncable::ModelTypeToRootTag(syncable::NIGORI));
1021 ASSERT_TRUE(nigori_entry.good()); 1037 ASSERT_TRUE(nigori_entry.good());
1022 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1038 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
(...skipping 28 matching lines...) Expand all
1051 // Data for testing encryption/decryption. 1067 // Data for testing encryption/decryption.
1052 sync_pb::EntitySpecifics other_encrypted_specifics; 1068 sync_pb::EntitySpecifics other_encrypted_specifics;
1053 other_encrypted_specifics.mutable_bookmark()->set_title("title"); 1069 other_encrypted_specifics.mutable_bookmark()->set_title("title");
1054 other_cryptographer.Encrypt( 1070 other_cryptographer.Encrypt(
1055 other_encrypted_specifics, 1071 other_encrypted_specifics,
1056 other_encrypted_specifics.mutable_encrypted()); 1072 other_encrypted_specifics.mutable_encrypted());
1057 sync_pb::EntitySpecifics our_encrypted_specifics; 1073 sync_pb::EntitySpecifics our_encrypted_specifics;
1058 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); 1074 our_encrypted_specifics.mutable_bookmark()->set_title("title2");
1059 1075
1060 // Receive the initial nigori node. 1076 // Receive the initial nigori node.
1061 SyncShareAsDelegate(); 1077 SyncShareNudge();
1062 encrypted_types = syncable::ModelTypeSet::All(); 1078 encrypted_types = syncable::ModelTypeSet::All();
1063 { 1079 {
1064 // Local changes with different passphrase, different types, and sync_tabs. 1080 // Local changes with different passphrase, different types, and sync_tabs.
1065 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1081 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1066 sync_pb::EntitySpecifics specifics; 1082 sync_pb::EntitySpecifics specifics;
1067 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1083 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1068 cryptographer(&wtrans)->AddKey(local_key_params); 1084 cryptographer(&wtrans)->AddKey(local_key_params);
1069 cryptographer(&wtrans)->Encrypt( 1085 cryptographer(&wtrans)->Encrypt(
1070 our_encrypted_specifics, 1086 our_encrypted_specifics,
1071 our_encrypted_specifics.mutable_encrypted()); 1087 our_encrypted_specifics.mutable_encrypted());
(...skipping 20 matching lines...) Expand all
1092 nigori->set_encrypt_everything(false); 1108 nigori->set_encrypt_everything(false);
1093 nigori->set_using_explicit_passphrase(true); 1109 nigori->set_using_explicit_passphrase(true);
1094 mock_server_->SetNigori(1, 20, 20, specifics); 1110 mock_server_->SetNigori(1, 20, 20, specifics);
1095 } 1111 }
1096 1112
1097 // Will result in downloading the server nigori, which puts the local nigori 1113 // Will result in downloading the server nigori, which puts the local nigori
1098 // in a state of conflict. This is resolved by merging the local and server 1114 // in a state of conflict. This is resolved by merging the local and server
1099 // data (with priority given to the server's encryption keys if they are 1115 // data (with priority given to the server's encryption keys if they are
1100 // undecryptable), which we then commit. The cryptographer should have pending 1116 // undecryptable), which we then commit. The cryptographer should have pending
1101 // keys and merge the set of encrypted types. 1117 // keys and merge the set of encrypted types.
1102 SyncShareAsDelegate(); // Resolve conflict in this cycle. 1118 SyncShareNudge(); // Resolve conflict in this cycle.
1103 SyncShareAsDelegate(); // Commit local change in this cycle. 1119 SyncShareNudge(); // Commit local change in this cycle.
1104 { 1120 {
1105 // Ensure the nigori data merged (encrypted types, sync_tabs). 1121 // Ensure the nigori data merged (encrypted types, sync_tabs).
1106 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1122 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1107 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1123 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1108 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1124 syncable::ModelTypeToRootTag(syncable::NIGORI));
1109 ASSERT_TRUE(nigori_entry.good()); 1125 ASSERT_TRUE(nigori_entry.good());
1110 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1126 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1111 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1127 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1112 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); 1128 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS);
1113 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 1129 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
1114 EXPECT_TRUE(encrypted_types.Equals( 1130 EXPECT_TRUE(encrypted_types.Equals(
1115 cryptographer(&wtrans)->GetEncryptedTypes())); 1131 cryptographer(&wtrans)->GetEncryptedTypes()));
1116 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); 1132 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything());
1117 EXPECT_TRUE(specifics.nigori().sync_tabs()); 1133 EXPECT_TRUE(specifics.nigori().sync_tabs());
1118 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase()); 1134 EXPECT_TRUE(specifics.nigori().using_explicit_passphrase());
1119 // Supply the pending keys. Afterwards, we should be able to decrypt both 1135 // Supply the pending keys. Afterwards, we should be able to decrypt both
1120 // our own encrypted data and data encrypted by the other cryptographer, 1136 // our own encrypted data and data encrypted by the other cryptographer,
1121 // but the key provided by the other cryptographer should be the default. 1137 // but the key provided by the other cryptographer should be the default.
1122 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); 1138 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params));
1123 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1139 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1124 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); 1140 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1125 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); 1141 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted());
1126 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1142 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
1127 // Normally this would be written as part of SetPassphrase, but we do it 1143 // Normally this would be written as part of SetPassphrase, but we do it
1128 // manually for the test. 1144 // manually for the test.
1129 nigori_entry.Put(SPECIFICS, specifics); 1145 nigori_entry.Put(SPECIFICS, specifics);
1130 nigori_entry.Put(IS_UNSYNCED, true); 1146 nigori_entry.Put(IS_UNSYNCED, true);
1131 } 1147 }
1132 1148
1133 SyncShareAsDelegate(); 1149 SyncShareNudge();
1134 { 1150 {
1135 // Ensure everything is committed and stable now. The cryptographer 1151 // Ensure everything is committed and stable now. The cryptographer
1136 // should be able to decrypt both sets of keys, sync_tabs should be true, 1152 // should be able to decrypt both sets of keys, sync_tabs should be true,
1137 // and the encrypted types should have been unioned. 1153 // and the encrypted types should have been unioned.
1138 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1154 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1139 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1155 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1140 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1156 syncable::ModelTypeToRootTag(syncable::NIGORI));
1141 ASSERT_TRUE(nigori_entry.good()); 1157 ASSERT_TRUE(nigori_entry.good());
1142 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1158 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1143 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1159 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 EXPECT_TRUE(entry_b.Get(syncable::ID).ServerKnows()); 1728 EXPECT_TRUE(entry_b.Get(syncable::ID).ServerKnows());
1713 EXPECT_TRUE(parent2.Get(syncable::ID) == entry_b.Get(syncable::PARENT_ID)); 1729 EXPECT_TRUE(parent2.Get(syncable::ID) == entry_b.Get(syncable::PARENT_ID));
1714 } 1730 }
1715 } 1731 }
1716 1732
1717 TEST_F(SyncerTest, UpdateWithZeroLengthName) { 1733 TEST_F(SyncerTest, UpdateWithZeroLengthName) {
1718 // One illegal update 1734 // One illegal update
1719 mock_server_->AddUpdateDirectory(1, 0, "", 1, 10); 1735 mock_server_->AddUpdateDirectory(1, 0, "", 1, 10);
1720 // And one legal one that we're going to delete. 1736 // And one legal one that we're going to delete.
1721 mock_server_->AddUpdateDirectory(2, 0, "FOO", 1, 10); 1737 mock_server_->AddUpdateDirectory(2, 0, "FOO", 1, 10);
1722 SyncShareAsDelegate(); 1738 SyncShareNudge();
1723 // Delete the legal one. The new update has a null name. 1739 // Delete the legal one. The new update has a null name.
1724 mock_server_->AddUpdateDirectory(2, 0, "", 2, 20); 1740 mock_server_->AddUpdateDirectory(2, 0, "", 2, 20);
1725 mock_server_->SetLastUpdateDeleted(); 1741 mock_server_->SetLastUpdateDeleted();
1726 SyncShareAsDelegate(); 1742 SyncShareNudge();
1727 } 1743 }
1728 1744
1729 TEST_F(SyncerTest, TestBasicUpdate) { 1745 TEST_F(SyncerTest, TestBasicUpdate) {
1730 string id = "some_id"; 1746 string id = "some_id";
1731 string parent_id = "0"; 1747 string parent_id = "0";
1732 string name = "in_root"; 1748 string name = "in_root";
1733 int64 version = 10; 1749 int64 version = 10;
1734 int64 timestamp = 10; 1750 int64 timestamp = 10;
1735 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp); 1751 mock_server_->AddUpdateDirectory(id, parent_id, name, version, timestamp);
1736 1752
1737 SyncShareAsDelegate(); 1753 SyncShareNudge();
1738 { 1754 {
1739 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1755 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1740 Entry entry(&trans, GET_BY_ID, 1756 Entry entry(&trans, GET_BY_ID,
1741 syncable::Id::CreateFromServerId("some_id")); 1757 syncable::Id::CreateFromServerId("some_id"));
1742 ASSERT_TRUE(entry.good()); 1758 ASSERT_TRUE(entry.good());
1743 EXPECT_TRUE(entry.Get(IS_DIR)); 1759 EXPECT_TRUE(entry.Get(IS_DIR));
1744 EXPECT_TRUE(entry.Get(SERVER_VERSION) == version); 1760 EXPECT_TRUE(entry.Get(SERVER_VERSION) == version);
1745 EXPECT_TRUE(entry.Get(BASE_VERSION) == version); 1761 EXPECT_TRUE(entry.Get(BASE_VERSION) == version);
1746 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 1762 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
1747 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 1763 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 1921
1906 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry"); 1922 MutableEntry entry(&trans, CREATE, parent.Get(ID), "new_entry");
1907 ASSERT_TRUE(entry.good()); 1923 ASSERT_TRUE(entry.good());
1908 metahandle_new_entry = entry.Get(META_HANDLE); 1924 metahandle_new_entry = entry.Get(META_HANDLE);
1909 WriteTestDataToEntry(&trans, &entry); 1925 WriteTestDataToEntry(&trans, &entry);
1910 } 1926 }
1911 1927
1912 // Mix in a directory creation too for later. 1928 // Mix in a directory creation too for later.
1913 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10); 1929 mock_server_->AddUpdateDirectory(2, 0, "dir_in_root", 10, 10);
1914 mock_server_->SetCommitTimeRename("renamed_"); 1930 mock_server_->SetCommitTimeRename("renamed_");
1915 SyncShareAsDelegate(); 1931 SyncShareNudge();
1916 1932
1917 // Verify it was correctly renamed. 1933 // Verify it was correctly renamed.
1918 { 1934 {
1919 ReadTransaction trans(FROM_HERE, directory()); 1935 ReadTransaction trans(FROM_HERE, directory());
1920 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle_folder); 1936 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle_folder);
1921 ASSERT_TRUE(entry_folder.good()); 1937 ASSERT_TRUE(entry_folder.good());
1922 EXPECT_EQ("renamed_Folder", entry_folder.Get(NON_UNIQUE_NAME)); 1938 EXPECT_EQ("renamed_Folder", entry_folder.Get(NON_UNIQUE_NAME));
1923 1939
1924 Entry entry_new(&trans, GET_BY_HANDLE, metahandle_new_entry); 1940 Entry entry_new(&trans, GET_BY_HANDLE, metahandle_new_entry);
1925 ASSERT_TRUE(entry_new.good()); 1941 ASSERT_TRUE(entry_new.good());
(...skipping 20 matching lines...) Expand all
1946 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1962 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
1947 MutableEntry parent(&trans, CREATE, root_id_, "Folder"); 1963 MutableEntry parent(&trans, CREATE, root_id_, "Folder");
1948 ASSERT_TRUE(parent.good()); 1964 ASSERT_TRUE(parent.good());
1949 parent.Put(IS_DIR, true); 1965 parent.Put(IS_DIR, true);
1950 parent.Put(SPECIFICS, DefaultBookmarkSpecifics()); 1966 parent.Put(SPECIFICS, DefaultBookmarkSpecifics());
1951 parent.Put(IS_UNSYNCED, true); 1967 parent.Put(IS_UNSYNCED, true);
1952 metahandle = parent.Get(META_HANDLE); 1968 metahandle = parent.Get(META_HANDLE);
1953 } 1969 }
1954 1970
1955 mock_server_->SetCommitTimeRename(i18nString); 1971 mock_server_->SetCommitTimeRename(i18nString);
1956 SyncShareAsDelegate(); 1972 SyncShareNudge();
1957 1973
1958 // Verify it was correctly renamed. 1974 // Verify it was correctly renamed.
1959 { 1975 {
1960 ReadTransaction trans(FROM_HERE, directory()); 1976 ReadTransaction trans(FROM_HERE, directory());
1961 string expected_folder_name(i18nString); 1977 string expected_folder_name(i18nString);
1962 expected_folder_name.append("Folder"); 1978 expected_folder_name.append("Folder");
1963 1979
1964 1980
1965 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle); 1981 Entry entry_folder(&trans, GET_BY_HANDLE, metahandle);
1966 ASSERT_TRUE(entry_folder.good()); 1982 ASSERT_TRUE(entry_folder.good());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 // well as reassociate the id. 2042 // well as reassociate the id.
2027 mock_server_->AddUpdateDirectory(new_folder_id, root_id_, 2043 mock_server_->AddUpdateDirectory(new_folder_id, root_id_,
2028 "new_folder", new_version, timestamp); 2044 "new_folder", new_version, timestamp);
2029 mock_server_->SetLastUpdateOriginatorFields( 2045 mock_server_->SetLastUpdateOriginatorFields(
2030 directory()->cache_guid(), folder_id.GetServerId()); 2046 directory()->cache_guid(), folder_id.GetServerId());
2031 2047
2032 // We don't want it accidentally committed, just the update applied. 2048 // We don't want it accidentally committed, just the update applied.
2033 mock_server_->set_conflict_all_commits(true); 2049 mock_server_->set_conflict_all_commits(true);
2034 2050
2035 // Alright! Apply that update! 2051 // Alright! Apply that update!
2036 SyncShareAsDelegate(); 2052 SyncShareNudge();
2037 { 2053 {
2038 // The folder's ID should have been updated. 2054 // The folder's ID should have been updated.
2039 ReadTransaction trans(FROM_HERE, directory()); 2055 ReadTransaction trans(FROM_HERE, directory());
2040 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder); 2056 Entry folder(&trans, GET_BY_HANDLE, metahandle_folder);
2041 ASSERT_TRUE(folder.good()); 2057 ASSERT_TRUE(folder.good());
2042 EXPECT_EQ("new_folder", folder.Get(NON_UNIQUE_NAME)); 2058 EXPECT_EQ("new_folder", folder.Get(NON_UNIQUE_NAME));
2043 EXPECT_TRUE(new_version == folder.Get(BASE_VERSION)); 2059 EXPECT_TRUE(new_version == folder.Get(BASE_VERSION));
2044 EXPECT_TRUE(new_folder_id == folder.Get(ID)); 2060 EXPECT_TRUE(new_folder_id == folder.Get(ID));
2045 EXPECT_TRUE(folder.Get(ID).ServerKnows()); 2061 EXPECT_TRUE(folder.Get(ID).ServerKnows());
2046 EXPECT_EQ(trans.root_id(), folder.Get(PARENT_ID)); 2062 EXPECT_EQ(trans.root_id(), folder.Get(PARENT_ID));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 // Generate an update from the server with a relevant ID reassignment. 2108 // Generate an update from the server with a relevant ID reassignment.
2093 mock_server_->AddUpdateBookmark(new_entry_id, root_id_, 2109 mock_server_->AddUpdateBookmark(new_entry_id, root_id_,
2094 "new_entry", new_version, timestamp); 2110 "new_entry", new_version, timestamp);
2095 mock_server_->SetLastUpdateOriginatorFields( 2111 mock_server_->SetLastUpdateOriginatorFields(
2096 directory()->cache_guid(), entry_id.GetServerId()); 2112 directory()->cache_guid(), entry_id.GetServerId());
2097 2113
2098 // We don't want it accidentally committed, just the update applied. 2114 // We don't want it accidentally committed, just the update applied.
2099 mock_server_->set_conflict_all_commits(true); 2115 mock_server_->set_conflict_all_commits(true);
2100 2116
2101 // Alright! Apply that update! 2117 // Alright! Apply that update!
2102 SyncShareAsDelegate(); 2118 SyncShareNudge();
2103 { 2119 {
2104 ReadTransaction trans(FROM_HERE, directory()); 2120 ReadTransaction trans(FROM_HERE, directory());
2105 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle); 2121 Entry entry(&trans, GET_BY_HANDLE, entry_metahandle);
2106 ASSERT_TRUE(entry.good()); 2122 ASSERT_TRUE(entry.good());
2107 EXPECT_TRUE(new_version == entry.Get(BASE_VERSION)); 2123 EXPECT_TRUE(new_version == entry.Get(BASE_VERSION));
2108 EXPECT_TRUE(new_entry_id == entry.Get(ID)); 2124 EXPECT_TRUE(new_entry_id == entry.Get(ID));
2109 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME)); 2125 EXPECT_EQ("new_entry", entry.Get(NON_UNIQUE_NAME));
2110 } 2126 }
2111 } 2127 }
2112 2128
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 { 2171 {
2156 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2172 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2157 Id new_entry_id = GetOnlyEntryWithName( 2173 Id new_entry_id = GetOnlyEntryWithName(
2158 &trans, trans.root_id(), "new_entry"); 2174 &trans, trans.root_id(), "new_entry");
2159 MutableEntry entry(&trans, GET_BY_ID, new_entry_id); 2175 MutableEntry entry(&trans, GET_BY_ID, new_entry_id);
2160 ASSERT_TRUE(entry.good()); 2176 ASSERT_TRUE(entry.good());
2161 entry.Put(syncable::IS_DEL, true); 2177 entry.Put(syncable::IS_DEL, true);
2162 } 2178 }
2163 2179
2164 // Just don't CHECK fail in sync, have the update split. 2180 // Just don't CHECK fail in sync, have the update split.
2165 SyncShareAsDelegate(); 2181 SyncShareNudge();
2166 { 2182 {
2167 ReadTransaction trans(FROM_HERE, directory()); 2183 ReadTransaction trans(FROM_HERE, directory());
2168 Id new_entry_id = GetOnlyEntryWithName( 2184 Id new_entry_id = GetOnlyEntryWithName(
2169 &trans, trans.root_id(), "new_entry"); 2185 &trans, trans.root_id(), "new_entry");
2170 Entry entry(&trans, GET_BY_ID, new_entry_id); 2186 Entry entry(&trans, GET_BY_ID, new_entry_id);
2171 ASSERT_TRUE(entry.good()); 2187 ASSERT_TRUE(entry.good());
2172 EXPECT_FALSE(entry.Get(IS_DEL)); 2188 EXPECT_FALSE(entry.Get(IS_DEL));
2173 2189
2174 Entry old_entry(&trans, GET_BY_ID, entry_id); 2190 Entry old_entry(&trans, GET_BY_ID, entry_id);
2175 ASSERT_TRUE(old_entry.good()); 2191 ASSERT_TRUE(old_entry.good());
2176 EXPECT_TRUE(old_entry.Get(IS_DEL)); 2192 EXPECT_TRUE(old_entry.Get(IS_DEL));
2177 } 2193 }
2178 } 2194 }
2179 2195
2180 // TODO(chron): Add more unsanitized name tests. 2196 // TODO(chron): Add more unsanitized name tests.
2181 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) { 2197 TEST_F(SyncerTest, ConflictMatchingEntryHandlesUnsanitizedNames) {
2182 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10); 2198 mock_server_->AddUpdateDirectory(1, 0, "A/A", 10, 10);
2183 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10); 2199 mock_server_->AddUpdateDirectory(2, 0, "B/B", 10, 10);
2184 mock_server_->set_conflict_all_commits(true); 2200 mock_server_->set_conflict_all_commits(true);
2185 SyncShareAsDelegate(); 2201 SyncShareNudge();
2186 { 2202 {
2187 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2203 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2188 2204
2189 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2205 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2190 ASSERT_TRUE(A.good()); 2206 ASSERT_TRUE(A.good());
2191 A.Put(IS_UNSYNCED, true); 2207 A.Put(IS_UNSYNCED, true);
2192 A.Put(IS_UNAPPLIED_UPDATE, true); 2208 A.Put(IS_UNAPPLIED_UPDATE, true);
2193 A.Put(SERVER_VERSION, 20); 2209 A.Put(SERVER_VERSION, 20);
2194 2210
2195 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2211 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
(...skipping 19 matching lines...) Expand all
2215 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false); 2231 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false);
2216 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false); 2232 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false);
2217 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20); 2233 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20);
2218 } 2234 }
2219 } 2235 }
2220 2236
2221 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) { 2237 TEST_F(SyncerTest, ConflictMatchingEntryHandlesNormalNames) {
2222 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2238 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2223 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2239 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2224 mock_server_->set_conflict_all_commits(true); 2240 mock_server_->set_conflict_all_commits(true);
2225 SyncShareAsDelegate(); 2241 SyncShareNudge();
2226 { 2242 {
2227 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2243 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2228 2244
2229 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2245 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2230 ASSERT_TRUE(A.good()); 2246 ASSERT_TRUE(A.good());
2231 A.Put(IS_UNSYNCED, true); 2247 A.Put(IS_UNSYNCED, true);
2232 A.Put(IS_UNAPPLIED_UPDATE, true); 2248 A.Put(IS_UNAPPLIED_UPDATE, true);
2233 A.Put(SERVER_VERSION, 20); 2249 A.Put(SERVER_VERSION, 20);
2234 2250
2235 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2251 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 Id child_id = 2335 Id child_id =
2320 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 2336 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
2321 Entry child(&trans, syncable::GET_BY_ID, child_id); 2337 Entry child(&trans, syncable::GET_BY_ID, child_id);
2322 ASSERT_TRUE(child.good()); 2338 ASSERT_TRUE(child.good());
2323 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID)); 2339 EXPECT_EQ(parent_entry.Get(ID), child.Get(PARENT_ID));
2324 } 2340 }
2325 } 2341 }
2326 2342
2327 TEST_F(SyncerTest, NegativeIDInUpdate) { 2343 TEST_F(SyncerTest, NegativeIDInUpdate) {
2328 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40); 2344 mock_server_->AddUpdateBookmark(-10, 0, "bad", 40, 40);
2329 SyncShareAsDelegate(); 2345 SyncShareNudge();
2330 // The negative id would make us CHECK! 2346 // The negative id would make us CHECK!
2331 } 2347 }
2332 2348
2333 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) { 2349 TEST_F(SyncerTest, UnappliedUpdateOnCreatedItemItemDoesNotCrash) {
2334 int64 metahandle_fred; 2350 int64 metahandle_fred;
2335 { 2351 {
2336 // Create an item. 2352 // Create an item.
2337 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2353 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2338 MutableEntry fred_match(&trans, CREATE, trans.root_id(), 2354 MutableEntry fred_match(&trans, CREATE, trans.root_id(),
2339 "fred_match"); 2355 "fred_match");
2340 ASSERT_TRUE(fred_match.good()); 2356 ASSERT_TRUE(fred_match.good());
2341 metahandle_fred = fred_match.Get(META_HANDLE); 2357 metahandle_fred = fred_match.Get(META_HANDLE);
2342 WriteTestDataToEntry(&trans, &fred_match); 2358 WriteTestDataToEntry(&trans, &fred_match);
2343 } 2359 }
2344 // Commit it. 2360 // Commit it.
2345 SyncShareAsDelegate(); 2361 SyncShareNudge();
2346 EXPECT_EQ(1u, mock_server_->committed_ids().size()); 2362 EXPECT_EQ(1u, mock_server_->committed_ids().size());
2347 mock_server_->set_conflict_all_commits(true); 2363 mock_server_->set_conflict_all_commits(true);
2348 syncable::Id fred_match_id; 2364 syncable::Id fred_match_id;
2349 { 2365 {
2350 // Now receive a change from outside. 2366 // Now receive a change from outside.
2351 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2367 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2352 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred); 2368 MutableEntry fred_match(&trans, GET_BY_HANDLE, metahandle_fred);
2353 ASSERT_TRUE(fred_match.good()); 2369 ASSERT_TRUE(fred_match.good());
2354 EXPECT_TRUE(fred_match.Get(ID).ServerKnows()); 2370 EXPECT_TRUE(fred_match.Get(ID).ServerKnows());
2355 fred_match_id = fred_match.Get(ID); 2371 fred_match_id = fred_match.Get(ID);
2356 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(), 2372 mock_server_->AddUpdateBookmark(fred_match_id, trans.root_id(),
2357 "fred_match", 40, 40); 2373 "fred_match", 40, 40);
2358 } 2374 }
2359 // Run the syncer. 2375 // Run the syncer.
2360 for (int i = 0 ; i < 30 ; ++i) { 2376 for (int i = 0 ; i < 30 ; ++i) {
2361 SyncShareAsDelegate(); 2377 SyncShareNudge();
2362 } 2378 }
2363 } 2379 }
2364 2380
2365 /** 2381 /**
2366 * In the event that we have a double changed entry, that is changed on both 2382 * In the event that we have a double changed entry, that is changed on both
2367 * the client and the server, the conflict resolver should just drop one of 2383 * the client and the server, the conflict resolver should just drop one of
2368 * them and accept the other. 2384 * them and accept the other.
2369 */ 2385 */
2370 2386
2371 TEST_F(SyncerTest, DoublyChangedWithResolver) { 2387 TEST_F(SyncerTest, DoublyChangedWithResolver) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2414 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2430 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2415 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete"); 2431 MutableEntry entry(&wtrans, syncable::CREATE, root_id_, "Pete");
2416 ASSERT_TRUE(entry.good()); 2432 ASSERT_TRUE(entry.good());
2417 EXPECT_FALSE(entry.Get(ID).ServerKnows()); 2433 EXPECT_FALSE(entry.Get(ID).ServerKnows());
2418 entry.Put(syncable::IS_DIR, true); 2434 entry.Put(syncable::IS_DIR, true);
2419 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2435 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2420 entry.Put(syncable::IS_UNSYNCED, true); 2436 entry.Put(syncable::IS_UNSYNCED, true);
2421 entry.Put(syncable::MTIME, test_time); 2437 entry.Put(syncable::MTIME, test_time);
2422 entry_metahandle = entry.Get(META_HANDLE); 2438 entry_metahandle = entry.Get(META_HANDLE);
2423 } 2439 }
2424 SyncShareAsDelegate(); 2440 SyncShareNudge();
2425 syncable::Id id; 2441 syncable::Id id;
2426 int64 version; 2442 int64 version;
2427 int64 server_position_in_parent; 2443 int64 server_position_in_parent;
2428 { 2444 {
2429 ReadTransaction trans(FROM_HERE, directory()); 2445 ReadTransaction trans(FROM_HERE, directory());
2430 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle); 2446 Entry entry(&trans, syncable::GET_BY_HANDLE, entry_metahandle);
2431 ASSERT_TRUE(entry.good()); 2447 ASSERT_TRUE(entry.good());
2432 id = entry.Get(ID); 2448 id = entry.Get(ID);
2433 EXPECT_TRUE(id.ServerKnows()); 2449 EXPECT_TRUE(id.ServerKnows());
2434 version = entry.Get(BASE_VERSION); 2450 version = entry.Get(BASE_VERSION);
2435 server_position_in_parent = entry.Get(SERVER_POSITION_IN_PARENT); 2451 server_position_in_parent = entry.Get(SERVER_POSITION_IN_PARENT);
2436 } 2452 }
2437 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit(); 2453 sync_pb::SyncEntity* update = mock_server_->AddUpdateFromLastCommit();
2438 EXPECT_EQ("Pete", update->name()); 2454 EXPECT_EQ("Pete", update->name());
2439 EXPECT_EQ(id.GetServerId(), update->id_string()); 2455 EXPECT_EQ(id.GetServerId(), update->id_string());
2440 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string()); 2456 EXPECT_EQ(root_id_.GetServerId(), update->parent_id_string());
2441 EXPECT_EQ(version, update->version()); 2457 EXPECT_EQ(version, update->version());
2442 EXPECT_EQ(server_position_in_parent, update->position_in_parent()); 2458 EXPECT_EQ(server_position_in_parent, update->position_in_parent());
2443 SyncShareAsDelegate(); 2459 SyncShareNudge();
2444 { 2460 {
2445 ReadTransaction trans(FROM_HERE, directory()); 2461 ReadTransaction trans(FROM_HERE, directory());
2446 Entry entry(&trans, syncable::GET_BY_ID, id); 2462 Entry entry(&trans, syncable::GET_BY_ID, id);
2447 ASSERT_TRUE(entry.good()); 2463 ASSERT_TRUE(entry.good());
2448 EXPECT_TRUE(entry.Get(MTIME) == test_time); 2464 EXPECT_TRUE(entry.Get(MTIME) == test_time);
2449 } 2465 }
2450 } 2466 }
2451 2467
2452 TEST_F(SyncerTest, ParentAndChildBothMatch) { 2468 TEST_F(SyncerTest, ParentAndChildBothMatch) {
2453 const syncable::FullModelTypeSet all_types = 2469 const syncable::FullModelTypeSet all_types =
(...skipping 14 matching lines...) Expand all
2468 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm"); 2484 MutableEntry child(&wtrans, CREATE, parent.Get(ID), "test.htm");
2469 ASSERT_TRUE(child.good()); 2485 ASSERT_TRUE(child.good());
2470 child.Put(ID, child_id); 2486 child.Put(ID, child_id);
2471 child.Put(BASE_VERSION, 1); 2487 child.Put(BASE_VERSION, 1);
2472 child.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2488 child.Put(SPECIFICS, DefaultBookmarkSpecifics());
2473 WriteTestDataToEntry(&wtrans, &child); 2489 WriteTestDataToEntry(&wtrans, &child);
2474 } 2490 }
2475 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); 2491 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10);
2476 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); 2492 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10);
2477 mock_server_->set_conflict_all_commits(true); 2493 mock_server_->set_conflict_all_commits(true);
2478 SyncShareAsDelegate(); 2494 SyncShareNudge();
2479 SyncShareAsDelegate(); 2495 SyncShareNudge();
2480 SyncShareAsDelegate(); 2496 SyncShareNudge();
2481 { 2497 {
2482 ReadTransaction trans(FROM_HERE, directory()); 2498 ReadTransaction trans(FROM_HERE, directory());
2483 Directory::ChildHandles children; 2499 Directory::ChildHandles children;
2484 directory()->GetChildHandlesById(&trans, root_id_, &children); 2500 directory()->GetChildHandlesById(&trans, root_id_, &children);
2485 EXPECT_EQ(1u, children.size()); 2501 EXPECT_EQ(1u, children.size());
2486 directory()->GetChildHandlesById(&trans, parent_id, &children); 2502 directory()->GetChildHandlesById(&trans, parent_id, &children);
2487 EXPECT_EQ(1u, children.size()); 2503 EXPECT_EQ(1u, children.size());
2488 std::vector<int64> unapplied; 2504 std::vector<int64> unapplied;
2489 directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied); 2505 directory()->GetUnappliedUpdateMetaHandles(&trans, all_types, &unapplied);
2490 EXPECT_EQ(0u, unapplied.size()); 2506 EXPECT_EQ(0u, unapplied.size());
2491 syncable::Directory::UnsyncedMetaHandles unsynced; 2507 syncable::Directory::UnsyncedMetaHandles unsynced;
2492 directory()->GetUnsyncedMetaHandles(&trans, &unsynced); 2508 directory()->GetUnsyncedMetaHandles(&trans, &unsynced);
2493 EXPECT_EQ(0u, unsynced.size()); 2509 EXPECT_EQ(0u, unsynced.size());
2494 saw_syncer_event_ = false; 2510 saw_syncer_event_ = false;
2495 } 2511 }
2496 } 2512 }
2497 2513
2498 TEST_F(SyncerTest, CommittingNewDeleted) { 2514 TEST_F(SyncerTest, CommittingNewDeleted) {
2499 { 2515 {
2500 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2516 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2501 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob"); 2517 MutableEntry entry(&trans, CREATE, trans.root_id(), "bob");
2502 entry.Put(IS_UNSYNCED, true); 2518 entry.Put(IS_UNSYNCED, true);
2503 entry.Put(IS_DEL, true); 2519 entry.Put(IS_DEL, true);
2504 } 2520 }
2505 SyncShareAsDelegate(); 2521 SyncShareNudge();
2506 EXPECT_EQ(0u, mock_server_->committed_ids().size()); 2522 EXPECT_EQ(0u, mock_server_->committed_ids().size());
2507 } 2523 }
2508 2524
2509 // Original problem synopsis: 2525 // Original problem synopsis:
2510 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION) 2526 // Check failed: entry->Get(BASE_VERSION) <= entry->Get(SERVER_VERSION)
2511 // Client creates entry, client finishes committing entry. Between 2527 // Client creates entry, client finishes committing entry. Between
2512 // commit and getting update back, we delete the entry. 2528 // commit and getting update back, we delete the entry.
2513 // We get the update for the entry, but the local one was modified 2529 // We get the update for the entry, but the local one was modified
2514 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set. 2530 // so we store the entry but don't apply it. IS_UNAPPLIED_UPDATE is set.
2515 // We commit deletion and get a new version number. 2531 // We commit deletion and get a new version number.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 } 2594 }
2579 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2595 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2580 const StatusController& status(session_->status_controller()); 2596 const StatusController& status(session_->status_controller());
2581 EXPECT_EQ(0, status.TotalNumServerConflictingItems()); 2597 EXPECT_EQ(0, status.TotalNumServerConflictingItems());
2582 } 2598 }
2583 2599
2584 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2600 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2585 int64 newfolder_metahandle; 2601 int64 newfolder_metahandle;
2586 2602
2587 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2603 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2588 SyncShareAsDelegate(); 2604 SyncShareNudge();
2589 { 2605 {
2590 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2606 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2591 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local"); 2607 MutableEntry newfolder(&trans, CREATE, ids_.FromNumber(1), "local");
2592 ASSERT_TRUE(newfolder.good()); 2608 ASSERT_TRUE(newfolder.good());
2593 newfolder.Put(IS_UNSYNCED, true); 2609 newfolder.Put(IS_UNSYNCED, true);
2594 newfolder.Put(IS_DIR, true); 2610 newfolder.Put(IS_DIR, true);
2595 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2611 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2596 newfolder_metahandle = newfolder.Get(META_HANDLE); 2612 newfolder_metahandle = newfolder.Get(META_HANDLE);
2597 } 2613 }
2598 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20); 2614 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20);
2599 mock_server_->SetLastUpdateDeleted(); 2615 mock_server_->SetLastUpdateDeleted();
2600 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); 2616 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES);
2601 { 2617 {
2602 ReadTransaction trans(FROM_HERE, directory()); 2618 ReadTransaction trans(FROM_HERE, directory());
2603 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); 2619 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle);
2604 ASSERT_TRUE(entry.good()); 2620 ASSERT_TRUE(entry.good());
2605 } 2621 }
2606 } 2622 }
2607 2623
2608 TEST_F(SyncerTest, FolderSwapUpdate) { 2624 TEST_F(SyncerTest, FolderSwapUpdate) {
2609 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); 2625 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10);
2610 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); 2626 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10);
2611 SyncShareAsDelegate(); 2627 SyncShareNudge();
2612 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); 2628 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20);
2613 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); 2629 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20);
2614 SyncShareAsDelegate(); 2630 SyncShareNudge();
2615 { 2631 {
2616 ReadTransaction trans(FROM_HERE, directory()); 2632 ReadTransaction trans(FROM_HERE, directory());
2617 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2633 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2618 ASSERT_TRUE(id1.good()); 2634 ASSERT_TRUE(id1.good());
2619 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME)); 2635 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME));
2620 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); 2636 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID));
2621 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2637 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2622 ASSERT_TRUE(id2.good()); 2638 ASSERT_TRUE(id2.good());
2623 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); 2639 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME));
2624 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2640 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
2625 } 2641 }
2626 saw_syncer_event_ = false; 2642 saw_syncer_event_ = false;
2627 } 2643 }
2628 2644
2629 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) { 2645 TEST_F(SyncerTest, NameCollidingFolderSwapWorksFine) {
2630 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10); 2646 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10);
2631 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10); 2647 mock_server_->AddUpdateDirectory(1024, 0, "fred", 1, 10);
2632 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10); 2648 mock_server_->AddUpdateDirectory(4096, 0, "alice", 1, 10);
2633 SyncShareAsDelegate(); 2649 SyncShareNudge();
2634 { 2650 {
2635 ReadTransaction trans(FROM_HERE, directory()); 2651 ReadTransaction trans(FROM_HERE, directory());
2636 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2652 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2637 ASSERT_TRUE(id1.good()); 2653 ASSERT_TRUE(id1.good());
2638 EXPECT_TRUE("bob" == id1.Get(NON_UNIQUE_NAME)); 2654 EXPECT_TRUE("bob" == id1.Get(NON_UNIQUE_NAME));
2639 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); 2655 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID));
2640 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2656 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2641 ASSERT_TRUE(id2.good()); 2657 ASSERT_TRUE(id2.good());
2642 EXPECT_TRUE("fred" == id2.Get(NON_UNIQUE_NAME)); 2658 EXPECT_TRUE("fred" == id2.Get(NON_UNIQUE_NAME));
2643 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2659 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
2644 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096)); 2660 Entry id3(&trans, GET_BY_ID, ids_.FromNumber(4096));
2645 ASSERT_TRUE(id3.good()); 2661 ASSERT_TRUE(id3.good());
2646 EXPECT_TRUE("alice" == id3.Get(NON_UNIQUE_NAME)); 2662 EXPECT_TRUE("alice" == id3.Get(NON_UNIQUE_NAME));
2647 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID)); 2663 EXPECT_TRUE(root_id_ == id3.Get(PARENT_ID));
2648 } 2664 }
2649 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20); 2665 mock_server_->AddUpdateDirectory(1024, 0, "bob", 2, 20);
2650 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20); 2666 mock_server_->AddUpdateDirectory(7801, 0, "fred", 2, 20);
2651 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20); 2667 mock_server_->AddUpdateDirectory(4096, 0, "bob", 2, 20);
2652 SyncShareAsDelegate(); 2668 SyncShareNudge();
2653 { 2669 {
2654 ReadTransaction trans(FROM_HERE, directory()); 2670 ReadTransaction trans(FROM_HERE, directory());
2655 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801)); 2671 Entry id1(&trans, GET_BY_ID, ids_.FromNumber(7801));
2656 ASSERT_TRUE(id1.good()); 2672 ASSERT_TRUE(id1.good());
2657 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME)); 2673 EXPECT_TRUE("fred" == id1.Get(NON_UNIQUE_NAME));
2658 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID)); 2674 EXPECT_TRUE(root_id_ == id1.Get(PARENT_ID));
2659 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024)); 2675 Entry id2(&trans, GET_BY_ID, ids_.FromNumber(1024));
2660 ASSERT_TRUE(id2.good()); 2676 ASSERT_TRUE(id2.good());
2661 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME)); 2677 EXPECT_TRUE("bob" == id2.Get(NON_UNIQUE_NAME));
2662 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID)); 2678 EXPECT_TRUE(root_id_ == id2.Get(PARENT_ID));
(...skipping 13 matching lines...) Expand all
2676 for (uint32 i = 0; i < items_to_commit; i++) { 2692 for (uint32 i = 0; i < items_to_commit; i++) {
2677 string nameutf8 = base::StringPrintf("%d", i); 2693 string nameutf8 = base::StringPrintf("%d", i);
2678 string name(nameutf8.begin(), nameutf8.end()); 2694 string name(nameutf8.begin(), nameutf8.end());
2679 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2695 MutableEntry e(&trans, CREATE, trans.root_id(), name);
2680 e.Put(IS_UNSYNCED, true); 2696 e.Put(IS_UNSYNCED, true);
2681 e.Put(IS_DIR, true); 2697 e.Put(IS_DIR, true);
2682 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2698 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2683 } 2699 }
2684 } 2700 }
2685 uint32 num_loops = 0; 2701 uint32 num_loops = 0;
2686 while (SyncShareAsDelegate()) { 2702 while (SyncShareNudge()) {
2687 num_loops++; 2703 num_loops++;
2688 ASSERT_LT(num_loops, max_batches * 2); 2704 ASSERT_LT(num_loops, max_batches * 2);
2689 } 2705 }
2690 EXPECT_GE(mock_server_->commit_messages().size(), max_batches); 2706 EXPECT_GE(mock_server_->commit_messages().size(), max_batches);
2691 } 2707 }
2692 2708
2693 TEST_F(SyncerTest, HugeConflict) { 2709 TEST_F(SyncerTest, HugeConflict) {
2694 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 2710 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
2695 2711
2696 syncable::Id parent_id = ids_.NewServerId(); 2712 syncable::Id parent_id = ids_.NewServerId();
2697 syncable::Id last_id = parent_id; 2713 syncable::Id last_id = parent_id;
2698 vector<syncable::Id> tree_ids; 2714 vector<syncable::Id> tree_ids;
2699 2715
2700 // Create a lot of updates for which the parent does not exist yet. 2716 // Create a lot of updates for which the parent does not exist yet.
2701 // Generate a huge deep tree which should all fail to apply at first. 2717 // Generate a huge deep tree which should all fail to apply at first.
2702 { 2718 {
2703 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2719 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2704 for (int i = 0; i < item_count ; i++) { 2720 for (int i = 0; i < item_count ; i++) {
2705 syncable::Id next_id = ids_.NewServerId(); 2721 syncable::Id next_id = ids_.NewServerId();
2706 tree_ids.push_back(next_id); 2722 tree_ids.push_back(next_id);
2707 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20); 2723 mock_server_->AddUpdateDirectory(next_id, last_id, "BOB", 2, 20);
2708 last_id = next_id; 2724 last_id = next_id;
2709 } 2725 }
2710 } 2726 }
2711 SyncShareAsDelegate(); 2727 SyncShareNudge();
2712 2728
2713 // Check they're in the expected conflict state. 2729 // Check they're in the expected conflict state.
2714 { 2730 {
2715 ReadTransaction trans(FROM_HERE, directory()); 2731 ReadTransaction trans(FROM_HERE, directory());
2716 for (int i = 0; i < item_count; i++) { 2732 for (int i = 0; i < item_count; i++) {
2717 Entry e(&trans, GET_BY_ID, tree_ids[i]); 2733 Entry e(&trans, GET_BY_ID, tree_ids[i]);
2718 // They should all exist but none should be applied. 2734 // They should all exist but none should be applied.
2719 ASSERT_TRUE(e.good()); 2735 ASSERT_TRUE(e.good());
2720 EXPECT_TRUE(e.Get(IS_DEL)); 2736 EXPECT_TRUE(e.Get(IS_DEL));
2721 EXPECT_TRUE(e.Get(IS_UNAPPLIED_UPDATE)); 2737 EXPECT_TRUE(e.Get(IS_UNAPPLIED_UPDATE));
2722 } 2738 }
2723 } 2739 }
2724 2740
2725 // Add the missing parent directory. 2741 // Add the missing parent directory.
2726 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(), 2742 mock_server_->AddUpdateDirectory(parent_id, TestIdFactory::root(),
2727 "BOB", 2, 20); 2743 "BOB", 2, 20);
2728 SyncShareAsDelegate(); 2744 SyncShareNudge();
2729 2745
2730 // Now they should all be OK. 2746 // Now they should all be OK.
2731 { 2747 {
2732 ReadTransaction trans(FROM_HERE, directory()); 2748 ReadTransaction trans(FROM_HERE, directory());
2733 for (int i = 0; i < item_count; i++) { 2749 for (int i = 0; i < item_count; i++) {
2734 Entry e(&trans, GET_BY_ID, tree_ids[i]); 2750 Entry e(&trans, GET_BY_ID, tree_ids[i]);
2735 ASSERT_TRUE(e.good()); 2751 ASSERT_TRUE(e.good());
2736 EXPECT_FALSE(e.Get(IS_DEL)); 2752 EXPECT_FALSE(e.Get(IS_DEL));
2737 EXPECT_FALSE(e.Get(IS_UNAPPLIED_UPDATE)); 2753 EXPECT_FALSE(e.Get(IS_UNAPPLIED_UPDATE));
2738 } 2754 }
2739 } 2755 }
2740 } 2756 }
2741 2757
2742 TEST_F(SyncerTest, DontCrashOnCaseChange) { 2758 TEST_F(SyncerTest, DontCrashOnCaseChange) {
2743 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2759 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2744 SyncShareAsDelegate(); 2760 SyncShareNudge();
2745 { 2761 {
2746 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2762 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2747 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1)); 2763 MutableEntry e(&trans, GET_BY_ID, ids_.FromNumber(1));
2748 ASSERT_TRUE(e.good()); 2764 ASSERT_TRUE(e.good());
2749 e.Put(IS_UNSYNCED, true); 2765 e.Put(IS_UNSYNCED, true);
2750 } 2766 }
2751 mock_server_->set_conflict_all_commits(true); 2767 mock_server_->set_conflict_all_commits(true);
2752 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20); 2768 mock_server_->AddUpdateDirectory(1, 0, "BOB", 2, 20);
2753 SyncShareAsDelegate(); // USED TO CAUSE AN ASSERT 2769 SyncShareNudge(); // USED TO CAUSE AN ASSERT
2754 saw_syncer_event_ = false; 2770 saw_syncer_event_ = false;
2755 } 2771 }
2756 2772
2757 TEST_F(SyncerTest, UnsyncedItemAndUpdate) { 2773 TEST_F(SyncerTest, UnsyncedItemAndUpdate) {
2758 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 2774 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
2759 SyncShareAsDelegate(); 2775 SyncShareNudge();
2760 mock_server_->set_conflict_all_commits(true); 2776 mock_server_->set_conflict_all_commits(true);
2761 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20); 2777 mock_server_->AddUpdateDirectory(2, 0, "bob", 2, 20);
2762 SyncShareAsDelegate(); // USED TO CAUSE AN ASSERT 2778 SyncShareNudge(); // USED TO CAUSE AN ASSERT
2763 saw_syncer_event_ = false; 2779 saw_syncer_event_ = false;
2764 } 2780 }
2765 2781
2766 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) { 2782 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath) {
2767 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2783 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2768 SyncShareAsDelegate(); 2784 SyncShareNudge();
2769 int64 local_folder_handle; 2785 int64 local_folder_handle;
2770 syncable::Id local_folder_id; 2786 syncable::Id local_folder_id;
2771 { 2787 {
2772 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2788 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2773 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); 2789 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm");
2774 ASSERT_TRUE(new_entry.good()); 2790 ASSERT_TRUE(new_entry.good());
2775 local_folder_id = new_entry.Get(ID); 2791 local_folder_id = new_entry.Get(ID);
2776 local_folder_handle = new_entry.Get(META_HANDLE); 2792 local_folder_handle = new_entry.Get(META_HANDLE);
2777 new_entry.Put(IS_UNSYNCED, true); 2793 new_entry.Put(IS_UNSYNCED, true);
2778 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2794 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2779 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2795 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2780 ASSERT_TRUE(old.good()); 2796 ASSERT_TRUE(old.good());
2781 WriteTestDataToEntry(&wtrans, &old); 2797 WriteTestDataToEntry(&wtrans, &old);
2782 } 2798 }
2783 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); 2799 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20);
2784 mock_server_->set_conflict_all_commits(true); 2800 mock_server_->set_conflict_all_commits(true);
2785 SyncShareAsDelegate(); 2801 SyncShareNudge();
2786 saw_syncer_event_ = false; 2802 saw_syncer_event_ = false;
2787 { 2803 {
2788 // Update #20 should have been dropped in favor of the local version. 2804 // Update #20 should have been dropped in favor of the local version.
2789 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2805 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2790 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2806 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2791 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2807 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2792 ASSERT_TRUE(server.good()); 2808 ASSERT_TRUE(server.good());
2793 ASSERT_TRUE(local.good()); 2809 ASSERT_TRUE(local.good());
2794 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2810 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2795 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2811 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2796 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2812 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2797 EXPECT_TRUE(server.Get(IS_UNSYNCED)); 2813 EXPECT_TRUE(server.Get(IS_UNSYNCED));
2798 EXPECT_TRUE(local.Get(IS_UNSYNCED)); 2814 EXPECT_TRUE(local.Get(IS_UNSYNCED));
2799 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME)); 2815 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME));
2800 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2816 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2801 } 2817 }
2802 // Allow local changes to commit. 2818 // Allow local changes to commit.
2803 mock_server_->set_conflict_all_commits(false); 2819 mock_server_->set_conflict_all_commits(false);
2804 SyncShareAsDelegate(); 2820 SyncShareNudge();
2805 saw_syncer_event_ = false; 2821 saw_syncer_event_ = false;
2806 2822
2807 // Now add a server change to make the two names equal. There should 2823 // Now add a server change to make the two names equal. There should
2808 // be no conflict with that, since names are not unique. 2824 // be no conflict with that, since names are not unique.
2809 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30); 2825 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30);
2810 SyncShareAsDelegate(); 2826 SyncShareNudge();
2811 saw_syncer_event_ = false; 2827 saw_syncer_event_ = false;
2812 { 2828 {
2813 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2829 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2814 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2830 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2815 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2831 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2816 ASSERT_TRUE(server.good()); 2832 ASSERT_TRUE(server.good());
2817 ASSERT_TRUE(local.good()); 2833 ASSERT_TRUE(local.good());
2818 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2834 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2819 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2835 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2820 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2836 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2821 EXPECT_FALSE(server.Get(IS_UNSYNCED)); 2837 EXPECT_FALSE(server.Get(IS_UNSYNCED));
2822 EXPECT_FALSE(local.Get(IS_UNSYNCED)); 2838 EXPECT_FALSE(local.Get(IS_UNSYNCED));
2823 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); 2839 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME));
2824 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2840 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2825 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 2841 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
2826 server.Get(SPECIFICS).bookmark().url()); 2842 server.Get(SPECIFICS).bookmark().url());
2827 } 2843 }
2828 } 2844 }
2829 2845
2830 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. 2846 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol.
2831 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { 2847 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) {
2832 mock_server_->set_use_legacy_bookmarks_protocol(true); 2848 mock_server_->set_use_legacy_bookmarks_protocol(true);
2833 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2849 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2834 SyncShareAsDelegate(); 2850 SyncShareNudge();
2835 int64 local_folder_handle; 2851 int64 local_folder_handle;
2836 syncable::Id local_folder_id; 2852 syncable::Id local_folder_id;
2837 { 2853 {
2838 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2854 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2839 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm"); 2855 MutableEntry new_entry(&wtrans, CREATE, wtrans.root_id(), "Bar.htm");
2840 ASSERT_TRUE(new_entry.good()); 2856 ASSERT_TRUE(new_entry.good());
2841 local_folder_id = new_entry.Get(ID); 2857 local_folder_id = new_entry.Get(ID);
2842 local_folder_handle = new_entry.Get(META_HANDLE); 2858 local_folder_handle = new_entry.Get(META_HANDLE);
2843 new_entry.Put(IS_UNSYNCED, true); 2859 new_entry.Put(IS_UNSYNCED, true);
2844 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2860 new_entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2845 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2861 MutableEntry old(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2846 ASSERT_TRUE(old.good()); 2862 ASSERT_TRUE(old.good());
2847 WriteTestDataToEntry(&wtrans, &old); 2863 WriteTestDataToEntry(&wtrans, &old);
2848 } 2864 }
2849 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20); 2865 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 20, 20);
2850 mock_server_->set_conflict_all_commits(true); 2866 mock_server_->set_conflict_all_commits(true);
2851 SyncShareAsDelegate(); 2867 SyncShareNudge();
2852 saw_syncer_event_ = false; 2868 saw_syncer_event_ = false;
2853 { 2869 {
2854 // Update #20 should have been dropped in favor of the local version. 2870 // Update #20 should have been dropped in favor of the local version.
2855 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2871 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2856 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2872 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2857 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2873 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2858 ASSERT_TRUE(server.good()); 2874 ASSERT_TRUE(server.good());
2859 ASSERT_TRUE(local.good()); 2875 ASSERT_TRUE(local.good());
2860 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2876 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2861 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2877 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2862 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2878 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2863 EXPECT_TRUE(server.Get(IS_UNSYNCED)); 2879 EXPECT_TRUE(server.Get(IS_UNSYNCED));
2864 EXPECT_TRUE(local.Get(IS_UNSYNCED)); 2880 EXPECT_TRUE(local.Get(IS_UNSYNCED));
2865 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME)); 2881 EXPECT_EQ("Foo.htm", server.Get(NON_UNIQUE_NAME));
2866 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2882 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2867 } 2883 }
2868 // Allow local changes to commit. 2884 // Allow local changes to commit.
2869 mock_server_->set_conflict_all_commits(false); 2885 mock_server_->set_conflict_all_commits(false);
2870 SyncShareAsDelegate(); 2886 SyncShareNudge();
2871 saw_syncer_event_ = false; 2887 saw_syncer_event_ = false;
2872 2888
2873 // Now add a server change to make the two names equal. There should 2889 // Now add a server change to make the two names equal. There should
2874 // be no conflict with that, since names are not unique. 2890 // be no conflict with that, since names are not unique.
2875 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30); 2891 mock_server_->AddUpdateBookmark(1, 0, "Bar.htm", 30, 30);
2876 SyncShareAsDelegate(); 2892 SyncShareNudge();
2877 saw_syncer_event_ = false; 2893 saw_syncer_event_ = false;
2878 { 2894 {
2879 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2895 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2880 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2896 MutableEntry server(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2881 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle); 2897 MutableEntry local(&wtrans, GET_BY_HANDLE, local_folder_handle);
2882 ASSERT_TRUE(server.good()); 2898 ASSERT_TRUE(server.good());
2883 ASSERT_TRUE(local.good()); 2899 ASSERT_TRUE(local.good());
2884 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2900 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2885 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2901 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2886 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2902 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2887 EXPECT_FALSE(server.Get(IS_UNSYNCED)); 2903 EXPECT_FALSE(server.Get(IS_UNSYNCED));
2888 EXPECT_FALSE(local.Get(IS_UNSYNCED)); 2904 EXPECT_FALSE(local.Get(IS_UNSYNCED));
2889 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); 2905 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME));
2890 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2906 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2891 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 2907 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
2892 server.Get(SPECIFICS).bookmark().url()); 2908 server.Get(SPECIFICS).bookmark().url());
2893 } 2909 }
2894 } 2910 }
2895 2911
2896 // Circular links should be resolved by the server. 2912 // Circular links should be resolved by the server.
2897 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { 2913 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) {
2898 // we don't currently resolve this. This test ensures we don't. 2914 // we don't currently resolve this. This test ensures we don't.
2899 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2915 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2900 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2916 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2901 SyncShareAsDelegate(); 2917 SyncShareNudge();
2902 { 2918 {
2903 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2919 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2904 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2920 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2905 ASSERT_TRUE(A.good()); 2921 ASSERT_TRUE(A.good());
2906 A.Put(IS_UNSYNCED, true); 2922 A.Put(IS_UNSYNCED, true);
2907 ASSERT_TRUE(A.Put(PARENT_ID, ids_.FromNumber(2))); 2923 ASSERT_TRUE(A.Put(PARENT_ID, ids_.FromNumber(2)));
2908 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B")); 2924 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B"));
2909 } 2925 }
2910 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20); 2926 mock_server_->AddUpdateDirectory(2, 1, "A", 20, 20);
2911 mock_server_->set_conflict_all_commits(true); 2927 mock_server_->set_conflict_all_commits(true);
2912 SyncShareAsDelegate(); 2928 SyncShareNudge();
2913 saw_syncer_event_ = false; 2929 saw_syncer_event_ = false;
2914 { 2930 {
2915 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2931 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2916 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2932 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2917 ASSERT_TRUE(A.good()); 2933 ASSERT_TRUE(A.good());
2918 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2934 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2919 ASSERT_TRUE(B.good()); 2935 ASSERT_TRUE(B.good());
2920 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B"); 2936 EXPECT_TRUE(A.Get(NON_UNIQUE_NAME) == "B");
2921 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B"); 2937 EXPECT_TRUE(B.Get(NON_UNIQUE_NAME) == "B");
2922 } 2938 }
2923 } 2939 }
2924 2940
2925 TEST_F(SyncerTest, SwapEntryNames) { 2941 TEST_F(SyncerTest, SwapEntryNames) {
2926 // Simple transaction test. 2942 // Simple transaction test.
2927 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2943 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2928 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2944 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2929 mock_server_->set_conflict_all_commits(true); 2945 mock_server_->set_conflict_all_commits(true);
2930 SyncShareAsDelegate(); 2946 SyncShareNudge();
2931 { 2947 {
2932 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 2948 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
2933 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 2949 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
2934 ASSERT_TRUE(A.good()); 2950 ASSERT_TRUE(A.good());
2935 A.Put(IS_UNSYNCED, true); 2951 A.Put(IS_UNSYNCED, true);
2936 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2952 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2937 ASSERT_TRUE(B.good()); 2953 ASSERT_TRUE(B.good());
2938 B.Put(IS_UNSYNCED, true); 2954 B.Put(IS_UNSYNCED, true);
2939 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "C")); 2955 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "C"));
2940 ASSERT_TRUE(B.Put(NON_UNIQUE_NAME, "A")); 2956 ASSERT_TRUE(B.Put(NON_UNIQUE_NAME, "A"));
2941 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B")); 2957 ASSERT_TRUE(A.Put(NON_UNIQUE_NAME, "B"));
2942 } 2958 }
2943 SyncShareAsDelegate(); 2959 SyncShareNudge();
2944 saw_syncer_event_ = false; 2960 saw_syncer_event_ = false;
2945 } 2961 }
2946 2962
2947 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) { 2963 TEST_F(SyncerTest, DualDeletionWithNewItemNameClash) {
2948 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2964 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2949 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10); 2965 mock_server_->AddUpdateBookmark(2, 0, "B", 10, 10);
2950 mock_server_->set_conflict_all_commits(true); 2966 mock_server_->set_conflict_all_commits(true);
2951 SyncShareAsDelegate(); 2967 SyncShareNudge();
2952 { 2968 {
2953 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2969 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2954 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 2970 MutableEntry B(&trans, GET_BY_ID, ids_.FromNumber(2));
2955 ASSERT_TRUE(B.good()); 2971 ASSERT_TRUE(B.good());
2956 WriteTestDataToEntry(&trans, &B); 2972 WriteTestDataToEntry(&trans, &B);
2957 B.Put(IS_DEL, true); 2973 B.Put(IS_DEL, true);
2958 } 2974 }
2959 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11); 2975 mock_server_->AddUpdateBookmark(2, 0, "A", 11, 11);
2960 mock_server_->SetLastUpdateDeleted(); 2976 mock_server_->SetLastUpdateDeleted();
2961 SyncShareAsDelegate(); 2977 SyncShareNudge();
2962 { 2978 {
2963 ReadTransaction trans(FROM_HERE, directory()); 2979 ReadTransaction trans(FROM_HERE, directory());
2964 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 2980 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
2965 ASSERT_TRUE(B.good()); 2981 ASSERT_TRUE(B.good());
2966 EXPECT_FALSE(B.Get(IS_UNSYNCED)); 2982 EXPECT_FALSE(B.Get(IS_UNSYNCED));
2967 EXPECT_FALSE(B.Get(IS_UNAPPLIED_UPDATE)); 2983 EXPECT_FALSE(B.Get(IS_UNAPPLIED_UPDATE));
2968 } 2984 }
2969 saw_syncer_event_ = false; 2985 saw_syncer_event_ = false;
2970 } 2986 }
2971 2987
2972 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) { 2988 TEST_F(SyncerTest, ResolveWeWroteTheyDeleted) {
2973 int64 bob_metahandle; 2989 int64 bob_metahandle;
2974 2990
2975 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10); 2991 mock_server_->AddUpdateBookmark(1, 0, "bob", 1, 10);
2976 SyncShareAsDelegate(); 2992 SyncShareNudge();
2977 { 2993 {
2978 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2994 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2979 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 2995 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
2980 ASSERT_TRUE(bob.good()); 2996 ASSERT_TRUE(bob.good());
2981 bob_metahandle = bob.Get(META_HANDLE); 2997 bob_metahandle = bob.Get(META_HANDLE);
2982 WriteTestDataToEntry(&trans, &bob); 2998 WriteTestDataToEntry(&trans, &bob);
2983 } 2999 }
2984 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10); 3000 mock_server_->AddUpdateBookmark(1, 0, "bob", 2, 10);
2985 mock_server_->SetLastUpdateDeleted(); 3001 mock_server_->SetLastUpdateDeleted();
2986 mock_server_->set_conflict_all_commits(true); 3002 mock_server_->set_conflict_all_commits(true);
2987 SyncShareAsDelegate(); 3003 SyncShareNudge();
2988 SyncShareAsDelegate(); 3004 SyncShareNudge();
2989 { 3005 {
2990 ReadTransaction trans(FROM_HERE, directory()); 3006 ReadTransaction trans(FROM_HERE, directory());
2991 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle); 3007 Entry bob(&trans, GET_BY_HANDLE, bob_metahandle);
2992 ASSERT_TRUE(bob.good()); 3008 ASSERT_TRUE(bob.good());
2993 EXPECT_TRUE(bob.Get(IS_UNSYNCED)); 3009 EXPECT_TRUE(bob.Get(IS_UNSYNCED));
2994 EXPECT_FALSE(bob.Get(ID).ServerKnows()); 3010 EXPECT_FALSE(bob.Get(ID).ServerKnows());
2995 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE)); 3011 EXPECT_FALSE(bob.Get(IS_UNAPPLIED_UPDATE));
2996 EXPECT_FALSE(bob.Get(IS_DEL)); 3012 EXPECT_FALSE(bob.Get(IS_DEL));
2997 } 3013 }
2998 saw_syncer_event_ = false; 3014 saw_syncer_event_ = false;
(...skipping 13 matching lines...) Expand all
3012 ASSERT_TRUE(folder2.good()); 3028 ASSERT_TRUE(folder2.good());
3013 folder2.Put(IS_UNSYNCED, false); 3029 folder2.Put(IS_UNSYNCED, false);
3014 folder2.Put(IS_DIR, true); 3030 folder2.Put(IS_DIR, true);
3015 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3031 folder2.Put(SPECIFICS, DefaultBookmarkSpecifics());
3016 folder2.Put(BASE_VERSION, 3); 3032 folder2.Put(BASE_VERSION, 3);
3017 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000")); 3033 folder2.Put(ID, syncable::Id::CreateFromServerId("mock_server:10000"));
3018 } 3034 }
3019 mock_server_->set_next_new_id(10000); 3035 mock_server_->set_next_new_id(10000);
3020 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 3036 EXPECT_EQ(1u, directory()->unsynced_entity_count());
3021 // we get back a bad id in here (should never happen). 3037 // we get back a bad id in here (should never happen).
3022 SyncShareAsDelegate(); 3038 SyncShareNudge();
3023 EXPECT_EQ(1u, directory()->unsynced_entity_count()); 3039 EXPECT_EQ(1u, directory()->unsynced_entity_count());
3024 SyncShareAsDelegate(); // another bad id in here. 3040 SyncShareNudge(); // another bad id in here.
3025 EXPECT_EQ(0u, directory()->unsynced_entity_count()); 3041 EXPECT_EQ(0u, directory()->unsynced_entity_count());
3026 saw_syncer_event_ = false; 3042 saw_syncer_event_ = false;
3027 } 3043 }
3028 3044
3029 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) { 3045 TEST_F(SyncerTest, DeletedEntryWithBadParentInLoopCalculation) {
3030 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10); 3046 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10);
3031 SyncShareAsDelegate(); 3047 SyncShareNudge();
3032 { 3048 {
3033 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3049 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3034 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1)); 3050 MutableEntry bob(&trans, GET_BY_ID, ids_.FromNumber(1));
3035 ASSERT_TRUE(bob.good()); 3051 ASSERT_TRUE(bob.good());
3036 // This is valid, because the parent could have gone away a long time ago. 3052 // This is valid, because the parent could have gone away a long time ago.
3037 bob.Put(PARENT_ID, ids_.FromNumber(54)); 3053 bob.Put(PARENT_ID, ids_.FromNumber(54));
3038 bob.Put(IS_DEL, true); 3054 bob.Put(IS_DEL, true);
3039 bob.Put(IS_UNSYNCED, true); 3055 bob.Put(IS_UNSYNCED, true);
3040 } 3056 }
3041 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10); 3057 mock_server_->AddUpdateDirectory(2, 1, "fred", 1, 10);
3042 SyncShareAsDelegate(); 3058 SyncShareNudge();
3043 SyncShareAsDelegate(); 3059 SyncShareNudge();
3044 } 3060 }
3045 3061
3046 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) { 3062 TEST_F(SyncerTest, ConflictResolverMergesLocalDeleteAndServerUpdate) {
3047 { 3063 {
3048 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3064 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3049 3065
3050 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name"); 3066 MutableEntry local_deleted(&trans, CREATE, trans.root_id(), "name");
3051 local_deleted.Put(ID, ids_.FromNumber(1)); 3067 local_deleted.Put(ID, ids_.FromNumber(1));
3052 local_deleted.Put(BASE_VERSION, 1); 3068 local_deleted.Put(BASE_VERSION, 1);
3053 local_deleted.Put(IS_DEL, true); 3069 local_deleted.Put(IS_DEL, true);
3054 local_deleted.Put(IS_DIR, false); 3070 local_deleted.Put(IS_DIR, false);
3055 local_deleted.Put(IS_UNSYNCED, true); 3071 local_deleted.Put(IS_UNSYNCED, true);
3056 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3072 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics());
3057 } 3073 }
3058 3074
3059 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); 3075 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10);
3060 3076
3061 // We don't care about actually committing, just the resolution. 3077 // We don't care about actually committing, just the resolution.
3062 mock_server_->set_conflict_all_commits(true); 3078 mock_server_->set_conflict_all_commits(true);
3063 SyncShareAsDelegate(); 3079 SyncShareNudge();
3064 3080
3065 { 3081 {
3066 ReadTransaction trans(FROM_HERE, directory()); 3082 ReadTransaction trans(FROM_HERE, directory());
3067 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); 3083 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1));
3068 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 10); 3084 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 10);
3069 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false); 3085 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false);
3070 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true); 3086 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true);
3071 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true); 3087 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true);
3072 EXPECT_TRUE(local_deleted.Get(IS_DIR) == false); 3088 EXPECT_TRUE(local_deleted.Get(IS_DIR) == false);
3073 } 3089 }
(...skipping 15 matching lines...) Expand all
3089 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3105 local_deleted.Put(SPECIFICS, DefaultBookmarkSpecifics());
3090 } 3106 }
3091 3107
3092 // Server update: entry-type object (not a container), revision 10. 3108 // Server update: entry-type object (not a container), revision 10.
3093 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10); 3109 mock_server_->AddUpdateBookmark(ids_.FromNumber(1), root_id_, "name", 10, 10);
3094 3110
3095 // Don't attempt to commit. 3111 // Don't attempt to commit.
3096 mock_server_->set_conflict_all_commits(true); 3112 mock_server_->set_conflict_all_commits(true);
3097 3113
3098 // The syncer should not attempt to apply the invalid update. 3114 // The syncer should not attempt to apply the invalid update.
3099 SyncShareAsDelegate(); 3115 SyncShareNudge();
3100 3116
3101 { 3117 {
3102 ReadTransaction trans(FROM_HERE, directory()); 3118 ReadTransaction trans(FROM_HERE, directory());
3103 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1)); 3119 Entry local_deleted(&trans, GET_BY_ID, ids_.FromNumber(1));
3104 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 1); 3120 EXPECT_TRUE(local_deleted.Get(BASE_VERSION) == 1);
3105 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false); 3121 EXPECT_TRUE(local_deleted.Get(IS_UNAPPLIED_UPDATE) == false);
3106 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true); 3122 EXPECT_TRUE(local_deleted.Get(IS_UNSYNCED) == true);
3107 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true); 3123 EXPECT_TRUE(local_deleted.Get(IS_DEL) == true);
3108 EXPECT_TRUE(local_deleted.Get(IS_DIR) == true); 3124 EXPECT_TRUE(local_deleted.Get(IS_DIR) == true);
3109 } 3125 }
3110 } 3126 }
3111 3127
3112 // Bug Synopsis: 3128 // Bug Synopsis:
3113 // Merge conflict resolution will merge a new local entry with another entry 3129 // Merge conflict resolution will merge a new local entry with another entry
3114 // that needs updates, resulting in CHECK. 3130 // that needs updates, resulting in CHECK.
3115 TEST_F(SyncerTest, MergingExistingItems) { 3131 TEST_F(SyncerTest, MergingExistingItems) {
3116 mock_server_->set_conflict_all_commits(true); 3132 mock_server_->set_conflict_all_commits(true);
3117 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); 3133 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10);
3118 SyncShareAsDelegate(); 3134 SyncShareNudge();
3119 { 3135 {
3120 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3136 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3121 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base"); 3137 MutableEntry entry(&trans, CREATE, trans.root_id(), "Copy of base");
3122 WriteTestDataToEntry(&trans, &entry); 3138 WriteTestDataToEntry(&trans, &entry);
3123 } 3139 }
3124 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); 3140 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50);
3125 SyncRepeatedlyToTriggerConflictResolution(session_.get()); 3141 SyncRepeatedlyToTriggerConflictResolution(session_.get());
3126 } 3142 }
3127 3143
3128 // In this test a long changelog contains a child at the start of the changelog 3144 // In this test a long changelog contains a child at the start of the changelog
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3176 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID)); 3192 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID));
3177 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME)); 3193 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME));
3178 EXPECT_TRUE(child.good()); 3194 EXPECT_TRUE(child.good());
3179 } 3195 }
3180 } 3196 }
3181 3197
3182 TEST_F(SyncerTest, DontMergeTwoExistingItems) { 3198 TEST_F(SyncerTest, DontMergeTwoExistingItems) {
3183 mock_server_->set_conflict_all_commits(true); 3199 mock_server_->set_conflict_all_commits(true);
3184 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10); 3200 mock_server_->AddUpdateBookmark(1, 0, "base", 10, 10);
3185 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10); 3201 mock_server_->AddUpdateBookmark(2, 0, "base2", 10, 10);
3186 SyncShareAsDelegate(); 3202 SyncShareNudge();
3187 { 3203 {
3188 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3204 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3189 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3205 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3190 ASSERT_TRUE(entry.good()); 3206 ASSERT_TRUE(entry.good());
3191 EXPECT_TRUE(entry.Put(NON_UNIQUE_NAME, "Copy of base")); 3207 EXPECT_TRUE(entry.Put(NON_UNIQUE_NAME, "Copy of base"));
3192 entry.Put(IS_UNSYNCED, true); 3208 entry.Put(IS_UNSYNCED, true);
3193 } 3209 }
3194 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50); 3210 mock_server_->AddUpdateBookmark(1, 0, "Copy of base", 50, 50);
3195 SyncRepeatedlyToTriggerConflictResolution(session_.get()); 3211 SyncRepeatedlyToTriggerConflictResolution(session_.get());
3196 { 3212 {
3197 ReadTransaction trans(FROM_HERE, directory()); 3213 ReadTransaction trans(FROM_HERE, directory());
3198 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1)); 3214 Entry entry1(&trans, GET_BY_ID, ids_.FromNumber(1));
3199 EXPECT_FALSE(entry1.Get(IS_UNAPPLIED_UPDATE)); 3215 EXPECT_FALSE(entry1.Get(IS_UNAPPLIED_UPDATE));
3200 EXPECT_FALSE(entry1.Get(IS_UNSYNCED)); 3216 EXPECT_FALSE(entry1.Get(IS_UNSYNCED));
3201 EXPECT_FALSE(entry1.Get(IS_DEL)); 3217 EXPECT_FALSE(entry1.Get(IS_DEL));
3202 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2)); 3218 Entry entry2(&trans, GET_BY_ID, ids_.FromNumber(2));
3203 EXPECT_FALSE(entry2.Get(IS_UNAPPLIED_UPDATE)); 3219 EXPECT_FALSE(entry2.Get(IS_UNAPPLIED_UPDATE));
3204 EXPECT_TRUE(entry2.Get(IS_UNSYNCED)); 3220 EXPECT_TRUE(entry2.Get(IS_UNSYNCED));
3205 EXPECT_FALSE(entry2.Get(IS_DEL)); 3221 EXPECT_FALSE(entry2.Get(IS_DEL));
3206 EXPECT_EQ(entry1.Get(NON_UNIQUE_NAME), entry2.Get(NON_UNIQUE_NAME)); 3222 EXPECT_EQ(entry1.Get(NON_UNIQUE_NAME), entry2.Get(NON_UNIQUE_NAME));
3207 } 3223 }
3208 } 3224 }
3209 3225
3210 TEST_F(SyncerTest, TestUndeleteUpdate) { 3226 TEST_F(SyncerTest, TestUndeleteUpdate) {
3211 mock_server_->set_conflict_all_commits(true); 3227 mock_server_->set_conflict_all_commits(true);
3212 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1); 3228 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1);
3213 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2); 3229 mock_server_->AddUpdateDirectory(2, 1, "bar", 1, 2);
3214 SyncShareAsDelegate(); 3230 SyncShareNudge();
3215 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3); 3231 mock_server_->AddUpdateDirectory(2, 1, "bar", 2, 3);
3216 mock_server_->SetLastUpdateDeleted(); 3232 mock_server_->SetLastUpdateDeleted();
3217 SyncShareAsDelegate(); 3233 SyncShareNudge();
3218 3234
3219 int64 metahandle; 3235 int64 metahandle;
3220 { 3236 {
3221 ReadTransaction trans(FROM_HERE, directory()); 3237 ReadTransaction trans(FROM_HERE, directory());
3222 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3238 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3223 ASSERT_TRUE(entry.good()); 3239 ASSERT_TRUE(entry.good());
3224 EXPECT_TRUE(entry.Get(IS_DEL)); 3240 EXPECT_TRUE(entry.Get(IS_DEL));
3225 metahandle = entry.Get(META_HANDLE); 3241 metahandle = entry.Get(META_HANDLE);
3226 } 3242 }
3227 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4); 3243 mock_server_->AddUpdateDirectory(1, 0, "foo", 2, 4);
3228 mock_server_->SetLastUpdateDeleted(); 3244 mock_server_->SetLastUpdateDeleted();
3229 SyncShareAsDelegate(); 3245 SyncShareNudge();
3230 // This used to be rejected as it's an undeletion. Now, it results in moving 3246 // This used to be rejected as it's an undeletion. Now, it results in moving
3231 // the delete path aside. 3247 // the delete path aside.
3232 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5); 3248 mock_server_->AddUpdateDirectory(2, 1, "bar", 3, 5);
3233 SyncShareAsDelegate(); 3249 SyncShareNudge();
3234 { 3250 {
3235 ReadTransaction trans(FROM_HERE, directory()); 3251 ReadTransaction trans(FROM_HERE, directory());
3236 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3252 Entry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3237 ASSERT_TRUE(entry.good()); 3253 ASSERT_TRUE(entry.good());
3238 EXPECT_TRUE(entry.Get(IS_DEL)); 3254 EXPECT_TRUE(entry.Get(IS_DEL));
3239 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3255 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3240 EXPECT_TRUE(entry.Get(IS_UNAPPLIED_UPDATE)); 3256 EXPECT_TRUE(entry.Get(IS_UNAPPLIED_UPDATE));
3241 EXPECT_NE(entry.Get(META_HANDLE), metahandle); 3257 EXPECT_NE(entry.Get(META_HANDLE), metahandle);
3242 } 3258 }
3243 } 3259 }
3244 3260
3245 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) { 3261 TEST_F(SyncerTest, TestMoveSanitizedNamedFolder) {
3246 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1); 3262 mock_server_->AddUpdateDirectory(1, 0, "foo", 1, 1);
3247 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2); 3263 mock_server_->AddUpdateDirectory(2, 0, ":::", 1, 2);
3248 SyncShareAsDelegate(); 3264 SyncShareNudge();
3249 { 3265 {
3250 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3266 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3251 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2)); 3267 MutableEntry entry(&trans, GET_BY_ID, ids_.FromNumber(2));
3252 ASSERT_TRUE(entry.good()); 3268 ASSERT_TRUE(entry.good());
3253 EXPECT_TRUE(entry.Put(PARENT_ID, ids_.FromNumber(1))); 3269 EXPECT_TRUE(entry.Put(PARENT_ID, ids_.FromNumber(1)));
3254 EXPECT_TRUE(entry.Put(IS_UNSYNCED, true)); 3270 EXPECT_TRUE(entry.Put(IS_UNSYNCED, true));
3255 } 3271 }
3256 SyncShareAsDelegate(); 3272 SyncShareNudge();
3257 // We use the same sync ts as before so our times match up. 3273 // We use the same sync ts as before so our times match up.
3258 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2); 3274 mock_server_->AddUpdateDirectory(2, 1, ":::", 2, 2);
3259 SyncShareAsDelegate(); 3275 SyncShareNudge();
3260 } 3276 }
3261 3277
3262 // Don't crash when this occurs. 3278 // Don't crash when this occurs.
3263 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) { 3279 TEST_F(SyncerTest, UpdateWhereParentIsNotAFolder) {
3264 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10); 3280 mock_server_->AddUpdateBookmark(1, 0, "B", 10, 10);
3265 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10); 3281 mock_server_->AddUpdateDirectory(2, 1, "BookmarkParent", 10, 10);
3266 // Used to cause a CHECK 3282 // Used to cause a CHECK
3267 SyncShareAsDelegate(); 3283 SyncShareNudge();
3268 { 3284 {
3269 ReadTransaction rtrans(FROM_HERE, directory()); 3285 ReadTransaction rtrans(FROM_HERE, directory());
3270 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); 3286 Entry good_entry(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1));
3271 ASSERT_TRUE(good_entry.good()); 3287 ASSERT_TRUE(good_entry.good());
3272 EXPECT_FALSE(good_entry.Get(IS_UNAPPLIED_UPDATE)); 3288 EXPECT_FALSE(good_entry.Get(IS_UNAPPLIED_UPDATE));
3273 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); 3289 Entry bad_parent(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2));
3274 ASSERT_TRUE(bad_parent.good()); 3290 ASSERT_TRUE(bad_parent.good());
3275 EXPECT_TRUE(bad_parent.Get(IS_UNAPPLIED_UPDATE)); 3291 EXPECT_TRUE(bad_parent.Get(IS_UNAPPLIED_UPDATE));
3276 } 3292 }
3277 } 3293 }
3278 3294
3279 const char kRootId[] = "0"; 3295 const char kRootId[] = "0";
3280 3296
3281 TEST_F(SyncerTest, DirectoryUpdateTest) { 3297 TEST_F(SyncerTest, DirectoryUpdateTest) {
3282 Id in_root_id = ids_.NewServerId(); 3298 Id in_root_id = ids_.NewServerId();
3283 Id in_in_root_id = ids_.NewServerId(); 3299 Id in_in_root_id = ids_.NewServerId();
3284 3300
3285 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(), 3301 mock_server_->AddUpdateDirectory(in_root_id, TestIdFactory::root(),
3286 "in_root_name", 2, 2); 3302 "in_root_name", 2, 2);
3287 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id, 3303 mock_server_->AddUpdateDirectory(in_in_root_id, in_root_id,
3288 "in_in_root_name", 3, 3); 3304 "in_in_root_name", 3, 3);
3289 SyncShareAsDelegate(); 3305 SyncShareNudge();
3290 { 3306 {
3291 ReadTransaction trans(FROM_HERE, directory()); 3307 ReadTransaction trans(FROM_HERE, directory());
3292 Entry in_root(&trans, GET_BY_ID, in_root_id); 3308 Entry in_root(&trans, GET_BY_ID, in_root_id);
3293 ASSERT_TRUE(in_root.good()); 3309 ASSERT_TRUE(in_root.good());
3294 EXPECT_EQ("in_root_name", in_root.Get(NON_UNIQUE_NAME)); 3310 EXPECT_EQ("in_root_name", in_root.Get(NON_UNIQUE_NAME));
3295 EXPECT_EQ(TestIdFactory::root(), in_root.Get(PARENT_ID)); 3311 EXPECT_EQ(TestIdFactory::root(), in_root.Get(PARENT_ID));
3296 3312
3297 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id); 3313 Entry in_in_root(&trans, GET_BY_ID, in_in_root_id);
3298 ASSERT_TRUE(in_in_root.good()); 3314 ASSERT_TRUE(in_in_root.good());
3299 EXPECT_EQ("in_in_root_name", in_in_root.Get(NON_UNIQUE_NAME)); 3315 EXPECT_EQ("in_in_root_name", in_in_root.Get(NON_UNIQUE_NAME));
(...skipping 17 matching lines...) Expand all
3317 foo_metahandle = parent.Get(META_HANDLE); 3333 foo_metahandle = parent.Get(META_HANDLE);
3318 3334
3319 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar"); 3335 MutableEntry child(&wtrans, syncable::CREATE, parent.Get(ID), "bar");
3320 ASSERT_TRUE(child.good()); 3336 ASSERT_TRUE(child.good());
3321 child.Put(syncable::IS_UNSYNCED, true); 3337 child.Put(syncable::IS_UNSYNCED, true);
3322 child.Put(syncable::IS_DIR, true); 3338 child.Put(syncable::IS_DIR, true);
3323 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 3339 child.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
3324 bar_metahandle = child.Get(META_HANDLE); 3340 bar_metahandle = child.Get(META_HANDLE);
3325 in_dir_id = parent.Get(syncable::ID); 3341 in_dir_id = parent.Get(syncable::ID);
3326 } 3342 }
3327 SyncShareAsDelegate(); 3343 SyncShareNudge();
3328 { 3344 {
3329 ReadTransaction trans(FROM_HERE, directory()); 3345 ReadTransaction trans(FROM_HERE, directory());
3330 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id); 3346 Entry fail_by_old_id_entry(&trans, GET_BY_ID, in_root_id);
3331 ASSERT_FALSE(fail_by_old_id_entry.good()); 3347 ASSERT_FALSE(fail_by_old_id_entry.good());
3332 3348
3333 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle); 3349 Entry foo_entry(&trans, GET_BY_HANDLE, foo_metahandle);
3334 ASSERT_TRUE(foo_entry.good()); 3350 ASSERT_TRUE(foo_entry.good());
3335 EXPECT_EQ("foo", foo_entry.Get(NON_UNIQUE_NAME)); 3351 EXPECT_EQ("foo", foo_entry.Get(NON_UNIQUE_NAME));
3336 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id); 3352 EXPECT_NE(foo_entry.Get(syncable::ID), in_root_id);
3337 3353
3338 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle); 3354 Entry bar_entry(&trans, GET_BY_HANDLE, bar_metahandle);
3339 ASSERT_TRUE(bar_entry.good()); 3355 ASSERT_TRUE(bar_entry.good());
3340 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME)); 3356 EXPECT_EQ("bar", bar_entry.Get(NON_UNIQUE_NAME));
3341 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id); 3357 EXPECT_NE(bar_entry.Get(syncable::ID), in_dir_id);
3342 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID)); 3358 EXPECT_EQ(foo_entry.Get(syncable::ID), bar_entry.Get(PARENT_ID));
3343 } 3359 }
3344 } 3360 }
3345 3361
3346 TEST_F(SyncerTest, TestClientCommand) { 3362 TEST_F(SyncerTest, TestClientCommand) {
3347 using sync_pb::ClientCommand; 3363 using sync_pb::ClientCommand;
3348 3364
3349 ClientCommand* command = mock_server_->GetNextClientCommand(); 3365 ClientCommand* command = mock_server_->GetNextClientCommand();
3350 command->set_set_sync_poll_interval(8); 3366 command->set_set_sync_poll_interval(8);
3351 command->set_set_sync_long_poll_interval(800); 3367 command->set_set_sync_long_poll_interval(800);
3352 command->set_sessions_commit_delay_seconds(3141); 3368 command->set_sessions_commit_delay_seconds(3141);
3353 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); 3369 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1);
3354 SyncShareAsDelegate(); 3370 SyncShareNudge();
3355 3371
3356 EXPECT_TRUE(TimeDelta::FromSeconds(8) == 3372 EXPECT_TRUE(TimeDelta::FromSeconds(8) ==
3357 last_short_poll_interval_received_); 3373 last_short_poll_interval_received_);
3358 EXPECT_TRUE(TimeDelta::FromSeconds(800) == 3374 EXPECT_TRUE(TimeDelta::FromSeconds(800) ==
3359 last_long_poll_interval_received_); 3375 last_long_poll_interval_received_);
3360 EXPECT_TRUE(TimeDelta::FromSeconds(3141) == 3376 EXPECT_TRUE(TimeDelta::FromSeconds(3141) ==
3361 last_sessions_commit_delay_seconds_); 3377 last_sessions_commit_delay_seconds_);
3362 3378
3363 command = mock_server_->GetNextClientCommand(); 3379 command = mock_server_->GetNextClientCommand();
3364 command->set_set_sync_poll_interval(180); 3380 command->set_set_sync_poll_interval(180);
3365 command->set_set_sync_long_poll_interval(190); 3381 command->set_set_sync_long_poll_interval(190);
3366 command->set_sessions_commit_delay_seconds(2718); 3382 command->set_sessions_commit_delay_seconds(2718);
3367 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1); 3383 mock_server_->AddUpdateDirectory(1, 0, "in_root", 1, 1);
3368 SyncShareAsDelegate(); 3384 SyncShareNudge();
3369 3385
3370 EXPECT_TRUE(TimeDelta::FromSeconds(180) == 3386 EXPECT_TRUE(TimeDelta::FromSeconds(180) ==
3371 last_short_poll_interval_received_); 3387 last_short_poll_interval_received_);
3372 EXPECT_TRUE(TimeDelta::FromSeconds(190) == 3388 EXPECT_TRUE(TimeDelta::FromSeconds(190) ==
3373 last_long_poll_interval_received_); 3389 last_long_poll_interval_received_);
3374 EXPECT_TRUE(TimeDelta::FromSeconds(2718) == 3390 EXPECT_TRUE(TimeDelta::FromSeconds(2718) ==
3375 last_sessions_commit_delay_seconds_); 3391 last_sessions_commit_delay_seconds_);
3376 } 3392 }
3377 3393
3378 TEST_F(SyncerTest, EnsureWeSendUpOldParent) { 3394 TEST_F(SyncerTest, EnsureWeSendUpOldParent) {
3379 syncable::Id folder_one_id = ids_.FromNumber(1); 3395 syncable::Id folder_one_id = ids_.FromNumber(1);
3380 syncable::Id folder_two_id = ids_.FromNumber(2); 3396 syncable::Id folder_two_id = ids_.FromNumber(2);
3381 3397
3382 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(), 3398 mock_server_->AddUpdateDirectory(folder_one_id, TestIdFactory::root(),
3383 "folder_one", 1, 1); 3399 "folder_one", 1, 1);
3384 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(), 3400 mock_server_->AddUpdateDirectory(folder_two_id, TestIdFactory::root(),
3385 "folder_two", 1, 1); 3401 "folder_two", 1, 1);
3386 SyncShareAsDelegate(); 3402 SyncShareNudge();
3387 { 3403 {
3388 // A moved entry should send an "old parent." 3404 // A moved entry should send an "old parent."
3389 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3405 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3390 MutableEntry entry(&trans, GET_BY_ID, folder_one_id); 3406 MutableEntry entry(&trans, GET_BY_ID, folder_one_id);
3391 ASSERT_TRUE(entry.good()); 3407 ASSERT_TRUE(entry.good());
3392 entry.Put(PARENT_ID, folder_two_id); 3408 entry.Put(PARENT_ID, folder_two_id);
3393 entry.Put(IS_UNSYNCED, true); 3409 entry.Put(IS_UNSYNCED, true);
3394 // A new entry should send no "old parent." 3410 // A new entry should send no "old parent."
3395 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder"); 3411 MutableEntry create(&trans, CREATE, trans.root_id(), "new_folder");
3396 create.Put(IS_UNSYNCED, true); 3412 create.Put(IS_UNSYNCED, true);
3397 create.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3413 create.Put(SPECIFICS, DefaultBookmarkSpecifics());
3398 } 3414 }
3399 SyncShareAsDelegate(); 3415 SyncShareNudge();
3400 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit(); 3416 const sync_pb::CommitMessage& commit = mock_server_->last_sent_commit();
3401 ASSERT_EQ(2, commit.entries_size()); 3417 ASSERT_EQ(2, commit.entries_size());
3402 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2"); 3418 EXPECT_TRUE(commit.entries(0).parent_id_string() == "2");
3403 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0"); 3419 EXPECT_TRUE(commit.entries(0).old_parent_id() == "0");
3404 EXPECT_FALSE(commit.entries(1).has_old_parent_id()); 3420 EXPECT_FALSE(commit.entries(1).has_old_parent_id());
3405 } 3421 }
3406 3422
3407 TEST_F(SyncerTest, Test64BitVersionSupport) { 3423 TEST_F(SyncerTest, Test64BitVersionSupport) {
3408 int64 really_big_int = std::numeric_limits<int64>::max() - 12; 3424 int64 really_big_int = std::numeric_limits<int64>::max() - 12;
3409 const string name("ringo's dang orang ran rings around my o-ring"); 3425 const string name("ringo's dang orang ran rings around my o-ring");
(...skipping 14 matching lines...) Expand all
3424 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle); 3440 Entry entry(&rtrans, syncable::GET_BY_HANDLE, item_metahandle);
3425 ASSERT_TRUE(entry.good()); 3441 ASSERT_TRUE(entry.good());
3426 EXPECT_TRUE(really_big_int == entry.Get(syncable::BASE_VERSION)); 3442 EXPECT_TRUE(really_big_int == entry.Get(syncable::BASE_VERSION));
3427 } 3443 }
3428 3444
3429 TEST_F(SyncerTest, TestSimpleUndelete) { 3445 TEST_F(SyncerTest, TestSimpleUndelete) {
3430 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 3446 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
3431 mock_server_->set_conflict_all_commits(true); 3447 mock_server_->set_conflict_all_commits(true);
3432 // Let there be an entry from the server. 3448 // Let there be an entry from the server.
3433 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10); 3449 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10);
3434 SyncShareAsDelegate(); 3450 SyncShareNudge();
3435 // Check it out and delete it. 3451 // Check it out and delete it.
3436 { 3452 {
3437 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3453 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3438 MutableEntry entry(&wtrans, GET_BY_ID, id); 3454 MutableEntry entry(&wtrans, GET_BY_ID, id);
3439 ASSERT_TRUE(entry.good()); 3455 ASSERT_TRUE(entry.good());
3440 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3456 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3441 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3457 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3442 EXPECT_FALSE(entry.Get(IS_DEL)); 3458 EXPECT_FALSE(entry.Get(IS_DEL));
3443 // Delete it locally. 3459 // Delete it locally.
3444 entry.Put(IS_DEL, true); 3460 entry.Put(IS_DEL, true);
3445 } 3461 }
3446 SyncShareAsDelegate(); 3462 SyncShareNudge();
3447 // Confirm we see IS_DEL and not SERVER_IS_DEL. 3463 // Confirm we see IS_DEL and not SERVER_IS_DEL.
3448 { 3464 {
3449 ReadTransaction trans(FROM_HERE, directory()); 3465 ReadTransaction trans(FROM_HERE, directory());
3450 Entry entry(&trans, GET_BY_ID, id); 3466 Entry entry(&trans, GET_BY_ID, id);
3451 ASSERT_TRUE(entry.good()); 3467 ASSERT_TRUE(entry.good());
3452 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3468 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3453 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3469 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3454 EXPECT_TRUE(entry.Get(IS_DEL)); 3470 EXPECT_TRUE(entry.Get(IS_DEL));
3455 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3471 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3456 } 3472 }
3457 SyncShareAsDelegate(); 3473 SyncShareNudge();
3458 // Update from server confirming deletion. 3474 // Update from server confirming deletion.
3459 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11); 3475 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 11);
3460 mock_server_->SetLastUpdateDeleted(); 3476 mock_server_->SetLastUpdateDeleted();
3461 SyncShareAsDelegate(); 3477 SyncShareNudge();
3462 // IS_DEL AND SERVER_IS_DEL now both true. 3478 // IS_DEL AND SERVER_IS_DEL now both true.
3463 { 3479 {
3464 ReadTransaction trans(FROM_HERE, directory()); 3480 ReadTransaction trans(FROM_HERE, directory());
3465 Entry entry(&trans, GET_BY_ID, id); 3481 Entry entry(&trans, GET_BY_ID, id);
3466 ASSERT_TRUE(entry.good()); 3482 ASSERT_TRUE(entry.good());
3467 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3483 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3468 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3484 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3469 EXPECT_TRUE(entry.Get(IS_DEL)); 3485 EXPECT_TRUE(entry.Get(IS_DEL));
3470 EXPECT_TRUE(entry.Get(SERVER_IS_DEL)); 3486 EXPECT_TRUE(entry.Get(SERVER_IS_DEL));
3471 } 3487 }
3472 // Undelete from server. 3488 // Undelete from server.
3473 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12); 3489 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12);
3474 SyncShareAsDelegate(); 3490 SyncShareNudge();
3475 // IS_DEL and SERVER_IS_DEL now both false. 3491 // IS_DEL and SERVER_IS_DEL now both false.
3476 { 3492 {
3477 ReadTransaction trans(FROM_HERE, directory()); 3493 ReadTransaction trans(FROM_HERE, directory());
3478 Entry entry(&trans, GET_BY_ID, id); 3494 Entry entry(&trans, GET_BY_ID, id);
3479 ASSERT_TRUE(entry.good()); 3495 ASSERT_TRUE(entry.good());
3480 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3496 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3481 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3497 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3482 EXPECT_FALSE(entry.Get(IS_DEL)); 3498 EXPECT_FALSE(entry.Get(IS_DEL));
3483 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3499 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3484 } 3500 }
3485 } 3501 }
3486 3502
3487 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) { 3503 TEST_F(SyncerTest, TestUndeleteWithMissingDeleteUpdate) {
3488 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root(); 3504 Id id = ids_.MakeServer("undeletion item"), root = TestIdFactory::root();
3489 // Let there be a entry, from the server. 3505 // Let there be a entry, from the server.
3490 mock_server_->set_conflict_all_commits(true); 3506 mock_server_->set_conflict_all_commits(true);
3491 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10); 3507 mock_server_->AddUpdateBookmark(id, root, "foo", 1, 10);
3492 SyncShareAsDelegate(); 3508 SyncShareNudge();
3493 // Check it out and delete it. 3509 // Check it out and delete it.
3494 { 3510 {
3495 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 3511 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
3496 MutableEntry entry(&wtrans, GET_BY_ID, id); 3512 MutableEntry entry(&wtrans, GET_BY_ID, id);
3497 ASSERT_TRUE(entry.good()); 3513 ASSERT_TRUE(entry.good());
3498 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3514 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3499 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3515 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3500 EXPECT_FALSE(entry.Get(IS_DEL)); 3516 EXPECT_FALSE(entry.Get(IS_DEL));
3501 // Delete it locally. 3517 // Delete it locally.
3502 entry.Put(IS_DEL, true); 3518 entry.Put(IS_DEL, true);
3503 } 3519 }
3504 SyncShareAsDelegate(); 3520 SyncShareNudge();
3505 // Confirm we see IS_DEL and not SERVER_IS_DEL. 3521 // Confirm we see IS_DEL and not SERVER_IS_DEL.
3506 { 3522 {
3507 ReadTransaction trans(FROM_HERE, directory()); 3523 ReadTransaction trans(FROM_HERE, directory());
3508 Entry entry(&trans, GET_BY_ID, id); 3524 Entry entry(&trans, GET_BY_ID, id);
3509 ASSERT_TRUE(entry.good()); 3525 ASSERT_TRUE(entry.good());
3510 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3526 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3511 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3527 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3512 EXPECT_TRUE(entry.Get(IS_DEL)); 3528 EXPECT_TRUE(entry.Get(IS_DEL));
3513 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3529 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3514 } 3530 }
3515 SyncShareAsDelegate(); 3531 SyncShareNudge();
3516 // Say we do not get an update from server confirming deletion. Undelete 3532 // Say we do not get an update from server confirming deletion. Undelete
3517 // from server 3533 // from server
3518 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12); 3534 mock_server_->AddUpdateBookmark(id, root, "foo", 2, 12);
3519 SyncShareAsDelegate(); 3535 SyncShareNudge();
3520 // IS_DEL and SERVER_IS_DEL now both false. 3536 // IS_DEL and SERVER_IS_DEL now both false.
3521 { 3537 {
3522 ReadTransaction trans(FROM_HERE, directory()); 3538 ReadTransaction trans(FROM_HERE, directory());
3523 Entry entry(&trans, GET_BY_ID, id); 3539 Entry entry(&trans, GET_BY_ID, id);
3524 ASSERT_TRUE(entry.good()); 3540 ASSERT_TRUE(entry.good());
3525 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE)); 3541 EXPECT_FALSE(entry.Get(IS_UNAPPLIED_UPDATE));
3526 EXPECT_FALSE(entry.Get(IS_UNSYNCED)); 3542 EXPECT_FALSE(entry.Get(IS_UNSYNCED));
3527 EXPECT_FALSE(entry.Get(IS_DEL)); 3543 EXPECT_FALSE(entry.Get(IS_DEL));
3528 EXPECT_FALSE(entry.Get(SERVER_IS_DEL)); 3544 EXPECT_FALSE(entry.Get(SERVER_IS_DEL));
3529 } 3545 }
3530 } 3546 }
3531 3547
3532 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) { 3548 TEST_F(SyncerTest, TestUndeleteIgnoreCorrectlyUnappliedUpdate) {
3533 Id id1 = ids_.MakeServer("first"), id2 = ids_.MakeServer("second"); 3549 Id id1 = ids_.MakeServer("first"), id2 = ids_.MakeServer("second");
3534 Id root = TestIdFactory::root(); 3550 Id root = TestIdFactory::root();
3535 // Duplicate! expect path clashing! 3551 // Duplicate! expect path clashing!
3536 mock_server_->set_conflict_all_commits(true); 3552 mock_server_->set_conflict_all_commits(true);
3537 mock_server_->AddUpdateBookmark(id1, root, "foo", 1, 10); 3553 mock_server_->AddUpdateBookmark(id1, root, "foo", 1, 10);
3538 mock_server_->AddUpdateBookmark(id2, root, "foo", 1, 10); 3554 mock_server_->AddUpdateBookmark(id2, root, "foo", 1, 10);
3539 SyncShareAsDelegate(); 3555 SyncShareNudge();
3540 mock_server_->AddUpdateBookmark(id2, root, "foo2", 2, 20); 3556 mock_server_->AddUpdateBookmark(id2, root, "foo2", 2, 20);
3541 SyncShareAsDelegate(); // Now just don't explode. 3557 SyncShareNudge(); // Now just don't explode.
3542 } 3558 }
3543 3559
3544 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) { 3560 TEST_F(SyncerTest, ClientTagServerCreatedUpdatesWork) {
3545 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10); 3561 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10);
3546 mock_server_->SetLastUpdateClientTag("permfolder"); 3562 mock_server_->SetLastUpdateClientTag("permfolder");
3547 3563
3548 SyncShareAsDelegate(); 3564 SyncShareNudge();
3549 3565
3550 { 3566 {
3551 ReadTransaction trans(FROM_HERE, directory()); 3567 ReadTransaction trans(FROM_HERE, directory());
3552 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 3568 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
3553 ASSERT_TRUE(perm_folder.good()); 3569 ASSERT_TRUE(perm_folder.good());
3554 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 3570 EXPECT_FALSE(perm_folder.Get(IS_DEL));
3555 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3571 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3556 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 3572 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
3557 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder"); 3573 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder");
3558 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1"); 3574 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1");
3559 } 3575 }
3560 3576
3561 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100); 3577 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100);
3562 mock_server_->SetLastUpdateClientTag("permfolder"); 3578 mock_server_->SetLastUpdateClientTag("permfolder");
3563 SyncShareAsDelegate(); 3579 SyncShareNudge();
3564 3580
3565 { 3581 {
3566 ReadTransaction trans(FROM_HERE, directory()); 3582 ReadTransaction trans(FROM_HERE, directory());
3567 3583
3568 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 3584 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
3569 ASSERT_TRUE(perm_folder.good()); 3585 ASSERT_TRUE(perm_folder.good());
3570 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 3586 EXPECT_FALSE(perm_folder.Get(IS_DEL));
3571 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3587 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3572 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 3588 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
3573 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder"); 3589 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder");
3574 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem_renamed"); 3590 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem_renamed");
3575 } 3591 }
3576 } 3592 }
3577 3593
3578 TEST_F(SyncerTest, ClientTagIllegalUpdateIgnored) { 3594 TEST_F(SyncerTest, ClientTagIllegalUpdateIgnored) {
3579 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10); 3595 mock_server_->AddUpdateDirectory(1, 0, "permitem1", 1, 10);
3580 mock_server_->SetLastUpdateClientTag("permfolder"); 3596 mock_server_->SetLastUpdateClientTag("permfolder");
3581 3597
3582 SyncShareAsDelegate(); 3598 SyncShareNudge();
3583 3599
3584 { 3600 {
3585 ReadTransaction trans(FROM_HERE, directory()); 3601 ReadTransaction trans(FROM_HERE, directory());
3586 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder"); 3602 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "permfolder");
3587 ASSERT_TRUE(perm_folder.good()); 3603 ASSERT_TRUE(perm_folder.good());
3588 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3604 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3589 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 3605 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
3590 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder"); 3606 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "permfolder");
3591 EXPECT_TRUE(perm_folder.Get(NON_UNIQUE_NAME) == "permitem1"); 3607 EXPECT_TRUE(perm_folder.Get(NON_UNIQUE_NAME) == "permitem1");
3592 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); 3608 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows());
3593 } 3609 }
3594 3610
3595 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100); 3611 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100);
3596 mock_server_->SetLastUpdateClientTag("wrongtag"); 3612 mock_server_->SetLastUpdateClientTag("wrongtag");
3597 SyncShareAsDelegate(); 3613 SyncShareNudge();
3598 3614
3599 { 3615 {
3600 ReadTransaction trans(FROM_HERE, directory()); 3616 ReadTransaction trans(FROM_HERE, directory());
3601 3617
3602 // This update is rejected because it has the same ID, but a 3618 // This update is rejected because it has the same ID, but a
3603 // different tag than one that is already on the client. 3619 // different tag than one that is already on the client.
3604 // The client has a ServerKnows ID, which cannot be overwritten. 3620 // The client has a ServerKnows ID, which cannot be overwritten.
3605 Entry rejected_update(&trans, GET_BY_CLIENT_TAG, "wrongtag"); 3621 Entry rejected_update(&trans, GET_BY_CLIENT_TAG, "wrongtag");
3606 EXPECT_FALSE(rejected_update.good()); 3622 EXPECT_FALSE(rejected_update.good());
3607 3623
(...skipping 24 matching lines...) Expand all
3632 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); 3648 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows());
3633 original_metahandle = perm_folder.Get(META_HANDLE); 3649 original_metahandle = perm_folder.Get(META_HANDLE);
3634 } 3650 }
3635 3651
3636 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100); 3652 mock_server_->AddUpdateBookmark(1, 0, "permitem_renamed", 10, 100);
3637 mock_server_->SetLastUpdateClientTag("clientperm"); 3653 mock_server_->SetLastUpdateClientTag("clientperm");
3638 mock_server_->GetMutableLastUpdate()->mutable_specifics()-> 3654 mock_server_->GetMutableLastUpdate()->mutable_specifics()->
3639 CopyFrom(server_bookmark); 3655 CopyFrom(server_bookmark);
3640 mock_server_->set_conflict_all_commits(true); 3656 mock_server_->set_conflict_all_commits(true);
3641 3657
3642 SyncShareAsDelegate(); 3658 SyncShareNudge();
3643 // This should cause client tag reunion, preserving the metahandle. 3659 // This should cause client tag reunion, preserving the metahandle.
3644 { 3660 {
3645 ReadTransaction trans(FROM_HERE, directory()); 3661 ReadTransaction trans(FROM_HERE, directory());
3646 3662
3647 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm"); 3663 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm");
3648 ASSERT_TRUE(perm_folder.good()); 3664 ASSERT_TRUE(perm_folder.good());
3649 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 3665 EXPECT_FALSE(perm_folder.Get(IS_DEL));
3650 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3666 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3651 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED)); 3667 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED));
3652 EXPECT_EQ(10, perm_folder.Get(BASE_VERSION)); 3668 EXPECT_EQ(10, perm_folder.Get(BASE_VERSION));
3653 // Entry should have been given the new ID while preserving the 3669 // Entry should have been given the new ID while preserving the
3654 // metahandle; client should have won the conflict resolution. 3670 // metahandle; client should have won the conflict resolution.
3655 EXPECT_EQ(original_metahandle, perm_folder.Get(META_HANDLE)); 3671 EXPECT_EQ(original_metahandle, perm_folder.Get(META_HANDLE));
3656 EXPECT_EQ("clientperm", perm_folder.Get(UNIQUE_CLIENT_TAG)); 3672 EXPECT_EQ("clientperm", perm_folder.Get(UNIQUE_CLIENT_TAG));
3657 EXPECT_EQ("clientname", perm_folder.Get(NON_UNIQUE_NAME)); 3673 EXPECT_EQ("clientname", perm_folder.Get(NON_UNIQUE_NAME));
3658 EXPECT_EQ(local_bookmark.SerializeAsString(), 3674 EXPECT_EQ(local_bookmark.SerializeAsString(),
3659 perm_folder.Get(SPECIFICS).SerializeAsString()); 3675 perm_folder.Get(SPECIFICS).SerializeAsString());
3660 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows()); 3676 EXPECT_TRUE(perm_folder.Get(ID).ServerKnows());
3661 } 3677 }
3662 3678
3663 mock_server_->set_conflict_all_commits(false); 3679 mock_server_->set_conflict_all_commits(false);
3664 SyncShareAsDelegate(); 3680 SyncShareNudge();
3665 3681
3666 // The resolved entry ought to commit cleanly. 3682 // The resolved entry ought to commit cleanly.
3667 { 3683 {
3668 ReadTransaction trans(FROM_HERE, directory()); 3684 ReadTransaction trans(FROM_HERE, directory());
3669 3685
3670 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm"); 3686 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm");
3671 ASSERT_TRUE(perm_folder.good()); 3687 ASSERT_TRUE(perm_folder.good());
3672 EXPECT_FALSE(perm_folder.Get(IS_DEL)); 3688 EXPECT_FALSE(perm_folder.Get(IS_DEL));
3673 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3689 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3674 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 3690 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
(...skipping 18 matching lines...) Expand all
3693 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); 3709 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm");
3694 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 3710 perm_folder.Put(SPECIFICS, DefaultBookmarkSpecifics());
3695 perm_folder.Put(IS_UNSYNCED, true); 3711 perm_folder.Put(IS_UNSYNCED, true);
3696 perm_folder.Put(IS_DEL, true); 3712 perm_folder.Put(IS_DEL, true);
3697 } 3713 }
3698 3714
3699 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100); 3715 mock_server_->AddUpdateDirectory(1, 0, "permitem_renamed", 10, 100);
3700 mock_server_->SetLastUpdateClientTag("clientperm"); 3716 mock_server_->SetLastUpdateClientTag("clientperm");
3701 mock_server_->set_conflict_all_commits(true); 3717 mock_server_->set_conflict_all_commits(true);
3702 3718
3703 SyncShareAsDelegate(); 3719 SyncShareNudge();
3704 // This should cause client tag overwrite. 3720 // This should cause client tag overwrite.
3705 { 3721 {
3706 ReadTransaction trans(FROM_HERE, directory()); 3722 ReadTransaction trans(FROM_HERE, directory());
3707 3723
3708 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm"); 3724 Entry perm_folder(&trans, GET_BY_CLIENT_TAG, "clientperm");
3709 ASSERT_TRUE(perm_folder.good()); 3725 ASSERT_TRUE(perm_folder.good());
3710 ASSERT_TRUE(perm_folder.Get(ID).ServerKnows()); 3726 ASSERT_TRUE(perm_folder.Get(ID).ServerKnows());
3711 EXPECT_TRUE(perm_folder.Get(IS_DEL)); 3727 EXPECT_TRUE(perm_folder.Get(IS_DEL));
3712 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3728 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3713 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED)); 3729 EXPECT_TRUE(perm_folder.Get(IS_UNSYNCED));
3714 EXPECT_EQ(perm_folder.Get(BASE_VERSION), 10); 3730 EXPECT_EQ(perm_folder.Get(BASE_VERSION), 10);
3715 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "clientperm"); 3731 EXPECT_EQ(perm_folder.Get(UNIQUE_CLIENT_TAG), "clientperm");
3716 } 3732 }
3717 } 3733 }
3718 3734
3719 TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) { 3735 TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) {
3720 // This test is written assuming that ID comparison 3736 // This test is written assuming that ID comparison
3721 // will work out in a particular way. 3737 // will work out in a particular way.
3722 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(2)); 3738 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(2));
3723 EXPECT_TRUE(ids_.FromNumber(3) < ids_.FromNumber(4)); 3739 EXPECT_TRUE(ids_.FromNumber(3) < ids_.FromNumber(4));
3724 3740
3725 mock_server_->AddUpdateBookmark(1, 0, "One", 10, 100); 3741 mock_server_->AddUpdateBookmark(1, 0, "One", 10, 100);
3726 mock_server_->SetLastUpdateClientTag("tag1"); 3742 mock_server_->SetLastUpdateClientTag("tag1");
3727 mock_server_->AddUpdateBookmark(4, 0, "Four", 11, 110); 3743 mock_server_->AddUpdateBookmark(4, 0, "Four", 11, 110);
3728 mock_server_->SetLastUpdateClientTag("tag2"); 3744 mock_server_->SetLastUpdateClientTag("tag2");
3729 3745
3730 mock_server_->set_conflict_all_commits(true); 3746 mock_server_->set_conflict_all_commits(true);
3731 3747
3732 SyncShareAsDelegate(); 3748 SyncShareNudge();
3733 int64 tag1_metahandle = syncable::kInvalidMetaHandle; 3749 int64 tag1_metahandle = syncable::kInvalidMetaHandle;
3734 int64 tag2_metahandle = syncable::kInvalidMetaHandle; 3750 int64 tag2_metahandle = syncable::kInvalidMetaHandle;
3735 // This should cause client tag overwrite. 3751 // This should cause client tag overwrite.
3736 { 3752 {
3737 ReadTransaction trans(FROM_HERE, directory()); 3753 ReadTransaction trans(FROM_HERE, directory());
3738 3754
3739 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); 3755 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1");
3740 ASSERT_TRUE(tag1.good()); 3756 ASSERT_TRUE(tag1.good());
3741 ASSERT_TRUE(tag1.Get(ID).ServerKnows()); 3757 ASSERT_TRUE(tag1.Get(ID).ServerKnows());
3742 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID)); 3758 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID));
(...skipping 19 matching lines...) Expand all
3762 3778
3763 syncable::Directory::ChildHandles children; 3779 syncable::Directory::ChildHandles children;
3764 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 3780 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
3765 ASSERT_EQ(2U, children.size()); 3781 ASSERT_EQ(2U, children.size());
3766 } 3782 }
3767 3783
3768 mock_server_->AddUpdateBookmark(2, 0, "Two", 12, 120); 3784 mock_server_->AddUpdateBookmark(2, 0, "Two", 12, 120);
3769 mock_server_->SetLastUpdateClientTag("tag1"); 3785 mock_server_->SetLastUpdateClientTag("tag1");
3770 mock_server_->AddUpdateBookmark(3, 0, "Three", 13, 130); 3786 mock_server_->AddUpdateBookmark(3, 0, "Three", 13, 130);
3771 mock_server_->SetLastUpdateClientTag("tag2"); 3787 mock_server_->SetLastUpdateClientTag("tag2");
3772 SyncShareAsDelegate(); 3788 SyncShareNudge();
3773 3789
3774 { 3790 {
3775 ReadTransaction trans(FROM_HERE, directory()); 3791 ReadTransaction trans(FROM_HERE, directory());
3776 3792
3777 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); 3793 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1");
3778 ASSERT_TRUE(tag1.good()); 3794 ASSERT_TRUE(tag1.good());
3779 ASSERT_TRUE(tag1.Get(ID).ServerKnows()); 3795 ASSERT_TRUE(tag1.Get(ID).ServerKnows());
3780 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID)) 3796 ASSERT_TRUE(ids_.FromNumber(1) == tag1.Get(ID))
3781 << "ID 1 should be kept, since it was less than ID 2."; 3797 << "ID 1 should be kept, since it was less than ID 2.";
3782 EXPECT_FALSE(tag1.Get(IS_DEL)); 3798 EXPECT_FALSE(tag1.Get(IS_DEL));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
3834 mock_server_->SetLastUpdateClientTag("tag c"); 3850 mock_server_->SetLastUpdateClientTag("tag c");
3835 mock_server_->AddUpdateBookmark(202, 0, "Two C", 19, 190); 3851 mock_server_->AddUpdateBookmark(202, 0, "Two C", 19, 190);
3836 mock_server_->SetLastUpdateClientTag("tag c"); 3852 mock_server_->SetLastUpdateClientTag("tag c");
3837 mock_server_->AddUpdateBookmark(204, 0, "Three C", 20, 200); 3853 mock_server_->AddUpdateBookmark(204, 0, "Three C", 20, 200);
3838 mock_server_->SetLastUpdateClientTag("tag c"); 3854 mock_server_->SetLastUpdateClientTag("tag c");
3839 mock_server_->AddUpdateBookmark(201, 0, "Four C", 21, 210); 3855 mock_server_->AddUpdateBookmark(201, 0, "Four C", 21, 210);
3840 mock_server_->SetLastUpdateClientTag("tag c"); // Least ID: winner. 3856 mock_server_->SetLastUpdateClientTag("tag c"); // Least ID: winner.
3841 3857
3842 mock_server_->set_conflict_all_commits(true); 3858 mock_server_->set_conflict_all_commits(true);
3843 3859
3844 SyncShareAsDelegate(); 3860 SyncShareNudge();
3845 // This should cause client tag overwrite. 3861 // This should cause client tag overwrite.
3846 { 3862 {
3847 ReadTransaction trans(FROM_HERE, directory()); 3863 ReadTransaction trans(FROM_HERE, directory());
3848 3864
3849 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a"); 3865 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a");
3850 ASSERT_TRUE(tag_a.good()); 3866 ASSERT_TRUE(tag_a.good());
3851 EXPECT_TRUE(tag_a.Get(ID).ServerKnows()); 3867 EXPECT_TRUE(tag_a.Get(ID).ServerKnows());
3852 EXPECT_EQ(ids_.FromNumber(1), tag_a.Get(ID)); 3868 EXPECT_EQ(ids_.FromNumber(1), tag_a.Get(ID));
3853 EXPECT_FALSE(tag_a.Get(IS_DEL)); 3869 EXPECT_FALSE(tag_a.Get(IS_DEL));
3854 EXPECT_FALSE(tag_a.Get(IS_UNAPPLIED_UPDATE)); 3870 EXPECT_FALSE(tag_a.Get(IS_UNAPPLIED_UPDATE));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3902 EXPECT_FALSE(tag_alpha.good()); 3918 EXPECT_FALSE(tag_alpha.good());
3903 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob"); 3919 Entry tag_bob(&trans, GET_BY_SERVER_TAG, "bob");
3904 EXPECT_FALSE(tag_bob.good()); 3920 EXPECT_FALSE(tag_bob.good());
3905 } 3921 }
3906 3922
3907 // Now download some tagged items as updates. 3923 // Now download some tagged items as updates.
3908 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10); 3924 mock_server_->AddUpdateDirectory(1, 0, "update1", 1, 10);
3909 mock_server_->SetLastUpdateServerTag("alpha"); 3925 mock_server_->SetLastUpdateServerTag("alpha");
3910 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20); 3926 mock_server_->AddUpdateDirectory(2, 0, "update2", 2, 20);
3911 mock_server_->SetLastUpdateServerTag("bob"); 3927 mock_server_->SetLastUpdateServerTag("bob");
3912 SyncShareAsDelegate(); 3928 SyncShareNudge();
3913 3929
3914 { 3930 {
3915 ReadTransaction trans(FROM_HERE, directory()); 3931 ReadTransaction trans(FROM_HERE, directory());
3916 3932
3917 // The new items should be applied as new entries, and we should be able 3933 // The new items should be applied as new entries, and we should be able
3918 // to look them up by their tag values. 3934 // to look them up by their tag values.
3919 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha"); 3935 Entry tag_alpha(&trans, GET_BY_SERVER_TAG, "alpha");
3920 ASSERT_TRUE(tag_alpha.good()); 3936 ASSERT_TRUE(tag_alpha.good());
3921 ASSERT_TRUE(!tag_alpha.Get(IS_DEL)); 3937 ASSERT_TRUE(!tag_alpha.Get(IS_DEL));
3922 ASSERT_TRUE(tag_alpha.Get(UNIQUE_SERVER_TAG) == "alpha"); 3938 ASSERT_TRUE(tag_alpha.Get(UNIQUE_SERVER_TAG) == "alpha");
(...skipping 10 matching lines...) Expand all
3933 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty()); 3949 ASSERT_TRUE(hurdle.Get(UNIQUE_SERVER_TAG).empty());
3934 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob"); 3950 ASSERT_TRUE(hurdle.Get(NON_UNIQUE_NAME) == "bob");
3935 } 3951 }
3936 } 3952 }
3937 3953
3938 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) { 3954 TEST_F(SyncerTest, GetUpdatesSetsRequestedTypes) {
3939 // The expectations of this test happen in the MockConnectionManager's 3955 // The expectations of this test happen in the MockConnectionManager's
3940 // GetUpdates handler. EnableDatatype sets the expectation value from our 3956 // GetUpdates handler. EnableDatatype sets the expectation value from our
3941 // set of enabled/disabled datatypes. 3957 // set of enabled/disabled datatypes.
3942 EnableDatatype(syncable::BOOKMARKS); 3958 EnableDatatype(syncable::BOOKMARKS);
3943 SyncShareAsDelegate(); 3959 SyncShareNudge();
3944 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 3960 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
3945 3961
3946 EnableDatatype(syncable::AUTOFILL); 3962 EnableDatatype(syncable::AUTOFILL);
3947 SyncShareAsDelegate(); 3963 SyncShareNudge();
3948 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 3964 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
3949 3965
3950 EnableDatatype(syncable::PREFERENCES); 3966 EnableDatatype(syncable::PREFERENCES);
3951 SyncShareAsDelegate(); 3967 SyncShareNudge();
3952 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 3968 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
3953 3969
3954 DisableDatatype(syncable::BOOKMARKS); 3970 DisableDatatype(syncable::BOOKMARKS);
3955 SyncShareAsDelegate(); 3971 SyncShareNudge();
3956 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 3972 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
3957 3973
3958 DisableDatatype(syncable::AUTOFILL); 3974 DisableDatatype(syncable::AUTOFILL);
3959 SyncShareAsDelegate(); 3975 SyncShareNudge();
3960 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 3976 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
3961 3977
3962 DisableDatatype(syncable::PREFERENCES); 3978 DisableDatatype(syncable::PREFERENCES);
3963 EnableDatatype(syncable::AUTOFILL); 3979 EnableDatatype(syncable::AUTOFILL);
3964 SyncShareAsDelegate(); 3980 SyncShareNudge();
3965 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 3981 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
3966 } 3982 }
3967 3983
3984 // A typical scenario: server and client each have one update for the other.
3985 // It is the "happy path" alternative to the test below.
3986 TEST_F(SyncerTest, UpdateThenCommit) {
3987 syncable::Id to_receive = ids_.NewServerId();
3988 syncable::Id to_commit = ids_.NewLocalId();
3989
3990 mock_server_->AddUpdateDirectory(to_receive, ids_.root(), "x", 1, 10);
3991 int64 commit_handle = CreateUnsyncedDirectory("y", to_commit);
3992 SyncShareNudge();
3993
3994 ReadTransaction trans(FROM_HERE, directory());
3995
3996 Entry received(&trans, GET_BY_ID, to_receive);
3997 ASSERT_TRUE(received.good());
3998 EXPECT_FALSE(received.Get(IS_UNSYNCED));
3999 EXPECT_FALSE(received.Get(IS_UNAPPLIED_UPDATE));
4000
4001 Entry committed(&trans, GET_BY_HANDLE, commit_handle);
4002 ASSERT_TRUE(committed.good());
4003 EXPECT_FALSE(committed.Get(IS_UNSYNCED));
4004 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE));
4005 }
4006
4007 // Same as above, but this time we fail to download updates.
4008 // We should not attempt to commit anything unless we successfully downloaded
4009 // updates, otherwise we risk causing a server-side conflict.
4010 TEST_F(SyncerTest, UpdateFailsThenDontCommit) {
4011 syncable::Id to_receive = ids_.NewServerId();
4012 syncable::Id to_commit = ids_.NewLocalId();
4013
4014 mock_server_->AddUpdateDirectory(to_receive, ids_.root(), "x", 1, 10);
4015 int64 commit_handle = CreateUnsyncedDirectory("y", to_commit);
4016 mock_server_->FailNextPostBufferToPathCall();
4017 SyncShareNudge();
4018
4019 ReadTransaction trans(FROM_HERE, directory());
4020
4021 // We did not receive this update.
4022 Entry received(&trans, GET_BY_ID, to_receive);
4023 ASSERT_FALSE(received.good());
4024
4025 // And our local update remains unapplied.
4026 Entry committed(&trans, GET_BY_HANDLE, commit_handle);
4027 ASSERT_TRUE(committed.good());
4028 EXPECT_TRUE(committed.Get(IS_UNSYNCED));
4029 EXPECT_FALSE(committed.Get(IS_UNAPPLIED_UPDATE));
4030
4031 // Inform the Mock we won't be fetching all updates.
4032 mock_server_->ClearUpdatesQueue();
4033 }
4034
4035 // Downloads two updates and applies them successfully.
4036 // This is the "happy path" alternative to the test below.
4037 TEST_F(SyncerTest, ConfigureDownloadsTwoBatchesSuccess) {
4038 syncable::Id node1 = ids_.NewServerId();
4039 syncable::Id node2 = ids_.NewServerId();
4040
4041 // Construct the first GetUpdates response.
4042 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10);
4043 mock_server_->SetChangesRemaining(1);
4044 mock_server_->NextUpdateBatch();
4045
4046 // Construct the second GetUpdates response.
4047 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20);
4048
4049 SyncShareConfigure();
4050
4051 ReadTransaction trans(FROM_HERE, directory());
4052 // Both nodes should be downloaded and applied.
4053
4054 Entry n1(&trans, GET_BY_ID, node1);
4055 ASSERT_TRUE(n1.good());
4056 EXPECT_FALSE(n1.Get(IS_UNAPPLIED_UPDATE));
4057
4058 Entry n2(&trans, GET_BY_ID, node2);
4059 ASSERT_TRUE(n2.good());
4060 EXPECT_FALSE(n2.Get(IS_UNAPPLIED_UPDATE));
4061 }
4062
4063 // Same as the above case, but this time the second batch fails to download.
4064 TEST_F(SyncerTest, ConfigureFailsDontApplyUpdates) {
4065 syncable::Id node1 = ids_.NewServerId();
4066 syncable::Id node2 = ids_.NewServerId();
4067
4068 // The scenario: we have two batches of updates with one update each. A
4069 // normal confgure step would download all the updates one batch at a time and
4070 // apply them. This configure will succeed in downloading the first batch
4071 // then fail when downloading the second.
4072 mock_server_->FailNthPostBufferToPathCall(2);
4073
4074 // Construct the first GetUpdates response.
4075 mock_server_->AddUpdateDirectory(node1, ids_.root(), "one", 1, 10);
4076 mock_server_->SetChangesRemaining(1);
4077 mock_server_->NextUpdateBatch();
4078
4079 // Consutrct the second GetUpdates response.
4080 mock_server_->AddUpdateDirectory(node2, ids_.root(), "two", 1, 20);
4081
4082 SyncShareConfigure();
4083
4084 ReadTransaction trans(FROM_HERE, directory());
4085
4086 // The first node was downloaded, but not applied.
4087 Entry n1(&trans, GET_BY_ID, node1);
4088 ASSERT_TRUE(n1.good());
4089 EXPECT_TRUE(n1.Get(IS_UNAPPLIED_UPDATE));
4090
4091 // The second node was not downloaded.
4092 Entry n2(&trans, GET_BY_ID, node2);
4093 EXPECT_FALSE(n2.good());
4094
4095 // One update remains undownloaded.
4096 mock_server_->ClearUpdatesQueue();
4097 }
4098
3968 // Test what happens if a client deletes, then recreates, an object very 4099 // Test what happens if a client deletes, then recreates, an object very
3969 // quickly. It is possible that the deletion gets sent as a commit, and 4100 // quickly. It is possible that the deletion gets sent as a commit, and
3970 // the undelete happens during the commit request. The principle here 4101 // the undelete happens during the commit request. The principle here
3971 // is that with a single committing client, conflicts should never 4102 // is that with a single committing client, conflicts should never
3972 // be encountered, and a client encountering its past actions during 4103 // be encountered, and a client encountering its past actions during
3973 // getupdates should never feed back to override later actions. 4104 // getupdates should never feed back to override later actions.
3974 // 4105 //
3975 // In cases of ordering A-F below, the outcome should be the same. 4106 // In cases of ordering A-F below, the outcome should be the same.
3976 // Exercised by UndeleteDuringCommit: 4107 // Exercised by UndeleteDuringCommit:
3977 // A. Delete - commit - undelete - commitresponse. 4108 // A. Delete - commit - undelete - commitresponse.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
4095 } 4226 }
4096 4227
4097 protected: 4228 protected:
4098 const std::string client_tag_; 4229 const std::string client_tag_;
4099 int64 metahandle_; 4230 int64 metahandle_;
4100 }; 4231 };
4101 4232
4102 TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) { 4233 TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) {
4103 Create(); 4234 Create();
4104 ExpectUnsyncedCreation(); 4235 ExpectUnsyncedCreation();
4105 SyncShareAsDelegate(); 4236 SyncShareNudge();
4106 4237
4107 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4238 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4108 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4239 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4109 ExpectSyncedAndCreated(); 4240 ExpectSyncedAndCreated();
4110 4241
4111 // Delete, begin committing the delete, then undelete while committing. 4242 // Delete, begin committing the delete, then undelete while committing.
4112 Delete(); 4243 Delete();
4113 ExpectUnsyncedDeletion(); 4244 ExpectUnsyncedDeletion();
4114 mock_server_->SetMidCommitCallback( 4245 mock_server_->SetMidCommitCallback(
4115 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this))); 4246 base::Bind(&SyncerUndeletionTest::Undelete, base::Unretained(this)));
4116 SyncShareAsDelegate(); 4247 SyncShareNudge();
4117 4248
4118 // The item ought to exist as an unsynced undeletion (meaning, 4249 // The item ought to exist as an unsynced undeletion (meaning,
4119 // we think that the next commit ought to be a recreation commit). 4250 // we think that the next commit ought to be a recreation commit).
4120 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4251 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4121 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4252 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4122 ExpectUnsyncedUndeletion(); 4253 ExpectUnsyncedUndeletion();
4123 4254
4124 // Now, encounter a GetUpdates corresponding to the deletion from 4255 // Now, encounter a GetUpdates corresponding to the deletion from
4125 // the server. The undeletion should prevail again and be committed. 4256 // the server. The undeletion should prevail again and be committed.
4126 // None of this should trigger any conflict detection -- it is perfectly 4257 // None of this should trigger any conflict detection -- it is perfectly
4127 // normal to recieve updates from our own commits. 4258 // normal to recieve updates from our own commits.
4128 mock_server_->SetMidCommitCallback(base::Closure()); 4259 mock_server_->SetMidCommitCallback(base::Closure());
4129 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); 4260 mock_server_->AddUpdateTombstone(Get(metahandle_, ID));
4130 SyncShareAsDelegate(); 4261 SyncShareNudge();
4131 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4262 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4132 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4263 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4133 ExpectSyncedAndCreated(); 4264 ExpectSyncedAndCreated();
4134 } 4265 }
4135 4266
4136 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { 4267 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) {
4137 Create(); 4268 Create();
4138 ExpectUnsyncedCreation(); 4269 ExpectUnsyncedCreation();
4139 SyncShareAsDelegate(); 4270 SyncShareNudge();
4140 4271
4141 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4272 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4142 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4273 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4143 ExpectSyncedAndCreated(); 4274 ExpectSyncedAndCreated();
4144 4275
4145 // Delete and undelete, then sync to pick up the result. 4276 // Delete and undelete, then sync to pick up the result.
4146 Delete(); 4277 Delete();
4147 ExpectUnsyncedDeletion(); 4278 ExpectUnsyncedDeletion();
4148 Undelete(); 4279 Undelete();
4149 ExpectUnsyncedEdit(); // Edit, not undelete: server thinks it exists. 4280 ExpectUnsyncedEdit(); // Edit, not undelete: server thinks it exists.
4150 SyncShareAsDelegate(); 4281 SyncShareNudge();
4151 4282
4152 // The item ought to have committed successfully. 4283 // The item ought to have committed successfully.
4153 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4284 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4154 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4285 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4155 ExpectSyncedAndCreated(); 4286 ExpectSyncedAndCreated();
4156 EXPECT_EQ(2, Get(metahandle_, BASE_VERSION)); 4287 EXPECT_EQ(2, Get(metahandle_, BASE_VERSION));
4157 4288
4158 // Now, encounter a GetUpdates corresponding to the just-committed 4289 // Now, encounter a GetUpdates corresponding to the just-committed
4159 // update. 4290 // update.
4160 mock_server_->AddUpdateFromLastCommit(); 4291 mock_server_->AddUpdateFromLastCommit();
4161 SyncShareAsDelegate(); 4292 SyncShareNudge();
4162 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4293 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4163 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4294 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4164 ExpectSyncedAndCreated(); 4295 ExpectSyncedAndCreated();
4165 } 4296 }
4166 4297
4167 TEST_F(SyncerUndeletionTest, UndeleteAfterCommitButBeforeGetUpdates) { 4298 TEST_F(SyncerUndeletionTest, UndeleteAfterCommitButBeforeGetUpdates) {
4168 Create(); 4299 Create();
4169 ExpectUnsyncedCreation(); 4300 ExpectUnsyncedCreation();
4170 SyncShareAsDelegate(); 4301 SyncShareNudge();
4171 4302
4172 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4303 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4173 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4304 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4174 ExpectSyncedAndCreated(); 4305 ExpectSyncedAndCreated();
4175 4306
4176 // Delete and commit. 4307 // Delete and commit.
4177 Delete(); 4308 Delete();
4178 ExpectUnsyncedDeletion(); 4309 ExpectUnsyncedDeletion();
4179 SyncShareAsDelegate(); 4310 SyncShareNudge();
4180 4311
4181 // The item ought to have committed successfully. 4312 // The item ought to have committed successfully.
4182 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4313 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4183 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4314 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4184 ExpectSyncedAndDeleted(); 4315 ExpectSyncedAndDeleted();
4185 4316
4186 // Before the GetUpdates, the item is locally undeleted. 4317 // Before the GetUpdates, the item is locally undeleted.
4187 Undelete(); 4318 Undelete();
4188 ExpectUnsyncedUndeletion(); 4319 ExpectUnsyncedUndeletion();
4189 4320
4190 // Now, encounter a GetUpdates corresponding to the just-committed 4321 // Now, encounter a GetUpdates corresponding to the just-committed
4191 // deletion update. The undeletion should prevail. 4322 // deletion update. The undeletion should prevail.
4192 mock_server_->AddUpdateFromLastCommit(); 4323 mock_server_->AddUpdateFromLastCommit();
4193 SyncShareAsDelegate(); 4324 SyncShareNudge();
4194 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4325 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4195 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4326 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4196 ExpectSyncedAndCreated(); 4327 ExpectSyncedAndCreated();
4197 } 4328 }
4198 4329
4199 TEST_F(SyncerUndeletionTest, UndeleteAfterDeleteAndGetUpdates) { 4330 TEST_F(SyncerUndeletionTest, UndeleteAfterDeleteAndGetUpdates) {
4200 Create(); 4331 Create();
4201 ExpectUnsyncedCreation(); 4332 ExpectUnsyncedCreation();
4202 SyncShareAsDelegate(); 4333 SyncShareNudge();
4203 4334
4204 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4335 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4205 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4336 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4206 ExpectSyncedAndCreated(); 4337 ExpectSyncedAndCreated();
4207 4338
4208 mock_server_->AddUpdateFromLastCommit(); 4339 mock_server_->AddUpdateFromLastCommit();
4209 SyncShareAsDelegate(); 4340 SyncShareNudge();
4210 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4341 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4211 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4342 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4212 ExpectSyncedAndCreated(); 4343 ExpectSyncedAndCreated();
4213 4344
4214 // Delete and commit. 4345 // Delete and commit.
4215 Delete(); 4346 Delete();
4216 ExpectUnsyncedDeletion(); 4347 ExpectUnsyncedDeletion();
4217 SyncShareAsDelegate(); 4348 SyncShareNudge();
4218 4349
4219 // The item ought to have committed successfully. 4350 // The item ought to have committed successfully.
4220 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4351 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4221 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4352 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4222 ExpectSyncedAndDeleted(); 4353 ExpectSyncedAndDeleted();
4223 4354
4224 // Now, encounter a GetUpdates corresponding to the just-committed 4355 // Now, encounter a GetUpdates corresponding to the just-committed
4225 // deletion update. Should be consistent. 4356 // deletion update. Should be consistent.
4226 mock_server_->AddUpdateFromLastCommit(); 4357 mock_server_->AddUpdateFromLastCommit();
4227 SyncShareAsDelegate(); 4358 SyncShareNudge();
4228 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4359 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4229 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4360 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4230 ExpectSyncedAndDeleted(); 4361 ExpectSyncedAndDeleted();
4231 4362
4232 // After the GetUpdates, the item is locally undeleted. 4363 // After the GetUpdates, the item is locally undeleted.
4233 Undelete(); 4364 Undelete();
4234 ExpectUnsyncedUndeletion(); 4365 ExpectUnsyncedUndeletion();
4235 4366
4236 // Now, encounter a GetUpdates corresponding to the just-committed 4367 // Now, encounter a GetUpdates corresponding to the just-committed
4237 // deletion update. The undeletion should prevail. 4368 // deletion update. The undeletion should prevail.
4238 SyncShareAsDelegate(); 4369 SyncShareNudge();
4239 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4370 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4240 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4371 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4241 ExpectSyncedAndCreated(); 4372 ExpectSyncedAndCreated();
4242 } 4373 }
4243 4374
4244 // Test processing of undeletion GetUpdateses. 4375 // Test processing of undeletion GetUpdateses.
4245 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletes) { 4376 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletes) {
4246 Create(); 4377 Create();
4247 ExpectUnsyncedCreation(); 4378 ExpectUnsyncedCreation();
4248 SyncShareAsDelegate(); 4379 SyncShareNudge();
4249 4380
4250 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4381 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4251 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4382 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4252 ExpectSyncedAndCreated(); 4383 ExpectSyncedAndCreated();
4253 4384
4254 // Add a delete from the server. 4385 // Add a delete from the server.
4255 mock_server_->AddUpdateFromLastCommit(); 4386 mock_server_->AddUpdateFromLastCommit();
4256 SyncShareAsDelegate(); 4387 SyncShareNudge();
4257 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4388 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4258 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4389 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4259 ExpectSyncedAndCreated(); 4390 ExpectSyncedAndCreated();
4260 4391
4261 // Some other client deletes the item. 4392 // Some other client deletes the item.
4262 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); 4393 mock_server_->AddUpdateTombstone(Get(metahandle_, ID));
4263 SyncShareAsDelegate(); 4394 SyncShareNudge();
4264 4395
4265 // The update ought to have applied successfully. 4396 // The update ought to have applied successfully.
4266 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4397 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4267 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4398 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4268 ExpectSyncedAndDeleted(); 4399 ExpectSyncedAndDeleted();
4269 4400
4270 // Undelete it locally. 4401 // Undelete it locally.
4271 Undelete(); 4402 Undelete();
4272 ExpectUnsyncedUndeletion(); 4403 ExpectUnsyncedUndeletion();
4273 SyncShareAsDelegate(); 4404 SyncShareNudge();
4274 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4405 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4275 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4406 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4276 ExpectSyncedAndCreated(); 4407 ExpectSyncedAndCreated();
4277 4408
4278 // Now, encounter a GetUpdates corresponding to the just-committed 4409 // Now, encounter a GetUpdates corresponding to the just-committed
4279 // deletion update. The undeletion should prevail. 4410 // deletion update. The undeletion should prevail.
4280 mock_server_->AddUpdateFromLastCommit(); 4411 mock_server_->AddUpdateFromLastCommit();
4281 SyncShareAsDelegate(); 4412 SyncShareNudge();
4282 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4413 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4283 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4414 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4284 ExpectSyncedAndCreated(); 4415 ExpectSyncedAndCreated();
4285 } 4416 }
4286 4417
4287 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletesImmediately) { 4418 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletesImmediately) {
4288 Create(); 4419 Create();
4289 ExpectUnsyncedCreation(); 4420 ExpectUnsyncedCreation();
4290 SyncShareAsDelegate(); 4421 SyncShareNudge();
4291 4422
4292 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4423 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4293 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4424 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4294 ExpectSyncedAndCreated(); 4425 ExpectSyncedAndCreated();
4295 4426
4296 // Some other client deletes the item before we get a chance 4427 // Some other client deletes the item before we get a chance
4297 // to GetUpdates our original request. 4428 // to GetUpdates our original request.
4298 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); 4429 mock_server_->AddUpdateTombstone(Get(metahandle_, ID));
4299 SyncShareAsDelegate(); 4430 SyncShareNudge();
4300 4431
4301 // The update ought to have applied successfully. 4432 // The update ought to have applied successfully.
4302 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4433 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4303 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4434 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4304 ExpectSyncedAndDeleted(); 4435 ExpectSyncedAndDeleted();
4305 4436
4306 // Undelete it locally. 4437 // Undelete it locally.
4307 Undelete(); 4438 Undelete();
4308 ExpectUnsyncedUndeletion(); 4439 ExpectUnsyncedUndeletion();
4309 SyncShareAsDelegate(); 4440 SyncShareNudge();
4310 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4441 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4311 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4442 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4312 ExpectSyncedAndCreated(); 4443 ExpectSyncedAndCreated();
4313 4444
4314 // Now, encounter a GetUpdates corresponding to the just-committed 4445 // Now, encounter a GetUpdates corresponding to the just-committed
4315 // deletion update. The undeletion should prevail. 4446 // deletion update. The undeletion should prevail.
4316 mock_server_->AddUpdateFromLastCommit(); 4447 mock_server_->AddUpdateFromLastCommit();
4317 SyncShareAsDelegate(); 4448 SyncShareNudge();
4318 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4449 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4319 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4450 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4320 ExpectSyncedAndCreated(); 4451 ExpectSyncedAndCreated();
4321 } 4452 }
4322 4453
4323 TEST_F(SyncerUndeletionTest, OtherClientUndeletes) { 4454 TEST_F(SyncerUndeletionTest, OtherClientUndeletes) {
4324 Create(); 4455 Create();
4325 ExpectUnsyncedCreation(); 4456 ExpectUnsyncedCreation();
4326 SyncShareAsDelegate(); 4457 SyncShareNudge();
4327 4458
4328 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4459 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4329 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4460 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4330 ExpectSyncedAndCreated(); 4461 ExpectSyncedAndCreated();
4331 4462
4332 // Get the updates of our just-committed entry. 4463 // Get the updates of our just-committed entry.
4333 mock_server_->AddUpdateFromLastCommit(); 4464 mock_server_->AddUpdateFromLastCommit();
4334 SyncShareAsDelegate(); 4465 SyncShareNudge();
4335 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4466 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4336 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4467 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4337 ExpectSyncedAndCreated(); 4468 ExpectSyncedAndCreated();
4338 4469
4339 // We delete the item. 4470 // We delete the item.
4340 Delete(); 4471 Delete();
4341 ExpectUnsyncedDeletion(); 4472 ExpectUnsyncedDeletion();
4342 SyncShareAsDelegate(); 4473 SyncShareNudge();
4343 4474
4344 // The update ought to have applied successfully. 4475 // The update ought to have applied successfully.
4345 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4476 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4346 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4477 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4347 ExpectSyncedAndDeleted(); 4478 ExpectSyncedAndDeleted();
4348 4479
4349 // Now, encounter a GetUpdates corresponding to the just-committed 4480 // Now, encounter a GetUpdates corresponding to the just-committed
4350 // deletion update. 4481 // deletion update.
4351 mock_server_->AddUpdateFromLastCommit(); 4482 mock_server_->AddUpdateFromLastCommit();
4352 SyncShareAsDelegate(); 4483 SyncShareNudge();
4353 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4484 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4354 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4485 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4355 ExpectSyncedAndDeleted(); 4486 ExpectSyncedAndDeleted();
4356 4487
4357 // Some other client undeletes the item. 4488 // Some other client undeletes the item.
4358 mock_server_->AddUpdateBookmark(Get(metahandle_, ID), 4489 mock_server_->AddUpdateBookmark(Get(metahandle_, ID),
4359 Get(metahandle_, PARENT_ID), 4490 Get(metahandle_, PARENT_ID),
4360 "Thadeusz", 100, 1000); 4491 "Thadeusz", 100, 1000);
4361 mock_server_->SetLastUpdateClientTag(client_tag_); 4492 mock_server_->SetLastUpdateClientTag(client_tag_);
4362 SyncShareAsDelegate(); 4493 SyncShareNudge();
4363 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4494 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4364 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4495 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4365 ExpectSyncedAndCreated(); 4496 ExpectSyncedAndCreated();
4366 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); 4497 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME));
4367 } 4498 }
4368 4499
4369 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) { 4500 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) {
4370 Create(); 4501 Create();
4371 ExpectUnsyncedCreation(); 4502 ExpectUnsyncedCreation();
4372 SyncShareAsDelegate(); 4503 SyncShareNudge();
4373 4504
4374 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4505 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4375 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4506 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4376 ExpectSyncedAndCreated(); 4507 ExpectSyncedAndCreated();
4377 4508
4378 // Get the updates of our just-committed entry. 4509 // Get the updates of our just-committed entry.
4379 mock_server_->AddUpdateFromLastCommit(); 4510 mock_server_->AddUpdateFromLastCommit();
4380 SyncShareAsDelegate(); 4511 SyncShareNudge();
4381 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4512 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4382 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4513 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4383 ExpectSyncedAndCreated(); 4514 ExpectSyncedAndCreated();
4384 4515
4385 // We delete the item. 4516 // We delete the item.
4386 Delete(); 4517 Delete();
4387 ExpectUnsyncedDeletion(); 4518 ExpectUnsyncedDeletion();
4388 SyncShareAsDelegate(); 4519 SyncShareNudge();
4389 4520
4390 // The update ought to have applied successfully. 4521 // The update ought to have applied successfully.
4391 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4522 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4392 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4523 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4393 ExpectSyncedAndDeleted(); 4524 ExpectSyncedAndDeleted();
4394 4525
4395 // Some other client undeletes before we see the update from our 4526 // Some other client undeletes before we see the update from our
4396 // commit. 4527 // commit.
4397 mock_server_->AddUpdateBookmark(Get(metahandle_, ID), 4528 mock_server_->AddUpdateBookmark(Get(metahandle_, ID),
4398 Get(metahandle_, PARENT_ID), 4529 Get(metahandle_, PARENT_ID),
4399 "Thadeusz", 100, 1000); 4530 "Thadeusz", 100, 1000);
4400 mock_server_->SetLastUpdateClientTag(client_tag_); 4531 mock_server_->SetLastUpdateClientTag(client_tag_);
4401 SyncShareAsDelegate(); 4532 SyncShareNudge();
4402 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); 4533 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems());
4403 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); 4534 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests());
4404 ExpectSyncedAndCreated(); 4535 ExpectSyncedAndCreated();
4405 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); 4536 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME));
4406 } 4537 }
4407 4538
4408 // A group of tests exercising the syncer's handling of sibling ordering, as 4539 // A group of tests exercising the syncer's handling of sibling ordering, as
4409 // represented in the sync protocol. 4540 // represented in the sync protocol.
4410 class SyncerPositionUpdateTest : public SyncerTest { 4541 class SyncerPositionUpdateTest : public SyncerTest {
4411 public: 4542 public:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4456 4587
4457 TEST_F(SyncerPositionUpdateTest, InOrderPositive) { 4588 TEST_F(SyncerPositionUpdateTest, InOrderPositive) {
4458 // Add a bunch of items in increasing order, starting with just positive 4589 // Add a bunch of items in increasing order, starting with just positive
4459 // position values. 4590 // position values.
4460 AddRootItemWithPosition(100); 4591 AddRootItemWithPosition(100);
4461 AddRootItemWithPosition(199); 4592 AddRootItemWithPosition(199);
4462 AddRootItemWithPosition(200); 4593 AddRootItemWithPosition(200);
4463 AddRootItemWithPosition(201); 4594 AddRootItemWithPosition(201);
4464 AddRootItemWithPosition(400); 4595 AddRootItemWithPosition(400);
4465 4596
4466 SyncShareAsDelegate(); 4597 SyncShareNudge();
4467 ExpectLocalItemsInServerOrder(); 4598 ExpectLocalItemsInServerOrder();
4468 } 4599 }
4469 4600
4470 TEST_F(SyncerPositionUpdateTest, InOrderNegative) { 4601 TEST_F(SyncerPositionUpdateTest, InOrderNegative) {
4471 // Test negative position values, but in increasing order. 4602 // Test negative position values, but in increasing order.
4472 AddRootItemWithPosition(-400); 4603 AddRootItemWithPosition(-400);
4473 AddRootItemWithPosition(-201); 4604 AddRootItemWithPosition(-201);
4474 AddRootItemWithPosition(-200); 4605 AddRootItemWithPosition(-200);
4475 AddRootItemWithPosition(-150); 4606 AddRootItemWithPosition(-150);
4476 AddRootItemWithPosition(100); 4607 AddRootItemWithPosition(100);
4477 4608
4478 SyncShareAsDelegate(); 4609 SyncShareNudge();
4479 ExpectLocalItemsInServerOrder(); 4610 ExpectLocalItemsInServerOrder();
4480 } 4611 }
4481 4612
4482 TEST_F(SyncerPositionUpdateTest, ReverseOrder) { 4613 TEST_F(SyncerPositionUpdateTest, ReverseOrder) {
4483 // Test when items are sent in the reverse order. 4614 // Test when items are sent in the reverse order.
4484 AddRootItemWithPosition(400); 4615 AddRootItemWithPosition(400);
4485 AddRootItemWithPosition(201); 4616 AddRootItemWithPosition(201);
4486 AddRootItemWithPosition(200); 4617 AddRootItemWithPosition(200);
4487 AddRootItemWithPosition(100); 4618 AddRootItemWithPosition(100);
4488 AddRootItemWithPosition(-150); 4619 AddRootItemWithPosition(-150);
4489 AddRootItemWithPosition(-201); 4620 AddRootItemWithPosition(-201);
4490 AddRootItemWithPosition(-200); 4621 AddRootItemWithPosition(-200);
4491 AddRootItemWithPosition(-400); 4622 AddRootItemWithPosition(-400);
4492 4623
4493 SyncShareAsDelegate(); 4624 SyncShareNudge();
4494 ExpectLocalItemsInServerOrder(); 4625 ExpectLocalItemsInServerOrder();
4495 } 4626 }
4496 4627
4497 TEST_F(SyncerPositionUpdateTest, RandomOrderInBatches) { 4628 TEST_F(SyncerPositionUpdateTest, RandomOrderInBatches) {
4498 // Mix it all up, interleaving position values, and try multiple batches of 4629 // Mix it all up, interleaving position values, and try multiple batches of
4499 // updates. 4630 // updates.
4500 AddRootItemWithPosition(400); 4631 AddRootItemWithPosition(400);
4501 AddRootItemWithPosition(201); 4632 AddRootItemWithPosition(201);
4502 AddRootItemWithPosition(-400); 4633 AddRootItemWithPosition(-400);
4503 AddRootItemWithPosition(100); 4634 AddRootItemWithPosition(100);
4504 4635
4505 SyncShareAsDelegate(); 4636 SyncShareNudge();
4506 ExpectLocalItemsInServerOrder(); 4637 ExpectLocalItemsInServerOrder();
4507 4638
4508 AddRootItemWithPosition(-150); 4639 AddRootItemWithPosition(-150);
4509 AddRootItemWithPosition(-200); 4640 AddRootItemWithPosition(-200);
4510 AddRootItemWithPosition(200); 4641 AddRootItemWithPosition(200);
4511 AddRootItemWithPosition(-201); 4642 AddRootItemWithPosition(-201);
4512 4643
4513 SyncShareAsDelegate(); 4644 SyncShareNudge();
4514 ExpectLocalItemsInServerOrder(); 4645 ExpectLocalItemsInServerOrder();
4515 4646
4516 AddRootItemWithPosition(-144); 4647 AddRootItemWithPosition(-144);
4517 4648
4518 SyncShareAsDelegate(); 4649 SyncShareNudge();
4519 ExpectLocalItemsInServerOrder(); 4650 ExpectLocalItemsInServerOrder();
4520 } 4651 }
4521 4652
4522 class SyncerPositionTiebreakingTest : public SyncerTest { 4653 class SyncerPositionTiebreakingTest : public SyncerTest {
4523 public: 4654 public:
4524 SyncerPositionTiebreakingTest() 4655 SyncerPositionTiebreakingTest()
4525 : low_id_(Id::CreateFromServerId("A")), 4656 : low_id_(Id::CreateFromServerId("A")),
4526 mid_id_(Id::CreateFromServerId("M")), 4657 mid_id_(Id::CreateFromServerId("M")),
4527 high_id_(Id::CreateFromServerId("Z")), 4658 high_id_(Id::CreateFromServerId("Z")),
4528 next_revision_(1) { 4659 next_revision_(1) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4568 4699
4569 private: 4700 private:
4570 int next_revision_; 4701 int next_revision_;
4571 DISALLOW_COPY_AND_ASSIGN(SyncerPositionTiebreakingTest); 4702 DISALLOW_COPY_AND_ASSIGN(SyncerPositionTiebreakingTest);
4572 }; 4703 };
4573 4704
4574 TEST_F(SyncerPositionTiebreakingTest, LowMidHigh) { 4705 TEST_F(SyncerPositionTiebreakingTest, LowMidHigh) {
4575 Add(low_id_); 4706 Add(low_id_);
4576 Add(mid_id_); 4707 Add(mid_id_);
4577 Add(high_id_); 4708 Add(high_id_);
4578 SyncShareAsDelegate(); 4709 SyncShareNudge();
4579 ExpectLocalOrderIsByServerId(); 4710 ExpectLocalOrderIsByServerId();
4580 } 4711 }
4581 4712
4582 TEST_F(SyncerPositionTiebreakingTest, LowHighMid) { 4713 TEST_F(SyncerPositionTiebreakingTest, LowHighMid) {
4583 Add(low_id_); 4714 Add(low_id_);
4584 Add(high_id_); 4715 Add(high_id_);
4585 Add(mid_id_); 4716 Add(mid_id_);
4586 SyncShareAsDelegate(); 4717 SyncShareNudge();
4587 ExpectLocalOrderIsByServerId(); 4718 ExpectLocalOrderIsByServerId();
4588 } 4719 }
4589 4720
4590 TEST_F(SyncerPositionTiebreakingTest, HighMidLow) { 4721 TEST_F(SyncerPositionTiebreakingTest, HighMidLow) {
4591 Add(high_id_); 4722 Add(high_id_);
4592 Add(mid_id_); 4723 Add(mid_id_);
4593 Add(low_id_); 4724 Add(low_id_);
4594 SyncShareAsDelegate(); 4725 SyncShareNudge();
4595 ExpectLocalOrderIsByServerId(); 4726 ExpectLocalOrderIsByServerId();
4596 } 4727 }
4597 4728
4598 TEST_F(SyncerPositionTiebreakingTest, HighLowMid) { 4729 TEST_F(SyncerPositionTiebreakingTest, HighLowMid) {
4599 Add(high_id_); 4730 Add(high_id_);
4600 Add(low_id_); 4731 Add(low_id_);
4601 Add(mid_id_); 4732 Add(mid_id_);
4602 SyncShareAsDelegate(); 4733 SyncShareNudge();
4603 ExpectLocalOrderIsByServerId(); 4734 ExpectLocalOrderIsByServerId();
4604 } 4735 }
4605 4736
4606 TEST_F(SyncerPositionTiebreakingTest, MidHighLow) { 4737 TEST_F(SyncerPositionTiebreakingTest, MidHighLow) {
4607 Add(mid_id_); 4738 Add(mid_id_);
4608 Add(high_id_); 4739 Add(high_id_);
4609 Add(low_id_); 4740 Add(low_id_);
4610 SyncShareAsDelegate(); 4741 SyncShareNudge();
4611 ExpectLocalOrderIsByServerId(); 4742 ExpectLocalOrderIsByServerId();
4612 } 4743 }
4613 4744
4614 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4745 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4615 Add(mid_id_); 4746 Add(mid_id_);
4616 Add(low_id_); 4747 Add(low_id_);
4617 Add(high_id_); 4748 Add(high_id_);
4618 SyncShareAsDelegate(); 4749 SyncShareNudge();
4619 ExpectLocalOrderIsByServerId(); 4750 ExpectLocalOrderIsByServerId();
4620 } 4751 }
4621 4752
4622 } // namespace browser_sync 4753 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/syncer.cc ('k') | sync/sessions/status_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698