[Cleanup] Used scoped pointers in KeyedServiceFactory's SetTestingFactory functions.
[chromium-blink-merge.git] / chrome / browser / signin / fake_signin_manager.h
blob7128ae41309704b19471ea4f4a5eedf0834d020b
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.
5 #ifndef CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_
6 #define CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_
8 #include <string>
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"
15 namespace content {
16 class BrowserContext;
19 class Profile;
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.
25 // Overrides InitTokenService to do-nothing in tests.
26 class FakeSigninManagerBase : public SigninManagerBase {
27 public:
28 explicit FakeSigninManagerBase(Profile* profile);
29 ~FakeSigninManagerBase() override;
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);
39 #if !defined(OS_CHROMEOS)
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;
48 void set_auth_in_progress(const std::string& account_id) {
49 possibly_invalid_account_id_ = account_id;
52 void set_password(const std::string& password) { password_ = password; }
54 void SignIn(const std::string& account_id,
55 const std::string& username,
56 const std::string& password);
58 void FailSignin(const GoogleServiceAuthError& error);
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;
67 void SignOut(signin_metrics::ProfileSignout signout_source_metric) override;
69 void CompletePendingSignin() override;
71 // Username specified in StartSignInWithRefreshToken() call.
72 std::string username_;
75 #endif // !defined (OS_CHROMEOS)
77 #if defined(OS_CHROMEOS)
78 typedef FakeSigninManagerBase FakeSigninManagerForTesting;
79 #else
80 typedef FakeSigninManager FakeSigninManagerForTesting;
81 #endif
83 #endif // CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_