| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 virtual void TearDown() { | 233 virtual void TearDown() { |
| 234 mock_server_.reset(); | 234 mock_server_.reset(); |
| 235 delete syncer_; | 235 delete syncer_; |
| 236 syncer_ = NULL; | 236 syncer_ = NULL; |
| 237 syncdb_.TearDown(); | 237 syncdb_.TearDown(); |
| 238 } | 238 } |
| 239 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { | 239 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { |
| 240 EXPECT_FALSE(entry->Get(IS_DIR)); | 240 EXPECT_FALSE(entry->Get(IS_DIR)); |
| 241 EXPECT_FALSE(entry->Get(IS_DEL)); | 241 EXPECT_FALSE(entry->Get(IS_DEL)); |
| 242 sync_pb::EntitySpecifics specifics; | 242 sync_pb::EntitySpecifics specifics; |
| 243 specifics.MutableExtension(sync_pb::bookmark)->set_url("http://demo/"); | 243 specifics.mutable_bookmark()->set_url("http://demo/"); |
| 244 specifics.MutableExtension(sync_pb::bookmark)->set_favicon("PNG"); | 244 specifics.mutable_bookmark()->set_favicon("PNG"); |
| 245 entry->Put(syncable::SPECIFICS, specifics); | 245 entry->Put(syncable::SPECIFICS, specifics); |
| 246 entry->Put(syncable::IS_UNSYNCED, true); | 246 entry->Put(syncable::IS_UNSYNCED, true); |
| 247 } | 247 } |
| 248 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { | 248 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { |
| 249 EXPECT_FALSE(entry->Get(IS_DIR)); | 249 EXPECT_FALSE(entry->Get(IS_DIR)); |
| 250 EXPECT_FALSE(entry->Get(IS_DEL)); | 250 EXPECT_FALSE(entry->Get(IS_DEL)); |
| 251 VerifyTestBookmarkDataInEntry(entry); | 251 VerifyTestBookmarkDataInEntry(entry); |
| 252 } | 252 } |
| 253 void VerifyTestBookmarkDataInEntry(Entry* entry) { | 253 void VerifyTestBookmarkDataInEntry(Entry* entry) { |
| 254 const sync_pb::EntitySpecifics& specifics = entry->Get(syncable::SPECIFICS); | 254 const sync_pb::EntitySpecifics& specifics = entry->Get(syncable::SPECIFICS); |
| 255 EXPECT_TRUE(specifics.HasExtension(sync_pb::bookmark)); | 255 EXPECT_TRUE(specifics.has_bookmark()); |
| 256 EXPECT_EQ("PNG", specifics.GetExtension(sync_pb::bookmark).favicon()); | 256 EXPECT_EQ("PNG", specifics.bookmark().favicon()); |
| 257 EXPECT_EQ("http://demo/", specifics.GetExtension(sync_pb::bookmark).url()); | 257 EXPECT_EQ("http://demo/", specifics.bookmark().url()); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { | 260 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { |
| 261 // We should trigger after less than 6 syncs, but extra does no harm. | 261 // We should trigger after less than 6 syncs, but extra does no harm. |
| 262 for (int i = 0 ; i < 6 ; ++i) | 262 for (int i = 0 ; i < 6 ; ++i) |
| 263 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); | 263 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); |
| 264 } | 264 } |
| 265 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { | 265 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { |
| 266 // We should trigger after less than 10 syncs, but we want to avoid brittle | 266 // We should trigger after less than 10 syncs, but we want to avoid brittle |
| 267 // tests. | 267 // tests. |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \ | 653 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \ |
| 654 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \ | 654 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \ |
| 655 } while (0) | 655 } while (0) |
| 656 | 656 |
| 657 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { | 657 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { |
| 658 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 658 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 659 ASSERT_TRUE(dir.good()); | 659 ASSERT_TRUE(dir.good()); |
| 660 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 660 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 661 KeyParams other_params = {"localhost", "dummy", "foobar2"}; | 661 KeyParams other_params = {"localhost", "dummy", "foobar2"}; |
| 662 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; | 662 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; |
| 663 bookmark.MutableExtension(sync_pb::bookmark)->set_url("url"); | 663 bookmark.mutable_bookmark()->set_url("url"); |
| 664 bookmark.MutableExtension(sync_pb::bookmark)->set_title("title"); | 664 bookmark.mutable_bookmark()->set_title("title"); |
| 665 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | 665 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); |
| 666 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 666 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 667 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 667 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| 668 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); | 668 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); |
| 669 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); | 669 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); |
| 670 SyncShareAsDelegate(); | 670 SyncShareAsDelegate(); |
| 671 // Server side change will put A in conflict. | 671 // Server side change will put A in conflict. |
| 672 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); | 672 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); |
| 673 { | 673 { |
| 674 // Mark bookmarks as encrypted and set the cryptographer to have pending | 674 // Mark bookmarks as encrypted and set the cryptographer to have pending |
| 675 // keys. | 675 // keys. |
| 676 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 676 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 677 browser_sync::Cryptographer other_cryptographer; | 677 browser_sync::Cryptographer other_cryptographer; |
| 678 other_cryptographer.AddKey(other_params); | 678 other_cryptographer.AddKey(other_params); |
| 679 sync_pb::EntitySpecifics specifics; | 679 sync_pb::EntitySpecifics specifics; |
| 680 sync_pb::NigoriSpecifics* nigori = | 680 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 681 specifics.MutableExtension(sync_pb::nigori); | |
| 682 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 681 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 683 nigori->set_encrypt_bookmarks(true); | 682 nigori->set_encrypt_bookmarks(true); |
| 684 // Set up with an old passphrase, but have pending keys | 683 // Set up with an old passphrase, but have pending keys |
| 685 syncdb_.manager()->GetCryptographer(&wtrans)->AddKey(key_params); | 684 syncdb_.manager()->GetCryptographer(&wtrans)->AddKey(key_params); |
| 686 syncdb_.manager()->GetCryptographer(&wtrans)->Encrypt( | 685 syncdb_.manager()->GetCryptographer(&wtrans)->Encrypt( |
| 687 bookmark, | 686 bookmark, |
| 688 encrypted_bookmark.mutable_encrypted()); | 687 encrypted_bookmark.mutable_encrypted()); |
| 689 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); | 688 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); |
| 690 | 689 |
| 691 // In conflict but properly encrypted. | 690 // In conflict but properly encrypted. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 } | 772 } |
| 774 } | 773 } |
| 775 | 774 |
| 776 TEST_F(SyncerTest, EncryptionAwareConflicts) { | 775 TEST_F(SyncerTest, EncryptionAwareConflicts) { |
| 777 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 776 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 778 ASSERT_TRUE(dir.good()); | 777 ASSERT_TRUE(dir.good()); |
| 779 KeyParams key_params = {"localhost", "dummy", "foobar"}; | 778 KeyParams key_params = {"localhost", "dummy", "foobar"}; |
| 780 browser_sync::Cryptographer other_cryptographer; | 779 browser_sync::Cryptographer other_cryptographer; |
| 781 other_cryptographer.AddKey(key_params); | 780 other_cryptographer.AddKey(key_params); |
| 782 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; | 781 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; |
| 783 bookmark.MutableExtension(sync_pb::bookmark)->set_title("title"); | 782 bookmark.mutable_bookmark()->set_title("title"); |
| 784 other_cryptographer.Encrypt(bookmark, | 783 other_cryptographer.Encrypt(bookmark, |
| 785 encrypted_bookmark.mutable_encrypted()); | 784 encrypted_bookmark.mutable_encrypted()); |
| 786 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); | 785 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); |
| 787 modified_bookmark.MutableExtension(sync_pb::bookmark)->set_title("title2"); | 786 modified_bookmark.mutable_bookmark()->set_title("title2"); |
| 788 other_cryptographer.Encrypt(modified_bookmark, | 787 other_cryptographer.Encrypt(modified_bookmark, |
| 789 modified_bookmark.mutable_encrypted()); | 788 modified_bookmark.mutable_encrypted()); |
| 790 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; | 789 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; |
| 791 pref.MutableExtension(sync_pb::preference)->set_name("name"); | 790 pref.mutable_preference()->set_name("name"); |
| 792 AddDefaultExtensionValue(syncable::PREFERENCES, &encrypted_pref); | 791 AddDefaultExtensionValue(syncable::PREFERENCES, &encrypted_pref); |
| 793 other_cryptographer.Encrypt(pref, | 792 other_cryptographer.Encrypt(pref, |
| 794 encrypted_pref.mutable_encrypted()); | 793 encrypted_pref.mutable_encrypted()); |
| 795 modified_pref.MutableExtension(sync_pb::preference)->set_name("name2"); | 794 modified_pref.mutable_preference()->set_name("name2"); |
| 796 other_cryptographer.Encrypt(modified_pref, | 795 other_cryptographer.Encrypt(modified_pref, |
| 797 modified_pref.mutable_encrypted()); | 796 modified_pref.mutable_encrypted()); |
| 798 { | 797 { |
| 799 // Mark bookmarks and preferences as encrypted and set the cryptographer to | 798 // Mark bookmarks and preferences as encrypted and set the cryptographer to |
| 800 // have pending keys. | 799 // have pending keys. |
| 801 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 800 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 802 sync_pb::EntitySpecifics specifics; | 801 sync_pb::EntitySpecifics specifics; |
| 803 sync_pb::NigoriSpecifics* nigori = | 802 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 804 specifics.MutableExtension(sync_pb::nigori); | |
| 805 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 803 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 806 nigori->set_encrypt_bookmarks(true); | 804 nigori->set_encrypt_bookmarks(true); |
| 807 nigori->set_encrypt_preferences(true); | 805 nigori->set_encrypt_preferences(true); |
| 808 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); | 806 syncdb_.manager()->GetCryptographer(&wtrans)->Update(*nigori); |
| 809 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 807 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 810 has_pending_keys()); | 808 has_pending_keys()); |
| 811 } | 809 } |
| 812 | 810 |
| 813 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); | 811 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); |
| 814 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); | 812 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 | 960 |
| 963 TEST_F(SyncerTest, NigoriConflicts) { | 961 TEST_F(SyncerTest, NigoriConflicts) { |
| 964 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 962 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 965 ASSERT_TRUE(dir.good()); | 963 ASSERT_TRUE(dir.good()); |
| 966 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; | 964 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; |
| 967 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; | 965 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; |
| 968 browser_sync::Cryptographer other_cryptographer; | 966 browser_sync::Cryptographer other_cryptographer; |
| 969 other_cryptographer.AddKey(other_key_params); | 967 other_cryptographer.AddKey(other_key_params); |
| 970 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); | 968 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); |
| 971 sync_pb::EntitySpecifics initial_nigori_specifics; | 969 sync_pb::EntitySpecifics initial_nigori_specifics; |
| 972 initial_nigori_specifics.MutableExtension(sync_pb::nigori); | 970 initial_nigori_specifics.mutable_nigori(); |
| 973 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); | 971 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); |
| 974 | 972 |
| 975 // Data for testing encryption/decryption. | 973 // Data for testing encryption/decryption. |
| 976 sync_pb::EntitySpecifics other_encrypted_specifics; | 974 sync_pb::EntitySpecifics other_encrypted_specifics; |
| 977 other_encrypted_specifics.MutableExtension(sync_pb::bookmark)-> | 975 other_encrypted_specifics.mutable_bookmark()->set_title("title"); |
| 978 set_title("title"); | |
| 979 other_cryptographer.Encrypt( | 976 other_cryptographer.Encrypt( |
| 980 other_encrypted_specifics, | 977 other_encrypted_specifics, |
| 981 other_encrypted_specifics.mutable_encrypted()); | 978 other_encrypted_specifics.mutable_encrypted()); |
| 982 sync_pb::EntitySpecifics our_encrypted_specifics; | 979 sync_pb::EntitySpecifics our_encrypted_specifics; |
| 983 our_encrypted_specifics.MutableExtension(sync_pb::bookmark)-> | 980 our_encrypted_specifics.mutable_bookmark()->set_title("title2"); |
| 984 set_title("title2"); | |
| 985 | 981 |
| 986 // Receive the initial nigori node. | 982 // Receive the initial nigori node. |
| 987 SyncShareAsDelegate(); | 983 SyncShareAsDelegate(); |
| 988 encrypted_types = syncable::ModelTypeSet::All(); | 984 encrypted_types = syncable::ModelTypeSet::All(); |
| 989 { | 985 { |
| 990 // Local changes with different passphrase, different types, and sync_tabs. | 986 // Local changes with different passphrase, different types, and sync_tabs. |
| 991 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 987 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 992 sync_pb::EntitySpecifics specifics; | 988 sync_pb::EntitySpecifics specifics; |
| 993 sync_pb::NigoriSpecifics* nigori = | 989 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 994 specifics.MutableExtension(sync_pb::nigori); | |
| 995 syncdb_.manager()->GetCryptographer(&wtrans)->AddKey(local_key_params); | 990 syncdb_.manager()->GetCryptographer(&wtrans)->AddKey(local_key_params); |
| 996 syncdb_.manager()->GetCryptographer(&wtrans)->Encrypt( | 991 syncdb_.manager()->GetCryptographer(&wtrans)->Encrypt( |
| 997 our_encrypted_specifics, | 992 our_encrypted_specifics, |
| 998 our_encrypted_specifics.mutable_encrypted()); | 993 our_encrypted_specifics.mutable_encrypted()); |
| 999 syncdb_.manager()->GetCryptographer(&wtrans)->GetKeys( | 994 syncdb_.manager()->GetCryptographer(&wtrans)->GetKeys( |
| 1000 nigori->mutable_encrypted()); | 995 nigori->mutable_encrypted()); |
| 1001 syncdb_.manager()->GetCryptographer(&wtrans)-> | 996 syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1002 UpdateNigoriFromEncryptedTypes(nigori); | 997 UpdateNigoriFromEncryptedTypes(nigori); |
| 1003 nigori->set_sync_tabs(true); | 998 nigori->set_sync_tabs(true); |
| 1004 syncdb_.manager()->GetCryptographer(&wtrans)->set_encrypt_everything(); | 999 syncdb_.manager()->GetCryptographer(&wtrans)->set_encrypt_everything(); |
| 1005 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1000 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1006 syncable::ModelTypeToRootTag(syncable::NIGORI)); | 1001 syncable::ModelTypeToRootTag(syncable::NIGORI)); |
| 1007 ASSERT_TRUE(nigori_entry.good()); | 1002 ASSERT_TRUE(nigori_entry.good()); |
| 1008 nigori_entry.Put(SPECIFICS, specifics); | 1003 nigori_entry.Put(SPECIFICS, specifics); |
| 1009 nigori_entry.Put(IS_UNSYNCED, true); | 1004 nigori_entry.Put(IS_UNSYNCED, true); |
| 1010 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1005 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1011 has_pending_keys()); | 1006 has_pending_keys()); |
| 1012 EXPECT_TRUE(encrypted_types.Equals( | 1007 EXPECT_TRUE(encrypted_types.Equals( |
| 1013 syncdb_.manager()->GetCryptographer(&wtrans)->GetEncryptedTypes())); | 1008 syncdb_.manager()->GetCryptographer(&wtrans)->GetEncryptedTypes())); |
| 1014 } | 1009 } |
| 1015 { | 1010 { |
| 1016 sync_pb::EntitySpecifics specifics; | 1011 sync_pb::EntitySpecifics specifics; |
| 1017 sync_pb::NigoriSpecifics* nigori = | 1012 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1018 specifics.MutableExtension(sync_pb::nigori); | |
| 1019 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 1013 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
| 1020 nigori->set_encrypt_bookmarks(true); | 1014 nigori->set_encrypt_bookmarks(true); |
| 1021 nigori->set_encrypt_preferences(true); | 1015 nigori->set_encrypt_preferences(true); |
| 1022 nigori->set_encrypt_everything(false); | 1016 nigori->set_encrypt_everything(false); |
| 1023 mock_server_->SetNigori(1, 20, 20, specifics); | 1017 mock_server_->SetNigori(1, 20, 20, specifics); |
| 1024 } | 1018 } |
| 1025 | 1019 |
| 1026 // Will result in downloading the server nigori, which puts the local nigori | 1020 // Will result in downloading the server nigori, which puts the local nigori |
| 1027 // in a state of conflict. This is resolved by merging the local and server | 1021 // in a state of conflict. This is resolved by merging the local and server |
| 1028 // data (with priority given to the server's encryption keys if they are | 1022 // data (with priority given to the server's encryption keys if they are |
| 1029 // undecryptable), which we then commit. The cryptographer should have pending | 1023 // undecryptable), which we then commit. The cryptographer should have pending |
| 1030 // keys and merge the set of encrypted types. | 1024 // keys and merge the set of encrypted types. |
| 1031 SyncShareAsDelegate(); // Resolve conflict in this cycle. | 1025 SyncShareAsDelegate(); // Resolve conflict in this cycle. |
| 1032 SyncShareAsDelegate(); // Commit local change in this cycle. | 1026 SyncShareAsDelegate(); // Commit local change in this cycle. |
| 1033 { | 1027 { |
| 1034 // Ensure the nigori data merged (encrypted types, sync_tabs). | 1028 // Ensure the nigori data merged (encrypted types, sync_tabs). |
| 1035 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 1029 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 1036 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1030 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1037 syncable::ModelTypeToRootTag(syncable::NIGORI)); | 1031 syncable::ModelTypeToRootTag(syncable::NIGORI)); |
| 1038 ASSERT_TRUE(nigori_entry.good()); | 1032 ASSERT_TRUE(nigori_entry.good()); |
| 1039 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1033 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1040 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1034 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1041 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); | 1035 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); |
| 1042 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1036 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1043 has_pending_keys()); | 1037 has_pending_keys()); |
| 1044 EXPECT_TRUE(encrypted_types.Equals( | 1038 EXPECT_TRUE(encrypted_types.Equals( |
| 1045 syncdb_.manager()->GetCryptographer(&wtrans)->GetEncryptedTypes())); | 1039 syncdb_.manager()->GetCryptographer(&wtrans)->GetEncryptedTypes())); |
| 1046 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1040 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1047 encrypt_everything()); | 1041 encrypt_everything()); |
| 1048 EXPECT_TRUE(specifics.GetExtension(sync_pb::nigori).sync_tabs()); | 1042 EXPECT_TRUE(specifics.nigori().sync_tabs()); |
| 1049 // Supply the pending keys. Afterwards, we should be able to decrypt both | 1043 // Supply the pending keys. Afterwards, we should be able to decrypt both |
| 1050 // our own encrypted data and data encrypted by the other cryptographer, | 1044 // our own encrypted data and data encrypted by the other cryptographer, |
| 1051 // but the key provided by the other cryptographer should be the default. | 1045 // but the key provided by the other cryptographer should be the default. |
| 1052 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1046 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1053 DecryptPendingKeys(other_key_params)); | 1047 DecryptPendingKeys(other_key_params)); |
| 1054 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1048 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1055 has_pending_keys()); | 1049 has_pending_keys()); |
| 1056 sync_pb::NigoriSpecifics* nigori = | 1050 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
| 1057 specifics.MutableExtension(sync_pb::nigori); | |
| 1058 syncdb_.manager()->GetCryptographer(&wtrans)->GetKeys( | 1051 syncdb_.manager()->GetCryptographer(&wtrans)->GetKeys( |
| 1059 nigori->mutable_encrypted()); | 1052 nigori->mutable_encrypted()); |
| 1060 syncdb_.manager()->GetCryptographer(&wtrans)-> | 1053 syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1061 UpdateNigoriFromEncryptedTypes(nigori); | 1054 UpdateNigoriFromEncryptedTypes(nigori); |
| 1062 // Normally this would be written as part of SetPassphrase, but we do it | 1055 // Normally this would be written as part of SetPassphrase, but we do it |
| 1063 // manually for the test. | 1056 // manually for the test. |
| 1064 nigori_entry.Put(SPECIFICS, specifics); | 1057 nigori_entry.Put(SPECIFICS, specifics); |
| 1065 nigori_entry.Put(IS_UNSYNCED, true); | 1058 nigori_entry.Put(IS_UNSYNCED, true); |
| 1066 } | 1059 } |
| 1067 | 1060 |
| 1068 SyncShareAsDelegate(); | 1061 SyncShareAsDelegate(); |
| 1069 { | 1062 { |
| 1070 // Ensure everything is committed and stable now. The cryptographer | 1063 // Ensure everything is committed and stable now. The cryptographer |
| 1071 // should be able to decrypt both sets of keys, sync_tabs should be true, | 1064 // should be able to decrypt both sets of keys, sync_tabs should be true, |
| 1072 // and the encrypted types should have been unioned. | 1065 // and the encrypted types should have been unioned. |
| 1073 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 1066 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 1074 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, | 1067 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, |
| 1075 syncable::ModelTypeToRootTag(syncable::NIGORI)); | 1068 syncable::ModelTypeToRootTag(syncable::NIGORI)); |
| 1076 ASSERT_TRUE(nigori_entry.good()); | 1069 ASSERT_TRUE(nigori_entry.good()); |
| 1077 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); | 1070 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); |
| 1078 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); | 1071 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); |
| 1079 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)->CanDecrypt( | 1072 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)->CanDecrypt( |
| 1080 our_encrypted_specifics.encrypted())); | 1073 our_encrypted_specifics.encrypted())); |
| 1081 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1074 EXPECT_FALSE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1082 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); | 1075 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); |
| 1083 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)->CanDecrypt( | 1076 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)->CanDecrypt( |
| 1084 other_encrypted_specifics.encrypted())); | 1077 other_encrypted_specifics.encrypted())); |
| 1085 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> | 1078 EXPECT_TRUE(syncdb_.manager()->GetCryptographer(&wtrans)-> |
| 1086 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); | 1079 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); |
| 1087 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).GetExtension(sync_pb::nigori) | 1080 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori().sync_tabs()); |
| 1088 .sync_tabs()); | |
| 1089 } | 1081 } |
| 1090 } | 1082 } |
| 1091 | 1083 |
| 1092 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { | 1084 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { |
| 1093 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 1085 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 1094 ASSERT_TRUE(dir.good()); | 1086 ASSERT_TRUE(dir.good()); |
| 1095 { | 1087 { |
| 1096 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); | 1088 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir); |
| 1097 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), | 1089 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), |
| 1098 "Pete"); | 1090 "Pete"); |
| (...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2376 LoopSyncShare(); | 2368 LoopSyncShare(); |
| 2377 syncable::Directory::ChildHandles children; | 2369 syncable::Directory::ChildHandles children; |
| 2378 { | 2370 { |
| 2379 ReadTransaction trans(FROM_HERE, dir); | 2371 ReadTransaction trans(FROM_HERE, dir); |
| 2380 dir->GetChildHandlesById(&trans, parent_id_, &children); | 2372 dir->GetChildHandlesById(&trans, parent_id_, &children); |
| 2381 // We expect the conflict resolver to preserve the local entry. | 2373 // We expect the conflict resolver to preserve the local entry. |
| 2382 Entry child(&trans, syncable::GET_BY_ID, child_id_); | 2374 Entry child(&trans, syncable::GET_BY_ID, child_id_); |
| 2383 ASSERT_TRUE(child.good()); | 2375 ASSERT_TRUE(child.good()); |
| 2384 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); | 2376 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); |
| 2385 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); | 2377 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); |
| 2386 EXPECT_TRUE(child.Get(SPECIFICS).HasExtension(sync_pb::bookmark)); | 2378 EXPECT_TRUE(child.Get(SPECIFICS).has_bookmark()); |
| 2387 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME)); | 2379 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME)); |
| 2388 VerifyTestBookmarkDataInEntry(&child); | 2380 VerifyTestBookmarkDataInEntry(&child); |
| 2389 } | 2381 } |
| 2390 | 2382 |
| 2391 // Only one entry, since we just overwrite one. | 2383 // Only one entry, since we just overwrite one. |
| 2392 EXPECT_EQ(1u, children.size()); | 2384 EXPECT_EQ(1u, children.size()); |
| 2393 saw_syncer_event_ = false; | 2385 saw_syncer_event_ = false; |
| 2394 } | 2386 } |
| 2395 | 2387 |
| 2396 // We got this repro case when someone was editing bookmarks while sync was | 2388 // We got this repro case when someone was editing bookmarks while sync was |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2831 ASSERT_TRUE(server.good()); | 2823 ASSERT_TRUE(server.good()); |
| 2832 ASSERT_TRUE(local.good()); | 2824 ASSERT_TRUE(local.good()); |
| 2833 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); | 2825 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); |
| 2834 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); | 2826 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); |
| 2835 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); | 2827 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); |
| 2836 EXPECT_FALSE(server.Get(IS_UNSYNCED)); | 2828 EXPECT_FALSE(server.Get(IS_UNSYNCED)); |
| 2837 EXPECT_FALSE(local.Get(IS_UNSYNCED)); | 2829 EXPECT_FALSE(local.Get(IS_UNSYNCED)); |
| 2838 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); | 2830 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); |
| 2839 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); | 2831 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); |
| 2840 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. | 2832 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. |
| 2841 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); | 2833 server.Get(SPECIFICS).bookmark().url()); |
| 2842 } | 2834 } |
| 2843 } | 2835 } |
| 2844 | 2836 |
| 2845 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. | 2837 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. |
| 2846 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { | 2838 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { |
| 2847 mock_server_->set_use_legacy_bookmarks_protocol(true); | 2839 mock_server_->set_use_legacy_bookmarks_protocol(true); |
| 2848 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2840 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2849 CHECK(dir.good()); | 2841 CHECK(dir.good()); |
| 2850 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); | 2842 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); |
| 2851 SyncShareAsDelegate(); | 2843 SyncShareAsDelegate(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2899 ASSERT_TRUE(server.good()); | 2891 ASSERT_TRUE(server.good()); |
| 2900 ASSERT_TRUE(local.good()); | 2892 ASSERT_TRUE(local.good()); |
| 2901 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); | 2893 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); |
| 2902 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); | 2894 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); |
| 2903 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); | 2895 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); |
| 2904 EXPECT_FALSE(server.Get(IS_UNSYNCED)); | 2896 EXPECT_FALSE(server.Get(IS_UNSYNCED)); |
| 2905 EXPECT_FALSE(local.Get(IS_UNSYNCED)); | 2897 EXPECT_FALSE(local.Get(IS_UNSYNCED)); |
| 2906 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); | 2898 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); |
| 2907 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); | 2899 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); |
| 2908 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. | 2900 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. |
| 2909 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); | 2901 server.Get(SPECIFICS).bookmark().url()); |
| 2910 } | 2902 } |
| 2911 } | 2903 } |
| 2912 | 2904 |
| 2913 // Circular links should be resolved by the server. | 2905 // Circular links should be resolved by the server. |
| 2914 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { | 2906 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { |
| 2915 // we don't currently resolve this. This test ensures we don't. | 2907 // we don't currently resolve this. This test ensures we don't. |
| 2916 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 2908 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 2917 CHECK(dir.good()); | 2909 CHECK(dir.good()); |
| 2918 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); | 2910 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); |
| 2919 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); | 2911 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3685 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1"); | 3677 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1"); |
| 3686 } | 3678 } |
| 3687 } | 3679 } |
| 3688 | 3680 |
| 3689 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { | 3681 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { |
| 3690 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3682 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
| 3691 EXPECT_TRUE(dir.good()); | 3683 EXPECT_TRUE(dir.good()); |
| 3692 int64 original_metahandle = 0; | 3684 int64 original_metahandle = 0; |
| 3693 | 3685 |
| 3694 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); | 3686 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); |
| 3695 local_bookmark.MutableExtension(sync_pb::bookmark)-> | 3687 local_bookmark.mutable_bookmark()->set_url("http://foo/localsite"); |
| 3696 set_url("http://foo/localsite"); | |
| 3697 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); | 3688 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); |
| 3698 server_bookmark.MutableExtension(sync_pb::bookmark)-> | 3689 server_bookmark.mutable_bookmark()->set_url("http://bar/serversite"); |
| 3699 set_url("http://bar/serversite"); | |
| 3700 | 3690 |
| 3701 { | 3691 { |
| 3702 WriteTransaction trans(FROM_HERE, UNITTEST, dir); | 3692 WriteTransaction trans(FROM_HERE, UNITTEST, dir); |
| 3703 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); | 3693 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); |
| 3704 ASSERT_TRUE(perm_folder.good()); | 3694 ASSERT_TRUE(perm_folder.good()); |
| 3705 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); | 3695 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); |
| 3706 perm_folder.Put(SPECIFICS, local_bookmark); | 3696 perm_folder.Put(SPECIFICS, local_bookmark); |
| 3707 perm_folder.Put(IS_UNSYNCED, true); | 3697 perm_folder.Put(IS_UNSYNCED, true); |
| 3708 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); | 3698 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); |
| 3709 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); | 3699 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4716 Add(low_id_); | 4706 Add(low_id_); |
| 4717 Add(high_id_); | 4707 Add(high_id_); |
| 4718 SyncShareAsDelegate(); | 4708 SyncShareAsDelegate(); |
| 4719 ExpectLocalOrderIsByServerId(); | 4709 ExpectLocalOrderIsByServerId(); |
| 4720 } | 4710 } |
| 4721 | 4711 |
| 4722 const SyncerTest::CommitOrderingTest | 4712 const SyncerTest::CommitOrderingTest |
| 4723 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 4713 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
| 4724 | 4714 |
| 4725 } // namespace browser_sync | 4715 } // namespace browser_sync |
| OLD | NEW |