OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/url_request/url_request_test_util.h" | 5 #include "net/url_request/url_request_test_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "net/http/http_network_session.h" | 10 #include "net/http/http_network_session.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 TestURLRequestContext::TestURLRequestContext(const std::string& proxy) { | 89 TestURLRequestContext::TestURLRequestContext(const std::string& proxy) { |
90 set_host_resolver( | 90 set_host_resolver( |
91 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, | 91 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
92 NULL, NULL)); | 92 NULL, NULL)); |
93 net::ProxyConfig proxy_config; | 93 net::ProxyConfig proxy_config; |
94 proxy_config.proxy_rules().ParseFromString(proxy); | 94 proxy_config.proxy_rules().ParseFromString(proxy); |
95 set_proxy_service(net::ProxyService::CreateFixed(proxy_config)); | 95 set_proxy_service(net::ProxyService::CreateFixed(proxy_config)); |
96 Init(); | 96 Init(); |
97 } | 97 } |
98 | 98 |
| 99 TestURLRequestContext::TestURLRequestContext(const std::string& proxy, |
| 100 net::HostResolver* host_resolver) { |
| 101 set_host_resolver(host_resolver); |
| 102 net::ProxyConfig proxy_config; |
| 103 proxy_config.proxy_rules().ParseFromString(proxy); |
| 104 set_proxy_service(net::ProxyService::CreateFixed(proxy_config)); |
| 105 Init(); |
| 106 } |
| 107 |
99 TestURLRequestContext::~TestURLRequestContext() { | 108 TestURLRequestContext::~TestURLRequestContext() { |
100 delete ftp_transaction_factory(); | 109 delete ftp_transaction_factory(); |
101 delete http_transaction_factory(); | 110 delete http_transaction_factory(); |
102 delete http_auth_handler_factory(); | 111 delete http_auth_handler_factory(); |
103 delete cert_verifier(); | 112 delete cert_verifier(); |
104 delete host_resolver(); | 113 delete host_resolver(); |
105 } | 114 } |
106 | 115 |
107 void TestURLRequestContext::Init() { | 116 void TestURLRequestContext::Init() { |
108 set_cert_verifier(new net::CertVerifier); | 117 set_cert_verifier(new net::CertVerifier); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 if (!request->status().is_io_pending()) | 280 if (!request->status().is_io_pending()) |
272 OnResponseCompleted(request); | 281 OnResponseCompleted(request); |
273 else if (cancel_in_rd_pending_) | 282 else if (cancel_in_rd_pending_) |
274 request->Cancel(); | 283 request->Cancel(); |
275 } | 284 } |
276 | 285 |
277 void TestDelegate::OnResponseCompleted(net::URLRequest* request) { | 286 void TestDelegate::OnResponseCompleted(net::URLRequest* request) { |
278 if (quit_on_complete_) | 287 if (quit_on_complete_) |
279 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 288 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
280 } | 289 } |
| 290 |
| 291 TestHttpNetworkDelegate::TestHttpNetworkDelegate() |
| 292 : last_os_error_(0), |
| 293 error_count_(0) { |
| 294 } |
| 295 |
| 296 TestHttpNetworkDelegate::~TestHttpNetworkDelegate() {} |
| 297 |
| 298 void TestHttpNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request) { |
| 299 } |
| 300 |
| 301 void TestHttpNetworkDelegate::OnSendHttpRequest( |
| 302 net::HttpRequestHeaders* headers) { |
| 303 } |
| 304 |
| 305 void TestHttpNetworkDelegate::OnResponseStarted(net::URLRequest* request) { |
| 306 if (request->status().status() == net::URLRequestStatus::FAILED) { |
| 307 error_count_++; |
| 308 last_os_error_ = request->status().os_error(); |
| 309 } |
| 310 } |
| 311 void TestHttpNetworkDelegate::OnReadCompleted(net::URLRequest* request, |
| 312 int bytes_read) { |
| 313 if (request->status().status() == net::URLRequestStatus::FAILED) { |
| 314 error_count_++; |
| 315 last_os_error_ = request->status().os_error(); |
| 316 } |
| 317 } |
OLD | NEW |