OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "net/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "net/base/auth.h" | 17 #include "net/base/auth.h" |
18 #include "net/base/request_priority.h" | 18 #include "net/base/request_priority.h" |
19 #include "net/base/sdch_observer.h" | 19 #include "net/base/sdch_observer.h" |
20 #include "net/base/test_data_directory.h" | 20 #include "net/base/test_data_directory.h" |
21 #include "net/cookies/cookie_store_test_helpers.h" | 21 #include "net/cookies/cookie_store_test_helpers.h" |
22 #include "net/http/http_transaction_factory.h" | 22 #include "net/http/http_transaction_factory.h" |
23 #include "net/http/http_transaction_test_util.h" | 23 #include "net/http/http_transaction_test_util.h" |
24 #include "net/log/test_net_log.h" | |
25 #include "net/log/test_net_log_entry.h" | |
26 #include "net/log/test_net_log_util.h" | |
24 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
25 #include "net/test/cert_test_util.h" | 28 #include "net/test/cert_test_util.h" |
26 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
27 #include "net/url_request/url_request_job_factory_impl.h" | 30 #include "net/url_request/url_request_job_factory_impl.h" |
28 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
29 #include "net/url_request/url_request_test_util.h" | 32 #include "net/url_request/url_request_test_util.h" |
30 #include "net/websockets/websocket_handshake_stream_base.h" | 33 #include "net/websockets/websocket_handshake_stream_base.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "url/gurl.h" | 36 #include "url/gurl.h" |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 // Confirm we don't advertise SDCH encoding in the case of a POST. | 621 // Confirm we don't advertise SDCH encoding in the case of a POST. |
619 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { | 622 TEST_F(URLRequestHttpJobTest, SdchAdvertisementPost) { |
620 EnableSdch(); | 623 EnableSdch(); |
621 req_->set_method("POST"); | 624 req_->set_method("POST"); |
622 test_job_interceptor_->set_main_intercept_job( | 625 test_job_interceptor_->set_main_intercept_job( |
623 base::WrapUnique(new TestURLRequestHttpJob(req_.get()))); | 626 base::WrapUnique(new TestURLRequestHttpJob(req_.get()))); |
624 req_->Start(); | 627 req_->Start(); |
625 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); | 628 EXPECT_FALSE(TransactionAcceptsSdchEncoding()); |
626 } | 629 } |
627 | 630 |
631 TEST_F(URLRequestHttpJobTest, HSTSInternalRedirectTest) { | |
632 // Setup HSTS state. | |
633 context_.transport_security_state()->AddHSTS( | |
634 "upgrade.test", base::Time::Now() + base::TimeDelta::FromSeconds(10), | |
635 true); | |
636 ASSERT_TRUE( | |
637 context_.transport_security_state()->ShouldUpgradeToSSL("upgrade.test")); | |
638 ASSERT_FALSE(context_.transport_security_state()->ShouldUpgradeToSSL( | |
639 "no-upgrade.test")); | |
640 | |
641 net::TestNetLog net_log; | |
642 context_.set_net_log(&net_log); | |
mmenke
2016/06/17 15:06:18
Could you move this into the test fixture, just be
Mike West
2016/06/17 16:35:17
Sure! Done.
| |
643 | |
644 struct TestCase { | |
645 const char* url; | |
646 bool upgrade_expected; | |
647 const char* url_expected; | |
648 } cases[] = { | |
649 {"http://upgrade.test/", true, "https://upgrade.test/"}, | |
650 {"ws://upgrade.test/", true, "wss://upgrade.test/"}, | |
651 {"http://upgrade.test:123/", true, "https://upgrade.test:123/"}, | |
652 {"ws://upgrade.test:123/", true, "wss://upgrade.test:123/"}, | |
653 {"http://no-upgrade.test/", false, "http://no-upgrade.test/"}, | |
654 {"ws://no-upgrade.test/", false, "ws://no-upgrade.test/"}, | |
655 {"http://no-upgrade.test:123/", false, "http://no-upgrade.test:123/"}, | |
656 {"ws://no-upgrade.test:123/", false, "ws://no-upgrade.test:123/"}, | |
mmenke
2016/06/17 15:06:18
Hrm...Websocket requests generally aren't made thr
Mike West
2016/06/17 16:35:17
I look forward to exploring the crazy in the other
| |
657 }; | |
658 | |
659 for (const auto& test : cases) { | |
660 SCOPED_TRACE(test.url); | |
661 TestDelegate d; | |
662 TestNetworkDelegate network_delegate; | |
663 std::unique_ptr<URLRequest> r( | |
664 context_.CreateRequest(GURL(test.url), DEFAULT_PRIORITY, &d)); | |
665 std::unique_ptr<URLRequestJob> job(URLRequestHttpJob::Factory( | |
666 r.get(), &network_delegate, url::kHttpScheme)); | |
mmenke
2016/06/17 15:06:18
This object isn't being used anywhere, please dele
Mike West
2016/06/17 16:35:17
Done.
| |
667 | |
668 net_log.Clear(); | |
669 r->Start(); | |
670 base::RunLoop().Run(); | |
671 | |
672 if (test.upgrade_expected) { | |
673 net::TestNetLogEntry::List entries; | |
674 net_log.GetEntries(&entries); | |
675 int redirects = 0; | |
676 for (const auto& entry : entries) { | |
677 if (entry.type == net::NetLog::TYPE_URL_REQUEST_REDIRECT_JOB) { | |
678 redirects++; | |
679 std::string value; | |
680 EXPECT_TRUE(entry.GetStringValue("reason", &value)); | |
681 EXPECT_EQ("HSTS", value); | |
682 } | |
683 } | |
684 EXPECT_EQ(1, redirects); | |
685 EXPECT_EQ(1, d.received_redirect_count()); | |
mmenke
2016/06/17 15:06:18
Suggest checking r->url_chain()'s length as well,
Mike West
2016/06/17 16:35:17
Added.
| |
686 } else { | |
687 EXPECT_EQ(0, d.received_redirect_count()); | |
688 } | |
689 EXPECT_EQ(GURL(test.url_expected), r->url()); | |
690 } | |
691 } | |
692 | |
628 class MockSdchObserver : public SdchObserver { | 693 class MockSdchObserver : public SdchObserver { |
629 public: | 694 public: |
630 MockSdchObserver() {} | 695 MockSdchObserver() {} |
631 MOCK_METHOD2(OnDictionaryAdded, | 696 MOCK_METHOD2(OnDictionaryAdded, |
632 void(const GURL& request_url, const std::string& server_hash)); | 697 void(const GURL& request_url, const std::string& server_hash)); |
633 MOCK_METHOD1(OnDictionaryRemoved, void(const std::string& server_hash)); | 698 MOCK_METHOD1(OnDictionaryRemoved, void(const std::string& server_hash)); |
634 MOCK_METHOD1(OnDictionaryUsed, void(const std::string& server_hash)); | 699 MOCK_METHOD1(OnDictionaryUsed, void(const std::string& server_hash)); |
635 MOCK_METHOD2(OnGetDictionary, | 700 MOCK_METHOD2(OnGetDictionary, |
636 void(const GURL& request_url, const GURL& dictionary_url)); | 701 void(const GURL& request_url, const GURL& dictionary_url)); |
637 MOCK_METHOD0(OnClearDictionaries, void()); | 702 MOCK_METHOD0(OnClearDictionaries, void()); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 create_helper.release()); | 1002 create_helper.release()); |
938 req_->SetLoadFlags(LOAD_DISABLE_CACHE); | 1003 req_->SetLoadFlags(LOAD_DISABLE_CACHE); |
939 req_->Start(); | 1004 req_->Start(); |
940 base::RunLoop().RunUntilIdle(); | 1005 base::RunLoop().RunUntilIdle(); |
941 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); | 1006 EXPECT_EQ(URLRequestStatus::IO_PENDING, req_->status().status()); |
942 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); | 1007 EXPECT_TRUE(fake_handshake_stream->initialize_stream_was_called()); |
943 } | 1008 } |
944 | 1009 |
945 #endif // !defined(OS_IOS) | 1010 #endif // !defined(OS_IOS) |
946 | 1011 |
1012 class URLRequestHttpJobInternalRedirectTest : public ::testing::Test { | |
1013 protected: | |
1014 URLRequestHttpJobInternalRedirectTest() | |
1015 : context_(new TestURLRequestContext(true)) { | |
1016 std::unique_ptr<HttpNetworkSession::Params> params( | |
1017 new HttpNetworkSession::Params); | |
1018 context_->set_enable_brotli(true); | |
1019 context_->set_http_network_session_params(std::move(params)); | |
1020 context_->set_client_socket_factory(&socket_factory_); | |
1021 context_->Init(); | |
1022 } | |
1023 | |
1024 MockClientSocketFactory socket_factory_; | |
1025 std::unique_ptr<TestURLRequestContext> context_; | |
1026 }; | |
1027 | |
947 } // namespace | 1028 } // namespace |
948 | 1029 |
949 } // namespace net | 1030 } // namespace net |
OLD | NEW |