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

Side by Side Diff: components/browser_sync/profile_sync_service_unittest.cc

Issue 2663783002: [Sync] Split encryption state and logic out of PSS and SBHI. (Closed)
Patch Set: Tweak comment. Created 3 years, 10 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
« no previous file with comments | « components/browser_sync/profile_sync_service.cc ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/browser_sync/profile_sync_service.h" 5 #include "components/browser_sync/profile_sync_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 DCHECK(!configure_called_.is_null()); 66 DCHECK(!configure_called_.is_null());
67 configure_called_.Run(reason); 67 configure_called_.Run(reason);
68 } 68 }
69 69
70 void ReenableType(syncer::ModelType type) override {} 70 void ReenableType(syncer::ModelType type) override {}
71 void ResetDataTypeErrors() override {} 71 void ResetDataTypeErrors() override {}
72 void PurgeForMigration(syncer::ModelTypeSet undesired_types, 72 void PurgeForMigration(syncer::ModelTypeSet undesired_types,
73 syncer::ConfigureReason reason) override {} 73 syncer::ConfigureReason reason) override {}
74 void Stop() override{}; 74 void Stop() override{};
75 ModelTypeSet GetActiveDataTypes() const override { return ModelTypeSet(); } 75 ModelTypeSet GetActiveDataTypes() const override { return ModelTypeSet(); }
76 bool IsNigoriEnabled() const override { return true; }
76 State state() const override { return syncer::DataTypeManager::CONFIGURED; } 77 State state() const override { return syncer::DataTypeManager::CONFIGURED; }
77 78
78 private: 79 private:
79 ConfigureCalled configure_called_; 80 ConfigureCalled configure_called_;
80 }; 81 };
81 82
82 ACTION_P(ReturnNewDataTypeManager, configure_called) { 83 ACTION_P(ReturnNewDataTypeManager, configure_called) {
83 return new FakeDataTypeManager(configure_called); 84 return new FakeDataTypeManager(configure_called);
84 } 85 }
85 86
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 syncer::SyncPrefs sync_prefs(prefs()); 244 syncer::SyncPrefs sync_prefs(prefs());
244 sync_prefs.SetFirstSyncTime(base::Time::Now()); 245 sync_prefs.SetFirstSyncTime(base::Time::Now());
245 sync_prefs.SetFirstSetupComplete(); 246 sync_prefs.SetFirstSetupComplete();
246 sync_prefs.SetKeepEverythingSynced(true); 247 sync_prefs.SetKeepEverythingSynced(true);
247 service_->Initialize(); 248 service_->Initialize();
248 } 249 }
249 250
250 void InitializeForFirstSync() { service_->Initialize(); } 251 void InitializeForFirstSync() { service_->Initialize(); }
251 252
252 void TriggerPassphraseRequired() { 253 void TriggerPassphraseRequired() {
253 service_->OnPassphraseRequired(syncer::REASON_DECRYPTION, 254 service_->GetEncryptionObserverForTest()->OnPassphraseRequired(
254 sync_pb::EncryptedData()); 255 syncer::REASON_DECRYPTION, sync_pb::EncryptedData());
255 } 256 }
256 257
257 void TriggerDataTypeStartRequest() { 258 void TriggerDataTypeStartRequest() {
258 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS); 259 service_->OnDataTypeRequestsSyncStartup(syncer::BOOKMARKS);
259 } 260 }
260 261
261 void OnConfigureCalled(syncer::ConfigureReason configure_reason) { 262 void OnConfigureCalled(syncer::ConfigureReason configure_reason) {
262 syncer::DataTypeManager::ConfigureResult result; 263 syncer::DataTypeManager::ConfigureResult result;
263 result.status = syncer::DataTypeManager::OK; 264 result.status = syncer::DataTypeManager::OK;
264 if (configure_reason == syncer::CONFIGURE_REASON_CATCH_UP) 265 if (configure_reason == syncer::CONFIGURE_REASON_CATCH_UP)
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 testing::Mock::VerifyAndClearExpectations(component_factory()); 727 testing::Mock::VerifyAndClearExpectations(component_factory());
727 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 728 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
728 syncer::DataTypeManager::ConfigureResult result; 729 syncer::DataTypeManager::ConfigureResult result;
729 result.status = syncer::DataTypeManager::OK; 730 result.status = syncer::DataTypeManager::OK;
730 service()->OnConfigureDone(result); 731 service()->OnConfigureDone(result);
731 732
732 // Simulate user entering encryption passphrase. Ensure that catch up 733 // Simulate user entering encryption passphrase. Ensure that catch up
733 // configure cycle is started (DTM::Configure is called with 734 // configure cycle is started (DTM::Configure is called with
734 // CONFIGURE_REASON_CATCH_UP). 735 // CONFIGURE_REASON_CATCH_UP).
735 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 736 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
736 service()->OnLocalSetPassphraseEncryption(nigori_state); 737 service()->GetEncryptionObserverForTest()->OnLocalSetPassphraseEncryption(
738 nigori_state);
737 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 739 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
738 EXPECT_TRUE(captured_callback.is_null()); 740 EXPECT_TRUE(captured_callback.is_null());
739 741
740 // Simulate configure successful. Ensure that SBH::ClearServerData is called. 742 // Simulate configure successful. Ensure that SBH::ClearServerData is called.
741 result.was_catch_up_configure = true; 743 result.was_catch_up_configure = true;
742 service()->OnConfigureDone(result); 744 service()->OnConfigureDone(result);
743 result.was_catch_up_configure = false; 745 result.was_catch_up_configure = false;
744 EXPECT_FALSE(captured_callback.is_null()); 746 EXPECT_FALSE(captured_callback.is_null());
745 747
746 // Once SBH::ClearServerData finishes successfully ensure that sync is 748 // Once SBH::ClearServerData finishes successfully ensure that sync is
(...skipping 24 matching lines...) Expand all
771 InitializeForNthSync(); 773 InitializeForNthSync();
772 testing::Mock::VerifyAndClearExpectations(component_factory()); 774 testing::Mock::VerifyAndClearExpectations(component_factory());
773 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 775 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
774 syncer::DataTypeManager::ConfigureResult result; 776 syncer::DataTypeManager::ConfigureResult result;
775 result.status = syncer::DataTypeManager::OK; 777 result.status = syncer::DataTypeManager::OK;
776 service()->OnConfigureDone(result); 778 service()->OnConfigureDone(result);
777 779
778 // Simulate user entering encryption passphrase. Ensure Configure was called 780 // Simulate user entering encryption passphrase. Ensure Configure was called
779 // but don't let it continue. 781 // but don't let it continue.
780 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 782 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
781 service()->OnLocalSetPassphraseEncryption(nigori_state); 783 service()->GetEncryptionObserverForTest()->OnLocalSetPassphraseEncryption(
784 nigori_state);
782 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 785 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
783 786
784 // Simulate browser restart. First configuration is a regular one. 787 // Simulate browser restart. First configuration is a regular one.
785 service()->Shutdown(); 788 service()->Shutdown();
786 syncer::SyncManager::ClearServerDataCallback captured_callback; 789 syncer::SyncManager::ClearServerDataCallback captured_callback;
787 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback); 790 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
788 ExpectDataTypeManagerCreation( 791 ExpectDataTypeManagerCreation(
789 1, GetRecordingConfigureCalledCallback(&configure_reason)); 792 1, GetRecordingConfigureCalledCallback(&configure_reason));
790 service()->RequestStart(); 793 service()->RequestStart();
791 testing::Mock::VerifyAndClearExpectations(component_factory()); 794 testing::Mock::VerifyAndClearExpectations(component_factory());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 switches::kSyncClearDataOnPassphraseEncryption); 826 switches::kSyncClearDataOnPassphraseEncryption);
824 IssueTestTokens(); 827 IssueTestTokens();
825 CreateService(ProfileSyncService::AUTO_START); 828 CreateService(ProfileSyncService::AUTO_START);
826 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback); 829 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
827 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 830 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
828 InitializeForNthSync(); 831 InitializeForNthSync();
829 testing::Mock::VerifyAndClearExpectations(component_factory()); 832 testing::Mock::VerifyAndClearExpectations(component_factory());
830 833
831 // Simulate user entering encryption passphrase. 834 // Simulate user entering encryption passphrase.
832 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 835 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
833 service()->OnLocalSetPassphraseEncryption(nigori_state); 836 service()->GetEncryptionObserverForTest()->OnLocalSetPassphraseEncryption(
837 nigori_state);
834 EXPECT_FALSE(captured_callback.is_null()); 838 EXPECT_FALSE(captured_callback.is_null());
835 captured_callback.Reset(); 839 captured_callback.Reset();
836 840
837 // Simulate browser restart. First configuration is a regular one. 841 // Simulate browser restart. First configuration is a regular one.
838 service()->Shutdown(); 842 service()->Shutdown();
839 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback); 843 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
840 ExpectDataTypeManagerCreation( 844 ExpectDataTypeManagerCreation(
841 1, GetRecordingConfigureCalledCallback(&configure_reason)); 845 1, GetRecordingConfigureCalledCallback(&configure_reason));
842 service()->RequestStart(); 846 service()->RequestStart();
843 testing::Mock::VerifyAndClearExpectations(component_factory()); 847 testing::Mock::VerifyAndClearExpectations(component_factory());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 // Progress the controller to RUNNING first, which is how the service 969 // Progress the controller to RUNNING first, which is how the service
966 // determines whether a type is enabled. 970 // determines whether a type is enabled.
967 controller->StartAssociating(base::Bind(&DoNothing)); 971 controller->StartAssociating(base::Bind(&DoNothing));
968 controller->FinishStart(DataTypeController::OK_FIRST_RUN); 972 controller->FinishStart(DataTypeController::OK_FIRST_RUN);
969 service()->RegisterDataTypeController(std::move(controller)); 973 service()->RegisterDataTypeController(std::move(controller));
970 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); 974 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate());
971 } 975 }
972 976
973 } // namespace 977 } // namespace
974 } // namespace browser_sync 978 } // namespace browser_sync
OLDNEW
« no previous file with comments | « components/browser_sync/profile_sync_service.cc ('k') | components/sync/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698