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"
17 #include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
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
{
28 TestSigninClient(PrefService
* pref_service
);
29 ~TestSigninClient() override
;
31 // SigninClient implementation that is specialized for unit tests.
34 // NOTE: This should be changed to return a properly-initalized PrefService
35 // once there is a unit test that requires it.
36 PrefService
* GetPrefs() override
;
38 // Returns a pointer to a loaded database.
39 scoped_refptr
<TokenWebData
> GetDatabase() override
;
42 bool CanRevokeCredentials() override
;
44 // Returns empty string.
45 std::string
GetSigninScopedDeviceId() override
;
48 void OnSignedOut() override
;
50 // Trace that this was called.
51 void PostSignedIn(const std::string
& account_id
,
52 const std::string
& username
,
53 const std::string
& password
) override
;
55 std::string
get_signed_in_password() { return signed_in_password_
; }
57 // Returns the empty string.
58 std::string
GetProductVersion() override
;
60 // Returns a TestURLRequestContextGetter or an manually provided
61 // URLRequestContextGetter.
62 net::URLRequestContextGetter
* GetURLRequestContext() override
;
64 // For testing purposes, can override the TestURLRequestContextGetter created
65 // in the default constructor.
66 void SetURLRequestContext(net::URLRequestContextGetter
* request_context
);
69 ios::ProfileOAuth2TokenServiceIOSProvider
* GetIOSProvider() override
;
73 bool ShouldMergeSigninCredentialsIntoCookieJar() override
;
75 // Registers |callback| and returns the subscription.
76 // Note that |callback| will never be called.
77 scoped_ptr
<SigninClient::CookieChangedSubscription
> AddCookieChangedCallback(
79 const std::string
& name
,
80 const net::CookieStore::CookieChangedCallback
& callback
) override
;
83 ios::FakeProfileOAuth2TokenServiceIOSProvider
* GetIOSProviderAsFake();
86 void set_are_signin_cookies_allowed(bool value
) {
87 are_signin_cookies_allowed_
= value
;
90 // SigninClient overrides:
91 bool IsFirstRun() const override
;
92 base::Time
GetInstallDate() override
;
93 bool AreSigninCookiesAllowed() override
;
94 void AddContentSettingsObserver(
95 content_settings::Observer
* observer
) override
;
96 void RemoveContentSettingsObserver(
97 content_settings::Observer
* observer
) override
;
100 // Loads the token database.
103 base::ScopedTempDir temp_dir_
;
104 scoped_refptr
<net::URLRequestContextGetter
> request_context_
;
105 scoped_refptr
<TokenWebData
> database_
;
106 PrefService
* pref_service_
;
107 bool are_signin_cookies_allowed_
;
109 // Pointer to be filled by PostSignedIn.
110 std::string signed_in_password_
;
113 scoped_ptr
<ios::FakeProfileOAuth2TokenServiceIOSProvider
> iosProvider_
;
116 DISALLOW_COPY_AND_ASSIGN(TestSigninClient
);
119 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_