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/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/invalidation/fake_invalidation_service.h" | 13 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
14 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 14 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 15 #include "chrome/browser/signin/account_tracker_service_factory.h" |
15 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" | 16 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
16 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 17 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
18 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
19 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" | 20 #include "chrome/browser/sync/glue/sync_backend_host_mock.h" |
20 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" | 21 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" |
21 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 22 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
25 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
26 #include "chrome/test/base/testing_pref_service_syncable.h" | 27 #include "chrome/test/base/testing_pref_service_syncable.h" |
27 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
28 #include "chrome/test/base/testing_profile_manager.h" | 29 #include "chrome/test/base/testing_profile_manager.h" |
29 #include "components/invalidation/invalidation_service.h" | 30 #include "components/invalidation/invalidation_service.h" |
30 #include "components/invalidation/profile_invalidation_provider.h" | 31 #include "components/invalidation/profile_invalidation_provider.h" |
| 32 #include "components/signin/core/browser/account_tracker_service.h" |
| 33 #include "components/signin/core/browser/signin_manager.h" |
31 #include "components/signin/core/browser/signin_manager.h" | 34 #include "components/signin/core/browser/signin_manager.h" |
32 #include "components/sync_driver/data_type_manager.h" | 35 #include "components/sync_driver/data_type_manager.h" |
33 #include "components/sync_driver/pref_names.h" | 36 #include "components/sync_driver/pref_names.h" |
34 #include "components/sync_driver/sync_prefs.h" | 37 #include "components/sync_driver/sync_prefs.h" |
35 #include "content/public/test/test_browser_thread_bundle.h" | 38 #include "content/public/test/test_browser_thread_bundle.h" |
36 #include "google_apis/gaia/gaia_constants.h" | 39 #include "google_apis/gaia/gaia_constants.h" |
37 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
39 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
40 | 43 |
41 namespace content { | 44 namespace content { |
42 class BrowserContext; | 45 class BrowserContext; |
43 } | 46 } |
44 | 47 |
45 namespace browser_sync { | 48 namespace browser_sync { |
46 | 49 |
47 namespace { | 50 namespace { |
48 | 51 |
| 52 const char kGaiaId[] = "12345"; |
| 53 const char kEmail[] = "test_user@gmail.com"; |
| 54 |
49 class FakeDataTypeManager : public sync_driver::DataTypeManager { | 55 class FakeDataTypeManager : public sync_driver::DataTypeManager { |
50 public: | 56 public: |
51 explicit FakeDataTypeManager(sync_driver::DataTypeManagerObserver* observer) | 57 explicit FakeDataTypeManager(sync_driver::DataTypeManagerObserver* observer) |
52 : observer_(observer) {} | 58 : observer_(observer) {} |
53 ~FakeDataTypeManager() override{}; | 59 ~FakeDataTypeManager() override{}; |
54 | 60 |
55 void Configure(syncer::ModelTypeSet desired_types, | 61 void Configure(syncer::ModelTypeSet desired_types, |
56 syncer::ConfigureReason reason) override { | 62 syncer::ConfigureReason reason) override { |
57 sync_driver::DataTypeManager::ConfigureResult result; | 63 sync_driver::DataTypeManager::ConfigureResult result; |
58 result.status = sync_driver::DataTypeManager::OK; | 64 result.status = sync_driver::DataTypeManager::OK; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 204 |
199 void TearDown() override { | 205 void TearDown() override { |
200 // Kill the service before the profile. | 206 // Kill the service before the profile. |
201 if (service_) | 207 if (service_) |
202 service_->Shutdown(); | 208 service_->Shutdown(); |
203 | 209 |
204 service_.reset(); | 210 service_.reset(); |
205 } | 211 } |
206 | 212 |
207 void IssueTestTokens() { | 213 void IssueTestTokens() { |
| 214 std::string account_id = |
| 215 AccountTrackerServiceFactory::GetForProfile(profile_) |
| 216 ->SeedAccountInfo(kGaiaId, kEmail); |
208 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) | 217 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_) |
209 ->UpdateCredentials("test", "oauth2_login_token"); | 218 ->UpdateCredentials(account_id, "oauth2_login_token"); |
210 } | 219 } |
211 | 220 |
212 void CreateService(ProfileSyncServiceStartBehavior behavior) { | 221 void CreateService(ProfileSyncServiceStartBehavior behavior) { |
213 SigninManagerBase* signin = | 222 SigninManagerBase* signin = |
214 SigninManagerFactory::GetForProfile(profile_); | 223 SigninManagerFactory::GetForProfile(profile_); |
215 signin->SetAuthenticatedUsername("test"); | 224 signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); |
216 ProfileOAuth2TokenService* oauth2_token_service = | 225 ProfileOAuth2TokenService* oauth2_token_service = |
217 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 226 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
218 components_factory_ = new ProfileSyncComponentsFactoryMock(); | 227 components_factory_ = new ProfileSyncComponentsFactoryMock(); |
219 service_.reset(new ProfileSyncService( | 228 service_.reset(new ProfileSyncService( |
220 scoped_ptr<ProfileSyncComponentsFactory>(components_factory_), | 229 scoped_ptr<ProfileSyncComponentsFactory>(components_factory_), |
221 profile_, | 230 profile_, |
222 make_scoped_ptr(new SupervisedUserSigninManagerWrapper(profile_, | 231 make_scoped_ptr(new SupervisedUserSigninManagerWrapper(profile_, |
223 signin)), | 232 signin)), |
224 oauth2_token_service, | 233 oauth2_token_service, |
225 behavior)); | 234 behavior)); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 528 } |
520 | 529 |
521 TEST_F(ProfileSyncServiceTest, BackupBeforeFirstSync) { | 530 TEST_F(ProfileSyncServiceTest, BackupBeforeFirstSync) { |
522 CreateServiceWithoutSignIn(); | 531 CreateServiceWithoutSignIn(); |
523 ExpectDataTypeManagerCreation(2); | 532 ExpectDataTypeManagerCreation(2); |
524 std::vector<bool> delete_dir_param; | 533 std::vector<bool> delete_dir_param; |
525 ExpectSyncBackendHostCreationCollectDeleteDir(2, &delete_dir_param); | 534 ExpectSyncBackendHostCreationCollectDeleteDir(2, &delete_dir_param); |
526 InitializeForFirstSync(); | 535 InitializeForFirstSync(); |
527 | 536 |
528 SigninManagerFactory::GetForProfile(profile()) | 537 SigninManagerFactory::GetForProfile(profile()) |
529 ->SetAuthenticatedUsername("test"); | 538 ->SetAuthenticatedAccountInfo(kGaiaId, kEmail); |
530 IssueTestTokens(); | 539 IssueTestTokens(); |
531 PumpLoop(); | 540 PumpLoop(); |
532 | 541 |
533 // At this time, backup is finished. Task is posted to start sync again. | 542 // At this time, backup is finished. Task is posted to start sync again. |
534 EXPECT_EQ(ProfileSyncService::BACKUP, service()->backend_mode()); | 543 EXPECT_EQ(ProfileSyncService::BACKUP, service()->backend_mode()); |
535 EXPECT_FALSE(service()->SyncActive()); | 544 EXPECT_FALSE(service()->SyncActive()); |
536 EXPECT_EQ(1u, delete_dir_param.size()); | 545 EXPECT_EQ(1u, delete_dir_param.size()); |
537 EXPECT_TRUE(delete_dir_param[0]); | 546 EXPECT_TRUE(delete_dir_param[0]); |
538 | 547 |
539 // Pump loop to start sync. | 548 // Pump loop to start sync. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 EXPECT_FALSE(ProfileSyncService::IsSyncEnabled()); | 654 EXPECT_FALSE(ProfileSyncService::IsSyncEnabled()); |
646 } | 655 } |
647 | 656 |
648 // Verify that no disable sync flag enables sync. | 657 // Verify that no disable sync flag enables sync. |
649 TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) { | 658 TEST_F(ProfileSyncServiceTest, NoDisableSyncFlag) { |
650 EXPECT_TRUE(ProfileSyncService::IsSyncEnabled()); | 659 EXPECT_TRUE(ProfileSyncService::IsSyncEnabled()); |
651 } | 660 } |
652 | 661 |
653 } // namespace | 662 } // namespace |
654 } // namespace browser_sync | 663 } // namespace browser_sync |
OLD | NEW |