Implement multiple alternative services per origin.
[chromium-blink-merge.git] / components / signin / core / browser / test_signin_client.h
blob8c359707f6b8f4e964ae819c7184081535035ec2
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 #if defined(OS_IOS)
17 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
18 #endif
20 class PrefService;
22 // An implementation of SigninClient for use in unittests. Instantiates test
23 // versions of the various objects that SigninClient is required to provide as
24 // part of its interface.
25 class TestSigninClient : public SigninClient {
26 public:
27 TestSigninClient();
28 TestSigninClient(PrefService* pref_service);
29 ~TestSigninClient() override;
31 // SigninClient implementation that is specialized for unit tests.
33 void DoFinalInit() override;
35 // Returns NULL.
36 // NOTE: This should be changed to return a properly-initalized PrefService
37 // once there is a unit test that requires it.
38 PrefService* GetPrefs() override;
40 // Returns a pointer to a loaded database.
41 scoped_refptr<TokenWebData> GetDatabase() override;
43 // Returns true.
44 bool CanRevokeCredentials() override;
46 // Returns empty string.
47 std::string GetSigninScopedDeviceId() override;
49 // Does nothing.
50 void OnSignedOut() override;
52 // Trace that this was called.
53 void PostSignedIn(const std::string& account_id,
54 const std::string& username,
55 const std::string& password) override;
57 std::string get_signed_in_password() { return signed_in_password_; }
59 // Returns the empty string.
60 std::string GetProductVersion() override;
62 // Returns a TestURLRequestContextGetter or an manually provided
63 // URLRequestContextGetter.
64 net::URLRequestContextGetter* GetURLRequestContext() override;
66 // For testing purposes, can override the TestURLRequestContextGetter created
67 // in the default constructor.
68 void SetURLRequestContext(net::URLRequestContextGetter* request_context);
70 #if defined(OS_IOS)
71 ios::ProfileOAuth2TokenServiceIOSProvider* GetIOSProvider() override;
72 #endif
74 // Returns true.
75 bool ShouldMergeSigninCredentialsIntoCookieJar() override;
77 // Registers |callback| and returns the subscription.
78 // Note that |callback| will never be called.
79 scoped_ptr<SigninClient::CookieChangedSubscription> AddCookieChangedCallback(
80 const GURL& url,
81 const std::string& name,
82 const net::CookieStore::CookieChangedCallback& callback) override;
84 bool UpdateAccountInfo(
85 AccountTrackerService::AccountInfo* out_account_info) override;
87 #if defined(OS_IOS)
88 ios::FakeProfileOAuth2TokenServiceIOSProvider* GetIOSProviderAsFake();
89 #endif
91 void set_are_signin_cookies_allowed(bool value) {
92 are_signin_cookies_allowed_ = value;
95 // SigninClient overrides:
96 bool IsFirstRun() const override;
97 base::Time GetInstallDate() override;
98 bool AreSigninCookiesAllowed() override;
99 void AddContentSettingsObserver(
100 content_settings::Observer* observer) override;
101 void RemoveContentSettingsObserver(
102 content_settings::Observer* observer) override;
103 void DelayNetworkCall(const base::Closure& callback) override;
104 GaiaAuthFetcher* CreateGaiaAuthFetcher(
105 GaiaAuthConsumer* consumer,
106 const std::string& source,
107 net::URLRequestContextGetter* getter) override;
109 private:
110 // Loads the token database.
111 void LoadDatabase();
113 base::ScopedTempDir temp_dir_;
114 scoped_refptr<net::URLRequestContextGetter> request_context_;
115 scoped_refptr<TokenWebData> database_;
116 PrefService* pref_service_;
117 bool are_signin_cookies_allowed_;
119 // Pointer to be filled by PostSignedIn.
120 std::string signed_in_password_;
122 #if defined(OS_IOS)
123 scoped_ptr<ios::FakeProfileOAuth2TokenServiceIOSProvider> iosProvider_;
124 #endif
126 DISALLOW_COPY_AND_ASSIGN(TestSigninClient);
129 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_