Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Unified Diff: net/url_request/url_request_test_util.cc

Issue 10408067: [net] Switch TestURLRequestContext to use MockCachingHostResolver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to trunk. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/url_request/url_request_test_util.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() {
« no previous file with comments | « net/url_request/url_request_test_util.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698