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

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

Powered by Google App Engine
This is Rietveld 408576698