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