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

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

Powered by Google App Engine
This is Rietveld 408576698