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 "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 Loading... |
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@gmail.com"); | 171 "test_user"); |
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 Loading... |
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@gmail.com"); | 219 "test_user"); |
220 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); | 220 sync_->signin()->SetAuthenticatedUsername("test_user"); |
221 GoogleServiceSigninSuccessDetails details("test_user@gmail.com", ""); | 221 GoogleServiceSigninSuccessDetails details("test_user", ""); |
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 Loading... |
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@gmail.com"); | 266 "test_user"); |
267 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); | 267 sync_->signin()->SetAuthenticatedUsername("test_user"); |
268 GoogleServiceSigninSuccessDetails details("test_user@gmail.com", ""); | 268 GoogleServiceSigninSuccessDetails details("test_user", ""); |
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@gmail.com"); | 287 "test_user"); |
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@gmail.com", | 316 GoogleServiceSigninSuccessDetails details("test_user", std::string()); |
317 std::string()); | |
318 content::NotificationService::current()->Notify( | 317 content::NotificationService::current()->Notify( |
319 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 318 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
320 content::Source<Profile>(profile_.get()), | 319 content::Source<Profile>(profile_.get()), |
321 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 320 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
322 | 321 |
323 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 322 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
324 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 323 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
325 sync_->SetSetupInProgress(false); | 324 sync_->SetSetupInProgress(false); |
326 | 325 |
327 // Verify we successfully finish startup and configuration. | 326 // Verify we successfully finish startup and configuration. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 360 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
362 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 361 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
363 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 362 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
364 GaiaConstants::kSyncService, "sync_token"); | 363 GaiaConstants::kSyncService, "sync_token"); |
365 sync_->Initialize(); | 364 sync_->Initialize(); |
366 EXPECT_TRUE(sync_->ShouldPushChanges()); | 365 EXPECT_TRUE(sync_->ShouldPushChanges()); |
367 } | 366 } |
368 | 367 |
369 TEST_F(ProfileSyncServiceStartupTest, StartNormal) { | 368 TEST_F(ProfileSyncServiceStartupTest, StartNormal) { |
370 // Pre load the tokens | 369 // Pre load the tokens |
371 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 370 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
372 "test_user@gmail.com"); | |
373 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 371 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
374 profile_.get(), NULL); | 372 profile_.get(), NULL); |
375 CreateSyncService(); | 373 CreateSyncService(); |
376 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 374 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
377 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 375 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
378 EXPECT_CALL(*data_type_manager, state()). | 376 EXPECT_CALL(*data_type_manager, state()). |
379 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 377 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
380 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 378 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
381 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 379 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
382 | 380 |
(...skipping 12 matching lines...) Expand all Loading... |
395 // Clear the datatype preference fields (simulating bug 154940). | 393 // Clear the datatype preference fields (simulating bug 154940). |
396 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced); | 394 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced); |
397 syncer::ModelTypeSet user_types = syncer::UserTypes(); | 395 syncer::ModelTypeSet user_types = syncer::UserTypes(); |
398 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); | 396 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); |
399 iter.Good(); iter.Inc()) { | 397 iter.Good(); iter.Inc()) { |
400 profile_->GetPrefs()->ClearPref( | 398 profile_->GetPrefs()->ClearPref( |
401 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); | 399 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); |
402 } | 400 } |
403 | 401 |
404 // Pre load the tokens | 402 // Pre load the tokens |
405 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 403 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
406 "test_user@gmail.com"); | |
407 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 404 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
408 profile_.get(), NULL); | 405 profile_.get(), NULL); |
409 CreateSyncService(); | 406 CreateSyncService(); |
410 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 407 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
411 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 408 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
412 EXPECT_CALL(*data_type_manager, state()). | 409 EXPECT_CALL(*data_type_manager, state()). |
413 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 410 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
414 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 411 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
415 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 412 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
416 | 413 |
417 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 414 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
418 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 415 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
419 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 416 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
420 GaiaConstants::kSyncService, "sync_token"); | 417 GaiaConstants::kSyncService, "sync_token"); |
421 sync_->Initialize(); | 418 sync_->Initialize(); |
422 | 419 |
423 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( | 420 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( |
424 prefs::kSyncKeepEverythingSynced)); | 421 prefs::kSyncKeepEverythingSynced)); |
425 } | 422 } |
426 | 423 |
427 // Verify that the recovery of datatype preferences doesn't overwrite a valid | 424 // Verify that the recovery of datatype preferences doesn't overwrite a valid |
428 // case where only bookmarks are enabled. | 425 // case where only bookmarks are enabled. |
429 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { | 426 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { |
430 // Explicitly set Keep Everything Synced to false and have only bookmarks | 427 // Explicitly set Keep Everything Synced to false and have only bookmarks |
431 // enabled. | 428 // enabled. |
432 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 429 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); |
433 | 430 |
434 // Pre load the tokens | 431 // Pre load the tokens |
435 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 432 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
436 "test_user@gmail.com"); | |
437 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 433 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
438 profile_.get(), NULL); | 434 profile_.get(), NULL); |
439 CreateSyncService(); | 435 CreateSyncService(); |
440 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 436 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
441 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 437 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
442 EXPECT_CALL(*data_type_manager, state()). | 438 EXPECT_CALL(*data_type_manager, state()). |
443 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 439 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
444 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 440 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
445 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 441 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
446 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 442 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
447 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 443 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
448 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 444 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
449 GaiaConstants::kSyncService, "sync_token"); | 445 GaiaConstants::kSyncService, "sync_token"); |
450 sync_->Initialize(); | 446 sync_->Initialize(); |
451 | 447 |
452 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( | 448 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
453 prefs::kSyncKeepEverythingSynced)); | 449 prefs::kSyncKeepEverythingSynced)); |
454 } | 450 } |
455 | 451 |
456 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { | 452 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { |
457 // Service should not be started by Initialize() since it's managed. | 453 // Service should not be started by Initialize() since it's managed. |
458 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 454 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
459 "test_user@gmail.com"); | |
460 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 455 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
461 profile_.get(), NULL); | 456 profile_.get(), NULL); |
462 CreateSyncService(); | 457 CreateSyncService(); |
463 | 458 |
464 // Disable sync through policy. | 459 // Disable sync through policy. |
465 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 460 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); |
466 EXPECT_CALL(*sync_->components_factory_mock(), | 461 EXPECT_CALL(*sync_->components_factory_mock(), |
467 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 462 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
468 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 463 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
469 | 464 |
470 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 465 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
471 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 466 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
472 sync_->Initialize(); | 467 sync_->Initialize(); |
473 } | 468 } |
474 | 469 |
475 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { | 470 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { |
476 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 471 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
477 "test_user@gmail.com"); | |
478 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 472 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
479 profile_.get(), NULL); | 473 profile_.get(), NULL); |
480 CreateSyncService(); | 474 CreateSyncService(); |
481 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 475 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
482 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 476 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
483 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 477 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
484 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 478 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
485 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 479 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
486 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 480 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
487 GaiaConstants::kSyncService, "token"); | 481 GaiaConstants::kSyncService, "token"); |
(...skipping 10 matching lines...) Expand all Loading... |
498 // When switching back to unmanaged, the state should change, but the service | 492 // When switching back to unmanaged, the state should change, but the service |
499 // should not start up automatically (kSyncSetupCompleted will be false). | 493 // should not start up automatically (kSyncSetupCompleted will be false). |
500 Mock::VerifyAndClearExpectations(data_type_manager); | 494 Mock::VerifyAndClearExpectations(data_type_manager); |
501 EXPECT_CALL(*sync_->components_factory_mock(), | 495 EXPECT_CALL(*sync_->components_factory_mock(), |
502 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 496 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
503 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 497 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
504 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged); | 498 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged); |
505 } | 499 } |
506 | 500 |
507 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { | 501 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { |
508 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 502 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
509 "test_user@gmail.com"); | |
510 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 503 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
511 profile_.get(), NULL); | 504 profile_.get(), NULL); |
512 CreateSyncService(); | 505 CreateSyncService(); |
513 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 506 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
514 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED; | 507 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED; |
515 syncer::SyncError error( | 508 syncer::SyncError error( |
516 FROM_HERE, "Association failed.", syncer::BOOKMARKS); | 509 FROM_HERE, "Association failed.", syncer::BOOKMARKS); |
517 std::map<syncer::ModelType, syncer::SyncError> errors; | 510 std::map<syncer::ModelType, syncer::SyncError> errors; |
518 errors[syncer::BOOKMARKS] = error; | 511 errors[syncer::BOOKMARKS] = error; |
519 DataTypeManager::ConfigureResult result( | 512 DataTypeManager::ConfigureResult result( |
(...skipping 12 matching lines...) Expand all Loading... |
532 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 525 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
533 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 526 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
534 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 527 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
535 GaiaConstants::kSyncService, "token"); | 528 GaiaConstants::kSyncService, "token"); |
536 sync_->Initialize(); | 529 sync_->Initialize(); |
537 EXPECT_TRUE(sync_->HasUnrecoverableError()); | 530 EXPECT_TRUE(sync_->HasUnrecoverableError()); |
538 } | 531 } |
539 | 532 |
540 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { | 533 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { |
541 // Pre load the tokens | 534 // Pre load the tokens |
542 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 535 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "test_user"); |
543 "test_user@gmail.com"); | |
544 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( | 536 SigninManagerFactory::GetForProfile(profile_.get())->Initialize( |
545 profile_.get(), NULL); | 537 profile_.get(), NULL); |
546 CreateSyncService(); | 538 CreateSyncService(); |
547 | 539 |
548 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 540 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); |
549 | 541 |
550 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 542 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
551 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 543 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
552 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 544 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); |
553 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( | 545 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( |
554 GaiaConstants::kSyncService, "token"); | 546 GaiaConstants::kSyncService, "token"); |
555 sync_->fail_initial_download(); | 547 sync_->fail_initial_download(); |
556 | 548 |
557 sync_->SetSetupInProgress(true); | 549 sync_->SetSetupInProgress(true); |
558 sync_->Initialize(); | 550 sync_->Initialize(); |
559 sync_->SetSetupInProgress(false); | 551 sync_->SetSetupInProgress(false); |
560 EXPECT_FALSE(sync_->sync_initialized()); | 552 EXPECT_FALSE(sync_->sync_initialized()); |
561 EXPECT_TRUE(sync_->GetBackendForTest()); | 553 EXPECT_TRUE(sync_->GetBackendForTest()); |
562 } | 554 } |
OLD | NEW |