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_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/account_tracker_service.h"
25 #include "components/signin/core/browser/fake_profile_oauth2_token_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(std::make_pair(
107 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase
));
108 testing_facotries
.push_back(
109 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(),
110 BuildAutoIssuingFakeProfileOAuth2TokenService
));
111 testing_facotries
.push_back(
112 std::make_pair(ProfileSyncServiceFactory::GetInstance(),
115 profile_
= profile_manager_
.CreateTestingProfile(
116 "sync-startup-test", scoped_ptr
<PrefServiceSyncable
>(),
117 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(),
121 void TearDown() override
{ sync_
->RemoveObserver(&observer_
); }
123 static scoped_ptr
<KeyedService
> BuildService(
124 content::BrowserContext
* browser_context
) {
125 Profile
* profile
= static_cast<Profile
*>(browser_context
);
126 return make_scoped_ptr(new TestProfileSyncServiceNoBackup(
127 scoped_ptr
<ProfileSyncComponentsFactory
>(
128 new ProfileSyncComponentsFactoryMock()),
129 profile
, make_scoped_ptr(new SupervisedUserSigninManagerWrapper(
130 profile
, SigninManagerFactory::GetForProfile(profile
))),
131 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
132 browser_sync::MANUAL_START
));
135 void CreateSyncService() {
136 sync_
= static_cast<ProfileSyncService
*>(
137 ProfileSyncServiceFactory::GetForProfile(profile_
));
138 sync_
->AddObserver(&observer_
);
141 void IssueTestTokens(const std::string
& account_id
) {
142 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_
)
143 ->UpdateCredentials(account_id
, "oauth2_login_token");
146 ProfileSyncComponentsFactoryMock
* components_factory_mock() {
147 return static_cast<ProfileSyncComponentsFactoryMock
*>(sync_
->factory());
150 FakeSigninManagerForTesting
* fake_signin() {
151 return static_cast<FakeSigninManagerForTesting
*>(sync_
->signin());
154 void SetError(DataTypeManager::ConfigureResult
* result
) {
155 sync_driver::DataTypeStatusTable::TypeErrorMap errors
;
156 errors
[syncer::BOOKMARKS
] =
157 syncer::SyncError(FROM_HERE
,
158 syncer::SyncError::UNRECOVERABLE_ERROR
,
161 result
->data_type_status_table
.UpdateFailedDataTypes(errors
);
165 static std::string
SimulateTestUserSignin(
167 FakeSigninManagerForTesting
* fake_signin
,
168 ProfileSyncService
* sync
) {
169 std::string account_id
=
170 AccountTrackerServiceFactory::GetForProfile(profile
)
171 ->SeedAccountInfo(kGaiaId
, kEmail
);
172 profile
->GetPrefs()->SetString(prefs::kGoogleServicesAccountId
,
174 #if !defined(OS_CHROMEOS)
175 fake_signin
->SignIn(kGaiaId
, kEmail
, kDummyPassword
);
177 fake_signin
->SetAuthenticatedAccountInfo(kGaiaId
, kEmail
);
179 sync
->GoogleSigninSucceeded(account_id
, kEmail
, kDummyPassword
);
184 DataTypeManagerMock
* SetUpDataTypeManager() {
185 DataTypeManagerMock
* data_type_manager
= new DataTypeManagerMock();
186 EXPECT_CALL(*components_factory_mock(),
187 CreateDataTypeManager(_
, _
, _
, _
, _
)).
188 WillOnce(Return(data_type_manager
));
189 return data_type_manager
;
192 browser_sync::SyncBackendHostMock
* SetUpSyncBackendHost() {
193 browser_sync::SyncBackendHostMock
* sync_backend_host
=
194 new browser_sync::SyncBackendHostMock();
195 EXPECT_CALL(*components_factory_mock(),
196 CreateSyncBackendHost(_
, _
, _
, _
, _
)).
197 WillOnce(Return(sync_backend_host
));
198 return sync_backend_host
;
201 content::TestBrowserThreadBundle thread_bundle_
;
202 TestingProfileManager profile_manager_
;
203 TestingProfile
* profile_
;
204 ProfileSyncService
* sync_
;
205 SyncServiceObserverMock observer_
;
206 sync_driver::DataTypeStatusTable data_type_status_table_
;
209 class ProfileSyncServiceStartupCrosTest
: public ProfileSyncServiceStartupTest
{
211 void SetUp() override
{
212 ProfileSyncServiceStartupTest::SetUp();
213 sync_
= static_cast<ProfileSyncService
*>(
214 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
215 profile_
, BuildCrosService
));
216 sync_
->AddObserver(&observer_
);
219 static scoped_ptr
<KeyedService
> BuildCrosService(
220 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 make_scoped_ptr(new TestProfileSyncServiceNoBackup(
230 scoped_ptr
<ProfileSyncComponentsFactory
>(
231 new ProfileSyncComponentsFactoryMock()),
232 profile
, make_scoped_ptr(
233 new SupervisedUserSigninManagerWrapper(profile
, signin
)),
234 oauth2_token_service
, browser_sync::AUTO_START
));
238 TEST_F(ProfileSyncServiceStartupTest
, StartFirstTime
) {
239 // We've never completed startup.
240 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
242 SetUpSyncBackendHost();
243 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
244 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).Times(0);
246 // Should not actually start, rather just clean things up and wait
248 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
251 // Preferences should be back to defaults.
254 profile_
->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime
));
255 EXPECT_FALSE(profile_
->GetPrefs()->GetBoolean(
256 sync_driver::prefs::kSyncHasSetupCompleted
));
257 Mock::VerifyAndClearExpectations(data_type_manager
);
259 // Then start things up.
260 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).Times(1);
261 EXPECT_CALL(*data_type_manager
, state()).
262 WillOnce(Return(DataTypeManager::CONFIGURED
)).
263 WillOnce(Return(DataTypeManager::CONFIGURED
));
264 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
265 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
267 sync_
->SetSetupInProgress(true);
269 // Simulate successful signin as test_user.
270 std::string account_id
=
271 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
272 // Create some tokens in the token service.
273 IssueTestTokens(account_id
);
275 // Simulate the UI telling sync it has finished setting up.
276 sync_
->SetSetupInProgress(false);
277 EXPECT_TRUE(sync_
->IsSyncActive());
280 // TODO(pavely): Reenable test once android is switched to oauth2.
281 TEST_F(ProfileSyncServiceStartupTest
, DISABLED_StartNoCredentials
) {
282 // We've never completed startup.
283 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
286 // Should not actually start, rather just clean things up and wait
288 EXPECT_CALL(*components_factory_mock(),
289 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
290 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
293 // Preferences should be back to defaults.
296 profile_
->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime
));
297 EXPECT_FALSE(profile_
->GetPrefs()->GetBoolean(
298 sync_driver::prefs::kSyncHasSetupCompleted
));
300 // Then start things up.
301 sync_
->SetSetupInProgress(true);
303 // Simulate successful signin as test_user.
304 std::string account_id
=
305 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
307 ProfileOAuth2TokenService
* token_service
=
308 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_
);
309 token_service
->LoadCredentials(account_id
);
311 sync_
->SetSetupInProgress(false);
312 // ProfileSyncService should try to start by requesting access token.
313 // This request should fail as login token was not issued.
314 EXPECT_FALSE(sync_
->IsSyncActive());
315 EXPECT_EQ(GoogleServiceAuthError::USER_NOT_SIGNED_UP
,
316 sync_
->GetAuthError().state());
319 // TODO(pavely): Reenable test once android is switched to oauth2.
320 TEST_F(ProfileSyncServiceStartupTest
, DISABLED_StartInvalidCredentials
) {
322 std::string account_id
=
323 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
324 SyncBackendHostMock
* mock_sbh
= SetUpSyncBackendHost();
326 // Tell the backend to stall while downloading control types (simulating an
328 mock_sbh
->set_fail_initial_download(true);
330 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
331 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).Times(0);
333 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
335 EXPECT_FALSE(sync_
->IsSyncActive());
336 Mock::VerifyAndClearExpectations(data_type_manager
);
338 // Update the credentials, unstalling the backend.
339 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
340 EXPECT_CALL(*data_type_manager
, state()).
341 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
342 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
343 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
344 sync_
->SetSetupInProgress(true);
346 // Simulate successful signin.
347 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
349 sync_
->SetSetupInProgress(false);
351 // Verify we successfully finish startup and configuration.
352 EXPECT_TRUE(sync_
->IsSyncActive());
356 // http://crbug.com/396402
357 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials
359 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials
361 TEST_F(ProfileSyncServiceStartupCrosTest
, MAYBE_StartCrosNoCredentials
) {
362 EXPECT_CALL(*components_factory_mock(),
363 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
364 EXPECT_CALL(*components_factory_mock(),
365 CreateSyncBackendHost(_
, _
, _
, _
, _
)).Times(0);
366 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
367 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
370 // Sync should not start because there are no tokens yet.
371 EXPECT_FALSE(sync_
->IsSyncActive());
372 sync_
->SetSetupInProgress(false);
374 // Sync should not start because there are still no tokens.
375 EXPECT_FALSE(sync_
->IsSyncActive());
378 TEST_F(ProfileSyncServiceStartupCrosTest
, StartFirstTime
) {
379 SetUpSyncBackendHost();
380 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
381 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
382 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
383 EXPECT_CALL(*data_type_manager
, state()).
384 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
385 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
386 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
389 AccountTrackerServiceFactory::GetForProfile(profile_
)
390 ->PickAccountIdForAccount("12345", kEmail
));
392 EXPECT_TRUE(sync_
->IsSyncActive());
396 // http://crbug.com/396402
397 #define MAYBE_StartNormal DISABLED_StartNormal
399 #define MAYBE_StartNormal StartNormal
401 TEST_F(ProfileSyncServiceStartupTest
, MAYBE_StartNormal
) {
402 // Pre load the tokens
404 std::string account_id
=
405 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
406 sync_
->SetSyncSetupCompleted();
407 SetUpSyncBackendHost();
408 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
409 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
410 EXPECT_CALL(*data_type_manager
, state()).
411 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
412 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
413 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
415 IssueTestTokens(account_id
);
420 // Test that we can recover from a case where a bug in the code resulted in
421 // OnUserChoseDatatypes not being properly called and datatype preferences
422 // therefore being left unset.
423 TEST_F(ProfileSyncServiceStartupTest
, StartRecoverDatatypePrefs
) {
424 // Clear the datatype preference fields (simulating bug 154940).
425 profile_
->GetPrefs()->ClearPref(
426 sync_driver::prefs::kSyncKeepEverythingSynced
);
427 syncer::ModelTypeSet user_types
= syncer::UserTypes();
428 for (syncer::ModelTypeSet::Iterator iter
= user_types
.First();
429 iter
.Good(); iter
.Inc()) {
430 profile_
->GetPrefs()->ClearPref(
431 sync_driver::SyncPrefs::GetPrefNameForDataType(iter
.Get()));
434 // Pre load the tokens
436 std::string account_id
=
437 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
438 sync_
->SetSyncSetupCompleted();
439 SetUpSyncBackendHost();
440 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
441 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
442 EXPECT_CALL(*data_type_manager
, state()).
443 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
444 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
445 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
447 IssueTestTokens(account_id
);
450 EXPECT_TRUE(profile_
->GetPrefs()->GetBoolean(
451 sync_driver::prefs::kSyncKeepEverythingSynced
));
454 // Verify that the recovery of datatype preferences doesn't overwrite a valid
455 // case where only bookmarks are enabled.
457 // http://crbug.com/396402
458 #define MAYBE_StartDontRecoverDatatypePrefs DISABLED_StartDontRecoverDatatypePrefs
460 #define MAYBE_StartDontRecoverDatatypePrefs StartDontRecoverDatatypePrefs
462 TEST_F(ProfileSyncServiceStartupTest
, MAYBE_StartDontRecoverDatatypePrefs
) {
463 // Explicitly set Keep Everything Synced to false and have only bookmarks
465 profile_
->GetPrefs()->SetBoolean(
466 sync_driver::prefs::kSyncKeepEverythingSynced
, false);
468 // Pre load the tokens
470 std::string account_id
=
471 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
472 sync_
->SetSyncSetupCompleted();
473 SetUpSyncBackendHost();
474 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
475 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
476 EXPECT_CALL(*data_type_manager
, state()).
477 WillRepeatedly(Return(DataTypeManager::CONFIGURED
));
478 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
479 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
480 IssueTestTokens(account_id
);
483 EXPECT_FALSE(profile_
->GetPrefs()->GetBoolean(
484 sync_driver::prefs::kSyncKeepEverythingSynced
));
488 // http://crbug.com/396402
489 #define MAYBE_ManagedStartup DISABLED_ManagedStartup
491 #define MAYBE_ManagedStartup ManagedStartup
493 TEST_F(ProfileSyncServiceStartupTest
, MAYBE_ManagedStartup
) {
494 // Service should not be started by Initialize() since it's managed.
495 profile_
->GetPrefs()->SetString(prefs::kGoogleServicesAccountId
,
499 // Disable sync through policy.
500 profile_
->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged
, true);
501 EXPECT_CALL(*components_factory_mock(),
502 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
503 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
508 TEST_F(ProfileSyncServiceStartupTest
, SwitchManaged
) {
510 std::string account_id
=
511 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
512 sync_
->SetSyncSetupCompleted();
513 SetUpSyncBackendHost();
514 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
515 EXPECT_CALL(*data_type_manager
, Configure(_
, _
));
516 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
517 IssueTestTokens(account_id
);
520 // The service should stop when switching to managed mode.
521 Mock::VerifyAndClearExpectations(data_type_manager
);
522 EXPECT_CALL(*data_type_manager
, state()).
523 WillOnce(Return(DataTypeManager::CONFIGURED
));
524 EXPECT_CALL(*data_type_manager
, Stop()).Times(1);
525 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
526 profile_
->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged
, true);
528 // When switching back to unmanaged, the state should change, but the service
529 // should not start up automatically (kSyncSetupCompleted will be false).
530 Mock::VerifyAndClearExpectations(data_type_manager
);
531 EXPECT_CALL(*components_factory_mock(),
532 CreateDataTypeManager(_
, _
, _
, _
, _
)).Times(0);
533 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
534 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged
);
537 TEST_F(ProfileSyncServiceStartupTest
, StartFailure
) {
539 std::string account_id
=
540 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
541 sync_
->SetSyncSetupCompleted();
542 SetUpSyncBackendHost();
543 DataTypeManagerMock
* data_type_manager
= SetUpDataTypeManager();
544 DataTypeManager::ConfigureStatus status
= DataTypeManager::ABORTED
;
545 DataTypeManager::ConfigureResult
result(
547 syncer::ModelTypeSet());
548 EXPECT_CALL(*data_type_manager
, Configure(_
, _
)).WillRepeatedly(
549 DoAll(InvokeOnConfigureStart(sync_
),
550 InvokeOnConfigureDone(
552 base::Bind(&ProfileSyncServiceStartupTest::SetError
,
553 base::Unretained(this)),
555 EXPECT_CALL(*data_type_manager
, state()).
556 WillOnce(Return(DataTypeManager::STOPPED
));
557 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
558 IssueTestTokens(account_id
);
560 EXPECT_TRUE(sync_
->HasUnrecoverableError());
563 TEST_F(ProfileSyncServiceStartupTest
, StartDownloadFailed
) {
564 // Pre load the tokens
566 std::string account_id
=
567 SimulateTestUserSignin(profile_
, fake_signin(), sync_
);
568 SyncBackendHostMock
* mock_sbh
= SetUpSyncBackendHost();
569 mock_sbh
->set_fail_initial_download(true);
571 profile_
->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted
);
573 EXPECT_CALL(observer_
, OnStateChanged()).Times(AnyNumber());
576 sync_
->SetSetupInProgress(true);
577 IssueTestTokens(account_id
);
578 sync_
->SetSetupInProgress(false);
579 EXPECT_FALSE(sync_
->IsSyncActive());