Chromium Code Reviews| 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\"}"; | |
| 53 | 54 |
| 54 typedef std::map<std::string, std::string> CookieMap; | 55 typedef std::map<std::string, std::string> CookieMap; |
| 55 | 56 |
| 56 // Parses cookie name-value map our of |request|. | 57 // Parses cookie name-value map our of |request|. |
| 57 CookieMap GetRequestCookies(const HttpRequest& request) { | 58 CookieMap GetRequestCookies(const HttpRequest& request) { |
| 58 CookieMap result; | 59 CookieMap result; |
| 59 std::map<std::string, std::string>::const_iterator iter = | 60 std::map<std::string, std::string>::const_iterator iter = |
| 60 request.headers.find("Cookie"); | 61 request.headers.find("Cookie"); |
| 61 if (iter != request.headers.end()) { | 62 if (iter != request.headers.end()) { |
| 62 std::vector<std::string> cookie_nv_pairs; | 63 std::vector<std::string> cookie_nv_pairs; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 REGISTER_RESPONSE_HANDLER( | 170 REGISTER_RESPONSE_HANDLER( |
| 170 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); | 171 gaia_urls->oauth2_token_info_url(), HandleTokenInfo); |
| 171 | 172 |
| 172 // Handles /oauth2/v2/IssueToken GAIA call. | 173 // Handles /oauth2/v2/IssueToken GAIA call. |
| 173 REGISTER_RESPONSE_HANDLER( | 174 REGISTER_RESPONSE_HANDLER( |
| 174 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); | 175 gaia_urls->oauth2_issue_token_url(), HandleIssueToken); |
| 175 | 176 |
| 176 // Handles /ListAccounts GAIA call. | 177 // Handles /ListAccounts GAIA call. |
| 177 REGISTER_RESPONSE_HANDLER( | 178 REGISTER_RESPONSE_HANDLER( |
| 178 gaia_urls->list_accounts_url(), HandleListAccounts); | 179 gaia_urls->list_accounts_url(), HandleListAccounts); |
| 180 | |
| 181 // Handles /plus/v1/people/me | |
| 182 REGISTER_RESPONSE_HANDLER( | |
| 183 gaia_urls->people_get_url(), HandlePeopleGet); | |
| 179 } | 184 } |
| 180 | 185 |
| 181 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { | 186 scoped_ptr<HttpResponse> FakeGaia::HandleRequest(const HttpRequest& request) { |
| 182 // The scheme and host of the URL is actually not important but required to | 187 // The scheme and host of the URL is actually not important but required to |
| 183 // get a valid GURL in order to parse |request.relative_url|. | 188 // get a valid GURL in order to parse |request.relative_url|. |
| 184 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); | 189 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); |
| 185 std::string request_path = request_url.path(); | 190 std::string request_path = request_url.path(); |
| 186 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); | 191 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); |
| 187 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); | 192 RequestHandlerMap::iterator iter = request_handlers_.find(request_path); |
| 188 if (iter != request_handlers_.end()) { | 193 if (iter != request_handlers_.end()) { |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 http_response->set_code(net::HTTP_BAD_REQUEST); | 527 http_response->set_code(net::HTTP_BAD_REQUEST); |
| 523 } | 528 } |
| 524 } | 529 } |
| 525 | 530 |
| 526 void FakeGaia::HandleListAccounts(const HttpRequest& request, | 531 void FakeGaia::HandleListAccounts(const HttpRequest& request, |
| 527 BasicHttpResponse* http_response) { | 532 BasicHttpResponse* http_response) { |
| 528 http_response->set_content(base::StringPrintf( | 533 http_response->set_content(base::StringPrintf( |
| 529 kListAccountsResponseFormat, merge_session_params_.email.c_str())); | 534 kListAccountsResponseFormat, merge_session_params_.email.c_str())); |
| 530 http_response->set_code(net::HTTP_OK); | 535 http_response->set_code(net::HTTP_OK); |
| 531 } | 536 } |
| 537 | |
| 538 | |
| 539 void FakeGaia::HandlePeopleGet(const HttpRequest& request, | |
| 540 BasicHttpResponse* http_response) { | |
| 541 http_response->set_content(base::StringPrintf( | |
| 542 kPeopleGetResponseFormat, "name")); | |
|
Roger Tawa OOO till Jul 10th
2014/05/27 19:15:38
Is it worth using StringPrintf if we are hardcodin
Mike Lerman
2014/05/27 19:43:03
Done.
| |
| 543 http_response->set_code(net::HTTP_OK); | |
| 544 } | |
| OLD | NEW |