OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_ |
6 #define CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_ | 6 #define CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "components/signin/core/browser/signin_manager.h" | 11 #include "components/signin/core/browser/signin_manager.h" |
12 #include "components/signin/core/browser/signin_metrics.h" | 12 #include "components/signin/core/browser/signin_metrics.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 class BrowserContext; | 15 class BrowserContext; |
16 } | 16 } |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 // SigninManager to use for testing. Tests should use the type | 20 // SigninManager to use for testing. Tests should use the type |
21 // SigninManagerForTesting to ensure that the right type for their platform is | 21 // SigninManagerForTesting to ensure that the right type for their platform is |
22 // used. | 22 // used. |
23 | 23 |
24 // Overrides InitTokenService to do-nothing in tests. | 24 // Overrides InitTokenService to do-nothing in tests. |
25 class FakeSigninManagerBase : public SigninManagerBase { | 25 class FakeSigninManagerBase : public SigninManagerBase { |
26 public: | 26 public: |
27 explicit FakeSigninManagerBase(Profile* profile); | 27 explicit FakeSigninManagerBase(Profile* profile); |
28 virtual ~FakeSigninManagerBase(); | 28 ~FakeSigninManagerBase() override; |
29 | 29 |
30 // Helper function to be used with | 30 // Helper function to be used with |
31 // KeyedService::SetTestingFactory(). In order to match | 31 // KeyedService::SetTestingFactory(). In order to match |
32 // the API of SigninManagerFactory::GetForProfile(), returns a | 32 // the API of SigninManagerFactory::GetForProfile(), returns a |
33 // FakeSigninManagerBase* on ChromeOS, and a FakeSigninManager* on all other | 33 // FakeSigninManagerBase* on ChromeOS, and a FakeSigninManager* on all other |
34 // platforms. The returned instance is initialized. | 34 // platforms. The returned instance is initialized. |
35 static KeyedService* Build(content::BrowserContext* context); | 35 static KeyedService* Build(content::BrowserContext* context); |
36 }; | 36 }; |
37 | 37 |
38 #if !defined(OS_CHROMEOS) | 38 #if !defined(OS_CHROMEOS) |
39 | 39 |
40 // A signin manager that bypasses actual authentication routines with servers | 40 // A signin manager that bypasses actual authentication routines with servers |
41 // and accepts the credentials provided to StartSignIn. | 41 // and accepts the credentials provided to StartSignIn. |
42 class FakeSigninManager : public SigninManager { | 42 class FakeSigninManager : public SigninManager { |
43 public: | 43 public: |
44 explicit FakeSigninManager(Profile* profile); | 44 explicit FakeSigninManager(Profile* profile); |
45 virtual ~FakeSigninManager(); | 45 ~FakeSigninManager() override; |
46 | 46 |
47 void set_auth_in_progress(const std::string& username) { | 47 void set_auth_in_progress(const std::string& username) { |
48 possibly_invalid_username_ = username; | 48 possibly_invalid_username_ = username; |
49 } | 49 } |
50 | 50 |
51 void set_password(const std::string& password) { password_ = password; } | 51 void set_password(const std::string& password) { password_ = password; } |
52 | 52 |
53 void SignIn(const std::string& username, const std::string& password); | 53 void SignIn(const std::string& username, const std::string& password); |
54 | 54 |
55 void FailSignin(const GoogleServiceAuthError& error); | 55 void FailSignin(const GoogleServiceAuthError& error); |
56 | 56 |
57 virtual void StartSignInWithRefreshToken( | 57 void StartSignInWithRefreshToken( |
58 const std::string& refresh_token, | 58 const std::string& refresh_token, |
59 const std::string& username, | 59 const std::string& username, |
60 const std::string& password, | 60 const std::string& password, |
61 const OAuthTokenFetchedCallback& oauth_fetched_callback) override; | 61 const OAuthTokenFetchedCallback& oauth_fetched_callback) override; |
62 | 62 |
63 virtual void SignOut(signin_metrics::ProfileSignout signout_source_metric) | 63 void SignOut(signin_metrics::ProfileSignout signout_source_metric) override; |
64 override; | |
65 | 64 |
66 virtual void CompletePendingSignin() override; | 65 void CompletePendingSignin() override; |
67 }; | 66 }; |
68 | 67 |
69 #endif // !defined (OS_CHROMEOS) | 68 #endif // !defined (OS_CHROMEOS) |
70 | 69 |
71 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
72 typedef FakeSigninManagerBase FakeSigninManagerForTesting; | 71 typedef FakeSigninManagerBase FakeSigninManagerForTesting; |
73 #else | 72 #else |
74 typedef FakeSigninManager FakeSigninManagerForTesting; | 73 typedef FakeSigninManager FakeSigninManagerForTesting; |
75 #endif | 74 #endif |
76 | 75 |
77 #endif // CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_ | 76 #endif // CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_ |
OLD | NEW |