test_signin_client.h revision a02191e04bc25c4935f804f2c080ae28663d096d
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.
4
5#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_
6#define COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_
7
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"
15
16#if defined(OS_IOS)
17#include "ios/public/test/fake_profile_oauth2_token_service_ios_provider.h"
18#endif
19
20// An implementation of SigninClient for use in unittests. Instantiates test
21// versions of the various objects that SigninClient is required to provide as
22// part of its interface.
23class TestSigninClient : public SigninClient {
24 public:
25  TestSigninClient();
26  virtual ~TestSigninClient();
27
28  // SigninClient implementation that is specialized for unit tests.
29
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  virtual PrefService* GetPrefs() OVERRIDE;
34
35  // Returns a pointer to a loaded database.
36  virtual scoped_refptr<TokenWebData> GetDatabase() OVERRIDE;
37
38  // Returns true.
39  virtual bool CanRevokeCredentials() OVERRIDE;
40
41  // Returns the empty string.
42  virtual std::string GetProductVersion() OVERRIDE;
43
44  // Returns a TestURLRequestContextGetter.
45  virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
46
47#if defined(OS_IOS)
48  virtual ios::ProfileOAuth2TokenServiceIOSProvider* GetIOSProvider() OVERRIDE;
49#endif
50
51  // Returns true.
52  virtual bool ShouldMergeSigninCredentialsIntoCookieJar() OVERRIDE;
53
54  // Does nothing.
55  virtual void SetCookieChangedCallback(const CookieChangedCallback& callback)
56      OVERRIDE;
57
58#if defined(OS_IOS)
59  ios::FakeProfileOAuth2TokenServiceIOSProvider* GetIOSProviderAsFake();
60#endif
61
62 private:
63  // Loads the token database.
64  void LoadDatabase();
65
66  base::ScopedTempDir temp_dir_;
67  scoped_refptr<net::TestURLRequestContextGetter> request_context_;
68  scoped_refptr<TokenWebData> database_;
69
70#if defined(OS_IOS)
71  scoped_ptr<ios::FakeProfileOAuth2TokenServiceIOSProvider> iosProvider_;
72#endif
73
74  DISALLOW_COPY_AND_ASSIGN(TestSigninClient);
75};
76
77#endif  // COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_
78