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

Side by Side Diff: chrome/browser/sync/glue/new_non_frontend_data_type_controller_unittest.cc

Issue 10662035: [Sync] Put everything in sync/api into csync namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comments Created 8 years, 5 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 #include "chrome/browser/sync/glue/new_non_frontend_data_type_controller.h" 5 #include "chrome/browser/sync/glue/new_non_frontend_data_type_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 void SetAssociateExpectations() { 200 void SetAssociateExpectations() {
201 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)). 201 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)).
202 WillOnce(GetWeakPtrToSyncableService(&syncable_service_)); 202 WillOnce(GetWeakPtrToSyncableService(&syncable_service_));
203 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()). 203 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()).
204 WillOnce(Return(true)); 204 WillOnce(Return(true));
205 EXPECT_CALL(*change_processor_, ActivateDataType(_)); 205 EXPECT_CALL(*change_processor_, ActivateDataType(_));
206 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)). 206 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)).
207 WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); 207 WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true)));
208 EXPECT_CALL(*change_processor_, GetSyncData(_)). 208 EXPECT_CALL(*change_processor_, GetSyncData(_)).
209 WillOnce(Return(SyncError())); 209 WillOnce(Return(csync::SyncError()));
210 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); 210 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_));
211 } 211 }
212 212
213 void SetActivateExpectations(DataTypeController::StartResult result) { 213 void SetActivateExpectations(DataTypeController::StartResult result) {
214 EXPECT_CALL(start_callback_, Run(result,_)); 214 EXPECT_CALL(start_callback_, Run(result,_));
215 } 215 }
216 216
217 void SetStopExpectations() { 217 void SetStopExpectations() {
218 EXPECT_CALL(*dtc_mock_, StopModels()); 218 EXPECT_CALL(*dtc_mock_, StopModels());
219 EXPECT_CALL(*change_processor_, Disconnect()).WillOnce(Return(true)); 219 EXPECT_CALL(*change_processor_, Disconnect()).WillOnce(Return(true));
(...skipping 23 matching lines...) Expand all
243 243
244 MessageLoopForUI message_loop_; 244 MessageLoopForUI message_loop_;
245 content::TestBrowserThread ui_thread_; 245 content::TestBrowserThread ui_thread_;
246 content::TestBrowserThread db_thread_; 246 content::TestBrowserThread db_thread_;
247 ProfileMock profile_; 247 ProfileMock profile_;
248 scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_; 248 scoped_ptr<ProfileSyncComponentsFactoryMock> profile_sync_factory_;
249 StrictMock<ProfileSyncServiceMock> service_; 249 StrictMock<ProfileSyncServiceMock> service_;
250 StartCallbackMock start_callback_; 250 StartCallbackMock start_callback_;
251 ModelLoadCallbackMock model_load_callback_; 251 ModelLoadCallbackMock model_load_callback_;
252 // Must be destroyed after new_non_frontend_dtc_. 252 // Must be destroyed after new_non_frontend_dtc_.
253 FakeSyncableService syncable_service_; 253 csync::FakeSyncableService syncable_service_;
254 scoped_refptr<NewNonFrontendDataTypeControllerFake> new_non_frontend_dtc_; 254 scoped_refptr<NewNonFrontendDataTypeControllerFake> new_non_frontend_dtc_;
255 scoped_refptr<NewNonFrontendDataTypeControllerMock> dtc_mock_; 255 scoped_refptr<NewNonFrontendDataTypeControllerMock> dtc_mock_;
256 scoped_refptr<SharedChangeProcessorMock> change_processor_; 256 scoped_refptr<SharedChangeProcessorMock> change_processor_;
257 scoped_ptr<SyncChangeProcessor> saved_change_processor_; 257 scoped_ptr<csync::SyncChangeProcessor> saved_change_processor_;
258 }; 258 };
259 259
260 TEST_F(SyncNewNonFrontendDataTypeControllerTest, StartOk) { 260 TEST_F(SyncNewNonFrontendDataTypeControllerTest, StartOk) {
261 SetStartExpectations(); 261 SetStartExpectations();
262 SetAssociateExpectations(); 262 SetAssociateExpectations();
263 SetActivateExpectations(DataTypeController::OK); 263 SetActivateExpectations(DataTypeController::OK);
264 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 264 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
265 Start(); 265 Start();
266 WaitForDTC(); 266 WaitForDTC();
267 EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state()); 267 EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state());
268 } 268 }
269 269
270 TEST_F(SyncNewNonFrontendDataTypeControllerTest, StartFirstRun) { 270 TEST_F(SyncNewNonFrontendDataTypeControllerTest, StartFirstRun) {
271 SetStartExpectations(); 271 SetStartExpectations();
272 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)). 272 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)).
273 WillOnce(GetWeakPtrToSyncableService(&syncable_service_)); 273 WillOnce(GetWeakPtrToSyncableService(&syncable_service_));
274 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()). 274 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()).
275 WillOnce(Return(true)); 275 WillOnce(Return(true));
276 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)). 276 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)).
277 WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true))); 277 WillOnce(DoAll(SetArgumentPointee<0>(false), Return(true)));
278 EXPECT_CALL(*change_processor_, GetSyncData(_)). 278 EXPECT_CALL(*change_processor_, GetSyncData(_)).
279 WillOnce(Return(SyncError())); 279 WillOnce(Return(csync::SyncError()));
280 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); 280 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_));
281 SetActivateExpectations(DataTypeController::OK_FIRST_RUN); 281 SetActivateExpectations(DataTypeController::OK_FIRST_RUN);
282 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 282 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
283 Start(); 283 Start();
284 WaitForDTC(); 284 WaitForDTC();
285 EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state()); 285 EXPECT_EQ(DataTypeController::RUNNING, new_non_frontend_dtc_->state());
286 } 286 }
287 287
288 // Start the DTC and have StartModels() return false. Then, stop the 288 // Start the DTC and have StartModels() return false. Then, stop the
289 // DTC without finishing model startup. It should stop cleanly. 289 // DTC without finishing model startup. It should stop cleanly.
(...skipping 19 matching lines...) Expand all
309 // cleanly. 309 // cleanly.
310 TEST_F(SyncNewNonFrontendDataTypeControllerTest, StartAssociationFailed) { 310 TEST_F(SyncNewNonFrontendDataTypeControllerTest, StartAssociationFailed) {
311 SetStartExpectations(); 311 SetStartExpectations();
312 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)). 312 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)).
313 WillOnce(GetWeakPtrToSyncableService(&syncable_service_)); 313 WillOnce(GetWeakPtrToSyncableService(&syncable_service_));
314 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()). 314 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()).
315 WillOnce(Return(true)); 315 WillOnce(Return(true));
316 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)). 316 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)).
317 WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true))); 317 WillOnce(DoAll(SetArgumentPointee<0>(true), Return(true)));
318 EXPECT_CALL(*change_processor_, GetSyncData(_)). 318 EXPECT_CALL(*change_processor_, GetSyncData(_)).
319 WillOnce(Return(SyncError())); 319 WillOnce(Return(csync::SyncError()));
320 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_)); 320 EXPECT_CALL(*dtc_mock_, RecordAssociationTime(_));
321 SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED); 321 SetStartFailExpectations(DataTypeController::ASSOCIATION_FAILED);
322 // Set up association to fail with an association failed error. 322 // Set up association to fail with an association failed error.
323 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 323 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
324 syncable_service_.set_merge_data_and_start_syncing_error( 324 syncable_service_.set_merge_data_and_start_syncing_error(
325 SyncError(FROM_HERE, "Sync Error", new_non_frontend_dtc_->type())); 325 csync::SyncError(FROM_HERE, "Sync Error", new_non_frontend_dtc_->type()));
326 Start(); 326 Start();
327 WaitForDTC(); 327 WaitForDTC();
328 EXPECT_EQ(DataTypeController::DISABLED, new_non_frontend_dtc_->state()); 328 EXPECT_EQ(DataTypeController::DISABLED, new_non_frontend_dtc_->state());
329 new_non_frontend_dtc_->Stop(); 329 new_non_frontend_dtc_->Stop();
330 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 330 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
331 } 331 }
332 332
333 TEST_F(SyncNewNonFrontendDataTypeControllerTest, 333 TEST_F(SyncNewNonFrontendDataTypeControllerTest,
334 StartAssociationTriggersUnrecoverableError) { 334 StartAssociationTriggersUnrecoverableError) {
335 SetStartExpectations(); 335 SetStartExpectations();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 WillOnce(GetWeakPtrToSyncableService(&syncable_service_)); 374 WillOnce(GetWeakPtrToSyncableService(&syncable_service_));
375 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()). 375 EXPECT_CALL(*change_processor_, CryptoReadyIfNecessary()).
376 WillOnce(Return(true)); 376 WillOnce(Return(true));
377 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)). 377 EXPECT_CALL(*change_processor_, SyncModelHasUserCreatedNodes(_)).
378 WillOnce(DoAll( 378 WillOnce(DoAll(
379 SignalEvent(&wait_for_db_thread_pause), 379 SignalEvent(&wait_for_db_thread_pause),
380 WaitOnEvent(&pause_db_thread), 380 WaitOnEvent(&pause_db_thread),
381 SetArgumentPointee<0>(true), 381 SetArgumentPointee<0>(true),
382 Return(true))); 382 Return(true)));
383 EXPECT_CALL(*change_processor_, GetSyncData(_)). 383 EXPECT_CALL(*change_processor_, GetSyncData(_)).
384 WillOnce(Return(SyncError(FROM_HERE, "Disconnected.", AUTOFILL_PROFILE))); 384 WillOnce(
385 Return(
386 csync::SyncError(FROM_HERE, "Disconnected.", AUTOFILL_PROFILE)));
385 EXPECT_CALL(*change_processor_, Disconnect()). 387 EXPECT_CALL(*change_processor_, Disconnect()).
386 WillOnce(DoAll(SignalEvent(&pause_db_thread), Return(true))); 388 WillOnce(DoAll(SignalEvent(&pause_db_thread), Return(true)));
387 EXPECT_CALL(service_, DeactivateDataType(_)); 389 EXPECT_CALL(service_, DeactivateDataType(_));
388 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 390 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
389 Start(); 391 Start();
390 wait_for_db_thread_pause.Wait(); 392 wait_for_db_thread_pause.Wait();
391 new_non_frontend_dtc_->Stop(); 393 new_non_frontend_dtc_->Stop();
392 WaitForDTC(); 394 WaitForDTC();
393 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 395 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
394 } 396 }
(...skipping 16 matching lines...) Expand all
411 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 413 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
412 Start(); 414 Start();
413 new_non_frontend_dtc_->Stop(); 415 new_non_frontend_dtc_->Stop();
414 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 416 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
415 Mock::VerifyAndClearExpectations(&profile_sync_factory_); 417 Mock::VerifyAndClearExpectations(&profile_sync_factory_);
416 Mock::VerifyAndClearExpectations(&service_); 418 Mock::VerifyAndClearExpectations(&service_);
417 Mock::VerifyAndClearExpectations(change_processor_); 419 Mock::VerifyAndClearExpectations(change_processor_);
418 Mock::VerifyAndClearExpectations(dtc_mock_); 420 Mock::VerifyAndClearExpectations(dtc_mock_);
419 421
420 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)). 422 EXPECT_CALL(*change_processor_, Connect(_,_,_,_)).
421 WillOnce(Return(base::WeakPtr<SyncableService>())); 423 WillOnce(Return(base::WeakPtr<csync::SyncableService>()));
422 new_non_frontend_dtc_->UnblockBackendTasks(); 424 new_non_frontend_dtc_->UnblockBackendTasks();
423 EXPECT_CALL(*dtc_mock_, RecordUnrecoverableError(_, _)); 425 EXPECT_CALL(*dtc_mock_, RecordUnrecoverableError(_, _));
424 WaitForDTC(); 426 WaitForDTC();
425 } 427 }
426 428
427 TEST_F(SyncNewNonFrontendDataTypeControllerTest, Stop) { 429 TEST_F(SyncNewNonFrontendDataTypeControllerTest, Stop) {
428 SetStartExpectations(); 430 SetStartExpectations();
429 SetAssociateExpectations(); 431 SetAssociateExpectations();
430 SetActivateExpectations(DataTypeController::OK); 432 SetActivateExpectations(DataTypeController::OK);
431 SetStopExpectations(); 433 SetStopExpectations();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 new_non_frontend_dtc_.get(), 488 new_non_frontend_dtc_.get(),
487 FROM_HERE, 489 FROM_HERE,
488 std::string("Test"))); 490 std::string("Test")));
489 WaitForDTC(); 491 WaitForDTC();
490 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state()); 492 EXPECT_EQ(DataTypeController::NOT_RUNNING, new_non_frontend_dtc_->state());
491 } 493 }
492 494
493 } // namespace 495 } // namespace
494 496
495 } // namespace browser_sync 497 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698