MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_service_startup_unittest.cc
blobad4410123eef5d3d77a7bb388ebc6279560818cb
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
3 // found in the LICENSE file.
5 #include "base/files/file_util.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/prefs/pref_service_syncable.h"
10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
12 #include "chrome/browser/signin/fake_signin_manager.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/browser/sync/glue/sync_backend_host_mock.h"
16 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h"
18 #include "chrome/browser/sync/profile_sync_test_util.h"
19 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
20 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_browser_process.h"
22 #include "chrome/test/base/testing_profile.h"
23 #include "chrome/test/base/testing_profile_manager.h"
24 #include "components/signin/core/browser/profile_oauth2_token_service.h"
25 #include "components/signin/core/browser/signin_manager.h"
26 #include "components/sync_driver/data_type_manager.h"
27 #include "components/sync_driver/data_type_manager_mock.h"
28 #include "components/sync_driver/pref_names.h"
29 #include "components/sync_driver/sync_prefs.h"
30 #include "content/public/test/test_browser_thread_bundle.h"
31 #include "content/public/test/test_utils.h"
32 #include "google_apis/gaia/gaia_auth_consumer.h"
33 #include "google_apis/gaia/gaia_constants.h"
34 #include "google_apis/gaia/oauth2_token_service.h"
35 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h"
38 using browser_sync::SyncBackendHostMock;
39 using content::BrowserThread;
40 using sync_driver::DataTypeManager;
41 using sync_driver::DataTypeManagerMock;
42 using testing::_;
43 using testing::AnyNumber;
44 using testing::DoAll;
45 using testing::InvokeArgument;
46 using testing::Mock;
47 using testing::Return;
48 using testing::SaveArg;
50 ACTION_P(InvokeOnConfigureStart, pss) {
51 ProfileSyncService* service =
52 static_cast<ProfileSyncService*>(pss);
53 service->OnConfigureStart();
56 ACTION_P3(InvokeOnConfigureDone, pss, error_callback, result) {
57 ProfileSyncService* service =
58 static_cast<ProfileSyncService*>(pss);
59 DataTypeManager::ConfigureResult configure_result =
60 static_cast<DataTypeManager::ConfigureResult>(result);
61 if (result.status == sync_driver::DataTypeManager::ABORTED)
62 error_callback.Run(&configure_result);
63 service->OnConfigureDone(configure_result);
66 class TestProfileSyncServiceNoBackup : public ProfileSyncService {
67 public:
68 TestProfileSyncServiceNoBackup(
69 scoped_ptr<ProfileSyncComponentsFactory> factory,
70 Profile* profile,
71 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
72 ProfileOAuth2TokenService* oauth2_token_service,
73 browser_sync::ProfileSyncServiceStartBehavior start_behavior)
74 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(),
75 oauth2_token_service, start_behavior) {}
77 protected:
78 bool NeedBackup() const override { return false; }
81 class ProfileSyncServiceStartupTest : public testing::Test {
82 public:
83 ProfileSyncServiceStartupTest()
84 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
85 content::TestBrowserThreadBundle::REAL_FILE_THREAD |
86 content::TestBrowserThreadBundle::REAL_IO_THREAD),
87 profile_manager_(TestingBrowserProcess::GetGlobal()),
88 sync_(NULL) {}
90 virtual ~ProfileSyncServiceStartupTest() {
93 virtual void SetUp() {
94 CHECK(profile_manager_.SetUp());
96 TestingProfile::TestingFactories testing_facotries;
97 testing_facotries.push_back(
98 std::make_pair(SigninManagerFactory::GetInstance(),
99 FakeSigninManagerBase::Build));
100 testing_facotries.push_back(
101 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(),
102 BuildAutoIssuingFakeProfileOAuth2TokenService));
103 testing_facotries.push_back(
104 std::make_pair(ProfileSyncServiceFactory::GetInstance(),
105 BuildService));
107 profile_ = profile_manager_.CreateTestingProfile(
108 "sync-startup-test", scoped_ptr<PrefServiceSyncable>(),
109 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(),
110 testing_facotries);
113 virtual void TearDown() {
114 sync_->RemoveObserver(&observer_);
117 static KeyedService* BuildService(content::BrowserContext* browser_context) {
118 Profile* profile = static_cast<Profile*>(browser_context);
119 return new TestProfileSyncServiceNoBackup(
120 scoped_ptr<ProfileSyncComponentsFactory>(
121 new ProfileSyncComponentsFactoryMock()),
122 profile,
123 make_scoped_ptr(new SupervisedUserSigninManagerWrapper(
124 profile, SigninManagerFactory::GetForProfile(profile))),
125 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
126 browser_sync::MANUAL_START);
129 void CreateSyncService() {
130 sync_ = static_cast<ProfileSyncService*>(
131 ProfileSyncServiceFactory::GetForProfile(profile_));
132 sync_->AddObserver(&observer_);
135 void IssueTestTokens() {
136 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
137 ->UpdateCredentials("test_user@gmail.com", "oauth2_login_token");
140 ProfileSyncComponentsFactoryMock* components_factory_mock() {
141 return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory());
144 FakeSigninManagerForTesting* fake_signin() {
145 return static_cast<FakeSigninManagerForTesting*>(sync_->signin());
148 void SetError(DataTypeManager::ConfigureResult* result) {
149 sync_driver::DataTypeStatusTable::TypeErrorMap errors;
150 errors[syncer::BOOKMARKS] =
151 syncer::SyncError(FROM_HERE,
152 syncer::SyncError::UNRECOVERABLE_ERROR,
153 "Error",
154 syncer::BOOKMARKS);
155 result->data_type_status_table.UpdateFailedDataTypes(errors);
158 protected:
159 void SimulateTestUserSignin() {
160 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
161 "test_user@gmail.com");
162 #if !defined(OS_CHROMEOS)
163 fake_signin()->SignIn("test_user@gmail.com", "");
164 #else
165 fake_signin()->SetAuthenticatedUsername("test_user@gmail.com");
166 sync_->GoogleSigninSucceeded("test_user@gmail.com",
167 "test_user@gmail.com",
168 "");
169 #endif
172 DataTypeManagerMock* SetUpDataTypeManager() {
173 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock();
174 EXPECT_CALL(*components_factory_mock(),
175 CreateDataTypeManager(_, _, _, _, _)).
176 WillOnce(Return(data_type_manager));
177 return data_type_manager;
180 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() {
181 browser_sync::SyncBackendHostMock* sync_backend_host =
182 new browser_sync::SyncBackendHostMock();
183 EXPECT_CALL(*components_factory_mock(),
184 CreateSyncBackendHost(_, _, _, _, _)).
185 WillOnce(Return(sync_backend_host));
186 return sync_backend_host;
189 content::TestBrowserThreadBundle thread_bundle_;
190 TestingProfileManager profile_manager_;
191 TestingProfile* profile_;
192 ProfileSyncService* sync_;
193 ProfileSyncServiceObserverMock observer_;
194 sync_driver::DataTypeStatusTable data_type_status_table_;
197 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
198 public:
199 virtual void SetUp() {
200 ProfileSyncServiceStartupTest::SetUp();
201 sync_ = static_cast<ProfileSyncService*>(
202 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
203 profile_, BuildCrosService));
204 sync_->AddObserver(&observer_);
207 static KeyedService* BuildCrosService(content::BrowserContext* context) {
208 Profile* profile = static_cast<Profile*>(context);
209 SigninManagerBase* signin =
210 SigninManagerFactory::GetForProfile(profile);
211 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
212 "test_user@gmail.com");
213 signin->SetAuthenticatedUsername("test_user@gmail.com");
214 ProfileOAuth2TokenService* oauth2_token_service =
215 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
216 EXPECT_TRUE(signin->IsAuthenticated());
217 return new TestProfileSyncServiceNoBackup(
218 scoped_ptr<ProfileSyncComponentsFactory>(
219 new ProfileSyncComponentsFactoryMock()),
220 profile,
221 make_scoped_ptr(new SupervisedUserSigninManagerWrapper(profile,
222 signin)),
223 oauth2_token_service,
224 browser_sync::AUTO_START);
228 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
229 // We've never completed startup.
230 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
231 CreateSyncService();
232 SetUpSyncBackendHost();
233 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
234 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
236 // Should not actually start, rather just clean things up and wait
237 // to be enabled.
238 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
239 sync_->Initialize();
241 // Preferences should be back to defaults.
242 EXPECT_EQ(
244 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
245 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
246 sync_driver::prefs::kSyncHasSetupCompleted));
247 Mock::VerifyAndClearExpectations(data_type_manager);
249 // Then start things up.
250 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
251 EXPECT_CALL(*data_type_manager, state()).
252 WillOnce(Return(DataTypeManager::CONFIGURED)).
253 WillOnce(Return(DataTypeManager::CONFIGURED));
254 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
255 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
257 sync_->SetSetupInProgress(true);
259 // Simulate successful signin as test_user.
260 SimulateTestUserSignin();
261 // Create some tokens in the token service.
262 IssueTestTokens();
264 // Simulate the UI telling sync it has finished setting up.
265 sync_->SetSetupInProgress(false);
266 EXPECT_TRUE(sync_->SyncActive());
269 // TODO(pavely): Reenable test once android is switched to oauth2.
270 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
271 // We've never completed startup.
272 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
273 CreateSyncService();
275 // Should not actually start, rather just clean things up and wait
276 // to be enabled.
277 EXPECT_CALL(*components_factory_mock(),
278 CreateDataTypeManager(_, _, _, _, _)).Times(0);
279 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
280 sync_->Initialize();
282 // Preferences should be back to defaults.
283 EXPECT_EQ(
285 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
286 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
287 sync_driver::prefs::kSyncHasSetupCompleted));
289 // Then start things up.
290 sync_->SetSetupInProgress(true);
292 // Simulate successful signin as test_user.
293 SimulateTestUserSignin();
295 ProfileOAuth2TokenService* token_service =
296 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
297 token_service->LoadCredentials("test_user@gmail.com");
299 sync_->SetSetupInProgress(false);
300 // ProfileSyncService should try to start by requesting access token.
301 // This request should fail as login token was not issued.
302 EXPECT_FALSE(sync_->SyncActive());
303 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP,
304 sync_->GetAuthError().state());
307 // TODO(pavely): Reenable test once android is switched to oauth2.
308 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
309 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
310 "test_user@gmail.com");
311 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com");
312 CreateSyncService();
313 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
315 // Tell the backend to stall while downloading control types (simulating an
316 // auth error).
317 mock_sbh->set_fail_initial_download(true);
319 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
320 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
322 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
323 sync_->Initialize();
324 EXPECT_FALSE(sync_->SyncActive());
325 Mock::VerifyAndClearExpectations(data_type_manager);
327 // Update the credentials, unstalling the backend.
328 EXPECT_CALL(*data_type_manager, Configure(_, _));
329 EXPECT_CALL(*data_type_manager, state()).
330 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
331 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
332 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
333 sync_->SetSetupInProgress(true);
335 // Simulate successful signin.
336 SimulateTestUserSignin();
338 sync_->SetSetupInProgress(false);
340 // Verify we successfully finish startup and configuration.
341 EXPECT_TRUE(sync_->SyncActive());
344 #if defined(OS_WIN)
345 // http://crbug.com/396402
346 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials
347 #else
348 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials
349 #endif
350 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) {
351 EXPECT_CALL(*components_factory_mock(),
352 CreateDataTypeManager(_, _, _, _, _)).Times(0);
353 EXPECT_CALL(*components_factory_mock(),
354 CreateSyncBackendHost(_, _, _, _, _)).Times(0);
355 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
356 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
358 sync_->Initialize();
359 // Sync should not start because there are no tokens yet.
360 EXPECT_FALSE(sync_->SyncActive());
361 sync_->SetSetupInProgress(false);
363 // Sync should not start because there are still no tokens.
364 EXPECT_FALSE(sync_->SyncActive());
367 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) {
368 SetUpSyncBackendHost();
369 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
370 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
371 EXPECT_CALL(*data_type_manager, Configure(_, _));
372 EXPECT_CALL(*data_type_manager, state()).
373 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
374 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
375 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
377 IssueTestTokens();
378 sync_->Initialize();
379 EXPECT_TRUE(sync_->SyncActive());
382 #if defined(OS_WIN)
383 // http://crbug.com/396402
384 #define MAYBE_StartNormal DISABLED_StartNormal
385 #else
386 #define MAYBE_StartNormal StartNormal
387 #endif
388 TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartNormal) {
389 // Pre load the tokens
390 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
391 "test_user@gmail.com");
392 SigninManagerFactory::GetForProfile(profile_)
393 ->SetAuthenticatedUsername("test_user@gmail.com");
394 CreateSyncService();
395 sync_->SetSyncSetupCompleted();
396 SetUpSyncBackendHost();
397 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
398 EXPECT_CALL(*data_type_manager, Configure(_, _));
399 EXPECT_CALL(*data_type_manager, state()).
400 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
401 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
402 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
404 IssueTestTokens();
406 sync_->Initialize();
409 // Test that we can recover from a case where a bug in the code resulted in
410 // OnUserChoseDatatypes not being properly called and datatype preferences
411 // therefore being left unset.
412 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
413 // Clear the datatype preference fields (simulating bug 154940).
414 profile_->GetPrefs()->ClearPref(
415 sync_driver::prefs::kSyncKeepEverythingSynced);
416 syncer::ModelTypeSet user_types = syncer::UserTypes();
417 for (syncer::ModelTypeSet::Iterator iter = user_types.First();
418 iter.Good(); iter.Inc()) {
419 profile_->GetPrefs()->ClearPref(
420 sync_driver::SyncPrefs::GetPrefNameForDataType(iter.Get()));
423 // Pre load the tokens
424 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
425 "test_user@gmail.com");
426 SigninManagerFactory::GetForProfile(profile_)
427 ->SetAuthenticatedUsername("test_user@gmail.com");
428 CreateSyncService();
429 sync_->SetSyncSetupCompleted();
430 SetUpSyncBackendHost();
431 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
432 EXPECT_CALL(*data_type_manager, Configure(_, _));
433 EXPECT_CALL(*data_type_manager, state()).
434 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
435 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
436 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
438 IssueTestTokens();
439 sync_->Initialize();
441 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(
442 sync_driver::prefs::kSyncKeepEverythingSynced));
445 // Verify that the recovery of datatype preferences doesn't overwrite a valid
446 // case where only bookmarks are enabled.
447 #if defined(OS_WIN)
448 // http://crbug.com/396402
449 #define MAYBE_StartDontRecoverDatatypePrefs DISABLED_StartDontRecoverDatatypePrefs
450 #else
451 #define MAYBE_StartDontRecoverDatatypePrefs StartDontRecoverDatatypePrefs
452 #endif
453 TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartDontRecoverDatatypePrefs) {
454 // Explicitly set Keep Everything Synced to false and have only bookmarks
455 // enabled.
456 profile_->GetPrefs()->SetBoolean(
457 sync_driver::prefs::kSyncKeepEverythingSynced, false);
459 // Pre load the tokens
460 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
461 "test_user@gmail.com");
462 SigninManagerFactory::GetForProfile(profile_)
463 ->SetAuthenticatedUsername("test_user@gmail.com");
464 CreateSyncService();
465 sync_->SetSyncSetupCompleted();
466 SetUpSyncBackendHost();
467 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
468 EXPECT_CALL(*data_type_manager, Configure(_, _));
469 EXPECT_CALL(*data_type_manager, state()).
470 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
471 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
472 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
473 IssueTestTokens();
474 sync_->Initialize();
476 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
477 sync_driver::prefs::kSyncKeepEverythingSynced));
480 #if defined(OS_WIN)
481 // http://crbug.com/396402
482 #define MAYBE_ManagedStartup DISABLED_ManagedStartup
483 #else
484 #define MAYBE_ManagedStartup ManagedStartup
485 #endif
486 TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) {
487 // Service should not be started by Initialize() since it's managed.
488 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
489 "test_user@gmail.com");
490 CreateSyncService();
492 // Disable sync through policy.
493 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
494 EXPECT_CALL(*components_factory_mock(),
495 CreateDataTypeManager(_, _, _, _, _)).Times(0);
496 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
498 sync_->Initialize();
501 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
502 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
503 "test_user@gmail.com");
504 SigninManagerFactory::GetForProfile(profile_)
505 ->SetAuthenticatedUsername("test_user@gmail.com");
506 CreateSyncService();
507 sync_->SetSyncSetupCompleted();
508 SetUpSyncBackendHost();
509 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
510 EXPECT_CALL(*data_type_manager, Configure(_, _));
511 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
512 IssueTestTokens();
513 sync_->Initialize();
515 // The service should stop when switching to managed mode.
516 Mock::VerifyAndClearExpectations(data_type_manager);
517 EXPECT_CALL(*data_type_manager, state()).
518 WillOnce(Return(DataTypeManager::CONFIGURED));
519 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
520 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
521 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
523 // When switching back to unmanaged, the state should change, but the service
524 // should not start up automatically (kSyncSetupCompleted will be false).
525 Mock::VerifyAndClearExpectations(data_type_manager);
526 EXPECT_CALL(*components_factory_mock(),
527 CreateDataTypeManager(_, _, _, _, _)).Times(0);
528 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
529 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged);
532 TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
533 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
534 "test_user@gmail.com");
535 SigninManagerFactory::GetForProfile(profile_)
536 ->SetAuthenticatedUsername("test_user@gmail.com");
537 CreateSyncService();
538 sync_->SetSyncSetupCompleted();
539 SetUpSyncBackendHost();
540 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
541 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED;
542 DataTypeManager::ConfigureResult result(
543 status,
544 syncer::ModelTypeSet());
545 EXPECT_CALL(*data_type_manager, Configure(_, _)).WillRepeatedly(
546 DoAll(InvokeOnConfigureStart(sync_),
547 InvokeOnConfigureDone(
548 sync_,
549 base::Bind(&ProfileSyncServiceStartupTest::SetError,
550 base::Unretained(this)),
551 result)));
552 EXPECT_CALL(*data_type_manager, state()).
553 WillOnce(Return(DataTypeManager::STOPPED));
554 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
555 IssueTestTokens();
556 sync_->Initialize();
557 EXPECT_TRUE(sync_->HasUnrecoverableError());
560 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
561 // Pre load the tokens
562 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
563 "test_user@gmail.com");
564 SigninManagerFactory::GetForProfile(profile_)
565 ->SetAuthenticatedUsername("test_user@gmail.com");
566 CreateSyncService();
567 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
568 mock_sbh->set_fail_initial_download(true);
570 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
572 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
573 sync_->Initialize();
575 sync_->SetSetupInProgress(true);
576 IssueTestTokens();
577 sync_->SetSetupInProgress(false);
578 EXPECT_FALSE(sync_->SyncActive());