1 // Copyright (c) 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.
5 #ifndef GOOGLE_APIS_GAIA_FAKE_GAIA_H_
6 #define GOOGLE_APIS_GAIA_FAKE_GAIA_H_
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
16 class DictionaryValue;
20 namespace test_server {
21 class BasicHttpResponse;
27 // This is a test helper that implements a fake GAIA service for use in browser
28 // tests. It's mainly intended for use with EmbeddedTestServer, for which it can
29 // be registered as an additional request handler.
32 typedef std::set<std::string> ScopeSet;
34 // Access token details used for token minting and the token info endpoint.
35 struct AccessTokenInfo {
40 std::string issued_to;
51 // Handles a request and returns a response if the request was recognized as a
52 // GAIA request. Note that this respects the switches::kGaiaUrl and friends so
53 // that this can used with EmbeddedTestServer::RegisterRequestHandler().
54 scoped_ptr<net::test_server::HttpResponse> HandleRequest(
55 const net::test_server::HttpRequest& request);
57 // Configures an OAuth2 token that'll be returned when a client requests an
58 // access token for the given refresh token.
59 void IssueOAuthToken(const std::string& refresh_token,
60 const AccessTokenInfo& token_info);
63 typedef std::map<std::string, AccessTokenInfo> AccessTokenInfoMap;
65 // Formats a JSON response with the data in |response_dict|.
66 void FormatJSONResponse(const base::DictionaryValue& response_dict,
67 net::test_server::BasicHttpResponse* http_response);
69 // Returns the access token associated with |refresh_token| or NULL if not
71 const AccessTokenInfo* GetAccessTokenInfo(
72 const std::string& refresh_token) const;
74 // Extracts the parameter named |key| from |query| and places it in |value|.
75 // Returns false if no parameter is found.
76 static bool GetQueryParameter(const std::string& query,
77 const std::string& key,
80 AccessTokenInfoMap access_token_info_map_;
81 std::string service_login_response_;
83 DISALLOW_COPY_AND_ASSIGN(FakeGaia);
86 #endif // GOOGLE_APIS_GAIA_FAKE_GAIA_H_