| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 default_context_.set_network_delegate(&default_network_delegate_); | 608 default_context_.set_network_delegate(&default_network_delegate_); |
| 609 default_context_.set_net_log(&net_log_); | 609 default_context_.set_net_log(&net_log_); |
| 610 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); | 610 job_factory_.SetProtocolHandler("data", new DataProtocolHandler); |
| 611 #if !defined(DISABLE_FILE_SUPPORT) | 611 #if !defined(DISABLE_FILE_SUPPORT) |
| 612 job_factory_.SetProtocolHandler( | 612 job_factory_.SetProtocolHandler( |
| 613 "file", new FileProtocolHandler(base::MessageLoopProxy::current())); | 613 "file", new FileProtocolHandler(base::MessageLoopProxy::current())); |
| 614 #endif | 614 #endif |
| 615 default_context_.set_job_factory(&job_factory_); | 615 default_context_.set_job_factory(&job_factory_); |
| 616 default_context_.Init(); | 616 default_context_.Init(); |
| 617 } | 617 } |
| 618 virtual ~URLRequestTest() { | 618 ~URLRequestTest() override { |
| 619 // URLRequestJobs may post clean-up tasks on destruction. | 619 // URLRequestJobs may post clean-up tasks on destruction. |
| 620 base::RunLoop().RunUntilIdle(); | 620 base::RunLoop().RunUntilIdle(); |
| 621 } | 621 } |
| 622 | 622 |
| 623 // Adds the TestJobInterceptor to the default context. | 623 // Adds the TestJobInterceptor to the default context. |
| 624 TestJobInterceptor* AddTestInterceptor() { | 624 TestJobInterceptor* AddTestInterceptor() { |
| 625 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); | 625 TestJobInterceptor* protocol_handler_ = new TestJobInterceptor(); |
| 626 job_factory_.SetProtocolHandler("http", NULL); | 626 job_factory_.SetProtocolHandler("http", NULL); |
| 627 job_factory_.SetProtocolHandler("http", protocol_handler_); | 627 job_factory_.SetProtocolHandler("http", protocol_handler_); |
| 628 return protocol_handler_; | 628 return protocol_handler_; |
| (...skipping 5816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6445 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); | 6445 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); |
| 6446 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); | 6446 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); |
| 6447 } | 6447 } |
| 6448 | 6448 |
| 6449 class HTTPSRequestTest : public testing::Test { | 6449 class HTTPSRequestTest : public testing::Test { |
| 6450 public: | 6450 public: |
| 6451 HTTPSRequestTest() : default_context_(true) { | 6451 HTTPSRequestTest() : default_context_(true) { |
| 6452 default_context_.set_network_delegate(&default_network_delegate_); | 6452 default_context_.set_network_delegate(&default_network_delegate_); |
| 6453 default_context_.Init(); | 6453 default_context_.Init(); |
| 6454 } | 6454 } |
| 6455 virtual ~HTTPSRequestTest() {} | 6455 ~HTTPSRequestTest() override {} |
| 6456 | 6456 |
| 6457 protected: | 6457 protected: |
| 6458 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 6458 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 6459 TestURLRequestContext default_context_; | 6459 TestURLRequestContext default_context_; |
| 6460 }; | 6460 }; |
| 6461 | 6461 |
| 6462 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 6462 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 6463 SpawnedTestServer test_server( | 6463 SpawnedTestServer test_server( |
| 6464 SpawnedTestServer::TYPE_HTTPS, | 6464 SpawnedTestServer::TYPE_HTTPS, |
| 6465 SpawnedTestServer::kLocalhost, | 6465 SpawnedTestServer::kLocalhost, |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7118 false /* require rev. checking for local | 7118 false /* require rev. checking for local |
| 7119 anchors */); | 7119 anchors */); |
| 7120 ssl_config_service->set_fallback_min_version(version); | 7120 ssl_config_service->set_fallback_min_version(version); |
| 7121 set_ssl_config_service(ssl_config_service); | 7121 set_ssl_config_service(ssl_config_service); |
| 7122 } | 7122 } |
| 7123 }; | 7123 }; |
| 7124 | 7124 |
| 7125 class HTTPSFallbackTest : public testing::Test { | 7125 class HTTPSFallbackTest : public testing::Test { |
| 7126 public: | 7126 public: |
| 7127 HTTPSFallbackTest() : context_(true) {} | 7127 HTTPSFallbackTest() : context_(true) {} |
| 7128 virtual ~HTTPSFallbackTest() {} | 7128 ~HTTPSFallbackTest() override {} |
| 7129 | 7129 |
| 7130 protected: | 7130 protected: |
| 7131 void DoFallbackTest(const SpawnedTestServer::SSLOptions& ssl_options) { | 7131 void DoFallbackTest(const SpawnedTestServer::SSLOptions& ssl_options) { |
| 7132 DCHECK(!request_); | 7132 DCHECK(!request_); |
| 7133 context_.Init(); | 7133 context_.Init(); |
| 7134 delegate_.set_allow_certificate_errors(true); | 7134 delegate_.set_allow_certificate_errors(true); |
| 7135 | 7135 |
| 7136 SpawnedTestServer test_server( | 7136 SpawnedTestServer test_server( |
| 7137 SpawnedTestServer::TYPE_HTTPS, | 7137 SpawnedTestServer::TYPE_HTTPS, |
| 7138 ssl_options, | 7138 ssl_options, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7370 | 7370 |
| 7371 class HTTPSSessionTest : public testing::Test { | 7371 class HTTPSSessionTest : public testing::Test { |
| 7372 public: | 7372 public: |
| 7373 HTTPSSessionTest() : default_context_(true) { | 7373 HTTPSSessionTest() : default_context_(true) { |
| 7374 cert_verifier_.set_default_result(OK); | 7374 cert_verifier_.set_default_result(OK); |
| 7375 | 7375 |
| 7376 default_context_.set_network_delegate(&default_network_delegate_); | 7376 default_context_.set_network_delegate(&default_network_delegate_); |
| 7377 default_context_.set_cert_verifier(&cert_verifier_); | 7377 default_context_.set_cert_verifier(&cert_verifier_); |
| 7378 default_context_.Init(); | 7378 default_context_.Init(); |
| 7379 } | 7379 } |
| 7380 virtual ~HTTPSSessionTest() {} | 7380 ~HTTPSSessionTest() override {} |
| 7381 | 7381 |
| 7382 protected: | 7382 protected: |
| 7383 MockCertVerifier cert_verifier_; | 7383 MockCertVerifier cert_verifier_; |
| 7384 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 7384 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 7385 TestURLRequestContext default_context_; | 7385 TestURLRequestContext default_context_; |
| 7386 }; | 7386 }; |
| 7387 | 7387 |
| 7388 // Tests that session resumption is not attempted if an invalid certificate | 7388 // Tests that session resumption is not attempted if an invalid certificate |
| 7389 // is presented. | 7389 // is presented. |
| 7390 TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) { | 7390 TEST_F(HTTPSSessionTest, DontResumeSessionsForInvalidCertificates) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7469 class HTTPSOCSPTest : public HTTPSRequestTest { | 7469 class HTTPSOCSPTest : public HTTPSRequestTest { |
| 7470 public: | 7470 public: |
| 7471 HTTPSOCSPTest() | 7471 HTTPSOCSPTest() |
| 7472 : context_(true), | 7472 : context_(true), |
| 7473 ev_test_policy_( | 7473 ev_test_policy_( |
| 7474 new ScopedTestEVPolicy(EVRootCAMetadata::GetInstance(), | 7474 new ScopedTestEVPolicy(EVRootCAMetadata::GetInstance(), |
| 7475 kOCSPTestCertFingerprint, | 7475 kOCSPTestCertFingerprint, |
| 7476 kOCSPTestCertPolicy)) { | 7476 kOCSPTestCertPolicy)) { |
| 7477 } | 7477 } |
| 7478 | 7478 |
| 7479 virtual void SetUp() override { | 7479 void SetUp() override { |
| 7480 SetupContext(&context_); | 7480 SetupContext(&context_); |
| 7481 context_.Init(); | 7481 context_.Init(); |
| 7482 | 7482 |
| 7483 scoped_refptr<X509Certificate> root_cert = | 7483 scoped_refptr<X509Certificate> root_cert = |
| 7484 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); | 7484 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); |
| 7485 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); | 7485 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert.get()); |
| 7486 test_root_.reset(new ScopedTestRoot(root_cert.get())); | 7486 test_root_.reset(new ScopedTestRoot(root_cert.get())); |
| 7487 | 7487 |
| 7488 #if defined(USE_NSS) || defined(OS_IOS) | 7488 #if defined(USE_NSS) || defined(OS_IOS) |
| 7489 SetURLRequestContextForNSSHttpIO(&context_); | 7489 SetURLRequestContextForNSSHttpIO(&context_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 7506 scoped_ptr<URLRequest> r(context_.CreateRequest( | 7506 scoped_ptr<URLRequest> r(context_.CreateRequest( |
| 7507 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); | 7507 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); |
| 7508 r->Start(); | 7508 r->Start(); |
| 7509 | 7509 |
| 7510 base::RunLoop().Run(); | 7510 base::RunLoop().Run(); |
| 7511 | 7511 |
| 7512 EXPECT_EQ(1, d.response_started_count()); | 7512 EXPECT_EQ(1, d.response_started_count()); |
| 7513 *out_cert_status = r->ssl_info().cert_status; | 7513 *out_cert_status = r->ssl_info().cert_status; |
| 7514 } | 7514 } |
| 7515 | 7515 |
| 7516 virtual ~HTTPSOCSPTest() { | 7516 ~HTTPSOCSPTest() override { |
| 7517 #if defined(USE_NSS) || defined(OS_IOS) | 7517 #if defined(USE_NSS) || defined(OS_IOS) |
| 7518 ShutdownNSSHttpIO(); | 7518 ShutdownNSSHttpIO(); |
| 7519 #endif | 7519 #endif |
| 7520 } | 7520 } |
| 7521 | 7521 |
| 7522 protected: | 7522 protected: |
| 7523 // SetupContext configures the URLRequestContext that will be used for making | 7523 // SetupContext configures the URLRequestContext that will be used for making |
| 7524 // connetions to testserver. This can be overridden in test subclasses for | 7524 // connetions to testserver. This can be overridden in test subclasses for |
| 7525 // different behaviour. | 7525 // different behaviour. |
| 7526 virtual void SetupContext(URLRequestContext* context) { | 7526 virtual void SetupContext(URLRequestContext* context) { |
| (...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8276 | 8276 |
| 8277 EXPECT_FALSE(r->is_pending()); | 8277 EXPECT_FALSE(r->is_pending()); |
| 8278 EXPECT_EQ(1, d->response_started_count()); | 8278 EXPECT_EQ(1, d->response_started_count()); |
| 8279 EXPECT_FALSE(d->received_data_before_response()); | 8279 EXPECT_FALSE(d->received_data_before_response()); |
| 8280 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 8280 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8281 } | 8281 } |
| 8282 } | 8282 } |
| 8283 #endif // !defined(DISABLE_FTP_SUPPORT) | 8283 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 8284 | 8284 |
| 8285 } // namespace net | 8285 } // namespace net |
| OLD | NEW |