Chromium Code Reviews| 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 // | |
| 16 // Tests would typically do something like the following: | |
| 17 // | |
| 18 // FakeProfileOAuth2TokenService service; | |
| 19 // ... | |
| 20 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers | |
| 21 // ... | |
| 22 // // Confirm that there is at least one active request. | |
| 23 // EXPECT_GT(0U, service.GetPendingRequests().size()); | |
| 24 // ... | |
| 25 // // Make any pending token fetches for a given scope succeed. | |
| 26 // ScopeSet scopes; | |
| 27 // scopes.insert(GaiaConstants::kYourServiceScope); | |
| 28 // IssueTokenForScope(scopes, "access_token", base::Time()::Max()); | |
| 29 // ... | |
| 30 // // ...or make them fail... | |
| 31 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); | |
| 32 // | |
| 33 class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService { | |
| 34 public: | |
| 35 class PendingRequest { | |
| 36 public: | |
| 37 PendingRequest(); | |
| 38 ~PendingRequest(); | |
| 39 std::string client_id; | |
| 40 std::string client_secret; | |
| 41 ScopeSet scopes; | |
| 42 base::WeakPtr<RequestImpl> request; | |
| 43 }; | |
| 44 | |
| 45 FakeProfileOAuth2TokenService(); | |
| 46 virtual ~FakeProfileOAuth2TokenService(); | |
| 47 | |
| 48 // Sets the current refresh token (for signed in profiles). If |token| is | |
| 49 // non-empty, this will fire OnRefreshTokenAvailable() on any Observers. | |
| 50 // OnRefreshTokensLoaded() will always be invoked (so tests can mimic a | |
|
fgorski
2013/08/16 18:41:07
Could this comment be a bit clearer?
I understand
Andrew T Wilson (Slow)
2013/08/19 12:15:56
Rewrote this - hopefully it's clearer.
| |
| 51 // missing refresh token by passing in an empty string). | |
| 52 void IssueRefreshToken(const std::string& token); | |
| 53 | |
| 54 // Gets a list of active requests (can be used by tests to validate that the | |
| 55 // correct request has been issued). | |
| 56 std::vector<PendingRequest> GetPendingRequests(); | |
| 57 | |
| 58 // Helper routines to issue tokens for pending requests (also removes the | |
| 59 // request from our queue of pending requests). | |
|
fgorski
2013/08/16 18:41:07
nit: I get why you make the remove part of the com
Andrew T Wilson (Slow)
2013/08/19 12:15:56
You're right - I wrote the comment before writing
| |
| 60 void IssueTokenForScope(const ScopeSet& scope, | |
|
fgorski
2013/08/16 18:41:07
nit: s/scope/scopes/
Applies elsewhere in this cl
Andrew T Wilson (Slow)
2013/08/19 12:15:56
Done.
| |
| 61 const std::string& access_token, | |
| 62 const base::Time& expiration); | |
| 63 void IssueErrorForScope(const ScopeSet& scope, | |
| 64 const GoogleServiceAuthError& error); | |
| 65 | |
| 66 virtual void Shutdown() OVERRIDE; | |
| 67 | |
| 68 // Helper function to be used with | |
| 69 // BrowserContextKeyedService::SetTestingFactory(). | |
| 70 static BrowserContextKeyedService* Build(content::BrowserContext* profile); | |
| 71 | |
| 72 protected: | |
| 73 // OAuth2TokenService overrides. | |
| 74 virtual void FetchOAuth2Token(RequestImpl* request, | |
| 75 net::URLRequestContextGetter* getter, | |
| 76 const std::string& client_id, | |
| 77 const std::string& client_secret, | |
| 78 const ScopeSet& scopes) OVERRIDE; | |
| 79 | |
| 80 virtual std::string GetRefreshToken() OVERRIDE; | |
| 81 | |
| 82 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | |
| 83 | |
| 84 private: | |
| 85 void CompleteRequests(const ScopeSet& scopes, | |
| 86 const GoogleServiceAuthError& error, | |
| 87 const std::string& access_token, | |
| 88 const base::Time& expiration); | |
| 89 | |
| 90 std::vector<PendingRequest> pending_requests_; | |
| 91 std::string refresh_token_; | |
| 92 }; | |
| 93 | |
| 94 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | |
| OLD | NEW |