OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" | 9 #include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h" |
10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" | 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.h" |
12 #include "chrome/browser/signin/fake_signin_manager.h" | 12 #include "chrome/browser/signin/fake_signin_manager.h" |
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
14 #include "chrome/browser/signin/signin_manager.h" | 14 #include "chrome/browser/signin/signin_manager.h" |
15 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
16 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | 16 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" |
17 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 17 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
18 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
19 #include "chrome/browser/sync/profile_sync_test_util.h" | 19 #include "chrome/browser/sync/profile_sync_test_util.h" |
20 #include "chrome/browser/sync/sync_prefs.h" | |
21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
22 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
23 #include "components/signin/core/profile_oauth2_token_service.h" | 22 #include "components/signin/core/profile_oauth2_token_service.h" |
24 #include "components/sync_driver/data_type_manager.h" | 23 #include "components/sync_driver/data_type_manager.h" |
25 #include "components/sync_driver/data_type_manager_mock.h" | 24 #include "components/sync_driver/data_type_manager_mock.h" |
| 25 #include "components/sync_driver/pref_names.h" |
| 26 #include "components/sync_driver/sync_prefs.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
28 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
30 #include "google_apis/gaia/gaia_auth_consumer.h" | 31 #include "google_apis/gaia/gaia_auth_consumer.h" |
31 #include "google_apis/gaia/gaia_constants.h" | 32 #include "google_apis/gaia/gaia_constants.h" |
32 #include "google_apis/gaia/oauth2_token_service.h" | 33 #include "google_apis/gaia/oauth2_token_service.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
35 | 36 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 new ProfileSyncComponentsFactoryMock(), | 165 new ProfileSyncComponentsFactoryMock(), |
165 profile, | 166 profile, |
166 new ManagedUserSigninManagerWrapper(signin), | 167 new ManagedUserSigninManagerWrapper(signin), |
167 oauth2_token_service, | 168 oauth2_token_service, |
168 browser_sync::AUTO_START); | 169 browser_sync::AUTO_START); |
169 } | 170 } |
170 }; | 171 }; |
171 | 172 |
172 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { | 173 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { |
173 // We've never completed startup. | 174 // We've never completed startup. |
174 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 175 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
175 CreateSyncService(); | 176 CreateSyncService(); |
176 SetUpSyncBackendHost(); | 177 SetUpSyncBackendHost(); |
177 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 178 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
178 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); | 179 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); |
179 | 180 |
180 // Should not actually start, rather just clean things up and wait | 181 // Should not actually start, rather just clean things up and wait |
181 // to be enabled. | 182 // to be enabled. |
182 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 183 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
183 sync_->Initialize(); | 184 sync_->Initialize(); |
184 | 185 |
185 // Preferences should be back to defaults. | 186 // Preferences should be back to defaults. |
186 EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); | 187 EXPECT_EQ( |
187 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)); | 188 0, |
| 189 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); |
| 190 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
| 191 sync_driver::prefs::kSyncHasSetupCompleted)); |
188 Mock::VerifyAndClearExpectations(data_type_manager); | 192 Mock::VerifyAndClearExpectations(data_type_manager); |
189 | 193 |
190 // Then start things up. | 194 // Then start things up. |
191 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); | 195 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); |
192 EXPECT_CALL(*data_type_manager, state()). | 196 EXPECT_CALL(*data_type_manager, state()). |
193 WillOnce(Return(DataTypeManager::CONFIGURED)). | 197 WillOnce(Return(DataTypeManager::CONFIGURED)). |
194 WillOnce(Return(DataTypeManager::CONFIGURED)); | 198 WillOnce(Return(DataTypeManager::CONFIGURED)); |
195 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 199 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
196 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 200 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
197 | 201 |
(...skipping 13 matching lines...) Expand all Loading... |
211 IssueTestTokens(); | 215 IssueTestTokens(); |
212 | 216 |
213 // Simulate the UI telling sync it has finished setting up. | 217 // Simulate the UI telling sync it has finished setting up. |
214 sync_->SetSetupInProgress(false); | 218 sync_->SetSetupInProgress(false); |
215 EXPECT_TRUE(sync_->ShouldPushChanges()); | 219 EXPECT_TRUE(sync_->ShouldPushChanges()); |
216 } | 220 } |
217 | 221 |
218 // TODO(pavely): Reenable test once android is switched to oauth2. | 222 // TODO(pavely): Reenable test once android is switched to oauth2. |
219 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { | 223 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { |
220 // We've never completed startup. | 224 // We've never completed startup. |
221 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 225 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
222 CreateSyncService(); | 226 CreateSyncService(); |
223 | 227 |
224 // Should not actually start, rather just clean things up and wait | 228 // Should not actually start, rather just clean things up and wait |
225 // to be enabled. | 229 // to be enabled. |
226 EXPECT_CALL(*components_factory_mock(), | 230 EXPECT_CALL(*components_factory_mock(), |
227 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 231 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
228 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 232 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
229 sync_->Initialize(); | 233 sync_->Initialize(); |
230 | 234 |
231 // Preferences should be back to defaults. | 235 // Preferences should be back to defaults. |
232 EXPECT_EQ(0, profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime)); | 236 EXPECT_EQ( |
233 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted)); | 237 0, |
| 238 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); |
| 239 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
| 240 sync_driver::prefs::kSyncHasSetupCompleted)); |
234 | 241 |
235 // Then start things up. | 242 // Then start things up. |
236 sync_->SetSetupInProgress(true); | 243 sync_->SetSetupInProgress(true); |
237 | 244 |
238 // Simulate successful signin as test_user. | 245 // Simulate successful signin as test_user. |
239 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 246 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
240 "test_user@gmail.com"); | 247 "test_user@gmail.com"); |
241 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); | 248 sync_->signin()->SetAuthenticatedUsername("test_user@gmail.com"); |
242 GoogleServiceSigninSuccessDetails details("test_user@gmail.com", ""); | 249 GoogleServiceSigninSuccessDetails details("test_user@gmail.com", ""); |
243 content::NotificationService::current()->Notify( | 250 content::NotificationService::current()->Notify( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 303 |
297 // Verify we successfully finish startup and configuration. | 304 // Verify we successfully finish startup and configuration. |
298 EXPECT_TRUE(sync_->ShouldPushChanges()); | 305 EXPECT_TRUE(sync_->ShouldPushChanges()); |
299 } | 306 } |
300 | 307 |
301 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { | 308 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { |
302 EXPECT_CALL(*components_factory_mock(), | 309 EXPECT_CALL(*components_factory_mock(), |
303 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 310 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
304 EXPECT_CALL(*components_factory_mock(), | 311 EXPECT_CALL(*components_factory_mock(), |
305 CreateSyncBackendHost(_, _, _)).Times(0); | 312 CreateSyncBackendHost(_, _, _)).Times(0); |
306 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 313 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
307 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 314 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
308 | 315 |
309 sync_->Initialize(); | 316 sync_->Initialize(); |
310 // Sync should not start because there are no tokens yet. | 317 // Sync should not start because there are no tokens yet. |
311 EXPECT_FALSE(sync_->ShouldPushChanges()); | 318 EXPECT_FALSE(sync_->ShouldPushChanges()); |
312 sync_->SetSetupInProgress(false); | 319 sync_->SetSetupInProgress(false); |
313 | 320 |
314 // Sync should not start because there are still no tokens. | 321 // Sync should not start because there are still no tokens. |
315 EXPECT_FALSE(sync_->ShouldPushChanges()); | 322 EXPECT_FALSE(sync_->ShouldPushChanges()); |
316 } | 323 } |
317 | 324 |
318 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { | 325 TEST_F(ProfileSyncServiceStartupCrosTest, StartFirstTime) { |
319 SetUpSyncBackendHost(); | 326 SetUpSyncBackendHost(); |
320 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 327 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
321 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 328 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
322 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 329 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
323 EXPECT_CALL(*data_type_manager, state()). | 330 EXPECT_CALL(*data_type_manager, state()). |
324 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 331 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
325 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 332 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
326 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 333 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
327 | 334 |
328 IssueTestTokens(); | 335 IssueTestTokens(); |
329 sync_->Initialize(); | 336 sync_->Initialize(); |
330 EXPECT_TRUE(sync_->ShouldPushChanges()); | 337 EXPECT_TRUE(sync_->ShouldPushChanges()); |
331 } | 338 } |
(...skipping 17 matching lines...) Expand all Loading... |
349 IssueTestTokens(); | 356 IssueTestTokens(); |
350 | 357 |
351 sync_->Initialize(); | 358 sync_->Initialize(); |
352 } | 359 } |
353 | 360 |
354 // Test that we can recover from a case where a bug in the code resulted in | 361 // Test that we can recover from a case where a bug in the code resulted in |
355 // OnUserChoseDatatypes not being properly called and datatype preferences | 362 // OnUserChoseDatatypes not being properly called and datatype preferences |
356 // therefore being left unset. | 363 // therefore being left unset. |
357 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { | 364 TEST_F(ProfileSyncServiceStartupTest, StartRecoverDatatypePrefs) { |
358 // Clear the datatype preference fields (simulating bug 154940). | 365 // Clear the datatype preference fields (simulating bug 154940). |
359 profile_->GetPrefs()->ClearPref(prefs::kSyncKeepEverythingSynced); | 366 profile_->GetPrefs()->ClearPref( |
| 367 sync_driver::prefs::kSyncKeepEverythingSynced); |
360 syncer::ModelTypeSet user_types = syncer::UserTypes(); | 368 syncer::ModelTypeSet user_types = syncer::UserTypes(); |
361 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); | 369 for (syncer::ModelTypeSet::Iterator iter = user_types.First(); |
362 iter.Good(); iter.Inc()) { | 370 iter.Good(); iter.Inc()) { |
363 profile_->GetPrefs()->ClearPref( | 371 profile_->GetPrefs()->ClearPref( |
364 browser_sync::SyncPrefs::GetPrefNameForDataType(iter.Get())); | 372 sync_driver::SyncPrefs::GetPrefNameForDataType(iter.Get())); |
365 } | 373 } |
366 | 374 |
367 // Pre load the tokens | 375 // Pre load the tokens |
368 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 376 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
369 "test_user@gmail.com"); | 377 "test_user@gmail.com"); |
370 SigninManagerFactory::GetForProfile(profile_.get()) | 378 SigninManagerFactory::GetForProfile(profile_.get()) |
371 ->SetAuthenticatedUsername("test_user@gmail.com"); | 379 ->SetAuthenticatedUsername("test_user@gmail.com"); |
372 CreateSyncService(); | 380 CreateSyncService(); |
373 sync_->SetSyncSetupCompleted(); | 381 sync_->SetSyncSetupCompleted(); |
374 SetUpSyncBackendHost(); | 382 SetUpSyncBackendHost(); |
375 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 383 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
376 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 384 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
377 EXPECT_CALL(*data_type_manager, state()). | 385 EXPECT_CALL(*data_type_manager, state()). |
378 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 386 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
379 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 387 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
380 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 388 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
381 | 389 |
382 IssueTestTokens(); | 390 IssueTestTokens(); |
383 sync_->Initialize(); | 391 sync_->Initialize(); |
384 | 392 |
385 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( | 393 EXPECT_TRUE(profile_->GetPrefs()->GetBoolean( |
386 prefs::kSyncKeepEverythingSynced)); | 394 sync_driver::prefs::kSyncKeepEverythingSynced)); |
387 } | 395 } |
388 | 396 |
389 // Verify that the recovery of datatype preferences doesn't overwrite a valid | 397 // Verify that the recovery of datatype preferences doesn't overwrite a valid |
390 // case where only bookmarks are enabled. | 398 // case where only bookmarks are enabled. |
391 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { | 399 TEST_F(ProfileSyncServiceStartupTest, StartDontRecoverDatatypePrefs) { |
392 // Explicitly set Keep Everything Synced to false and have only bookmarks | 400 // Explicitly set Keep Everything Synced to false and have only bookmarks |
393 // enabled. | 401 // enabled. |
394 profile_->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); | 402 profile_->GetPrefs()->SetBoolean( |
| 403 sync_driver::prefs::kSyncKeepEverythingSynced, false); |
395 | 404 |
396 // Pre load the tokens | 405 // Pre load the tokens |
397 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 406 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
398 "test_user@gmail.com"); | 407 "test_user@gmail.com"); |
399 SigninManagerFactory::GetForProfile(profile_.get()) | 408 SigninManagerFactory::GetForProfile(profile_.get()) |
400 ->SetAuthenticatedUsername("test_user@gmail.com"); | 409 ->SetAuthenticatedUsername("test_user@gmail.com"); |
401 CreateSyncService(); | 410 CreateSyncService(); |
402 sync_->SetSyncSetupCompleted(); | 411 sync_->SetSyncSetupCompleted(); |
403 SetUpSyncBackendHost(); | 412 SetUpSyncBackendHost(); |
404 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 413 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
405 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 414 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
406 EXPECT_CALL(*data_type_manager, state()). | 415 EXPECT_CALL(*data_type_manager, state()). |
407 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); | 416 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); |
408 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 417 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
409 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 418 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
410 IssueTestTokens(); | 419 IssueTestTokens(); |
411 sync_->Initialize(); | 420 sync_->Initialize(); |
412 | 421 |
413 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( | 422 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
414 prefs::kSyncKeepEverythingSynced)); | 423 sync_driver::prefs::kSyncKeepEverythingSynced)); |
415 } | 424 } |
416 | 425 |
417 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { | 426 TEST_F(ProfileSyncServiceStartupTest, ManagedStartup) { |
418 // Service should not be started by Initialize() since it's managed. | 427 // Service should not be started by Initialize() since it's managed. |
419 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 428 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
420 "test_user@gmail.com"); | 429 "test_user@gmail.com"); |
421 CreateSyncService(); | 430 CreateSyncService(); |
422 | 431 |
423 // Disable sync through policy. | 432 // Disable sync through policy. |
424 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 433 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); |
425 EXPECT_CALL(*components_factory_mock(), | 434 EXPECT_CALL(*components_factory_mock(), |
426 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 435 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
427 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 436 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
428 | 437 |
429 sync_->Initialize(); | 438 sync_->Initialize(); |
430 } | 439 } |
431 | 440 |
432 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { | 441 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { |
433 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 442 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
434 "test_user@gmail.com"); | 443 "test_user@gmail.com"); |
435 SigninManagerFactory::GetForProfile(profile_.get()) | 444 SigninManagerFactory::GetForProfile(profile_.get()) |
436 ->SetAuthenticatedUsername("test_user@gmail.com"); | 445 ->SetAuthenticatedUsername("test_user@gmail.com"); |
437 CreateSyncService(); | 446 CreateSyncService(); |
438 sync_->SetSyncSetupCompleted(); | 447 sync_->SetSyncSetupCompleted(); |
439 SetUpSyncBackendHost(); | 448 SetUpSyncBackendHost(); |
440 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); | 449 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); |
441 EXPECT_CALL(*data_type_manager, Configure(_, _)); | 450 EXPECT_CALL(*data_type_manager, Configure(_, _)); |
442 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 451 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
443 IssueTestTokens(); | 452 IssueTestTokens(); |
444 sync_->Initialize(); | 453 sync_->Initialize(); |
445 | 454 |
446 // The service should stop when switching to managed mode. | 455 // The service should stop when switching to managed mode. |
447 Mock::VerifyAndClearExpectations(data_type_manager); | 456 Mock::VerifyAndClearExpectations(data_type_manager); |
448 EXPECT_CALL(*data_type_manager, state()). | 457 EXPECT_CALL(*data_type_manager, state()). |
449 WillOnce(Return(DataTypeManager::CONFIGURED)); | 458 WillOnce(Return(DataTypeManager::CONFIGURED)); |
450 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 459 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
451 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 460 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
452 profile_->GetPrefs()->SetBoolean(prefs::kSyncManaged, true); | 461 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); |
453 | 462 |
454 // When switching back to unmanaged, the state should change, but the service | 463 // When switching back to unmanaged, the state should change, but the service |
455 // should not start up automatically (kSyncSetupCompleted will be false). | 464 // should not start up automatically (kSyncSetupCompleted will be false). |
456 Mock::VerifyAndClearExpectations(data_type_manager); | 465 Mock::VerifyAndClearExpectations(data_type_manager); |
457 EXPECT_CALL(*components_factory_mock(), | 466 EXPECT_CALL(*components_factory_mock(), |
458 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 467 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
459 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 468 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
460 profile_->GetPrefs()->ClearPref(prefs::kSyncManaged); | 469 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged); |
461 } | 470 } |
462 | 471 |
463 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { | 472 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { |
464 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 473 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
465 "test_user@gmail.com"); | 474 "test_user@gmail.com"); |
466 SigninManagerFactory::GetForProfile(profile_.get()) | 475 SigninManagerFactory::GetForProfile(profile_.get()) |
467 ->SetAuthenticatedUsername("test_user@gmail.com"); | 476 ->SetAuthenticatedUsername("test_user@gmail.com"); |
468 CreateSyncService(); | 477 CreateSyncService(); |
469 sync_->SetSyncSetupCompleted(); | 478 sync_->SetSyncSetupCompleted(); |
470 SetUpSyncBackendHost(); | 479 SetUpSyncBackendHost(); |
(...skipping 27 matching lines...) Expand all Loading... |
498 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { | 507 TEST_F(ProfileSyncServiceStartupTest, StartDownloadFailed) { |
499 // Pre load the tokens | 508 // Pre load the tokens |
500 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 509 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
501 "test_user@gmail.com"); | 510 "test_user@gmail.com"); |
502 SigninManagerFactory::GetForProfile(profile_.get()) | 511 SigninManagerFactory::GetForProfile(profile_.get()) |
503 ->SetAuthenticatedUsername("test_user@gmail.com"); | 512 ->SetAuthenticatedUsername("test_user@gmail.com"); |
504 CreateSyncService(); | 513 CreateSyncService(); |
505 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); | 514 SyncBackendHostMock* mock_sbh = SetUpSyncBackendHost(); |
506 mock_sbh->set_fail_initial_download(true); | 515 mock_sbh->set_fail_initial_download(true); |
507 | 516 |
508 profile_->GetPrefs()->ClearPref(prefs::kSyncHasSetupCompleted); | 517 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
509 | 518 |
510 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 519 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
511 sync_->Initialize(); | 520 sync_->Initialize(); |
512 | 521 |
513 sync_->SetSetupInProgress(true); | 522 sync_->SetSetupInProgress(true); |
514 IssueTestTokens(); | 523 IssueTestTokens(); |
515 sync_->SetSetupInProgress(false); | 524 sync_->SetSetupInProgress(false); |
516 EXPECT_FALSE(sync_->sync_initialized()); | 525 EXPECT_FALSE(sync_->sync_initialized()); |
517 } | 526 } |
OLD | NEW |