| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| 5 #define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| 6 |
| 7 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 8 |
| 9 namespace content { |
| 10 class BrowserContext; |
| 11 } |
| 12 |
| 13 // Helper class to simplify writing unittests that depend on an instance of |
| 14 // ProfileOAuth2TokenService. |
| 15 class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService { |
| 16 public: |
| 17 struct PendingRequest { |
| 18 std::string client_id; |
| 19 std::string client_secret; |
| 20 ScopeSet scopes; |
| 21 base::WeakPtr<RequestImpl> request; |
| 22 }; |
| 23 |
| 24 FakeProfileOAuth2TokenService(); |
| 25 ~FakeProfileOAuth2TokenService(); |
| 26 |
| 27 // Sets the current refresh token (for signed in profiles). If |token| is |
| 28 // non-empty, this will fire OnRefreshTokenAvailable() on any Observers. |
| 29 // OnRefreshTokensLoaded() will always be invoked (so tests can mimic a |
| 30 // missing refresh token by passing in an empty string). |
| 31 void IssueRefreshToken(const std::string& token); |
| 32 |
| 33 // Gets a list of active requests (can be used by tests to validate that the |
| 34 // correct request has been issued). |
| 35 std::vector<PendingRequest> GetPendingRequests(); |
| 36 |
| 37 // Helper routines to issue tokens for pending requests (also removes the |
| 38 // request from our queue of pending requests). |
| 39 void IssueTokenForScope(const ScopeSet& scope, |
| 40 const std::string& access_token, |
| 41 const base::Time& expiration); |
| 42 void IssueErrorForScope(const ScopeSet& scope, |
| 43 const GoogleServiceAuthError& error); |
| 44 |
| 45 virtual void Shutdown() OVERRIDE; |
| 46 |
| 47 // Helper function to be used with |
| 48 // BrowserContextKeyedService::SetTestingFactory(). |
| 49 static BrowserContextKeyedService* Build(content::BrowserContext* profile); |
| 50 |
| 51 protected: |
| 52 // OAuth2TokenService overrides. |
| 53 virtual void FetchOAuth2Token(RequestImpl* request, |
| 54 net::URLRequestContextGetter* getter, |
| 55 const std::string& client_id, |
| 56 const std::string& client_secret, |
| 57 const ScopeSet& scopes) OVERRIDE; |
| 58 |
| 59 virtual std::string GetRefreshToken() OVERRIDE; |
| 60 |
| 61 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
| 62 |
| 63 private: |
| 64 void CompleteRequests(const ScopeSet& scopes, |
| 65 const GoogleServiceAuthError& error, |
| 66 const std::string& access_token, |
| 67 const base::Time& expiration); |
| 68 |
| 69 std::vector<PendingRequest> pending_requests_; |
| 70 std::string refresh_token_; |
| 71 }; |
| 72 |
| 73 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |