Chromium Code Reviews| 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 #include "net/test/url_request/url_request_failed_job.h" | 5 #include "net/test/url_request/url_request_failed_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/base/url_util.h" | 15 #include "net/base/url_util.h" |
| 16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
| 17 #include "net/ssl/ssl_cert_request_info.h" | |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 #include "net/url_request/url_request_filter.h" | 19 #include "net/url_request/url_request_filter.h" |
| 19 #include "net/url_request/url_request_interceptor.h" | 20 #include "net/url_request/url_request_interceptor.h" |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char kMockHostname[] = "mock.failed.request"; | 26 const char kMockHostname[] = "mock.failed.request"; |
| 26 | 27 |
| 27 // String names of failure phases matching FailurePhase enum. | 28 // String names of failure phases matching FailurePhase enum. |
| 28 const char* kFailurePhase[]{ | 29 const char* kFailurePhase[]{ |
| 29 "start", // START | 30 "start", // START |
| 30 "readsync", // READ_SYNC | 31 "readsync", // READ_SYNC |
| 31 "readasync", // READ_ASYNC | 32 "readasync", // READ_ASYNC |
| 33 "certreq", // CERT_REQUESTED | |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 static_assert(arraysize(kFailurePhase) == | 36 static_assert(arraysize(kFailurePhase) == |
| 35 URLRequestFailedJob::FailurePhase::MAX_FAILURE_PHASE, | 37 URLRequestFailedJob::FailurePhase::MAX_FAILURE_PHASE, |
| 36 "kFailurePhase must match FailurePhase enum"); | 38 "kFailurePhase must match FailurePhase enum"); |
| 37 | 39 |
| 38 class MockJobInterceptor : public URLRequestInterceptor { | 40 class MockJobInterceptor : public URLRequestInterceptor { |
| 39 public: | 41 public: |
| 40 MockJobInterceptor() {} | 42 MockJobInterceptor() {} |
| 41 ~MockJobInterceptor() override {} | 43 ~MockJobInterceptor() override {} |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 62 | 64 |
| 63 private: | 65 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); | 66 DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor); |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 GURL GetMockUrl(const std::string& scheme, | 69 GURL GetMockUrl(const std::string& scheme, |
| 68 const std::string& hostname, | 70 const std::string& hostname, |
| 69 URLRequestFailedJob::FailurePhase phase, | 71 URLRequestFailedJob::FailurePhase phase, |
| 70 int net_error) { | 72 int net_error) { |
| 71 CHECK_GE(phase, URLRequestFailedJob::FailurePhase::START); | 73 CHECK_GE(phase, URLRequestFailedJob::FailurePhase::START); |
| 72 CHECK_LE(phase, URLRequestFailedJob::FailurePhase::READ_ASYNC); | 74 CHECK_LE(phase, URLRequestFailedJob::FailurePhase::CERT_REQUESTED); |
|
svaldez
2015/11/20 16:30:10
Shouldn't this just be CHECK_LT(..., MAX_FAILURE_P
mef
2015/11/20 16:44:06
Done.
| |
| 73 CHECK_LT(net_error, OK); | 75 CHECK_LT(net_error, OK); |
| 74 return GURL(scheme + "://" + hostname + "/error?" + kFailurePhase[phase] + | 76 return GURL(scheme + "://" + hostname + "/error?" + kFailurePhase[phase] + |
| 75 "=" + base::IntToString(net_error)); | 77 "=" + base::IntToString(net_error)); |
| 76 } | 78 } |
| 77 | 79 |
| 78 } // namespace | 80 } // namespace |
| 79 | 81 |
| 80 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, | 82 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, |
| 81 NetworkDelegate* network_delegate, | 83 NetworkDelegate* network_delegate, |
| 82 FailurePhase phase, | 84 FailurePhase phase, |
| 83 int net_error) | 85 int net_error) |
| 84 : URLRequestJob(request, network_delegate), | 86 : URLRequestJob(request, network_delegate), |
| 85 phase_(phase), | 87 phase_(phase), |
| 86 net_error_(net_error), | 88 net_error_(net_error), |
| 87 weak_factory_(this) { | 89 weak_factory_(this) { |
| 88 CHECK_GE(phase, URLRequestFailedJob::FailurePhase::START); | 90 CHECK_GE(phase, URLRequestFailedJob::FailurePhase::START); |
| 89 CHECK_LE(phase, URLRequestFailedJob::FailurePhase::READ_ASYNC); | 91 CHECK_LE(phase, URLRequestFailedJob::FailurePhase::CERT_REQUESTED); |
|
svaldez
2015/11/20 16:30:10
see above.
mef
2015/11/20 16:44:06
Done.
| |
| 90 CHECK_LT(net_error, OK); | 92 CHECK_LT(net_error, OK); |
| 91 } | 93 } |
| 92 | 94 |
| 93 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, | 95 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, |
| 94 NetworkDelegate* network_delegate, | 96 NetworkDelegate* network_delegate, |
| 95 int net_error) | 97 int net_error) |
| 96 : URLRequestFailedJob(request, network_delegate, START, net_error) { | 98 : URLRequestFailedJob(request, network_delegate, START, net_error) { |
| 97 } | 99 } |
| 98 | 100 |
| 99 void URLRequestFailedJob::Start() { | 101 void URLRequestFailedJob::Start() { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 113 return ERR_IO_PENDING; | 115 return ERR_IO_PENDING; |
| 114 } | 116 } |
| 115 | 117 |
| 116 int URLRequestFailedJob::GetResponseCode() const { | 118 int URLRequestFailedJob::GetResponseCode() const { |
| 117 // If we have headers, get the response code from them. | 119 // If we have headers, get the response code from them. |
| 118 if (response_info_.headers) | 120 if (response_info_.headers) |
| 119 return response_info_.headers->response_code(); | 121 return response_info_.headers->response_code(); |
| 120 return URLRequestJob::GetResponseCode(); | 122 return URLRequestJob::GetResponseCode(); |
| 121 } | 123 } |
| 122 | 124 |
| 125 void URLRequestFailedJob::ContinueWithCertificate( | |
| 126 X509Certificate* client_cert, | |
| 127 SSLPrivateKey* client_private_key) { | |
| 128 NotifyStartError(URLRequestStatus::FromError(net_error_)); | |
| 129 } | |
| 130 | |
| 123 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) { | 131 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) { |
| 124 *info = response_info_; | 132 *info = response_info_; |
| 125 } | 133 } |
| 126 | 134 |
| 127 // static | 135 // static |
| 128 void URLRequestFailedJob::AddUrlHandler() { | 136 void URLRequestFailedJob::AddUrlHandler() { |
| 129 return AddUrlHandlerForHostname(kMockHostname); | 137 return AddUrlHandlerForHostname(kMockHostname); |
| 130 } | 138 } |
| 131 | 139 |
| 132 // static | 140 // static |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 | 185 |
| 178 void URLRequestFailedJob::StartAsync() { | 186 void URLRequestFailedJob::StartAsync() { |
| 179 if (phase_ == START) { | 187 if (phase_ == START) { |
| 180 if (net_error_ != ERR_IO_PENDING) { | 188 if (net_error_ != ERR_IO_PENDING) { |
| 181 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); | 189 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); |
| 182 return; | 190 return; |
| 183 } | 191 } |
| 184 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 192 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 185 return; | 193 return; |
| 186 } | 194 } |
| 195 if (phase_ == CERT_REQUESTED) { | |
| 196 scoped_refptr<SSLCertRequestInfo> request_all(new SSLCertRequestInfo()); | |
| 197 NotifyCertificateRequested(request_all.get()); | |
| 198 return; | |
| 199 } | |
| 187 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); | 200 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); |
| 188 NotifyHeadersComplete(); | 201 NotifyHeadersComplete(); |
| 189 } | 202 } |
| 190 | 203 |
| 191 } // namespace net | 204 } // namespace net |
| OLD | NEW |