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

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

Issue 9460047: sync: remove use of protobuf extensions in protocol to reduce static init overhead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fred's review Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 virtual void TearDown() { 227 virtual void TearDown() {
228 mock_server_.reset(); 228 mock_server_.reset();
229 delete syncer_; 229 delete syncer_;
230 syncer_ = NULL; 230 syncer_ = NULL;
231 dir_maker_.TearDown(); 231 dir_maker_.TearDown();
232 } 232 }
233 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) { 233 void WriteTestDataToEntry(WriteTransaction* trans, MutableEntry* entry) {
234 EXPECT_FALSE(entry->Get(IS_DIR)); 234 EXPECT_FALSE(entry->Get(IS_DIR));
235 EXPECT_FALSE(entry->Get(IS_DEL)); 235 EXPECT_FALSE(entry->Get(IS_DEL));
236 sync_pb::EntitySpecifics specifics; 236 sync_pb::EntitySpecifics specifics;
237 specifics.MutableExtension(sync_pb::bookmark)->set_url("http://demo/"); 237 specifics.mutable_bookmark()->set_url("http://demo/");
238 specifics.MutableExtension(sync_pb::bookmark)->set_favicon("PNG"); 238 specifics.mutable_bookmark()->set_favicon("PNG");
239 entry->Put(syncable::SPECIFICS, specifics); 239 entry->Put(syncable::SPECIFICS, specifics);
240 entry->Put(syncable::IS_UNSYNCED, true); 240 entry->Put(syncable::IS_UNSYNCED, true);
241 } 241 }
242 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) { 242 void VerifyTestDataInEntry(BaseTransaction* trans, Entry* entry) {
243 EXPECT_FALSE(entry->Get(IS_DIR)); 243 EXPECT_FALSE(entry->Get(IS_DIR));
244 EXPECT_FALSE(entry->Get(IS_DEL)); 244 EXPECT_FALSE(entry->Get(IS_DEL));
245 VerifyTestBookmarkDataInEntry(entry); 245 VerifyTestBookmarkDataInEntry(entry);
246 } 246 }
247 void VerifyTestBookmarkDataInEntry(Entry* entry) { 247 void VerifyTestBookmarkDataInEntry(Entry* entry) {
248 const sync_pb::EntitySpecifics& specifics = entry->Get(syncable::SPECIFICS); 248 const sync_pb::EntitySpecifics& specifics = entry->Get(syncable::SPECIFICS);
249 EXPECT_TRUE(specifics.HasExtension(sync_pb::bookmark)); 249 EXPECT_TRUE(specifics.has_bookmark());
250 EXPECT_EQ("PNG", specifics.GetExtension(sync_pb::bookmark).favicon()); 250 EXPECT_EQ("PNG", specifics.bookmark().favicon());
251 EXPECT_EQ("http://demo/", specifics.GetExtension(sync_pb::bookmark).url()); 251 EXPECT_EQ("http://demo/", specifics.bookmark().url());
252 } 252 }
253 253
254 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) { 254 void SyncRepeatedlyToTriggerConflictResolution(SyncSession* session) {
255 // We should trigger after less than 6 syncs, but extra does no harm. 255 // We should trigger after less than 6 syncs, but extra does no harm.
256 for (int i = 0 ; i < 6 ; ++i) 256 for (int i = 0 ; i < 6 ; ++i)
257 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); 257 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END);
258 } 258 }
259 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) { 259 void SyncRepeatedlyToTriggerStuckSignal(SyncSession* session) {
260 // We should trigger after less than 10 syncs, but we want to avoid brittle 260 // We should trigger after less than 10 syncs, but we want to avoid brittle
261 // tests. 261 // tests.
262 for (int i = 0 ; i < 12 ; ++i) 262 for (int i = 0 ; i < 12 ; ++i)
263 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END); 263 syncer_->SyncShare(session, SYNCER_BEGIN, SYNCER_END);
264 } 264 }
265 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { 265 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
266 sync_pb::EntitySpecifics result; 266 sync_pb::EntitySpecifics result;
267 AddDefaultExtensionValue(syncable::BOOKMARKS, &result); 267 AddDefaultFieldValue(syncable::BOOKMARKS, &result);
268 return result; 268 return result;
269 } 269 }
270 270
271 sync_pb::EntitySpecifics DefaultPreferencesSpecifics() { 271 sync_pb::EntitySpecifics DefaultPreferencesSpecifics() {
272 sync_pb::EntitySpecifics result; 272 sync_pb::EntitySpecifics result;
273 AddDefaultExtensionValue(syncable::PREFERENCES, &result); 273 AddDefaultFieldValue(syncable::PREFERENCES, &result);
274 return result; 274 return result;
275 } 275 }
276 // Enumeration of alterations to entries for commit ordering tests. 276 // Enumeration of alterations to entries for commit ordering tests.
277 enum EntryFeature { 277 enum EntryFeature {
278 LIST_END = 0, // Denotes the end of the list of features from below. 278 LIST_END = 0, // Denotes the end of the list of features from below.
279 SYNCED, // Items are unsynced by default 279 SYNCED, // Items are unsynced by default
280 DELETED, 280 DELETED,
281 OLD_MTIME, 281 OLD_MTIME,
282 MOVED_FROM_ROOT, 282 MOVED_FROM_ROOT,
283 }; 283 };
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 expected_order.push_back(ids_.MakeLocal("b")); 574 expected_order.push_back(ids_.MakeLocal("b"));
575 expected_order.push_back(ids_.MakeLocal("c")); 575 expected_order.push_back(ids_.MakeLocal("c"));
576 expected_order.push_back(ids_.MakeLocal("d")); 576 expected_order.push_back(ids_.MakeLocal("d"));
577 expected_order.push_back(ids_.MakeLocal("e")); 577 expected_order.push_back(ids_.MakeLocal("e"));
578 DoTruncationTest(unsynced_handle_view, expected_order); 578 DoTruncationTest(unsynced_handle_view, expected_order);
579 } 579 }
580 580
581 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) { 581 TEST_F(SyncerTest, GetCommitIdsFiltersThrottledEntries) {
582 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS); 582 const syncable::ModelTypeSet throttled_types(syncable::BOOKMARKS);
583 sync_pb::EntitySpecifics bookmark_data; 583 sync_pb::EntitySpecifics bookmark_data;
584 AddDefaultExtensionValue(syncable::BOOKMARKS, &bookmark_data); 584 AddDefaultFieldValue(syncable::BOOKMARKS, &bookmark_data);
585 585
586 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 586 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
587 SyncShareAsDelegate(); 587 SyncShareAsDelegate();
588 588
589 { 589 {
590 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 590 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
591 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 591 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
592 ASSERT_TRUE(A.good()); 592 ASSERT_TRUE(A.good());
593 A.Put(IS_UNSYNCED, true); 593 A.Put(IS_UNSYNCED, true);
594 A.Put(SPECIFICS, bookmark_data); 594 A.Put(SPECIFICS, bookmark_data);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 EXPECT_TRUE(parent_id == -1 || \ 639 EXPECT_TRUE(parent_id == -1 || \
640 entryA.Get(PARENT_ID) == id_fac.FromNumber(parent_id)); \ 640 entryA.Get(PARENT_ID) == id_fac.FromNumber(parent_id)); \
641 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \ 641 EXPECT_EQ(version, entryA.Get(BASE_VERSION)); \
642 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \ 642 EXPECT_EQ(server_version, entryA.Get(SERVER_VERSION)); \
643 } while (0) 643 } while (0)
644 644
645 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) { 645 TEST_F(SyncerTest, GetCommitIdsFiltersUnreadyEntries) {
646 KeyParams key_params = {"localhost", "dummy", "foobar"}; 646 KeyParams key_params = {"localhost", "dummy", "foobar"};
647 KeyParams other_params = {"localhost", "dummy", "foobar2"}; 647 KeyParams other_params = {"localhost", "dummy", "foobar2"};
648 sync_pb::EntitySpecifics bookmark, encrypted_bookmark; 648 sync_pb::EntitySpecifics bookmark, encrypted_bookmark;
649 bookmark.MutableExtension(sync_pb::bookmark)->set_url("url"); 649 bookmark.mutable_bookmark()->set_url("url");
650 bookmark.MutableExtension(sync_pb::bookmark)->set_title("title"); 650 bookmark.mutable_bookmark()->set_title("title");
651 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); 651 AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark);
652 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 652 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
653 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 653 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
654 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10); 654 mock_server_->AddUpdateDirectory(3, 0, "C", 10, 10);
655 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10); 655 mock_server_->AddUpdateDirectory(4, 0, "D", 10, 10);
656 SyncShareAsDelegate(); 656 SyncShareAsDelegate();
657 // Server side change will put A in conflict. 657 // Server side change will put A in conflict.
658 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20); 658 mock_server_->AddUpdateDirectory(1, 0, "A", 20, 20);
659 { 659 {
660 // Mark bookmarks as encrypted and set the cryptographer to have pending 660 // Mark bookmarks as encrypted and set the cryptographer to have pending
661 // keys. 661 // keys.
662 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 662 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
663 browser_sync::Cryptographer other_cryptographer(&encryptor_); 663 browser_sync::Cryptographer other_cryptographer(&encryptor_);
664 other_cryptographer.AddKey(other_params); 664 other_cryptographer.AddKey(other_params);
665 sync_pb::EntitySpecifics specifics; 665 sync_pb::EntitySpecifics specifics;
666 sync_pb::NigoriSpecifics* nigori = 666 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
667 specifics.MutableExtension(sync_pb::nigori);
668 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 667 other_cryptographer.GetKeys(nigori->mutable_encrypted());
669 nigori->set_encrypt_bookmarks(true); 668 nigori->set_encrypt_bookmarks(true);
670 // Set up with an old passphrase, but have pending keys 669 // Set up with an old passphrase, but have pending keys
671 cryptographer(&wtrans)->AddKey(key_params); 670 cryptographer(&wtrans)->AddKey(key_params);
672 cryptographer(&wtrans)->Encrypt(bookmark, 671 cryptographer(&wtrans)->Encrypt(bookmark,
673 encrypted_bookmark.mutable_encrypted()); 672 encrypted_bookmark.mutable_encrypted());
674 cryptographer(&wtrans)->Update(*nigori); 673 cryptographer(&wtrans)->Update(*nigori);
675 674
676 // In conflict but properly encrypted. 675 // In conflict but properly encrypted.
677 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 676 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans); 754 VERIFY_ENTRY(3, false, false, false, 0, 11, 11, ids_, &rtrans);
756 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans); 755 VERIFY_ENTRY(4, false, false, false, 0, 11, 11, ids_, &rtrans);
757 } 756 }
758 } 757 }
759 758
760 TEST_F(SyncerTest, EncryptionAwareConflicts) { 759 TEST_F(SyncerTest, EncryptionAwareConflicts) {
761 KeyParams key_params = {"localhost", "dummy", "foobar"}; 760 KeyParams key_params = {"localhost", "dummy", "foobar"};
762 browser_sync::Cryptographer other_cryptographer(&encryptor_); 761 browser_sync::Cryptographer other_cryptographer(&encryptor_);
763 other_cryptographer.AddKey(key_params); 762 other_cryptographer.AddKey(key_params);
764 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark; 763 sync_pb::EntitySpecifics bookmark, encrypted_bookmark, modified_bookmark;
765 bookmark.MutableExtension(sync_pb::bookmark)->set_title("title"); 764 bookmark.mutable_bookmark()->set_title("title");
766 other_cryptographer.Encrypt(bookmark, 765 other_cryptographer.Encrypt(bookmark,
767 encrypted_bookmark.mutable_encrypted()); 766 encrypted_bookmark.mutable_encrypted());
768 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); 767 AddDefaultFieldValue(syncable::BOOKMARKS, &encrypted_bookmark);
769 modified_bookmark.MutableExtension(sync_pb::bookmark)->set_title("title2"); 768 modified_bookmark.mutable_bookmark()->set_title("title2");
770 other_cryptographer.Encrypt(modified_bookmark, 769 other_cryptographer.Encrypt(modified_bookmark,
771 modified_bookmark.mutable_encrypted()); 770 modified_bookmark.mutable_encrypted());
772 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref; 771 sync_pb::EntitySpecifics pref, encrypted_pref, modified_pref;
773 pref.MutableExtension(sync_pb::preference)->set_name("name"); 772 pref.mutable_preference()->set_name("name");
774 AddDefaultExtensionValue(syncable::PREFERENCES, &encrypted_pref); 773 AddDefaultFieldValue(syncable::PREFERENCES, &encrypted_pref);
775 other_cryptographer.Encrypt(pref, 774 other_cryptographer.Encrypt(pref,
776 encrypted_pref.mutable_encrypted()); 775 encrypted_pref.mutable_encrypted());
777 modified_pref.MutableExtension(sync_pb::preference)->set_name("name2"); 776 modified_pref.mutable_preference()->set_name("name2");
778 other_cryptographer.Encrypt(modified_pref, 777 other_cryptographer.Encrypt(modified_pref,
779 modified_pref.mutable_encrypted()); 778 modified_pref.mutable_encrypted());
780 { 779 {
781 // Mark bookmarks and preferences as encrypted and set the cryptographer to 780 // Mark bookmarks and preferences as encrypted and set the cryptographer to
782 // have pending keys. 781 // have pending keys.
783 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 782 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
784 sync_pb::EntitySpecifics specifics; 783 sync_pb::EntitySpecifics specifics;
785 sync_pb::NigoriSpecifics* nigori = 784 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
786 specifics.MutableExtension(sync_pb::nigori);
787 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 785 other_cryptographer.GetKeys(nigori->mutable_encrypted());
788 nigori->set_encrypt_bookmarks(true); 786 nigori->set_encrypt_bookmarks(true);
789 nigori->set_encrypt_preferences(true); 787 nigori->set_encrypt_preferences(true);
790 cryptographer(&wtrans)->Update(*nigori); 788 cryptographer(&wtrans)->Update(*nigori);
791 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 789 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
792 } 790 }
793 791
794 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark); 792 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark);
795 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark); 793 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark);
796 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark); 794 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 938
941 #undef VERIFY_ENTRY 939 #undef VERIFY_ENTRY
942 940
943 TEST_F(SyncerTest, NigoriConflicts) { 941 TEST_F(SyncerTest, NigoriConflicts) {
944 KeyParams local_key_params = {"localhost", "dummy", "blargle"}; 942 KeyParams local_key_params = {"localhost", "dummy", "blargle"};
945 KeyParams other_key_params = {"localhost", "dummy", "foobar"}; 943 KeyParams other_key_params = {"localhost", "dummy", "foobar"};
946 browser_sync::Cryptographer other_cryptographer(&encryptor_); 944 browser_sync::Cryptographer other_cryptographer(&encryptor_);
947 other_cryptographer.AddKey(other_key_params); 945 other_cryptographer.AddKey(other_key_params);
948 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI); 946 syncable::ModelTypeSet encrypted_types(syncable::PASSWORDS, syncable::NIGORI);
949 sync_pb::EntitySpecifics initial_nigori_specifics; 947 sync_pb::EntitySpecifics initial_nigori_specifics;
950 initial_nigori_specifics.MutableExtension(sync_pb::nigori); 948 initial_nigori_specifics.mutable_nigori();
951 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics); 949 mock_server_->SetNigori(1, 10, 10, initial_nigori_specifics);
952 950
953 // Data for testing encryption/decryption. 951 // Data for testing encryption/decryption.
954 sync_pb::EntitySpecifics other_encrypted_specifics; 952 sync_pb::EntitySpecifics other_encrypted_specifics;
955 other_encrypted_specifics.MutableExtension(sync_pb::bookmark)-> 953 other_encrypted_specifics.mutable_bookmark()->set_title("title");
956 set_title("title");
957 other_cryptographer.Encrypt( 954 other_cryptographer.Encrypt(
958 other_encrypted_specifics, 955 other_encrypted_specifics,
959 other_encrypted_specifics.mutable_encrypted()); 956 other_encrypted_specifics.mutable_encrypted());
960 sync_pb::EntitySpecifics our_encrypted_specifics; 957 sync_pb::EntitySpecifics our_encrypted_specifics;
961 our_encrypted_specifics.MutableExtension(sync_pb::bookmark)-> 958 our_encrypted_specifics.mutable_bookmark()->set_title("title2");
962 set_title("title2");
963 959
964 // Receive the initial nigori node. 960 // Receive the initial nigori node.
965 SyncShareAsDelegate(); 961 SyncShareAsDelegate();
966 encrypted_types = syncable::ModelTypeSet::All(); 962 encrypted_types = syncable::ModelTypeSet::All();
967 { 963 {
968 // Local changes with different passphrase, different types, and sync_tabs. 964 // Local changes with different passphrase, different types, and sync_tabs.
969 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 965 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
970 sync_pb::EntitySpecifics specifics; 966 sync_pb::EntitySpecifics specifics;
971 sync_pb::NigoriSpecifics* nigori = 967 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
972 specifics.MutableExtension(sync_pb::nigori);
973 cryptographer(&wtrans)->AddKey(local_key_params); 968 cryptographer(&wtrans)->AddKey(local_key_params);
974 cryptographer(&wtrans)->Encrypt( 969 cryptographer(&wtrans)->Encrypt(
975 our_encrypted_specifics, 970 our_encrypted_specifics,
976 our_encrypted_specifics.mutable_encrypted()); 971 our_encrypted_specifics.mutable_encrypted());
977 cryptographer(&wtrans)->GetKeys( 972 cryptographer(&wtrans)->GetKeys(
978 nigori->mutable_encrypted()); 973 nigori->mutable_encrypted());
979 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 974 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
980 nigori->set_sync_tabs(true); 975 nigori->set_sync_tabs(true);
981 cryptographer(&wtrans)->set_encrypt_everything(); 976 cryptographer(&wtrans)->set_encrypt_everything();
982 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 977 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
983 syncable::ModelTypeToRootTag(syncable::NIGORI)); 978 syncable::ModelTypeToRootTag(syncable::NIGORI));
984 ASSERT_TRUE(nigori_entry.good()); 979 ASSERT_TRUE(nigori_entry.good());
985 nigori_entry.Put(SPECIFICS, specifics); 980 nigori_entry.Put(SPECIFICS, specifics);
986 nigori_entry.Put(IS_UNSYNCED, true); 981 nigori_entry.Put(IS_UNSYNCED, true);
987 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 982 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
988 EXPECT_TRUE(encrypted_types.Equals( 983 EXPECT_TRUE(encrypted_types.Equals(
989 cryptographer(&wtrans)->GetEncryptedTypes())); 984 cryptographer(&wtrans)->GetEncryptedTypes()));
990 } 985 }
991 { 986 {
992 sync_pb::EntitySpecifics specifics; 987 sync_pb::EntitySpecifics specifics;
993 sync_pb::NigoriSpecifics* nigori = 988 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
994 specifics.MutableExtension(sync_pb::nigori);
995 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 989 other_cryptographer.GetKeys(nigori->mutable_encrypted());
996 nigori->set_encrypt_bookmarks(true); 990 nigori->set_encrypt_bookmarks(true);
997 nigori->set_encrypt_preferences(true); 991 nigori->set_encrypt_preferences(true);
998 nigori->set_encrypt_everything(false); 992 nigori->set_encrypt_everything(false);
999 mock_server_->SetNigori(1, 20, 20, specifics); 993 mock_server_->SetNigori(1, 20, 20, specifics);
1000 } 994 }
1001 995
1002 // Will result in downloading the server nigori, which puts the local nigori 996 // Will result in downloading the server nigori, which puts the local nigori
1003 // in a state of conflict. This is resolved by merging the local and server 997 // in a state of conflict. This is resolved by merging the local and server
1004 // data (with priority given to the server's encryption keys if they are 998 // data (with priority given to the server's encryption keys if they are
1005 // undecryptable), which we then commit. The cryptographer should have pending 999 // undecryptable), which we then commit. The cryptographer should have pending
1006 // keys and merge the set of encrypted types. 1000 // keys and merge the set of encrypted types.
1007 SyncShareAsDelegate(); // Resolve conflict in this cycle. 1001 SyncShareAsDelegate(); // Resolve conflict in this cycle.
1008 SyncShareAsDelegate(); // Commit local change in this cycle. 1002 SyncShareAsDelegate(); // Commit local change in this cycle.
1009 { 1003 {
1010 // Ensure the nigori data merged (encrypted types, sync_tabs). 1004 // Ensure the nigori data merged (encrypted types, sync_tabs).
1011 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1005 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1012 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1006 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1013 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1007 syncable::ModelTypeToRootTag(syncable::NIGORI));
1014 ASSERT_TRUE(nigori_entry.good()); 1008 ASSERT_TRUE(nigori_entry.good());
1015 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1009 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1016 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1010 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1017 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS); 1011 sync_pb::EntitySpecifics specifics = nigori_entry.Get(SPECIFICS);
1018 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys()); 1012 EXPECT_TRUE(cryptographer(&wtrans)->has_pending_keys());
1019 EXPECT_TRUE(encrypted_types.Equals( 1013 EXPECT_TRUE(encrypted_types.Equals(
1020 cryptographer(&wtrans)->GetEncryptedTypes())); 1014 cryptographer(&wtrans)->GetEncryptedTypes()));
1021 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything()); 1015 EXPECT_TRUE(cryptographer(&wtrans)->encrypt_everything());
1022 EXPECT_TRUE(specifics.GetExtension(sync_pb::nigori).sync_tabs()); 1016 EXPECT_TRUE(specifics.nigori().sync_tabs());
1023 // Supply the pending keys. Afterwards, we should be able to decrypt both 1017 // Supply the pending keys. Afterwards, we should be able to decrypt both
1024 // our own encrypted data and data encrypted by the other cryptographer, 1018 // our own encrypted data and data encrypted by the other cryptographer,
1025 // but the key provided by the other cryptographer should be the default. 1019 // but the key provided by the other cryptographer should be the default.
1026 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params)); 1020 EXPECT_TRUE(cryptographer(&wtrans)->DecryptPendingKeys(other_key_params));
1027 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys()); 1021 EXPECT_FALSE(cryptographer(&wtrans)->has_pending_keys());
1028 sync_pb::NigoriSpecifics* nigori = 1022 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
1029 specifics.MutableExtension(sync_pb::nigori);
1030 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted()); 1023 cryptographer(&wtrans)->GetKeys(nigori->mutable_encrypted());
1031 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori); 1024 cryptographer(&wtrans)->UpdateNigoriFromEncryptedTypes(nigori);
1032 // Normally this would be written as part of SetPassphrase, but we do it 1025 // Normally this would be written as part of SetPassphrase, but we do it
1033 // manually for the test. 1026 // manually for the test.
1034 nigori_entry.Put(SPECIFICS, specifics); 1027 nigori_entry.Put(SPECIFICS, specifics);
1035 nigori_entry.Put(IS_UNSYNCED, true); 1028 nigori_entry.Put(IS_UNSYNCED, true);
1036 } 1029 }
1037 1030
1038 SyncShareAsDelegate(); 1031 SyncShareAsDelegate();
1039 { 1032 {
1040 // Ensure everything is committed and stable now. The cryptographer 1033 // Ensure everything is committed and stable now. The cryptographer
1041 // should be able to decrypt both sets of keys, sync_tabs should be true, 1034 // should be able to decrypt both sets of keys, sync_tabs should be true,
1042 // and the encrypted types should have been unioned. 1035 // and the encrypted types should have been unioned.
1043 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1036 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1044 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG, 1037 MutableEntry nigori_entry(&wtrans, GET_BY_SERVER_TAG,
1045 syncable::ModelTypeToRootTag(syncable::NIGORI)); 1038 syncable::ModelTypeToRootTag(syncable::NIGORI));
1046 ASSERT_TRUE(nigori_entry.good()); 1039 ASSERT_TRUE(nigori_entry.good());
1047 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE)); 1040 EXPECT_FALSE(nigori_entry.Get(IS_UNAPPLIED_UPDATE));
1048 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED)); 1041 EXPECT_FALSE(nigori_entry.Get(IS_UNSYNCED));
1049 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( 1042 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt(
1050 our_encrypted_specifics.encrypted())); 1043 our_encrypted_specifics.encrypted()));
1051 EXPECT_FALSE(cryptographer(&wtrans)-> 1044 EXPECT_FALSE(cryptographer(&wtrans)->
1052 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted())); 1045 CanDecryptUsingDefaultKey(our_encrypted_specifics.encrypted()));
1053 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt( 1046 EXPECT_TRUE(cryptographer(&wtrans)->CanDecrypt(
1054 other_encrypted_specifics.encrypted())); 1047 other_encrypted_specifics.encrypted()));
1055 EXPECT_TRUE(cryptographer(&wtrans)-> 1048 EXPECT_TRUE(cryptographer(&wtrans)->
1056 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted())); 1049 CanDecryptUsingDefaultKey(other_encrypted_specifics.encrypted()));
1057 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).GetExtension(sync_pb::nigori) 1050 EXPECT_TRUE(nigori_entry.Get(SPECIFICS).nigori().sync_tabs());
1058 .sync_tabs());
1059 } 1051 }
1060 } 1052 }
1061 1053
1062 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) { 1054 TEST_F(SyncerTest, TestGetUnsyncedAndSimpleCommit) {
1063 { 1055 {
1064 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 1056 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1065 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(), 1057 MutableEntry parent(&wtrans, syncable::CREATE, wtrans.root_id(),
1066 "Pete"); 1058 "Pete");
1067 ASSERT_TRUE(parent.good()); 1059 ASSERT_TRUE(parent.good());
1068 parent.Put(syncable::IS_UNSYNCED, true); 1060 parent.Put(syncable::IS_UNSYNCED, true);
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 LoopSyncShare(); 2284 LoopSyncShare();
2293 syncable::Directory::ChildHandles children; 2285 syncable::Directory::ChildHandles children;
2294 { 2286 {
2295 ReadTransaction trans(FROM_HERE, directory()); 2287 ReadTransaction trans(FROM_HERE, directory());
2296 directory()->GetChildHandlesById(&trans, parent_id_, &children); 2288 directory()->GetChildHandlesById(&trans, parent_id_, &children);
2297 // We expect the conflict resolver to preserve the local entry. 2289 // We expect the conflict resolver to preserve the local entry.
2298 Entry child(&trans, syncable::GET_BY_ID, child_id_); 2290 Entry child(&trans, syncable::GET_BY_ID, child_id_);
2299 ASSERT_TRUE(child.good()); 2291 ASSERT_TRUE(child.good());
2300 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); 2292 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED));
2301 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); 2293 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE));
2302 EXPECT_TRUE(child.Get(SPECIFICS).HasExtension(sync_pb::bookmark)); 2294 EXPECT_TRUE(child.Get(SPECIFICS).has_bookmark());
2303 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME)); 2295 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME));
2304 VerifyTestBookmarkDataInEntry(&child); 2296 VerifyTestBookmarkDataInEntry(&child);
2305 } 2297 }
2306 2298
2307 // Only one entry, since we just overwrite one. 2299 // Only one entry, since we just overwrite one.
2308 EXPECT_EQ(1u, children.size()); 2300 EXPECT_EQ(1u, children.size());
2309 saw_syncer_event_ = false; 2301 saw_syncer_event_ = false;
2310 } 2302 }
2311 2303
2312 // We got this repro case when someone was editing bookmarks while sync was 2304 // We got this repro case when someone was editing bookmarks while sync was
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 ASSERT_TRUE(server.good()); 2712 ASSERT_TRUE(server.good());
2721 ASSERT_TRUE(local.good()); 2713 ASSERT_TRUE(local.good());
2722 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2714 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2723 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2715 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2724 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2716 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2725 EXPECT_FALSE(server.Get(IS_UNSYNCED)); 2717 EXPECT_FALSE(server.Get(IS_UNSYNCED));
2726 EXPECT_FALSE(local.Get(IS_UNSYNCED)); 2718 EXPECT_FALSE(local.Get(IS_UNSYNCED));
2727 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); 2719 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME));
2728 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2720 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2729 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 2721 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
2730 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); 2722 server.Get(SPECIFICS).bookmark().url());
2731 } 2723 }
2732 } 2724 }
2733 2725
2734 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol. 2726 // Same as NewEntryAnddServerEntrySharePath, but using the old-style protocol.
2735 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) { 2727 TEST_F(SyncerTest, NewEntryAndAlteredServerEntrySharePath_OldBookmarksProto) {
2736 mock_server_->set_use_legacy_bookmarks_protocol(true); 2728 mock_server_->set_use_legacy_bookmarks_protocol(true);
2737 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10); 2729 mock_server_->AddUpdateBookmark(1, 0, "Foo.htm", 10, 10);
2738 SyncShareAsDelegate(); 2730 SyncShareAsDelegate();
2739 int64 local_folder_handle; 2731 int64 local_folder_handle;
2740 syncable::Id local_folder_id; 2732 syncable::Id local_folder_id;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2786 ASSERT_TRUE(server.good()); 2778 ASSERT_TRUE(server.good());
2787 ASSERT_TRUE(local.good()); 2779 ASSERT_TRUE(local.good());
2788 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE)); 2780 EXPECT_TRUE(local.Get(META_HANDLE) != server.Get(META_HANDLE));
2789 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE)); 2781 EXPECT_FALSE(server.Get(IS_UNAPPLIED_UPDATE));
2790 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE)); 2782 EXPECT_FALSE(local.Get(IS_UNAPPLIED_UPDATE));
2791 EXPECT_FALSE(server.Get(IS_UNSYNCED)); 2783 EXPECT_FALSE(server.Get(IS_UNSYNCED));
2792 EXPECT_FALSE(local.Get(IS_UNSYNCED)); 2784 EXPECT_FALSE(local.Get(IS_UNSYNCED));
2793 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME)); 2785 EXPECT_EQ("Bar.htm", server.Get(NON_UNIQUE_NAME));
2794 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME)); 2786 EXPECT_EQ("Bar.htm", local.Get(NON_UNIQUE_NAME));
2795 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark. 2787 EXPECT_EQ("http://google.com", // Default from AddUpdateBookmark.
2796 server.Get(SPECIFICS).GetExtension(sync_pb::bookmark).url()); 2788 server.Get(SPECIFICS).bookmark().url());
2797 } 2789 }
2798 } 2790 }
2799 2791
2800 // Circular links should be resolved by the server. 2792 // Circular links should be resolved by the server.
2801 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) { 2793 TEST_F(SyncerTest, SiblingDirectoriesBecomeCircular) {
2802 // we don't currently resolve this. This test ensures we don't. 2794 // we don't currently resolve this. This test ensures we don't.
2803 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10); 2795 mock_server_->AddUpdateDirectory(1, 0, "A", 10, 10);
2804 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10); 2796 mock_server_->AddUpdateDirectory(2, 0, "B", 10, 10);
2805 SyncShareAsDelegate(); 2797 SyncShareAsDelegate();
2806 { 2798 {
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
3514 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3506 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3515 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED)); 3507 EXPECT_FALSE(perm_folder.Get(IS_UNSYNCED));
3516 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1"); 3508 EXPECT_EQ(perm_folder.Get(NON_UNIQUE_NAME), "permitem1");
3517 } 3509 }
3518 } 3510 }
3519 3511
3520 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) { 3512 TEST_F(SyncerTest, ClientTagUncommittedTagMatchesUpdate) {
3521 int64 original_metahandle = 0; 3513 int64 original_metahandle = 0;
3522 3514
3523 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics()); 3515 sync_pb::EntitySpecifics local_bookmark(DefaultBookmarkSpecifics());
3524 local_bookmark.MutableExtension(sync_pb::bookmark)-> 3516 local_bookmark.mutable_bookmark()->set_url("http://foo/localsite");
3525 set_url("http://foo/localsite");
3526 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics()); 3517 sync_pb::EntitySpecifics server_bookmark(DefaultBookmarkSpecifics());
3527 server_bookmark.MutableExtension(sync_pb::bookmark)-> 3518 server_bookmark.mutable_bookmark()->set_url("http://bar/serversite");
3528 set_url("http://bar/serversite");
3529 3519
3530 { 3520 {
3531 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 3521 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
3532 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname"); 3522 MutableEntry perm_folder(&trans, CREATE, ids_.root(), "clientname");
3533 ASSERT_TRUE(perm_folder.good()); 3523 ASSERT_TRUE(perm_folder.good());
3534 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm"); 3524 perm_folder.Put(UNIQUE_CLIENT_TAG, "clientperm");
3535 perm_folder.Put(SPECIFICS, local_bookmark); 3525 perm_folder.Put(SPECIFICS, local_bookmark);
3536 perm_folder.Put(IS_UNSYNCED, true); 3526 perm_folder.Put(IS_UNSYNCED, true);
3537 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE)); 3527 EXPECT_FALSE(perm_folder.Get(IS_UNAPPLIED_UPDATE));
3538 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows()); 3528 EXPECT_FALSE(perm_folder.Get(ID).ServerKnows());
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
4522 Add(low_id_); 4512 Add(low_id_);
4523 Add(high_id_); 4513 Add(high_id_);
4524 SyncShareAsDelegate(); 4514 SyncShareAsDelegate();
4525 ExpectLocalOrderIsByServerId(); 4515 ExpectLocalOrderIsByServerId();
4526 } 4516 }
4527 4517
4528 const SyncerTest::CommitOrderingTest 4518 const SyncerTest::CommitOrderingTest
4529 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; 4519 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()};
4530 4520
4531 } // namespace browser_sync 4521 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncer_proto_util.cc ('k') | chrome/browser/sync/engine/syncer_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698