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

Side by Side Diff: components/sync/driver/async_directory_type_controller_unittest.cc

Issue 1302233003: Replace gmock's deprecated SetArgumentPointee with SetArgPointee. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2017 Created 3 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/sync/driver/async_directory_type_controller.h" 5 #include "components/sync/driver/async_directory_type_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 26 matching lines...) Expand all
37 37
38 namespace { 38 namespace {
39 39
40 using base::WaitableEvent; 40 using base::WaitableEvent;
41 using testing::_; 41 using testing::_;
42 using testing::AtLeast; 42 using testing::AtLeast;
43 using testing::DoAll; 43 using testing::DoAll;
44 using testing::InvokeWithoutArgs; 44 using testing::InvokeWithoutArgs;
45 using testing::Mock; 45 using testing::Mock;
46 using testing::Return; 46 using testing::Return;
47 using testing::SetArgumentPointee; 47 using testing::SetArgPointee;
48 using testing::StrictMock; 48 using testing::StrictMock;
49 49
50 const ModelType kType = AUTOFILL_PROFILE; 50 const ModelType kType = AUTOFILL_PROFILE;
51 51
52 ACTION_P(WaitOnEvent, event) { 52 ACTION_P(WaitOnEvent, event) {
53 event->Wait(); 53 event->Wait();
54 } 54 }
55 55
56 ACTION_P(SignalEvent, event) { 56 ACTION_P(SignalEvent, event) {
57 event->Signal(); 57 event->Signal();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 void SetStartExpectations() { 219 void SetStartExpectations() {
220 EXPECT_CALL(*dtc_mock_.get(), StartModels()).WillOnce(Return(true)); 220 EXPECT_CALL(*dtc_mock_.get(), StartModels()).WillOnce(Return(true));
221 EXPECT_CALL(model_load_callback_, Run(_, _)); 221 EXPECT_CALL(model_load_callback_, Run(_, _));
222 } 222 }
223 223
224 void SetAssociateExpectations() { 224 void SetAssociateExpectations() {
225 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr()); 225 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr());
226 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary()) 226 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary())
227 .WillOnce(Return(true)); 227 .WillOnce(Return(true));
228 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_)) 228 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_))
229 .WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); 229 .WillOnce(DoAll(SetArgPointee<0>(true), Return(true)));
230 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _)) 230 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _))
231 .WillOnce(Return(SyncError())); 231 .WillOnce(Return(SyncError()));
232 EXPECT_CALL(*change_processor_.get(), GetSyncCount()).WillOnce(Return(0)); 232 EXPECT_CALL(*change_processor_.get(), GetSyncCount()).WillOnce(Return(0));
233 EXPECT_CALL(*change_processor_.get(), RecordAssociationTime(_)); 233 EXPECT_CALL(*change_processor_.get(), RecordAssociationTime(_));
234 } 234 }
235 235
236 void SetActivateExpectations(DataTypeController::ConfigureResult result) { 236 void SetActivateExpectations(DataTypeController::ConfigureResult result) {
237 EXPECT_CALL(start_callback_, Run(result, _, _)); 237 EXPECT_CALL(start_callback_, Run(result, _, _));
238 } 238 }
239 239
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 WaitForDTC(); 279 WaitForDTC();
280 EXPECT_EQ(DataTypeController::RUNNING, non_ui_dtc_->state()); 280 EXPECT_EQ(DataTypeController::RUNNING, non_ui_dtc_->state());
281 } 281 }
282 282
283 TEST_F(SyncAsyncDirectoryTypeControllerTest, StartFirstRun) { 283 TEST_F(SyncAsyncDirectoryTypeControllerTest, StartFirstRun) {
284 SetStartExpectations(); 284 SetStartExpectations();
285 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr()); 285 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr());
286 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary()) 286 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary())
287 .WillOnce(Return(true)); 287 .WillOnce(Return(true));
288 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_)) 288 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_))
289 .WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true))); 289 .WillOnce(DoAll(SetArgPointee<0>(false), Return(true)));
290 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _)) 290 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _))
291 .WillOnce(Return(SyncError())); 291 .WillOnce(Return(SyncError()));
292 EXPECT_CALL(*change_processor_.get(), RecordAssociationTime(_)); 292 EXPECT_CALL(*change_processor_.get(), RecordAssociationTime(_));
293 SetActivateExpectations(DataTypeController::OK_FIRST_RUN); 293 SetActivateExpectations(DataTypeController::OK_FIRST_RUN);
294 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state()); 294 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state());
295 Start(); 295 Start();
296 WaitForDTC(); 296 WaitForDTC();
297 EXPECT_EQ(DataTypeController::RUNNING, non_ui_dtc_->state()); 297 EXPECT_EQ(DataTypeController::RUNNING, non_ui_dtc_->state());
298 } 298 }
299 299
(...skipping 13 matching lines...) Expand all
313 313
314 // Start the DTC and have MergeDataAndStartSyncing() return an error. 314 // Start the DTC and have MergeDataAndStartSyncing() return an error.
315 // The DTC should become disabled, and the DTC should still stop 315 // The DTC should become disabled, and the DTC should still stop
316 // cleanly. 316 // cleanly.
317 TEST_F(SyncAsyncDirectoryTypeControllerTest, StartAssociationFailed) { 317 TEST_F(SyncAsyncDirectoryTypeControllerTest, StartAssociationFailed) {
318 SetStartExpectations(); 318 SetStartExpectations();
319 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr()); 319 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr());
320 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary()) 320 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary())
321 .WillOnce(Return(true)); 321 .WillOnce(Return(true));
322 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_)) 322 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_))
323 .WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); 323 .WillOnce(DoAll(SetArgPointee<0>(true), Return(true)));
324 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _)) 324 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _))
325 .WillOnce(Return(SyncError())); 325 .WillOnce(Return(SyncError()));
326 EXPECT_CALL(*change_processor_.get(), RecordAssociationTime(_)); 326 EXPECT_CALL(*change_processor_.get(), RecordAssociationTime(_));
327 SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); 327 SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED);
328 // Set up association to fail with an association failed error. 328 // Set up association to fail with an association failed error.
329 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state()); 329 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state());
330 syncable_service_.set_merge_data_and_start_syncing_error(SyncError( 330 syncable_service_.set_merge_data_and_start_syncing_error(SyncError(
331 FROM_HERE, SyncError::DATATYPE_ERROR, "Sync Error", non_ui_dtc_->type())); 331 FROM_HERE, SyncError::DATATYPE_ERROR, "Sync Error", non_ui_dtc_->type()));
332 Start(); 332 Start();
333 WaitForDTC(); 333 WaitForDTC();
334 EXPECT_EQ(DataTypeController::DISABLED, non_ui_dtc_->state()); 334 EXPECT_EQ(DataTypeController::DISABLED, non_ui_dtc_->state());
335 non_ui_dtc_->Stop(); 335 non_ui_dtc_->Stop();
336 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state()); 336 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state());
337 } 337 }
338 338
339 TEST_F(SyncAsyncDirectoryTypeControllerTest, 339 TEST_F(SyncAsyncDirectoryTypeControllerTest,
340 StartAssociationTriggersUnrecoverableError) { 340 StartAssociationTriggersUnrecoverableError) {
341 SetStartExpectations(); 341 SetStartExpectations();
342 SetStartFailExpectations(DataTypeController::UNRECOVERABLE_ERROR); 342 SetStartFailExpectations(DataTypeController::UNRECOVERABLE_ERROR);
343 // Set up association to fail with an unrecoverable error. 343 // Set up association to fail with an unrecoverable error.
344 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr()); 344 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr());
345 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary()) 345 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary())
346 .WillRepeatedly(Return(true)); 346 .WillRepeatedly(Return(true));
347 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_)) 347 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_))
348 .WillRepeatedly(DoAll(SetArgumentPointee<0>(false), Return(false))); 348 .WillRepeatedly(DoAll(SetArgPointee<0>(false), Return(false)));
349 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state()); 349 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state());
350 Start(); 350 Start();
351 WaitForDTC(); 351 WaitForDTC();
352 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state()); 352 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state());
353 } 353 }
354 354
355 TEST_F(SyncAsyncDirectoryTypeControllerTest, StartAssociationCryptoNotReady) { 355 TEST_F(SyncAsyncDirectoryTypeControllerTest, StartAssociationCryptoNotReady) {
356 SetStartExpectations(); 356 SetStartExpectations();
357 SetStartFailExpectations(DataTypeController::NEEDS_CRYPTO); 357 SetStartFailExpectations(DataTypeController::NEEDS_CRYPTO);
358 // Set up association to fail with a NEEDS_CRYPTO error. 358 // Set up association to fail with a NEEDS_CRYPTO error.
(...skipping 15 matching lines...) Expand all
374 WaitableEvent pause_db_thread( 374 WaitableEvent pause_db_thread(
375 base::WaitableEvent::ResetPolicy::AUTOMATIC, 375 base::WaitableEvent::ResetPolicy::AUTOMATIC,
376 base::WaitableEvent::InitialState::NOT_SIGNALED); 376 base::WaitableEvent::InitialState::NOT_SIGNALED);
377 377
378 SetStartExpectations(); 378 SetStartExpectations();
379 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr()); 379 change_processor_->SetConnectReturn(syncable_service_.AsWeakPtr());
380 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary()) 380 EXPECT_CALL(*change_processor_.get(), CryptoReadyIfNecessary())
381 .WillOnce(Return(true)); 381 .WillOnce(Return(true));
382 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_)) 382 EXPECT_CALL(*change_processor_.get(), SyncModelHasUserCreatedNodes(_))
383 .WillOnce(DoAll(SignalEvent(&wait_for_db_thread_pause), 383 .WillOnce(DoAll(SignalEvent(&wait_for_db_thread_pause),
384 WaitOnEvent(&pause_db_thread), 384 WaitOnEvent(&pause_db_thread), SetArgPointee<0>(true),
385 SetArgumentPointee<0>(true), Return(true))); 385 Return(true)));
386 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _)) 386 EXPECT_CALL(*change_processor_.get(), GetAllSyncDataReturnError(_, _))
387 .WillOnce(Return(SyncError(FROM_HERE, SyncError::DATATYPE_ERROR, 387 .WillOnce(Return(SyncError(FROM_HERE, SyncError::DATATYPE_ERROR,
388 "Disconnected.", kType))); 388 "Disconnected.", kType)));
389 EXPECT_CALL(*dtc_mock_.get(), StopModels()); 389 EXPECT_CALL(*dtc_mock_.get(), StopModels());
390 EXPECT_CALL(*change_processor_.get(), Disconnect()) 390 EXPECT_CALL(*change_processor_.get(), Disconnect())
391 .WillOnce(DoAll(SignalEvent(&pause_db_thread), Return(true))); 391 .WillOnce(DoAll(SignalEvent(&pause_db_thread), Return(true)));
392 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state()); 392 EXPECT_EQ(DataTypeController::NOT_RUNNING, non_ui_dtc_->state());
393 Start(); 393 Start();
394 wait_for_db_thread_pause.Wait(); 394 wait_for_db_thread_pause.Wait();
395 non_ui_dtc_->Stop(); 395 non_ui_dtc_->Stop();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 backend_thread_.task_runner()->PostTask( 473 backend_thread_.task_runner()->PostTask(
474 FROM_HERE, 474 FROM_HERE,
475 base::Bind(&DataTypeErrorHandler::OnUnrecoverableError, 475 base::Bind(&DataTypeErrorHandler::OnUnrecoverableError,
476 base::Passed(non_ui_dtc_->CreateErrorHandler()), error)); 476 base::Passed(non_ui_dtc_->CreateErrorHandler()), error));
477 WaitForDTC(); 477 WaitForDTC();
478 } 478 }
479 479
480 } // namespace 480 } // namespace
481 481
482 } // namespace syncer 482 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698