diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 11:21:12 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 11:21:12 +0000 |
commit | 3014321f5622f30e8e7f88fdb55bcc0e612b4f65 (patch) | |
tree | e5e5c03075f8dcd6a8a5ae421b51514e6b8aaa46 /google_apis/gaia/fake_gaia.h | |
parent | c6f86d379547ea28ca4c3de64dd0c6cb0cfb2e87 (diff) | |
download | chromium_src-3014321f5622f30e8e7f88fdb55bcc0e612b4f65.zip chromium_src-3014321f5622f30e8e7f88fdb55bcc0e612b4f65.tar.gz chromium_src-3014321f5622f30e8e7f88fdb55bcc0e612b4f65.tar.bz2 |
Add a fake GAIA implementation for use with the test server.
This is for the benefit of integration tests that need the browser to
interface with GAIA and friends, such as for OAuth2 token minting.
BUG=chromium:243889
R=joi@chromium.org, xiyuan@chromium.org, zelidrag@chromium.org
Review URL: https://codereview.chromium.org/24172005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224108 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gaia/fake_gaia.h')
-rw-r--r-- | google_apis/gaia/fake_gaia.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/google_apis/gaia/fake_gaia.h b/google_apis/gaia/fake_gaia.h new file mode 100644 index 0000000..24f6891 --- /dev/null +++ b/google_apis/gaia/fake_gaia.h @@ -0,0 +1,86 @@ +// Copyright (c) 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 GOOGLE_APIS_GAIA_FAKE_GAIA_H_ +#define GOOGLE_APIS_GAIA_FAKE_GAIA_H_ + +#include <map> +#include <set> +#include <string> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" + +namespace base { +class DictionaryValue; +} + +namespace net { +namespace test_server { +class BasicHttpResponse; +struct HttpRequest; +class HttpResponse; +} +} + +// This is a test helper that implements a fake GAIA service for use in browser +// tests. It's mainly intended for use with EmbeddedTestServer, for which it can +// be registered as an additional request handler. +class FakeGaia { + public: + typedef std::set<std::string> ScopeSet; + + // Access token details used for token minting and the token info endpoint. + struct AccessTokenInfo { + AccessTokenInfo(); + ~AccessTokenInfo(); + + std::string token; + std::string issued_to; + std::string audience; + std::string user_id; + ScopeSet scopes; + int expires_in; + std::string email; + }; + + FakeGaia(); + ~FakeGaia(); + + // Handles a request and returns a response if the request was recognized as a + // GAIA request. Note that this respects the switches::kGaiaUrl and friends so + // that this can used with EmbeddedTestServer::RegisterRequestHandler(). + scoped_ptr<net::test_server::HttpResponse> HandleRequest( + const net::test_server::HttpRequest& request); + + // Configures an OAuth2 token that'll be returned when a client requests an + // access token for the given refresh token. + void IssueOAuthToken(const std::string& refresh_token, + const AccessTokenInfo& token_info); + + private: + typedef std::map<std::string, AccessTokenInfo> AccessTokenInfoMap; + + // Formats a JSON response with the data in |response_dict|. + void FormatJSONResponse(const base::DictionaryValue& response_dict, + net::test_server::BasicHttpResponse* http_response); + + // Returns the access token associated with |refresh_token| or NULL if not + // found. + const AccessTokenInfo* GetAccessTokenInfo( + const std::string& refresh_token) const; + + // Extracts the parameter named |key| from |query| and places it in |value|. + // Returns false if no parameter is found. + static bool GetQueryParameter(const std::string& query, + const std::string& key, + std::string* value); + + AccessTokenInfoMap access_token_info_map_; + std::string service_login_response_; + + DISALLOW_COPY_AND_ASSIGN(FakeGaia); +}; + +#endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_ |