Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/sync/engine/net/server_connection_manager.h" | 27 #include "chrome/browser/sync/engine/net/server_connection_manager.h" |
| 28 #include "chrome/browser/sync/engine/process_updates_command.h" | 28 #include "chrome/browser/sync/engine/process_updates_command.h" |
| 29 #include "chrome/browser/sync/engine/nigori_util.h" | 29 #include "chrome/browser/sync/engine/nigori_util.h" |
| 30 #include "chrome/browser/sync/engine/syncer.h" | 30 #include "chrome/browser/sync/engine/syncer.h" |
| 31 #include "chrome/browser/sync/engine/syncer_proto_util.h" | 31 #include "chrome/browser/sync/engine/syncer_proto_util.h" |
| 32 #include "chrome/browser/sync/engine/syncer_util.h" | 32 #include "chrome/browser/sync/engine/syncer_util.h" |
| 33 #include "chrome/browser/sync/engine/syncproto.h" | 33 #include "chrome/browser/sync/engine/syncproto.h" |
| 34 #include "chrome/browser/sync/protocol/sync.pb.h" | 34 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 35 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 35 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 36 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 36 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
| 37 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | |
| 37 #include "chrome/browser/sync/sessions/sync_session_context.h" | 38 #include "chrome/browser/sync/sessions/sync_session_context.h" |
| 38 #include "chrome/browser/sync/syncable/directory_manager.h" | 39 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 39 #include "chrome/browser/sync/syncable/model_type.h" | 40 #include "chrome/browser/sync/syncable/model_type.h" |
| 40 #include "chrome/browser/sync/syncable/syncable.h" | 41 #include "chrome/browser/sync/syncable/syncable.h" |
| 41 #include "chrome/browser/sync/test/engine/fake_model_worker.h" | 42 #include "chrome/browser/sync/test/engine/fake_model_worker.h" |
| 42 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" | 43 #include "chrome/browser/sync/test/engine/mock_connection_manager.h" |
| 43 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" | 44 #include "chrome/browser/sync/test/engine/test_directory_setter_upper.h" |
| 44 #include "chrome/browser/sync/test/engine/test_id_factory.h" | 45 #include "chrome/browser/sync/test/engine/test_id_factory.h" |
| 45 #include "chrome/browser/sync/test/engine/test_syncable_utils.h" | 46 #include "chrome/browser/sync/test/engine/test_syncable_utils.h" |
| 46 #include "chrome/browser/sync/util/cryptographer.h" | 47 #include "chrome/browser/sync/util/cryptographer.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 using syncable::IS_DEL; | 82 using syncable::IS_DEL; |
| 82 using syncable::IS_DIR; | 83 using syncable::IS_DIR; |
| 83 using syncable::IS_UNAPPLIED_UPDATE; | 84 using syncable::IS_UNAPPLIED_UPDATE; |
| 84 using syncable::IS_UNSYNCED; | 85 using syncable::IS_UNSYNCED; |
| 85 using syncable::META_HANDLE; | 86 using syncable::META_HANDLE; |
| 86 using syncable::MTIME; | 87 using syncable::MTIME; |
| 87 using syncable::NEXT_ID; | 88 using syncable::NEXT_ID; |
| 88 using syncable::NON_UNIQUE_NAME; | 89 using syncable::NON_UNIQUE_NAME; |
| 89 using syncable::PARENT_ID; | 90 using syncable::PARENT_ID; |
| 90 using syncable::PREV_ID; | 91 using syncable::PREV_ID; |
| 92 using syncable::PREV_SERVER_SPECIFICS; | |
| 91 using syncable::SERVER_IS_DEL; | 93 using syncable::SERVER_IS_DEL; |
| 92 using syncable::SERVER_NON_UNIQUE_NAME; | 94 using syncable::SERVER_NON_UNIQUE_NAME; |
| 93 using syncable::SERVER_PARENT_ID; | 95 using syncable::SERVER_PARENT_ID; |
| 94 using syncable::SERVER_POSITION_IN_PARENT; | 96 using syncable::SERVER_POSITION_IN_PARENT; |
| 95 using syncable::SERVER_SPECIFICS; | 97 using syncable::SERVER_SPECIFICS; |
| 96 using syncable::SERVER_VERSION; | 98 using syncable::SERVER_VERSION; |
| 97 using syncable::UNIQUE_CLIENT_TAG; | 99 using syncable::UNIQUE_CLIENT_TAG; |
| 98 using syncable::UNIQUE_SERVER_TAG; | 100 using syncable::UNIQUE_SERVER_TAG; |
| 99 using syncable::SPECIFICS; | 101 using syncable::SPECIFICS; |
| 100 using syncable::SYNCING; | 102 using syncable::SYNCING; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 GetModelSafeRoutingInfo(&info); | 174 GetModelSafeRoutingInfo(&info); |
| 173 GetWorkers(&workers); | 175 GetWorkers(&workers); |
| 174 syncable::ModelTypePayloadMap types = | 176 syncable::ModelTypePayloadMap types = |
| 175 syncable::ModelTypePayloadMapFromRoutingInfo(info, std::string()); | 177 syncable::ModelTypePayloadMapFromRoutingInfo(info, std::string()); |
| 176 return new SyncSession(context_.get(), this, | 178 return new SyncSession(context_.get(), this, |
| 177 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), | 179 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), |
| 178 info, workers); | 180 info, workers); |
| 179 } | 181 } |
| 180 | 182 |
| 181 bool SyncShareAsDelegate() { | 183 bool SyncShareAsDelegate() { |
| 182 scoped_ptr<SyncSession> session(MakeSession()); | 184 session_.reset(MakeSession()); |
| 183 syncer_->SyncShare(session.get(), SYNCER_BEGIN, SYNCER_END); | 185 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); |
| 184 return session->HasMoreToSync(); | 186 return session_->HasMoreToSync(); |
| 185 } | 187 } |
| 186 | 188 |
| 187 void LoopSyncShare() { | 189 void LoopSyncShare() { |
| 188 bool should_loop = false; | 190 bool should_loop = false; |
| 189 int loop_iterations = 0; | 191 int loop_iterations = 0; |
| 190 do { | 192 do { |
| 191 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; | 193 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; |
| 192 should_loop = SyncShareAsDelegate(); | 194 should_loop = SyncShareAsDelegate(); |
| 193 } while (should_loop); | 195 } while (should_loop); |
| 194 } | 196 } |
| 195 | 197 |
| 196 virtual void SetUp() { | 198 virtual void SetUp() { |
| 197 syncdb_.SetUp(); | 199 syncdb_.SetUp(); |
| 198 | 200 |
| 199 mock_server_.reset( | 201 mock_server_.reset( |
| 200 new MockConnectionManager(syncdb_.manager(), syncdb_.name())); | 202 new MockConnectionManager(syncdb_.manager(), syncdb_.name())); |
| 201 EnableDatatype(syncable::BOOKMARKS); | 203 EnableDatatype(syncable::BOOKMARKS); |
| 202 EnableDatatype(syncable::NIGORI); | 204 EnableDatatype(syncable::NIGORI); |
| 205 EnableDatatype(syncable::PREFERENCES); | |
| 206 EnableDatatype(syncable::NIGORI); | |
| 203 worker_ = new FakeModelWorker(GROUP_PASSIVE); | 207 worker_ = new FakeModelWorker(GROUP_PASSIVE); |
| 204 std::vector<SyncEngineEventListener*> listeners; | 208 std::vector<SyncEngineEventListener*> listeners; |
| 205 listeners.push_back(this); | 209 listeners.push_back(this); |
| 206 context_.reset(new SyncSessionContext(mock_server_.get(), | 210 context_.reset(new SyncSessionContext(mock_server_.get(), |
| 207 syncdb_.manager(), this, listeners, NULL)); | 211 syncdb_.manager(), this, listeners, NULL)); |
| 208 context_->set_account_name(syncdb_.name()); | 212 context_->set_account_name(syncdb_.name()); |
| 209 ASSERT_FALSE(context_->resolver()); | 213 ASSERT_FALSE(context_->resolver()); |
| 210 syncer_ = new Syncer(); | 214 syncer_ = new Syncer(); |
| 211 session_.reset(MakeSession()); | 215 session_.reset(MakeSession()); |
| 212 | 216 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 expected_order.push_back(ids_.MakeLocal("b")); | 559 expected_order.push_back(ids_.MakeLocal("b")); |
| 556 expected_order.push_back(ids_.MakeLocal("c")); | 560 expected_order.push_back(ids_.MakeLocal("c")); |
| 557 expected_order.push_back(ids_.MakeLocal("e")); | 561 expected_order.push_back(ids_.MakeLocal("e")); |
| 558 DoTruncationTest(dir, unsynced_handle_view, expected_order); | 562 DoTruncationTest(dir, unsynced_handle_view, expected_order); |
| 559 } | 563 } |
| 560 | 564 |
| 561 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { | 565 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { |
| 562 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 566 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 563 ASSERT_TRUE(dir.good()); | 567 ASSERT_TRUE(dir.good()); |
| 564 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS); | 568 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS); |
| 565 KeyParams key_params = {"localhost", "dummy", "foobar"}; | |
| 566 sync_pb::EntitySpecifics bookmark_data; | 569 sync_pb::EntitySpecifics bookmark_data; |
| 567 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data); | 570 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data); |
| 568 | 571 |
| 569 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 572 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 570 SyncShareAsDelegate(); | 573 SyncShareAsDelegate(); |
| 571 | 574 |
| 572 { | 575 { |
| 573 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 576 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 574 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 577 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 575 ASSERT_TRUE(A.good()); | 578 ASSERT_TRUE(A.good()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 599 SyncShareAsDelegate(); | 602 SyncShareAsDelegate(); |
| 600 { | 603 { |
| 601 // It should have been committed. | 604 // It should have been committed. |
| 602 ReadTransaction rtrans(FROM_HERE, dir); | 605 ReadTransaction rtrans(FROM_HERE, dir); |
| 603 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 606 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); |
| 604 ASSERT_TRUE(entryA.good()); | 607 ASSERT_TRUE(entryA.good()); |
| 605 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); | 608 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); |
| 606 } | 609 } |
| 607 } | 610 } |
| 608 | 611 |
| 612 // We use a macro so we can preserve the error location. | |
| 613 #define VERIFY_ENTRY(id, is_unapplied, is_unsynced, prev_initialized, \ | |
| 614 parent_id, version, server_version, id_fac, rtrans) \ | |
| 615 do { \ | |
| 616 Entry entryA(rtrans, syncable::GET_BY_ID, id_fac.FromNumber(id)); \ | |
| 617 ASSERT_TRUE(entryA.good()); \ | |
| 618 EXPECT_EQ(is_unsynced, entryA.Get(IS_UNSYNCED)); \ | |
| 619 EXPECT_EQ(is_unapplied, entryA.Get(IS_UNAPPLIED_UPDATE)); \ | |
| 620 EXPECT_EQ(prev_initialized, \ | |
| 621 syncable::IsRealDataType(syncable::GetModelTypeFromSpecifics( \ | |
| 622 entryA.Get(PREV_SERVER_SPECIFICS)))); \ | |
| 623 EXPECT_TRUE(parent_id == -1 || \ | |
| 624 entryA.Get(PARENT_ID) == id_fac.FromNumber(parent_id)); \ | |
| 625 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \ | |
| 626 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \ | |
| 627 } while (0) | |
| 628 | |
| 609 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { | 629 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { |
| 610 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 630 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 611 ASSERT_TRUE(dir.good()); | 631 ASSERT_TRUE(dir.good()); |
| 612 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 632 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 613 sync_pb::EncryptedData encrypted; | 633 KeyParams other_params = {"localhost", "dummy", "foobar2"}; |
| 614 sync_pb::EntitySpecifics encrypted_bookmark; | 634 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; |
| 615 encrypted_bookmark.mutable_encrypted(); | 635 bookmark.MutableExtension(sync_pb::bookmark)->set_url("url"); |
| 636 bookmark.MutableExtension(sync_pb::bookmark)->set_title("title"); | |
| 616 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | 637 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); |
| 617 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 638 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 618 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 639 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 619 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); | 640 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); |
| 620 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); | 641 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); |
| 621 SyncShareAsDelegate(); | 642 SyncShareAsDelegate(); |
| 622 // Server side change will put A in conflict. | 643 // Server side change will put A in conflict. |
| 623 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); | 644 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); |
| 624 { | 645 { |
| 625 // Mark bookmarks as encrypted and set the cryptographer to have pending | 646 // Mark bookmarks as encrypted and set the cryptographer to have pending |
| 626 // keys. | 647 // keys. |
| 627 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 648 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 628 browser_sync::Cryptographer other_cryptographer; | 649 browser_sync::Cryptographer other_cryptographer; |
| 629 other_cryptographer.AddKey(key_params); | 650 other_cryptographer.AddKey(other_params); |
| 630 sync_pb::EntitySpecifics specifics; | 651 sync_pb::EntitySpecifics specifics; |
| 631 sync_pb::NigoriSpecifics* nigori = | 652 sync_pb::NigoriSpecifics* nigori = |
| 632 specifics.MutableExtension(sync_pb::nigori); | 653 specifics.MutableExtension(sync_pb::nigori); |
| 633 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 654 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 634 nigori->set_encrypt_bookmarks(true); | 655 nigori->set_encrypt_bookmarks(true); |
| 656 // Set up with an old passphrase, but have pending keys | |
| 657 syncdb_.manager()->GetCryptographer(&wtrans)->AddKey(key_params); | |
| 658 syncdb_.manager()->GetCryptographer(&wtrans)->Encrypt( | |
| 659 bookmark, | |
| 660 encrypted_bookmark.mutable_encrypted()); | |
| 635 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); | 661 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); |
| 636 | 662 |
| 637 // In conflict but properly encrypted. | 663 // In conflict but properly encrypted. |
| 638 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | 664 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); |
| 639 ASSERT_TRUE(A.good()); | 665 ASSERT_TRUE(A.good()); |
| 640 A.Put(IS_UNSYNCED, true); | 666 A.Put(IS_UNSYNCED, true); |
| 641 A.Put(SPECIFICS, encrypted_bookmark); | 667 A.Put(SPECIFICS, encrypted_bookmark); |
| 642 A.Put(NON_UNIQUE_NAME, kEncryptedString); | 668 A.Put(NON_UNIQUE_NAME, kEncryptedString); |
| 643 // Not in conflict and properly encrypted. | 669 // Not in conflict and properly encrypted. |
| 644 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | 670 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 655 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); | 681 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); |
| 656 ASSERT_TRUE(D.good()); | 682 ASSERT_TRUE(D.good()); |
| 657 D.Put(IS_UNSYNCED, true); | 683 D.Put(IS_UNSYNCED, true); |
| 658 D.Put(SPECIFICS, encrypted_bookmark); | 684 D.Put(SPECIFICS, encrypted_bookmark); |
| 659 D.Put(NON_UNIQUE_NAME, "not encrypted"); | 685 D.Put(NON_UNIQUE_NAME, "not encrypted"); |
| 660 } | 686 } |
| 661 SyncShareAsDelegate(); | 687 SyncShareAsDelegate(); |
| 662 { | 688 { |
| 663 // We remove any unready entries from the status controller's unsynced | 689 // We remove any unready entries from the status controller's unsynced |
| 664 // handles, so this should remain 0 even though the entries didn't commit. | 690 // handles, so this should remain 0 even though the entries didn't commit. |
| 665 ASSERT_EQ(0U, session_->status_controller().unsynced_handles().size()); | 691 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); |
| 666 // Nothing should have commited due to bookmarks being encrypted and | 692 // Nothing should have commited due to bookmarks being encrypted and |
| 667 // the cryptographer having pending keys. A would have been resolved | 693 // the cryptographer having pending keys. A would have been resolved |
| 668 // as a simple conflict, but still be unsynced until the next sync cycle. | 694 // as a simple conflict, but still be unsynced until the next sync cycle. |
| 669 ReadTransaction rtrans(FROM_HERE, dir); | 695 ReadTransaction rtrans(FROM_HERE, dir); |
| 670 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 696 VERIFY_ENTRY(1, false, true, false, 0, 20, 20, ids_, &rtrans); |
| 671 ASSERT_TRUE(entryA.good()); | 697 VERIFY_ENTRY(2, false, true, false, 0, 10, 10, ids_, &rtrans); |
| 672 EXPECT_TRUE(entryA.Get(IS_UNSYNCED)); | 698 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); |
| 673 Entry entryB(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); | 699 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); |
| 674 ASSERT_TRUE(entryB.good()); | |
| 675 EXPECT_TRUE(entryB.Get(IS_UNSYNCED)); | |
| 676 Entry entryC(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(3)); | |
| 677 ASSERT_TRUE(entryC.good()); | |
| 678 EXPECT_TRUE(entryC.Get(IS_UNSYNCED)); | |
| 679 Entry entryD(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(4)); | |
| 680 ASSERT_TRUE(entryD.good()); | |
| 681 EXPECT_TRUE(entryD.Get(IS_UNSYNCED)); | |
| 682 | 700 |
| 683 // Resolve the pending keys. | 701 // Resolve the pending keys. |
| 684 syncdb_.manager()->GetCryptographer(&rtrans)->DecryptPendingKeys( | 702 syncdb_.manager()->GetCryptographer(&rtrans)->DecryptPendingKeys( |
| 685 key_params); | 703 other_params); |
| 686 } | 704 } |
| 687 SyncShareAsDelegate(); | 705 SyncShareAsDelegate(); |
| 688 { | 706 { |
| 689 ASSERT_EQ(0U, session_->status_controller().unsynced_handles().size()); | 707 // 2 unsynced handles to reflect the items that committed succesfully. |
| 708 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); | |
| 690 // All properly encrypted and non-conflicting items should commit. "A" was | 709 // All properly encrypted and non-conflicting items should commit. "A" was |
| 691 // conflicting, but last sync cycle resolved it as simple conflict, so on | 710 // conflicting, but last sync cycle resolved it as simple conflict, so on |
| 692 // this sync cycle it committed succesfullly. | 711 // this sync cycle it committed succesfullly. |
| 693 ReadTransaction rtrans(FROM_HERE, dir); | 712 ReadTransaction rtrans(FROM_HERE, dir); |
| 694 // Committed successfully. | 713 // Committed successfully. |
| 695 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 714 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); |
| 696 ASSERT_TRUE(entryA.good()); | |
| 697 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); | |
| 698 EXPECT_FALSE(entryA.Get(IS_UNAPPLIED_UPDATE)); | |
| 699 // Committed successfully. | 715 // Committed successfully. |
| 700 Entry entryB(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); | 716 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 701 ASSERT_TRUE(entryB.good()); | |
| 702 EXPECT_FALSE(entryB.Get(IS_UNSYNCED)); | |
| 703 EXPECT_FALSE(entryB.Get(IS_UNAPPLIED_UPDATE)); | |
| 704 // Was not properly encrypted. | 717 // Was not properly encrypted. |
| 705 Entry entryC(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(3)); | 718 VERIFY_ENTRY(3, false, true, false, 0, 10, 10, ids_, &rtrans); |
| 706 ASSERT_TRUE(entryC.good()); | |
| 707 EXPECT_TRUE(entryC.Get(IS_UNSYNCED)); | |
| 708 EXPECT_FALSE(entryC.Get(IS_UNAPPLIED_UPDATE)); | |
| 709 // Was not properly encrypted. | 719 // Was not properly encrypted. |
| 710 Entry entryD(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(4)); | 720 VERIFY_ENTRY(4, false, true, false, 0, 10, 10, ids_, &rtrans); |
| 711 ASSERT_TRUE(entryD.good()); | |
| 712 EXPECT_TRUE(entryD.Get(IS_UNSYNCED)); | |
| 713 EXPECT_FALSE(entryD.Get(IS_UNAPPLIED_UPDATE)); | |
| 714 } | 721 } |
| 715 { | 722 { |
| 716 // Fix the remaining items. | 723 // Fix the remaining items. |
| 717 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 724 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 718 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); | 725 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); |
| 719 ASSERT_TRUE(C.good()); | 726 ASSERT_TRUE(C.good()); |
| 720 C.Put(SPECIFICS, encrypted_bookmark); | 727 C.Put(SPECIFICS, encrypted_bookmark); |
| 721 C.Put(NON_UNIQUE_NAME, kEncryptedString); | 728 C.Put(NON_UNIQUE_NAME, kEncryptedString); |
| 722 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); | 729 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); |
| 723 ASSERT_TRUE(D.good()); | 730 ASSERT_TRUE(D.good()); |
| 724 D.Put(SPECIFICS, encrypted_bookmark); | 731 D.Put(SPECIFICS, encrypted_bookmark); |
| 725 D.Put(NON_UNIQUE_NAME, kEncryptedString); | 732 D.Put(NON_UNIQUE_NAME, kEncryptedString); |
| 726 } | 733 } |
| 727 SyncShareAsDelegate(); | 734 SyncShareAsDelegate(); |
| 728 { | 735 { |
| 729 ASSERT_EQ(0U, session_->status_controller().unsynced_handles().size()); | 736 // We attempted to commit two items. |
| 737 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); | |
| 738 EXPECT_TRUE(session_->status_controller().did_commit_items()); | |
| 730 // None should be unsynced anymore. | 739 // None should be unsynced anymore. |
| 731 ReadTransaction rtrans(FROM_HERE, dir); | 740 ReadTransaction rtrans(FROM_HERE, dir); |
| 732 Entry entryA(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(1)); | 741 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); |
| 733 ASSERT_TRUE(entryA.good()); | 742 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 734 EXPECT_FALSE(entryA.Get(IS_UNSYNCED)); | 743 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 735 EXPECT_FALSE(entryA.Get(IS_UNAPPLIED_UPDATE)); | 744 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 736 Entry entryB(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(2)); | |
| 737 ASSERT_TRUE(entryB.good()); | |
| 738 EXPECT_FALSE(entryB.Get(IS_UNSYNCED)); | |
| 739 EXPECT_FALSE(entryB.Get(IS_UNAPPLIED_UPDATE)); | |
| 740 Entry entryC(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(3)); | |
| 741 ASSERT_TRUE(entryC.good()); | |
| 742 EXPECT_FALSE(entryC.Get(IS_UNSYNCED)); | |
| 743 EXPECT_FALSE(entryC.Get(IS_UNAPPLIED_UPDATE)); | |
| 744 Entry entryD(&rtrans, syncable::GET_BY_ID, ids_.FromNumber(4)); | |
| 745 ASSERT_TRUE(entryD.good()); | |
| 746 EXPECT_FALSE(entryD.Get(IS_UNSYNCED)); | |
| 747 EXPECT_FALSE(entryD.Get(IS_UNAPPLIED_UPDATE)); | |
| 748 } | 745 } |
| 749 } | 746 } |
| 750 | 747 |
| 748 TEST_F(SyncerTest, EncryptionAwareConflicts) { | |
|
tim (not reviewing)
2011/12/15 20:55:11
I like the coverage but.. it would be _REALLY_ nic
| |
| 749 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | |
| 750 ASSERT_TRUE(dir.good()); | |
| 751 KeyParams key_params = {"localhost", "dummy", "foobar"}; | |
| 752 browser_sync::Cryptographer other_cryptographer; | |
| 753 other_cryptographer.AddKey(key_params); | |
| 754 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; | |
| 755 bookmark.MutableExtension(sync_pb::bookmark)->set_title("title"); | |
| 756 other_cryptographer.Encrypt(bookmark, | |
| 757 encrypted_bookmark.mutable_encrypted()); | |
| 758 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | |
| 759 modified_bookmark.MutableExtension(sync_pb::bookmark)->set_title("title2"); | |
| 760 other_cryptographer.Encrypt(modified_bookmark, | |
| 761 modified_bookmark.mutable_encrypted()); | |
| 762 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; | |
| 763 pref.MutableExtension(sync_pb::preference)->set_name("name"); | |
| 764 AddDefaultExtensionValue(syncable::PREFERENCES, &encrypted_pref); | |
| 765 other_cryptographer.Encrypt(pref, | |
| 766 encrypted_pref.mutable_encrypted()); | |
| 767 modified_pref.MutableExtension(sync_pb::preference)->set_name("name2"); | |
| 768 other_cryptographer.Encrypt(modified_pref, | |
| 769 modified_pref.mutable_encrypted()); | |
| 770 { | |
| 771 // Mark bookmarks and preferences as encrypted and set the cryptographer to | |
| 772 // have pending keys. | |
| 773 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | |
| 774 sync_pb::EntitySpecifics specifics; | |
| 775 sync_pb::NigoriSpecifics* nigori = | |
| 776 specifics.MutableExtension(sync_pb::nigori); | |
| 777 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | |
| 778 nigori->set_encrypt_bookmarks(true); | |
| 779 nigori->set_encrypt_preferences(true); | |
| 780 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); | |
| 781 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | |
| 782 has_pending_keys()); | |
| 783 } | |
| 784 | |
| 785 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); | |
| 786 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); | |
| 787 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); | |
| 788 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref); | |
| 789 SyncShareAsDelegate(); | |
| 790 { | |
| 791 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); | |
| 792 // Initial state. Everything is normal. | |
| 793 ReadTransaction rtrans(FROM_HERE, dir); | |
| 794 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); | |
| 795 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); | |
| 796 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); | |
| 797 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); | |
| 798 } | |
| 799 // Server side encryption will not be applied due to undecryptable data. | |
| 800 // At this point, PREV_SERVER_SPECIFICS should be filled for all four items. | |
| 801 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 20, 20, true, 0, | |
| 802 encrypted_bookmark); | |
| 803 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 20, 20, false, 2, | |
| 804 encrypted_bookmark); | |
| 805 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 20, 20, false, 1, | |
| 806 encrypted_bookmark); | |
| 807 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 20, 20, false, 0, | |
| 808 encrypted_pref); | |
| 809 SyncShareAsDelegate(); | |
| 810 { | |
| 811 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); | |
| 812 // All should be unapplied due to being undecryptable and have a valid | |
| 813 // PREV_SERVER_SPECIFICS. | |
| 814 ReadTransaction rtrans(FROM_HERE, dir); | |
| 815 VERIFY_ENTRY(1, true, false, true, 0, 10, 20, ids_, &rtrans); | |
| 816 VERIFY_ENTRY(2, true, false, true, 1, 10, 20, ids_, &rtrans); | |
| 817 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); | |
| 818 VERIFY_ENTRY(4, true, false, true, 0, 10, 20, ids_, &rtrans); | |
| 819 } | |
| 820 // Server side change that don't modify anything should not affect | |
| 821 // PREV_SERVER_SPECIFICS (such as name changes and mtime changes). | |
| 822 mock_server_->AddUpdateSpecifics(1, 0, kEncryptedString, 30, 30, true, 0, | |
| 823 encrypted_bookmark); | |
| 824 mock_server_->AddUpdateSpecifics(2, 1, kEncryptedString, 30, 30, false, 2, | |
| 825 encrypted_bookmark); | |
| 826 // Item 3 doesn't change. | |
| 827 mock_server_->AddUpdateSpecifics(4, 0, kEncryptedString, 30, 30, false, 0, | |
| 828 encrypted_pref); | |
| 829 SyncShareAsDelegate(); | |
| 830 { | |
| 831 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); | |
| 832 // Items 1, 2, and 4 should have newer server versions, 3 remains the same. | |
| 833 // All should remain unapplied due to be undecryptable. | |
| 834 ReadTransaction rtrans(FROM_HERE, dir); | |
| 835 VERIFY_ENTRY(1, true, false, true, 0, 10, 30, ids_, &rtrans); | |
| 836 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); | |
| 837 VERIFY_ENTRY(3, true, false, true, 1, 10, 20, ids_, &rtrans); | |
| 838 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); | |
| 839 } | |
| 840 // Positional changes, parent changes, and specifics changes should reset | |
| 841 // PREV_SERVER_SPECIFICS. | |
| 842 // Became unencrypted. | |
| 843 mock_server_->AddUpdateSpecifics(1, 0, "A", 40, 40, true, 0, bookmark); | |
| 844 // Reordered to after item 2. | |
| 845 mock_server_->AddUpdateSpecifics(3, 1, kEncryptedString, 30, 30, false, 3, | |
| 846 encrypted_bookmark); | |
| 847 SyncShareAsDelegate(); | |
| 848 { | |
| 849 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); | |
| 850 // Items 2 and 4 should be the only ones with PREV_SERVER_SPECIFICS set. | |
| 851 // Items 1 is now unencrypted, so should have applied normally. | |
| 852 ReadTransaction rtrans(FROM_HERE, dir); | |
| 853 VERIFY_ENTRY(1, false, false, false, 0, 40, 40, ids_, &rtrans); | |
| 854 VERIFY_ENTRY(2, true, false, true, 1, 10, 30, ids_, &rtrans); | |
| 855 VERIFY_ENTRY(3, true, false, false, 1, 10, 30, ids_, &rtrans); | |
| 856 VERIFY_ENTRY(4, true, false, true, 0, 10, 30, ids_, &rtrans); | |
| 857 } | |
| 858 // Make local changes, which should remain unsynced for items 2, 3, 4. | |
| 859 { | |
| 860 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | |
| 861 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); | |
| 862 ASSERT_TRUE(A.good()); | |
| 863 A.Put(SPECIFICS, modified_bookmark); | |
| 864 A.Put(NON_UNIQUE_NAME, kEncryptedString); | |
| 865 A.Put(IS_UNSYNCED, true); | |
| 866 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); | |
| 867 ASSERT_TRUE(B.good()); | |
| 868 B.Put(SPECIFICS, modified_bookmark); | |
| 869 B.Put(NON_UNIQUE_NAME, kEncryptedString); | |
| 870 B.Put(IS_UNSYNCED, true); | |
| 871 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3)); | |
| 872 ASSERT_TRUE(C.good()); | |
| 873 C.Put(SPECIFICS, modified_bookmark); | |
| 874 C.Put(NON_UNIQUE_NAME, kEncryptedString); | |
| 875 C.Put(IS_UNSYNCED, true); | |
| 876 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4)); | |
| 877 ASSERT_TRUE(D.good()); | |
| 878 D.Put(SPECIFICS, modified_pref); | |
| 879 D.Put(NON_UNIQUE_NAME, kEncryptedString); | |
| 880 D.Put(IS_UNSYNCED, true); | |
| 881 } | |
| 882 SyncShareAsDelegate(); | |
| 883 { | |
| 884 EXPECT_EQ(0U, session_->status_controller().unsynced_handles().size()); | |
| 885 // Item 1 remains unsynced due to there being pending keys. | |
| 886 // Items 2, 3, 4 should remain unsynced since they were not up to date. | |
| 887 ReadTransaction rtrans(FROM_HERE, dir); | |
| 888 VERIFY_ENTRY(1, false, true, false, 0, 40, 40, ids_, &rtrans); | |
| 889 VERIFY_ENTRY(2, true, true, true, 1, 10, 30, ids_, &rtrans); | |
| 890 VERIFY_ENTRY(3, true, true, false, 1, 10, 30, ids_, &rtrans); | |
| 891 VERIFY_ENTRY(4, true, true, true, 0, 10, 30, ids_, &rtrans); | |
| 892 } | |
| 893 { | |
| 894 ReadTransaction rtrans(FROM_HERE, dir); | |
| 895 // Resolve the pending keys. | |
| 896 syncdb_.manager()->GetCryptographer(&rtrans)->DecryptPendingKeys( | |
| 897 key_params); | |
| 898 } | |
| 899 // First cycle resolves conflicts, second cycle commits changes. | |
| 900 SyncShareAsDelegate(); | |
| 901 EXPECT_EQ(2, session_->status_controller().syncer_status(). | |
| 902 num_server_overwrites); | |
| 903 EXPECT_EQ(1, session_->status_controller().syncer_status(). | |
| 904 num_local_overwrites); | |
| 905 // We attempted to commit item 1. | |
| 906 EXPECT_EQ(1U, session_->status_controller().unsynced_handles().size()); | |
| 907 EXPECT_TRUE(session_->status_controller().did_commit_items()); | |
| 908 SyncShareAsDelegate(); | |
| 909 { | |
| 910 // Everything should be resolved now. The local changes should have | |
| 911 // overwritten the server changes for 2 and 4, while the server changes | |
| 912 // overwrote the local for entry 3. | |
| 913 // We attempted to commit two handles. | |
| 914 EXPECT_EQ(0, session_->status_controller().syncer_status(). | |
| 915 num_server_overwrites); | |
| 916 EXPECT_EQ(0, session_->status_controller().syncer_status(). | |
| 917 num_local_overwrites); | |
| 918 EXPECT_EQ(2U, session_->status_controller().unsynced_handles().size()); | |
| 919 EXPECT_TRUE(session_->status_controller().did_commit_items()); | |
| 920 ReadTransaction rtrans(FROM_HERE, dir); | |
| 921 VERIFY_ENTRY(1, false, false, false, 0, 41, 41, ids_, &rtrans); | |
| 922 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); | |
| 923 VERIFY_ENTRY(3, false, false, false, 1, 30, 30, ids_, &rtrans); | |
| 924 VERIFY_ENTRY(4, false, false, false, 0, 31, 31, ids_, &rtrans); | |
| 925 } | |
| 926 } | |
| 927 | |
| 751 TEST_F(SyncerTest, NigoriConflicts) { | 928 TEST_F(SyncerTest, NigoriConflicts) { |
| 752 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 929 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 753 ASSERT_TRUE(dir.good()); | 930 ASSERT_TRUE(dir.good()); |
| 754 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; | 931 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; |
| 755 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; | 932 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; |
| 756 browser_sync::Cryptographer other_cryptographer; | 933 browser_sync::Cryptographer other_cryptographer; |
| 757 other_cryptographer.AddKey(other_key_params); | 934 other_cryptographer.AddKey(other_key_params); |
| 758 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); | 935 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); |
| 759 sync_pb::EntitySpecifics initial_nigori_specifics; | 936 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 760 initial_nigori_specifics.MutableExtension(sync_pb::nigori); | 937 initial_nigori_specifics.MutableExtension(sync_pb::nigori); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 our_encrypted_specifics.encrypted())); | 1040 our_encrypted_specifics.encrypted())); |
| 864 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1041 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 865 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); | 1042 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); |
| 866 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)->CanDecrypt( | 1043 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)->CanDecrypt( |
| 867 other_encrypted_specifics.encrypted())); | 1044 other_encrypted_specifics.encrypted())); |
| 868 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1045 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 869 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); | 1046 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); |
| 870 } | 1047 } |
| 871 } | 1048 } |
| 872 | 1049 |
| 1050 #undef VERIFY_ENTRY | |
| 873 | 1051 |
| 874 // TODO(chron): More corner case unit tests around validation. | 1052 // TODO(chron): More corner case unit tests around validation. |
| 875 TEST_F(SyncerTest, TestCommitMetahandleIterator) { | 1053 TEST_F(SyncerTest, TestCommitMetahandleIterator) { |
| 876 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1054 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 877 ASSERT_TRUE(dir.good()); | 1055 ASSERT_TRUE(dir.good()); |
| 878 StatusController* status = session_->mutable_status_controller(); | 1056 StatusController* status = session_->mutable_status_controller(); |
| 879 const vector<int64>& unsynced(status->unsynced_handles()); | 1057 const vector<int64>& unsynced(status->unsynced_handles()); |
| 880 | 1058 |
| 881 { | 1059 { |
| 882 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 1060 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| (...skipping 4050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4933 EXPECT_GE(0, Get(metahandle_, BASE_VERSION)); | 5111 EXPECT_GE(0, Get(metahandle_, BASE_VERSION)); |
| 4934 EXPECT_GE(0, Get(metahandle_, SERVER_VERSION)); | 5112 EXPECT_GE(0, Get(metahandle_, SERVER_VERSION)); |
| 4935 } | 5113 } |
| 4936 | 5114 |
| 4937 protected: | 5115 protected: |
| 4938 const std::string client_tag_; | 5116 const std::string client_tag_; |
| 4939 int64 metahandle_; | 5117 int64 metahandle_; |
| 4940 }; | 5118 }; |
| 4941 | 5119 |
| 4942 TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) { | 5120 TEST_F(SyncerUndeletionTest, UndeleteDuringCommit) { |
| 4943 const StatusController& status = session_->status_controller(); | |
| 4944 | |
| 4945 Create(); | 5121 Create(); |
| 4946 ExpectUnsyncedCreation(); | 5122 ExpectUnsyncedCreation(); |
| 4947 SyncShareAsDelegate(); | 5123 SyncShareAsDelegate(); |
| 4948 | 5124 |
| 4949 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5125 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4950 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5126 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 4951 ExpectSyncedAndCreated(); | 5127 ExpectSyncedAndCreated(); |
| 4952 | 5128 |
| 4953 // Delete, begin committing the delete, then undelete while committing. | 5129 // Delete, begin committing the delete, then undelete while committing. |
| 4954 Delete(); | 5130 Delete(); |
| 4955 ExpectUnsyncedDeletion(); | 5131 ExpectUnsyncedDeletion(); |
| 4956 mock_server_->SetMidCommitCallback( | 5132 mock_server_->SetMidCommitCallback( |
| 4957 NewCallback<SyncerUndeletionTest>(this, | 5133 NewCallback<SyncerUndeletionTest>(this, |
| 4958 &SyncerUndeletionTest::Undelete)); | 5134 &SyncerUndeletionTest::Undelete)); |
| 4959 SyncShareAsDelegate(); | 5135 SyncShareAsDelegate(); |
| 4960 | 5136 |
| 4961 // The item ought to exist as an unsynced undeletion (meaning, | 5137 // The item ought to exist as an unsynced undeletion (meaning, |
| 4962 // we think that the next commit ought to be a recreation commit). | 5138 // we think that the next commit ought to be a recreation commit). |
| 4963 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5139 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 4964 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5140 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4965 ExpectUnsyncedUndeletion(); | 5141 ExpectUnsyncedUndeletion(); |
| 4966 | 5142 |
| 4967 // Now, encounter a GetUpdates corresponding to the deletion from | 5143 // Now, encounter a GetUpdates corresponding to the deletion from |
| 4968 // the server. The undeletion should prevail again and be committed. | 5144 // the server. The undeletion should prevail again and be committed. |
| 4969 // None of this should trigger any conflict detection -- it is perfectly | 5145 // None of this should trigger any conflict detection -- it is perfectly |
| 4970 // normal to recieve updates from our own commits. | 5146 // normal to recieve updates from our own commits. |
| 4971 mock_server_->SetMidCommitCallback(NULL); | 5147 mock_server_->SetMidCommitCallback(NULL); |
| 4972 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); | 5148 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); |
| 4973 SyncShareAsDelegate(); | 5149 SyncShareAsDelegate(); |
| 4974 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5150 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 4975 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5151 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4976 ExpectSyncedAndCreated(); | 5152 ExpectSyncedAndCreated(); |
| 4977 } | 5153 } |
| 4978 | 5154 |
| 4979 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { | 5155 TEST_F(SyncerUndeletionTest, UndeleteBeforeCommit) { |
| 4980 const StatusController& status = session_->status_controller(); | |
| 4981 | |
| 4982 Create(); | 5156 Create(); |
| 4983 ExpectUnsyncedCreation(); | 5157 ExpectUnsyncedCreation(); |
| 4984 SyncShareAsDelegate(); | 5158 SyncShareAsDelegate(); |
| 4985 | 5159 |
| 4986 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5160 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 4987 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5161 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 4988 ExpectSyncedAndCreated(); | 5162 ExpectSyncedAndCreated(); |
| 4989 | 5163 |
| 4990 // Delete and undelete, then sync to pick up the result. | 5164 // Delete and undelete, then sync to pick up the result. |
| 4991 Delete(); | 5165 Delete(); |
| 4992 ExpectUnsyncedDeletion(); | 5166 ExpectUnsyncedDeletion(); |
| 4993 Undelete(); | 5167 Undelete(); |
| 4994 ExpectUnsyncedEdit(); // Edit, not undelete: server thinks it exists. | 5168 ExpectUnsyncedEdit(); // Edit, not undelete: server thinks it exists. |
| 4995 SyncShareAsDelegate(); | 5169 SyncShareAsDelegate(); |
| 4996 | 5170 |
| 4997 // The item ought to have committed successfully. | 5171 // The item ought to have committed successfully. |
| 4998 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5172 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 4999 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5173 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5000 ExpectSyncedAndCreated(); | 5174 ExpectSyncedAndCreated(); |
| 5001 EXPECT_EQ(2, Get(metahandle_, BASE_VERSION)); | 5175 EXPECT_EQ(2, Get(metahandle_, BASE_VERSION)); |
| 5002 | 5176 |
| 5003 // Now, encounter a GetUpdates corresponding to the just-committed | 5177 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5004 // update. | 5178 // update. |
| 5005 mock_server_->AddUpdateFromLastCommit(); | 5179 mock_server_->AddUpdateFromLastCommit(); |
| 5006 SyncShareAsDelegate(); | 5180 SyncShareAsDelegate(); |
| 5007 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5181 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5008 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5182 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5009 ExpectSyncedAndCreated(); | 5183 ExpectSyncedAndCreated(); |
| 5010 } | 5184 } |
| 5011 | 5185 |
| 5012 TEST_F(SyncerUndeletionTest, UndeleteAfterCommitButBeforeGetUpdates) { | 5186 TEST_F(SyncerUndeletionTest, UndeleteAfterCommitButBeforeGetUpdates) { |
| 5013 const StatusController& status = session_->status_controller(); | |
| 5014 | |
| 5015 Create(); | 5187 Create(); |
| 5016 ExpectUnsyncedCreation(); | 5188 ExpectUnsyncedCreation(); |
| 5017 SyncShareAsDelegate(); | 5189 SyncShareAsDelegate(); |
| 5018 | 5190 |
| 5019 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5191 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5020 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5192 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5021 ExpectSyncedAndCreated(); | 5193 ExpectSyncedAndCreated(); |
| 5022 | 5194 |
| 5023 // Delete and commit. | 5195 // Delete and commit. |
| 5024 Delete(); | 5196 Delete(); |
| 5025 ExpectUnsyncedDeletion(); | 5197 ExpectUnsyncedDeletion(); |
| 5026 SyncShareAsDelegate(); | 5198 SyncShareAsDelegate(); |
| 5027 | 5199 |
| 5028 // The item ought to have committed successfully. | 5200 // The item ought to have committed successfully. |
| 5029 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5201 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5030 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5202 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5031 ExpectSyncedAndDeleted(); | 5203 ExpectSyncedAndDeleted(); |
| 5032 | 5204 |
| 5033 // Before the GetUpdates, the item is locally undeleted. | 5205 // Before the GetUpdates, the item is locally undeleted. |
| 5034 Undelete(); | 5206 Undelete(); |
| 5035 ExpectUnsyncedUndeletion(); | 5207 ExpectUnsyncedUndeletion(); |
| 5036 | 5208 |
| 5037 // Now, encounter a GetUpdates corresponding to the just-committed | 5209 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5038 // deletion update. The undeletion should prevail. | 5210 // deletion update. The undeletion should prevail. |
| 5039 mock_server_->AddUpdateFromLastCommit(); | 5211 mock_server_->AddUpdateFromLastCommit(); |
| 5040 SyncShareAsDelegate(); | 5212 SyncShareAsDelegate(); |
| 5041 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5213 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5042 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5214 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5043 ExpectSyncedAndCreated(); | 5215 ExpectSyncedAndCreated(); |
| 5044 } | 5216 } |
| 5045 | 5217 |
| 5046 TEST_F(SyncerUndeletionTest, UndeleteAfterDeleteAndGetUpdates) { | 5218 TEST_F(SyncerUndeletionTest, UndeleteAfterDeleteAndGetUpdates) { |
| 5047 const StatusController& status = session_->status_controller(); | |
| 5048 | |
| 5049 Create(); | 5219 Create(); |
| 5050 ExpectUnsyncedCreation(); | 5220 ExpectUnsyncedCreation(); |
| 5051 SyncShareAsDelegate(); | 5221 SyncShareAsDelegate(); |
| 5052 | 5222 |
| 5053 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5223 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5054 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5224 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5055 ExpectSyncedAndCreated(); | 5225 ExpectSyncedAndCreated(); |
| 5056 | 5226 |
| 5057 mock_server_->AddUpdateFromLastCommit(); | 5227 mock_server_->AddUpdateFromLastCommit(); |
| 5058 SyncShareAsDelegate(); | 5228 SyncShareAsDelegate(); |
| 5059 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5229 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5060 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5230 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5061 ExpectSyncedAndCreated(); | 5231 ExpectSyncedAndCreated(); |
| 5062 | 5232 |
| 5063 // Delete and commit. | 5233 // Delete and commit. |
| 5064 Delete(); | 5234 Delete(); |
| 5065 ExpectUnsyncedDeletion(); | 5235 ExpectUnsyncedDeletion(); |
| 5066 SyncShareAsDelegate(); | 5236 SyncShareAsDelegate(); |
| 5067 | 5237 |
| 5068 // The item ought to have committed successfully. | 5238 // The item ought to have committed successfully. |
| 5069 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5239 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5070 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5240 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5071 ExpectSyncedAndDeleted(); | 5241 ExpectSyncedAndDeleted(); |
| 5072 | 5242 |
| 5073 // Now, encounter a GetUpdates corresponding to the just-committed | 5243 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5074 // deletion update. Should be consistent. | 5244 // deletion update. Should be consistent. |
| 5075 mock_server_->AddUpdateFromLastCommit(); | 5245 mock_server_->AddUpdateFromLastCommit(); |
| 5076 SyncShareAsDelegate(); | 5246 SyncShareAsDelegate(); |
| 5077 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5247 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5078 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5248 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5079 ExpectSyncedAndDeleted(); | 5249 ExpectSyncedAndDeleted(); |
| 5080 | 5250 |
| 5081 // After the GetUpdates, the item is locally undeleted. | 5251 // After the GetUpdates, the item is locally undeleted. |
| 5082 Undelete(); | 5252 Undelete(); |
| 5083 ExpectUnsyncedUndeletion(); | 5253 ExpectUnsyncedUndeletion(); |
| 5084 | 5254 |
| 5085 // Now, encounter a GetUpdates corresponding to the just-committed | 5255 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5086 // deletion update. The undeletion should prevail. | 5256 // deletion update. The undeletion should prevail. |
| 5087 SyncShareAsDelegate(); | 5257 SyncShareAsDelegate(); |
| 5088 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5258 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5089 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5259 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5090 ExpectSyncedAndCreated(); | 5260 ExpectSyncedAndCreated(); |
| 5091 } | 5261 } |
| 5092 | 5262 |
| 5093 // Test processing of undeletion GetUpdateses. | 5263 // Test processing of undeletion GetUpdateses. |
| 5094 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletes) { | 5264 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletes) { |
| 5095 const StatusController& status = session_->status_controller(); | |
| 5096 | |
| 5097 Create(); | 5265 Create(); |
| 5098 ExpectUnsyncedCreation(); | 5266 ExpectUnsyncedCreation(); |
| 5099 SyncShareAsDelegate(); | 5267 SyncShareAsDelegate(); |
| 5100 | 5268 |
| 5101 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5269 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5102 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5270 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5103 ExpectSyncedAndCreated(); | 5271 ExpectSyncedAndCreated(); |
| 5104 | 5272 |
| 5105 // Add a delete from the server. | 5273 // Add a delete from the server. |
| 5106 mock_server_->AddUpdateFromLastCommit(); | 5274 mock_server_->AddUpdateFromLastCommit(); |
| 5107 SyncShareAsDelegate(); | 5275 SyncShareAsDelegate(); |
| 5108 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5276 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5109 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5277 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5110 ExpectSyncedAndCreated(); | 5278 ExpectSyncedAndCreated(); |
| 5111 | 5279 |
| 5112 // Some other client deletes the item. | 5280 // Some other client deletes the item. |
| 5113 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); | 5281 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); |
| 5114 SyncShareAsDelegate(); | 5282 SyncShareAsDelegate(); |
| 5115 | 5283 |
| 5116 // The update ought to have applied successfully. | 5284 // The update ought to have applied successfully. |
| 5117 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5285 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5118 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5286 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5119 ExpectSyncedAndDeleted(); | 5287 ExpectSyncedAndDeleted(); |
| 5120 | 5288 |
| 5121 // Undelete it locally. | 5289 // Undelete it locally. |
| 5122 Undelete(); | 5290 Undelete(); |
| 5123 ExpectUnsyncedUndeletion(); | 5291 ExpectUnsyncedUndeletion(); |
| 5124 SyncShareAsDelegate(); | 5292 SyncShareAsDelegate(); |
| 5125 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5293 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5126 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5294 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5127 ExpectSyncedAndCreated(); | 5295 ExpectSyncedAndCreated(); |
| 5128 | 5296 |
| 5129 // Now, encounter a GetUpdates corresponding to the just-committed | 5297 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5130 // deletion update. The undeletion should prevail. | 5298 // deletion update. The undeletion should prevail. |
| 5131 mock_server_->AddUpdateFromLastCommit(); | 5299 mock_server_->AddUpdateFromLastCommit(); |
| 5132 SyncShareAsDelegate(); | 5300 SyncShareAsDelegate(); |
| 5133 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5301 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5134 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5302 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5135 ExpectSyncedAndCreated(); | 5303 ExpectSyncedAndCreated(); |
| 5136 } | 5304 } |
| 5137 | 5305 |
| 5138 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletesImmediately) { | 5306 TEST_F(SyncerUndeletionTest, UndeleteAfterOtherClientDeletesImmediately) { |
| 5139 const StatusController& status = session_->status_controller(); | |
| 5140 | |
| 5141 Create(); | 5307 Create(); |
| 5142 ExpectUnsyncedCreation(); | 5308 ExpectUnsyncedCreation(); |
| 5143 SyncShareAsDelegate(); | 5309 SyncShareAsDelegate(); |
| 5144 | 5310 |
| 5145 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5311 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5146 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5312 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5147 ExpectSyncedAndCreated(); | 5313 ExpectSyncedAndCreated(); |
| 5148 | 5314 |
| 5149 // Some other client deletes the item before we get a chance | 5315 // Some other client deletes the item before we get a chance |
| 5150 // to GetUpdates our original request. | 5316 // to GetUpdates our original request. |
| 5151 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); | 5317 mock_server_->AddUpdateTombstone(Get(metahandle_, ID)); |
| 5152 SyncShareAsDelegate(); | 5318 SyncShareAsDelegate(); |
| 5153 | 5319 |
| 5154 // The update ought to have applied successfully. | 5320 // The update ought to have applied successfully. |
| 5155 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5321 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5156 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5322 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5157 ExpectSyncedAndDeleted(); | 5323 ExpectSyncedAndDeleted(); |
| 5158 | 5324 |
| 5159 // Undelete it locally. | 5325 // Undelete it locally. |
| 5160 Undelete(); | 5326 Undelete(); |
| 5161 ExpectUnsyncedUndeletion(); | 5327 ExpectUnsyncedUndeletion(); |
| 5162 SyncShareAsDelegate(); | 5328 SyncShareAsDelegate(); |
| 5163 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5329 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5164 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5330 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5165 ExpectSyncedAndCreated(); | 5331 ExpectSyncedAndCreated(); |
| 5166 | 5332 |
| 5167 // Now, encounter a GetUpdates corresponding to the just-committed | 5333 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5168 // deletion update. The undeletion should prevail. | 5334 // deletion update. The undeletion should prevail. |
| 5169 mock_server_->AddUpdateFromLastCommit(); | 5335 mock_server_->AddUpdateFromLastCommit(); |
| 5170 SyncShareAsDelegate(); | 5336 SyncShareAsDelegate(); |
| 5171 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5337 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5172 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5338 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5173 ExpectSyncedAndCreated(); | 5339 ExpectSyncedAndCreated(); |
| 5174 } | 5340 } |
| 5175 | 5341 |
| 5176 TEST_F(SyncerUndeletionTest, OtherClientUndeletes) { | 5342 TEST_F(SyncerUndeletionTest, OtherClientUndeletes) { |
| 5177 const StatusController& status = session_->status_controller(); | |
| 5178 | |
| 5179 Create(); | 5343 Create(); |
| 5180 ExpectUnsyncedCreation(); | 5344 ExpectUnsyncedCreation(); |
| 5181 SyncShareAsDelegate(); | 5345 SyncShareAsDelegate(); |
| 5182 | 5346 |
| 5183 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5347 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5184 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5348 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5185 ExpectSyncedAndCreated(); | 5349 ExpectSyncedAndCreated(); |
| 5186 | 5350 |
| 5187 // Get the updates of our just-committed entry. | 5351 // Get the updates of our just-committed entry. |
| 5188 mock_server_->AddUpdateFromLastCommit(); | 5352 mock_server_->AddUpdateFromLastCommit(); |
| 5189 SyncShareAsDelegate(); | 5353 SyncShareAsDelegate(); |
| 5190 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5354 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5191 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5355 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5192 ExpectSyncedAndCreated(); | 5356 ExpectSyncedAndCreated(); |
| 5193 | 5357 |
| 5194 // We delete the item. | 5358 // We delete the item. |
| 5195 Delete(); | 5359 Delete(); |
| 5196 ExpectUnsyncedDeletion(); | 5360 ExpectUnsyncedDeletion(); |
| 5197 SyncShareAsDelegate(); | 5361 SyncShareAsDelegate(); |
| 5198 | 5362 |
| 5199 // The update ought to have applied successfully. | 5363 // The update ought to have applied successfully. |
| 5200 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5364 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5201 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5365 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5202 ExpectSyncedAndDeleted(); | 5366 ExpectSyncedAndDeleted(); |
| 5203 | 5367 |
| 5204 // Now, encounter a GetUpdates corresponding to the just-committed | 5368 // Now, encounter a GetUpdates corresponding to the just-committed |
| 5205 // deletion update. | 5369 // deletion update. |
| 5206 mock_server_->AddUpdateFromLastCommit(); | 5370 mock_server_->AddUpdateFromLastCommit(); |
| 5207 SyncShareAsDelegate(); | 5371 SyncShareAsDelegate(); |
| 5208 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5372 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5209 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5373 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5210 ExpectSyncedAndDeleted(); | 5374 ExpectSyncedAndDeleted(); |
| 5211 | 5375 |
| 5212 // Some other client undeletes the item. | 5376 // Some other client undeletes the item. |
| 5213 mock_server_->AddUpdateBookmark(Get(metahandle_, ID), | 5377 mock_server_->AddUpdateBookmark(Get(metahandle_, ID), |
| 5214 Get(metahandle_, PARENT_ID), | 5378 Get(metahandle_, PARENT_ID), |
| 5215 "Thadeusz", 100, 1000); | 5379 "Thadeusz", 100, 1000); |
| 5216 mock_server_->SetLastUpdateClientTag(client_tag_); | 5380 mock_server_->SetLastUpdateClientTag(client_tag_); |
| 5217 SyncShareAsDelegate(); | 5381 SyncShareAsDelegate(); |
| 5218 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5382 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5219 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5383 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5220 ExpectSyncedAndCreated(); | 5384 ExpectSyncedAndCreated(); |
| 5221 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); | 5385 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); |
| 5222 } | 5386 } |
| 5223 | 5387 |
| 5224 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) { | 5388 TEST_F(SyncerUndeletionTest, OtherClientUndeletesImmediately) { |
| 5225 const StatusController& status = session_->status_controller(); | |
| 5226 | |
| 5227 Create(); | 5389 Create(); |
| 5228 ExpectUnsyncedCreation(); | 5390 ExpectUnsyncedCreation(); |
| 5229 SyncShareAsDelegate(); | 5391 SyncShareAsDelegate(); |
| 5230 | 5392 |
| 5231 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5393 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5232 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5394 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5233 ExpectSyncedAndCreated(); | 5395 ExpectSyncedAndCreated(); |
| 5234 | 5396 |
| 5235 // Get the updates of our just-committed entry. | 5397 // Get the updates of our just-committed entry. |
| 5236 mock_server_->AddUpdateFromLastCommit(); | 5398 mock_server_->AddUpdateFromLastCommit(); |
| 5237 SyncShareAsDelegate(); | 5399 SyncShareAsDelegate(); |
| 5238 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5400 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5239 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5401 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5240 ExpectSyncedAndCreated(); | 5402 ExpectSyncedAndCreated(); |
| 5241 | 5403 |
| 5242 // We delete the item. | 5404 // We delete the item. |
| 5243 Delete(); | 5405 Delete(); |
| 5244 ExpectUnsyncedDeletion(); | 5406 ExpectUnsyncedDeletion(); |
| 5245 SyncShareAsDelegate(); | 5407 SyncShareAsDelegate(); |
| 5246 | 5408 |
| 5247 // The update ought to have applied successfully. | 5409 // The update ought to have applied successfully. |
| 5248 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5410 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5249 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5411 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5250 ExpectSyncedAndDeleted(); | 5412 ExpectSyncedAndDeleted(); |
| 5251 | 5413 |
| 5252 // Some other client undeletes before we see the update from our | 5414 // Some other client undeletes before we see the update from our |
| 5253 // commit. | 5415 // commit. |
| 5254 mock_server_->AddUpdateBookmark(Get(metahandle_, ID), | 5416 mock_server_->AddUpdateBookmark(Get(metahandle_, ID), |
| 5255 Get(metahandle_, PARENT_ID), | 5417 Get(metahandle_, PARENT_ID), |
| 5256 "Thadeusz", 100, 1000); | 5418 "Thadeusz", 100, 1000); |
| 5257 mock_server_->SetLastUpdateClientTag(client_tag_); | 5419 mock_server_->SetLastUpdateClientTag(client_tag_); |
| 5258 SyncShareAsDelegate(); | 5420 SyncShareAsDelegate(); |
| 5259 EXPECT_EQ(0, status.TotalNumConflictingItems()); | 5421 EXPECT_EQ(0, session_->status_controller().TotalNumConflictingItems()); |
| 5260 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); | 5422 EXPECT_EQ(1, mock_server_->GetAndClearNumGetUpdatesRequests()); |
| 5261 ExpectSyncedAndCreated(); | 5423 ExpectSyncedAndCreated(); |
| 5262 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); | 5424 EXPECT_EQ("Thadeusz", Get(metahandle_, NON_UNIQUE_NAME)); |
| 5263 } | 5425 } |
| 5264 | 5426 |
| 5265 // A group of tests exercising the syncer's handling of sibling ordering, as | 5427 // A group of tests exercising the syncer's handling of sibling ordering, as |
| 5266 // represented in the sync protocol. | 5428 // represented in the sync protocol. |
| 5267 class SyncerPositionUpdateTest : public SyncerTest { | 5429 class SyncerPositionUpdateTest : public SyncerTest { |
| 5268 public: | 5430 public: |
| 5269 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {} | 5431 SyncerPositionUpdateTest() : next_update_id_(1), next_revision_(1) {} |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5477 Add(low_id_); | 5639 Add(low_id_); |
| 5478 Add(high_id_); | 5640 Add(high_id_); |
| 5479 SyncShareAsDelegate(); | 5641 SyncShareAsDelegate(); |
| 5480 ExpectLocalOrderIsByServerId(); | 5642 ExpectLocalOrderIsByServerId(); |
| 5481 } | 5643 } |
| 5482 | 5644 |
| 5483 const SyncerTest::CommitOrderingTest | 5645 const SyncerTest::CommitOrderingTest |
| 5484 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 5646 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
| 5485 | 5647 |
| 5486 } // namespace browser_sync | 5648 } // namespace browser_sync |
| OLD | NEW |