| OLD | NEW |
| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "sync/util/time.h" | 55 #include "sync/util/time.h" |
| 56 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 57 | 57 |
| 58 using base::TimeDelta; | 58 using base::TimeDelta; |
| 59 | 59 |
| 60 using std::map; | 60 using std::map; |
| 61 using std::multimap; | 61 using std::multimap; |
| 62 using std::set; | 62 using std::set; |
| 63 using std::string; | 63 using std::string; |
| 64 | 64 |
| 65 namespace csync { | 65 namespace syncer { |
| 66 | 66 |
| 67 using syncable::BaseTransaction; | 67 using syncable::BaseTransaction; |
| 68 using syncable::Blob; | 68 using syncable::Blob; |
| 69 using syncable::CountEntriesWithName; | 69 using syncable::CountEntriesWithName; |
| 70 using syncable::Directory; | 70 using syncable::Directory; |
| 71 using syncable::Entry; | 71 using syncable::Entry; |
| 72 using syncable::GetFirstEntryWithName; | 72 using syncable::GetFirstEntryWithName; |
| 73 using syncable::GetOnlyEntryWithName; | 73 using syncable::GetOnlyEntryWithName; |
| 74 using syncable::Id; | 74 using syncable::Id; |
| 75 using syncable::kEncryptedString; | 75 using syncable::kEncryptedString; |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 553 |
| 554 scoped_ptr<SyncSession> session_; | 554 scoped_ptr<SyncSession> session_; |
| 555 scoped_ptr<SyncSessionContext> context_; | 555 scoped_ptr<SyncSessionContext> context_; |
| 556 bool saw_syncer_event_; | 556 bool saw_syncer_event_; |
| 557 base::TimeDelta last_short_poll_interval_received_; | 557 base::TimeDelta last_short_poll_interval_received_; |
| 558 base::TimeDelta last_long_poll_interval_received_; | 558 base::TimeDelta last_long_poll_interval_received_; |
| 559 base::TimeDelta last_sessions_commit_delay_seconds_; | 559 base::TimeDelta last_sessions_commit_delay_seconds_; |
| 560 scoped_refptr<ModelSafeWorker> worker_; | 560 scoped_refptr<ModelSafeWorker> worker_; |
| 561 | 561 |
| 562 syncable::ModelTypeSet enabled_datatypes_; | 562 syncable::ModelTypeSet enabled_datatypes_; |
| 563 csync::TrafficRecorder traffic_recorder_; | 563 syncer::TrafficRecorder traffic_recorder_; |
| 564 | 564 |
| 565 DISALLOW_COPY_AND_ASSIGN(SyncerTest); | 565 DISALLOW_COPY_AND_ASSIGN(SyncerTest); |
| 566 }; | 566 }; |
| 567 | 567 |
| 568 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { | 568 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { |
| 569 { | 569 { |
| 570 Syncer::UnsyncedMetaHandles handles; | 570 Syncer::UnsyncedMetaHandles handles; |
| 571 { | 571 { |
| 572 syncable::ReadTransaction trans(FROM_HERE, directory()); | 572 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 573 SyncerUtil::GetUnsyncedEntries(&trans, &handles); | 573 SyncerUtil::GetUnsyncedEntries(&trans, &handles); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 707 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 708 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); | 708 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); |
| 709 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); | 709 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); |
| 710 SyncShareNudge(); | 710 SyncShareNudge(); |
| 711 // Server side change will put A in conflict. | 711 // Server side change will put A in conflict. |
| 712 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); | 712 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); |
| 713 { | 713 { |
| 714 // Mark bookmarks as encrypted and set the cryptographer to have pending | 714 // Mark bookmarks as encrypted and set the cryptographer to have pending |
| 715 // keys. | 715 // keys. |
| 716 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 716 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
| 717 csync::Cryptographer other_cryptographer(&encryptor_); | 717 syncer::Cryptographer other_cryptographer(&encryptor_); |
| 718 other_cryptographer.AddKey(other_params); | 718 other_cryptographer.AddKey(other_params); |
| 719 sync_pb::EntitySpecifics specifics; | 719 sync_pb::EntitySpecifics specifics; |
| 720 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 720 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 721 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 721 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 722 nigori->set_encrypt_bookmarks(true); | 722 nigori->set_encrypt_bookmarks(true); |
| 723 // Set up with an old passphrase, but have pending keys | 723 // Set up with an old passphrase, but have pending keys |
| 724 cryptographer(&wtrans)->AddKey(key_params); | 724 cryptographer(&wtrans)->AddKey(key_params); |
| 725 cryptographer(&wtrans)->Encrypt(bookmark, | 725 cryptographer(&wtrans)->Encrypt(bookmark, |
| 726 encrypted_bookmark.mutable_encrypted()); | 726 encrypted_bookmark.mutable_encrypted()); |
| 727 cryptographer(&wtrans)->Update(*nigori); | 727 cryptographer(&wtrans)->Update(*nigori); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 syncable::ReadTransaction rtrans(FROM_HERE, directory()); | 800 syncable::ReadTransaction rtrans(FROM_HERE, directory()); |
| 801 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); | 801 VERIFY_ENTRY(1, false, false, false, 0, 21, 21, ids_, &rtrans); |
| 802 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); | 802 VERIFY_ENTRY(2, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 803 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); | 803 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 804 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); | 804 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); |
| 805 } | 805 } |
| 806 } | 806 } |
| 807 | 807 |
| 808 TEST_F(SyncerTest, EncryptionAwareConflicts) { | 808 TEST_F(SyncerTest, EncryptionAwareConflicts) { |
| 809 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 809 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 810 csync::Cryptographer other_cryptographer(&encryptor_); | 810 syncer::Cryptographer other_cryptographer(&encryptor_); |
| 811 other_cryptographer.AddKey(key_params); | 811 other_cryptographer.AddKey(key_params); |
| 812 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; | 812 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; |
| 813 bookmark.mutable_bookmark()->set_title("title"); | 813 bookmark.mutable_bookmark()->set_title("title"); |
| 814 other_cryptographer.Encrypt(bookmark, | 814 other_cryptographer.Encrypt(bookmark, |
| 815 encrypted_bookmark.mutable_encrypted()); | 815 encrypted_bookmark.mutable_encrypted()); |
| 816 AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark); | 816 AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark); |
| 817 modified_bookmark.mutable_bookmark()->set_title("title2"); | 817 modified_bookmark.mutable_bookmark()->set_title("title2"); |
| 818 other_cryptographer.Encrypt(modified_bookmark, | 818 other_cryptographer.Encrypt(modified_bookmark, |
| 819 modified_bookmark.mutable_encrypted()); | 819 modified_bookmark.mutable_encrypted()); |
| 820 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; | 820 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 | 974 |
| 975 #undef VERIFY_ENTRY | 975 #undef VERIFY_ENTRY |
| 976 | 976 |
| 977 // Receive an old nigori with old encryption keys and encrypted types. We should | 977 // Receive an old nigori with old encryption keys and encrypted types. We should |
| 978 // not revert our default key or encrypted types. | 978 // not revert our default key or encrypted types. |
| 979 TEST_F(SyncerTest, ReceiveOldNigori) { | 979 TEST_F(SyncerTest, ReceiveOldNigori) { |
| 980 KeyParams old_key = {"localhost", "dummy", "old"}; | 980 KeyParams old_key = {"localhost", "dummy", "old"}; |
| 981 KeyParams current_key = {"localhost", "dummy", "cur"}; | 981 KeyParams current_key = {"localhost", "dummy", "cur"}; |
| 982 | 982 |
| 983 // Data for testing encryption/decryption. | 983 // Data for testing encryption/decryption. |
| 984 csync::Cryptographer other_cryptographer(&encryptor_); | 984 syncer::Cryptographer other_cryptographer(&encryptor_); |
| 985 other_cryptographer.AddKey(old_key); | 985 other_cryptographer.AddKey(old_key); |
| 986 sync_pb::EntitySpecifics other_encrypted_specifics; | 986 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 987 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | 987 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 988 other_cryptographer.Encrypt( | 988 other_cryptographer.Encrypt( |
| 989 other_encrypted_specifics, | 989 other_encrypted_specifics, |
| 990 other_encrypted_specifics.mutable_encrypted()); | 990 other_encrypted_specifics.mutable_encrypted()); |
| 991 sync_pb::EntitySpecifics our_encrypted_specifics; | 991 sync_pb::EntitySpecifics our_encrypted_specifics; |
| 992 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); | 992 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| 993 syncable::ModelTypeSet encrypted_types = syncable::ModelTypeSet::All(); | 993 syncable::ModelTypeSet encrypted_types = syncable::ModelTypeSet::All(); |
| 994 | 994 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 } | 1057 } |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 // Resolve a confict between two nigori's with different encrypted types, | 1060 // Resolve a confict between two nigori's with different encrypted types, |
| 1061 // and encryption keys (remote is explicit). Afterwards, the encrypted types | 1061 // and encryption keys (remote is explicit). Afterwards, the encrypted types |
| 1062 // should be unioned and the cryptographer should have both keys and be | 1062 // should be unioned and the cryptographer should have both keys and be |
| 1063 // encrypting with the remote encryption key by default. | 1063 // encrypting with the remote encryption key by default. |
| 1064 TEST_F(SyncerTest, NigoriConflicts) { | 1064 TEST_F(SyncerTest, NigoriConflicts) { |
| 1065 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; | 1065 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; |
| 1066 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; | 1066 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; |
| 1067 csync::Cryptographer other_cryptographer(&encryptor_); | 1067 syncer::Cryptographer other_cryptographer(&encryptor_); |
| 1068 other_cryptographer.AddKey(other_key_params); | 1068 other_cryptographer.AddKey(other_key_params); |
| 1069 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); | 1069 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); |
| 1070 sync_pb::EntitySpecifics initial_nigori_specifics; | 1070 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 1071 initial_nigori_specifics.mutable_nigori(); | 1071 initial_nigori_specifics.mutable_nigori(); |
| 1072 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | 1072 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| 1073 | 1073 |
| 1074 // Data for testing encryption/decryption. | 1074 // Data for testing encryption/decryption. |
| 1075 sync_pb::EntitySpecifics other_encrypted_specifics; | 1075 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 1076 other_encrypted_specifics.mutable_bookmark()->set_title("title"); | 1076 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 1077 other_cryptographer.Encrypt( | 1077 other_cryptographer.Encrypt( |
| (...skipping 3746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4824 } | 4824 } |
| 4825 | 4825 |
| 4826 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4826 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
| 4827 Add(mid_id_); | 4827 Add(mid_id_); |
| 4828 Add(low_id_); | 4828 Add(low_id_); |
| 4829 Add(high_id_); | 4829 Add(high_id_); |
| 4830 SyncShareNudge(); | 4830 SyncShareNudge(); |
| 4831 ExpectLocalOrderIsByServerId(); | 4831 ExpectLocalOrderIsByServerId(); |
| 4832 } | 4832 } |
| 4833 | 4833 |
| 4834 } // namespace csync | 4834 } // namespace syncer |
| OLD | NEW |