| OLD | NEW |
| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/signin/signin_manager.h" | 10 #include "chrome/browser/signin/signin_manager.h" |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 288 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); |
| 289 | 289 |
| 290 // When switching back to unmanaged, the state should change, but the service | 290 // When switching back to unmanaged, the state should change, but the service |
| 291 // should not start up automatically (kSyncSetupCompleted will be false). | 291 // should not start up automatically (kSyncSetupCompleted will be false). |
| 292 Mock::VerifyAndClearExpectations(data_type_manager); | 292 Mock::VerifyAndClearExpectations(data_type_manager); |
| 293 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _)).Times(0); | 293 EXPECT_CALL(*factory_mock(), CreateDataTypeManager(_, _)).Times(0); |
| 294 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 294 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 295 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged); | 295 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged); |
| 296 } | 296 } |
| 297 | 297 |
| 298 TEST_F(ProfileSyncServiceStartupTest, ClearServerData) { | |
| 299 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | |
| 300 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); | |
| 301 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 302 | |
| 303 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | |
| 304 GaiaConstants::kSyncService, "sync_token"); | |
| 305 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); | |
| 306 service_->Initialize(); | |
| 307 Mock::VerifyAndClearExpectations(data_type_manager); | |
| 308 | |
| 309 // Success can overwrite failure, failure cannot overwrite success. We want | |
| 310 // this behavior because once clear has succeeded, sync gets disabled, and | |
| 311 // we don't care about any subsequent failures (e.g. timeouts) | |
| 312 service_->ResetClearServerDataState(); | |
| 313 EXPECT_TRUE(ProfileSyncService::CLEAR_NOT_STARTED == | |
| 314 service_->GetClearServerDataState()); | |
| 315 | |
| 316 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 317 service_->OnClearServerDataFailed(); | |
| 318 EXPECT_TRUE(ProfileSyncService::CLEAR_FAILED == | |
| 319 service_->GetClearServerDataState()); | |
| 320 | |
| 321 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 322 service_->OnClearServerDataSucceeded(); | |
| 323 EXPECT_TRUE(ProfileSyncService::CLEAR_SUCCEEDED == | |
| 324 service_->GetClearServerDataState()); | |
| 325 | |
| 326 service_->OnClearServerDataFailed(); | |
| 327 EXPECT_TRUE(ProfileSyncService::CLEAR_SUCCEEDED == | |
| 328 service_->GetClearServerDataState()); | |
| 329 | |
| 330 // Now test the timeout states | |
| 331 service_->ResetClearServerDataState(); | |
| 332 EXPECT_TRUE(ProfileSyncService::CLEAR_NOT_STARTED == | |
| 333 service_->GetClearServerDataState()); | |
| 334 | |
| 335 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 336 service_->OnClearServerDataTimeout(); | |
| 337 EXPECT_TRUE(ProfileSyncService::CLEAR_FAILED == | |
| 338 service_->GetClearServerDataState()); | |
| 339 | |
| 340 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 341 service_->OnClearServerDataSucceeded(); | |
| 342 EXPECT_TRUE(ProfileSyncService::CLEAR_SUCCEEDED == | |
| 343 service_->GetClearServerDataState()); | |
| 344 | |
| 345 service_->OnClearServerDataFailed(); | |
| 346 EXPECT_TRUE(ProfileSyncService::CLEAR_SUCCEEDED == | |
| 347 service_->GetClearServerDataState()); | |
| 348 | |
| 349 // Test the pending state, doesn't matter what state | |
| 350 // the back end syncmgr returns | |
| 351 EXPECT_CALL(*data_type_manager, state()). | |
| 352 WillOnce(Return(DataTypeManager::STOPPED)); | |
| 353 service_->ResetClearServerDataState(); | |
| 354 service_->ClearServerData(); | |
| 355 EXPECT_TRUE(ProfileSyncService::CLEAR_CLEARING == | |
| 356 service_->GetClearServerDataState()); | |
| 357 | |
| 358 // Stop the timer and reset the state | |
| 359 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | |
| 360 service_->OnClearServerDataSucceeded(); | |
| 361 service_->ResetClearServerDataState(); | |
| 362 } | |
| 363 | |
| 364 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { | 298 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { |
| 365 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 299 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
| 366 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED; | 300 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED; |
| 367 SyncError error(FROM_HERE, "Association failed.", syncable::BOOKMARKS); | 301 SyncError error(FROM_HERE, "Association failed.", syncable::BOOKMARKS); |
| 368 std::list<SyncError> errors; | 302 std::list<SyncError> errors; |
| 369 errors.push_back(error); | 303 errors.push_back(error); |
| 370 browser_sync::DataTypeManager::ConfigureResult result( | 304 browser_sync::DataTypeManager::ConfigureResult result( |
| 371 status, | 305 status, |
| 372 syncable::ModelTypeSet(), | 306 syncable::ModelTypeSet(), |
| 373 errors, | 307 errors, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 399 | 333 |
| 400 // Preload the tokens. | 334 // Preload the tokens. |
| 401 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 335 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
| 402 GaiaConstants::kSyncService, "sync_token"); | 336 GaiaConstants::kSyncService, "sync_token"); |
| 403 service_->fail_initial_download(); | 337 service_->fail_initial_download(); |
| 404 | 338 |
| 405 service_->Initialize(); | 339 service_->Initialize(); |
| 406 EXPECT_FALSE(service_->sync_initialized()); | 340 EXPECT_FALSE(service_->sync_initialized()); |
| 407 EXPECT_FALSE(service_->GetBackendForTest()); | 341 EXPECT_FALSE(service_->GetBackendForTest()); |
| 408 } | 342 } |
| OLD | NEW |