Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / signin / core / browser / test_signin_client.h
blob56a3e76b7dd0bd52d1224ab68697f3c9798bd46d
1 // Copyright 2014 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 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/files/scoped_temp_dir.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/signin/core/browser/signin_client.h"
14 #include "net/url_request/url_request_test_util.h"
16 class PrefService;
18 // An implementation of SigninClient for use in unittests. Instantiates test
19 // versions of the various objects that SigninClient is required to provide as
20 // part of its interface.
21 class TestSigninClient : public SigninClient {
22 public:
23 TestSigninClient(PrefService* pref_service);
24 ~TestSigninClient() override;
26 // SigninClient implementation that is specialized for unit tests.
28 void DoFinalInit() override;
30 // Returns NULL.
31 // NOTE: This should be changed to return a properly-initalized PrefService
32 // once there is a unit test that requires it.
33 PrefService* GetPrefs() override;
35 // Returns a pointer to a loaded database.
36 scoped_refptr<TokenWebData> GetDatabase() override;
38 // Returns true.
39 bool CanRevokeCredentials() override;
41 // Returns empty string.
42 std::string GetSigninScopedDeviceId() override;
44 // Does nothing.
45 void OnSignedOut() override;
47 // Trace that this was called.
48 void PostSignedIn(const std::string& account_id,
49 const std::string& username,
50 const std::string& password) override;
52 std::string get_signed_in_password() { return signed_in_password_; }
54 // Returns the empty string.
55 std::string GetProductVersion() override;
57 // Returns a TestURLRequestContextGetter or an manually provided
58 // URLRequestContextGetter.
59 net::URLRequestContextGetter* GetURLRequestContext() override;
61 // For testing purposes, can override the TestURLRequestContextGetter created
62 // in the default constructor.
63 void SetURLRequestContext(net::URLRequestContextGetter* request_context);
65 // Returns true.
66 bool ShouldMergeSigninCredentialsIntoCookieJar() override;
68 // Registers |callback| and returns the subscription.
69 // Note that |callback| will never be called.
70 scoped_ptr<SigninClient::CookieChangedSubscription> AddCookieChangedCallback(
71 const GURL& url,
72 const std::string& name,
73 const net::CookieStore::CookieChangedCallback& callback) override;
75 bool UpdateAccountInfo(AccountInfo* out_account_info) override;
77 void set_are_signin_cookies_allowed(bool value) {
78 are_signin_cookies_allowed_ = value;
81 // SigninClient overrides:
82 bool IsFirstRun() const override;
83 base::Time GetInstallDate() override;
84 bool AreSigninCookiesAllowed() override;
85 void AddContentSettingsObserver(
86 content_settings::Observer* observer) override;
87 void RemoveContentSettingsObserver(
88 content_settings::Observer* observer) override;
89 void DelayNetworkCall(const base::Closure& callback) override;
90 GaiaAuthFetcher* CreateGaiaAuthFetcher(
91 GaiaAuthConsumer* consumer,
92 const std::string& source,
93 net::URLRequestContextGetter* getter) override;
95 // Loads the token database.
96 void LoadTokenDatabase();
98 private:
99 base::ScopedTempDir temp_dir_;
100 scoped_refptr<net::URLRequestContextGetter> request_context_;
101 scoped_refptr<TokenWebData> database_;
102 PrefService* pref_service_;
103 bool are_signin_cookies_allowed_;
105 // Pointer to be filled by PostSignedIn.
106 std::string signed_in_password_;
108 DISALLOW_COPY_AND_ASSIGN(TestSigninClient);
111 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_