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

Side by Side Diff: chrome/browser/sync/profile_sync_service_startup_unittest.cc

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 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
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 "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 "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/signin/fake_signin_manager.h" 10 #include "chrome/browser/signin/fake_signin_manager.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 sync_->AddObserver(&observer_); 161 sync_->AddObserver(&observer_);
162 sync_->set_synchronous_sync_configuration(); 162 sync_->set_synchronous_sync_configuration();
163 } 163 }
164 164
165 static BrowserContextKeyedService* BuildCrosService( 165 static BrowserContextKeyedService* BuildCrosService(
166 content::BrowserContext* context) { 166 content::BrowserContext* context) {
167 Profile* profile = static_cast<Profile*>(context); 167 Profile* profile = static_cast<Profile*>(context);
168 SigninManagerBase* signin = 168 SigninManagerBase* signin =
169 SigninManagerFactory::GetForProfile(profile); 169 SigninManagerFactory::GetForProfile(profile);
170 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 170 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
171 "test_user"); 171 "test_user@gmail.com");
172 signin->Initialize(profile, NULL); 172 signin->Initialize(profile, NULL);
173 EXPECT_FALSE(signin->GetAuthenticatedUsername().empty()); 173 EXPECT_FALSE(signin->GetAuthenticatedUsername().empty());
174 return new TestProfileSyncService( 174 return new TestProfileSyncService(
175 new ProfileSyncComponentsFactoryMock(), 175 new ProfileSyncComponentsFactoryMock(),
176 profile, 176 profile,
177 signin, 177 signin,
178 ProfileSyncService::AUTO_START, 178 ProfileSyncService::AUTO_START,
179 true); 179 true);
180 } 180 }
181 }; 181 };
(...skipping 27 matching lines...) Expand all
209 EXPECT_CALL(*data_type_manager, state()). 209 EXPECT_CALL(*data_type_manager, state()).
210 WillOnce(Return(DataTypeManager::CONFIGURED)). 210 WillOnce(Return(DataTypeManager::CONFIGURED)).
211 WillOnce(Return(DataTypeManager::CONFIGURED)); 211 WillOnce(Return(DataTypeManager::CONFIGURED));
212 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 212 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
213 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 213 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
214 214
215 sync_->SetSetupInProgress(true); 215 sync_->SetSetupInProgress(true);
216 216
217 // Simulate successful signin as test_user. 217 // Simulate successful signin as test_user.
218 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 218 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
219 "test_user"); 219 "test_user@gmail.com");
220 sync_->signin()->SetAuthenticatedUsername("test_user"); 220 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com");
221 GoogleServiceSigninSuccessDetails details("test_user", ""); 221 GoogleServiceSigninSuccessDetails details("test_user@gmail.com", "");
222 content::NotificationService::current()->Notify( 222 content::NotificationService::current()->Notify(
223 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 223 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
224 content::Source<Profile>(profile_.get()), 224 content::Source<Profile>(profile_.get()),
225 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 225 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
226 226
227 // Create some tokens in the token service. 227 // Create some tokens in the token service.
228 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 228 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
229 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 229 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
230 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 230 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
231 GaiaConstants::kSyncService, "token"); 231 GaiaConstants::kSyncService, "token");
(...skipping 24 matching lines...) Expand all
256 256
257 // Preferences should be back to defaults. 257 // Preferences should be back to defaults.
258 EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); 258 EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime));
259 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)); 259 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted));
260 260
261 // Then start things up. 261 // Then start things up.
262 sync_->SetSetupInProgress(true); 262 sync_->SetSetupInProgress(true);
263 263
264 // Simulate successful signin as test_user. 264 // Simulate successful signin as test_user.
265 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 265 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
266 "test_user"); 266 "test_user@gmail.com");
267 sync_->signin()->SetAuthenticatedUsername("test_user"); 267 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com");
268 GoogleServiceSigninSuccessDetails details("test_user", ""); 268 GoogleServiceSigninSuccessDetails details("test_user@gmail.com", "");
269 content::NotificationService::current()->Notify( 269 content::NotificationService::current()->Notify(
270 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 270 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
271 content::Source<Profile>(profile_.get()), 271 content::Source<Profile>(profile_.get()),
272 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 272 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
273 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens. 273 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens.
274 token_service->LoadTokensFromDB(); 274 token_service->LoadTokensFromDB();
275 275
276 sync_->SetSetupInProgress(false); 276 sync_->SetSetupInProgress(false);
277 // ProfileSyncService should try to start by requesting access token. 277 // ProfileSyncService should try to start by requesting access token.
278 // This request should fail as login token was not issued to TokenService. 278 // This request should fail as login token was not issued to TokenService.
279 EXPECT_FALSE(sync_->ShouldPushChanges()); 279 EXPECT_FALSE(sync_->ShouldPushChanges());
280 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP, 280 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP,
281 sync_->GetAuthError().state()); 281 sync_->GetAuthError().state());
282 } 282 }
283 283
284 // TODO(pavely): Reenable test once android is switched to oauth2. 284 // TODO(pavely): Reenable test once android is switched to oauth2.
285 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) { 285 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
286 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 286 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
287 "test_user"); 287 "test_user@gmail.com");
288 SigninManagerFactory::GetForProfile( 288 SigninManagerFactory::GetForProfile(
289 profile_.get())->Initialize(profile_.get(), NULL); 289 profile_.get())->Initialize(profile_.get(), NULL);
290 CreateSyncService(); 290 CreateSyncService();
291 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 291 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
292 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); 292 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
293 // Issue login token so that ProfileSyncServer tries to initialize backend. 293 // Issue login token so that ProfileSyncServer tries to initialize backend.
294 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 294 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
295 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 295 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
296 296
297 // Tell the backend to stall while downloading control types (simulating an 297 // Tell the backend to stall while downloading control types (simulating an
298 // auth error). 298 // auth error).
299 sync_->fail_initial_download(); 299 sync_->fail_initial_download();
300 300
301 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 301 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
302 sync_->Initialize(); 302 sync_->Initialize();
303 EXPECT_TRUE(sync_->GetBackendForTest()); 303 EXPECT_TRUE(sync_->GetBackendForTest());
304 EXPECT_FALSE(sync_->sync_initialized()); 304 EXPECT_FALSE(sync_->sync_initialized());
305 Mock::VerifyAndClearExpectations(data_type_manager); 305 Mock::VerifyAndClearExpectations(data_type_manager);
306 306
307 // Update the credentials, unstalling the backend. 307 // Update the credentials, unstalling the backend.
308 EXPECT_CALL(*data_type_manager, Configure(_, _)); 308 EXPECT_CALL(*data_type_manager, Configure(_, _));
309 EXPECT_CALL(*data_type_manager, state()). 309 EXPECT_CALL(*data_type_manager, state()).
310 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 310 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
311 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 311 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
312 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 312 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
313 sync_->SetSetupInProgress(true); 313 sync_->SetSetupInProgress(true);
314 314
315 // Simulate successful signin. 315 // Simulate successful signin.
316 GoogleServiceSigninSuccessDetails details("test_user", std::string()); 316 GoogleServiceSigninSuccessDetails details("test_user@gmail.com",
317 std::string());
317 content::NotificationService::current()->Notify( 318 content::NotificationService::current()->Notify(
318 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 319 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
319 content::Source<Profile>(profile_.get()), 320 content::Source<Profile>(profile_.get()),
320 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 321 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
321 322
322 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 323 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
323 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 324 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
324 sync_->SetSetupInProgress(false); 325 sync_->SetSetupInProgress(false);
325 326
326 // Verify we successfully finish startup and configuration. 327 // Verify we successfully finish startup and configuration.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 361 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
361 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 362 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
362 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 363 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
363 GaiaConstants::kSyncService, "sync_token"); 364 GaiaConstants::kSyncService, "sync_token");
364 sync_->Initialize(); 365 sync_->Initialize();
365 EXPECT_TRUE(sync_->ShouldPushChanges()); 366 EXPECT_TRUE(sync_->ShouldPushChanges());
366 } 367 }
367 368
368 TEST_F(ProfileSyncServiceStartupTest, StartNormal) { 369 TEST_F(ProfileSyncServiceStartupTest, StartNormal) {
369 // Pre load the tokens 370 // Pre load the tokens
370 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 371 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
372 "test_user@gmail.com");
371 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 373 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
372 profile_.get(), NULL); 374 profile_.get(), NULL);
373 CreateSyncService(); 375 CreateSyncService();
374 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 376 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
375 EXPECT_CALL(*data_type_manager, Configure(_, _)); 377 EXPECT_CALL(*data_type_manager, Configure(_, _));
376 EXPECT_CALL(*data_type_manager, state()). 378 EXPECT_CALL(*data_type_manager, state()).
377 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 379 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
378 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 380 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
379 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 381 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
380 382
(...skipping 12 matching lines...) Expand all
393 // Clear the datatype preference fields (simulating bug 154940). 395 // Clear the datatype preference fields (simulating bug 154940).
394 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced); 396 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced);
395 syncer::ModelTypeSet user_types = syncer::UserTypes(); 397 syncer::ModelTypeSet user_types = syncer::UserTypes();
396 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); 398 for (syncer::ModelTypeSet::Iterator iter = user_types.First();
397 iter.Good(); iter.Inc()) { 399 iter.Good(); iter.Inc()) {
398 profile_->GetPrefs()->ClearPref( 400 profile_->GetPrefs()->ClearPref(
399 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); 401 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get()));
400 } 402 }
401 403
402 // Pre load the tokens 404 // Pre load the tokens
403 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 405 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
406 "test_user@gmail.com");
404 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 407 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
405 profile_.get(), NULL); 408 profile_.get(), NULL);
406 CreateSyncService(); 409 CreateSyncService();
407 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 410 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
408 EXPECT_CALL(*data_type_manager, Configure(_, _)); 411 EXPECT_CALL(*data_type_manager, Configure(_, _));
409 EXPECT_CALL(*data_type_manager, state()). 412 EXPECT_CALL(*data_type_manager, state()).
410 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 413 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
411 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 414 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
412 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 415 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
413 416
414 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 417 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
415 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 418 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
416 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 419 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
417 GaiaConstants::kSyncService, "sync_token"); 420 GaiaConstants::kSyncService, "sync_token");
418 sync_->Initialize(); 421 sync_->Initialize();
419 422
420 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( 423 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(
421 prefs::kSyncKeepEverythingSynced)); 424 prefs::kSyncKeepEverythingSynced));
422 } 425 }
423 426
424 // Verify that the recovery of datatype preferences doesn't overwrite a valid 427 // Verify that the recovery of datatype preferences doesn't overwrite a valid
425 // case where only bookmarks are enabled. 428 // case where only bookmarks are enabled.
426 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { 429 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) {
427 // Explicitly set Keep Everything Synced to false and have only bookmarks 430 // Explicitly set Keep Everything Synced to false and have only bookmarks
428 // enabled. 431 // enabled.
429 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); 432 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
430 433
431 // Pre load the tokens 434 // Pre load the tokens
432 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 435 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
436 "test_user@gmail.com");
433 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 437 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
434 profile_.get(), NULL); 438 profile_.get(), NULL);
435 CreateSyncService(); 439 CreateSyncService();
436 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 440 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
437 EXPECT_CALL(*data_type_manager, Configure(_, _)); 441 EXPECT_CALL(*data_type_manager, Configure(_, _));
438 EXPECT_CALL(*data_type_manager, state()). 442 EXPECT_CALL(*data_type_manager, state()).
439 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 443 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
440 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 444 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
441 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 445 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
442 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 446 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
443 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 447 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
444 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 448 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
445 GaiaConstants::kSyncService, "sync_token"); 449 GaiaConstants::kSyncService, "sync_token");
446 sync_->Initialize(); 450 sync_->Initialize();
447 451
448 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( 452 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
449 prefs::kSyncKeepEverythingSynced)); 453 prefs::kSyncKeepEverythingSynced));
450 } 454 }
451 455
452 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { 456 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) {
453 // Service should not be started by Initialize() since it's managed. 457 // Service should not be started by Initialize() since it's managed.
454 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 458 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
459 "test_user@gmail.com");
455 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 460 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
456 profile_.get(), NULL); 461 profile_.get(), NULL);
457 CreateSyncService(); 462 CreateSyncService();
458 463
459 // Disable sync through policy. 464 // Disable sync through policy.
460 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); 465 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true);
461 EXPECT_CALL(*sync_->components_factory_mock(), 466 EXPECT_CALL(*sync_->components_factory_mock(),
462 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); 467 CreateDataTypeManager(_, _, _, _, _, _)).Times(0);
463 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 468 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
464 469
465 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 470 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
466 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 471 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
467 sync_->Initialize(); 472 sync_->Initialize();
468 } 473 }
469 474
470 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { 475 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
471 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 476 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
477 "test_user@gmail.com");
472 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 478 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
473 profile_.get(), NULL); 479 profile_.get(), NULL);
474 CreateSyncService(); 480 CreateSyncService();
475 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 481 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
476 EXPECT_CALL(*data_type_manager, Configure(_, _)); 482 EXPECT_CALL(*data_type_manager, Configure(_, _));
477 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 483 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
478 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 484 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
479 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 485 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
480 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 486 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
481 GaiaConstants::kSyncService, "token"); 487 GaiaConstants::kSyncService, "token");
(...skipping 10 matching lines...) Expand all
492 // When switching back to unmanaged, the state should change, but the service 498 // When switching back to unmanaged, the state should change, but the service
493 // should not start up automatically (kSyncSetupCompleted will be false). 499 // should not start up automatically (kSyncSetupCompleted will be false).
494 Mock::VerifyAndClearExpectations(data_type_manager); 500 Mock::VerifyAndClearExpectations(data_type_manager);
495 EXPECT_CALL(*sync_->components_factory_mock(), 501 EXPECT_CALL(*sync_->components_factory_mock(),
496 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); 502 CreateDataTypeManager(_, _, _, _, _, _)).Times(0);
497 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 503 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
498 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged); 504 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged);
499 } 505 }
500 506
501 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { 507 TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
502 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 508 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
509 "test_user@gmail.com");
503 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 510 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
504 profile_.get(), NULL); 511 profile_.get(), NULL);
505 CreateSyncService(); 512 CreateSyncService();
506 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 513 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
507 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED; 514 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED;
508 syncer::SyncError error( 515 syncer::SyncError error(
509 FROM_HERE, "Association failed.", syncer::BOOKMARKS); 516 FROM_HERE, "Association failed.", syncer::BOOKMARKS);
510 std::map<syncer::ModelType, syncer::SyncError> errors; 517 std::map<syncer::ModelType, syncer::SyncError> errors;
511 errors[syncer::BOOKMARKS] = error; 518 errors[syncer::BOOKMARKS] = error;
512 DataTypeManager::ConfigureResult result( 519 DataTypeManager::ConfigureResult result(
(...skipping 12 matching lines...) Expand all
525 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 532 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
526 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 533 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
527 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 534 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
528 GaiaConstants::kSyncService, "token"); 535 GaiaConstants::kSyncService, "token");
529 sync_->Initialize(); 536 sync_->Initialize();
530 EXPECT_TRUE(sync_->HasUnrecoverableError()); 537 EXPECT_TRUE(sync_->HasUnrecoverableError());
531 } 538 }
532 539
533 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { 540 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
534 // Pre load the tokens 541 // Pre load the tokens
535 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); 542 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
543 "test_user@gmail.com");
536 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( 544 SigninManagerFactory::GetForProfile(profile_.get())->Initialize(
537 profile_.get(), NULL); 545 profile_.get(), NULL);
538 CreateSyncService(); 546 CreateSyncService();
539 547
540 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); 548 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted);
541 549
542 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 550 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
543 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 551 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
544 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 552 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
545 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 553 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
546 GaiaConstants::kSyncService, "token"); 554 GaiaConstants::kSyncService, "token");
547 sync_->fail_initial_download(); 555 sync_->fail_initial_download();
548 556
549 sync_->SetSetupInProgress(true); 557 sync_->SetSetupInProgress(true);
550 sync_->Initialize(); 558 sync_->Initialize();
551 sync_->SetSetupInProgress(false); 559 sync_->SetSetupInProgress(false);
552 EXPECT_FALSE(sync_->sync_initialized()); 560 EXPECT_FALSE(sync_->sync_initialized());
553 EXPECT_TRUE(sync_->GetBackendForTest()); 561 EXPECT_TRUE(sync_->GetBackendForTest());
554 } 562 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698