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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 1888963004: Add HttpProtocolHandler and convert everything to use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-supports-scheme
Patch Set: rebase (needs fixing) Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 #include "net/ssl/token_binding.h" 93 #include "net/ssl/token_binding.h"
94 #include "net/test/cert_test_util.h" 94 #include "net/test/cert_test_util.h"
95 #include "net/test/embedded_test_server/embedded_test_server.h" 95 #include "net/test/embedded_test_server/embedded_test_server.h"
96 #include "net/test/embedded_test_server/http_request.h" 96 #include "net/test/embedded_test_server/http_request.h"
97 #include "net/test/embedded_test_server/http_response.h" 97 #include "net/test/embedded_test_server/http_response.h"
98 #include "net/test/gtest_util.h" 98 #include "net/test/gtest_util.h"
99 #include "net/test/spawned_test_server/spawned_test_server.h" 99 #include "net/test/spawned_test_server/spawned_test_server.h"
100 #include "net/test/test_data_directory.h" 100 #include "net/test/test_data_directory.h"
101 #include "net/test/url_request/url_request_failed_job.h" 101 #include "net/test/url_request/url_request_failed_job.h"
102 #include "net/url_request/data_protocol_handler.h" 102 #include "net/url_request/data_protocol_handler.h"
103 #include "net/url_request/http_protocol_handler.h"
103 #include "net/url_request/static_http_user_agent_settings.h" 104 #include "net/url_request/static_http_user_agent_settings.h"
104 #include "net/url_request/url_request.h" 105 #include "net/url_request/url_request.h"
105 #include "net/url_request/url_request_filter.h" 106 #include "net/url_request/url_request_filter.h"
106 #include "net/url_request/url_request_http_job.h" 107 #include "net/url_request/url_request_http_job.h"
107 #include "net/url_request/url_request_intercepting_job_factory.h" 108 #include "net/url_request/url_request_intercepting_job_factory.h"
108 #include "net/url_request/url_request_interceptor.h" 109 #include "net/url_request/url_request_interceptor.h"
109 #include "net/url_request/url_request_job_factory_impl.h" 110 #include "net/url_request/url_request_job_factory_impl.h"
110 #include "net/url_request/url_request_redirect_job.h" 111 #include "net/url_request/url_request_redirect_job.h"
111 #include "net/url_request/url_request_test_job.h" 112 #include "net/url_request/url_request_test_job.h"
112 #include "net/url_request/url_request_test_util.h" 113 #include "net/url_request/url_request_test_util.h"
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 }; 730 };
730 731
731 } // namespace 732 } // namespace
732 733
733 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. 734 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.
734 class URLRequestTest : public PlatformTest { 735 class URLRequestTest : public PlatformTest {
735 public: 736 public:
736 URLRequestTest() : default_context_(true) { 737 URLRequestTest() : default_context_(true) {
737 default_context_.set_network_delegate(&default_network_delegate_); 738 default_context_.set_network_delegate(&default_network_delegate_);
738 default_context_.set_net_log(&net_log_); 739 default_context_.set_net_log(&net_log_);
739 job_factory_impl_ = new URLRequestJobFactoryImpl(); 740 std::unique_ptr<URLRequestJobFactoryImpl> job_factory =
740 job_factory_.reset(job_factory_impl_); 741 URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers();
742 job_factory_impl_ = job_factory.get();
743 job_factory_ = std::move(job_factory);
741 } 744 }
742 745
743 ~URLRequestTest() override { 746 ~URLRequestTest() override {
744 // URLRequestJobs may post clean-up tasks on destruction. 747 // URLRequestJobs may post clean-up tasks on destruction.
745 base::RunLoop().RunUntilIdle(); 748 base::RunLoop().RunUntilIdle();
746 } 749 }
747 750
748 void SetUp() override { 751 void SetUp() override {
749 SetUpFactory(); 752 SetUpFactory();
753 test_job_interceptor_ = new TestJobInterceptor;
754 job_factory_.reset(new URLRequestInterceptingJobFactory(
755 std::move(job_factory_), base::WrapUnique(test_job_interceptor_)));
750 default_context_.set_job_factory(job_factory_.get()); 756 default_context_.set_job_factory(job_factory_.get());
751 default_context_.Init(); 757 default_context_.Init();
752 PlatformTest::SetUp(); 758 PlatformTest::SetUp();
753 } 759 }
754 760
755 virtual void SetUpFactory() { 761 virtual void SetUpFactory() {
756 job_factory_impl_->SetProtocolHandler( 762 job_factory_impl_->SetProtocolHandler(
757 "data", base::WrapUnique(new DataProtocolHandler)); 763 "data", base::WrapUnique(new DataProtocolHandler));
764
758 #if !defined(DISABLE_FILE_SUPPORT) 765 #if !defined(DISABLE_FILE_SUPPORT)
759 job_factory_impl_->SetProtocolHandler( 766 job_factory_impl_->SetProtocolHandler(
760 "file", base::MakeUnique<FileProtocolHandler>( 767 "file", base::MakeUnique<FileProtocolHandler>(
761 base::ThreadTaskRunnerHandle::Get())); 768 base::ThreadTaskRunnerHandle::Get()));
762 #endif 769 #endif
763 } 770 }
764 771
765 TestNetworkDelegate* default_network_delegate() { 772 TestNetworkDelegate* default_network_delegate() {
766 return &default_network_delegate_; 773 return &default_network_delegate_;
767 } 774 }
768 775
769 const TestURLRequestContext& default_context() const { 776 const TestURLRequestContext& default_context() const {
770 return default_context_; 777 return default_context_;
771 } 778 }
772 779
773
774 // Adds the TestJobInterceptor to the default context.
775 TestJobInterceptor* AddTestInterceptor() {
776 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor();
777 job_factory_impl_->SetProtocolHandler("http", nullptr);
778 job_factory_impl_->SetProtocolHandler("http",
779 base::WrapUnique(protocol_handler_));
780 return protocol_handler_;
781 }
782
783 protected: 780 protected:
784 TestNetLog net_log_; 781 TestNetLog net_log_;
785 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 782 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
786 URLRequestJobFactoryImpl* job_factory_impl_; 783 URLRequestJobFactoryImpl* job_factory_impl_;
787 std::unique_ptr<URLRequestJobFactory> job_factory_; 784 std::unique_ptr<URLRequestJobFactory> job_factory_;
788 TestURLRequestContext default_context_; 785 TestURLRequestContext default_context_;
786 TestJobInterceptor* test_job_interceptor_;
789 }; 787 };
790 788
791 TEST_F(URLRequestTest, AboutBlankTest) { 789 TEST_F(URLRequestTest, AboutBlankTest) {
792 TestDelegate d; 790 TestDelegate d;
793 { 791 {
794 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( 792 std::unique_ptr<URLRequest> r(default_context_.CreateRequest(
795 GURL("about:blank"), DEFAULT_PRIORITY, &d)); 793 GURL("about:blank"), DEFAULT_PRIORITY, &d));
796 794
797 r->Start(); 795 r->Start();
798 EXPECT_TRUE(r->is_pending()); 796 EXPECT_TRUE(r->is_pending());
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 } 1348 }
1351 if (cancel_then_restart_main_request_) { 1349 if (cancel_then_restart_main_request_) {
1352 cancel_then_restart_main_request_ = false; 1350 cancel_then_restart_main_request_ = false;
1353 did_cancel_then_restart_main_ = true; 1351 did_cancel_then_restart_main_ = true;
1354 return new CancelThenRestartTestJob(request, network_delegate); 1352 return new CancelThenRestartTestJob(request, network_delegate);
1355 } 1353 }
1356 if (simulate_main_network_error_) { 1354 if (simulate_main_network_error_) {
1357 simulate_main_network_error_ = false; 1355 simulate_main_network_error_ = false;
1358 did_simulate_error_main_ = true; 1356 did_simulate_error_main_ = true;
1359 if (use_url_request_http_job_) { 1357 if (use_url_request_http_job_) {
1360 return URLRequestHttpJob::Factory(request, network_delegate, "http"); 1358 return new URLRequestHttpJob(
1359 request, network_delegate,
1360 request->context()->http_user_agent_settings());
1361 } 1361 }
1362 // This job will result in error since the requested URL is not one of the 1362 // This job will result in error since the requested URL is not one of the
1363 // URLs supported by these tests. 1363 // URLs supported by these tests.
1364 return new URLRequestTestJob(request, network_delegate, true); 1364 return new URLRequestTestJob(request, network_delegate, true);
1365 } 1365 }
1366 if (!intercept_main_request_) 1366 if (!intercept_main_request_)
1367 return nullptr; 1367 return nullptr;
1368 intercept_main_request_ = false; 1368 intercept_main_request_ = false;
1369 did_intercept_main_ = true; 1369 did_intercept_main_ = true;
1370 URLRequestTestJob* job = new URLRequestTestJob(request, 1370 URLRequestTestJob* job = new URLRequestTestJob(request,
(...skipping 11 matching lines...) Expand all
1382 if (cancel_redirect_request_) { 1382 if (cancel_redirect_request_) {
1383 cancel_redirect_request_ = false; 1383 cancel_redirect_request_ = false;
1384 did_cancel_redirect_ = true; 1384 did_cancel_redirect_ = true;
1385 return new CancelTestJob(request, network_delegate); 1385 return new CancelTestJob(request, network_delegate);
1386 } 1386 }
1387 if (!intercept_redirect_) 1387 if (!intercept_redirect_)
1388 return nullptr; 1388 return nullptr;
1389 intercept_redirect_ = false; 1389 intercept_redirect_ = false;
1390 did_intercept_redirect_ = true; 1390 did_intercept_redirect_ = true;
1391 if (use_url_request_http_job_) { 1391 if (use_url_request_http_job_) {
1392 return URLRequestHttpJob::Factory(request, network_delegate, "http"); 1392 return new URLRequestHttpJob(
1393 request, network_delegate,
1394 request->context()->http_user_agent_settings());
1393 } 1395 }
1394 return new URLRequestTestJob(request, 1396 return new URLRequestTestJob(request,
1395 network_delegate, 1397 network_delegate,
1396 redirect_headers_, 1398 redirect_headers_,
1397 redirect_data_, 1399 redirect_data_,
1398 true); 1400 true);
1399 } 1401 }
1400 1402
1401 URLRequestJob* MaybeInterceptResponse( 1403 URLRequestJob* MaybeInterceptResponse(
1402 URLRequest* request, 1404 URLRequest* request,
1403 NetworkDelegate* network_delegate) const override { 1405 NetworkDelegate* network_delegate) const override {
1404 if (cancel_final_request_) { 1406 if (cancel_final_request_) {
1405 cancel_final_request_ = false; 1407 cancel_final_request_ = false;
1406 did_cancel_final_ = true; 1408 did_cancel_final_ = true;
1407 return new CancelTestJob(request, network_delegate); 1409 return new CancelTestJob(request, network_delegate);
1408 } 1410 }
1409 if (!intercept_final_response_) 1411 if (!intercept_final_response_)
1410 return nullptr; 1412 return nullptr;
1411 intercept_final_response_ = false; 1413 intercept_final_response_ = false;
1412 did_intercept_final_ = true; 1414 did_intercept_final_ = true;
1413 if (use_url_request_http_job_) { 1415 if (use_url_request_http_job_) {
1414 return URLRequestHttpJob::Factory(request, network_delegate, "http"); 1416 return new URLRequestHttpJob(
1417 request, network_delegate,
1418 request->context()->http_user_agent_settings());
1415 } 1419 }
1416 return new URLRequestTestJob(request, 1420 return new URLRequestTestJob(request,
1417 network_delegate, 1421 network_delegate,
1418 final_headers_, 1422 final_headers_,
1419 final_data_, 1423 final_data_,
1420 true); 1424 true);
1421 } 1425 }
1422 1426
1423 void set_intercept_main_request(bool intercept_main_request) { 1427 void set_intercept_main_request(bool intercept_main_request) {
1424 intercept_main_request_ = intercept_main_request; 1428 intercept_main_request_ = intercept_main_request;
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 // Start on it. 2208 // Start on it.
2205 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { 2209 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) {
2206 TestDelegate d; 2210 TestDelegate d;
2207 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2211 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2208 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 2212 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
2209 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); 2213 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
2210 2214
2211 RequestPriority job_priority; 2215 RequestPriority job_priority;
2212 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( 2216 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
2213 req.get(), &default_network_delegate_, &job_priority)); 2217 req.get(), &default_network_delegate_, &job_priority));
2214 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 2218 test_job_interceptor_->set_main_intercept_job(std::move(job));
2215 EXPECT_EQ(DEFAULT_PRIORITY, job_priority); 2219 EXPECT_EQ(DEFAULT_PRIORITY, job_priority);
2216 2220
2217 req->SetPriority(LOW); 2221 req->SetPriority(LOW);
2218 2222
2219 req->Start(); 2223 req->Start();
2220 EXPECT_EQ(LOW, job_priority); 2224 EXPECT_EQ(LOW, job_priority);
2221 } 2225 }
2222 2226
2223 // Make sure that URLRequest passes on its priority updates to its 2227 // Make sure that URLRequest passes on its priority updates to its
2224 // job. 2228 // job.
2225 TEST_F(URLRequestTest, SetJobPriority) { 2229 TEST_F(URLRequestTest, SetJobPriority) {
2226 TestDelegate d; 2230 TestDelegate d;
2227 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2231 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2228 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); 2232 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
2229 2233
2230 RequestPriority job_priority; 2234 RequestPriority job_priority;
2231 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( 2235 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
2232 req.get(), &default_network_delegate_, &job_priority)); 2236 req.get(), &default_network_delegate_, &job_priority));
2233 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 2237 test_job_interceptor_->set_main_intercept_job(std::move(job));
2234 2238
2235 req->SetPriority(LOW); 2239 req->SetPriority(LOW);
2236 req->Start(); 2240 req->Start();
2237 EXPECT_EQ(LOW, job_priority); 2241 EXPECT_EQ(LOW, job_priority);
2238 2242
2239 req->SetPriority(MEDIUM); 2243 req->SetPriority(MEDIUM);
2240 EXPECT_EQ(MEDIUM, req->priority()); 2244 EXPECT_EQ(MEDIUM, req->priority());
2241 EXPECT_EQ(MEDIUM, job_priority); 2245 EXPECT_EQ(MEDIUM, job_priority);
2242 } 2246 }
2243 2247
2244 // Setting the IGNORE_LIMITS load flag should be okay if the priority 2248 // Setting the IGNORE_LIMITS load flag should be okay if the priority
2245 // is MAXIMUM_PRIORITY. 2249 // is MAXIMUM_PRIORITY.
2246 TEST_F(URLRequestTest, PriorityIgnoreLimits) { 2250 TEST_F(URLRequestTest, PriorityIgnoreLimits) {
2247 TestDelegate d; 2251 TestDelegate d;
2248 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 2252 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
2249 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d)); 2253 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d));
2250 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); 2254 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
2251 2255
2252 RequestPriority job_priority; 2256 RequestPriority job_priority;
2253 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( 2257 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
2254 req.get(), &default_network_delegate_, &job_priority)); 2258 req.get(), &default_network_delegate_, &job_priority));
2255 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 2259 test_job_interceptor_->set_main_intercept_job(std::move(job));
2256 2260
2257 req->SetLoadFlags(LOAD_IGNORE_LIMITS); 2261 req->SetLoadFlags(LOAD_IGNORE_LIMITS);
2258 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); 2262 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
2259 2263
2260 req->SetPriority(MAXIMUM_PRIORITY); 2264 req->SetPriority(MAXIMUM_PRIORITY);
2261 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); 2265 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
2262 2266
2263 req->Start(); 2267 req->Start();
2264 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); 2268 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
2265 EXPECT_EQ(MAXIMUM_PRIORITY, job_priority); 2269 EXPECT_EQ(MAXIMUM_PRIORITY, job_priority);
(...skipping 4501 matching lines...) Expand 10 before | Expand all | Expand 10 after
6767 http_test_server()->GetURL("/original#should-not-be-appended")); 6771 http_test_server()->GetURL("/original#should-not-be-appended"));
6768 GURL redirect_url(http_test_server()->GetURL("/echo")); 6772 GURL redirect_url(http_test_server()->GetURL("/echo"));
6769 6773
6770 TestDelegate d; 6774 TestDelegate d;
6771 std::unique_ptr<URLRequest> r( 6775 std::unique_ptr<URLRequest> r(
6772 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); 6776 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
6773 6777
6774 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( 6778 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
6775 r.get(), &default_network_delegate_, redirect_url, 6779 r.get(), &default_network_delegate_, redirect_url,
6776 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); 6780 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
6777 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 6781 test_job_interceptor_->set_main_intercept_job(std::move(job));
6778 6782
6779 r->Start(); 6783 r->Start();
6780 base::RunLoop().Run(); 6784 base::RunLoop().Run();
6781 6785
6782 EXPECT_EQ(OK, d.request_status()); 6786 EXPECT_EQ(OK, d.request_status());
6783 EXPECT_EQ(original_url, r->original_url()); 6787 EXPECT_EQ(original_url, r->original_url());
6784 EXPECT_EQ(redirect_url, r->url()); 6788 EXPECT_EQ(redirect_url, r->url());
6785 } 6789 }
6786 6790
6787 TEST_F(URLRequestTestHTTP, UnsupportedReferrerScheme) { 6791 TEST_F(URLRequestTestHTTP, UnsupportedReferrerScheme) {
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
7414 req->set_upload(CreateSimpleUploadData(kData)); 7418 req->set_upload(CreateSimpleUploadData(kData));
7415 HttpRequestHeaders headers; 7419 HttpRequestHeaders headers;
7416 headers.SetHeader(HttpRequestHeaders::kContentLength, 7420 headers.SetHeader(HttpRequestHeaders::kContentLength,
7417 base::SizeTToString(arraysize(kData) - 1)); 7421 base::SizeTToString(arraysize(kData) - 1));
7418 req->SetExtraRequestHeaders(headers); 7422 req->SetExtraRequestHeaders(headers);
7419 7423
7420 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( 7424 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
7421 req.get(), &default_network_delegate_, 7425 req.get(), &default_network_delegate_,
7422 http_test_server()->GetURL("/echo"), 7426 http_test_server()->GetURL("/echo"),
7423 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); 7427 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
7424 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 7428 test_job_interceptor_->set_main_intercept_job(std::move(job));
7425 7429
7426 req->Start(); 7430 req->Start();
7427 base::RunLoop().Run(); 7431 base::RunLoop().Run();
7428 EXPECT_EQ("GET", req->method()); 7432 EXPECT_EQ("GET", req->method());
7429 } 7433 }
7430 7434
7431 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { 7435 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
7432 ASSERT_TRUE(http_test_server()->Start()); 7436 ASSERT_TRUE(http_test_server()->Start());
7433 7437
7434 const char kData[] = "hello world"; 7438 const char kData[] = "hello world";
7435 7439
7436 TestDelegate d; 7440 TestDelegate d;
7437 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 7441 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
7438 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); 7442 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d));
7439 req->set_method("POST"); 7443 req->set_method("POST");
7440 req->set_upload(CreateSimpleUploadData(kData)); 7444 req->set_upload(CreateSimpleUploadData(kData));
7441 HttpRequestHeaders headers; 7445 HttpRequestHeaders headers;
7442 headers.SetHeader(HttpRequestHeaders::kContentLength, 7446 headers.SetHeader(HttpRequestHeaders::kContentLength,
7443 base::SizeTToString(arraysize(kData) - 1)); 7447 base::SizeTToString(arraysize(kData) - 1));
7444 req->SetExtraRequestHeaders(headers); 7448 req->SetExtraRequestHeaders(headers);
7445 7449
7446 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( 7450 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
7447 req.get(), &default_network_delegate_, 7451 req.get(), &default_network_delegate_,
7448 http_test_server()->GetURL("/echo"), 7452 http_test_server()->GetURL("/echo"),
7449 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, 7453 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
7450 "Very Good Reason")); 7454 "Very Good Reason"));
7451 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 7455 test_job_interceptor_->set_main_intercept_job(std::move(job));
7452 7456
7453 req->Start(); 7457 req->Start();
7454 base::RunLoop().Run(); 7458 base::RunLoop().Run();
7455 EXPECT_EQ("POST", req->method()); 7459 EXPECT_EQ("POST", req->method());
7456 EXPECT_EQ(kData, d.data_received()); 7460 EXPECT_EQ(kData, d.data_received());
7457 } 7461 }
7458 7462
7459 // Check that default A-L header is sent. 7463 // Check that default A-L header is sent.
7460 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { 7464 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) {
7461 ASSERT_TRUE(http_test_server()->Start()); 7465 ASSERT_TRUE(http_test_server()->Start());
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
7641 7645
7642 TestDelegate d; 7646 TestDelegate d;
7643 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 7647 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
7644 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); 7648 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d));
7645 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); 7649 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
7646 7650
7647 std::unique_ptr<URLRequestRedirectJob> redirect_job(new URLRequestRedirectJob( 7651 std::unique_ptr<URLRequestRedirectJob> redirect_job(new URLRequestRedirectJob(
7648 req.get(), &default_network_delegate_, 7652 req.get(), &default_network_delegate_,
7649 http_test_server()->GetURL("/echo"), 7653 http_test_server()->GetURL("/echo"),
7650 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); 7654 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"));
7651 AddTestInterceptor()->set_main_intercept_job(std::move(redirect_job)); 7655 test_job_interceptor_->set_main_intercept_job(std::move(redirect_job));
7652 7656
7653 req->SetPriority(LOW); 7657 req->SetPriority(LOW);
7654 req->Start(); 7658 req->Start();
7655 EXPECT_TRUE(req->is_pending()); 7659 EXPECT_TRUE(req->is_pending());
7656 7660
7657 RequestPriority job_priority; 7661 RequestPriority job_priority;
7658 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( 7662 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob(
7659 req.get(), &default_network_delegate_, &job_priority)); 7663 req.get(), &default_network_delegate_, &job_priority));
7660 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 7664 test_job_interceptor_->set_main_intercept_job(std::move(job));
7661 7665
7662 // Should trigger |job| to be started. 7666 // Should trigger |job| to be started.
7663 base::RunLoop().Run(); 7667 base::RunLoop().Run();
7664 EXPECT_EQ(LOW, job_priority); 7668 EXPECT_EQ(LOW, job_priority);
7665 } 7669 }
7666 7670
7667 // Check that creating a network request while entering/exiting suspend mode 7671 // Check that creating a network request while entering/exiting suspend mode
7668 // fails as it should. This is the only case where an HttpTransactionFactory 7672 // fails as it should. This is the only case where an HttpTransactionFactory
7669 // does not return an HttpTransaction. 7673 // does not return an HttpTransaction.
7670 TEST_F(URLRequestTestHTTP, NetworkSuspendTest) { 7674 TEST_F(URLRequestTestHTTP, NetworkSuspendTest) {
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after
10207 // See http://crbug.com/508900 10211 // See http://crbug.com/508900
10208 TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) { 10212 TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) {
10209 TestDelegate d; 10213 TestDelegate d;
10210 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 10214 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
10211 GURL("http://not-a-real-domain/"), DEFAULT_PRIORITY, &d)); 10215 GURL("http://not-a-real-domain/"), DEFAULT_PRIORITY, &d));
10212 10216
10213 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( 10217 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob(
10214 req.get(), &default_network_delegate_, 10218 req.get(), &default_network_delegate_,
10215 GURL("http://this-should-never-be-navigated-to/"), 10219 GURL("http://this-should-never-be-navigated-to/"),
10216 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp")); 10220 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp"));
10217 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10221 test_job_interceptor_->set_main_intercept_job(std::move(job));
10218 10222
10219 req->Start(); 10223 req->Start();
10220 req->Cancel(); 10224 req->Cancel();
10221 base::RunLoop().RunUntilIdle(); 10225 base::RunLoop().RunUntilIdle();
10222 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10226 EXPECT_EQ(ERR_ABORTED, d.request_status());
10223 EXPECT_EQ(0, d.received_redirect_count()); 10227 EXPECT_EQ(0, d.received_redirect_count());
10224 } 10228 }
10225 10229
10226 } // namespace net 10230 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698