| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // A base test fixture for mocking sync and signin infrastructure. Used for | 5 // A base test fixture for mocking sync and signin infrastructure. Used for |
| 6 // testing sync-related code. | 6 // testing sync-related code. |
| 7 | 7 |
| 8 #ifndef COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_ | 8 #ifndef COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_ |
| 9 #define COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_ | 9 #define COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_ |
| 10 | 10 |
| 11 #include <string> |
| 12 |
| 11 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
| 12 #include "components/pref_registry/testing_pref_service_syncable.h" | 14 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 13 #include "components/signin/core/browser/account_tracker_service.h" | 15 #include "components/signin/core/browser/account_tracker_service.h" |
| 14 #include "components/signin/core/browser/signin_manager_base.h" | 16 #include "components/signin/core/browser/signin_manager_base.h" |
| 15 #include "components/signin/core/browser/test_signin_client.h" | 17 #include "components/signin/core/browser/test_signin_client.h" |
| 16 #include "components/sync/base/model_type.h" | 18 #include "components/sync/base/model_type.h" |
| 17 #include "components/sync/driver/fake_sync_service.h" | 19 #include "components/sync/driver/fake_sync_service.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 21 |
| 20 namespace password_manager { | 22 namespace password_manager { |
| 21 | 23 |
| 22 class SyncUsernameTestBase : public testing::Test { | 24 class SyncUsernameTestBase : public testing::Test { |
| 23 public: | 25 public: |
| 24 SyncUsernameTestBase(); | 26 SyncUsernameTestBase(); |
| 25 ~SyncUsernameTestBase() override; | 27 ~SyncUsernameTestBase() override; |
| 26 | 28 |
| 27 // Instruct the signin manager to sign in with |email| or out. | 29 // Instruct the signin manager to sign in with |email| or out. |
| 28 void FakeSigninAs(const std::string& email); | 30 void FakeSigninAs(const std::string& email); |
| 29 void FakeSignout(); | 31 void FakeSignout(); |
| 30 | 32 |
| 31 // Produce a sample PasswordForm. | 33 // Produce a sample PasswordForm. |
| 32 static autofill::PasswordForm SimpleGaiaForm(const char* username); | 34 static autofill::PasswordForm SimpleGaiaForm(const char* username); |
| 33 static autofill::PasswordForm SimpleNonGaiaForm(const char* username); | 35 static autofill::PasswordForm SimpleNonGaiaForm(const char* username); |
| 34 | 36 |
| 35 // Instruct the sync service to pretend whether or not it is syncing | 37 // Instruct the sync service to pretend whether or not it is syncing |
| 36 // passwords. | 38 // passwords. |
| 37 void SetSyncingPasswords(bool syncing_passwords); | 39 void SetSyncingPasswords(bool syncing_passwords); |
| 38 | 40 |
| 39 const sync_driver::SyncService* sync_service() const { | 41 const syncer::SyncService* sync_service() const { return &sync_service_; } |
| 40 return &sync_service_; | |
| 41 } | |
| 42 | 42 |
| 43 const SigninManagerBase* signin_manager() { return &signin_manager_; } | 43 const SigninManagerBase* signin_manager() { return &signin_manager_; } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 class LocalFakeSyncService : public sync_driver::FakeSyncService { | 46 class LocalFakeSyncService : public syncer::FakeSyncService { |
| 47 public: | 47 public: |
| 48 LocalFakeSyncService(); | 48 LocalFakeSyncService(); |
| 49 ~LocalFakeSyncService() override; | 49 ~LocalFakeSyncService() override; |
| 50 | 50 |
| 51 // sync_driver::SyncService: | 51 // syncer::SyncService: |
| 52 syncer::ModelTypeSet GetPreferredDataTypes() const override; | 52 syncer::ModelTypeSet GetPreferredDataTypes() const override; |
| 53 | 53 |
| 54 void set_syncing_passwords(bool syncing_passwords) { | 54 void set_syncing_passwords(bool syncing_passwords) { |
| 55 syncing_passwords_ = syncing_passwords; | 55 syncing_passwords_ = syncing_passwords; |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 bool syncing_passwords_; | 59 bool syncing_passwords_; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class FakeSigninManagerBase : public SigninManagerBase { | 62 class FakeSigninManagerBase : public SigninManagerBase { |
| 63 public: | 63 public: |
| 64 FakeSigninManagerBase(SigninClient* client, | 64 FakeSigninManagerBase(SigninClient* client, |
| 65 AccountTrackerService* account_tracker_service) | 65 AccountTrackerService* account_tracker_service) |
| 66 : SigninManagerBase(client, account_tracker_service) {} | 66 : SigninManagerBase(client, account_tracker_service) {} |
| 67 | 67 |
| 68 using SigninManagerBase::clear_authenticated_user; | 68 using SigninManagerBase::clear_authenticated_user; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 user_prefs::TestingPrefServiceSyncable prefs_; | 71 user_prefs::TestingPrefServiceSyncable prefs_; |
| 72 TestSigninClient signin_client_; | 72 TestSigninClient signin_client_; |
| 73 AccountTrackerService account_tracker_; | 73 AccountTrackerService account_tracker_; |
| 74 FakeSigninManagerBase signin_manager_; | 74 FakeSigninManagerBase signin_manager_; |
| 75 LocalFakeSyncService sync_service_; | 75 LocalFakeSyncService sync_service_; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 } // namespace password_manager | 78 } // namespace password_manager |
| 79 | 79 |
| 80 #endif // COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_ | 80 #endif // COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_ |
| OLD | NEW |