Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / fake_signin_manager.h
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 "components/signin/core/browser/signin_manager.h"
12
13 namespace content {
14 class BrowserContext;
15 }
16
17 class Profile;
18
19 // SigninManager to use for testing. Tests should use the type
20 // SigninManagerForTesting to ensure that the right type for their platform is
21 // used.
22
23 // Overrides InitTokenService to do-nothing in tests.
24 class FakeSigninManagerBase : public SigninManagerBase {
25  public:
26   explicit FakeSigninManagerBase(Profile* profile);
27   virtual ~FakeSigninManagerBase();
28
29   // Helper function to be used with
30   // KeyedService::SetTestingFactory(). In order to match
31   // the API of SigninManagerFactory::GetForProfile(), returns a
32   // FakeSigninManagerBase* on ChromeOS, and a FakeSigninManager* on all other
33   // platforms. The returned instance is initialized.
34   static KeyedService* Build(content::BrowserContext* context);
35 };
36
37 #if !defined(OS_CHROMEOS)
38
39 // A signin manager that bypasses actual authentication routines with servers
40 // and accepts the credentials provided to StartSignIn.
41 class FakeSigninManager : public SigninManager {
42  public:
43   explicit FakeSigninManager(Profile* profile);
44   virtual ~FakeSigninManager();
45
46   void set_auth_in_progress(const std::string& username) {
47     possibly_invalid_username_ = username;
48   }
49
50   void set_password(const std::string& password) { password_ = password; }
51
52   void SignIn(const std::string& username, const std::string& password);
53
54   void FailSignin(const GoogleServiceAuthError& error);
55
56   virtual void StartSignInWithRefreshToken(
57       const std::string& refresh_token,
58       const std::string& username,
59       const std::string& password,
60       const OAuthTokenFetchedCallback& oauth_fetched_callback) OVERRIDE;
61
62   virtual void SignOut() OVERRIDE;
63
64   virtual void CompletePendingSignin() OVERRIDE;
65
66   virtual void AddMergeSessionObserver(
67       MergeSessionHelper::Observer* observer) OVERRIDE;
68   virtual void RemoveMergeSessionObserver(
69       MergeSessionHelper::Observer* observer) OVERRIDE;
70
71   void NotifyMergeSessionObservers(const GoogleServiceAuthError& error);
72
73  private:
74   ObserverList<MergeSessionHelper::Observer, true> merge_session_observer_list_;
75 };
76
77 #endif  // !defined (OS_CHROMEOS)
78
79 #if defined(OS_CHROMEOS)
80 typedef FakeSigninManagerBase FakeSigninManagerForTesting;
81 #else
82 typedef FakeSigninManager FakeSigninManagerForTesting;
83 #endif
84
85 #endif  // CHROME_BROWSER_SIGNIN_FAKE_SIGNIN_MANAGER_H_