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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/stringprintf.h" |
11 #include "net/base/network_quality_estimator.h" | 12 #include "net/base/network_quality_estimator.h" |
12 #include "net/base/socket_performance_watcher.h" | 13 #include "net/base/socket_performance_watcher.h" |
13 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
14 #include "net/base/test_data_directory.h" | 15 #include "net/base/test_data_directory.h" |
15 #include "net/cert/mock_cert_verifier.h" | 16 #include "net/cert/mock_cert_verifier.h" |
16 #include "net/dns/mock_host_resolver.h" | 17 #include "net/dns/mock_host_resolver.h" |
17 #include "net/http/http_auth_handler_factory.h" | 18 #include "net/http/http_auth_handler_factory.h" |
18 #include "net/http/http_network_session.h" | 19 #include "net/http/http_network_session.h" |
19 #include "net/http/http_network_transaction.h" | 20 #include "net/http/http_network_transaction.h" |
20 #include "net/http/http_server_properties_impl.h" | 21 #include "net/http/http_server_properties_impl.h" |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 673 |
673 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 674 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
674 | 675 |
675 AddHangingNonAlternateProtocolSocketData(); | 676 AddHangingNonAlternateProtocolSocketData(); |
676 CreateSessionWithNextProtos(); | 677 CreateSessionWithNextProtos(); |
677 | 678 |
678 SendRequestAndExpectHttpResponse("hello world"); | 679 SendRequestAndExpectHttpResponse("hello world"); |
679 SendRequestAndExpectQuicResponse("hello!"); | 680 SendRequestAndExpectQuicResponse("hello!"); |
680 } | 681 } |
681 | 682 |
| 683 TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceQuicSupportedVersion) { |
| 684 std::string altsvc_header = base::StringPrintf( |
| 685 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", GetParam()); |
| 686 MockRead http_reads[] = { |
| 687 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), |
| 688 MockRead("hello world"), |
| 689 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 690 MockRead(ASYNC, OK)}; |
| 691 |
| 692 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 693 0); |
| 694 socket_factory_.AddSocketDataProvider(&http_data); |
| 695 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); |
| 696 |
| 697 MockQuicData mock_quic_data; |
| 698 mock_quic_data.AddWrite( |
| 699 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 700 GetRequestHeaders("GET", "https", "/"))); |
| 701 mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 702 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 703 mock_quic_data.AddRead( |
| 704 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 705 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 706 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 707 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 708 |
| 709 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 710 |
| 711 AddHangingNonAlternateProtocolSocketData(); |
| 712 CreateSessionWithNextProtos(); |
| 713 |
| 714 SendRequestAndExpectHttpResponse("hello world"); |
| 715 SendRequestAndExpectQuicResponse("hello!"); |
| 716 } |
| 717 |
| 718 TEST_P(QuicNetworkTransactionTest, |
| 719 DoNotUseAlternativeServiceQuicUnsupportedVersion) { |
| 720 std::string altsvc_header = base::StringPrintf( |
| 721 "Alt-Svc: quic=\":443\"; v=\"%u\"\r\n\r\n", GetParam() - 1); |
| 722 MockRead http_reads[] = { |
| 723 MockRead("HTTP/1.1 200 OK\r\n"), MockRead(altsvc_header.c_str()), |
| 724 MockRead("hello world"), |
| 725 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 726 MockRead(ASYNC, OK)}; |
| 727 |
| 728 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 729 0); |
| 730 socket_factory_.AddSocketDataProvider(&http_data); |
| 731 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); |
| 732 socket_factory_.AddSocketDataProvider(&http_data); |
| 733 socket_factory_.AddSSLSocketDataProvider(&ssl_data_); |
| 734 |
| 735 CreateSessionWithNextProtos(); |
| 736 |
| 737 SendRequestAndExpectHttpResponse("hello world"); |
| 738 SendRequestAndExpectHttpResponse("hello world"); |
| 739 } |
| 740 |
682 // When multiple alternative services are advertised, | 741 // When multiple alternative services are advertised, |
683 // HttpStreamFactoryImpl::RequestStreamInternal() only passes the first one to | 742 // HttpStreamFactoryImpl::RequestStreamInternal() only passes the first one to |
684 // Job. This is what the following test verifies. | 743 // Job. This is what the following test verifies. |
685 // TODO(bnc): Update this test when multiple alternative services are handled | 744 // TODO(bnc): Update this test when multiple alternative services are handled |
686 // properly. | 745 // properly. |
687 TEST_P(QuicNetworkTransactionTest, UseFirstAlternativeServiceForQuic) { | 746 TEST_P(QuicNetworkTransactionTest, UseFirstAlternativeServiceForQuic) { |
688 MockRead http_reads[] = { | 747 MockRead http_reads[] = { |
689 MockRead("HTTP/1.1 200 OK\r\n"), | 748 MockRead("HTTP/1.1 200 OK\r\n"), |
690 MockRead("Alt-Svc: quic=\":443\", quic=\":1234\"\r\n\r\n"), | 749 MockRead("Alt-Svc: quic=\":443\", quic=\":1234\"\r\n\r\n"), |
691 MockRead("hello world"), | 750 MockRead("hello world"), |
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 AddHangingNonAlternateProtocolSocketData(); | 1745 AddHangingNonAlternateProtocolSocketData(); |
1687 CreateSessionWithNextProtos(); | 1746 CreateSessionWithNextProtos(); |
1688 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); | 1747 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
1689 SendRequestAndExpectQuicResponse("hello!"); | 1748 SendRequestAndExpectQuicResponse("hello!"); |
1690 EXPECT_TRUE( | 1749 EXPECT_TRUE( |
1691 test_network_quality_estimator_->IsRTTAvailableNotificationReceived()); | 1750 test_network_quality_estimator_->IsRTTAvailableNotificationReceived()); |
1692 } | 1751 } |
1693 | 1752 |
1694 } // namespace test | 1753 } // namespace test |
1695 } // namespace net | 1754 } // namespace net |
OLD | NEW |