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

Unified 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: Android fixes. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/signin/fake_profile_oauth2_token_service.h
diff --git a/chrome/browser/signin/fake_profile_oauth2_token_service.h b/chrome/browser/signin/fake_profile_oauth2_token_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..33fade99a35a348c914a5e6a245515ce576e9a0f
--- /dev/null
+++ b/chrome/browser/signin/fake_profile_oauth2_token_service.h
@@ -0,0 +1,94 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#ifndef CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
+#define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_
+
+#include "chrome/browser/signin/profile_oauth2_token_service.h"
+
+namespace content {
+class BrowserContext;
+}
+
+// Helper class to simplify writing unittests that depend on an instance of
+// ProfileOAuth2TokenService.
+//
+// Tests would typically do something like the following:
+//
+// FakeProfileOAuth2TokenService service;
+// ...
+// service.IssueRefreshToken("token"); // Issue refresh token/notify observers
+// ...
+// // Confirm that there is at least one active request.
+// EXPECT_GT(0U, service.GetPendingRequests().size());
+// ...
+// // Make any pending token fetches for a given scope succeed.
+// ScopeSet scopes;
+// scopes.insert(GaiaConstants::kYourServiceScope);
+// IssueTokenForScope(scopes, "access_token", base::Time()::Max());
+// ...
+// // ...or make them fail...
+// IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS));
+//
+class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService {
+ public:
+ class PendingRequest {
+ public:
+ PendingRequest();
+ ~PendingRequest();
+ std::string client_id;
+ std::string client_secret;
+ ScopeSet scopes;
+ base::WeakPtr<RequestImpl> request;
+ };
+
+ FakeProfileOAuth2TokenService();
+ virtual ~FakeProfileOAuth2TokenService();
+
+ // Sets the current refresh token (for signed in profiles). If |token| is
+ // non-empty, this will fire OnRefreshTokenAvailable() on any Observers.
+ // 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.
+ // missing refresh token by passing in an empty string).
+ void IssueRefreshToken(const std::string& token);
+
+ // Gets a list of active requests (can be used by tests to validate that the
+ // correct request has been issued).
+ std::vector<PendingRequest> GetPendingRequests();
+
+ // Helper routines to issue tokens for pending requests (also removes the
+ // 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
+ 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.
+ const std::string& access_token,
+ const base::Time& expiration);
+ void IssueErrorForScope(const ScopeSet& scope,
+ const GoogleServiceAuthError& error);
+
+ virtual void Shutdown() OVERRIDE;
+
+ // Helper function to be used with
+ // BrowserContextKeyedService::SetTestingFactory().
+ static BrowserContextKeyedService* Build(content::BrowserContext* profile);
+
+ protected:
+ // OAuth2TokenService overrides.
+ virtual void FetchOAuth2Token(RequestImpl* request,
+ net::URLRequestContextGetter* getter,
+ const std::string& client_id,
+ const std::string& client_secret,
+ const ScopeSet& scopes) OVERRIDE;
+
+ virtual std::string GetRefreshToken() OVERRIDE;
+
+ virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
+
+ private:
+ void CompleteRequests(const ScopeSet& scopes,
+ const GoogleServiceAuthError& error,
+ const std::string& access_token,
+ const base::Time& expiration);
+
+ std::vector<PendingRequest> pending_requests_;
+ std::string refresh_token_;
+};
+
+#endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698