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

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

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