Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/signin/fake_profile_oauth2_token_service.h

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Corrected comment. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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. If |token| is non-empty, this will invoke
49 // OnRefreshTokenAvailable() on all Observers, otherwise this will invoke
50 // OnRefreshTokenRevoked().
51 void IssueRefreshToken(const std::string& token);
52
53 // Gets a list of active requests (can be used by tests to validate that the
54 // correct request has been issued).
55 std::vector<PendingRequest> GetPendingRequests();
56
57 // Helper routines to issue tokens for pending requests.
58 void IssueTokenForScope(const ScopeSet& scopes,
59 const std::string& access_token,
60 const base::Time& expiration);
61 void IssueErrorForScope(const ScopeSet& scopes,
62 const GoogleServiceAuthError& error);
63
64 void IssueTokenForAllPendingRequests(const std::string& access_token,
65 const base::Time& expiration);
66
67 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error);
68
69 virtual void Shutdown() OVERRIDE;
70
71 // Helper function to be used with
72 // BrowserContextKeyedService::SetTestingFactory().
73 static BrowserContextKeyedService* Build(content::BrowserContext* profile);
74
75 protected:
76 // OAuth2TokenService overrides.
77 virtual void FetchOAuth2Token(RequestImpl* request,
78 net::URLRequestContextGetter* getter,
79 const std::string& client_id,
80 const std::string& client_secret,
81 const ScopeSet& scopes) OVERRIDE;
82
83 virtual std::string GetRefreshToken() OVERRIDE;
84
85 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
86
87 private:
88 // Helper function to complete pending requests - if |all_scopes| is true,
89 // then all pending requests are completed, otherwise, only those requests
90 // matching |scopes| are completed.
91 void CompleteRequests(bool all_scopes,
92 const ScopeSet& scopes,
93 const GoogleServiceAuthError& error,
94 const std::string& access_token,
95 const base::Time& expiration);
96
97 std::vector<PendingRequest> pending_requests_;
98 std::string refresh_token_;
99 };
100
101 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698