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

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

Issue 2770933007: [Sync] Replace ClearServerDataCallback with Closure. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/sync/driver/glue/sync_backend_host_core.h » ('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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 122
123 private: 123 private:
124 std::vector<bool>* delete_dir_param_; 124 std::vector<bool>* delete_dir_param_;
125 }; 125 };
126 126
127 // FakeSyncEngine that calls an external callback when ClearServerData is 127 // FakeSyncEngine that calls an external callback when ClearServerData is
128 // called. 128 // called.
129 class SyncEngineCaptureClearServerData : public FakeSyncEngine { 129 class SyncEngineCaptureClearServerData : public FakeSyncEngine {
130 public: 130 public:
131 using ClearServerDataCalled = 131 using ClearServerDataCalled = base::Callback<void(const base::Closure&)>;
132 base::Callback<void(const syncer::SyncManager::ClearServerDataCallback&)>;
133 explicit SyncEngineCaptureClearServerData( 132 explicit SyncEngineCaptureClearServerData(
134 const ClearServerDataCalled& clear_server_data_called) 133 const ClearServerDataCalled& clear_server_data_called)
135 : clear_server_data_called_(clear_server_data_called) {} 134 : clear_server_data_called_(clear_server_data_called) {}
136 135
137 void ClearServerData( 136 void ClearServerData(const base::Closure& callback) override {
138 const syncer::SyncManager::ClearServerDataCallback& callback) override {
139 clear_server_data_called_.Run(callback); 137 clear_server_data_called_.Run(callback);
140 } 138 }
141 139
142 private: 140 private:
143 ClearServerDataCalled clear_server_data_called_; 141 ClearServerDataCalled clear_server_data_called_;
144 }; 142 };
145 143
146 ACTION(ReturnNewFakeSyncEngine) { 144 ACTION(ReturnNewFakeSyncEngine) {
147 return new FakeSyncEngine(); 145 return new FakeSyncEngine();
148 } 146 }
149 147
150 ACTION(ReturnNewSyncEngineNoReturn) { 148 ACTION(ReturnNewSyncEngineNoReturn) {
151 return new SyncEngineNoReturn(); 149 return new SyncEngineNoReturn();
152 } 150 }
153 151
154 ACTION_P(ReturnNewMockHostCollectDeleteDirParam, delete_dir_param) { 152 ACTION_P(ReturnNewMockHostCollectDeleteDirParam, delete_dir_param) {
155 return new FakeSyncEngineCollectDeleteDirParam(delete_dir_param); 153 return new FakeSyncEngineCollectDeleteDirParam(delete_dir_param);
156 } 154 }
157 155
158 void OnClearServerDataCalled( 156 void OnClearServerDataCalled(base::Closure* captured_callback,
159 syncer::SyncManager::ClearServerDataCallback* captured_callback, 157 const base::Closure& callback) {
160 const syncer::SyncManager::ClearServerDataCallback& callback) {
161 *captured_callback = callback; 158 *captured_callback = callback;
162 } 159 }
163 160
164 ACTION_P(ReturnNewMockHostCaptureClearServerData, captured_callback) { 161 ACTION_P(ReturnNewMockHostCaptureClearServerData, captured_callback) {
165 return new SyncEngineCaptureClearServerData(base::Bind( 162 return new SyncEngineCaptureClearServerData(base::Bind(
166 &OnClearServerDataCalled, base::Unretained(captured_callback))); 163 &OnClearServerDataCalled, base::Unretained(captured_callback)));
167 } 164 }
168 165
169 void DoNothing(DataTypeController::ConfigureResult ignored1, 166 void DoNothing(DataTypeController::ConfigureResult ignored1,
170 const SyncMergeResult& ignored2, 167 const SyncMergeResult& ignored2,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 void ExpectSyncEngineCreationCollectDeleteDir( 295 void ExpectSyncEngineCreationCollectDeleteDir(
299 int times, 296 int times,
300 std::vector<bool>* delete_dir_param) { 297 std::vector<bool>* delete_dir_param) {
301 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _)) 298 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
302 .Times(times) 299 .Times(times)
303 .WillRepeatedly( 300 .WillRepeatedly(
304 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); 301 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param));
305 } 302 }
306 303
307 void ExpectSyncEngineCreationCaptureClearServerData( 304 void ExpectSyncEngineCreationCaptureClearServerData(
308 syncer::SyncManager::ClearServerDataCallback* captured_callback) { 305 base::Closure* captured_callback) {
309 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _)) 306 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
310 .Times(1) 307 .Times(1)
311 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback)); 308 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback));
312 } 309 }
313 310
314 void PrepareDelayedInitSyncEngine() { 311 void PrepareDelayedInitSyncEngine() {
315 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _)) 312 EXPECT_CALL(*component_factory_, CreateSyncEngine(_, _, _, _))
316 .WillOnce(ReturnNewSyncEngineNoReturn()); 313 .WillOnce(ReturnNewSyncEngineNoReturn());
317 } 314 }
318 315
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 695
699 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync 696 // Verify that OnLocalSetPassphraseEncryption triggers catch up configure sync
700 // cycle, calls ClearServerData, shuts down and restarts sync. 697 // cycle, calls ClearServerData, shuts down and restarts sync.
701 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) { 698 TEST_F(ProfileSyncServiceTest, OnLocalSetPassphraseEncryption) {
702 base::test::ScopedFeatureList scoped_feature_list; 699 base::test::ScopedFeatureList scoped_feature_list;
703 scoped_feature_list.InitAndEnableFeature( 700 scoped_feature_list.InitAndEnableFeature(
704 switches::kSyncClearDataOnPassphraseEncryption); 701 switches::kSyncClearDataOnPassphraseEncryption);
705 IssueTestTokens(); 702 IssueTestTokens();
706 CreateService(ProfileSyncService::AUTO_START); 703 CreateService(ProfileSyncService::AUTO_START);
707 704
708 syncer::SyncManager::ClearServerDataCallback captured_callback; 705 base::Closure captured_callback;
709 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 706 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
710 707
711 // Initialize sync, ensure that both DataTypeManager and SyncEngine are 708 // Initialize sync, ensure that both DataTypeManager and SyncEngine are
712 // initialized and DTM::Configure is called with 709 // initialized and DTM::Configure is called with
713 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE. 710 // CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE.
714 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback); 711 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
715 ExpectDataTypeManagerCreation( 712 ExpectDataTypeManagerCreation(
716 1, GetRecordingConfigureCalledCallback(&configure_reason)); 713 1, GetRecordingConfigureCalledCallback(&configure_reason));
717 InitializeForNthSync(); 714 InitializeForNthSync();
718 EXPECT_TRUE(service()->IsSyncActive()); 715 EXPECT_TRUE(service()->IsSyncActive());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 768
772 // Simulate user entering encryption passphrase. Ensure Configure was called 769 // Simulate user entering encryption passphrase. Ensure Configure was called
773 // but don't let it continue. 770 // but don't let it continue.
774 const syncer::SyncEncryptionHandler::NigoriState nigori_state; 771 const syncer::SyncEncryptionHandler::NigoriState nigori_state;
775 service()->GetEncryptionObserverForTest()->OnLocalSetPassphraseEncryption( 772 service()->GetEncryptionObserverForTest()->OnLocalSetPassphraseEncryption(
776 nigori_state); 773 nigori_state);
777 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason); 774 EXPECT_EQ(syncer::CONFIGURE_REASON_CATCH_UP, configure_reason);
778 775
779 // Simulate browser restart. First configuration is a regular one. 776 // Simulate browser restart. First configuration is a regular one.
780 service()->Shutdown(); 777 service()->Shutdown();
781 syncer::SyncManager::ClearServerDataCallback captured_callback; 778 base::Closure captured_callback;
782 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback); 779 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
783 ExpectDataTypeManagerCreation( 780 ExpectDataTypeManagerCreation(
784 1, GetRecordingConfigureCalledCallback(&configure_reason)); 781 1, GetRecordingConfigureCalledCallback(&configure_reason));
785 service()->RequestStart(); 782 service()->RequestStart();
786 testing::Mock::VerifyAndClearExpectations(component_factory()); 783 testing::Mock::VerifyAndClearExpectations(component_factory());
787 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 784 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
788 EXPECT_TRUE(captured_callback.is_null()); 785 EXPECT_TRUE(captured_callback.is_null());
789 786
790 // Simulate configure successful. This time it should be catch up. 787 // Simulate configure successful. This time it should be catch up.
791 service()->OnConfigureDone(result); 788 service()->OnConfigureDone(result);
(...skipping 12 matching lines...) Expand all
804 1, GetRecordingConfigureCalledCallback(&configure_reason)); 801 1, GetRecordingConfigureCalledCallback(&configure_reason));
805 captured_callback.Run(); 802 captured_callback.Run();
806 testing::Mock::VerifyAndClearExpectations(component_factory()); 803 testing::Mock::VerifyAndClearExpectations(component_factory());
807 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason); 804 EXPECT_EQ(syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE, configure_reason);
808 } 805 }
809 806
810 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets 807 // Verify that if after OnLocalSetPassphraseEncryption ClearServerData gets
811 // interrupted, transition again from catch up sync cycle after browser restart. 808 // interrupted, transition again from catch up sync cycle after browser restart.
812 TEST_F(ProfileSyncServiceTest, 809 TEST_F(ProfileSyncServiceTest,
813 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) { 810 OnLocalSetPassphraseEncryption_RestartDuringClearServerData) {
814 syncer::SyncManager::ClearServerDataCallback captured_callback; 811 base::Closure captured_callback;
815 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN; 812 syncer::ConfigureReason configure_reason = syncer::CONFIGURE_REASON_UNKNOWN;
816 base::test::ScopedFeatureList scoped_feature_list; 813 base::test::ScopedFeatureList scoped_feature_list;
817 scoped_feature_list.InitAndEnableFeature( 814 scoped_feature_list.InitAndEnableFeature(
818 switches::kSyncClearDataOnPassphraseEncryption); 815 switches::kSyncClearDataOnPassphraseEncryption);
819 IssueTestTokens(); 816 IssueTestTokens();
820 CreateService(ProfileSyncService::AUTO_START); 817 CreateService(ProfileSyncService::AUTO_START);
821 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback); 818 ExpectSyncEngineCreationCaptureClearServerData(&captured_callback);
822 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback()); 819 ExpectDataTypeManagerCreation(1, GetDefaultConfigureCalledCallback());
823 InitializeForNthSync(); 820 InitializeForNthSync();
824 testing::Mock::VerifyAndClearExpectations(component_factory()); 821 testing::Mock::VerifyAndClearExpectations(component_factory());
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 // Progress the controller to RUNNING first, which is how the service 958 // Progress the controller to RUNNING first, which is how the service
962 // determines whether a type is enabled. 959 // determines whether a type is enabled.
963 controller->StartAssociating(base::Bind(&DoNothing)); 960 controller->StartAssociating(base::Bind(&DoNothing));
964 controller->FinishStart(DataTypeController::OK_FIRST_RUN); 961 controller->FinishStart(DataTypeController::OK_FIRST_RUN);
965 service()->RegisterDataTypeController(std::move(controller)); 962 service()->RegisterDataTypeController(std::move(controller));
966 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate()); 963 EXPECT_NE(nullptr, service()->GetOpenTabsUIDelegate());
967 } 964 }
968 965
969 } // namespace 966 } // namespace
970 } // namespace browser_sync 967 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | components/sync/driver/glue/sync_backend_host_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698