summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-18 23:46:05 +0000
committermmenke@chromium.org <mmenke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-18 23:46:05 +0000
commit832e3e55268189085e872a54f9437b22f5c26cd7 (patch)
tree230b4f77a3db6690596ea6670c6a2b2421fc5ce5
parent4095d9edce7ae7727a404ef4ad40101c0660f49a (diff)
downloadchromium_src-832e3e55268189085e872a54f9437b22f5c26cd7.zip
chromium_src-832e3e55268189085e872a54f9437b22f5c26cd7.tar.gz
chromium_src-832e3e55268189085e872a54f9437b22f5c26cd7.tar.bz2
net: Make URLRequestJobFactories mandatory.
The URLRequestJobManager will now crash if there is not one. This is part of the work aimed at eliminating the JobManager. BUG=142945 Review URL: https://codereview.chromium.org/332833003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278192 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc8
-rw-r--r--components/data_reduction_proxy.gypi1
-rw-r--r--components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc61
-rw-r--r--net/url_request/url_request.cc3
-rw-r--r--net/url_request/url_request_job_manager.cc31
5 files changed, 32 insertions, 72 deletions
diff --git a/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc b/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc
index f0de8dc..69a46e7 100644
--- a/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc
+++ b/chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc
@@ -12,7 +12,6 @@
#include "base/message_loop/message_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/thread.h"
-#include "chrome/browser/net/chrome_url_request_context.h"
#include "content/public/test/test_browser_thread.h"
#include "net/base/request_priority.h"
#include "net/base/test_data_directory.h"
@@ -22,6 +21,7 @@
#include "net/test/cert_test_util.h"
#include "net/url_request/fraudulent_certificate_reporter.h"
#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
@@ -156,21 +156,21 @@ class MockReporter : public ChromeFraudulentCertificateReporter {
};
static void DoReportIsSent() {
- ChromeURLRequestContext context;
+ net::TestURLRequestContext context;
SendingTestReporter reporter(&context);
SSLInfo info = GetGoodSSLInfo();
reporter.SendReport("mail.google.com", info, true);
}
static void DoReportIsNotSent() {
- ChromeURLRequestContext context;
+ net::TestURLRequestContext context;
NotSendingTestReporter reporter(&context);
SSLInfo info = GetBadSSLInfo();
reporter.SendReport("www.example.com", info, true);
}
static void DoMockReportIsSent() {
- ChromeURLRequestContext context;
+ net::TestURLRequestContext context;
MockReporter reporter(&context);
SSLInfo info = GetGoodSSLInfo();
reporter.SendReport("mail.google.com", info, true);
diff --git a/components/data_reduction_proxy.gypi b/components/data_reduction_proxy.gypi
index 10bd62e..de00304 100644
--- a/components/data_reduction_proxy.gypi
+++ b/components/data_reduction_proxy.gypi
@@ -62,6 +62,7 @@
'dependencies' : [
'../base/base.gyp:base',
'../net/net.gyp:net',
+ '../net/net.gyp:net_test_support',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
'data_reduction_proxy_browser',
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
index fb732f8..ae84b52 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_protocol_unittest.cc
@@ -14,22 +14,15 @@
#include "net/base/completion_callback.h"
#include "net/base/host_port_pair.h"
#include "net/base/network_delegate.h"
-#include "net/cert/cert_verifier.h"
-#include "net/cert/mock_cert_verifier.h"
-#include "net/dns/mock_host_resolver.h"
-#include "net/http/http_network_layer.h"
#include "net/http/http_response_headers.h"
-#include "net/http/http_server_properties_impl.h"
#include "net/http/http_transaction_test_util.h"
#include "net/socket/socket_test_util.h"
-#include "net/ssl/ssl_config_service.h"
+#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
-using net::HttpNetworkLayer;
-using net::HttpNetworkSession;
using net::HttpResponseHeaders;
using net::HostPortPair;
using net::MockRead;
@@ -38,9 +31,8 @@ using net::ProxyRetryInfoMap;
using net::ProxyService;
using net::StaticSocketDataProvider;
using net::TestDelegate;
-using net::TransportSecurityState;
using net::URLRequest;
-using net::URLRequestContext;
+using net::TestURLRequestContext;
namespace {
@@ -119,43 +111,30 @@ class TestDataReductionProxyNetworkDelegate : public net::NetworkDelegate {
TestDataReductionProxyParams* test_data_reduction_proxy_params_;
};
-// Constructs a |URLRequestContext| that uses a |MockSocketFactory| to simulate
-// requests and responses.
+// Constructs a |TestURLRequestContext| that uses a |MockSocketFactory| to
+// simulate requests and responses.
class DataReductionProxyProtocolTest : public testing::Test {
public:
- DataReductionProxyProtocolTest()
- : ssl_config_service_(new net::SSLConfigServiceDefaults) {}
+ DataReductionProxyProtocolTest() : http_user_agent_settings_("", "") {}
- // Sets up the |URLRequestContext| with the provided |ProxyService|.
+ // Sets up the |TestURLRequestContext| with the provided |ProxyService|.
void ConfigureTestDependencies(ProxyService* proxy_service) {
- cert_verifier_.reset(new net::MockCertVerifier);
- transport_security_state_.reset(new TransportSecurityState);
- proxy_service_.reset(proxy_service);
- HttpNetworkSession::Params session_params;
- session_params.client_socket_factory = &mock_socket_factory_;
- session_params.host_resolver = &host_resolver_;
- session_params.cert_verifier = cert_verifier_.get();
- session_params.transport_security_state = transport_security_state_.get();
- session_params.proxy_service = proxy_service_.get();
- session_params.ssl_config_service = ssl_config_service_.get();
- session_params.http_server_properties =
- http_server_properties_.GetWeakPtr();
- network_session_ = new HttpNetworkSession(session_params);
- factory_.reset(new HttpNetworkLayer(network_session_.get()));
+ // Create a context with delayed initialization.
+ context_.reset(new TestURLRequestContext(true));
+ proxy_service_.reset(proxy_service);
proxy_params_.reset(new TestDataReductionProxyParams());
network_delegate_.reset(new TestDataReductionProxyNetworkDelegate(
proxy_params_.get()));
- context_.reset(new URLRequestContext());
- context_->set_host_resolver(&host_resolver_);
- context_->set_cert_verifier(cert_verifier_.get());
+ context_->set_client_socket_factory(&mock_socket_factory_);
context_->set_proxy_service(proxy_service_.get());
- context_->set_ssl_config_service(ssl_config_service_.get());
- context_->set_http_transaction_factory(factory_.get());
- context_->set_http_server_properties(http_server_properties_.GetWeakPtr());
- context_->set_transport_security_state(transport_security_state_.get());
context_->set_network_delegate(network_delegate_.get());
+ // This is needed to prevent the test context from adding language headers
+ // to requests.
+ context_->set_http_user_agent_settings(&http_user_agent_settings_);
+
+ context_->Init();
}
// Simulates a request to a data reduction proxy that may result in bypassing
@@ -312,18 +291,12 @@ class DataReductionProxyProtocolTest : public testing::Test {
base::MessageLoopForIO loop_;
net::MockClientSocketFactory mock_socket_factory_;
- net::MockHostResolver host_resolver_;
- scoped_ptr<net::CertVerifier> cert_verifier_;
- scoped_ptr<TransportSecurityState> transport_security_state_;
scoped_ptr<ProxyService> proxy_service_;
- const scoped_refptr<net::SSLConfigService> ssl_config_service_;
- scoped_refptr<HttpNetworkSession> network_session_;
- scoped_ptr<HttpNetworkLayer> factory_;
- net::HttpServerPropertiesImpl http_server_properties_;
scoped_ptr<TestDataReductionProxyParams> proxy_params_;
scoped_ptr<TestDataReductionProxyNetworkDelegate> network_delegate_;
+ net::StaticHttpUserAgentSettings http_user_agent_settings_;
- scoped_ptr<URLRequestContext> context_;
+ scoped_ptr<TestURLRequestContext> context_;
};
// Tests that request are deemed idempotent or not according to the method used.
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index d98ad5d..7495b7e 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -614,6 +614,9 @@ void URLRequest::set_delegate(Delegate* delegate) {
}
void URLRequest::Start() {
+ // Some values can be NULL, but the job factory must not be.
+ DCHECK(context_->job_factory());
+
DCHECK_EQ(network_delegate_, context_->network_delegate());
// Anything that sets |blocked_by_| before start should have cleaned up after
// itself.
diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc
index 4a91fd4..0fe557b 100644
--- a/net/url_request/url_request_job_manager.cc
+++ b/net/url_request/url_request_job_manager.cc
@@ -57,12 +57,7 @@ URLRequestJob* URLRequestJobManager::CreateJob(
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase
- if (job_factory) {
- if (!job_factory->IsHandledProtocol(scheme)) {
- return new URLRequestErrorJob(
- request, network_delegate, ERR_UNKNOWN_URL_SCHEME);
- }
- } else if (!SupportsScheme(scheme)) {
+ if (!job_factory->IsHandledProtocol(scheme)) {
return new URLRequestErrorJob(
request, network_delegate, ERR_UNKNOWN_URL_SCHEME);
}
@@ -85,12 +80,10 @@ URLRequestJob* URLRequestJobManager::CreateJob(
}
}
- if (job_factory) {
- URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler(
- scheme, request, network_delegate);
- if (job)
- return job;
- }
+ URLRequestJob* job = job_factory->MaybeCreateJobWithProtocolHandler(
+ scheme, request, network_delegate);
+ if (job)
+ return job;
// See if the request should be handled by a built-in protocol factory.
for (size_t i = 0; i < arraysize(kBuiltinFactories); ++i) {
@@ -124,13 +117,8 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptRedirect(
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase
- if (job_factory) {
- if (!job_factory->IsHandledProtocol(scheme)) {
- return NULL;
- }
- } else if (!SupportsScheme(scheme)) {
+ if (!job_factory->IsHandledProtocol(scheme))
return NULL;
- }
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {
@@ -156,13 +144,8 @@ URLRequestJob* URLRequestJobManager::MaybeInterceptResponse(
job_factory = request->context()->job_factory();
const std::string& scheme = request->url().scheme(); // already lowercase
- if (job_factory) {
- if (!job_factory->IsHandledProtocol(scheme)) {
- return NULL;
- }
- } else if (!SupportsScheme(scheme)) {
+ if (!job_factory->IsHandledProtocol(scheme))
return NULL;
- }
InterceptorList::const_iterator i;
for (i = interceptors_.begin(); i != interceptors_.end(); ++i) {