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

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 4 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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 18 matching lines...) Expand all
29 #include "sync/internal_api/public/engine/model_safe_worker.h" 29 #include "sync/internal_api/public/engine/model_safe_worker.h"
30 #include "sync/internal_api/public/engine/polling_constants.h" 30 #include "sync/internal_api/public/engine/polling_constants.h"
31 #include "sync/internal_api/public/http_post_provider_factory.h" 31 #include "sync/internal_api/public/http_post_provider_factory.h"
32 #include "sync/internal_api/public/http_post_provider_interface.h" 32 #include "sync/internal_api/public/http_post_provider_interface.h"
33 #include "sync/internal_api/public/read_node.h" 33 #include "sync/internal_api/public/read_node.h"
34 #include "sync/internal_api/public/read_transaction.h" 34 #include "sync/internal_api/public/read_transaction.h"
35 #include "sync/internal_api/public/test/test_internal_components_factory.h" 35 #include "sync/internal_api/public/test/test_internal_components_factory.h"
36 #include "sync/internal_api/public/test/test_user_share.h" 36 #include "sync/internal_api/public/test/test_user_share.h"
37 #include "sync/internal_api/public/write_node.h" 37 #include "sync/internal_api/public/write_node.h"
38 #include "sync/internal_api/public/write_transaction.h" 38 #include "sync/internal_api/public/write_transaction.h"
39 #include "sync/internal_api/sync_encryption_handler_impl.h"
39 #include "sync/internal_api/sync_manager_impl.h" 40 #include "sync/internal_api/sync_manager_impl.h"
40 #include "sync/internal_api/syncapi_internal.h" 41 #include "sync/internal_api/syncapi_internal.h"
41 #include "sync/js/js_arg_list.h" 42 #include "sync/js/js_arg_list.h"
42 #include "sync/js/js_backend.h" 43 #include "sync/js/js_backend.h"
43 #include "sync/js/js_event_handler.h" 44 #include "sync/js/js_event_handler.h"
44 #include "sync/js/js_reply_handler.h" 45 #include "sync/js/js_reply_handler.h"
45 #include "sync/js/js_test_util.h" 46 #include "sync/js/js_test_util.h"
46 #include "sync/notifier/sync_notifier.h" 47 #include "sync/notifier/sync_notifier.h"
47 #include "sync/notifier/sync_notifier_observer.h" 48 #include "sync/notifier/sync_notifier_observer.h"
48 #include "sync/protocol/bookmark_specifics.pb.h" 49 #include "sync/protocol/bookmark_specifics.pb.h"
(...skipping 21 matching lines...) Expand all
70 #include "testing/gmock/include/gmock/gmock.h" 71 #include "testing/gmock/include/gmock/gmock.h"
71 #include "testing/gtest/include/gtest/gtest.h" 72 #include "testing/gtest/include/gtest/gtest.h"
72 73
73 using base::ExpectDictStringValue; 74 using base::ExpectDictStringValue;
74 using testing::_; 75 using testing::_;
75 using testing::AnyNumber; 76 using testing::AnyNumber;
76 using testing::AtLeast; 77 using testing::AtLeast;
77 using testing::DoAll; 78 using testing::DoAll;
78 using testing::InSequence; 79 using testing::InSequence;
79 using testing::Invoke; 80 using testing::Invoke;
81 using testing::NiceMock;
80 using testing::Return; 82 using testing::Return;
81 using testing::SaveArg; 83 using testing::SaveArg;
82 using testing::StrictMock; 84 using testing::StrictMock;
83 85
84 namespace syncer { 86 namespace syncer {
85 87
86 using sessions::SyncSessionSnapshot; 88 using sessions::SyncSessionSnapshot;
87 using syncable::IS_DEL; 89 using syncable::IS_DEL;
88 using syncable::IS_UNSYNCED; 90 using syncable::IS_UNSYNCED;
89 using syncable::kEncryptedString; 91 using syncable::kEncryptedString;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 entry.Put(syncable::SPECIFICS, specifics); 220 entry.Put(syncable::SPECIFICS, specifics);
219 return entry.Get(syncable::META_HANDLE); 221 return entry.Get(syncable::META_HANDLE);
220 } 222 }
221 223
222 } // namespace 224 } // namespace
223 225
224 class SyncApiTest : public testing::Test { 226 class SyncApiTest : public testing::Test {
225 public: 227 public:
226 virtual void SetUp() { 228 virtual void SetUp() {
227 test_user_share_.SetUp(); 229 test_user_share_.SetUp();
230 SetUpEncryption();
228 } 231 }
229 232
230 virtual void TearDown() { 233 virtual void TearDown() {
231 test_user_share_.TearDown(); 234 test_user_share_.TearDown();
232 } 235 }
233 236
237 void SetUpEncryption() {
238 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
239 encryption_handler_.reset(
240 new SyncEncryptionHandlerImpl(test_user_share_.user_share(),
241 trans.GetCryptographer()));
242 trans.GetCryptographer()->SetNigoriHandler(encryption_handler_.get());
243 }
244
234 protected: 245 protected:
235 MessageLoop message_loop_; 246 MessageLoop message_loop_;
236 TestUserShare test_user_share_; 247 TestUserShare test_user_share_;
248 scoped_ptr<SyncEncryptionHandlerImpl> encryption_handler_;
237 }; 249 };
238 250
239 TEST_F(SyncApiTest, SanityCheckTest) { 251 TEST_F(SyncApiTest, SanityCheckTest) {
240 { 252 {
241 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 253 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
242 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); 254 EXPECT_TRUE(trans.GetWrappedTrans() != NULL);
243 } 255 }
244 { 256 {
245 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 257 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
246 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); 258 EXPECT_TRUE(trans.GetWrappedTrans() != NULL);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 password_node.GetPasswordSpecifics(); 477 password_node.GetPasswordSpecifics();
466 EXPECT_EQ("secret", data.password_value()); 478 EXPECT_EQ("secret", data.password_value());
467 } 479 }
468 } 480 }
469 481
470 TEST_F(SyncApiTest, WriteEncryptedTitle) { 482 TEST_F(SyncApiTest, WriteEncryptedTitle) {
471 KeyParams params = {"localhost", "username", "passphrase"}; 483 KeyParams params = {"localhost", "username", "passphrase"};
472 { 484 {
473 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); 485 ReadTransaction trans(FROM_HERE, test_user_share_.user_share());
474 trans.GetCryptographer()->AddKey(params); 486 trans.GetCryptographer()->AddKey(params);
475 trans.GetCryptographer()->set_encrypt_everything();
476 } 487 }
488 encryption_handler_->EnableEncryptEverything();
477 { 489 {
478 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 490 WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
479 ReadNode root_node(&trans); 491 ReadNode root_node(&trans);
480 root_node.InitByRootLookup(); 492 root_node.InitByRootLookup();
481 493
482 WriteNode bookmark_node(&trans); 494 WriteNode bookmark_node(&trans);
483 WriteNode::InitUniqueByCreationResult result = 495 WriteNode::InitUniqueByCreationResult result =
484 bookmark_node.InitUniqueByCreation(BOOKMARKS, 496 bookmark_node.InitUniqueByCreation(BOOKMARKS,
485 root_node, "foo"); 497 root_node, "foo");
486 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 498 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 }; 685 };
674 686
675 class SyncManagerObserverMock : public SyncManager::Observer { 687 class SyncManagerObserverMock : public SyncManager::Observer {
676 public: 688 public:
677 MOCK_METHOD1(OnSyncCycleCompleted, 689 MOCK_METHOD1(OnSyncCycleCompleted,
678 void(const SyncSessionSnapshot&)); // NOLINT 690 void(const SyncSessionSnapshot&)); // NOLINT
679 MOCK_METHOD3(OnInitializationComplete, 691 MOCK_METHOD3(OnInitializationComplete,
680 void(const WeakHandle<JsBackend>&, bool, 692 void(const WeakHandle<JsBackend>&, bool,
681 syncer::ModelTypeSet)); // NOLINT 693 syncer::ModelTypeSet)); // NOLINT
682 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT 694 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT
695 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT
696 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT
697 MOCK_METHOD1(OnActionableError,
698 void(const SyncProtocolError&)); // NOLINT
699 };
700
701 class SyncEncryptionHandlerObserverMock
702 : public SyncEncryptionHandler::Observer {
703 public:
683 MOCK_METHOD2(OnPassphraseRequired, 704 MOCK_METHOD2(OnPassphraseRequired,
684 void(PassphraseRequiredReason, 705 void(PassphraseRequiredReason,
685 const sync_pb::EncryptedData&)); // NOLINT 706 const sync_pb::EncryptedData&)); // NOLINT
686 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT 707 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT
687 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT 708 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT
688 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT
689 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT
690 MOCK_METHOD2(OnEncryptedTypesChanged, 709 MOCK_METHOD2(OnEncryptedTypesChanged,
691 void(ModelTypeSet, bool)); // NOLINT 710 void(ModelTypeSet, bool)); // NOLINT
692 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT 711 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
693 MOCK_METHOD1(OnActionableError, 712 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
694 void(const SyncProtocolError&)); // NOLINT
695 }; 713 };
696 714
697 class SyncNotifierMock : public SyncNotifier { 715 class SyncNotifierMock : public SyncNotifier {
698 public: 716 public:
699 MOCK_METHOD2(UpdateRegisteredIds, 717 MOCK_METHOD2(UpdateRegisteredIds,
700 void(SyncNotifierObserver*, const ObjectIdSet&)); 718 void(SyncNotifierObserver*, const ObjectIdSet&));
701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 719 MOCK_METHOD1(SetUniqueId, void(const std::string&));
702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); 720 MOCK_METHOD1(SetStateDeprecated, void(const std::string&));
703 MOCK_METHOD2(UpdateCredentials, 721 MOCK_METHOD2(UpdateCredentials,
704 void(const std::string&, const std::string&)); 722 void(const std::string&, const std::string&));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 SyncCredentials credentials; 754 SyncCredentials credentials;
737 credentials.email = "foo@bar.com"; 755 credentials.email = "foo@bar.com";
738 credentials.sync_token = "sometoken"; 756 credentials.sync_token = "sometoken";
739 757
740 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>(); 758 sync_notifier_mock_ = new StrictMock<SyncNotifierMock>();
741 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_)); 759 EXPECT_CALL(*sync_notifier_mock_, SetUniqueId(_));
742 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated("")); 760 EXPECT_CALL(*sync_notifier_mock_, SetStateDeprecated(""));
743 EXPECT_CALL(*sync_notifier_mock_, 761 EXPECT_CALL(*sync_notifier_mock_,
744 UpdateCredentials(credentials.email, credentials.sync_token)); 762 UpdateCredentials(credentials.email, credentials.sync_token));
745 763
746 sync_manager_.AddObserver(&observer_); 764 sync_manager_.AddObserver(&manager_observer_);
747 EXPECT_CALL(observer_, OnInitializationComplete(_, _, _)). 765 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _)).
748 WillOnce(SaveArg<0>(&js_backend_)); 766 WillOnce(SaveArg<0>(&js_backend_));
749 767
750 EXPECT_FALSE(js_backend_.IsInitialized()); 768 EXPECT_FALSE(js_backend_.IsInitialized());
751 769
752 std::vector<ModelSafeWorker*> workers; 770 std::vector<ModelSafeWorker*> workers;
753 ModelSafeRoutingInfo routing_info; 771 ModelSafeRoutingInfo routing_info;
754 GetModelSafeRoutingInfo(&routing_info); 772 GetModelSafeRoutingInfo(&routing_info);
755 773
756 // Takes ownership of |sync_notifier_mock_|. 774 // Takes ownership of |sync_notifier_mock_|.
757 sync_manager_.Init(temp_dir_.path(), 775 sync_manager_.Init(temp_dir_.path(),
758 WeakHandle<JsEventHandler>(), 776 WeakHandle<JsEventHandler>(),
759 "bogus", 0, false, 777 "bogus", 0, false,
760 base::MessageLoopProxy::current(), 778 base::MessageLoopProxy::current(),
761 scoped_ptr<HttpPostProviderFactory>( 779 scoped_ptr<HttpPostProviderFactory>(
762 new TestHttpPostProviderFactory()), 780 new TestHttpPostProviderFactory()),
763 workers, &extensions_activity_monitor_, this, 781 workers, &extensions_activity_monitor_, this,
764 credentials, 782 credentials,
765 scoped_ptr<SyncNotifier>(sync_notifier_mock_), 783 scoped_ptr<SyncNotifier>(sync_notifier_mock_),
766 "", "", // bootstrap tokens 784 "", "", // bootstrap tokens
767 true, // enable keystore encryption 785 true, // enable keystore encryption
768 scoped_ptr<InternalComponentsFactory>(GetFactory()), 786 scoped_ptr<InternalComponentsFactory>(GetFactory()),
769 &encryptor_, 787 &encryptor_,
770 &handler_, 788 &handler_,
771 NULL); 789 NULL);
772 790
791 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
792
773 EXPECT_TRUE(js_backend_.IsInitialized()); 793 EXPECT_TRUE(js_backend_.IsInitialized());
774 794
775 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 795 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
776 i != routing_info.end(); ++i) { 796 i != routing_info.end(); ++i) {
777 type_roots_[i->first] = MakeServerNodeForType( 797 type_roots_[i->first] = MakeServerNodeForType(
778 sync_manager_.GetUserShare(), i->first); 798 sync_manager_.GetUserShare(), i->first);
779 } 799 }
780 PumpLoop(); 800 PumpLoop();
781 } 801 }
782 802
783 void TearDown() { 803 void TearDown() {
784 sync_manager_.RemoveObserver(&observer_); 804 sync_manager_.RemoveObserver(&manager_observer_);
785 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet())); 805 EXPECT_CALL(*sync_notifier_mock_, UpdateRegisteredIds(_, ObjectIdSet()));
786 sync_manager_.ShutdownOnSyncThread(); 806 sync_manager_.ShutdownOnSyncThread();
787 sync_notifier_mock_ = NULL; 807 sync_notifier_mock_ = NULL;
788 PumpLoop(); 808 PumpLoop();
789 } 809 }
790 810
791 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { 811 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) {
792 (*out)[NIGORI] = GROUP_PASSIVE; 812 (*out)[NIGORI] = GROUP_PASSIVE;
793 (*out)[BOOKMARKS] = GROUP_PASSIVE; 813 (*out)[BOOKMARKS] = GROUP_PASSIVE;
794 (*out)[THEMES] = GROUP_PASSIVE; 814 (*out)[THEMES] = GROUP_PASSIVE;
(...skipping 14 matching lines...) Expand all
809 EncryptionStatus encryption_status) { 829 EncryptionStatus encryption_status) {
810 UserShare* share = sync_manager_.GetUserShare(); 830 UserShare* share = sync_manager_.GetUserShare();
811 share->directory->set_initial_sync_ended_for_type(NIGORI, true); 831 share->directory->set_initial_sync_ended_for_type(NIGORI, true);
812 832
813 // We need to create the nigori node as if it were an applied server update. 833 // We need to create the nigori node as if it were an applied server update.
814 int64 nigori_id = GetIdForDataType(NIGORI); 834 int64 nigori_id = GetIdForDataType(NIGORI);
815 if (nigori_id == kInvalidId) 835 if (nigori_id == kInvalidId)
816 return false; 836 return false;
817 837
818 // Set the nigori cryptographer information. 838 // Set the nigori cryptographer information.
839 if (encryption_status == FULL_ENCRYPTION)
840 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
841
819 WriteTransaction trans(FROM_HERE, share); 842 WriteTransaction trans(FROM_HERE, share);
820 Cryptographer* cryptographer = trans.GetCryptographer(); 843 Cryptographer* cryptographer = trans.GetCryptographer();
821 if (!cryptographer) 844 if (!cryptographer)
822 return false; 845 return false;
823 if (encryption_status != UNINITIALIZED) { 846 if (encryption_status != UNINITIALIZED) {
824 KeyParams params = {"localhost", "dummy", "foobar"}; 847 KeyParams params = {"localhost", "dummy", "foobar"};
825 cryptographer->AddKey(params); 848 cryptographer->AddKey(params);
826 } else { 849 } else {
827 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); 850 DCHECK_NE(nigori_status, WRITE_TO_NIGORI);
828 } 851 }
829 if (encryption_status == FULL_ENCRYPTION)
830 cryptographer->set_encrypt_everything();
831 if (nigori_status == WRITE_TO_NIGORI) { 852 if (nigori_status == WRITE_TO_NIGORI) {
832 sync_pb::NigoriSpecifics nigori; 853 sync_pb::NigoriSpecifics nigori;
833 cryptographer->GetKeys(nigori.mutable_encrypted()); 854 cryptographer->GetKeys(nigori.mutable_encrypted());
834 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori); 855 cryptographer->UpdateNigoriFromEncryptedTypes(&nigori);
835 WriteNode node(&trans); 856 WriteNode node(&trans);
836 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); 857 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id));
837 node.SetNigoriSpecifics(nigori); 858 node.SetNigoriSpecifics(nigori);
838 } 859 }
839 return cryptographer->is_ready(); 860 return cryptographer->is_ready();
840 } 861 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 return true; 901 return true;
881 } 902 }
882 903
883 virtual InternalComponentsFactory* GetFactory() { 904 virtual InternalComponentsFactory* GetFactory() {
884 return new TestInternalComponentsFactory(STORAGE_IN_MEMORY); 905 return new TestInternalComponentsFactory(STORAGE_IN_MEMORY);
885 } 906 }
886 907
887 // Returns true if we are currently encrypting all sync data. May 908 // Returns true if we are currently encrypting all sync data. May
888 // be called on any thread. 909 // be called on any thread.
889 bool EncryptEverythingEnabledForTest() { 910 bool EncryptEverythingEnabledForTest() {
890 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 911 return sync_manager_.GetEncryptionHandler()->EncryptEverythingEnabled();
891 return trans.GetCryptographer()->encrypt_everything();
892 } 912 }
893 913
894 // Gets the set of encrypted types from the cryptographer 914 // Gets the set of encrypted types from the cryptographer
895 // Note: opens a transaction. May be called from any thread. 915 // Note: opens a transaction. May be called from any thread.
896 syncer::ModelTypeSet GetEncryptedDataTypesForTest() { 916 syncer::ModelTypeSet GetEncryptedDataTypesForTest() {
897 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 917 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
898 return GetEncryptedTypes(&trans); 918 return GetEncryptedTypes(&trans);
899 } 919 }
900 920
901 void SimulateEnableNotificationsForTest() { 921 void SimulateEnableNotificationsForTest() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 // Sync Id's for the roots of the enabled datatypes. 962 // Sync Id's for the roots of the enabled datatypes.
943 std::map<ModelType, int64> type_roots_; 963 std::map<ModelType, int64> type_roots_;
944 FakeExtensionsActivityMonitor extensions_activity_monitor_; 964 FakeExtensionsActivityMonitor extensions_activity_monitor_;
945 965
946 protected: 966 protected:
947 FakeEncryptor encryptor_; 967 FakeEncryptor encryptor_;
948 TestUnrecoverableErrorHandler handler_; 968 TestUnrecoverableErrorHandler handler_;
949 StrictMock<SyncNotifierMock>* sync_notifier_mock_; 969 StrictMock<SyncNotifierMock>* sync_notifier_mock_;
950 SyncManagerImpl sync_manager_; 970 SyncManagerImpl sync_manager_;
951 WeakHandle<JsBackend> js_backend_; 971 WeakHandle<JsBackend> js_backend_;
952 StrictMock<SyncManagerObserverMock> observer_; 972 StrictMock<SyncManagerObserverMock> manager_observer_;
973 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
953 }; 974 };
954 975
955 TEST_F(SyncManagerTest, UpdateEnabledTypes) { 976 TEST_F(SyncManagerTest, UpdateEnabledTypes) {
956 ModelSafeRoutingInfo routes; 977 ModelSafeRoutingInfo routes;
957 GetModelSafeRoutingInfo(&routes); 978 GetModelSafeRoutingInfo(&routes);
958 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); 979 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes);
959 980
960 EXPECT_CALL(*sync_notifier_mock_, 981 EXPECT_CALL(*sync_notifier_mock_,
961 UpdateRegisteredIds( 982 UpdateRegisteredIds(
962 _, ModelTypeSetToObjectIdSet(enabled_types))); 983 _, ModelTypeSetToObjectIdSet(enabled_types)));
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1344
1324 TriggerOnIncomingNotificationForTest(empty_model_types); 1345 TriggerOnIncomingNotificationForTest(empty_model_types);
1325 TriggerOnIncomingNotificationForTest(model_types); 1346 TriggerOnIncomingNotificationForTest(model_types);
1326 1347
1327 // Should trigger the replies. 1348 // Should trigger the replies.
1328 PumpLoop(); 1349 PumpLoop();
1329 } 1350 }
1330 1351
1331 TEST_F(SyncManagerTest, RefreshEncryptionReady) { 1352 TEST_F(SyncManagerTest, RefreshEncryptionReady) {
1332 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1353 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1333 EXPECT_CALL(observer_, OnEncryptionComplete()); 1354 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1355 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1334 1356
1335 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 1357 sync_manager_.GetEncryptionHandler()->ReloadNigori();
1336 PumpLoop(); 1358 PumpLoop();
1337 1359
1338 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); 1360 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest();
1339 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); 1361 EXPECT_TRUE(encrypted_types.Has(PASSWORDS));
1340 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1362 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1341 1363
1342 { 1364 {
1343 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1365 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1344 ReadNode node(&trans); 1366 ReadNode node(&trans);
1345 EXPECT_EQ(BaseNode::INIT_OK, 1367 EXPECT_EQ(BaseNode::INIT_OK,
1346 node.InitByIdLookup(GetIdForDataType(NIGORI))); 1368 node.InitByIdLookup(GetIdForDataType(NIGORI)));
1347 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1369 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1348 EXPECT_TRUE(nigori.has_encrypted()); 1370 EXPECT_TRUE(nigori.has_encrypted());
1349 Cryptographer* cryptographer = trans.GetCryptographer(); 1371 Cryptographer* cryptographer = trans.GetCryptographer();
1350 EXPECT_TRUE(cryptographer->is_ready()); 1372 EXPECT_TRUE(cryptographer->is_ready());
1351 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1373 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1352 } 1374 }
1353 } 1375 }
1354 1376
1355 // Attempt to refresh encryption when nigori not downloaded. 1377 // Attempt to refresh encryption when nigori not downloaded.
1356 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { 1378 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) {
1357 // Don't set up encryption (no nigori node created). 1379 // Don't set up encryption (no nigori node created).
1358 1380
1359 // Should fail. 1381 // Should fail. Triggers an OnPassphraseRequired because the cryptographer
1360 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 1382 // is not ready.
1383 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)).Times(1);
1384 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1385 sync_manager_.GetEncryptionHandler()->ReloadNigori();
1361 PumpLoop(); 1386 PumpLoop();
1362 1387
1363 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); 1388 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest();
1364 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. 1389 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded.
1365 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1390 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1366 } 1391 }
1367 1392
1368 // Attempt to refresh encryption when nigori is empty. 1393 // Attempt to refresh encryption when nigori is empty.
1369 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { 1394 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) {
1370 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); 1395 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION));
1371 EXPECT_CALL(observer_, OnEncryptionComplete()); 1396 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(1);
1397 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1372 1398
1373 // Should write to nigori. 1399 // Should write to nigori.
1374 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 1400 sync_manager_.GetEncryptionHandler()->ReloadNigori();
1375 PumpLoop(); 1401 PumpLoop();
1376 1402
1377 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest(); 1403 const ModelTypeSet encrypted_types = GetEncryptedDataTypesForTest();
1378 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. 1404 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded.
1379 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1405 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1380 1406
1381 { 1407 {
1382 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1408 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1383 ReadNode node(&trans); 1409 ReadNode node(&trans);
1384 EXPECT_EQ(BaseNode::INIT_OK, 1410 EXPECT_EQ(BaseNode::INIT_OK,
1385 node.InitByIdLookup(GetIdForDataType(NIGORI))); 1411 node.InitByIdLookup(GetIdForDataType(NIGORI)));
1386 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1412 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1387 EXPECT_TRUE(nigori.has_encrypted()); 1413 EXPECT_TRUE(nigori.has_encrypted());
1388 Cryptographer* cryptographer = trans.GetCryptographer(); 1414 Cryptographer* cryptographer = trans.GetCryptographer();
1389 EXPECT_TRUE(cryptographer->is_ready()); 1415 EXPECT_TRUE(cryptographer->is_ready());
1390 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1416 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1391 } 1417 }
1392 } 1418 }
1393 1419
1394 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { 1420 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) {
1395 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1421 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1396 EXPECT_CALL(observer_, 1422 EXPECT_CALL(encryption_observer_,
1397 OnEncryptedTypesChanged( 1423 OnEncryptedTypesChanged(
1398 HasModelTypes(ModelTypeSet::All()), true)); 1424 HasModelTypes(ModelTypeSet::All()), true));
1399 EXPECT_CALL(observer_, OnEncryptionComplete()); 1425 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1400 sync_manager_.EnableEncryptEverything(); 1426 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1401 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1427 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1402 } 1428 }
1403 1429
1404 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { 1430 TEST_F(SyncManagerTest, EncryptDataTypesWithData) {
1405 size_t batch_size = 5; 1431 size_t batch_size = 5;
1406 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1432 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1407 1433
1408 // Create some unencrypted unsynced data. 1434 // Create some unencrypted unsynced data.
1409 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), 1435 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(),
1410 BOOKMARKS, 1436 BOOKMARKS,
(...skipping 14 matching lines...) Expand all
1425 // Last batch_size nodes are a third type that will not need encryption. 1451 // Last batch_size nodes are a third type that will not need encryption.
1426 for (; i < 3*batch_size; ++i) { 1452 for (; i < 3*batch_size; ++i) {
1427 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES, 1453 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES,
1428 base::StringPrintf("%"PRIuS"", i), 1454 base::StringPrintf("%"PRIuS"", i),
1429 GetIdForDataType(THEMES)); 1455 GetIdForDataType(THEMES));
1430 } 1456 }
1431 1457
1432 { 1458 {
1433 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1459 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1434 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( 1460 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
1435 Cryptographer::SensitiveTypes())); 1461 SyncEncryptionHandler::SensitiveTypes()));
1436 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1462 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1437 trans.GetWrappedTrans(), 1463 trans.GetWrappedTrans(),
1438 trans.GetCryptographer(), 1464 trans.GetCryptographer(),
1439 BOOKMARKS, 1465 BOOKMARKS,
1440 false /* not encrypted */)); 1466 false /* not encrypted */));
1441 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1467 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1442 trans.GetWrappedTrans(), 1468 trans.GetWrappedTrans(),
1443 trans.GetCryptographer(), 1469 trans.GetCryptographer(),
1444 SESSIONS, 1470 SESSIONS,
1445 false /* not encrypted */)); 1471 false /* not encrypted */));
1446 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1472 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1447 trans.GetWrappedTrans(), 1473 trans.GetWrappedTrans(),
1448 trans.GetCryptographer(), 1474 trans.GetCryptographer(),
1449 THEMES, 1475 THEMES,
1450 false /* not encrypted */)); 1476 false /* not encrypted */));
1451 } 1477 }
1452 1478
1453 EXPECT_CALL(observer_, 1479 EXPECT_CALL(encryption_observer_,
1454 OnEncryptedTypesChanged( 1480 OnEncryptedTypesChanged(
1455 HasModelTypes(ModelTypeSet::All()), true)); 1481 HasModelTypes(ModelTypeSet::All()), true));
1456 EXPECT_CALL(observer_, OnEncryptionComplete()); 1482 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1457 sync_manager_.EnableEncryptEverything(); 1483 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1458 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1484 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1459 { 1485 {
1460 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1486 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1461 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( 1487 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(
1462 ModelTypeSet::All())); 1488 ModelTypeSet::All()));
1463 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1489 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1464 trans.GetWrappedTrans(), 1490 trans.GetWrappedTrans(),
1465 trans.GetCryptographer(), 1491 trans.GetCryptographer(),
1466 BOOKMARKS, 1492 BOOKMARKS,
1467 true /* is encrypted */)); 1493 true /* is encrypted */));
1468 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1494 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1469 trans.GetWrappedTrans(), 1495 trans.GetWrappedTrans(),
1470 trans.GetCryptographer(), 1496 trans.GetCryptographer(),
1471 SESSIONS, 1497 SESSIONS,
1472 true /* is encrypted */)); 1498 true /* is encrypted */));
1473 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1499 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1474 trans.GetWrappedTrans(), 1500 trans.GetWrappedTrans(),
1475 trans.GetCryptographer(), 1501 trans.GetCryptographer(),
1476 THEMES, 1502 THEMES,
1477 true /* is encrypted */)); 1503 true /* is encrypted */));
1478 } 1504 }
1479 1505
1480 // Trigger's a ReEncryptEverything with new passphrase. 1506 // Trigger's a ReEncryptEverything with new passphrase.
1481 testing::Mock::VerifyAndClearExpectations(&observer_); 1507 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1482 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1508 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1483 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1509 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1484 EXPECT_CALL(observer_, OnEncryptionComplete()); 1510 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1485 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 1511 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1512 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1513 "new_passphrase", true);
1486 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1514 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1487 { 1515 {
1488 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1516 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1489 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); 1517 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All()));
1490 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1518 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1491 trans.GetWrappedTrans(), 1519 trans.GetWrappedTrans(),
1492 trans.GetCryptographer(), 1520 trans.GetCryptographer(),
1493 BOOKMARKS, 1521 BOOKMARKS,
1494 true /* is encrypted */)); 1522 true /* is encrypted */));
1495 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1523 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1496 trans.GetWrappedTrans(), 1524 trans.GetWrappedTrans(),
1497 trans.GetCryptographer(), 1525 trans.GetCryptographer(),
1498 SESSIONS, 1526 SESSIONS,
1499 true /* is encrypted */)); 1527 true /* is encrypted */));
1500 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1528 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1501 trans.GetWrappedTrans(), 1529 trans.GetWrappedTrans(),
1502 trans.GetCryptographer(), 1530 trans.GetCryptographer(),
1503 THEMES, 1531 THEMES,
1504 true /* is encrypted */)); 1532 true /* is encrypted */));
1505 } 1533 }
1506 // Calling EncryptDataTypes with an empty encrypted types should not trigger 1534 // Calling EncryptDataTypes with an empty encrypted types should not trigger
1507 // a reencryption and should just notify immediately. 1535 // a reencryption and should just notify immediately.
1508 // TODO(zea): add logic to ensure nothing was written. 1536 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1509 testing::Mock::VerifyAndClearExpectations(&observer_); 1537 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)).Times(0);
1510 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)).Times(0); 1538 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0);
1511 EXPECT_CALL(observer_, OnPassphraseAccepted()).Times(0); 1539 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0);
1512 EXPECT_CALL(observer_, OnEncryptionComplete()); 1540 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1513 sync_manager_.EnableEncryptEverything();
1514 } 1541 }
1515 1542
1516 // Test that when there are no pending keys and the cryptographer is not 1543 // Test that when there are no pending keys and the cryptographer is not
1517 // initialized, we add a key based on the current GAIA password. 1544 // initialized, we add a key based on the current GAIA password.
1518 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1545 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
1519 TEST_F(SyncManagerTest, SetInitialGaiaPass) { 1546 TEST_F(SyncManagerTest, SetInitialGaiaPass) {
1520 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1547 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1521 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1548 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1522 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1549 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1523 EXPECT_CALL(observer_, OnEncryptionComplete()); 1550 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1524 sync_manager_.SetEncryptionPassphrase("new_passphrase", false); 1551 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1552 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1553 "new_passphrase",
1554 false);
1555 EXPECT_FALSE(
1556 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1525 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1557 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1526 { 1558 {
1527 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1559 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1528 ReadNode node(&trans); 1560 ReadNode node(&trans);
1529 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1561 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1530 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1562 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1531 Cryptographer* cryptographer = trans.GetCryptographer(); 1563 Cryptographer* cryptographer = trans.GetCryptographer();
1532 EXPECT_TRUE(cryptographer->is_ready()); 1564 EXPECT_TRUE(cryptographer->is_ready());
1533 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1565 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1534 } 1566 }
1535 } 1567 }
1536 1568
1537 // Test that when there are no pending keys and we have on the old GAIA 1569 // Test that when there are no pending keys and we have on the old GAIA
1538 // password, we update and re-encrypt everything with the new GAIA password. 1570 // password, we update and re-encrypt everything with the new GAIA password.
1539 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1571 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
1540 TEST_F(SyncManagerTest, UpdateGaiaPass) { 1572 TEST_F(SyncManagerTest, UpdateGaiaPass) {
1541 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1573 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1542 Cryptographer verifier(&encryptor_); 1574 Cryptographer verifier(&encryptor_);
1543 { 1575 {
1544 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1576 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1545 Cryptographer* cryptographer = trans.GetCryptographer(); 1577 Cryptographer* cryptographer = trans.GetCryptographer();
1546 std::string bootstrap_token; 1578 std::string bootstrap_token;
1547 cryptographer->GetBootstrapToken(&bootstrap_token); 1579 cryptographer->GetBootstrapToken(&bootstrap_token);
1548 verifier.Bootstrap(bootstrap_token); 1580 verifier.Bootstrap(bootstrap_token);
1549 } 1581 }
1550 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1582 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1551 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1583 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1552 EXPECT_CALL(observer_, OnEncryptionComplete()); 1584 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1553 sync_manager_.SetEncryptionPassphrase("new_passphrase", false); 1585 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1586 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1587 "new_passphrase",
1588 false);
1589 EXPECT_FALSE(
1590 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1554 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1591 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1555 { 1592 {
1556 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1593 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1557 Cryptographer* cryptographer = trans.GetCryptographer(); 1594 Cryptographer* cryptographer = trans.GetCryptographer();
1558 EXPECT_TRUE(cryptographer->is_ready()); 1595 EXPECT_TRUE(cryptographer->is_ready());
1559 // Verify the default key has changed. 1596 // Verify the default key has changed.
1560 sync_pb::EncryptedData encrypted; 1597 sync_pb::EncryptedData encrypted;
1561 cryptographer->GetKeys(&encrypted); 1598 cryptographer->GetKeys(&encrypted);
1562 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1599 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1563 } 1600 }
(...skipping 18 matching lines...) Expand all
1582 1619
1583 WriteNode password_node(&trans); 1620 WriteNode password_node(&trans);
1584 WriteNode::InitUniqueByCreationResult result = 1621 WriteNode::InitUniqueByCreationResult result =
1585 password_node.InitUniqueByCreation(PASSWORDS, 1622 password_node.InitUniqueByCreation(PASSWORDS,
1586 root_node, "foo"); 1623 root_node, "foo");
1587 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1624 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1588 sync_pb::PasswordSpecificsData data; 1625 sync_pb::PasswordSpecificsData data;
1589 data.set_password_value("secret"); 1626 data.set_password_value("secret");
1590 password_node.SetPasswordSpecifics(data); 1627 password_node.SetPasswordSpecifics(data);
1591 } 1628 }
1592 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1629 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1593 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1630 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1594 EXPECT_CALL(observer_, OnEncryptionComplete()); 1631 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1595 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 1632 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1633 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1634 "new_passphrase",
1635 true);
1636 EXPECT_TRUE(
1637 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1596 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1638 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1597 { 1639 {
1598 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1640 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1599 Cryptographer* cryptographer = trans.GetCryptographer(); 1641 Cryptographer* cryptographer = trans.GetCryptographer();
1600 EXPECT_TRUE(cryptographer->is_ready()); 1642 EXPECT_TRUE(cryptographer->is_ready());
1601 // Verify the default key has changed. 1643 // Verify the default key has changed.
1602 sync_pb::EncryptedData encrypted; 1644 sync_pb::EncryptedData encrypted;
1603 cryptographer->GetKeys(&encrypted); 1645 cryptographer->GetKeys(&encrypted);
1604 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1646 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1605 1647
(...skipping 22 matching lines...) Expand all
1628 other_cryptographer.Bootstrap(bootstrap_token); 1670 other_cryptographer.Bootstrap(bootstrap_token);
1629 1671
1630 // Now update the nigori to reflect the new keys, and update the 1672 // Now update the nigori to reflect the new keys, and update the
1631 // cryptographer to have pending keys. 1673 // cryptographer to have pending keys.
1632 KeyParams params = {"localhost", "dummy", "passphrase2"}; 1674 KeyParams params = {"localhost", "dummy", "passphrase2"};
1633 other_cryptographer.AddKey(params); 1675 other_cryptographer.AddKey(params);
1634 WriteNode node(&trans); 1676 WriteNode node(&trans);
1635 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1677 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1636 sync_pb::NigoriSpecifics nigori; 1678 sync_pb::NigoriSpecifics nigori;
1637 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1679 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1638 cryptographer->Update(nigori); 1680 cryptographer->SetPendingKeys(nigori.encrypted());
1639 EXPECT_TRUE(cryptographer->has_pending_keys()); 1681 EXPECT_TRUE(cryptographer->has_pending_keys());
1640 node.SetNigoriSpecifics(nigori); 1682 node.SetNigoriSpecifics(nigori);
1641 } 1683 }
1642 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1684 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1643 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1685 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1644 EXPECT_CALL(observer_, OnEncryptionComplete()); 1686 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1645 sync_manager_.SetDecryptionPassphrase("passphrase2"); 1687 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1688 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2");
1689 EXPECT_FALSE(
1690 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1646 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1691 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1647 { 1692 {
1648 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1693 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1649 Cryptographer* cryptographer = trans.GetCryptographer(); 1694 Cryptographer* cryptographer = trans.GetCryptographer();
1650 EXPECT_TRUE(cryptographer->is_ready()); 1695 EXPECT_TRUE(cryptographer->is_ready());
1651 // Verify we're encrypting with the new key. 1696 // Verify we're encrypting with the new key.
1652 sync_pb::EncryptedData encrypted; 1697 sync_pb::EncryptedData encrypted;
1653 cryptographer->GetKeys(&encrypted); 1698 cryptographer->GetKeys(&encrypted);
1654 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1699 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1655 } 1700 }
(...skipping 17 matching lines...) Expand all
1673 1718
1674 // Now update the nigori to reflect the new keys, and update the 1719 // Now update the nigori to reflect the new keys, and update the
1675 // cryptographer to have pending keys. 1720 // cryptographer to have pending keys.
1676 KeyParams params = {"localhost", "dummy", "old_gaia"}; 1721 KeyParams params = {"localhost", "dummy", "old_gaia"};
1677 other_cryptographer.AddKey(params); 1722 other_cryptographer.AddKey(params);
1678 WriteNode node(&trans); 1723 WriteNode node(&trans);
1679 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1724 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1680 sync_pb::NigoriSpecifics nigori; 1725 sync_pb::NigoriSpecifics nigori;
1681 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1726 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1682 node.SetNigoriSpecifics(nigori); 1727 node.SetNigoriSpecifics(nigori);
1683 cryptographer->Update(nigori); 1728 cryptographer->SetPendingKeys(nigori.encrypted());
1684 1729
1685 // other_cryptographer now contains all encryption keys, and is encrypting 1730 // other_cryptographer now contains all encryption keys, and is encrypting
1686 // with the newest gaia. 1731 // with the newest gaia.
1687 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; 1732 KeyParams new_params = {"localhost", "dummy", "new_gaia"};
1688 other_cryptographer.AddKey(new_params); 1733 other_cryptographer.AddKey(new_params);
1689 } 1734 }
1690 // The bootstrap token should have been updated. Save it to ensure it's based 1735 // The bootstrap token should have been updated. Save it to ensure it's based
1691 // on the new GAIA password. 1736 // on the new GAIA password.
1692 std::string bootstrap_token; 1737 std::string bootstrap_token;
1693 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)) 1738 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_))
1694 .WillOnce(SaveArg<0>(&bootstrap_token)); 1739 .WillOnce(SaveArg<0>(&bootstrap_token));
1695 EXPECT_CALL(observer_, OnPassphraseRequired(_,_)); 1740 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_));
1696 sync_manager_.SetEncryptionPassphrase("new_gaia", false); 1741 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1742 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1743 "new_gaia",
1744 false);
1745 EXPECT_FALSE(
1746 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1697 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1747 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1698 testing::Mock::VerifyAndClearExpectations(&observer_); 1748 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1699 { 1749 {
1700 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1750 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1701 Cryptographer* cryptographer = trans.GetCryptographer(); 1751 Cryptographer* cryptographer = trans.GetCryptographer();
1702 EXPECT_TRUE(cryptographer->is_initialized()); 1752 EXPECT_TRUE(cryptographer->is_initialized());
1703 EXPECT_FALSE(cryptographer->is_ready()); 1753 EXPECT_FALSE(cryptographer->is_ready());
1704 // Verify we're encrypting with the new key, even though we have pending 1754 // Verify we're encrypting with the new key, even though we have pending
1705 // keys. 1755 // keys.
1706 sync_pb::EncryptedData encrypted; 1756 sync_pb::EncryptedData encrypted;
1707 other_cryptographer.GetKeys(&encrypted); 1757 other_cryptographer.GetKeys(&encrypted);
1708 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1758 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1709 } 1759 }
1710 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1760 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1711 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1761 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1712 EXPECT_CALL(observer_, OnEncryptionComplete()); 1762 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1713 sync_manager_.SetEncryptionPassphrase("old_gaia", false); 1763 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1764 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1765 "old_gaia",
1766 false);
1767 EXPECT_FALSE(
1768 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1714 { 1769 {
1715 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1770 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1716 Cryptographer* cryptographer = trans.GetCryptographer(); 1771 Cryptographer* cryptographer = trans.GetCryptographer();
1717 EXPECT_TRUE(cryptographer->is_ready()); 1772 EXPECT_TRUE(cryptographer->is_ready());
1718 1773
1719 // Verify we're encrypting with the new key. 1774 // Verify we're encrypting with the new key.
1720 sync_pb::EncryptedData encrypted; 1775 sync_pb::EncryptedData encrypted;
1721 other_cryptographer.GetKeys(&encrypted); 1776 other_cryptographer.GetKeys(&encrypted);
1722 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1777 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1723 1778
(...skipping 19 matching lines...) Expand all
1743 other_cryptographer.Bootstrap(bootstrap_token); 1798 other_cryptographer.Bootstrap(bootstrap_token);
1744 1799
1745 // Now update the nigori to reflect the new keys, and update the 1800 // Now update the nigori to reflect the new keys, and update the
1746 // cryptographer to have pending keys. 1801 // cryptographer to have pending keys.
1747 KeyParams params = {"localhost", "dummy", "explicit"}; 1802 KeyParams params = {"localhost", "dummy", "explicit"};
1748 other_cryptographer.AddKey(params); 1803 other_cryptographer.AddKey(params);
1749 WriteNode node(&trans); 1804 WriteNode node(&trans);
1750 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1805 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1751 sync_pb::NigoriSpecifics nigori; 1806 sync_pb::NigoriSpecifics nigori;
1752 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1807 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1753 cryptographer->Update(nigori); 1808 cryptographer->SetPendingKeys(nigori.encrypted());
1754 EXPECT_TRUE(cryptographer->has_pending_keys()); 1809 EXPECT_TRUE(cryptographer->has_pending_keys());
1755 nigori.set_using_explicit_passphrase(true); 1810 nigori.set_using_explicit_passphrase(true);
1756 node.SetNigoriSpecifics(nigori); 1811 node.SetNigoriSpecifics(nigori);
1757 } 1812 }
1758 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1813 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1759 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1814 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1760 EXPECT_CALL(observer_, OnEncryptionComplete()); 1815 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1761 sync_manager_.SetDecryptionPassphrase("explicit"); 1816 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1817 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit");
1818 EXPECT_TRUE(
1819 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1762 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1820 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1763 { 1821 {
1764 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1822 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1765 Cryptographer* cryptographer = trans.GetCryptographer(); 1823 Cryptographer* cryptographer = trans.GetCryptographer();
1766 EXPECT_TRUE(cryptographer->is_ready()); 1824 EXPECT_TRUE(cryptographer->is_ready());
1767 // Verify we're encrypting with the new key. 1825 // Verify we're encrypting with the new key.
1768 sync_pb::EncryptedData encrypted; 1826 sync_pb::EncryptedData encrypted;
1769 cryptographer->GetKeys(&encrypted); 1827 cryptographer->GetKeys(&encrypted);
1770 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1828 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1771 } 1829 }
(...skipping 11 matching lines...) Expand all
1783 Cryptographer* cryptographer = trans.GetCryptographer(); 1841 Cryptographer* cryptographer = trans.GetCryptographer();
1784 // Now update the nigori to reflect the new keys, and update the 1842 // Now update the nigori to reflect the new keys, and update the
1785 // cryptographer to have pending keys. 1843 // cryptographer to have pending keys.
1786 KeyParams params = {"localhost", "dummy", "passphrase"}; 1844 KeyParams params = {"localhost", "dummy", "passphrase"};
1787 other_cryptographer.AddKey(params); 1845 other_cryptographer.AddKey(params);
1788 WriteNode node(&trans); 1846 WriteNode node(&trans);
1789 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1847 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1790 sync_pb::NigoriSpecifics nigori; 1848 sync_pb::NigoriSpecifics nigori;
1791 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1849 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1792 node.SetNigoriSpecifics(nigori); 1850 node.SetNigoriSpecifics(nigori);
1793 cryptographer->Update(nigori); 1851 cryptographer->SetPendingKeys(nigori.encrypted());
1794 EXPECT_FALSE(cryptographer->is_ready()); 1852 EXPECT_FALSE(cryptographer->is_ready());
1795 } 1853 }
1796 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1854 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1797 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1855 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1798 EXPECT_CALL(observer_, OnEncryptionComplete()); 1856 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1799 sync_manager_.SetEncryptionPassphrase("passphrase", false); 1857 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1858 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1859 "passphrase",
1860 false);
1861 EXPECT_FALSE(
1862 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1800 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1863 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1801 { 1864 {
1802 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1865 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1803 Cryptographer* cryptographer = trans.GetCryptographer(); 1866 Cryptographer* cryptographer = trans.GetCryptographer();
1804 EXPECT_TRUE(cryptographer->is_ready()); 1867 EXPECT_TRUE(cryptographer->is_ready());
1805 } 1868 }
1806 } 1869 }
1807 1870
1808 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { 1871 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) {
1809 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1872 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1810 int64 node_id = 0; 1873 int64 node_id = 0;
1811 std::string tag = "foo"; 1874 std::string tag = "foo";
1812 { 1875 {
1813 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1876 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1814 ReadNode root_node(&trans); 1877 ReadNode root_node(&trans);
1815 root_node.InitByRootLookup(); 1878 root_node.InitByRootLookup();
1816 1879
1817 WriteNode password_node(&trans); 1880 WriteNode password_node(&trans);
1818 WriteNode::InitUniqueByCreationResult result = 1881 WriteNode::InitUniqueByCreationResult result =
1819 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); 1882 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag);
1820 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1883 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1821 node_id = password_node.GetId(); 1884 node_id = password_node.GetId();
1822 } 1885 }
1823 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 1886 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1824 EXPECT_CALL(observer_, OnPassphraseAccepted()); 1887 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1825 EXPECT_CALL(observer_, OnEncryptionComplete()); 1888 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1826 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 1889 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1890 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1891 "new_passphrase",
1892 true);
1893 EXPECT_TRUE(
1894 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
1827 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1895 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1828 { 1896 {
1829 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1897 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1830 ReadNode password_node(&trans); 1898 ReadNode password_node(&trans);
1831 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, 1899 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY,
1832 password_node.InitByClientTagLookup(PASSWORDS, 1900 password_node.InitByClientTagLookup(PASSWORDS,
1833 tag)); 1901 tag));
1834 } 1902 }
1835 { 1903 {
1836 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1904 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 1986
1919 { 1987 {
1920 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1988 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1921 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1989 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1922 trans.GetWrappedTrans(), 1990 trans.GetWrappedTrans(),
1923 trans.GetCryptographer(), 1991 trans.GetCryptographer(),
1924 BOOKMARKS, 1992 BOOKMARKS,
1925 false /* not encrypted */)); 1993 false /* not encrypted */));
1926 } 1994 }
1927 1995
1928 EXPECT_CALL(observer_, 1996 EXPECT_CALL(encryption_observer_,
1929 OnEncryptedTypesChanged( 1997 OnEncryptedTypesChanged(
1930 HasModelTypes(ModelTypeSet::All()), true)); 1998 HasModelTypes(ModelTypeSet::All()), true));
1931 EXPECT_CALL(observer_, OnEncryptionComplete()); 1999 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1932 sync_manager_.EnableEncryptEverything(); 2000 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1933 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 2001 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1934 2002
1935 { 2003 {
1936 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2004 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1937 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); 2005 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All()));
1938 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 2006 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1939 trans.GetWrappedTrans(), 2007 trans.GetWrappedTrans(),
1940 trans.GetCryptographer(), 2008 trans.GetCryptographer(),
1941 BOOKMARKS, 2009 BOOKMARKS,
1942 true /* is encrypted */)); 2010 true /* is encrypted */));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 { 2074 {
2007 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2075 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2008 WriteNode node(&trans); 2076 WriteNode node(&trans);
2009 EXPECT_EQ(BaseNode::INIT_OK, 2077 EXPECT_EQ(BaseNode::INIT_OK,
2010 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2078 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2011 node.SetEntitySpecifics(entity_specifics); 2079 node.SetEntitySpecifics(entity_specifics);
2012 } 2080 }
2013 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2081 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2014 2082
2015 // Encrypt the datatatype, should set is_unsynced. 2083 // Encrypt the datatatype, should set is_unsynced.
2016 EXPECT_CALL(observer_, 2084 EXPECT_CALL(encryption_observer_,
2017 OnEncryptedTypesChanged( 2085 OnEncryptedTypesChanged(
2018 HasModelTypes(ModelTypeSet::All()), true)); 2086 HasModelTypes(ModelTypeSet::All()), true));
2019 EXPECT_CALL(observer_, OnEncryptionComplete()); 2087 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2020 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2088 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2021 2089
2022 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2090 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2091 sync_manager_.GetEncryptionHandler()->ReloadNigori();
2023 PumpLoop(); 2092 PumpLoop();
2024 { 2093 {
2025 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2094 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2026 ReadNode node(&trans); 2095 ReadNode node(&trans);
2027 EXPECT_EQ(BaseNode::INIT_OK, 2096 EXPECT_EQ(BaseNode::INIT_OK,
2028 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2097 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2029 const syncable::Entry* node_entry = node.GetEntry(); 2098 const syncable::Entry* node_entry = node.GetEntry();
2030 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2099 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2031 EXPECT_TRUE(specifics.has_encrypted()); 2100 EXPECT_TRUE(specifics.has_encrypted());
2032 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2101 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2033 Cryptographer* cryptographer = trans.GetCryptographer(); 2102 Cryptographer* cryptographer = trans.GetCryptographer();
2034 EXPECT_TRUE(cryptographer->is_ready()); 2103 EXPECT_TRUE(cryptographer->is_ready());
2035 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2104 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2036 specifics.encrypted())); 2105 specifics.encrypted()));
2037 } 2106 }
2038 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2107 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2039 2108
2040 // Set a new passphrase. Should set is_unsynced. 2109 // Set a new passphrase. Should set is_unsynced.
2041 testing::Mock::VerifyAndClearExpectations(&observer_); 2110 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2042 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 2111 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
2043 EXPECT_CALL(observer_, OnPassphraseAccepted()); 2112 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2044 EXPECT_CALL(observer_, OnEncryptionComplete()); 2113 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2045 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 2114 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2115 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2116 "new_passphrase",
2117 true);
2046 { 2118 {
2047 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2119 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2048 ReadNode node(&trans); 2120 ReadNode node(&trans);
2049 EXPECT_EQ(BaseNode::INIT_OK, 2121 EXPECT_EQ(BaseNode::INIT_OK,
2050 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2122 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2051 const syncable::Entry* node_entry = node.GetEntry(); 2123 const syncable::Entry* node_entry = node.GetEntry();
2052 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2124 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2053 EXPECT_TRUE(specifics.has_encrypted()); 2125 EXPECT_TRUE(specifics.has_encrypted());
2054 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2126 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2055 Cryptographer* cryptographer = trans.GetCryptographer(); 2127 Cryptographer* cryptographer = trans.GetCryptographer();
2056 EXPECT_TRUE(cryptographer->is_ready()); 2128 EXPECT_TRUE(cryptographer->is_ready());
2057 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2129 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2058 specifics.encrypted())); 2130 specifics.encrypted()));
2059 } 2131 }
2060 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2132 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2061 2133
2062 // Force a re-encrypt everything. Should not set is_unsynced. 2134 // Force a re-encrypt everything. Should not set is_unsynced.
2063 testing::Mock::VerifyAndClearExpectations(&observer_); 2135 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2064 EXPECT_CALL(observer_, OnEncryptionComplete()); 2136 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2137 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2065 2138
2066 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2139 sync_manager_.GetEncryptionHandler()->ReloadNigori();
2067 PumpLoop(); 2140 PumpLoop();
2068 2141
2069 { 2142 {
2070 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2143 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2071 ReadNode node(&trans); 2144 ReadNode node(&trans);
2072 EXPECT_EQ(BaseNode::INIT_OK, 2145 EXPECT_EQ(BaseNode::INIT_OK,
2073 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2146 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2074 const syncable::Entry* node_entry = node.GetEntry(); 2147 const syncable::Entry* node_entry = node.GetEntry();
2075 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2148 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2076 EXPECT_TRUE(specifics.has_encrypted()); 2149 EXPECT_TRUE(specifics.has_encrypted());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 entity_specifics.mutable_password()->mutable_encrypted()); 2295 entity_specifics.mutable_password()->mutable_encrypted());
2223 } 2296 }
2224 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, 2297 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag,
2225 BaseNode::GenerateSyncableHash(PASSWORDS, 2298 BaseNode::GenerateSyncableHash(PASSWORDS,
2226 client_tag), 2299 client_tag),
2227 entity_specifics); 2300 entity_specifics);
2228 // New node shouldn't start off unsynced. 2301 // New node shouldn't start off unsynced.
2229 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2302 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2230 2303
2231 // Set a new passphrase. Should set is_unsynced. 2304 // Set a new passphrase. Should set is_unsynced.
2232 testing::Mock::VerifyAndClearExpectations(&observer_); 2305 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2233 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); 2306 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
2234 EXPECT_CALL(observer_, OnPassphraseAccepted()); 2307 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2235 EXPECT_CALL(observer_, OnEncryptionComplete()); 2308 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2236 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); 2309 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2310 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2311 "new_passphrase",
2312 true);
2313 EXPECT_TRUE(
2314 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase());
2237 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2315 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2238 } 2316 }
2239 2317
2240 // Passwords have their own handling for encryption. Verify it does not result 2318 // Passwords have their own handling for encryption. Verify it does not result
2241 // in unnecessary writes via ReencryptEverything. 2319 // in unnecessary writes via ReencryptEverything.
2242 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { 2320 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
2243 std::string client_tag = "title"; 2321 std::string client_tag = "title";
2244 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 2322 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2245 sync_pb::EntitySpecifics entity_specifics; 2323 sync_pb::EntitySpecifics entity_specifics;
2246 { 2324 {
2247 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2325 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2248 Cryptographer* cryptographer = trans.GetCryptographer(); 2326 Cryptographer* cryptographer = trans.GetCryptographer();
2249 sync_pb::PasswordSpecificsData data; 2327 sync_pb::PasswordSpecificsData data;
2250 data.set_password_value("secret"); 2328 data.set_password_value("secret");
2251 cryptographer->Encrypt( 2329 cryptographer->Encrypt(
2252 data, 2330 data,
2253 entity_specifics.mutable_password()->mutable_encrypted()); 2331 entity_specifics.mutable_password()->mutable_encrypted());
2254 } 2332 }
2255 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, 2333 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag,
2256 BaseNode::GenerateSyncableHash(PASSWORDS, 2334 BaseNode::GenerateSyncableHash(PASSWORDS,
2257 client_tag), 2335 client_tag),
2258 entity_specifics); 2336 entity_specifics);
2259 // New node shouldn't start off unsynced. 2337 // New node shouldn't start off unsynced.
2260 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2338 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2261 2339
2262 // Force a re-encrypt everything. Should not set is_unsynced. 2340 // Force a re-encrypt everything. Should not set is_unsynced.
2263 testing::Mock::VerifyAndClearExpectations(&observer_); 2341 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2264 EXPECT_CALL(observer_, OnEncryptionComplete()); 2342 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2265 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2343 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2344 sync_manager_.GetEncryptionHandler()->ReloadNigori();
2266 PumpLoop(); 2345 PumpLoop();
2267 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2346 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2268 } 2347 }
2269 2348
2270 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks 2349 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks
2271 // when we write the same data, but does set it when we write new data. 2350 // when we write the same data, but does set it when we write new data.
2272 TEST_F(SyncManagerTest, SetBookmarkTitle) { 2351 TEST_F(SyncManagerTest, SetBookmarkTitle) {
2273 std::string client_tag = "title"; 2352 std::string client_tag = "title";
2274 sync_pb::EntitySpecifics entity_specifics; 2353 sync_pb::EntitySpecifics entity_specifics;
2275 entity_specifics.mutable_bookmark()->set_url("url"); 2354 entity_specifics.mutable_bookmark()->set_url("url");
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 entity_specifics.mutable_bookmark()->set_url("url"); 2390 entity_specifics.mutable_bookmark()->set_url("url");
2312 entity_specifics.mutable_bookmark()->set_title("title"); 2391 entity_specifics.mutable_bookmark()->set_title("title");
2313 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, 2392 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag,
2314 BaseNode::GenerateSyncableHash(BOOKMARKS, 2393 BaseNode::GenerateSyncableHash(BOOKMARKS,
2315 client_tag), 2394 client_tag),
2316 entity_specifics); 2395 entity_specifics);
2317 // New node shouldn't start off unsynced. 2396 // New node shouldn't start off unsynced.
2318 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2397 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2319 2398
2320 // Encrypt the datatatype, should set is_unsynced. 2399 // Encrypt the datatatype, should set is_unsynced.
2321 EXPECT_CALL(observer_, 2400 EXPECT_CALL(encryption_observer_,
2322 OnEncryptedTypesChanged( 2401 OnEncryptedTypesChanged(
2323 HasModelTypes(ModelTypeSet::All()), true)); 2402 HasModelTypes(ModelTypeSet::All()), true));
2324 EXPECT_CALL(observer_, OnEncryptionComplete()); 2403 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2325 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2404 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2326 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2405 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2406 sync_manager_.GetEncryptionHandler()->ReloadNigori();
2327 PumpLoop(); 2407 PumpLoop();
2328 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2408 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2329 2409
2330 // Manually change to the same title. Should not set is_unsynced. 2410 // Manually change to the same title. Should not set is_unsynced.
2331 // NON_UNIQUE_NAME should be kEncryptedString. 2411 // NON_UNIQUE_NAME should be kEncryptedString.
2332 { 2412 {
2333 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2413 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2334 WriteNode node(&trans); 2414 WriteNode node(&trans);
2335 EXPECT_EQ(BaseNode::INIT_OK, 2415 EXPECT_EQ(BaseNode::INIT_OK,
2336 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2416 node.InitByClientTagLookup(BOOKMARKS, client_tag));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2406 MakeServerNode(sync_manager_.GetUserShare(), 2486 MakeServerNode(sync_manager_.GetUserShare(),
2407 PREFERENCES, 2487 PREFERENCES,
2408 client_tag, 2488 client_tag,
2409 BaseNode::GenerateSyncableHash(PREFERENCES, 2489 BaseNode::GenerateSyncableHash(PREFERENCES,
2410 client_tag), 2490 client_tag),
2411 entity_specifics); 2491 entity_specifics);
2412 // New node shouldn't start off unsynced. 2492 // New node shouldn't start off unsynced.
2413 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); 2493 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag));
2414 2494
2415 // Encrypt the datatatype, should set is_unsynced. 2495 // Encrypt the datatatype, should set is_unsynced.
2416 EXPECT_CALL(observer_, 2496 EXPECT_CALL(encryption_observer_,
2417 OnEncryptedTypesChanged( 2497 OnEncryptedTypesChanged(
2418 HasModelTypes(ModelTypeSet::All()), true)); 2498 HasModelTypes(ModelTypeSet::All()), true));
2419 EXPECT_CALL(observer_, OnEncryptionComplete()); 2499 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2420 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2500 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2421 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); 2501 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2502 sync_manager_.GetEncryptionHandler()->ReloadNigori();
2422 PumpLoop(); 2503 PumpLoop();
2423 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); 2504 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag));
2424 2505
2425 // Manually change to the same title. Should not set is_unsynced. 2506 // Manually change to the same title. Should not set is_unsynced.
2426 // NON_UNIQUE_NAME should be kEncryptedString. 2507 // NON_UNIQUE_NAME should be kEncryptedString.
2427 { 2508 {
2428 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2509 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2429 WriteNode node(&trans); 2510 WriteNode node(&trans);
2430 EXPECT_EQ(BaseNode::INIT_OK, 2511 EXPECT_EQ(BaseNode::INIT_OK,
2431 node.InitByClientTagLookup(PREFERENCES, client_tag)); 2512 node.InitByClientTagLookup(PREFERENCES, client_tag));
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2783 2864
2784 // Verify only the non-disabled types remain after cleanup. 2865 // Verify only the non-disabled types remain after cleanup.
2785 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2866 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2786 EXPECT_TRUE(new_enabled_types.Equals( 2867 EXPECT_TRUE(new_enabled_types.Equals(
2787 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2868 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2788 EXPECT_TRUE(disabled_types.Equals( 2869 EXPECT_TRUE(disabled_types.Equals(
2789 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2870 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2790 } 2871 }
2791 2872
2792 } // namespace 2873 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698