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/callback.h" | 6 #include "base/callback.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/invalidation/fake_invalidation_service.h" | 17 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
18 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 18 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
19 #include "chrome/browser/signin/account_tracker_service_factory.h" | 19 #include "chrome/browser/signin/account_tracker_service_factory.h" |
20 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 20 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
22 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/browser/sync/chrome_sync_client.h" |
23 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | 24 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" |
24 #include "chrome/browser/sync/profile_sync_service.h" | 25 #include "chrome/browser/sync/profile_sync_service.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "chrome/test/base/testing_browser_process.h" | 29 #include "chrome/test/base/testing_browser_process.h" |
29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
30 #include "chrome/test/base/testing_profile_manager.h" | 31 #include "chrome/test/base/testing_profile_manager.h" |
31 #include "components/invalidation/impl/profile_invalidation_provider.h" | 32 #include "components/invalidation/impl/profile_invalidation_provider.h" |
32 #include "components/invalidation/public/invalidation_service.h" | 33 #include "components/invalidation/public/invalidation_service.h" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 271 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
271 ->UpdateCredentials(account_id, "oauth2_login_token"); | 272 ->UpdateCredentials(account_id, "oauth2_login_token"); |
272 } | 273 } |
273 | 274 |
274 void CreateService(ProfileSyncServiceStartBehavior behavior) { | 275 void CreateService(ProfileSyncServiceStartBehavior behavior) { |
275 SigninManagerBase* signin = | 276 SigninManagerBase* signin = |
276 SigninManagerFactory::GetForProfile(profile_); | 277 SigninManagerFactory::GetForProfile(profile_); |
277 signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); | 278 signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); |
278 ProfileOAuth2TokenService* oauth2_token_service = | 279 ProfileOAuth2TokenService* oauth2_token_service = |
279 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 280 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
280 components_factory_.reset(new SyncApiComponentFactoryMock()); | 281 scoped_ptr<SyncApiComponentFactoryMock> components_factory( |
281 scoped_ptr<sync_driver::FakeSyncClient> sync_client( | 282 new SyncApiComponentFactoryMock()); |
282 new sync_driver::FakeSyncClient(components_factory_.get())); | 283 components_factory_ = components_factory.get(); |
| 284 scoped_ptr<ChromeSyncClient> sync_client( |
| 285 new ChromeSyncClient(profile_, components_factory.Pass())); |
283 service_.reset(new ProfileSyncService( | 286 service_.reset(new ProfileSyncService( |
284 sync_client.Pass(), profile_, | 287 sync_client.Pass(), profile_, |
285 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, | 288 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, |
286 behavior)); | 289 behavior)); |
287 service_->SetClearingBrowseringDataForTesting( | 290 service_->SetClearingBrowseringDataForTesting( |
288 base::Bind(&ProfileSyncServiceTest::ClearBrowsingDataCallback, | 291 base::Bind(&ProfileSyncServiceTest::ClearBrowsingDataCallback, |
289 base::Unretained(this))); | 292 base::Unretained(this))); |
290 service_->RegisterDataTypeController( | 293 service_->RegisterDataTypeController( |
291 new sync_driver::FakeDataTypeController(syncer::BOOKMARKS)); | 294 new sync_driver::FakeDataTypeController(syncer::BOOKMARKS)); |
292 } | 295 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 390 |
388 TestingProfile* profile() { | 391 TestingProfile* profile() { |
389 return profile_; | 392 return profile_; |
390 } | 393 } |
391 | 394 |
392 ProfileSyncService* service() { | 395 ProfileSyncService* service() { |
393 return service_.get(); | 396 return service_.get(); |
394 } | 397 } |
395 | 398 |
396 SyncApiComponentFactoryMock* components_factory() { | 399 SyncApiComponentFactoryMock* components_factory() { |
397 return components_factory_.get(); | 400 return components_factory_; |
398 } | 401 } |
399 | 402 |
400 void ClearBrowsingDataCallback(BrowsingDataRemover::Observer* observer, | 403 void ClearBrowsingDataCallback(BrowsingDataRemover::Observer* observer, |
401 Profile* profile, | 404 Profile* profile, |
402 base::Time start, | 405 base::Time start, |
403 base::Time end) { | 406 base::Time end) { |
404 EXPECT_EQ(profile_, profile); | 407 EXPECT_EQ(profile_, profile); |
405 clear_browsing_date_start_ = start; | 408 clear_browsing_date_start_ = start; |
406 } | 409 } |
407 | 410 |
408 protected: | 411 protected: |
409 void PumpLoop() { | 412 void PumpLoop() { |
410 base::RunLoop run_loop; | 413 base::RunLoop run_loop; |
411 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 414 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
412 run_loop.QuitClosure()); | 415 run_loop.QuitClosure()); |
413 run_loop.Run(); | 416 run_loop.Run(); |
414 } | 417 } |
415 | 418 |
416 // The requested start time when ClearBrowsingDataCallback is called. | 419 // The requested start time when ClearBrowsingDataCallback is called. |
417 base::Time clear_browsing_date_start_; | 420 base::Time clear_browsing_date_start_; |
418 | 421 |
419 private: | 422 private: |
420 content::TestBrowserThreadBundle thread_bundle_; | 423 content::TestBrowserThreadBundle thread_bundle_; |
421 TestingProfileManager profile_manager_; | 424 TestingProfileManager profile_manager_; |
422 TestingProfile* profile_; | 425 TestingProfile* profile_; |
423 scoped_ptr<ProfileSyncService> service_; | 426 scoped_ptr<ProfileSyncService> service_; |
424 | 427 |
425 // The current component factory used by sync. May be null if the server | 428 // The current component factory used by sync. May be null if the server |
426 // hasn't been created yet. | 429 // hasn't been created yet. |
427 scoped_ptr<SyncApiComponentFactoryMock> components_factory_; | 430 SyncApiComponentFactoryMock* components_factory_; |
428 }; | 431 }; |
429 | 432 |
430 // Verify that the server URLs are sane. | 433 // Verify that the server URLs are sane. |
431 TEST_F(ProfileSyncServiceTest, InitialState) { | 434 TEST_F(ProfileSyncServiceTest, InitialState) { |
432 CreateService(browser_sync::AUTO_START); | 435 CreateService(browser_sync::AUTO_START); |
433 InitializeForNthSync(); | 436 InitializeForNthSync(); |
434 const std::string& url = service()->sync_service_url().spec(); | 437 const std::string& url = service()->sync_service_url().spec(); |
435 EXPECT_TRUE(url == internal::kSyncServerUrl || | 438 EXPECT_TRUE(url == internal::kSyncServerUrl || |
436 url == internal::kSyncDevServerUrl); | 439 url == internal::kSyncDevServerUrl); |
437 } | 440 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 InitializeForNthSync(); | 999 InitializeForNthSync(); |
997 | 1000 |
998 syncer::SyncProtocolError client_cmd; | 1001 syncer::SyncProtocolError client_cmd; |
999 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; | 1002 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; |
1000 service()->OnActionableError(client_cmd); | 1003 service()->OnActionableError(client_cmd); |
1001 EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); | 1004 EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); |
1002 } | 1005 } |
1003 | 1006 |
1004 } // namespace | 1007 } // namespace |
1005 } // namespace browser_sync | 1008 } // namespace browser_sync |
OLD | NEW |