| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gaia/fake_gaia.h" | 5 #include "google_apis/gaia/fake_gaia.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 const base::FilePath::CharType kServiceLogin[] = | 44 const base::FilePath::CharType kServiceLogin[] = |
| 45 FILE_PATH_LITERAL("google_apis/test/service_login.html"); | 45 FILE_PATH_LITERAL("google_apis/test/service_login.html"); |
| 46 | 46 |
| 47 // OAuth2 Authentication header value prefix. | 47 // OAuth2 Authentication header value prefix. |
| 48 const char kAuthHeaderBearer[] = "Bearer "; | 48 const char kAuthHeaderBearer[] = "Bearer "; |
| 49 const char kAuthHeaderOAuth[] = "OAuth "; | 49 const char kAuthHeaderOAuth[] = "OAuth "; |
| 50 | 50 |
| 51 const char kListAccountsResponseFormat[] = | 51 const char kListAccountsResponseFormat[] = |
| 52 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; | 52 "[\"gaia.l.a.r\",[[\"gaia.l.a\",1,\"\",\"%s\",\"\",1,1,0]]]"; |
| 53 const char kPeopleGetResponseFormat[] = "{\"id\":\"%s\"}"; | |
| 54 | 53 |
| 55 typedef std::map<std::string, std::string> CookieMap; | 54 typedef std::map<std::string, std::string> CookieMap; |
| 56 | 55 |
| 57 // Parses cookie name-value map our of |request|. | 56 // Parses cookie name-value map our of |request|. |
| 58 CookieMap GetRequestCookies(const HttpRequest& request) { | 57 CookieMap GetRequestCookies(const HttpRequest& request) { |
| 59 CookieMap result; | 58 CookieMap result; |
| 60 std::map<std::string, std::string>::const_iterator iter = | 59 std::map<std::string, std::string>::const_iterator iter = |
| 61 request.headers.find("Cookie"); | 60 request.headers.find("Cookie"); |
| 62 if (iter != request.headers.end()) { | 61 if (iter != request.headers.end()) { |
| 63 std::vector<std::string> cookie_nv_pairs; | 62 std::vector<std::string> cookie_nv_pairs; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 REGISTER_RESPONSE_HANDLER( | 169 REGISTER_RESPONSE_HANDLER( |
| 171 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); | 170 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); |
| 172 | 171 |
| 173 // Handles /oauth2/v2/IssueToken GAIA call. | 172 // Handles /oauth2/v2/IssueToken GAIA call. |
| 174 REGISTER_RESPONSE_HANDLER( | 173 REGISTER_RESPONSE_HANDLER( |
| 175 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); | 174 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); |
| 176 | 175 |
| 177 // Handles /ListAccounts GAIA call. | 176 // Handles /ListAccounts GAIA call. |
| 178 REGISTER_RESPONSE_HANDLER( | 177 REGISTER_RESPONSE_HANDLER( |
| 179 gaia_urls->list_accounts_url(), HandleListAccounts); | 178 gaia_urls->list_accounts_url(), HandleListAccounts); |
| 180 | |
| 181 // Handles /plus/v1/people/me | |
| 182 REGISTER_RESPONSE_HANDLER( | |
| 183 gaia_urls->people_get_url(), HandlePeopleGet); | |
| 184 } | 179 } |
| 185 | 180 |
| 186 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { | 181 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { |
| 187 // The scheme and host of the URL is actually not important but required to | 182 // The scheme and host of the URL is actually not important but required to |
| 188 // get a valid GURL in order to parse |request.relative_url|. | 183 // get a valid GURL in order to parse |request.relative_url|. |
| 189 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); | 184 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 190 std::string request_path = request_url.path(); | 185 std::string request_path = request_url.path(); |
| 191 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 186 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 192 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); | 187 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); |
| 193 if (iter != request_handlers_.end()) { | 188 if (iter != request_handlers_.end()) { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 http_response->set_code(net::HTTP_BAD_REQUEST); | 522 http_response->set_code(net::HTTP_BAD_REQUEST); |
| 528 } | 523 } |
| 529 } | 524 } |
| 530 | 525 |
| 531 void FakeGaia::HandleListAccounts(const HttpRequest& request, | 526 void FakeGaia::HandleListAccounts(const HttpRequest& request, |
| 532 BasicHttpResponse* http_response) { | 527 BasicHttpResponse* http_response) { |
| 533 http_response->set_content(base::StringPrintf( | 528 http_response->set_content(base::StringPrintf( |
| 534 kListAccountsResponseFormat, merge_session_params_.email.c_str())); | 529 kListAccountsResponseFormat, merge_session_params_.email.c_str())); |
| 535 http_response->set_code(net::HTTP_OK); | 530 http_response->set_code(net::HTTP_OK); |
| 536 } | 531 } |
| 537 | |
| 538 | |
| 539 void FakeGaia::HandlePeopleGet(const HttpRequest& request, | |
| 540 BasicHttpResponse* http_response) { | |
| 541 http_response->set_content(base::StringPrintf( | |
| 542 kPeopleGetResponseFormat, "name")); | |
| 543 http_response->set_code(net::HTTP_OK); | |
| 544 } | |
| OLD | NEW |