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

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: Addressed code review feedback. 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.
Mattias Nissler (ping if slow) 2013/08/19 14:03:22 newline
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Done.
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;
Bernhard Bauer 2013/08/19 14:00:06 Make the member variables private?
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Made this a struct instead.
40 std::string client_secret;
41 ScopeSet scopes;
42 base::WeakPtr<RequestImpl> request;
Mattias Nissler (ping if slow) 2013/08/19 14:03:22 #include "base/memory/weak_ptr.h"
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Done.
43 };
44
45 FakeProfileOAuth2TokenService();
46 virtual ~FakeProfileOAuth2TokenService();
47
48 // Sets the current refresh token. This method allows tests to mimic
49 // what happens when the ProfileOAuth2TokenService has finished loading
50 // its refresh token from disk, so OnRefreshTokensLoaded() will be fired
51 // on all Observers. Additionally, if |token| is non-empty, this will also
52 // fire OnRefreshTokenAvailable() on the Observers.
53 void IssueRefreshToken(const std::string& token);
54
55 // Gets a list of active requests (can be used by tests to validate that the
56 // correct request has been issued).
57 std::vector<PendingRequest> GetPendingRequests();
58
59 // Helper routines to issue tokens for pending requests.
60 void IssueTokenForScope(const ScopeSet& scopes,
61 const std::string& access_token,
62 const base::Time& expiration);
63 void IssueErrorForScope(const ScopeSet& scopes,
64 const GoogleServiceAuthError& error);
65
66 void IssueTokenForAllPendingRequests(const std::string& access_token,
67 const base::Time& expiration);
68
Mattias Nissler (ping if slow) 2013/08/19 14:03:22 nit: if no newline on line #63, then none here eit
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Done.
69 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error);
70
71 virtual void Shutdown() OVERRIDE;
72
73 // Helper function to be used with
74 // BrowserContextKeyedService::SetTestingFactory().
75 static BrowserContextKeyedService* Build(content::BrowserContext* profile);
76
77 protected:
78 // OAuth2TokenService overrides.
79 virtual void FetchOAuth2Token(RequestImpl* request,
80 net::URLRequestContextGetter* getter,
81 const std::string& client_id,
82 const std::string& client_secret,
83 const ScopeSet& scopes) OVERRIDE;
84
85 virtual std::string GetRefreshToken() OVERRIDE;
86
87 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
Mattias Nissler (ping if slow) 2013/08/19 14:03:22 #include "base/compiler_specific.h"
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Done.
88
89 private:
90 // Helper function to complete pending requests - if |all_scopes| is true,
91 // then all pending requests are completed, otherwise, only those requests
92 // matching |scopes| are completed.
93 void CompleteRequests(bool all_scopes,
94 const ScopeSet& scopes,
95 const GoogleServiceAuthError& error,
96 const std::string& access_token,
97 const base::Time& expiration);
98
99 std::vector<PendingRequest> pending_requests_;
Mattias Nissler (ping if slow) 2013/08/19 14:03:22 #include <vector>
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Done.
100 std::string refresh_token_;
Mattias Nissler (ping if slow) 2013/08/19 14:03:22 #include <string>
Andrew T Wilson (Slow) 2013/08/20 09:28:35 Done.
101 };
102
103 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698