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

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: Merge with ToT 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
5 #ifndef CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
6 #define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
7
8 #include "chrome/browser/signin/profile_oauth2_token_service.h"
9
10 #include <string>
11 #include <vector>
12
13 #include "base/compiler_specific.h"
14 #include "base/memory/weak_ptr.h"
15
16 namespace content {
17 class BrowserContext;
18 }
19
20 // Helper class to simplify writing unittests that depend on an instance of
21 // ProfileOAuth2TokenService.
22 //
23 // Tests would typically do something like the following:
24 //
25 // FakeProfileOAuth2TokenService service;
26 // ...
27 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers
28 // ...
29 // // Confirm that there is at least one active request.
30 // EXPECT_GT(0U, service.GetPendingRequests().size());
31 // ...
32 // // Make any pending token fetches for a given scope succeed.
33 // ScopeSet scopes;
34 // scopes.insert(GaiaConstants::kYourServiceScope);
35 // IssueTokenForScope(scopes, "access_token", base::Time()::Max());
36 // ...
37 // // ...or make them fail...
38 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS));
39 //
40 class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService {
41 public:
42 struct PendingRequest {
43 PendingRequest();
44 ~PendingRequest();
Bernhard Bauer 2013/08/20 09:39:03 Nit: Add a newline?
Andrew T Wilson (Slow) 2013/08/20 12:24:22 Done.
45 std::string client_id;
46 std::string client_secret;
47 ScopeSet scopes;
48 base::WeakPtr<RequestImpl> request;
49 };
50
51 FakeProfileOAuth2TokenService();
52 virtual ~FakeProfileOAuth2TokenService();
53
54 // Sets the current refresh token. If |token| is non-empty, this will invoke
55 // OnRefreshTokenAvailable() on all Observers, otherwise this will invoke
56 // OnRefreshTokenRevoked().
57 void IssueRefreshToken(const std::string& token);
58
59 // Gets a list of active requests (can be used by tests to validate that the
60 // correct request has been issued).
61 std::vector<PendingRequest> GetPendingRequests();
62
63 // Helper routines to issue tokens for pending requests.
64 void IssueTokenForScope(const ScopeSet& scopes,
65 const std::string& access_token,
66 const base::Time& expiration);
67
68 void IssueErrorForScope(const ScopeSet& scopes,
69 const GoogleServiceAuthError& error);
70
71 void IssueTokenForAllPendingRequests(const std::string& access_token,
72 const base::Time& expiration);
73
74 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error);
75
76 virtual void Shutdown() OVERRIDE;
77
78 // Helper function to be used with
79 // BrowserContextKeyedService::SetTestingFactory().
80 static BrowserContextKeyedService* Build(content::BrowserContext* profile);
81
82 protected:
83 // OAuth2TokenService overrides.
84 virtual void FetchOAuth2Token(RequestImpl* request,
85 net::URLRequestContextGetter* getter,
86 const std::string& client_id,
87 const std::string& client_secret,
88 const ScopeSet& scopes) OVERRIDE;
89
90 virtual std::string GetRefreshToken() OVERRIDE;
91
92 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
93
94 private:
95 // Helper function to complete pending requests - if |all_scopes| is true,
96 // then all pending requests are completed, otherwise, only those requests
97 // matching |scopes| are completed.
98 void CompleteRequests(bool all_scopes,
99 const ScopeSet& scopes,
100 const GoogleServiceAuthError& error,
101 const std::string& access_token,
102 const base::Time& expiration);
103
104 std::vector<PendingRequest> pending_requests_;
105 std::string refresh_token_;
106
107 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService);
108 };
109
110 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698