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/account_tracker_service_factory.h" | 10 #include "chrome/browser/signin/account_tracker_service_factory.h" |
11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
12 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 12 #include "chrome/browser/signin/fake_signin_manager_builder.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_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
15 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | 15 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" |
16 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 16 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
| 17 #include "chrome/browser/sync/profile_sync_service.h" |
17 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
18 #include "chrome/browser/sync/profile_sync_test_util.h" | 19 #include "chrome/browser/sync/profile_sync_test_util.h" |
19 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 20 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
22 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
23 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
24 #include "components/signin/core/browser/account_tracker_service.h" | 25 #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/fake_profile_oauth2_token_service.h" |
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 27 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 DataTypeManager::ConfigureResult configure_result = | 70 DataTypeManager::ConfigureResult configure_result = |
70 static_cast<DataTypeManager::ConfigureResult>(result); | 71 static_cast<DataTypeManager::ConfigureResult>(result); |
71 if (result.status == sync_driver::DataTypeManager::ABORTED) | 72 if (result.status == sync_driver::DataTypeManager::ABORTED) |
72 error_callback.Run(&configure_result); | 73 error_callback.Run(&configure_result); |
73 service->OnConfigureDone(configure_result); | 74 service->OnConfigureDone(configure_result); |
74 } | 75 } |
75 | 76 |
76 class TestProfileSyncServiceNoBackup : public ProfileSyncService { | 77 class TestProfileSyncServiceNoBackup : public ProfileSyncService { |
77 public: | 78 public: |
78 TestProfileSyncServiceNoBackup( | 79 TestProfileSyncServiceNoBackup( |
79 scoped_ptr<ProfileSyncComponentsFactory> factory, | 80 scoped_ptr<sync_driver::SyncApiComponentFactory> factory, |
80 Profile* profile, | 81 Profile* profile, |
81 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, | 82 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, |
82 ProfileOAuth2TokenService* oauth2_token_service, | 83 ProfileOAuth2TokenService* oauth2_token_service, |
83 browser_sync::ProfileSyncServiceStartBehavior start_behavior) | 84 browser_sync::ProfileSyncServiceStartBehavior start_behavior) |
84 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(), | 85 : ProfileSyncService(factory.Pass(), profile, signin_wrapper.Pass(), |
85 oauth2_token_service, start_behavior) {} | 86 oauth2_token_service, start_behavior) {} |
86 | 87 |
87 protected: | 88 protected: |
88 bool NeedBackup() const override { return false; } | 89 bool NeedBackup() const override { return false; } |
89 }; | 90 }; |
(...skipping 27 matching lines...) Expand all Loading... |
117 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), | 118 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), |
118 testing_facotries); | 119 testing_facotries); |
119 } | 120 } |
120 | 121 |
121 void TearDown() override { sync_->RemoveObserver(&observer_); } | 122 void TearDown() override { sync_->RemoveObserver(&observer_); } |
122 | 123 |
123 static scoped_ptr<KeyedService> BuildService( | 124 static scoped_ptr<KeyedService> BuildService( |
124 content::BrowserContext* browser_context) { | 125 content::BrowserContext* browser_context) { |
125 Profile* profile = static_cast<Profile*>(browser_context); | 126 Profile* profile = static_cast<Profile*>(browser_context); |
126 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 127 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |
127 scoped_ptr<ProfileSyncComponentsFactory>( | 128 scoped_ptr<sync_driver::SyncApiComponentFactory>( |
128 new ProfileSyncComponentsFactoryMock()), | 129 new ProfileSyncComponentsFactoryMock()), |
129 profile, make_scoped_ptr(new SupervisedUserSigninManagerWrapper( | 130 profile, make_scoped_ptr(new SupervisedUserSigninManagerWrapper( |
130 profile, SigninManagerFactory::GetForProfile(profile))), | 131 profile, SigninManagerFactory::GetForProfile(profile))), |
131 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 132 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
132 browser_sync::MANUAL_START)); | 133 browser_sync::MANUAL_START)); |
133 } | 134 } |
134 | 135 |
135 void CreateSyncService() { | 136 void CreateSyncService() { |
136 sync_ = static_cast<ProfileSyncService*>( | 137 sync_ = static_cast<ProfileSyncService*>( |
137 ProfileSyncServiceFactory::GetForProfile(profile_)); | 138 ProfileSyncServiceFactory::GetForProfile(profile_)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_CALL(*components_factory_mock(), | 187 EXPECT_CALL(*components_factory_mock(), |
187 CreateDataTypeManager(_, _, _, _, _)). | 188 CreateDataTypeManager(_, _, _, _, _)). |
188 WillOnce(Return(data_type_manager)); | 189 WillOnce(Return(data_type_manager)); |
189 return data_type_manager; | 190 return data_type_manager; |
190 } | 191 } |
191 | 192 |
192 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { | 193 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { |
193 browser_sync::SyncBackendHostMock* sync_backend_host = | 194 browser_sync::SyncBackendHostMock* sync_backend_host = |
194 new browser_sync::SyncBackendHostMock(); | 195 new browser_sync::SyncBackendHostMock(); |
195 EXPECT_CALL(*components_factory_mock(), | 196 EXPECT_CALL(*components_factory_mock(), |
196 CreateSyncBackendHost(_, _, _, _, _)). | 197 CreateSyncBackendHost(_, _, _, _)). |
197 WillOnce(Return(sync_backend_host)); | 198 WillOnce(Return(sync_backend_host)); |
198 return sync_backend_host; | 199 return sync_backend_host; |
199 } | 200 } |
200 | 201 |
201 content::TestBrowserThreadBundle thread_bundle_; | 202 content::TestBrowserThreadBundle thread_bundle_; |
202 TestingProfileManager profile_manager_; | 203 TestingProfileManager profile_manager_; |
203 TestingProfile* profile_; | 204 TestingProfile* profile_; |
204 ProfileSyncService* sync_; | 205 ProfileSyncService* sync_; |
205 SyncServiceObserverMock observer_; | 206 SyncServiceObserverMock observer_; |
206 sync_driver::DataTypeStatusTable data_type_status_table_; | 207 sync_driver::DataTypeStatusTable data_type_status_table_; |
(...skipping 13 matching lines...) Expand all Loading... |
220 content::BrowserContext* context) { | 221 content::BrowserContext* context) { |
221 Profile* profile = static_cast<Profile*>(context); | 222 Profile* profile = static_cast<Profile*>(context); |
222 FakeSigninManagerForTesting* signin = | 223 FakeSigninManagerForTesting* signin = |
223 static_cast<FakeSigninManagerForTesting*>( | 224 static_cast<FakeSigninManagerForTesting*>( |
224 SigninManagerFactory::GetForProfile(profile)); | 225 SigninManagerFactory::GetForProfile(profile)); |
225 SimulateTestUserSignin(profile, signin, nullptr); | 226 SimulateTestUserSignin(profile, signin, nullptr); |
226 ProfileOAuth2TokenService* oauth2_token_service = | 227 ProfileOAuth2TokenService* oauth2_token_service = |
227 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 228 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
228 EXPECT_TRUE(signin->IsAuthenticated()); | 229 EXPECT_TRUE(signin->IsAuthenticated()); |
229 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 230 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |
230 scoped_ptr<ProfileSyncComponentsFactory>( | 231 scoped_ptr<sync_driver::SyncApiComponentFactory>( |
231 new ProfileSyncComponentsFactoryMock()), | 232 new ProfileSyncComponentsFactoryMock()), |
232 profile, make_scoped_ptr( | 233 profile, make_scoped_ptr( |
233 new SupervisedUserSigninManagerWrapper(profile, signin)), | 234 new SupervisedUserSigninManagerWrapper(profile, signin)), |
234 oauth2_token_service, browser_sync::AUTO_START)); | 235 oauth2_token_service, browser_sync::AUTO_START)); |
235 } | 236 } |
236 }; | 237 }; |
237 | 238 |
238 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { | 239 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { |
239 // We've never completed startup. | 240 // We've never completed startup. |
240 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 241 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
356 // http://crbug.com/396402 | 357 // http://crbug.com/396402 |
357 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials | 358 #define MAYBE_StartCrosNoCredentials DISABLED_StartCrosNoCredentials |
358 #else | 359 #else |
359 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials | 360 #define MAYBE_StartCrosNoCredentials StartCrosNoCredentials |
360 #endif | 361 #endif |
361 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { | 362 TEST_F(ProfileSyncServiceStartupCrosTest, MAYBE_StartCrosNoCredentials) { |
362 EXPECT_CALL(*components_factory_mock(), | 363 EXPECT_CALL(*components_factory_mock(), |
363 CreateDataTypeManager(_, _, _, _, _)).Times(0); | 364 CreateDataTypeManager(_, _, _, _, _)).Times(0); |
364 EXPECT_CALL(*components_factory_mock(), | 365 EXPECT_CALL(*components_factory_mock(), |
365 CreateSyncBackendHost(_, _, _, _, _)).Times(0); | 366 CreateSyncBackendHost(_, _, _, _)).Times(0); |
366 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 367 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
367 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 368 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
368 | 369 |
369 sync_->Initialize(); | 370 sync_->Initialize(); |
370 // Sync should not start because there are no tokens yet. | 371 // Sync should not start because there are no tokens yet. |
371 EXPECT_FALSE(sync_->IsSyncActive()); | 372 EXPECT_FALSE(sync_->IsSyncActive()); |
372 sync_->SetSetupInProgress(false); | 373 sync_->SetSetupInProgress(false); |
373 | 374 |
374 // Sync should not start because there are still no tokens. | 375 // Sync should not start because there are still no tokens. |
375 EXPECT_FALSE(sync_->IsSyncActive()); | 376 EXPECT_FALSE(sync_->IsSyncActive()); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 572 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
572 | 573 |
573 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 574 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
574 sync_->Initialize(); | 575 sync_->Initialize(); |
575 | 576 |
576 sync_->SetSetupInProgress(true); | 577 sync_->SetSetupInProgress(true); |
577 IssueTestTokens(account_id); | 578 IssueTestTokens(account_id); |
578 sync_->SetSetupInProgress(false); | 579 sync_->SetSetupInProgress(false); |
579 EXPECT_FALSE(sync_->IsSyncActive()); | 580 EXPECT_FALSE(sync_->IsSyncActive()); |
580 } | 581 } |
OLD | NEW |