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.h"
12 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
13 #include "chrome/browser/signin/fake_signin_manager.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/sync/glue/sync_backend_host_mock.h"
17 #include "chrome/browser/sync/profile_sync_components_factory_mock.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/profile_oauth2_token_service.h"
27 #include "components/signin/core/browser/signin_manager.h"
28 #include "components/sync_driver/data_type_manager.h"
29 #include "components/sync_driver/data_type_manager_mock.h"
30 #include "components/sync_driver/pref_names.h"
31 #include "components/sync_driver/sync_prefs.h"
32 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "content/public/test/test_utils.h"
34 #include "google_apis/gaia/gaia_auth_consumer.h"
35 #include "google_apis/gaia/gaia_constants.h"
36 #include "google_apis/gaia/oauth2_token_service.h"
37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gtest/include/gtest/gtest.h"
40 using browser_sync::SyncBackendHostMock
;
41 using content::BrowserThread
;
42 using sync_driver::DataTypeManager
;
43 using sync_driver::DataTypeManagerMock
;
45 using testing::AnyNumber
;
47 using testing::InvokeArgument
;
49 using testing::Return
;
50 using testing::SaveArg
;
54 const char kGaiaId
[] = "12345";
55 const char kEmail
[] = "test_user@gmail.com";
56 const char kDummyPassword
[] = "";
60 ACTION_P(InvokeOnConfigureStart
, pss
) {
61 ProfileSyncService
* service
=
62 static_cast<ProfileSyncService
*>(pss
);
63 service
->OnConfigureStart();
66 ACTION_P3(InvokeOnConfigureDone
, pss
, error_callback
, result
) {
67 ProfileSyncService
* service
=
68 static_cast<ProfileSyncService
*>(pss
);
69 DataTypeManager::ConfigureResult configure_result
=
70 static_cast<DataTypeManager::ConfigureResult
>(result
);
71 if (result
.status
== sync_driver::DataTypeManager::ABORTED
)
72 error_callback
.Run(&configure_result
);
73 service
->OnConfigureDone(configure_result
);
76 class TestProfileSyncServiceNoBackup
: public ProfileSyncService
{
78 TestProfileSyncServiceNoBackup(
79 scoped_ptr
<ProfileSyncComponentsFactory
> factory
,
81 scoped_ptr
<SupervisedUserSigninManagerWrapper
> signin_wrapper
,
82 ProfileOAuth2TokenService
* oauth2_token_service
,
83 browser_sync::ProfileSyncServiceStartBehavior start_behavior
)
84 : ProfileSyncService(factory
.Pass(), profile
, signin_wrapper
.Pass(),
85 oauth2_token_service
, start_behavior
) {}
88 bool NeedBackup() const override
{ return false; }
91 class ProfileSyncServiceStartupTest
: public testing::Test
{
93 ProfileSyncServiceStartupTest()
94 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD
|
95 content::TestBrowserThreadBundle::REAL_FILE_THREAD
|
96 content::TestBrowserThreadBundle::REAL_IO_THREAD
),
97 profile_manager_(TestingBrowserProcess::GetGlobal()),
100 ~ProfileSyncServiceStartupTest() override
{}
102 void SetUp() override
{
103 CHECK(profile_manager_
.SetUp());
105 TestingProfile::TestingFactories testing_facotries
;
106 testing_facotries
.push_back(
107 std::make_pair(SigninManagerFactory::GetInstance(),
108 FakeSigninManagerBase::Build
));
109 testing_facotries
.push_back(
110 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(),
111 BuildAutoIssuingFakeProfileOAuth2TokenService
));
112 testing_facotries
.push_back(
113 std::make_pair(ProfileSyncServiceFactory::GetInstance(),
116 profile_
= profile_manager_
.CreateTestingProfile(
117 "sync-startup-test", scoped_ptr
<PrefServiceSyncable
>(),
118 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(),
122 void TearDown() override
{ sync_
->RemoveObserver(&observer_
); }
124 static KeyedService
* BuildService(content::BrowserContext
* browser_context
) {
125 Profile
* profile
= static_cast<Profile
*>(browser_context
);
126 return new TestProfileSyncServiceNoBackup(
127 scoped_ptr
<ProfileSyncComponentsFactory
>(
128 new ProfileSyncComponentsFactoryMock()),
130 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
,
162 result
->data_type_status_table
.UpdateFailedDataTypes(errors
);
166 static std::string
SimulateTestUserSignin(
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
,
175 #if !defined(OS_CHROMEOS)
176 fake_signin
->SignIn(kGaiaId
, kEmail
, kDummyPassword
);
178 fake_signin
->SetAuthenticatedAccountInfo(kGaiaId
, kEmail
);
180 sync
->GoogleSigninSucceeded(account_id
, kEmail
, kDummyPassword
);
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
{
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 KeyedService
* BuildCrosService(content::BrowserContext
* context
) {
221 Profile
* profile
= static_cast<Profile
*>(context
);
222 FakeSigninManagerForTesting
* signin
=
223 static_cast<FakeSigninManagerForTesting
*>(
224 SigninManagerFactory::GetForProfile(profile
));
225 SimulateTestUserSignin(profile
, signin
, nullptr);
226 ProfileOAuth2TokenService
* oauth2_token_service
=
227 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
);
228 EXPECT_TRUE(signin
->IsAuthenticated());
229 return new TestProfileSyncServiceNoBackup(
230 scoped_ptr
<ProfileSyncComponentsFactory
>(
231 new ProfileSyncComponentsFactoryMock()),
233 make_scoped_ptr(new SupervisedUserSigninManagerWrapper(profile
,
235 oauth2_token_service
,
236 browser_sync::AUTO_START
);
240 TEST_F(ProfileSyncServiceStartupTest
, StartFirstTime
) {
241 // We've never completed startup.
242 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
244 SetUpSyncBackendHost();
245 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
246 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).Times(0);
248 // Should not actually start, rather just clean things up and wait
250 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
253 // Preferences should be back to defaults.
256 profile_
->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime
));
257 EXPECT_FALSE(profile_
->GetPrefs()->GetBoolean(
258 sync_driver::prefs::kSyncHasSetupCompleted
));
259 Mock::VerifyAndClearExpectations(data_type_manager
);
261 // Then start things up.
262 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).Times(1);
263 EXPECT_CALL(*data_type_manager
, state()).
264 WillOnce(Return(DataTypeManager::CONFIGURED
)).
265 WillOnce(Return(DataTypeManager::CONFIGURED
));
266 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
267 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
269 sync_
->SetSetupInProgress(true);
271 // Simulate successful signin as test_user.
272 std::string account_id
=
273 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
274 // Create some tokens in the token service.
275 IssueTestTokens(account_id
);
277 // Simulate the UI telling sync it has finished setting up.
278 sync_
->SetSetupInProgress(false);
279 EXPECT_TRUE(sync_
->IsSyncActive());
282 // TODO(pavely): Reenable test once android is switched to oauth2.
283 TEST_F(ProfileSyncServiceStartupTest
, DISABLED_StartNoCredentials
) {
284 // We've never completed startup.
285 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
288 // Should not actually start, rather just clean things up and wait
290 EXPECT_CALL(*components_factory_mock(),
291 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
292 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
295 // Preferences should be back to defaults.
298 profile_
->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime
));
299 EXPECT_FALSE(profile_
->GetPrefs()->GetBoolean(
300 sync_driver::prefs::kSyncHasSetupCompleted
));
302 // Then start things up.
303 sync_
->SetSetupInProgress(true);
305 // Simulate successful signin as test_user.
306 std::string account_id
=
307 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
309 ProfileOAuth2TokenService
* token_service
=
310 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_
);
311 token_service
->LoadCredentials(account_id
);
313 sync_
->SetSetupInProgress(false);
314 // ProfileSyncService should try to start by requesting access token.
315 // This request should fail as login token was not issued.
316 EXPECT_FALSE(sync_
->IsSyncActive());
317 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP
,
318 sync_
->GetAuthError().state());
321 // TODO(pavely): Reenable test once android is switched to oauth2.
322 TEST_F(ProfileSyncServiceStartupTest
, DISABLED_StartInvalidCredentials
) {
324 std::string account_id
=
325 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
326 SyncBackendHostMock
* mock_sbh
= SetUpSyncBackendHost();
328 // Tell the backend to stall while downloading control types (simulating an
330 mock_sbh
->set_fail_initial_download(true);
332 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
333 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).Times(0);
335 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
337 EXPECT_FALSE(sync_
->IsSyncActive());
338 Mock::VerifyAndClearExpectations(data_type_manager
);
340 // Update the credentials, unstalling the backend.
341 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
342 EXPECT_CALL(*data_type_manager
, state()).
343 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
344 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
345 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
346 sync_
->SetSetupInProgress(true);
348 // Simulate successful signin.
349 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
351 sync_
->SetSetupInProgress(false);
353 // Verify we successfully finish startup and configuration.
354 EXPECT_TRUE(sync_
->IsSyncActive());
358 // http://crbug.com/396402
359 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials
361 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials
363 TEST_F(ProfileSyncServiceStartupCrosTest
, MAYBE_StartCrosNoCredentials
) {
364 EXPECT_CALL(*components_factory_mock(),
365 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
366 EXPECT_CALL(*components_factory_mock(),
367 CreateSyncBackendHost(_
, _
, _
, _
, _
)).Times(0);
368 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
369 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
372 // Sync should not start because there are no tokens yet.
373 EXPECT_FALSE(sync_
->IsSyncActive());
374 sync_
->SetSetupInProgress(false);
376 // Sync should not start because there are still no tokens.
377 EXPECT_FALSE(sync_
->IsSyncActive());
380 TEST_F(ProfileSyncServiceStartupCrosTest
, StartFirstTime
) {
381 SetUpSyncBackendHost();
382 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
383 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
384 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
385 EXPECT_CALL(*data_type_manager
, state()).
386 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
387 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
388 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
391 AccountTrackerServiceFactory::GetForProfile(profile_
)
392 ->PickAccountIdForAccount("12345", kEmail
));
394 EXPECT_TRUE(sync_
->IsSyncActive());
398 // http://crbug.com/396402
399 #define MAYBE_StartNormal DISABLED_StartNormal
401 #define MAYBE_StartNormal StartNormal
403 TEST_F(ProfileSyncServiceStartupTest
, MAYBE_StartNormal
) {
404 // Pre load the tokens
406 std::string account_id
=
407 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
408 sync_
->SetSyncSetupCompleted();
409 SetUpSyncBackendHost();
410 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
411 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
412 EXPECT_CALL(*data_type_manager
, state()).
413 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
414 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
415 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
417 IssueTestTokens(account_id
);
422 // Test that we can recover from a case where a bug in the code resulted in
423 // OnUserChoseDatatypes not being properly called and datatype preferences
424 // therefore being left unset.
425 TEST_F(ProfileSyncServiceStartupTest
, StartRecoverDatatypePrefs
) {
426 // Clear the datatype preference fields (simulating bug 154940).
427 profile_
->GetPrefs()->ClearPref(
428 sync_driver::prefs::kSyncKeepEverythingSynced
);
429 syncer::ModelTypeSet user_types
= syncer::UserTypes();
430 for (syncer::ModelTypeSet::Iterator iter
= user_types
.First();
431 iter
.Good(); iter
.Inc()) {
432 profile_
->GetPrefs()->ClearPref(
433 sync_driver::SyncPrefs::GetPrefNameForDataType(iter
.Get()));
436 // Pre load the tokens
438 std::string account_id
=
439 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
440 sync_
->SetSyncSetupCompleted();
441 SetUpSyncBackendHost();
442 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
443 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
444 EXPECT_CALL(*data_type_manager
, state()).
445 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
446 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
447 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
449 IssueTestTokens(account_id
);
452 EXPECT_TRUE(profile_
->GetPrefs()->GetBoolean(
453 sync_driver::prefs::kSyncKeepEverythingSynced
));
456 // Verify that the recovery of datatype preferences doesn't overwrite a valid
457 // case where only bookmarks are enabled.
459 // http://crbug.com/396402
460 #define MAYBE_StartDontRecoverDatatypePrefs DISABLED_StartDontRecoverDatatypePrefs
462 #define MAYBE_StartDontRecoverDatatypePrefs StartDontRecoverDatatypePrefs
464 TEST_F(ProfileSyncServiceStartupTest
, MAYBE_StartDontRecoverDatatypePrefs
) {
465 // Explicitly set Keep Everything Synced to false and have only bookmarks
467 profile_
->GetPrefs()->SetBoolean(
468 sync_driver::prefs::kSyncKeepEverythingSynced
, false);
470 // Pre load the tokens
472 std::string account_id
=
473 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
474 sync_
->SetSyncSetupCompleted();
475 SetUpSyncBackendHost();
476 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
477 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
478 EXPECT_CALL(*data_type_manager
, state()).
479 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
480 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
481 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
482 IssueTestTokens(account_id
);
485 EXPECT_FALSE(profile_
->GetPrefs()->GetBoolean(
486 sync_driver::prefs::kSyncKeepEverythingSynced
));
490 // http://crbug.com/396402
491 #define MAYBE_ManagedStartup DISABLED_ManagedStartup
493 #define MAYBE_ManagedStartup ManagedStartup
495 TEST_F(ProfileSyncServiceStartupTest
, MAYBE_ManagedStartup
) {
496 // Service should not be started by Initialize() since it's managed.
497 profile_
->GetPrefs()->SetString(prefs::kGoogleServicesAccountId
,
501 // Disable sync through policy.
502 profile_
->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged
, true);
503 EXPECT_CALL(*components_factory_mock(),
504 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
505 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
510 TEST_F(ProfileSyncServiceStartupTest
, SwitchManaged
) {
512 std::string account_id
=
513 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
514 sync_
->SetSyncSetupCompleted();
515 SetUpSyncBackendHost();
516 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
517 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
518 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
519 IssueTestTokens(account_id
);
522 // The service should stop when switching to managed mode.
523 Mock::VerifyAndClearExpectations(data_type_manager
);
524 EXPECT_CALL(*data_type_manager
, state()).
525 WillOnce(Return(DataTypeManager::CONFIGURED
));
526 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
527 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
528 profile_
->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged
, true);
530 // When switching back to unmanaged, the state should change, but the service
531 // should not start up automatically (kSyncSetupCompleted will be false).
532 Mock::VerifyAndClearExpectations(data_type_manager
);
533 EXPECT_CALL(*components_factory_mock(),
534 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
535 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
536 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged
);
539 TEST_F(ProfileSyncServiceStartupTest
, StartFailure
) {
541 std::string account_id
=
542 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
543 sync_
->SetSyncSetupCompleted();
544 SetUpSyncBackendHost();
545 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
546 DataTypeManager::ConfigureStatus status
= DataTypeManager::ABORTED
;
547 DataTypeManager::ConfigureResult
result(
549 syncer::ModelTypeSet());
550 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).WillRepeatedly(
551 DoAll(InvokeOnConfigureStart(sync_
),
552 InvokeOnConfigureDone(
554 base::Bind(&ProfileSyncServiceStartupTest::SetError
,
555 base::Unretained(this)),
557 EXPECT_CALL(*data_type_manager
, state()).
558 WillOnce(Return(DataTypeManager::STOPPED
));
559 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
560 IssueTestTokens(account_id
);
562 EXPECT_TRUE(sync_
->HasUnrecoverableError());
565 TEST_F(ProfileSyncServiceStartupTest
, StartDownloadFailed
) {
566 // Pre load the tokens
568 std::string account_id
=
569 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
570 SyncBackendHostMock
* mock_sbh
= SetUpSyncBackendHost();
571 mock_sbh
->set_fail_initial_download(true);
573 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
575 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
578 sync_
->SetSetupInProgress(true);
579 IssueTestTokens(account_id
);
580 sync_
->SetSetupInProgress(false);
581 EXPECT_FALSE(sync_
->IsSyncActive());