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/files/file_util.h" | 5 #include "base/files/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 "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/prefs/pref_service_syncable.h" | 9 #include "chrome/browser/prefs/pref_service_syncable.h" |
10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 static_cast<ProfileSyncService*>(pss); | 52 static_cast<ProfileSyncService*>(pss); |
53 service->OnConfigureStart(); | 53 service->OnConfigureStart(); |
54 } | 54 } |
55 | 55 |
56 ACTION_P3(InvokeOnConfigureDone, pss, error_callback, result) { | 56 ACTION_P3(InvokeOnConfigureDone, pss, error_callback, result) { |
57 ProfileSyncService* service = | 57 ProfileSyncService* service = |
58 static_cast<ProfileSyncService*>(pss); | 58 static_cast<ProfileSyncService*>(pss); |
59 DataTypeManager::ConfigureResult configure_result = | 59 DataTypeManager::ConfigureResult configure_result = |
60 static_cast<DataTypeManager::ConfigureResult>(result); | 60 static_cast<DataTypeManager::ConfigureResult>(result); |
61 if (result.status == sync_driver::DataTypeManager::ABORTED) | 61 if (result.status == sync_driver::DataTypeManager::ABORTED) |
62 error_callback.Run(&configure_result); | 62 error_callback.Run(); |
63 service->OnConfigureDone(configure_result); | 63 service->OnConfigureDone(configure_result); |
64 } | 64 } |
65 | 65 |
66 class TestProfileSyncServiceNoBackup : public ProfileSyncService { | 66 class TestProfileSyncServiceNoBackup : public ProfileSyncService { |
67 public: | 67 public: |
68 TestProfileSyncServiceNoBackup( | 68 TestProfileSyncServiceNoBackup( |
69 scoped_ptr<ProfileSyncComponentsFactory> factory, | 69 scoped_ptr<ProfileSyncComponentsFactory> factory, |
70 Profile* profile, | 70 Profile* profile, |
71 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, | 71 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, |
72 ProfileOAuth2TokenService* oauth2_token_service, | 72 ProfileOAuth2TokenService* oauth2_token_service, |
73 browser_sync::ProfileSyncServiceStartBehavior start_behavior) | 73 browser_sync::ProfileSyncServiceStartBehavior start_behavior) |
74 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(), | 74 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(), |
75 oauth2_token_service, start_behavior) {} | 75 oauth2_token_service, start_behavior) {} |
76 | 76 |
77 protected: | 77 protected: |
78 virtual bool NeedBackup() const OVERRIDE { | 78 virtual bool NeedBackup() const OVERRIDE { |
79 return false; | 79 return false; |
80 } | 80 } |
81 }; | 81 }; |
82 | 82 |
83 class ProfileSyncServiceStartupTest : public testing::Test { | 83 class ProfileSyncServiceStartupTest : public testing::Test { |
84 public: | 84 public: |
85 ProfileSyncServiceStartupTest() | 85 ProfileSyncServiceStartupTest() |
86 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | | 86 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | |
87 content::TestBrowserThreadBundle::REAL_FILE_THREAD | | 87 content::TestBrowserThreadBundle::REAL_FILE_THREAD | |
88 content::TestBrowserThreadBundle::REAL_IO_THREAD), | 88 content::TestBrowserThreadBundle::REAL_IO_THREAD), |
89 profile_manager_(TestingBrowserProcess::GetGlobal()), | 89 profile_manager_(TestingBrowserProcess::GetGlobal()), |
90 sync_(NULL) {} | 90 sync_(NULL), |
| 91 data_type_status_table_(NULL) {} |
91 | 92 |
92 virtual ~ProfileSyncServiceStartupTest() { | 93 virtual ~ProfileSyncServiceStartupTest() { |
93 } | 94 } |
94 | 95 |
95 virtual void SetUp() { | 96 virtual void SetUp() { |
96 CHECK(profile_manager_.SetUp()); | 97 CHECK(profile_manager_.SetUp()); |
97 | 98 |
98 TestingProfile::TestingFactories testing_facotries; | 99 TestingProfile::TestingFactories testing_facotries; |
99 testing_facotries.push_back( | 100 testing_facotries.push_back( |
100 std::make_pair(SigninManagerFactory::GetInstance(), | 101 std::make_pair(SigninManagerFactory::GetInstance(), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 141 } |
141 | 142 |
142 ProfileSyncComponentsFactoryMock* components_factory_mock() { | 143 ProfileSyncComponentsFactoryMock* components_factory_mock() { |
143 return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory()); | 144 return static_cast<ProfileSyncComponentsFactoryMock*>(sync_->factory()); |
144 } | 145 } |
145 | 146 |
146 FakeSigninManagerForTesting* fake_signin() { | 147 FakeSigninManagerForTesting* fake_signin() { |
147 return static_cast<FakeSigninManagerForTesting*>(sync_->signin()); | 148 return static_cast<FakeSigninManagerForTesting*>(sync_->signin()); |
148 } | 149 } |
149 | 150 |
150 void SetError(DataTypeManager::ConfigureResult* result) { | 151 void SetError() { |
151 sync_driver::DataTypeStatusTable::TypeErrorMap errors; | 152 sync_driver::DataTypeStatusTable::TypeErrorMap errors; |
152 errors[syncer::BOOKMARKS] = | 153 errors[syncer::BOOKMARKS] = |
153 syncer::SyncError(FROM_HERE, | 154 syncer::SyncError(FROM_HERE, |
154 syncer::SyncError::UNRECOVERABLE_ERROR, | 155 syncer::SyncError::UNRECOVERABLE_ERROR, |
155 "Error", | 156 "Error", |
156 syncer::BOOKMARKS); | 157 syncer::BOOKMARKS); |
157 result->data_type_status_table.UpdateFailedDataTypes(errors); | 158 data_type_status_table_->UpdateFailedDataTypes(errors); |
158 } | 159 } |
159 | 160 |
160 protected: | 161 protected: |
161 void SimulateTestUserSignin() { | 162 void SimulateTestUserSignin() { |
162 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 163 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
163 "test_user@gmail.com"); | 164 "test_user@gmail.com"); |
164 #if !defined(OS_CHROMEOS) | 165 #if !defined(OS_CHROMEOS) |
165 fake_signin()->SignIn("test_user@gmail.com", ""); | 166 fake_signin()->SignIn("test_user@gmail.com", ""); |
166 #else | 167 #else |
167 fake_signin()->SetAuthenticatedUsername("test_user@gmail.com"); | 168 fake_signin()->SetAuthenticatedUsername("test_user@gmail.com"); |
168 sync_->GoogleSigninSucceeded("test_user@gmail.com", | 169 sync_->GoogleSigninSucceeded("test_user@gmail.com", |
169 "test_user@gmail.com", | 170 "test_user@gmail.com", |
170 ""); | 171 ""); |
171 #endif | 172 #endif |
172 } | 173 } |
173 | 174 |
174 DataTypeManagerMock* SetUpDataTypeManager() { | 175 DataTypeManagerMock* SetUpDataTypeManager() { |
175 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock(); | 176 DataTypeManagerMock* data_type_manager = new DataTypeManagerMock(); |
176 EXPECT_CALL(*components_factory_mock(), | 177 EXPECT_CALL(*components_factory_mock(), |
177 CreateDataTypeManager(_, _, _, _, _)). | 178 CreateDataTypeManager(_, _, _, _, _, _)). |
178 WillOnce(Return(data_type_manager)); | 179 WillOnce(DoAll(SaveArg<5>(&data_type_status_table_), |
| 180 Return(data_type_manager))); |
179 return data_type_manager; | 181 return data_type_manager; |
180 } | 182 } |
181 | 183 |
182 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { | 184 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { |
183 browser_sync::SyncBackendHostMock* sync_backend_host = | 185 browser_sync::SyncBackendHostMock* sync_backend_host = |
184 new browser_sync::SyncBackendHostMock(); | 186 new browser_sync::SyncBackendHostMock(); |
185 EXPECT_CALL(*components_factory_mock(), | 187 EXPECT_CALL(*components_factory_mock(), |
186 CreateSyncBackendHost(_, _, _, _, _)). | 188 CreateSyncBackendHost(_, _, _, _, _)). |
187 WillOnce(Return(sync_backend_host)); | 189 WillOnce(Return(sync_backend_host)); |
188 return sync_backend_host; | 190 return sync_backend_host; |
189 } | 191 } |
190 | 192 |
191 content::TestBrowserThreadBundle thread_bundle_; | 193 content::TestBrowserThreadBundle thread_bundle_; |
192 TestingProfileManager profile_manager_; | 194 TestingProfileManager profile_manager_; |
193 TestingProfile* profile_; | 195 TestingProfile* profile_; |
194 ProfileSyncService* sync_; | 196 ProfileSyncService* sync_; |
195 ProfileSyncServiceObserverMock observer_; | 197 ProfileSyncServiceObserverMock observer_; |
196 sync_driver::DataTypeStatusTable data_type_status_table_; | 198 sync_driver::DataTypeStatusTable* data_type_status_table_; |
197 }; | 199 }; |
198 | 200 |
199 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { | 201 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { |
200 public: | 202 public: |
201 virtual void SetUp() { | 203 virtual void SetUp() { |
202 ProfileSyncServiceStartupTest::SetUp(); | 204 ProfileSyncServiceStartupTest::SetUp(); |
203 sync_ = static_cast<ProfileSyncService*>( | 205 sync_ = static_cast<ProfileSyncService*>( |
204 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 206 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
205 profile_, BuildCrosService)); | 207 profile_, BuildCrosService)); |
206 sync_->AddObserver(&observer_); | 208 sync_->AddObserver(&observer_); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 272 |
271 // TODO(pavely): Reenable test once android is switched to oauth2. | 273 // TODO(pavely): Reenable test once android is switched to oauth2. |
272 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { | 274 TEST_F(ProfileSyncServiceStartupTest, DISABLED_StartNoCredentials) { |
273 // We've never completed startup. | 275 // We've never completed startup. |
274 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 276 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
275 CreateSyncService(); | 277 CreateSyncService(); |
276 | 278 |
277 // Should not actually start, rather just clean things up and wait | 279 // Should not actually start, rather just clean things up and wait |
278 // to be enabled. | 280 // to be enabled. |
279 EXPECT_CALL(*components_factory_mock(), | 281 EXPECT_CALL(*components_factory_mock(), |
280 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 282 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
281 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 283 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
282 sync_->Initialize(); | 284 sync_->Initialize(); |
283 | 285 |
284 // Preferences should be back to defaults. | 286 // Preferences should be back to defaults. |
285 EXPECT_EQ( | 287 EXPECT_EQ( |
286 0, | 288 0, |
287 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); | 289 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); |
288 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( | 290 EXPECT_FALSE(profile_->GetPrefs()->GetBoolean( |
289 sync_driver::prefs::kSyncHasSetupCompleted)); | 291 sync_driver::prefs::kSyncHasSetupCompleted)); |
290 | 292 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 346 } |
345 | 347 |
346 #if defined(OS_WIN) | 348 #if defined(OS_WIN) |
347 // http://crbug.com/396402 | 349 // http://crbug.com/396402 |
348 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials | 350 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials |
349 #else | 351 #else |
350 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials | 352 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials |
351 #endif | 353 #endif |
352 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { | 354 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { |
353 EXPECT_CALL(*components_factory_mock(), | 355 EXPECT_CALL(*components_factory_mock(), |
354 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 356 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
355 EXPECT_CALL(*components_factory_mock(), | 357 EXPECT_CALL(*components_factory_mock(), |
356 CreateSyncBackendHost(_, _, _, _, _)).Times(0); | 358 CreateSyncBackendHost(_, _, _, _, _)).Times(0); |
357 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 359 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
358 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 360 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
359 | 361 |
360 sync_->Initialize(); | 362 sync_->Initialize(); |
361 // Sync should not start because there are no tokens yet. | 363 // Sync should not start because there are no tokens yet. |
362 EXPECT_FALSE(sync_->ShouldPushChanges()); | 364 EXPECT_FALSE(sync_->ShouldPushChanges()); |
363 sync_->SetSetupInProgress(false); | 365 sync_->SetSetupInProgress(false); |
364 | 366 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 #endif | 489 #endif |
488 TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) { | 490 TEST_F(ProfileSyncServiceStartupTest, MAYBE_ManagedStartup) { |
489 // Service should not be started by Initialize() since it's managed. | 491 // Service should not be started by Initialize() since it's managed. |
490 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 492 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
491 "test_user@gmail.com"); | 493 "test_user@gmail.com"); |
492 CreateSyncService(); | 494 CreateSyncService(); |
493 | 495 |
494 // Disable sync through policy. | 496 // Disable sync through policy. |
495 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); | 497 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); |
496 EXPECT_CALL(*components_factory_mock(), | 498 EXPECT_CALL(*components_factory_mock(), |
497 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 499 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
498 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 500 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
499 | 501 |
500 sync_->Initialize(); | 502 sync_->Initialize(); |
501 } | 503 } |
502 | 504 |
503 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { | 505 TEST_F(ProfileSyncServiceStartupTest, SwitchManaged) { |
504 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 506 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
505 "test_user@gmail.com"); | 507 "test_user@gmail.com"); |
506 SigninManagerFactory::GetForProfile(profile_) | 508 SigninManagerFactory::GetForProfile(profile_) |
507 ->SetAuthenticatedUsername("test_user@gmail.com"); | 509 ->SetAuthenticatedUsername("test_user@gmail.com"); |
(...skipping 11 matching lines...) Expand all Loading... |
519 EXPECT_CALL(*data_type_manager, state()). | 521 EXPECT_CALL(*data_type_manager, state()). |
520 WillOnce(Return(DataTypeManager::CONFIGURED)); | 522 WillOnce(Return(DataTypeManager::CONFIGURED)); |
521 EXPECT_CALL(*data_type_manager, Stop()).Times(1); | 523 EXPECT_CALL(*data_type_manager, Stop()).Times(1); |
522 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 524 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
523 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); | 525 profile_->GetPrefs()->SetBoolean(sync_driver::prefs::kSyncManaged, true); |
524 | 526 |
525 // When switching back to unmanaged, the state should change, but the service | 527 // When switching back to unmanaged, the state should change, but the service |
526 // should not start up automatically (kSyncSetupCompleted will be false). | 528 // should not start up automatically (kSyncSetupCompleted will be false). |
527 Mock::VerifyAndClearExpectations(data_type_manager); | 529 Mock::VerifyAndClearExpectations(data_type_manager); |
528 EXPECT_CALL(*components_factory_mock(), | 530 EXPECT_CALL(*components_factory_mock(), |
529 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 531 CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
530 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 532 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
531 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged); | 533 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncManaged); |
532 } | 534 } |
533 | 535 |
534 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { | 536 TEST_F(ProfileSyncServiceStartupTest, StartFailure) { |
535 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 537 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
536 "test_user@gmail.com"); | 538 "test_user@gmail.com"); |
537 SigninManagerFactory::GetForProfile(profile_) | 539 SigninManagerFactory::GetForProfile(profile_) |
538 ->SetAuthenticatedUsername("test_user@gmail.com"); | 540 ->SetAuthenticatedUsername("test_user@gmail.com"); |
539 CreateSyncService(); | 541 CreateSyncService(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 574 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
573 | 575 |
574 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 576 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
575 sync_->Initialize(); | 577 sync_->Initialize(); |
576 | 578 |
577 sync_->SetSetupInProgress(true); | 579 sync_->SetSetupInProgress(true); |
578 IssueTestTokens(); | 580 IssueTestTokens(); |
579 sync_->SetSetupInProgress(false); | 581 sync_->SetSetupInProgress(false); |
580 EXPECT_FALSE(sync_->sync_initialized()); | 582 EXPECT_FALSE(sync_->sync_initialized()); |
581 } | 583 } |
OLD | NEW |