| 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 "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "base/power_monitor/power_monitor_source.h" | 37 #include "base/power_monitor/power_monitor_source.h" |
| 38 #include "base/run_loop.h" | 38 #include "base/run_loop.h" |
| 39 #include "base/single_thread_task_runner.h" | 39 #include "base/single_thread_task_runner.h" |
| 40 #include "base/strings/string_number_conversions.h" | 40 #include "base/strings/string_number_conversions.h" |
| 41 #include "base/strings/string_piece.h" | 41 #include "base/strings/string_piece.h" |
| 42 #include "base/strings/string_split.h" | 42 #include "base/strings/string_split.h" |
| 43 #include "base/strings/string_util.h" | 43 #include "base/strings/string_util.h" |
| 44 #include "base/strings/stringprintf.h" | 44 #include "base/strings/stringprintf.h" |
| 45 #include "base/strings/utf_string_conversions.h" | 45 #include "base/strings/utf_string_conversions.h" |
| 46 #include "base/test/histogram_tester.h" | 46 #include "base/test/histogram_tester.h" |
| 47 #include "base/test/scoped_task_scheduler.h" | |
| 48 #include "base/threading/thread_task_runner_handle.h" | 47 #include "base/threading/thread_task_runner_handle.h" |
| 49 #include "base/values.h" | 48 #include "base/values.h" |
| 50 #include "net/base/chunked_upload_data_stream.h" | 49 #include "net/base/chunked_upload_data_stream.h" |
| 51 #include "net/base/directory_listing.h" | 50 #include "net/base/directory_listing.h" |
| 52 #include "net/base/elements_upload_data_stream.h" | 51 #include "net/base/elements_upload_data_stream.h" |
| 53 #include "net/base/load_flags.h" | 52 #include "net/base/load_flags.h" |
| 54 #include "net/base/load_timing_info.h" | 53 #include "net/base/load_timing_info.h" |
| 55 #include "net/base/load_timing_info_test_util.h" | 54 #include "net/base/load_timing_info_test_util.h" |
| 56 #include "net/base/net_errors.h" | 55 #include "net/base/net_errors.h" |
| 57 #include "net/base/net_module.h" | 56 #include "net/base/net_module.h" |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 private: | 772 private: |
| 774 bool on_ssl_certificate_error_called_ = false; | 773 bool on_ssl_certificate_error_called_ = false; |
| 775 SSLInfo ssl_info_; | 774 SSLInfo ssl_info_; |
| 776 }; | 775 }; |
| 777 | 776 |
| 778 } // namespace | 777 } // namespace |
| 779 | 778 |
| 780 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. | 779 // Inherit PlatformTest since we require the autorelease pool on Mac OS X. |
| 781 class URLRequestTest : public PlatformTest { | 780 class URLRequestTest : public PlatformTest { |
| 782 public: | 781 public: |
| 783 URLRequestTest() | 782 URLRequestTest() : default_context_(true) { |
| 784 : scoped_task_scheduler_(base::MessageLoop::current()), | |
| 785 default_context_(true) { | |
| 786 default_context_.set_network_delegate(&default_network_delegate_); | 783 default_context_.set_network_delegate(&default_network_delegate_); |
| 787 default_context_.set_net_log(&net_log_); | 784 default_context_.set_net_log(&net_log_); |
| 788 job_factory_impl_ = new URLRequestJobFactoryImpl(); | 785 job_factory_impl_ = new URLRequestJobFactoryImpl(); |
| 789 job_factory_.reset(job_factory_impl_); | 786 job_factory_.reset(job_factory_impl_); |
| 790 } | 787 } |
| 791 | 788 |
| 792 ~URLRequestTest() override { | 789 ~URLRequestTest() override { |
| 793 // URLRequestJobs may post clean-up tasks on destruction. | 790 // URLRequestJobs may post clean-up tasks on destruction. |
| 794 base::RunLoop().RunUntilIdle(); | 791 base::RunLoop().RunUntilIdle(); |
| 795 } | 792 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 822 | 819 |
| 823 // Adds the TestJobInterceptor to the default context. | 820 // Adds the TestJobInterceptor to the default context. |
| 824 TestJobInterceptor* AddTestInterceptor() { | 821 TestJobInterceptor* AddTestInterceptor() { |
| 825 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 822 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
| 826 job_factory_impl_->SetProtocolHandler("http", nullptr); | 823 job_factory_impl_->SetProtocolHandler("http", nullptr); |
| 827 job_factory_impl_->SetProtocolHandler("http", | 824 job_factory_impl_->SetProtocolHandler("http", |
| 828 base::WrapUnique(protocol_handler_)); | 825 base::WrapUnique(protocol_handler_)); |
| 829 return protocol_handler_; | 826 return protocol_handler_; |
| 830 } | 827 } |
| 831 | 828 |
| 832 private: | |
| 833 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
| 834 | |
| 835 protected: | 829 protected: |
| 836 TestNetLog net_log_; | 830 TestNetLog net_log_; |
| 837 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 831 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 838 URLRequestJobFactoryImpl* job_factory_impl_; | 832 URLRequestJobFactoryImpl* job_factory_impl_; |
| 839 std::unique_ptr<URLRequestJobFactory> job_factory_; | 833 std::unique_ptr<URLRequestJobFactory> job_factory_; |
| 840 TestURLRequestContext default_context_; | 834 TestURLRequestContext default_context_; |
| 841 }; | 835 }; |
| 842 | 836 |
| 843 TEST_F(URLRequestTest, AboutBlankTest) { | 837 TEST_F(URLRequestTest, AboutBlankTest) { |
| 844 TestDelegate d; | 838 TestDelegate d; |
| (...skipping 7958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8803 origin_server()->GetURL("/path/to/file.html"), | 8797 origin_server()->GetURL("/path/to/file.html"), |
| 8804 origin_server()->GetURL("/")); | 8798 origin_server()->GetURL("/")); |
| 8805 | 8799 |
| 8806 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, | 8800 VerifyReferrerAfterRedirect(URLRequest::NEVER_CLEAR_REFERRER, |
| 8807 origin_server()->GetURL("/path/to/file.html"), | 8801 origin_server()->GetURL("/path/to/file.html"), |
| 8808 origin_server()->GetURL("/path/to/file.html")); | 8802 origin_server()->GetURL("/path/to/file.html")); |
| 8809 } | 8803 } |
| 8810 | 8804 |
| 8811 class HTTPSRequestTest : public testing::Test { | 8805 class HTTPSRequestTest : public testing::Test { |
| 8812 public: | 8806 public: |
| 8813 HTTPSRequestTest() | 8807 HTTPSRequestTest() : default_context_(true) { |
| 8814 : scoped_task_scheduler_(base::MessageLoop::current()), | |
| 8815 default_context_(true) { | |
| 8816 default_context_.set_network_delegate(&default_network_delegate_); | 8808 default_context_.set_network_delegate(&default_network_delegate_); |
| 8817 default_context_.Init(); | 8809 default_context_.Init(); |
| 8818 } | 8810 } |
| 8819 ~HTTPSRequestTest() override {} | 8811 ~HTTPSRequestTest() override {} |
| 8820 | 8812 |
| 8821 protected: | 8813 protected: |
| 8822 // Required by ChannelIDService. | |
| 8823 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
| 8824 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 8814 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 8825 TestURLRequestContext default_context_; | 8815 TestURLRequestContext default_context_; |
| 8826 }; | 8816 }; |
| 8827 | 8817 |
| 8828 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 8818 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 8829 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 8819 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 8830 test_server.AddDefaultHandlers( | 8820 test_server.AddDefaultHandlers( |
| 8831 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8821 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 8832 ASSERT_TRUE(test_server.Start()); | 8822 ASSERT_TRUE(test_server.Start()); |
| 8833 | 8823 |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9382 // With a newline at the end which makes the split think that there are | 9372 // With a newline at the end which makes the split think that there are |
| 9383 // three lines. | 9373 // three lines. |
| 9384 | 9374 |
| 9385 EXPECT_EQ(1, d.response_started_count()); | 9375 EXPECT_EQ(1, d.response_started_count()); |
| 9386 AssertTwoDistinctSessionsInserted(d.data_received()); | 9376 AssertTwoDistinctSessionsInserted(d.data_received()); |
| 9387 } | 9377 } |
| 9388 } | 9378 } |
| 9389 | 9379 |
| 9390 class HTTPSFallbackTest : public testing::Test { | 9380 class HTTPSFallbackTest : public testing::Test { |
| 9391 public: | 9381 public: |
| 9392 HTTPSFallbackTest() | 9382 HTTPSFallbackTest() : context_(true) { |
| 9393 : scoped_task_scheduler_(base::MessageLoop::current()), context_(true) { | |
| 9394 ssl_config_service_ = new TestSSLConfigService( | 9383 ssl_config_service_ = new TestSSLConfigService( |
| 9395 true /* check for EV */, false /* online revocation checking */, | 9384 true /* check for EV */, false /* online revocation checking */, |
| 9396 false /* require rev. checking for local anchors */, | 9385 false /* require rev. checking for local anchors */, |
| 9397 false /* token binding enabled */); | 9386 false /* token binding enabled */); |
| 9398 context_.set_ssl_config_service(ssl_config_service_.get()); | 9387 context_.set_ssl_config_service(ssl_config_service_.get()); |
| 9399 } | 9388 } |
| 9400 ~HTTPSFallbackTest() override {} | 9389 ~HTTPSFallbackTest() override {} |
| 9401 | 9390 |
| 9402 protected: | 9391 protected: |
| 9403 TestSSLConfigService* ssl_config_service() { | 9392 TestSSLConfigService* ssl_config_service() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 9428 EXPECT_EQ(version, SSLConnectionStatusToVersion( | 9417 EXPECT_EQ(version, SSLConnectionStatusToVersion( |
| 9429 request_->ssl_info().connection_status)); | 9418 request_->ssl_info().connection_status)); |
| 9430 } | 9419 } |
| 9431 | 9420 |
| 9432 void ExpectFailure(int error) { | 9421 void ExpectFailure(int error) { |
| 9433 EXPECT_EQ(1, delegate_.response_started_count()); | 9422 EXPECT_EQ(1, delegate_.response_started_count()); |
| 9434 EXPECT_EQ(error, delegate_.request_status()); | 9423 EXPECT_EQ(error, delegate_.request_status()); |
| 9435 } | 9424 } |
| 9436 | 9425 |
| 9437 private: | 9426 private: |
| 9438 // Required by ChannelIDService. | |
| 9439 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
| 9440 TestDelegate delegate_; | 9427 TestDelegate delegate_; |
| 9441 TestURLRequestContext context_; | 9428 TestURLRequestContext context_; |
| 9442 std::unique_ptr<URLRequest> request_; | 9429 std::unique_ptr<URLRequest> request_; |
| 9443 scoped_refptr<TestSSLConfigService> ssl_config_service_; | 9430 scoped_refptr<TestSSLConfigService> ssl_config_service_; |
| 9444 }; | 9431 }; |
| 9445 | 9432 |
| 9446 // Tests the TLS 1.0 fallback doesn't happen. | 9433 // Tests the TLS 1.0 fallback doesn't happen. |
| 9447 TEST_F(HTTPSFallbackTest, TLSv1NoFallback) { | 9434 TEST_F(HTTPSFallbackTest, TLSv1NoFallback) { |
| 9448 SpawnedTestServer::SSLOptions ssl_options( | 9435 SpawnedTestServer::SSLOptions ssl_options( |
| 9449 SpawnedTestServer::SSLOptions::CERT_OK); | 9436 SpawnedTestServer::SSLOptions::CERT_OK); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9484 ssl_options.tls_intolerant = | 9471 ssl_options.tls_intolerant = |
| 9485 SpawnedTestServer::SSLOptions::TLS_INTOLERANT_TLS1_3; | 9472 SpawnedTestServer::SSLOptions::TLS_INTOLERANT_TLS1_3; |
| 9486 ssl_config_service()->set_max_version(SSL_PROTOCOL_VERSION_TLS1_2); | 9473 ssl_config_service()->set_max_version(SSL_PROTOCOL_VERSION_TLS1_2); |
| 9487 | 9474 |
| 9488 ASSERT_NO_FATAL_FAILURE(DoFallbackTest(ssl_options)); | 9475 ASSERT_NO_FATAL_FAILURE(DoFallbackTest(ssl_options)); |
| 9489 ExpectConnection(SSL_CONNECTION_VERSION_TLS1_2); | 9476 ExpectConnection(SSL_CONNECTION_VERSION_TLS1_2); |
| 9490 } | 9477 } |
| 9491 | 9478 |
| 9492 class HTTPSSessionTest : public testing::Test { | 9479 class HTTPSSessionTest : public testing::Test { |
| 9493 public: | 9480 public: |
| 9494 HTTPSSessionTest() | 9481 HTTPSSessionTest() : default_context_(true) { |
| 9495 : scoped_task_scheduler_(base::MessageLoop::current()), | |
| 9496 default_context_(true) { | |
| 9497 cert_verifier_.set_default_result(OK); | 9482 cert_verifier_.set_default_result(OK); |
| 9498 | 9483 |
| 9499 default_context_.set_network_delegate(&default_network_delegate_); | 9484 default_context_.set_network_delegate(&default_network_delegate_); |
| 9500 default_context_.set_cert_verifier(&cert_verifier_); | 9485 default_context_.set_cert_verifier(&cert_verifier_); |
| 9501 default_context_.Init(); | 9486 default_context_.Init(); |
| 9502 } | 9487 } |
| 9503 ~HTTPSSessionTest() override {} | 9488 ~HTTPSSessionTest() override {} |
| 9504 | 9489 |
| 9505 protected: | 9490 protected: |
| 9506 // Required by ChannelIDService. | |
| 9507 base::test::ScopedTaskScheduler scoped_task_scheduler_; | |
| 9508 MockCertVerifier cert_verifier_; | 9491 MockCertVerifier cert_verifier_; |
| 9509 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 9492 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 9510 TestURLRequestContext default_context_; | 9493 TestURLRequestContext default_context_; |
| 9511 }; | 9494 }; |
| 9512 | 9495 |
| 9513 // Tests that session resumption is not attempted if an invalid certificate | 9496 // Tests that session resumption is not attempted if an invalid certificate |
| 9514 // is presented. | 9497 // is presented. |
| 9515 TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) { | 9498 TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) { |
| 9516 SpawnedTestServer::SSLOptions ssl_options; | 9499 SpawnedTestServer::SSLOptions ssl_options; |
| 9517 ssl_options.record_resume = true; | 9500 ssl_options.record_resume = true; |
| (...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11075 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 11058 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 11076 | 11059 |
| 11077 req->Start(); | 11060 req->Start(); |
| 11078 req->Cancel(); | 11061 req->Cancel(); |
| 11079 base::RunLoop().RunUntilIdle(); | 11062 base::RunLoop().RunUntilIdle(); |
| 11080 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 11063 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 11081 EXPECT_EQ(0, d.received_redirect_count()); | 11064 EXPECT_EQ(0, d.received_redirect_count()); |
| 11082 } | 11065 } |
| 11083 | 11066 |
| 11084 } // namespace net | 11067 } // namespace net |
| OLD | NEW |