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

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

Issue 2079783002: Move HSTS redirection from URLRequest to URLRequestHTTPJob. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: iOS Created 4 years, 6 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
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 "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 8635 matching lines...) Expand 10 before | Expand all | Expand 10 after
8646 std::string redirect_location; 8646 std::string redirect_location;
8647 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Location", &redirect_location)); 8647 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Location", &redirect_location));
8648 EXPECT_EQ(hsts_https_url.spec(), redirect_location); 8648 EXPECT_EQ(hsts_https_url.spec(), redirect_location);
8649 8649
8650 std::string received_cors_header; 8650 std::string received_cors_header;
8651 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Access-Control-Allow-Origin", 8651 EXPECT_TRUE(headers->EnumerateHeader(NULL, "Access-Control-Allow-Origin",
8652 &received_cors_header)); 8652 &received_cors_header));
8653 EXPECT_EQ(kOriginHeaderValue, received_cors_header); 8653 EXPECT_EQ(kOriginHeaderValue, received_cors_header);
8654 } 8654 }
8655 8655
8656 // This just tests the behaviour of GetHSTSRedirect(). End-to-end tests of HSTS
8657 // are performed in net/websockets/websocket_end_to_end_test.cc.
8658 TEST(WebSocketURLRequestTest, HSTSApplied) {
8659 TestNetworkDelegate network_delegate;
8660 TransportSecurityState transport_security_state;
8661 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1);
8662 bool include_subdomains = false;
8663 transport_security_state.AddHSTS("example.net", expiry, include_subdomains);
8664 TestURLRequestContext context(true);
8665 context.set_transport_security_state(&transport_security_state);
8666 context.set_network_delegate(&network_delegate);
8667 context.Init();
8668 GURL ws_url("ws://example.net/echo");
8669 TestDelegate delegate;
8670 std::unique_ptr<URLRequest> request(
8671 context.CreateRequest(ws_url, DEFAULT_PRIORITY, &delegate));
8672 EXPECT_TRUE(request->GetHSTSRedirect(&ws_url));
8673 EXPECT_TRUE(ws_url.SchemeIs("wss"));
8674 }
8675
8676 namespace { 8656 namespace {
8677 8657
8678 class SSLClientAuthTestDelegate : public TestDelegate { 8658 class SSLClientAuthTestDelegate : public TestDelegate {
8679 public: 8659 public:
8680 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { 8660 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) {
8681 } 8661 }
8682 void OnCertificateRequested(URLRequest* request, 8662 void OnCertificateRequested(URLRequest* request,
8683 SSLCertRequestInfo* cert_request_info) override { 8663 SSLCertRequestInfo* cert_request_info) override {
8684 on_certificate_requested_count_++; 8664 on_certificate_requested_count_++;
8685 base::MessageLoop::current()->QuitWhenIdle(); 8665 base::MessageLoop::current()->QuitWhenIdle();
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
10141 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10121 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10142 10122
10143 req->Start(); 10123 req->Start();
10144 req->Cancel(); 10124 req->Cancel();
10145 base::RunLoop().RunUntilIdle(); 10125 base::RunLoop().RunUntilIdle();
10146 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10126 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
10147 EXPECT_EQ(0, d.received_redirect_count()); 10127 EXPECT_EQ(0, d.received_redirect_count());
10148 } 10128 }
10149 10129
10150 } // namespace net 10130 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698