Index: net/url_request/url_request_test_util.cc |
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc |
index cf797e3ba03b447a6c91cd7da3a5f8b0b0e4b716..11eda377171c2109a055f5af9b35885c37875cad 100644 |
--- a/net/url_request/url_request_test_util.cc |
+++ b/net/url_request/url_request_test_util.cc |
@@ -12,6 +12,7 @@ |
#include "net/base/cert_verifier.h" |
#include "net/base/default_server_bound_cert_store.h" |
#include "net/base/host_port_pair.h" |
+#include "net/base/mock_host_resolver.h" |
#include "net/base/server_bound_cert_service.h" |
#include "net/http/http_network_session.h" |
#include "net/http/http_server_properties_impl.h" |
@@ -41,70 +42,16 @@ const int kStageDestruction = 1 << 10; |
TestURLRequestContext::TestURLRequestContext() |
: initialized_(false), |
ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { |
- context_storage_.set_host_resolver( |
- net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
- net::HostResolver::kDefaultRetryAttempts, |
- NULL)); |
- SetProxyDirect(); |
Init(); |
} |
TestURLRequestContext::TestURLRequestContext(bool delay_initialization) |
: initialized_(false), |
ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { |
- context_storage_.set_host_resolver( |
- net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
- net::HostResolver::kDefaultRetryAttempts, |
- NULL)); |
- SetProxyDirect(); |
if (!delay_initialization) |
Init(); |
} |
-TestURLRequestContext::TestURLRequestContext(const std::string& proxy) |
- : initialized_(false), |
- ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { |
- context_storage_.set_host_resolver( |
- net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
- net::HostResolver::kDefaultRetryAttempts, |
- NULL)); |
- SetProxyFromString(proxy); |
- Init(); |
-} |
- |
-TestURLRequestContext::TestURLRequestContext(const char* proxy) |
- : initialized_(false), |
- ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { |
- context_storage_.set_host_resolver( |
- net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
- net::HostResolver::kDefaultRetryAttempts, |
- NULL)); |
- SetProxyFromString(proxy); |
- Init(); |
-} |
- |
-TestURLRequestContext::TestURLRequestContext(const std::string& proxy, |
- net::HostResolver* host_resolver) |
- : initialized_(false), |
- ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { |
- context_storage_.set_host_resolver(host_resolver); |
- SetProxyFromString(proxy); |
- Init(); |
-} |
- |
-void TestURLRequestContext::SetProxyFromString(const std::string& proxy) { |
- DCHECK(!initialized_); |
- net::ProxyConfig proxy_config; |
- proxy_config.proxy_rules().ParseFromString(proxy); |
- context_storage_.set_proxy_service( |
- net::ProxyService::CreateFixed(proxy_config)); |
-} |
- |
-void TestURLRequestContext::SetProxyDirect() { |
- DCHECK(!initialized_); |
- context_storage_.set_proxy_service(net::ProxyService::CreateDirect()); |
-} |
- |
TestURLRequestContext::~TestURLRequestContext() { |
DCHECK(initialized_); |
} |
@@ -112,6 +59,11 @@ TestURLRequestContext::~TestURLRequestContext() { |
void TestURLRequestContext::Init() { |
DCHECK(!initialized_); |
initialized_ = true; |
+ |
+ if (!host_resolver()) |
+ context_storage_.set_host_resolver(new net::MockCachingHostResolver()); |
+ if (!proxy_service()) |
+ context_storage_.set_proxy_service(net::ProxyService::CreateDirect()); |
if (!cert_verifier()) |
context_storage_.set_cert_verifier(net::CertVerifier::CreateDefault()); |
if (!ftp_transaction_factory()) { |
@@ -160,7 +112,6 @@ void TestURLRequestContext::Init() { |
context_storage_.set_job_factory(new net::URLRequestJobFactory); |
} |
- |
TestURLRequest::TestURLRequest(const GURL& url, Delegate* delegate) |
: net::URLRequest(url, delegate), |
context_(new TestURLRequestContext) { |
@@ -177,6 +128,13 @@ TestURLRequestContextGetter::TestURLRequestContextGetter( |
DCHECK(io_message_loop_proxy.get()); |
} |
+TestURLRequestContextGetter::TestURLRequestContextGetter( |
+ const scoped_refptr<base::MessageLoopProxy>& io_message_loop_proxy, |
+ scoped_ptr<TestURLRequestContext> context) |
+ : io_message_loop_proxy_(io_message_loop_proxy), context_(context.Pass()) { |
+ DCHECK(io_message_loop_proxy.get()); |
+} |
+ |
TestURLRequestContextGetter::~TestURLRequestContextGetter() {} |
TestURLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() { |