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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
10 #include "chrome/browser/signin/account_tracker_service_factory.h" | 10 #include "chrome/browser/signin/account_tracker_service_factory.h" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 sync_->SetSetupInProgress(true); | 269 sync_->SetSetupInProgress(true); |
270 | 270 |
271 // Simulate successful signin as test_user. | 271 // Simulate successful signin as test_user. |
272 std::string account_id = | 272 std::string account_id = |
273 SimulateTestUserSignin(profile_, fake_signin(), sync_); | 273 SimulateTestUserSignin(profile_, fake_signin(), sync_); |
274 // Create some tokens in the token service. | 274 // Create some tokens in the token service. |
275 IssueTestTokens(account_id); | 275 IssueTestTokens(account_id); |
276 | 276 |
277 // Simulate the UI telling sync it has finished setting up. | 277 // Simulate the UI telling sync it has finished setting up. |
278 sync_->SetSetupInProgress(false); | 278 sync_->SetSetupInProgress(false); |
279 EXPECT_TRUE(sync_->SyncActive()); | 279 EXPECT_TRUE(sync_->IsSyncActive()); |
280 } | 280 } |
281 | 281 |
282 // TODO(pavely): Reenable test once android is switched to oauth2. | 282 // TODO(pavely): Reenable test once android is switched to oauth2. |
283 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { | 283 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { |
284 // We've never completed startup. | 284 // We've never completed startup. |
285 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 285 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
286 CreateSyncService(); | 286 CreateSyncService(); |
287 | 287 |
288 // Should not actually start, rather just clean things up and wait | 288 // Should not actually start, rather just clean things up and wait |
289 // to be enabled. | 289 // to be enabled. |
(...skipping 16 matching lines...) Expand all Loading... |
306 std::string account_id = | 306 std::string account_id = |
307 SimulateTestUserSignin(profile_, fake_signin(), sync_); | 307 SimulateTestUserSignin(profile_, fake_signin(), sync_); |
308 | 308 |
309 ProfileOAuth2TokenService* token_service = | 309 ProfileOAuth2TokenService* token_service = |
310 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 310 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
311 token_service->LoadCredentials(account_id); | 311 token_service->LoadCredentials(account_id); |
312 | 312 |
313 sync_->SetSetupInProgress(false); | 313 sync_->SetSetupInProgress(false); |
314 // ProfileSyncService should try to start by requesting access token. | 314 // ProfileSyncService should try to start by requesting access token. |
315 // This request should fail as login token was not issued. | 315 // This request should fail as login token was not issued. |
316 EXPECT_FALSE(sync_->SyncActive()); | 316 EXPECT_FALSE(sync_->IsSyncActive()); |
317 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP, | 317 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP, |
318 sync_->GetAuthError().state()); | 318 sync_->GetAuthError().state()); |
319 } | 319 } |
320 | 320 |
321 // TODO(pavely): Reenable test once android is switched to oauth2. | 321 // TODO(pavely): Reenable test once android is switched to oauth2. |
322 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { | 322 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { |
323 CreateSyncService(); | 323 CreateSyncService(); |
324 std::string account_id = | 324 std::string account_id = |
325 SimulateTestUserSignin(profile_, fake_signin(), sync_); | 325 SimulateTestUserSignin(profile_, fake_signin(), sync_); |
326 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); | 326 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); |
327 | 327 |
328 // Tell the backend to stall while downloading control types (simulating an | 328 // Tell the backend to stall while downloading control types (simulating an |
329 // auth error). | 329 // auth error). |
330 mock_sbh->set_fail_initial_download(true); | 330 mock_sbh->set_fail_initial_download(true); |
331 | 331 |
332 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 332 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
333 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); | 333 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); |
334 | 334 |
335 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 335 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
336 sync_->Initialize(); | 336 sync_->Initialize(); |
337 EXPECT_FALSE(sync_->SyncActive()); | 337 EXPECT_FALSE(sync_->IsSyncActive()); |
338 Mock::VerifyAndClearExpectations(data_type_manager); | 338 Mock::VerifyAndClearExpectations(data_type_manager); |
339 | 339 |
340 // Update the credentials, unstalling the backend. | 340 // Update the credentials, unstalling the backend. |
341 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 341 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
342 EXPECT_CALL(*data_type_manager, state()). | 342 EXPECT_CALL(*data_type_manager, state()). |
343 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 343 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
344 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 344 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
345 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 345 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
346 sync_->SetSetupInProgress(true); | 346 sync_->SetSetupInProgress(true); |
347 | 347 |
348 // Simulate successful signin. | 348 // Simulate successful signin. |
349 SimulateTestUserSignin(profile_, fake_signin(), sync_); | 349 SimulateTestUserSignin(profile_, fake_signin(), sync_); |
350 | 350 |
351 sync_->SetSetupInProgress(false); | 351 sync_->SetSetupInProgress(false); |
352 | 352 |
353 // Verify we successfully finish startup and configuration. | 353 // Verify we successfully finish startup and configuration. |
354 EXPECT_TRUE(sync_->SyncActive()); | 354 EXPECT_TRUE(sync_->IsSyncActive()); |
355 } | 355 } |
356 | 356 |
357 #if defined(OS_WIN) | 357 #if defined(OS_WIN) |
358 // http://crbug.com/396402 | 358 // http://crbug.com/396402 |
359 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials | 359 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials |
360 #else | 360 #else |
361 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials | 361 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials |
362 #endif | 362 #endif |
363 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { | 363 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { |
364 EXPECT_CALL(*components_factory_mock(), | 364 EXPECT_CALL(*components_factory_mock(), |
365 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 365 CreateDataTypeManager(_, _, _, _, _)).Times(0); |
366 EXPECT_CALL(*components_factory_mock(), | 366 EXPECT_CALL(*components_factory_mock(), |
367 CreateSyncBackendHost(_, _, _, _, _)).Times(0); | 367 CreateSyncBackendHost(_, _, _, _, _)).Times(0); |
368 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 368 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
369 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 369 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
370 | 370 |
371 sync_->Initialize(); | 371 sync_->Initialize(); |
372 // Sync should not start because there are no tokens yet. | 372 // Sync should not start because there are no tokens yet. |
373 EXPECT_FALSE(sync_->SyncActive()); | 373 EXPECT_FALSE(sync_->IsSyncActive()); |
374 sync_->SetSetupInProgress(false); | 374 sync_->SetSetupInProgress(false); |
375 | 375 |
376 // Sync should not start because there are still no tokens. | 376 // Sync should not start because there are still no tokens. |
377 EXPECT_FALSE(sync_->SyncActive()); | 377 EXPECT_FALSE(sync_->IsSyncActive()); |
378 } | 378 } |
379 | 379 |
380 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { | 380 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { |
381 SetUpSyncBackendHost(); | 381 SetUpSyncBackendHost(); |
382 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 382 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
383 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 383 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
384 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 384 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
385 EXPECT_CALL(*data_type_manager, state()). | 385 EXPECT_CALL(*data_type_manager, state()). |
386 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 386 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
387 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 387 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
388 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 388 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
389 | 389 |
390 IssueTestTokens( | 390 IssueTestTokens( |
391 AccountTrackerServiceFactory::GetForProfile(profile_) | 391 AccountTrackerServiceFactory::GetForProfile(profile_) |
392 ->PickAccountIdForAccount("12345", kEmail)); | 392 ->PickAccountIdForAccount("12345", kEmail)); |
393 sync_->Initialize(); | 393 sync_->Initialize(); |
394 EXPECT_TRUE(sync_->SyncActive()); | 394 EXPECT_TRUE(sync_->IsSyncActive()); |
395 } | 395 } |
396 | 396 |
397 #if defined(OS_WIN) | 397 #if defined(OS_WIN) |
398 // http://crbug.com/396402 | 398 // http://crbug.com/396402 |
399 #define MAYBE_StartNormal DISABLED_StartNormal | 399 #define MAYBE_StartNormal DISABLED_StartNormal |
400 #else | 400 #else |
401 #define MAYBE_StartNormal StartNormal | 401 #define MAYBE_StartNormal StartNormal |
402 #endif | 402 #endif |
403 TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartNormal) { | 403 TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartNormal) { |
404 // Pre load the tokens | 404 // Pre load the tokens |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 mock_sbh->set_fail_initial_download(true); | 571 mock_sbh->set_fail_initial_download(true); |
572 | 572 |
573 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 573 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
574 | 574 |
575 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 575 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
576 sync_->Initialize(); | 576 sync_->Initialize(); |
577 | 577 |
578 sync_->SetSetupInProgress(true); | 578 sync_->SetSetupInProgress(true); |
579 IssueTestTokens(account_id); | 579 IssueTestTokens(account_id); |
580 sync_->SetSetupInProgress(false); | 580 sync_->SetSetupInProgress(false); |
581 EXPECT_FALSE(sync_->SyncActive()); | 581 EXPECT_FALSE(sync_->IsSyncActive()); |
582 } | 582 } |
OLD | NEW |