OLD | NEW |
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 "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 #include "net/ssl/ssl_connection_status_flags.h" | 89 #include "net/ssl/ssl_connection_status_flags.h" |
90 #include "net/ssl/ssl_server_config.h" | 90 #include "net/ssl/ssl_server_config.h" |
91 #include "net/ssl/token_binding.h" | 91 #include "net/ssl/token_binding.h" |
92 #include "net/test/cert_test_util.h" | 92 #include "net/test/cert_test_util.h" |
93 #include "net/test/embedded_test_server/embedded_test_server.h" | 93 #include "net/test/embedded_test_server/embedded_test_server.h" |
94 #include "net/test/embedded_test_server/http_request.h" | 94 #include "net/test/embedded_test_server/http_request.h" |
95 #include "net/test/embedded_test_server/http_response.h" | 95 #include "net/test/embedded_test_server/http_response.h" |
96 #include "net/test/spawned_test_server/spawned_test_server.h" | 96 #include "net/test/spawned_test_server/spawned_test_server.h" |
97 #include "net/test/url_request/url_request_failed_job.h" | 97 #include "net/test/url_request/url_request_failed_job.h" |
98 #include "net/url_request/data_protocol_handler.h" | 98 #include "net/url_request/data_protocol_handler.h" |
| 99 #include "net/url_request/http_protocol_handler.h" |
99 #include "net/url_request/static_http_user_agent_settings.h" | 100 #include "net/url_request/static_http_user_agent_settings.h" |
100 #include "net/url_request/url_request.h" | 101 #include "net/url_request/url_request.h" |
101 #include "net/url_request/url_request_filter.h" | 102 #include "net/url_request/url_request_filter.h" |
102 #include "net/url_request/url_request_http_job.h" | 103 #include "net/url_request/url_request_http_job.h" |
103 #include "net/url_request/url_request_intercepting_job_factory.h" | 104 #include "net/url_request/url_request_intercepting_job_factory.h" |
104 #include "net/url_request/url_request_interceptor.h" | 105 #include "net/url_request/url_request_interceptor.h" |
105 #include "net/url_request/url_request_job_factory_impl.h" | 106 #include "net/url_request/url_request_job_factory_impl.h" |
106 #include "net/url_request/url_request_redirect_job.h" | 107 #include "net/url_request/url_request_redirect_job.h" |
107 #include "net/url_request/url_request_test_job.h" | 108 #include "net/url_request/url_request_test_job.h" |
108 #include "net/url_request/url_request_test_util.h" | 109 #include "net/url_request/url_request_test_util.h" |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 }; | 709 }; |
709 | 710 |
710 } // namespace | 711 } // namespace |
711 | 712 |
712 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 713 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
713 class URLRequestTest : public PlatformTest { | 714 class URLRequestTest : public PlatformTest { |
714 public: | 715 public: |
715 URLRequestTest() : default_context_(true) { | 716 URLRequestTest() : default_context_(true) { |
716 default_context_.set_network_delegate(&default_network_delegate_); | 717 default_context_.set_network_delegate(&default_network_delegate_); |
717 default_context_.set_net_log(&net_log_); | 718 default_context_.set_net_log(&net_log_); |
718 job_factory_impl_ = new URLRequestJobFactoryImpl(); | 719 std::unique_ptr<URLRequestJobFactoryImpl> job_factory = |
719 job_factory_.reset(job_factory_impl_); | 720 URLRequestJobFactoryImpl::CreateWithHttpProtocolHandlers(); |
| 721 job_factory_impl_ = job_factory.get(); |
| 722 job_factory_ = std::move(job_factory); |
720 } | 723 } |
721 | 724 |
722 ~URLRequestTest() override { | 725 ~URLRequestTest() override { |
723 // URLRequestJobs may post clean-up tasks on destruction. | 726 // URLRequestJobs may post clean-up tasks on destruction. |
724 base::RunLoop().RunUntilIdle(); | 727 base::RunLoop().RunUntilIdle(); |
725 } | 728 } |
726 | 729 |
727 void SetUp() override { | 730 void SetUp() override { |
728 SetUpFactory(); | 731 SetUpFactory(); |
| 732 test_job_interceptor_ = new TestJobInterceptor; |
| 733 job_factory_.reset(new URLRequestInterceptingJobFactory( |
| 734 std::move(job_factory_), base::WrapUnique(test_job_interceptor_))); |
729 default_context_.set_job_factory(job_factory_.get()); | 735 default_context_.set_job_factory(job_factory_.get()); |
730 default_context_.Init(); | 736 default_context_.Init(); |
731 PlatformTest::SetUp(); | 737 PlatformTest::SetUp(); |
732 } | 738 } |
733 | 739 |
734 virtual void SetUpFactory() { | 740 virtual void SetUpFactory() { |
735 job_factory_impl_->SetProtocolHandler( | 741 job_factory_impl_->SetProtocolHandler( |
736 "data", base::WrapUnique(new DataProtocolHandler)); | 742 "data", base::WrapUnique(new DataProtocolHandler)); |
| 743 |
737 #if !defined(DISABLE_FILE_SUPPORT) | 744 #if !defined(DISABLE_FILE_SUPPORT) |
738 job_factory_impl_->SetProtocolHandler( | 745 job_factory_impl_->SetProtocolHandler( |
739 "file", base::WrapUnique(new FileProtocolHandler( | 746 "file", base::WrapUnique(new FileProtocolHandler( |
740 base::ThreadTaskRunnerHandle::Get()))); | 747 base::ThreadTaskRunnerHandle::Get()))); |
741 #endif | 748 #endif |
742 } | 749 } |
743 | 750 |
744 TestNetworkDelegate* default_network_delegate() { | 751 TestNetworkDelegate* default_network_delegate() { |
745 return &default_network_delegate_; | 752 return &default_network_delegate_; |
746 } | 753 } |
747 | 754 |
748 const TestURLRequestContext& default_context() const { | 755 const TestURLRequestContext& default_context() const { |
749 return default_context_; | 756 return default_context_; |
750 } | 757 } |
751 | 758 |
752 | |
753 // Adds the TestJobInterceptor to the default context. | |
754 TestJobInterceptor* AddTestInterceptor() { | |
755 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | |
756 job_factory_impl_->SetProtocolHandler("http", nullptr); | |
757 job_factory_impl_->SetProtocolHandler("http", | |
758 base::WrapUnique(protocol_handler_)); | |
759 return protocol_handler_; | |
760 } | |
761 | |
762 protected: | 759 protected: |
763 TestNetLog net_log_; | 760 TestNetLog net_log_; |
764 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 761 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
765 URLRequestJobFactoryImpl* job_factory_impl_; | 762 URLRequestJobFactoryImpl* job_factory_impl_; |
766 std::unique_ptr<URLRequestJobFactory> job_factory_; | 763 std::unique_ptr<URLRequestJobFactory> job_factory_; |
767 TestURLRequestContext default_context_; | 764 TestURLRequestContext default_context_; |
| 765 TestJobInterceptor* test_job_interceptor_; |
768 }; | 766 }; |
769 | 767 |
770 TEST_F(URLRequestTest, AboutBlankTest) { | 768 TEST_F(URLRequestTest, AboutBlankTest) { |
771 TestDelegate d; | 769 TestDelegate d; |
772 { | 770 { |
773 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 771 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
774 GURL("about:blank"), DEFAULT_PRIORITY, &d)); | 772 GURL("about:blank"), DEFAULT_PRIORITY, &d)); |
775 | 773 |
776 r->Start(); | 774 r->Start(); |
777 EXPECT_TRUE(r->is_pending()); | 775 EXPECT_TRUE(r->is_pending()); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 } | 1327 } |
1330 if (cancel_then_restart_main_request_) { | 1328 if (cancel_then_restart_main_request_) { |
1331 cancel_then_restart_main_request_ = false; | 1329 cancel_then_restart_main_request_ = false; |
1332 did_cancel_then_restart_main_ = true; | 1330 did_cancel_then_restart_main_ = true; |
1333 return new CancelThenRestartTestJob(request, network_delegate); | 1331 return new CancelThenRestartTestJob(request, network_delegate); |
1334 } | 1332 } |
1335 if (simulate_main_network_error_) { | 1333 if (simulate_main_network_error_) { |
1336 simulate_main_network_error_ = false; | 1334 simulate_main_network_error_ = false; |
1337 did_simulate_error_main_ = true; | 1335 did_simulate_error_main_ = true; |
1338 if (use_url_request_http_job_) { | 1336 if (use_url_request_http_job_) { |
1339 return URLRequestHttpJob::Factory(request, network_delegate, "http"); | 1337 return new URLRequestHttpJob( |
| 1338 request, network_delegate, |
| 1339 request->context()->http_user_agent_settings()); |
1340 } | 1340 } |
1341 // This job will result in error since the requested URL is not one of the | 1341 // This job will result in error since the requested URL is not one of the |
1342 // URLs supported by these tests. | 1342 // URLs supported by these tests. |
1343 return new URLRequestTestJob(request, network_delegate, true); | 1343 return new URLRequestTestJob(request, network_delegate, true); |
1344 } | 1344 } |
1345 if (!intercept_main_request_) | 1345 if (!intercept_main_request_) |
1346 return nullptr; | 1346 return nullptr; |
1347 intercept_main_request_ = false; | 1347 intercept_main_request_ = false; |
1348 did_intercept_main_ = true; | 1348 did_intercept_main_ = true; |
1349 URLRequestTestJob* job = new URLRequestTestJob(request, | 1349 URLRequestTestJob* job = new URLRequestTestJob(request, |
(...skipping 11 matching lines...) Expand all Loading... |
1361 if (cancel_redirect_request_) { | 1361 if (cancel_redirect_request_) { |
1362 cancel_redirect_request_ = false; | 1362 cancel_redirect_request_ = false; |
1363 did_cancel_redirect_ = true; | 1363 did_cancel_redirect_ = true; |
1364 return new CancelTestJob(request, network_delegate); | 1364 return new CancelTestJob(request, network_delegate); |
1365 } | 1365 } |
1366 if (!intercept_redirect_) | 1366 if (!intercept_redirect_) |
1367 return nullptr; | 1367 return nullptr; |
1368 intercept_redirect_ = false; | 1368 intercept_redirect_ = false; |
1369 did_intercept_redirect_ = true; | 1369 did_intercept_redirect_ = true; |
1370 if (use_url_request_http_job_) { | 1370 if (use_url_request_http_job_) { |
1371 return URLRequestHttpJob::Factory(request, network_delegate, "http"); | 1371 return new URLRequestHttpJob( |
| 1372 request, network_delegate, |
| 1373 request->context()->http_user_agent_settings()); |
1372 } | 1374 } |
1373 return new URLRequestTestJob(request, | 1375 return new URLRequestTestJob(request, |
1374 network_delegate, | 1376 network_delegate, |
1375 redirect_headers_, | 1377 redirect_headers_, |
1376 redirect_data_, | 1378 redirect_data_, |
1377 true); | 1379 true); |
1378 } | 1380 } |
1379 | 1381 |
1380 URLRequestJob* MaybeInterceptResponse( | 1382 URLRequestJob* MaybeInterceptResponse( |
1381 URLRequest* request, | 1383 URLRequest* request, |
1382 NetworkDelegate* network_delegate) const override { | 1384 NetworkDelegate* network_delegate) const override { |
1383 if (cancel_final_request_) { | 1385 if (cancel_final_request_) { |
1384 cancel_final_request_ = false; | 1386 cancel_final_request_ = false; |
1385 did_cancel_final_ = true; | 1387 did_cancel_final_ = true; |
1386 return new CancelTestJob(request, network_delegate); | 1388 return new CancelTestJob(request, network_delegate); |
1387 } | 1389 } |
1388 if (!intercept_final_response_) | 1390 if (!intercept_final_response_) |
1389 return nullptr; | 1391 return nullptr; |
1390 intercept_final_response_ = false; | 1392 intercept_final_response_ = false; |
1391 did_intercept_final_ = true; | 1393 did_intercept_final_ = true; |
1392 if (use_url_request_http_job_) { | 1394 if (use_url_request_http_job_) { |
1393 return URLRequestHttpJob::Factory(request, network_delegate, "http"); | 1395 return new URLRequestHttpJob( |
| 1396 request, network_delegate, |
| 1397 request->context()->http_user_agent_settings()); |
1394 } | 1398 } |
1395 return new URLRequestTestJob(request, | 1399 return new URLRequestTestJob(request, |
1396 network_delegate, | 1400 network_delegate, |
1397 final_headers_, | 1401 final_headers_, |
1398 final_data_, | 1402 final_data_, |
1399 true); | 1403 true); |
1400 } | 1404 } |
1401 | 1405 |
1402 void set_intercept_main_request(bool intercept_main_request) { | 1406 void set_intercept_main_request(bool intercept_main_request) { |
1403 intercept_main_request_ = intercept_main_request; | 1407 intercept_main_request_ = intercept_main_request; |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2184 // Start on it. | 2188 // Start on it. |
2185 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { | 2189 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { |
2186 TestDelegate d; | 2190 TestDelegate d; |
2187 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2191 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
2188 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 2192 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
2189 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); | 2193 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
2190 | 2194 |
2191 RequestPriority job_priority; | 2195 RequestPriority job_priority; |
2192 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 2196 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
2193 req.get(), &default_network_delegate_, &job_priority)); | 2197 req.get(), &default_network_delegate_, &job_priority)); |
2194 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 2198 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
2195 EXPECT_EQ(DEFAULT_PRIORITY, job_priority); | 2199 EXPECT_EQ(DEFAULT_PRIORITY, job_priority); |
2196 | 2200 |
2197 req->SetPriority(LOW); | 2201 req->SetPriority(LOW); |
2198 | 2202 |
2199 req->Start(); | 2203 req->Start(); |
2200 EXPECT_EQ(LOW, job_priority); | 2204 EXPECT_EQ(LOW, job_priority); |
2201 } | 2205 } |
2202 | 2206 |
2203 // Make sure that URLRequest passes on its priority updates to its | 2207 // Make sure that URLRequest passes on its priority updates to its |
2204 // job. | 2208 // job. |
2205 TEST_F(URLRequestTest, SetJobPriority) { | 2209 TEST_F(URLRequestTest, SetJobPriority) { |
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 | 2213 |
2210 RequestPriority job_priority; | 2214 RequestPriority job_priority; |
2211 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 2215 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
2212 req.get(), &default_network_delegate_, &job_priority)); | 2216 req.get(), &default_network_delegate_, &job_priority)); |
2213 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 2217 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
2214 | 2218 |
2215 req->SetPriority(LOW); | 2219 req->SetPriority(LOW); |
2216 req->Start(); | 2220 req->Start(); |
2217 EXPECT_EQ(LOW, job_priority); | 2221 EXPECT_EQ(LOW, job_priority); |
2218 | 2222 |
2219 req->SetPriority(MEDIUM); | 2223 req->SetPriority(MEDIUM); |
2220 EXPECT_EQ(MEDIUM, req->priority()); | 2224 EXPECT_EQ(MEDIUM, req->priority()); |
2221 EXPECT_EQ(MEDIUM, job_priority); | 2225 EXPECT_EQ(MEDIUM, job_priority); |
2222 } | 2226 } |
2223 | 2227 |
2224 // Setting the IGNORE_LIMITS load flag should be okay if the priority | 2228 // Setting the IGNORE_LIMITS load flag should be okay if the priority |
2225 // is MAXIMUM_PRIORITY. | 2229 // is MAXIMUM_PRIORITY. |
2226 TEST_F(URLRequestTest, PriorityIgnoreLimits) { | 2230 TEST_F(URLRequestTest, PriorityIgnoreLimits) { |
2227 TestDelegate d; | 2231 TestDelegate d; |
2228 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2232 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
2229 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d)); | 2233 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d)); |
2230 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2234 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
2231 | 2235 |
2232 RequestPriority job_priority; | 2236 RequestPriority job_priority; |
2233 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 2237 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
2234 req.get(), &default_network_delegate_, &job_priority)); | 2238 req.get(), &default_network_delegate_, &job_priority)); |
2235 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 2239 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
2236 | 2240 |
2237 req->SetLoadFlags(LOAD_IGNORE_LIMITS); | 2241 req->SetLoadFlags(LOAD_IGNORE_LIMITS); |
2238 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2242 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
2239 | 2243 |
2240 req->SetPriority(MAXIMUM_PRIORITY); | 2244 req->SetPriority(MAXIMUM_PRIORITY); |
2241 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2245 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
2242 | 2246 |
2243 req->Start(); | 2247 req->Start(); |
2244 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2248 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
2245 EXPECT_EQ(MAXIMUM_PRIORITY, job_priority); | 2249 EXPECT_EQ(MAXIMUM_PRIORITY, job_priority); |
(...skipping 4523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6769 http_test_server()->GetURL("/original#should-not-be-appended")); | 6773 http_test_server()->GetURL("/original#should-not-be-appended")); |
6770 GURL redirect_url(http_test_server()->GetURL("/echo")); | 6774 GURL redirect_url(http_test_server()->GetURL("/echo")); |
6771 | 6775 |
6772 TestDelegate d; | 6776 TestDelegate d; |
6773 std::unique_ptr<URLRequest> r( | 6777 std::unique_ptr<URLRequest> r( |
6774 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 6778 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); |
6775 | 6779 |
6776 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 6780 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
6777 r.get(), &default_network_delegate_, redirect_url, | 6781 r.get(), &default_network_delegate_, redirect_url, |
6778 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); | 6782 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); |
6779 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 6783 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
6780 | 6784 |
6781 r->Start(); | 6785 r->Start(); |
6782 base::RunLoop().Run(); | 6786 base::RunLoop().Run(); |
6783 | 6787 |
6784 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); | 6788 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
6785 EXPECT_EQ(OK, r->status().error()); | 6789 EXPECT_EQ(OK, r->status().error()); |
6786 EXPECT_EQ(original_url, r->original_url()); | 6790 EXPECT_EQ(original_url, r->original_url()); |
6787 EXPECT_EQ(redirect_url, r->url()); | 6791 EXPECT_EQ(redirect_url, r->url()); |
6788 } | 6792 } |
6789 | 6793 |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7511 req->set_upload(CreateSimpleUploadData(kData)); | 7515 req->set_upload(CreateSimpleUploadData(kData)); |
7512 HttpRequestHeaders headers; | 7516 HttpRequestHeaders headers; |
7513 headers.SetHeader(HttpRequestHeaders::kContentLength, | 7517 headers.SetHeader(HttpRequestHeaders::kContentLength, |
7514 base::SizeTToString(arraysize(kData) - 1)); | 7518 base::SizeTToString(arraysize(kData) - 1)); |
7515 req->SetExtraRequestHeaders(headers); | 7519 req->SetExtraRequestHeaders(headers); |
7516 | 7520 |
7517 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 7521 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
7518 req.get(), &default_network_delegate_, | 7522 req.get(), &default_network_delegate_, |
7519 http_test_server()->GetURL("/echo"), | 7523 http_test_server()->GetURL("/echo"), |
7520 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); | 7524 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); |
7521 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 7525 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
7522 | 7526 |
7523 req->Start(); | 7527 req->Start(); |
7524 base::RunLoop().Run(); | 7528 base::RunLoop().Run(); |
7525 EXPECT_EQ("GET", req->method()); | 7529 EXPECT_EQ("GET", req->method()); |
7526 } | 7530 } |
7527 | 7531 |
7528 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 7532 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
7529 ASSERT_TRUE(http_test_server()->Start()); | 7533 ASSERT_TRUE(http_test_server()->Start()); |
7530 | 7534 |
7531 const char kData[] = "hello world"; | 7535 const char kData[] = "hello world"; |
7532 | 7536 |
7533 TestDelegate d; | 7537 TestDelegate d; |
7534 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7538 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
7535 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 7539 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
7536 req->set_method("POST"); | 7540 req->set_method("POST"); |
7537 req->set_upload(CreateSimpleUploadData(kData)); | 7541 req->set_upload(CreateSimpleUploadData(kData)); |
7538 HttpRequestHeaders headers; | 7542 HttpRequestHeaders headers; |
7539 headers.SetHeader(HttpRequestHeaders::kContentLength, | 7543 headers.SetHeader(HttpRequestHeaders::kContentLength, |
7540 base::SizeTToString(arraysize(kData) - 1)); | 7544 base::SizeTToString(arraysize(kData) - 1)); |
7541 req->SetExtraRequestHeaders(headers); | 7545 req->SetExtraRequestHeaders(headers); |
7542 | 7546 |
7543 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 7547 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
7544 req.get(), &default_network_delegate_, | 7548 req.get(), &default_network_delegate_, |
7545 http_test_server()->GetURL("/echo"), | 7549 http_test_server()->GetURL("/echo"), |
7546 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, | 7550 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, |
7547 "Very Good Reason")); | 7551 "Very Good Reason")); |
7548 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 7552 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
7549 | 7553 |
7550 req->Start(); | 7554 req->Start(); |
7551 base::RunLoop().Run(); | 7555 base::RunLoop().Run(); |
7552 EXPECT_EQ("POST", req->method()); | 7556 EXPECT_EQ("POST", req->method()); |
7553 EXPECT_EQ(kData, d.data_received()); | 7557 EXPECT_EQ(kData, d.data_received()); |
7554 } | 7558 } |
7555 | 7559 |
7556 // Check that default A-L header is sent. | 7560 // Check that default A-L header is sent. |
7557 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 7561 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
7558 ASSERT_TRUE(http_test_server()->Start()); | 7562 ASSERT_TRUE(http_test_server()->Start()); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7738 | 7742 |
7739 TestDelegate d; | 7743 TestDelegate d; |
7740 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7744 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
7741 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 7745 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); |
7742 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); | 7746 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
7743 | 7747 |
7744 std::unique_ptr<URLRequestRedirectJob> redirect_job(new URLRequestRedirectJob( | 7748 std::unique_ptr<URLRequestRedirectJob> redirect_job(new URLRequestRedirectJob( |
7745 req.get(), &default_network_delegate_, | 7749 req.get(), &default_network_delegate_, |
7746 http_test_server()->GetURL("/echo"), | 7750 http_test_server()->GetURL("/echo"), |
7747 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); | 7751 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); |
7748 AddTestInterceptor()->set_main_intercept_job(std::move(redirect_job)); | 7752 test_job_interceptor_->set_main_intercept_job(std::move(redirect_job)); |
7749 | 7753 |
7750 req->SetPriority(LOW); | 7754 req->SetPriority(LOW); |
7751 req->Start(); | 7755 req->Start(); |
7752 EXPECT_TRUE(req->is_pending()); | 7756 EXPECT_TRUE(req->is_pending()); |
7753 | 7757 |
7754 RequestPriority job_priority; | 7758 RequestPriority job_priority; |
7755 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 7759 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
7756 req.get(), &default_network_delegate_, &job_priority)); | 7760 req.get(), &default_network_delegate_, &job_priority)); |
7757 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 7761 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
7758 | 7762 |
7759 // Should trigger |job| to be started. | 7763 // Should trigger |job| to be started. |
7760 base::RunLoop().Run(); | 7764 base::RunLoop().Run(); |
7761 EXPECT_EQ(LOW, job_priority); | 7765 EXPECT_EQ(LOW, job_priority); |
7762 } | 7766 } |
7763 | 7767 |
7764 // Check that creating a network request while entering/exiting suspend mode | 7768 // Check that creating a network request while entering/exiting suspend mode |
7765 // fails as it should. This is the only case where an HttpTransactionFactory | 7769 // fails as it should. This is the only case where an HttpTransactionFactory |
7766 // does not return an HttpTransaction. | 7770 // does not return an HttpTransaction. |
7767 TEST_F(URLRequestTestHTTP, NetworkSuspendTest) { | 7771 TEST_F(URLRequestTestHTTP, NetworkSuspendTest) { |
(...skipping 2336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10104 // See http://crbug.com/508900 | 10108 // See http://crbug.com/508900 |
10105 TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) { | 10109 TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) { |
10106 TestDelegate d; | 10110 TestDelegate d; |
10107 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 10111 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
10108 GURL("http://not-a-real-domain/"), DEFAULT_PRIORITY, &d)); | 10112 GURL("http://not-a-real-domain/"), DEFAULT_PRIORITY, &d)); |
10109 | 10113 |
10110 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 10114 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
10111 req.get(), &default_network_delegate_, | 10115 req.get(), &default_network_delegate_, |
10112 GURL("http://this-should-never-be-navigated-to/"), | 10116 GURL("http://this-should-never-be-navigated-to/"), |
10113 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp")); | 10117 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp")); |
10114 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10118 test_job_interceptor_->set_main_intercept_job(std::move(job)); |
10115 | 10119 |
10116 req->Start(); | 10120 req->Start(); |
10117 req->Cancel(); | 10121 req->Cancel(); |
10118 base::RunLoop().RunUntilIdle(); | 10122 base::RunLoop().RunUntilIdle(); |
10119 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 10123 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
10120 EXPECT_EQ(0, d.received_redirect_count()); | 10124 EXPECT_EQ(0, d.received_redirect_count()); |
10121 } | 10125 } |
10122 | 10126 |
10123 } // namespace net | 10127 } // namespace net |
OLD | NEW |