test_signin_client.h revision 116680a4aac90f2aa7413d9095a592090648e557
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 20class PrefService; 21 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. 25class TestSigninClient : public SigninClient { 26 public: 27 TestSigninClient(); 28 TestSigninClient(PrefService* pref_service); 29 virtual ~TestSigninClient(); 30 31 // SigninClient implementation that is specialized for unit tests. 32 33 // Returns NULL. 34 // NOTE: This should be changed to return a properly-initalized PrefService 35 // once there is a unit test that requires it. 36 virtual PrefService* GetPrefs() OVERRIDE; 37 38 // Returns a pointer to a loaded database. 39 virtual scoped_refptr<TokenWebData> GetDatabase() OVERRIDE; 40 41 // Returns true. 42 virtual bool CanRevokeCredentials() OVERRIDE; 43 44 // Returns empty string. 45 virtual std::string GetSigninScopedDeviceId() OVERRIDE; 46 47 // Does nothing. 48 virtual void ClearSigninScopedDeviceId() OVERRIDE; 49 50 // Returns the empty string. 51 virtual std::string GetProductVersion() OVERRIDE; 52 53 // Returns a TestURLRequestContextGetter. 54 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE; 55 56#if defined(OS_IOS) 57 virtual ios::ProfileOAuth2TokenServiceIOSProvider* GetIOSProvider() OVERRIDE; 58#endif 59 60 // Returns true. 61 virtual bool ShouldMergeSigninCredentialsIntoCookieJar() OVERRIDE; 62 63 // Does nothing. 64 virtual void SetCookieChangedCallback(const CookieChangedCallback& callback) 65 OVERRIDE; 66 67#if defined(OS_IOS) 68 ios::FakeProfileOAuth2TokenServiceIOSProvider* GetIOSProviderAsFake(); 69#endif 70 71 // SigninClient overrides: 72 virtual void SetSigninProcess(int host_id) OVERRIDE; 73 virtual void ClearSigninProcess() OVERRIDE; 74 virtual bool IsSigninProcess(int host_id) const OVERRIDE; 75 virtual bool HasSigninProcess() const OVERRIDE; 76 77 private: 78 // Loads the token database. 79 void LoadDatabase(); 80 81 base::ScopedTempDir temp_dir_; 82 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 83 scoped_refptr<TokenWebData> database_; 84 int signin_host_id_; 85 86 PrefService* pref_service_; 87 88#if defined(OS_IOS) 89 scoped_ptr<ios::FakeProfileOAuth2TokenServiceIOSProvider> iosProvider_; 90#endif 91 92 DISALLOW_COPY_AND_ASSIGN(TestSigninClient); 93}; 94 95#endif // COMPONENTS_SIGNIN_CORE_BROWSER_TEST_SIGNIN_CLIENT_H_ 96