| 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 8611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8622 std::string redirect_location; | 8622 std::string redirect_location; |
| 8623 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Location", &redirect_location)); | 8623 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Location", &redirect_location)); |
| 8624 EXPECT_EQ(hsts_https_url.spec(), redirect_location); | 8624 EXPECT_EQ(hsts_https_url.spec(), redirect_location); |
| 8625 | 8625 |
| 8626 std::string received_cors_header; | 8626 std::string received_cors_header; |
| 8627 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Access-Control-Allow-Origin", | 8627 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Access-Control-Allow-Origin", |
| 8628 &received_cors_header)); | 8628 &received_cors_header)); |
| 8629 EXPECT_EQ(kOriginHeaderValue, received_cors_header); | 8629 EXPECT_EQ(kOriginHeaderValue, received_cors_header); |
| 8630 } | 8630 } |
| 8631 | 8631 |
| 8632 // This just tests the behaviour of GetHSTSRedirect(). End-to-end tests of HSTS | |
| 8633 // are performed in net/websockets/websocket_end_to_end_test.cc. | |
| 8634 TEST(WebSocketURLRequestTest, HSTSApplied) { | |
| 8635 TestNetworkDelegate network_delegate; | |
| 8636 TransportSecurityState transport_security_state; | |
| 8637 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 8638 bool include_subdomains = false; | |
| 8639 transport_security_state.AddHSTS("example.net", expiry, include_subdomains); | |
| 8640 TestURLRequestContext context(true); | |
| 8641 context.set_transport_security_state(&transport_security_state); | |
| 8642 context.set_network_delegate(&network_delegate); | |
| 8643 context.Init(); | |
| 8644 GURL ws_url("ws://example.net/echo"); | |
| 8645 TestDelegate delegate; | |
| 8646 std::unique_ptr<URLRequest> request( | |
| 8647 context.CreateRequest(ws_url, DEFAULT_PRIORITY, &delegate)); | |
| 8648 EXPECT_TRUE(request->GetHSTSRedirect(&ws_url)); | |
| 8649 EXPECT_TRUE(ws_url.SchemeIs("wss")); | |
| 8650 } | |
| 8651 | |
| 8652 namespace { | 8632 namespace { |
| 8653 | 8633 |
| 8654 class SSLClientAuthTestDelegate : public TestDelegate { | 8634 class SSLClientAuthTestDelegate : public TestDelegate { |
| 8655 public: | 8635 public: |
| 8656 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { | 8636 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { |
| 8657 } | 8637 } |
| 8658 void OnCertificateRequested(URLRequest* request, | 8638 void OnCertificateRequested(URLRequest* request, |
| 8659 SSLCertRequestInfo* cert_request_info) override { | 8639 SSLCertRequestInfo* cert_request_info) override { |
| 8660 on_certificate_requested_count_++; | 8640 on_certificate_requested_count_++; |
| 8661 base::MessageLoop::current()->QuitWhenIdle(); | 8641 base::MessageLoop::current()->QuitWhenIdle(); |
| (...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10104 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10084 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 10105 | 10085 |
| 10106 req->Start(); | 10086 req->Start(); |
| 10107 req->Cancel(); | 10087 req->Cancel(); |
| 10108 base::RunLoop().RunUntilIdle(); | 10088 base::RunLoop().RunUntilIdle(); |
| 10109 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); | 10089 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); |
| 10110 EXPECT_EQ(0, d.received_redirect_count()); | 10090 EXPECT_EQ(0, d.received_redirect_count()); |
| 10111 } | 10091 } |
| 10112 | 10092 |
| 10113 } // namespace net | 10093 } // namespace net |
| OLD | NEW |