Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / components / password_manager / sync / browser / sync_username_test_base.h
blobb039b1dd825c4843b08e429c6eca61a27f573b8f
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
3 // found in the LICENSE file.
5 // A base test fixture for mocking sync and signin infrastructure. Used for
6 // testing sync-related code.
8 #ifndef COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_
9 #define COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_
11 #include "components/autofill/core/common/password_form.h"
12 #include "components/pref_registry/testing_pref_service_syncable.h"
13 #include "components/signin/core/browser/account_tracker_service.h"
14 #include "components/signin/core/browser/signin_manager_base.h"
15 #include "components/signin/core/browser/test_signin_client.h"
16 #include "components/sync_driver/fake_sync_service.h"
17 #include "sync/internal_api/public/base/model_type.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace password_manager {
22 class SyncUsernameTestBase : public testing::Test {
23 public:
24 SyncUsernameTestBase();
25 ~SyncUsernameTestBase() override;
27 // Instruct the signin manager to sign in with |email| or out.
28 void FakeSigninAs(const std::string& email);
29 void FakeSignout();
31 // Produce a sample PasswordForm.
32 static autofill::PasswordForm SimpleGaiaForm(const char* username);
33 static autofill::PasswordForm SimpleNonGaiaForm(const char* username);
35 // Instruct the sync service to pretend whether or not it is syncing
36 // passwords.
37 void SetSyncingPasswords(bool syncing_passwords);
39 const sync_driver::SyncService* sync_service() const {
40 return &sync_service_;
43 const SigninManagerBase* signin_manager() { return &signin_manager_; }
45 private:
46 class LocalFakeSyncService : public sync_driver::FakeSyncService {
47 public:
48 LocalFakeSyncService();
49 ~LocalFakeSyncService() override;
51 // sync_driver::SyncService:
52 syncer::ModelTypeSet GetPreferredDataTypes() const override;
54 void set_syncing_passwords(bool syncing_passwords) {
55 syncing_passwords_ = syncing_passwords;
58 private:
59 bool syncing_passwords_;
62 class FakeSigninManagerBase : public SigninManagerBase {
63 public:
64 FakeSigninManagerBase(SigninClient* client,
65 AccountTrackerService* account_tracker_service)
66 : SigninManagerBase(client, account_tracker_service) {}
68 using SigninManagerBase::clear_authenticated_user;
71 user_prefs::TestingPrefServiceSyncable prefs_;
72 TestSigninClient signin_client_;
73 AccountTrackerService account_tracker_;
74 FakeSigninManagerBase signin_manager_;
75 LocalFakeSyncService sync_service_;
78 } // namespace password_manager
80 #endif // COMPONENTS_PASSWORD_MANAGER_SYNC_BROWSER_SYNC_USERNAME_TEST_BASE_H_