| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A complete set of unit tests for GaiaAuthFetcher. | 5 // A complete set of unit tests for GaiaAuthFetcher. |
| 6 // Originally ported from GoogleAuthenticator tests. | 6 // Originally ported from GoogleAuthenticator tests. |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 " \"token_type\": \"Bearer\"" | 46 " \"token_type\": \"Bearer\"" |
| 47 "}"; | 47 "}"; |
| 48 | 48 |
| 49 MockFetcher::MockFetcher(bool success, | 49 MockFetcher::MockFetcher(bool success, |
| 50 const GURL& url, | 50 const GURL& url, |
| 51 const std::string& results, | 51 const std::string& results, |
| 52 net::URLFetcher::RequestType request_type, | 52 net::URLFetcher::RequestType request_type, |
| 53 net::URLFetcherDelegate* d) | 53 net::URLFetcherDelegate* d) |
| 54 : TestURLFetcher(0, url, d) { | 54 : TestURLFetcher(0, url, d) { |
| 55 set_url(url); | 55 set_url(url); |
| 56 net::URLRequestStatus::Status code; | 56 net::Error error; |
| 57 | 57 |
| 58 if (success) { | 58 if (success) { |
| 59 error = net::OK; |
| 59 set_response_code(net::HTTP_OK); | 60 set_response_code(net::HTTP_OK); |
| 60 code = net::URLRequestStatus::SUCCESS; | |
| 61 } else { | 61 } else { |
| 62 set_response_code(net::HTTP_FORBIDDEN); | 62 error = net::ERR_FAILED; |
| 63 code = net::URLRequestStatus::FAILED; | |
| 64 } | 63 } |
| 65 | 64 |
| 66 set_status(net::URLRequestStatus(code, 0)); | 65 set_status(net::URLRequestStatus::FromError(error)); |
| 67 SetResponseString(results); | 66 SetResponseString(results); |
| 68 } | 67 } |
| 69 | 68 |
| 70 MockFetcher::MockFetcher(const GURL& url, | 69 MockFetcher::MockFetcher(const GURL& url, |
| 71 const net::URLRequestStatus& status, | 70 const net::URLRequestStatus& status, |
| 72 int response_code, | 71 int response_code, |
| 73 const net::ResponseCookies& cookies, | 72 const net::ResponseCookies& cookies, |
| 74 const std::string& results, | 73 const std::string& results, |
| 75 net::URLFetcher::RequestType request_type, | 74 net::URLFetcher::RequestType request_type, |
| 76 net::URLFetcherDelegate* d) | 75 net::URLFetcherDelegate* d) |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); | 878 GaiaAuthFetcher auth(&consumer, std::string(), GetRequestContext()); |
| 880 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); | 879 auth.StartGetTokenResponse(std::string(), std::string(), std::string()); |
| 881 | 880 |
| 882 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); | 881 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); |
| 883 MockFetcher mock_fetcher( | 882 MockFetcher mock_fetcher( |
| 884 GaiaUrls::GetInstance()->oauth2_iframe_url(), | 883 GaiaUrls::GetInstance()->oauth2_iframe_url(), |
| 885 status, net::HTTP_OK, cookies_, kGetTokenPairValidResponse, | 884 status, net::HTTP_OK, cookies_, kGetTokenPairValidResponse, |
| 886 net::URLFetcher::GET, &auth); | 885 net::URLFetcher::GET, &auth); |
| 887 auth.OnURLFetchComplete(&mock_fetcher); | 886 auth.OnURLFetchComplete(&mock_fetcher); |
| 888 } | 887 } |
| OLD | NEW |