| Index: net/url_request/url_request_unittest.cc
|
| diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
|
| index 5b98e35153751db431f745e670ecf9a6665be286..79683c2dc4ff0e9b02a70d8c34eed86f56567b8b 100644
|
| --- a/net/url_request/url_request_unittest.cc
|
| +++ b/net/url_request/url_request_unittest.cc
|
| @@ -100,6 +100,7 @@
|
| #include "net/test/test_data_directory.h"
|
| #include "net/test/url_request/url_request_failed_job.h"
|
| #include "net/url_request/data_protocol_handler.h"
|
| +#include "net/url_request/http_protocol_handler.h"
|
| #include "net/url_request/static_http_user_agent_settings.h"
|
| #include "net/url_request/url_request.h"
|
| #include "net/url_request/url_request_filter.h"
|
| @@ -736,8 +737,10 @@ class URLRequestTest : public PlatformTest {
|
| URLRequestTest() : default_context_(true) {
|
| default_context_.set_network_delegate(&default_network_delegate_);
|
| default_context_.set_net_log(&net_log_);
|
| - job_factory_impl_ = new URLRequestJobFactoryImpl();
|
| - job_factory_.reset(job_factory_impl_);
|
| + std::unique_ptr<URLRequestJobFactoryImpl> job_factory =
|
| + URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers();
|
| + job_factory_impl_ = job_factory.get();
|
| + job_factory_ = std::move(job_factory);
|
| }
|
|
|
| ~URLRequestTest() override {
|
| @@ -747,6 +750,9 @@ class URLRequestTest : public PlatformTest {
|
|
|
| void SetUp() override {
|
| SetUpFactory();
|
| + test_job_interceptor_ = new TestJobInterceptor;
|
| + job_factory_.reset(new URLRequestInterceptingJobFactory(
|
| + std::move(job_factory_), base::WrapUnique(test_job_interceptor_)));
|
| default_context_.set_job_factory(job_factory_.get());
|
| default_context_.Init();
|
| PlatformTest::SetUp();
|
| @@ -755,6 +761,7 @@ class URLRequestTest : public PlatformTest {
|
| virtual void SetUpFactory() {
|
| job_factory_impl_->SetProtocolHandler(
|
| "data", base::WrapUnique(new DataProtocolHandler));
|
| +
|
| #if !defined(DISABLE_FILE_SUPPORT)
|
| job_factory_impl_->SetProtocolHandler(
|
| "file", base::MakeUnique<FileProtocolHandler>(
|
| @@ -770,22 +777,13 @@ class URLRequestTest : public PlatformTest {
|
| return default_context_;
|
| }
|
|
|
| -
|
| - // Adds the TestJobInterceptor to the default context.
|
| - TestJobInterceptor* AddTestInterceptor() {
|
| - TestJobInterceptor* protocol_handler_ = new TestJobInterceptor();
|
| - job_factory_impl_->SetProtocolHandler("http", nullptr);
|
| - job_factory_impl_->SetProtocolHandler("http",
|
| - base::WrapUnique(protocol_handler_));
|
| - return protocol_handler_;
|
| - }
|
| -
|
| protected:
|
| TestNetLog net_log_;
|
| TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
|
| URLRequestJobFactoryImpl* job_factory_impl_;
|
| std::unique_ptr<URLRequestJobFactory> job_factory_;
|
| TestURLRequestContext default_context_;
|
| + TestJobInterceptor* test_job_interceptor_;
|
| };
|
|
|
| TEST_F(URLRequestTest, AboutBlankTest) {
|
| @@ -1357,7 +1355,9 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
|
| simulate_main_network_error_ = false;
|
| did_simulate_error_main_ = true;
|
| if (use_url_request_http_job_) {
|
| - return URLRequestHttpJob::Factory(request, network_delegate, "http");
|
| + return new URLRequestHttpJob(
|
| + request, network_delegate,
|
| + request->context()->http_user_agent_settings());
|
| }
|
| // This job will result in error since the requested URL is not one of the
|
| // URLs supported by these tests.
|
| @@ -1389,7 +1389,9 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
|
| intercept_redirect_ = false;
|
| did_intercept_redirect_ = true;
|
| if (use_url_request_http_job_) {
|
| - return URLRequestHttpJob::Factory(request, network_delegate, "http");
|
| + return new URLRequestHttpJob(
|
| + request, network_delegate,
|
| + request->context()->http_user_agent_settings());
|
| }
|
| return new URLRequestTestJob(request,
|
| network_delegate,
|
| @@ -1411,7 +1413,9 @@ class MockURLRequestInterceptor : public URLRequestInterceptor {
|
| intercept_final_response_ = false;
|
| did_intercept_final_ = true;
|
| if (use_url_request_http_job_) {
|
| - return URLRequestHttpJob::Factory(request, network_delegate, "http");
|
| + return new URLRequestHttpJob(
|
| + request, network_delegate,
|
| + request->context()->http_user_agent_settings());
|
| }
|
| return new URLRequestTestJob(request,
|
| network_delegate,
|
| @@ -2211,7 +2215,7 @@ TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) {
|
| RequestPriority job_priority;
|
| std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
|
| req.get(), &default_network_delegate_, &job_priority));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
| EXPECT_EQ(DEFAULT_PRIORITY, job_priority);
|
|
|
| req->SetPriority(LOW);
|
| @@ -2230,7 +2234,7 @@ TEST_F(URLRequestTest, SetJobPriority) {
|
| RequestPriority job_priority;
|
| std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
|
| req.get(), &default_network_delegate_, &job_priority));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| req->SetPriority(LOW);
|
| req->Start();
|
| @@ -2252,7 +2256,7 @@ TEST_F(URLRequestTest, PriorityIgnoreLimits) {
|
| RequestPriority job_priority;
|
| std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
|
| req.get(), &default_network_delegate_, &job_priority));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| req->SetLoadFlags(LOAD_IGNORE_LIMITS);
|
| EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
|
| @@ -6774,7 +6778,7 @@ TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) {
|
| std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
|
| r.get(), &default_network_delegate_, redirect_url,
|
| URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| r->Start();
|
| base::RunLoop().Run();
|
| @@ -7421,7 +7425,7 @@ TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
|
| req.get(), &default_network_delegate_,
|
| http_test_server()->GetURL("/echo"),
|
| URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| req->Start();
|
| base::RunLoop().Run();
|
| @@ -7448,7 +7452,7 @@ TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
|
| http_test_server()->GetURL("/echo"),
|
| URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
|
| "Very Good Reason"));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| req->Start();
|
| base::RunLoop().Run();
|
| @@ -7648,7 +7652,7 @@ TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) {
|
| req.get(), &default_network_delegate_,
|
| http_test_server()->GetURL("/echo"),
|
| URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(redirect_job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(redirect_job));
|
|
|
| req->SetPriority(LOW);
|
| req->Start();
|
| @@ -7657,7 +7661,7 @@ TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) {
|
| RequestPriority job_priority;
|
| std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
|
| req.get(), &default_network_delegate_, &job_priority));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| // Should trigger |job| to be started.
|
| base::RunLoop().Run();
|
| @@ -10214,7 +10218,7 @@ TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) {
|
| req.get(), &default_network_delegate_,
|
| GURL("http://this-should-never-be-navigated-to/"),
|
| URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp"));
|
| - AddTestInterceptor()->set_main_intercept_job(std::move(job));
|
| + test_job_interceptor_->set_main_intercept_job(std::move(job));
|
|
|
| req->Start();
|
| req->Cancel();
|
|
|