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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 bool issue_auth_token, | 94 bool issue_auth_token, |
95 bool synchronous_sync_configuration, | 95 bool synchronous_sync_configuration, |
96 bool sync_setup_completed, | 96 bool sync_setup_completed, |
97 syncer::StorageOption storage_option) { | 97 syncer::StorageOption storage_option) { |
98 if (service_) | 98 if (service_) |
99 return; | 99 return; |
100 | 100 |
101 SigninManagerBase* signin = | 101 SigninManagerBase* signin = |
102 SigninManagerFactory::GetForProfile(profile_.get()); | 102 SigninManagerFactory::GetForProfile(profile_.get()); |
103 signin->SetAuthenticatedUsername("test"); | 103 signin->SetAuthenticatedUsername("test"); |
104 OAuth2TokenService* oauth2_token_service = | 104 ProfileOAuth2TokenService* oauth2_token_service = |
105 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 105 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
106 ProfileSyncComponentsFactoryMock* factory = | 106 ProfileSyncComponentsFactoryMock* factory = |
107 new ProfileSyncComponentsFactoryMock(); | 107 new ProfileSyncComponentsFactoryMock(); |
108 service_.reset(new TestProfileSyncService( | 108 service_.reset(new TestProfileSyncService( |
109 factory, | 109 factory, |
110 profile_.get(), | 110 profile_.get(), |
111 signin, | 111 signin, |
112 oauth2_token_service, | 112 oauth2_token_service, |
113 ProfileSyncService::AUTO_START, | 113 ProfileSyncService::AUTO_START, |
114 true)); | 114 true)); |
(...skipping 25 matching lines...) Expand all Loading... |
140 done.Wait(); | 140 done.Wait(); |
141 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
142 if (service_->sync_initialized()) { | 142 if (service_->sync_initialized()) { |
143 return; | 143 return; |
144 } | 144 } |
145 } | 145 } |
146 LOG(ERROR) << "Backend not initialized."; | 146 LOG(ERROR) << "Backend not initialized."; |
147 } | 147 } |
148 | 148 |
149 void IssueTestTokens() { | 149 void IssueTestTokens() { |
150 TokenService* token_service = | 150 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()) |
151 TokenServiceFactory::GetForProfile(profile_.get()); | 151 ->UpdateCredentials("test", "oauth2_login_token"); |
152 token_service->IssueAuthTokenForTest( | 152 TokenServiceFactory::GetForProfile(profile_.get()) |
153 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); | 153 ->IssueAuthTokenForTest(GaiaConstants::kSyncService, "token"); |
154 token_service->IssueAuthTokenForTest( | |
155 GaiaConstants::kSyncService, "token"); | |
156 } | 154 } |
157 | 155 |
158 scoped_ptr<TestProfileSyncService> service_; | 156 scoped_ptr<TestProfileSyncService> service_; |
159 scoped_ptr<TestingProfile> profile_; | 157 scoped_ptr<TestingProfile> profile_; |
160 | 158 |
161 private: | 159 private: |
162 content::TestBrowserThreadBundle thread_bundle_; | 160 content::TestBrowserThreadBundle thread_bundle_; |
163 }; | 161 }; |
164 | 162 |
165 class TestProfileSyncServiceObserver : public ProfileSyncServiceObserver { | 163 class TestProfileSyncServiceObserver : public ProfileSyncServiceObserver { |
166 public: | 164 public: |
167 explicit TestProfileSyncServiceObserver(ProfileSyncService* service) | 165 explicit TestProfileSyncServiceObserver(ProfileSyncService* service) |
168 : service_(service), first_setup_in_progress_(false) {} | 166 : service_(service), first_setup_in_progress_(false) {} |
169 virtual void OnStateChanged() OVERRIDE { | 167 virtual void OnStateChanged() OVERRIDE { |
170 first_setup_in_progress_ = service_->FirstSetupInProgress(); | 168 first_setup_in_progress_ = service_->FirstSetupInProgress(); |
171 } | 169 } |
172 bool first_setup_in_progress() const { return first_setup_in_progress_; } | 170 bool first_setup_in_progress() const { return first_setup_in_progress_; } |
173 private: | 171 private: |
174 ProfileSyncService* service_; | 172 ProfileSyncService* service_; |
175 bool first_setup_in_progress_; | 173 bool first_setup_in_progress_; |
176 }; | 174 }; |
177 | 175 |
178 TEST_F(ProfileSyncServiceTest, InitialState) { | 176 TEST_F(ProfileSyncServiceTest, InitialState) { |
179 SigninManagerBase* signin = | 177 SigninManagerBase* signin = |
180 SigninManagerFactory::GetForProfile(profile_.get()); | 178 SigninManagerFactory::GetForProfile(profile_.get()); |
181 OAuth2TokenService* oauth2_token_service = | 179 ProfileOAuth2TokenService* oauth2_token_service = |
182 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 180 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
183 service_.reset(new TestProfileSyncService( | 181 service_.reset(new TestProfileSyncService( |
184 new ProfileSyncComponentsFactoryMock(), | 182 new ProfileSyncComponentsFactoryMock(), |
185 profile_.get(), | 183 profile_.get(), |
186 signin, | 184 signin, |
187 oauth2_token_service, | 185 oauth2_token_service, |
188 ProfileSyncService::MANUAL_START, | 186 ProfileSyncService::MANUAL_START, |
189 true)); | 187 true)); |
190 service_->Initialize(); | 188 service_->Initialize(); |
191 EXPECT_TRUE( | 189 EXPECT_TRUE( |
(...skipping 16 matching lines...) Expand all Loading... |
208 EXPECT_FALSE(observer.first_setup_in_progress()); | 206 EXPECT_FALSE(observer.first_setup_in_progress()); |
209 service.RemoveObserver(&observer); | 207 service.RemoveObserver(&observer); |
210 } | 208 } |
211 | 209 |
212 TEST_F(ProfileSyncServiceTest, DisabledByPolicy) { | 210 TEST_F(ProfileSyncServiceTest, DisabledByPolicy) { |
213 profile_->GetTestingPrefService()->SetManagedPref( | 211 profile_->GetTestingPrefService()->SetManagedPref( |
214 prefs::kSyncManaged, | 212 prefs::kSyncManaged, |
215 Value::CreateBooleanValue(true)); | 213 Value::CreateBooleanValue(true)); |
216 SigninManagerBase* signin = | 214 SigninManagerBase* signin = |
217 SigninManagerFactory::GetForProfile(profile_.get()); | 215 SigninManagerFactory::GetForProfile(profile_.get()); |
218 OAuth2TokenService* oauth2_token_service = | 216 ProfileOAuth2TokenService* oauth2_token_service = |
219 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 217 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
220 service_.reset(new TestProfileSyncService( | 218 service_.reset(new TestProfileSyncService( |
221 new ProfileSyncComponentsFactoryMock(), | 219 new ProfileSyncComponentsFactoryMock(), |
222 profile_.get(), | 220 profile_.get(), |
223 signin, | 221 signin, |
224 oauth2_token_service, | 222 oauth2_token_service, |
225 ProfileSyncService::MANUAL_START, | 223 ProfileSyncService::MANUAL_START, |
226 true)); | 224 true)); |
227 service_->Initialize(); | 225 service_->Initialize(); |
228 EXPECT_TRUE(service_->IsManaged()); | 226 EXPECT_TRUE(service_->IsManaged()); |
229 } | 227 } |
230 | 228 |
231 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { | 229 TEST_F(ProfileSyncServiceTest, AbortedByShutdown) { |
232 SigninManagerBase* signin = | 230 SigninManagerBase* signin = |
233 SigninManagerFactory::GetForProfile(profile_.get()); | 231 SigninManagerFactory::GetForProfile(profile_.get()); |
234 signin->SetAuthenticatedUsername("test"); | 232 signin->SetAuthenticatedUsername("test"); |
235 OAuth2TokenService* oauth2_token_service = | 233 ProfileOAuth2TokenService* oauth2_token_service = |
236 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 234 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
237 ProfileSyncComponentsFactoryMock* factory = | 235 ProfileSyncComponentsFactoryMock* factory = |
238 new ProfileSyncComponentsFactoryMock(); | 236 new ProfileSyncComponentsFactoryMock(); |
239 service_.reset(new TestProfileSyncService( | 237 service_.reset(new TestProfileSyncService( |
240 factory, | 238 factory, |
241 profile_.get(), | 239 profile_.get(), |
242 signin, | 240 signin, |
243 oauth2_token_service, | 241 oauth2_token_service, |
244 ProfileSyncService::AUTO_START, | 242 ProfileSyncService::AUTO_START, |
245 true)); | 243 true)); |
246 EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)).Times(0); | 244 EXPECT_CALL(*factory, CreateDataTypeManager(_, _, _, _, _, _)).Times(0); |
247 EXPECT_CALL(*factory, CreateBookmarkSyncComponents(_, _)). | 245 EXPECT_CALL(*factory, CreateBookmarkSyncComponents(_, _)). |
248 Times(0); | 246 Times(0); |
249 service_->RegisterDataTypeController( | 247 service_->RegisterDataTypeController( |
250 new BookmarkDataTypeController(service_->factory(), | 248 new BookmarkDataTypeController(service_->factory(), |
251 profile_.get(), | 249 profile_.get(), |
252 service_.get())); | 250 service_.get())); |
253 | 251 |
254 service_->Initialize(); | 252 service_->Initialize(); |
255 service_->Shutdown(); | 253 service_->Shutdown(); |
256 service_.reset(); | 254 service_.reset(); |
257 } | 255 } |
258 | 256 |
259 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { | 257 TEST_F(ProfileSyncServiceTest, DisableAndEnableSyncTemporarily) { |
260 SigninManagerBase* signin = | 258 SigninManagerBase* signin = |
261 SigninManagerFactory::GetForProfile(profile_.get()); | 259 SigninManagerFactory::GetForProfile(profile_.get()); |
262 signin->SetAuthenticatedUsername("test"); | 260 signin->SetAuthenticatedUsername("test"); |
263 OAuth2TokenService* oauth2_token_service = | 261 ProfileOAuth2TokenService* oauth2_token_service = |
264 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 262 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
265 ProfileSyncComponentsFactoryMock* factory = | 263 ProfileSyncComponentsFactoryMock* factory = |
266 new ProfileSyncComponentsFactoryMock(); | 264 new ProfileSyncComponentsFactoryMock(); |
267 service_.reset(new TestProfileSyncService( | 265 service_.reset(new TestProfileSyncService( |
268 factory, | 266 factory, |
269 profile_.get(), | 267 profile_.get(), |
270 signin, | 268 signin, |
271 oauth2_token_service, | 269 oauth2_token_service, |
272 ProfileSyncService::AUTO_START, | 270 ProfileSyncService::AUTO_START, |
273 true)); | 271 true)); |
(...skipping 20 matching lines...) Expand all Loading... |
294 profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); | 292 profile_->GetPrefs()->GetBoolean(prefs::kSyncSuppressStart)); |
295 } | 293 } |
296 | 294 |
297 // Certain ProfileSyncService tests don't apply to Chrome OS, for example | 295 // Certain ProfileSyncService tests don't apply to Chrome OS, for example |
298 // things that deal with concepts like "signing out" and policy. | 296 // things that deal with concepts like "signing out" and policy. |
299 #if !defined (OS_CHROMEOS) | 297 #if !defined (OS_CHROMEOS) |
300 | 298 |
301 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { | 299 TEST_F(ProfileSyncServiceTest, EnableSyncAndSignOut) { |
302 SigninManager* signin = | 300 SigninManager* signin = |
303 SigninManagerFactory::GetForProfile(profile_.get()); | 301 SigninManagerFactory::GetForProfile(profile_.get()); |
304 signin->SetAuthenticatedUsername("test@test.com"); | 302 signin->SetAuthenticatedUsername("test"); |
305 OAuth2TokenService* oauth2_token_service = | 303 ProfileOAuth2TokenService* oauth2_token_service = |
306 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); | 304 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_.get()); |
307 ProfileSyncComponentsFactoryMock* factory = | 305 ProfileSyncComponentsFactoryMock* factory = |
308 new ProfileSyncComponentsFactoryMock(); | 306 new ProfileSyncComponentsFactoryMock(); |
309 service_.reset(new TestProfileSyncService( | 307 service_.reset(new TestProfileSyncService( |
310 factory, | 308 factory, |
311 profile_.get(), | 309 profile_.get(), |
312 signin, | 310 signin, |
313 oauth2_token_service, | 311 oauth2_token_service, |
314 ProfileSyncService::AUTO_START, | 312 ProfileSyncService::AUTO_START, |
315 true)); | 313 true)); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 TEST_F(ProfileSyncServiceTest, FailToDownloadControlTypes) { | 488 TEST_F(ProfileSyncServiceTest, FailToDownloadControlTypes) { |
491 StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, | 489 StartSyncServiceAndSetInitialSyncEnded(false, true, true, true, |
492 syncer::STORAGE_IN_MEMORY); | 490 syncer::STORAGE_IN_MEMORY); |
493 | 491 |
494 // The backend is not ready. Ensure the PSS knows this. | 492 // The backend is not ready. Ensure the PSS knows this. |
495 EXPECT_FALSE(service_->sync_initialized()); | 493 EXPECT_FALSE(service_->sync_initialized()); |
496 } | 494 } |
497 | 495 |
498 } // namespace | 496 } // namespace |
499 } // namespace browser_sync | 497 } // namespace browser_sync |
OLD | NEW |