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
;
46 using testing::AnyNumber
;
48 using testing::InvokeArgument
;
50 using testing::Return
;
51 using testing::SaveArg
;
55 const char kGaiaId
[] = "12345";
56 const char kEmail
[] = "test_user@gmail.com";
57 const char kDummyPassword
[] = "";
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
{
79 TestProfileSyncServiceNoBackup(
80 scoped_ptr
<sync_driver::SyncApiComponentFactory
> factory
,
82 scoped_ptr
<SigninManagerWrapper
> 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
) {}
89 bool NeedBackup() const override
{ return false; }
92 class ProfileSyncServiceStartupTest
: public testing::Test
{
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()),
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(),
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 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 SigninManagerWrapper(
131 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 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(new SigninManagerWrapper(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());