Infobar material design refresh: bg color
[chromium-blink-merge.git] / chrome / browser / sync / profile_sync_service_startup_unittest.cc
blobd5d3c3c192ebffe2d2bb34e5962f065e66f5680d
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/account_tracker_service_factory.h"
11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
12 #include "chrome/browser/signin/fake_signin_manager_builder.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.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/sync/profile_sync_test_util.h"
20 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h"
21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_browser_process.h"
23 #include "chrome/test/base/testing_profile.h"
24 #include "chrome/test/base/testing_profile_manager.h"
25 #include "components/signin/core/browser/account_tracker_service.h"
26 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
27 #include "components/signin/core/browser/profile_oauth2_token_service.h"
28 #include "components/signin/core/browser/signin_manager.h"
29 #include "components/sync_driver/data_type_manager.h"
30 #include "components/sync_driver/data_type_manager_mock.h"
31 #include "components/sync_driver/pref_names.h"
32 #include "components/sync_driver/sync_prefs.h"
33 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "content/public/test/test_utils.h"
35 #include "google_apis/gaia/gaia_auth_consumer.h"
36 #include "google_apis/gaia/gaia_constants.h"
37 #include "google_apis/gaia/oauth2_token_service.h"
38 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h"
41 using browser_sync::SyncBackendHostMock;
42 using content::BrowserThread;
43 using sync_driver::DataTypeManager;
44 using sync_driver::DataTypeManagerMock;
45 using testing::_;
46 using testing::AnyNumber;
47 using testing::DoAll;
48 using testing::InvokeArgument;
49 using testing::Mock;
50 using testing::Return;
51 using testing::SaveArg;
53 namespace {
55 const char kGaiaId[] = "12345";
56 const char kEmail[] = "test_user@gmail.com";
57 const char kDummyPassword[] = "";
59 } // namespace
61 ACTION_P(InvokeOnConfigureStart, pss) {
62 ProfileSyncService* service =
63 static_cast<ProfileSyncService*>(pss);
64 service->OnConfigureStart();
67 ACTION_P3(InvokeOnConfigureDone, pss, error_callback, result) {
68 ProfileSyncService* service =
69 static_cast<ProfileSyncService*>(pss);
70 DataTypeManager::ConfigureResult configure_result =
71 static_cast<DataTypeManager::ConfigureResult>(result);
72 if (result.status == sync_driver::DataTypeManager::ABORTED)
73 error_callback.Run(&configure_result);
74 service->OnConfigureDone(configure_result);
77 class TestProfileSyncServiceNoBackup : public ProfileSyncService {
78 public:
79 TestProfileSyncServiceNoBackup(
80 scoped_ptr<sync_driver::SyncApiComponentFactory> factory,
81 Profile* profile,
82 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper,
83 ProfileOAuth2TokenService* oauth2_token_service,
84 browser_sync::ProfileSyncServiceStartBehavior start_behavior)
85 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(),
86 oauth2_token_service, start_behavior) {}
88 protected:
89 bool NeedBackup() const override { return false; }
92 class ProfileSyncServiceStartupTest : public testing::Test {
93 public:
94 ProfileSyncServiceStartupTest()
95 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD |
96 content::TestBrowserThreadBundle::REAL_FILE_THREAD |
97 content::TestBrowserThreadBundle::REAL_IO_THREAD),
98 profile_manager_(TestingBrowserProcess::GetGlobal()),
99 sync_(NULL) {}
101 ~ProfileSyncServiceStartupTest() override {}
103 void SetUp() override {
104 CHECK(profile_manager_.SetUp());
106 TestingProfile::TestingFactories testing_facotries;
107 testing_facotries.push_back(std::make_pair(
108 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase));
109 testing_facotries.push_back(
110 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(),
111 BuildAutoIssuingFakeProfileOAuth2TokenService));
112 testing_facotries.push_back(
113 std::make_pair(ProfileSyncServiceFactory::GetInstance(),
114 BuildService));
116 profile_ = profile_manager_.CreateTestingProfile(
117 "sync-startup-test", scoped_ptr<PrefServiceSyncable>(),
118 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(),
119 testing_facotries);
122 void TearDown() override { sync_->RemoveObserver(&observer_); }
124 static scoped_ptr<KeyedService> BuildService(
125 content::BrowserContext* browser_context) {
126 Profile* profile = static_cast<Profile*>(browser_context);
127 return make_scoped_ptr(new TestProfileSyncServiceNoBackup(
128 scoped_ptr<sync_driver::SyncApiComponentFactory>(
129 new ProfileSyncComponentsFactoryMock()),
130 profile, make_scoped_ptr(new SupervisedUserSigninManagerWrapper(
131 profile, SigninManagerFactory::GetForProfile(profile))),
132 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
133 browser_sync::MANUAL_START));
136 void CreateSyncService() {
137 sync_ = static_cast<ProfileSyncService*>(
138 ProfileSyncServiceFactory::GetForProfile(profile_));
139 sync_->AddObserver(&observer_);
142 void IssueTestTokens(const std::string& account_id) {
143 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
144 ->UpdateCredentials(account_id, "oauth2_login_token");
147 ProfileSyncComponentsFactoryMock* components_factory_mock() {
148 return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory());
151 FakeSigninManagerForTesting* fake_signin() {
152 return static_cast<FakeSigninManagerForTesting*>(sync_->signin());
155 void SetError(DataTypeManager::ConfigureResult* result) {
156 sync_driver::DataTypeStatusTable::TypeErrorMap errors;
157 errors[syncer::BOOKMARKS] =
158 syncer::SyncError(FROM_HERE,
159 syncer::SyncError::UNRECOVERABLE_ERROR,
160 "Error",
161 syncer::BOOKMARKS);
162 result->data_type_status_table.UpdateFailedDataTypes(errors);
165 protected:
166 static std::string SimulateTestUserSignin(
167 Profile* profile,
168 FakeSigninManagerForTesting* fake_signin,
169 ProfileSyncService* sync) {
170 std::string account_id =
171 AccountTrackerServiceFactory::GetForProfile(profile)
172 ->SeedAccountInfo(kGaiaId, kEmail);
173 profile->GetPrefs()->SetString(prefs::kGoogleServicesAccountId,
174 account_id);
175 #if !defined(OS_CHROMEOS)
176 fake_signin->SignIn(kGaiaId, kEmail, kDummyPassword);
177 #else
178 fake_signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail);
179 if (sync)
180 sync->GoogleSigninSucceeded(account_id, kEmail, kDummyPassword);
181 #endif
182 return account_id;
185 DataTypeManagerMock* SetUpDataTypeManager() {
186 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock();
187 EXPECT_CALL(*components_factory_mock(),
188 CreateDataTypeManager(_, _, _, _, _)).
189 WillOnce(Return(data_type_manager));
190 return data_type_manager;
193 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() {
194 browser_sync::SyncBackendHostMock* sync_backend_host =
195 new browser_sync::SyncBackendHostMock();
196 EXPECT_CALL(*components_factory_mock(),
197 CreateSyncBackendHost(_, _, _, _)).
198 WillOnce(Return(sync_backend_host));
199 return sync_backend_host;
202 content::TestBrowserThreadBundle thread_bundle_;
203 TestingProfileManager profile_manager_;
204 TestingProfile* profile_;
205 ProfileSyncService* sync_;
206 SyncServiceObserverMock observer_;
207 sync_driver::DataTypeStatusTable data_type_status_table_;
210 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
211 public:
212 void SetUp() override {
213 ProfileSyncServiceStartupTest::SetUp();
214 sync_ = static_cast<ProfileSyncService*>(
215 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
216 profile_, BuildCrosService));
217 sync_->AddObserver(&observer_);
220 static scoped_ptr<KeyedService> BuildCrosService(
221 content::BrowserContext* context) {
222 Profile* profile = static_cast<Profile*>(context);
223 FakeSigninManagerForTesting* signin =
224 static_cast<FakeSigninManagerForTesting*>(
225 SigninManagerFactory::GetForProfile(profile));
226 SimulateTestUserSignin(profile, signin, nullptr);
227 ProfileOAuth2TokenService* oauth2_token_service =
228 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
229 EXPECT_TRUE(signin->IsAuthenticated());
230 return make_scoped_ptr(new TestProfileSyncServiceNoBackup(
231 scoped_ptr<sync_driver::SyncApiComponentFactory>(
232 new ProfileSyncComponentsFactoryMock()),
233 profile, make_scoped_ptr(
234 new SupervisedUserSigninManagerWrapper(profile, signin)),
235 oauth2_token_service, browser_sync::AUTO_START));
239 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
240 // We've never completed startup.
241 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
242 CreateSyncService();
243 SetUpSyncBackendHost();
244 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
245 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
247 // Should not actually start, rather just clean things up and wait
248 // to be enabled.
249 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
250 sync_->Initialize();
252 // Preferences should be back to defaults.
253 EXPECT_EQ(
255 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
256 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
257 sync_driver::prefs::kSyncHasSetupCompleted));
258 Mock::VerifyAndClearExpectations(data_type_manager);
260 // Then start things up.
261 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
262 EXPECT_CALL(*data_type_manager, state()).
263 WillOnce(Return(DataTypeManager::CONFIGURED)).
264 WillOnce(Return(DataTypeManager::CONFIGURED));
265 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
266 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
268 sync_->SetSetupInProgress(true);
270 // Simulate successful signin as test_user.
271 std::string account_id =
272 SimulateTestUserSignin(profile_, fake_signin(), sync_);
273 // Create some tokens in the token service.
274 IssueTestTokens(account_id);
276 // Simulate the UI telling sync it has finished setting up.
277 sync_->SetSetupInProgress(false);
278 EXPECT_TRUE(sync_->IsSyncActive());
281 // TODO(pavely): Reenable test once android is switched to oauth2.
282 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) {
283 // We've never completed startup.
284 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
285 CreateSyncService();
287 // Should not actually start, rather just clean things up and wait
288 // to be enabled.
289 EXPECT_CALL(*components_factory_mock(),
290 CreateDataTypeManager(_, _, _, _, _)).Times(0);
291 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
292 sync_->Initialize();
294 // Preferences should be back to defaults.
295 EXPECT_EQ(
297 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime));
298 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
299 sync_driver::prefs::kSyncHasSetupCompleted));
301 // Then start things up.
302 sync_->SetSetupInProgress(true);
304 // Simulate successful signin as test_user.
305 std::string account_id =
306 SimulateTestUserSignin(profile_, fake_signin(), sync_);
308 ProfileOAuth2TokenService* token_service =
309 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
310 token_service->LoadCredentials(account_id);
312 sync_->SetSetupInProgress(false);
313 // ProfileSyncService should try to start by requesting access token.
314 // This request should fail as login token was not issued.
315 EXPECT_FALSE(sync_->IsSyncActive());
316 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP,
317 sync_->GetAuthError().state());
320 // TODO(pavely): Reenable test once android is switched to oauth2.
321 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartInvalidCredentials) {
322 CreateSyncService();
323 std::string account_id =
324 SimulateTestUserSignin(profile_, fake_signin(), sync_);
325 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
327 // Tell the backend to stall while downloading control types (simulating an
328 // auth error).
329 mock_sbh->set_fail_initial_download(true);
331 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
332 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
334 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
335 sync_->Initialize();
336 EXPECT_FALSE(sync_->IsSyncActive());
337 Mock::VerifyAndClearExpectations(data_type_manager);
339 // Update the credentials, unstalling the backend.
340 EXPECT_CALL(*data_type_manager, Configure(_, _));
341 EXPECT_CALL(*data_type_manager, state()).
342 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
343 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
344 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
345 sync_->SetSetupInProgress(true);
347 // Simulate successful signin.
348 SimulateTestUserSignin(profile_, fake_signin(), sync_);
350 sync_->SetSetupInProgress(false);
352 // Verify we successfully finish startup and configuration.
353 EXPECT_TRUE(sync_->IsSyncActive());
356 #if defined(OS_WIN)
357 // http://crbug.com/396402
358 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials
359 #else
360 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials
361 #endif
362 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) {
363 EXPECT_CALL(*components_factory_mock(),
364 CreateDataTypeManager(_, _, _, _, _)).Times(0);
365 EXPECT_CALL(*components_factory_mock(),
366 CreateSyncBackendHost(_, _, _, _)).Times(0);
367 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
368 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
370 sync_->Initialize();
371 // Sync should not start because there are no tokens yet.
372 EXPECT_FALSE(sync_->IsSyncActive());
373 sync_->SetSetupInProgress(false);
375 // Sync should not start because there are still no tokens.
376 EXPECT_FALSE(sync_->IsSyncActive());
379 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) {
380 SetUpSyncBackendHost();
381 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
382 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
383 EXPECT_CALL(*data_type_manager, Configure(_, _));
384 EXPECT_CALL(*data_type_manager, state()).
385 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
386 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
387 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
389 IssueTestTokens(
390 AccountTrackerServiceFactory::GetForProfile(profile_)
391 ->PickAccountIdForAccount("12345", kEmail));
392 sync_->Initialize();
393 EXPECT_TRUE(sync_->IsSyncActive());
396 #if defined(OS_WIN)
397 // http://crbug.com/396402
398 #define MAYBE_StartNormal DISABLED_StartNormal
399 #else
400 #define MAYBE_StartNormal StartNormal
401 #endif
402 TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartNormal) {
403 // Pre load the tokens
404 CreateSyncService();
405 std::string account_id =
406 SimulateTestUserSignin(profile_, fake_signin(), sync_);
407 sync_->SetSyncSetupCompleted();
408 SetUpSyncBackendHost();
409 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
410 EXPECT_CALL(*data_type_manager, Configure(_, _));
411 EXPECT_CALL(*data_type_manager, state()).
412 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
413 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
414 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
416 IssueTestTokens(account_id);
418 sync_->Initialize();
421 // Test that we can recover from a case where a bug in the code resulted in
422 // OnUserChoseDatatypes not being properly called and datatype preferences
423 // therefore being left unset.
424 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) {
425 // Clear the datatype preference fields (simulating bug 154940).
426 profile_->GetPrefs()->ClearPref(
427 sync_driver::prefs::kSyncKeepEverythingSynced);
428 syncer::ModelTypeSet user_types = syncer::UserTypes();
429 for (syncer::ModelTypeSet::Iterator iter = user_types.First();
430 iter.Good(); iter.Inc()) {
431 profile_->GetPrefs()->ClearPref(
432 sync_driver::SyncPrefs::GetPrefNameForDataType(iter.Get()));
435 // Pre load the tokens
436 CreateSyncService();
437 std::string account_id =
438 SimulateTestUserSignin(profile_, fake_signin(), sync_);
439 sync_->SetSyncSetupCompleted();
440 SetUpSyncBackendHost();
441 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
442 EXPECT_CALL(*data_type_manager, Configure(_, _));
443 EXPECT_CALL(*data_type_manager, state()).
444 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
445 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
446 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
448 IssueTestTokens(account_id);
449 sync_->Initialize();
451 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean(
452 sync_driver::prefs::kSyncKeepEverythingSynced));
455 // Verify that the recovery of datatype preferences doesn't overwrite a valid
456 // case where only bookmarks are enabled.
457 #if defined(OS_WIN)
458 // http://crbug.com/396402
459 #define MAYBE_StartDontRecoverDatatypePrefs DISABLED_StartDontRecoverDatatypePrefs
460 #else
461 #define MAYBE_StartDontRecoverDatatypePrefs StartDontRecoverDatatypePrefs
462 #endif
463 TEST_F(ProfileSyncServiceStartupTest, MAYBE_StartDontRecoverDatatypePrefs) {
464 // Explicitly set Keep Everything Synced to false and have only bookmarks
465 // enabled.
466 profile_->GetPrefs()->SetBoolean(
467 sync_driver::prefs::kSyncKeepEverythingSynced, false);
469 // Pre load the tokens
470 CreateSyncService();
471 std::string account_id =
472 SimulateTestUserSignin(profile_, fake_signin(), sync_);
473 sync_->SetSyncSetupCompleted();
474 SetUpSyncBackendHost();
475 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
476 EXPECT_CALL(*data_type_manager, Configure(_, _));
477 EXPECT_CALL(*data_type_manager, state()).
478 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
479 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
480 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
481 IssueTestTokens(account_id);
482 sync_->Initialize();
484 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(
485 sync_driver::prefs::kSyncKeepEverythingSynced));
488 #if defined(OS_WIN)
489 // http://crbug.com/396402
490 #define MAYBE_ManagedStartup DISABLED_ManagedStartup
491 #else
492 #define MAYBE_ManagedStartup ManagedStartup
493 #endif
494 TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) {
495 // Service should not be started by Initialize() since it's managed.
496 profile_->GetPrefs()->SetString(prefs::kGoogleServicesAccountId,
497 kEmail);
498 CreateSyncService();
500 // Disable sync through policy.
501 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
502 EXPECT_CALL(*components_factory_mock(),
503 CreateDataTypeManager(_, _, _, _, _)).Times(0);
504 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
506 sync_->Initialize();
509 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) {
510 CreateSyncService();
511 std::string account_id =
512 SimulateTestUserSignin(profile_, fake_signin(), sync_);
513 sync_->SetSyncSetupCompleted();
514 SetUpSyncBackendHost();
515 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
516 EXPECT_CALL(*data_type_manager, Configure(_, _));
517 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
518 IssueTestTokens(account_id);
519 sync_->Initialize();
521 // The service should stop when switching to managed mode.
522 Mock::VerifyAndClearExpectations(data_type_manager);
523 EXPECT_CALL(*data_type_manager, state()).
524 WillOnce(Return(DataTypeManager::CONFIGURED));
525 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
526 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
527 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true);
529 // When switching back to unmanaged, the state should change, but the service
530 // should not start up automatically (kSyncSetupCompleted will be false).
531 Mock::VerifyAndClearExpectations(data_type_manager);
532 EXPECT_CALL(*components_factory_mock(),
533 CreateDataTypeManager(_, _, _, _, _)).Times(0);
534 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
535 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged);
538 TEST_F(ProfileSyncServiceStartupTest, StartFailure) {
539 CreateSyncService();
540 std::string account_id =
541 SimulateTestUserSignin(profile_, fake_signin(), sync_);
542 sync_->SetSyncSetupCompleted();
543 SetUpSyncBackendHost();
544 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
545 DataTypeManager::ConfigureStatus status = DataTypeManager::ABORTED;
546 DataTypeManager::ConfigureResult result(
547 status,
548 syncer::ModelTypeSet());
549 EXPECT_CALL(*data_type_manager, Configure(_, _)).WillRepeatedly(
550 DoAll(InvokeOnConfigureStart(sync_),
551 InvokeOnConfigureDone(
552 sync_,
553 base::Bind(&ProfileSyncServiceStartupTest::SetError,
554 base::Unretained(this)),
555 result)));
556 EXPECT_CALL(*data_type_manager, state()).
557 WillOnce(Return(DataTypeManager::STOPPED));
558 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
559 IssueTestTokens(account_id);
560 sync_->Initialize();
561 EXPECT_TRUE(sync_->HasUnrecoverableError());
564 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) {
565 // Pre load the tokens
566 CreateSyncService();
567 std::string account_id =
568 SimulateTestUserSignin(profile_, fake_signin(), sync_);
569 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost();
570 mock_sbh->set_fail_initial_download(true);
572 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
574 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
575 sync_->Initialize();
577 sync_->SetSetupInProgress(true);
578 IssueTestTokens(account_id);
579 sync_->SetSetupInProgress(false);
580 EXPECT_FALSE(sync_->IsSyncActive());