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

Side by Side Diff: chrome/browser/sync/engine/apply_updates_command_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: fix nigori access in testserver 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 #include <string> 5 #include <string>
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "chrome/browser/sync/engine/apply_updates_command.h" 10 #include "chrome/browser/sync/engine/apply_updates_command.h"
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 558 }
559 559
560 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"}; 560 browser_sync::KeyParams params = {"localhost", "dummy", "foobar"};
561 cryptographer->AddKey(params); 561 cryptographer->AddKey(params);
562 562
563 sync_pb::EntitySpecifics specifics; 563 sync_pb::EntitySpecifics specifics;
564 sync_pb::PasswordSpecificsData data; 564 sync_pb::PasswordSpecificsData data;
565 data.set_origin("http://example.com"); 565 data.set_origin("http://example.com");
566 566
567 cryptographer->Encrypt(data, 567 cryptographer->Encrypt(data,
568 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); 568 specifics.mutable_password()->mutable_encrypted());
569 CreateUnappliedNewItem("item", specifics, false); 569 CreateUnappliedNewItem("item", specifics, false);
570 570
571 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); 571 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
572 apply_updates_command_.ExecuteImpl(session()); 572 apply_updates_command_.ExecuteImpl(session());
573 573
574 sessions::StatusController* status = session()->mutable_status_controller(); 574 sessions::StatusController* status = session()->mutable_status_controller();
575 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD); 575 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSWORD);
576 ASSERT_TRUE(status->update_progress()); 576 ASSERT_TRUE(status->update_progress());
577 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) 577 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize())
578 << "All updates should have been attempted"; 578 << "All updates should have been attempted";
579 ASSERT_TRUE(status->conflict_progress()); 579 ASSERT_TRUE(status->conflict_progress());
580 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize()) 580 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize())
581 << "No update should be in conflict because they're all decryptable"; 581 << "No update should be in conflict because they're all decryptable";
582 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) 582 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount())
583 << "The updates that can be decrypted should be applied"; 583 << "The updates that can be decrypted should be applied";
584 } 584 }
585 585
586 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) { 586 TEST_F(ApplyUpdatesCommandTest, UndecryptableData) {
587 // Undecryptable updates should not be applied. 587 // Undecryptable updates should not be applied.
588 sync_pb::EntitySpecifics encrypted_bookmark; 588 sync_pb::EntitySpecifics encrypted_bookmark;
589 encrypted_bookmark.mutable_encrypted(); 589 encrypted_bookmark.mutable_encrypted();
590 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark); 590 AddDefaultExtensionValue(syncable::BOOKMARKS, &encrypted_bookmark);
591 string root_server_id = syncable::GetNullId().GetServerId(); 591 string root_server_id = syncable::GetNullId().GetServerId();
592 CreateUnappliedNewItemWithParent("folder", 592 CreateUnappliedNewItemWithParent("folder",
593 encrypted_bookmark, 593 encrypted_bookmark,
594 root_server_id); 594 root_server_id);
595 CreateUnappliedNewItem("item2", encrypted_bookmark, false); 595 CreateUnappliedNewItem("item2", encrypted_bookmark, false);
596 sync_pb::EntitySpecifics encrypted_password; 596 sync_pb::EntitySpecifics encrypted_password;
597 encrypted_password.MutableExtension(sync_pb::password); 597 encrypted_password.mutable_password();
598 CreateUnappliedNewItem("item3", encrypted_password, false); 598 CreateUnappliedNewItem("item3", encrypted_password, false);
599 599
600 ExpectGroupsToChange(apply_updates_command_, GROUP_UI, GROUP_PASSWORD); 600 ExpectGroupsToChange(apply_updates_command_, GROUP_UI, GROUP_PASSWORD);
601 apply_updates_command_.ExecuteImpl(session()); 601 apply_updates_command_.ExecuteImpl(session());
602 602
603 sessions::StatusController* status = session()->mutable_status_controller(); 603 sessions::StatusController* status = session()->mutable_status_controller();
604 EXPECT_TRUE(status->HasConflictingUpdates()) 604 EXPECT_TRUE(status->HasConflictingUpdates())
605 << "Updates that can't be decrypted should trigger the syncer to have " 605 << "Updates that can't be decrypted should trigger the syncer to have "
606 << "conflicting updates."; 606 << "conflicting updates.";
607 { 607 {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); 646 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
647 ASSERT_TRUE(dir.good()); 647 ASSERT_TRUE(dir.good());
648 ReadTransaction trans(FROM_HERE, dir); 648 ReadTransaction trans(FROM_HERE, dir);
649 Cryptographer* cryptographer = 649 Cryptographer* cryptographer =
650 session()->context()->directory_manager()->GetCryptographer(&trans); 650 session()->context()->directory_manager()->GetCryptographer(&trans);
651 651
652 KeyParams params = {"localhost", "dummy", "foobar"}; 652 KeyParams params = {"localhost", "dummy", "foobar"};
653 cryptographer->AddKey(params); 653 cryptographer->AddKey(params);
654 654
655 cryptographer->Encrypt(data, 655 cryptographer->Encrypt(data,
656 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); 656 specifics.mutable_password()->mutable_encrypted());
657 } 657 }
658 CreateUnappliedNewItem("item1", specifics, false); 658 CreateUnappliedNewItem("item1", specifics, false);
659 } 659 }
660 { 660 {
661 // Create a new cryptographer, independent of the one in the session. 661 // Create a new cryptographer, independent of the one in the session.
662 Cryptographer cryptographer; 662 Cryptographer cryptographer;
663 KeyParams params = {"localhost", "dummy", "bazqux"}; 663 KeyParams params = {"localhost", "dummy", "bazqux"};
664 cryptographer.AddKey(params); 664 cryptographer.AddKey(params);
665 665
666 sync_pb::EntitySpecifics specifics; 666 sync_pb::EntitySpecifics specifics;
667 sync_pb::PasswordSpecificsData data; 667 sync_pb::PasswordSpecificsData data;
668 data.set_origin("http://example.com/2"); 668 data.set_origin("http://example.com/2");
669 669
670 cryptographer.Encrypt(data, 670 cryptographer.Encrypt(data,
671 specifics.MutableExtension(sync_pb::password)->mutable_encrypted()); 671 specifics.mutable_password()->mutable_encrypted());
672 CreateUnappliedNewItem("item2", specifics, false); 672 CreateUnappliedNewItem("item2", specifics, false);
673 } 673 }
674 674
675 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); 675 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD);
676 apply_updates_command_.ExecuteImpl(session()); 676 apply_updates_command_.ExecuteImpl(session());
677 677
678 sessions::StatusController* status = session()->mutable_status_controller(); 678 sessions::StatusController* status = session()->mutable_status_controller();
679 EXPECT_TRUE(status->HasConflictingUpdates()) 679 EXPECT_TRUE(status->HasConflictingUpdates())
680 << "Updates that can't be decrypted should trigger the syncer to have " 680 << "Updates that can't be decrypted should trigger the syncer to have "
681 << "conflicting updates."; 681 << "conflicting updates.";
(...skipping 29 matching lines...) Expand all
711 session()->context()->directory_manager()->GetCryptographer(&trans); 711 session()->context()->directory_manager()->GetCryptographer(&trans);
712 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); 712 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
713 } 713 }
714 714
715 // Nigori node updates should update the Cryptographer. 715 // Nigori node updates should update the Cryptographer.
716 Cryptographer other_cryptographer; 716 Cryptographer other_cryptographer;
717 KeyParams params = {"localhost", "dummy", "foobar"}; 717 KeyParams params = {"localhost", "dummy", "foobar"};
718 other_cryptographer.AddKey(params); 718 other_cryptographer.AddKey(params);
719 719
720 sync_pb::EntitySpecifics specifics; 720 sync_pb::EntitySpecifics specifics;
721 sync_pb::NigoriSpecifics* nigori = 721 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
722 specifics.MutableExtension(sync_pb::nigori);
723 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 722 other_cryptographer.GetKeys(nigori->mutable_encrypted());
724 nigori->set_encrypt_bookmarks(true); 723 nigori->set_encrypt_bookmarks(true);
725 encrypted_types.Put(syncable::BOOKMARKS); 724 encrypted_types.Put(syncable::BOOKMARKS);
726 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), 725 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
727 specifics, true); 726 specifics, true);
728 EXPECT_FALSE(cryptographer->has_pending_keys()); 727 EXPECT_FALSE(cryptographer->has_pending_keys());
729 728
730 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); 729 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
731 apply_updates_command_.ExecuteImpl(session()); 730 apply_updates_command_.ExecuteImpl(session());
732 731
(...skipping 30 matching lines...) Expand all
763 session()->context()->directory_manager()->GetCryptographer(&trans); 762 session()->context()->directory_manager()->GetCryptographer(&trans);
764 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); 763 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types));
765 } 764 }
766 765
767 // Nigori node updates should update the Cryptographer. 766 // Nigori node updates should update the Cryptographer.
768 Cryptographer other_cryptographer; 767 Cryptographer other_cryptographer;
769 KeyParams params = {"localhost", "dummy", "foobar"}; 768 KeyParams params = {"localhost", "dummy", "foobar"};
770 other_cryptographer.AddKey(params); 769 other_cryptographer.AddKey(params);
771 770
772 sync_pb::EntitySpecifics specifics; 771 sync_pb::EntitySpecifics specifics;
773 sync_pb::NigoriSpecifics* nigori = 772 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
774 specifics.MutableExtension(sync_pb::nigori);
775 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 773 other_cryptographer.GetKeys(nigori->mutable_encrypted());
776 nigori->set_encrypt_sessions(true); 774 nigori->set_encrypt_sessions(true);
777 nigori->set_encrypt_themes(true); 775 nigori->set_encrypt_themes(true);
778 encrypted_types.Put(syncable::SESSIONS); 776 encrypted_types.Put(syncable::SESSIONS);
779 encrypted_types.Put(syncable::THEMES); 777 encrypted_types.Put(syncable::THEMES);
780 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), 778 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
781 specifics, true); 779 specifics, true);
782 EXPECT_FALSE(cryptographer->has_pending_keys()); 780 EXPECT_FALSE(cryptographer->has_pending_keys());
783 781
784 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); 782 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 // Next five items are children of the root. 840 // Next five items are children of the root.
843 for (; i < 2*batch_s; ++i) { 841 for (; i < 2*batch_s; ++i) {
844 CreateUnsyncedItem(id_factory_.NewLocalId(), id_factory_.root(), 842 CreateUnsyncedItem(id_factory_.NewLocalId(), id_factory_.root(),
845 base::StringPrintf("Item %"PRIuS"", i), false, 843 base::StringPrintf("Item %"PRIuS"", i), false,
846 syncable::BOOKMARKS, NULL); 844 syncable::BOOKMARKS, NULL);
847 } 845 }
848 846
849 KeyParams params = {"localhost", "dummy", "foobar"}; 847 KeyParams params = {"localhost", "dummy", "foobar"};
850 cryptographer->AddKey(params); 848 cryptographer->AddKey(params);
851 sync_pb::EntitySpecifics specifics; 849 sync_pb::EntitySpecifics specifics;
852 sync_pb::NigoriSpecifics* nigori = 850 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
853 specifics.MutableExtension(sync_pb::nigori);
854 cryptographer->GetKeys(nigori->mutable_encrypted()); 851 cryptographer->GetKeys(nigori->mutable_encrypted());
855 nigori->set_encrypt_bookmarks(true); 852 nigori->set_encrypt_bookmarks(true);
856 encrypted_types.Put(syncable::BOOKMARKS); 853 encrypted_types.Put(syncable::BOOKMARKS);
857 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), 854 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
858 specifics, true); 855 specifics, true);
859 EXPECT_FALSE(cryptographer->has_pending_keys()); 856 EXPECT_FALSE(cryptographer->has_pending_keys());
860 EXPECT_TRUE(cryptographer->is_ready()); 857 EXPECT_TRUE(cryptographer->is_ready());
861 858
862 { 859 {
863 // Ensure we have unsynced nodes that aren't properly encrypted. 860 // Ensure we have unsynced nodes that aren't properly encrypted.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 base::StringPrintf("Item %"PRIuS"", i), false, 944 base::StringPrintf("Item %"PRIuS"", i), false,
948 syncable::BOOKMARKS, NULL); 945 syncable::BOOKMARKS, NULL);
949 } 946 }
950 947
951 // We encrypt with new keys, triggering the local cryptographer to be unready 948 // We encrypt with new keys, triggering the local cryptographer to be unready
952 // and unable to decrypt data (once updated). 949 // and unable to decrypt data (once updated).
953 Cryptographer other_cryptographer; 950 Cryptographer other_cryptographer;
954 KeyParams params = {"localhost", "dummy", "foobar"}; 951 KeyParams params = {"localhost", "dummy", "foobar"};
955 other_cryptographer.AddKey(params); 952 other_cryptographer.AddKey(params);
956 sync_pb::EntitySpecifics specifics; 953 sync_pb::EntitySpecifics specifics;
957 sync_pb::NigoriSpecifics* nigori = 954 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori();
958 specifics.MutableExtension(sync_pb::nigori);
959 other_cryptographer.GetKeys(nigori->mutable_encrypted()); 955 other_cryptographer.GetKeys(nigori->mutable_encrypted());
960 nigori->set_encrypt_bookmarks(true); 956 nigori->set_encrypt_bookmarks(true);
961 encrypted_types.Put(syncable::BOOKMARKS); 957 encrypted_types.Put(syncable::BOOKMARKS);
962 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI), 958 CreateUnappliedNewItem(syncable::ModelTypeToRootTag(syncable::NIGORI),
963 specifics, true); 959 specifics, true);
964 EXPECT_FALSE(cryptographer->has_pending_keys()); 960 EXPECT_FALSE(cryptographer->has_pending_keys());
965 961
966 { 962 {
967 // Ensure we have unsynced nodes that aren't properly encrypted. 963 // Ensure we have unsynced nodes that aren't properly encrypted.
968 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name()); 964 ScopedDirLookup dir(syncdb()->manager(), syncdb()->name());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 EXPECT_FALSE(cryptographer->is_ready()); 1002 EXPECT_FALSE(cryptographer->is_ready());
1007 EXPECT_TRUE(cryptographer->has_pending_keys()); 1003 EXPECT_TRUE(cryptographer->has_pending_keys());
1008 1004
1009 Syncer::UnsyncedMetaHandles handles; 1005 Syncer::UnsyncedMetaHandles handles;
1010 SyncerUtil::GetUnsyncedEntries(&trans, &handles); 1006 SyncerUtil::GetUnsyncedEntries(&trans, &handles);
1011 EXPECT_EQ(2*batch_s+1, handles.size()); 1007 EXPECT_EQ(2*batch_s+1, handles.size());
1012 } 1008 }
1013 } 1009 }
1014 1010
1015 } // namespace browser_sync 1011 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698