| 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 <ostream> | 6 #include <ostream> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1873 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 1873 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 1874 QuicSession::HANDSHAKE_CONFIRMED); | 1874 QuicSession::HANDSHAKE_CONFIRMED); |
| 1875 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); | 1875 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); |
| 1876 NetErrorDetails details; | 1876 NetErrorDetails details; |
| 1877 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); | 1877 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); |
| 1878 | 1878 |
| 1879 trans->PopulateNetErrorDetails(&details); | 1879 trans->PopulateNetErrorDetails(&details); |
| 1880 EXPECT_EQ(QUIC_INVALID_STREAM_ID, details.quic_connection_error); | 1880 EXPECT_EQ(QUIC_INVALID_STREAM_ID, details.quic_connection_error); |
| 1881 } | 1881 } |
| 1882 | 1882 |
| 1883 TEST_P(QuicNetworkTransactionTest, RstSteamErrorHandling) { |
| 1884 MockQuicData mock_quic_data; |
| 1885 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 1886 1, kClientDataStreamId1, true, true, |
| 1887 GetRequestHeaders("GET", "https", "/"))); |
| 1888 // Read the response headers, then a RST_STREAM frame. |
| 1889 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( |
| 1890 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 1891 mock_quic_data.AddRead(ConstructServerRstPacket( |
| 1892 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1893 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1)); |
| 1894 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
| 1895 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1896 |
| 1897 // The non-alternate protocol job needs to hang in order to guarantee that |
| 1898 // the alternate-protocol job will "win". |
| 1899 AddHangingNonAlternateProtocolSocketData(); |
| 1900 |
| 1901 // In order for a new QUIC session to be established via alternate-protocol |
| 1902 // without racing an HTTP connection, we need the host resolution to happen |
| 1903 // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 1904 // connection to the the server, in this test we require confirmation |
| 1905 // before encrypting so the HTTP job will still start. |
| 1906 host_resolver_.set_synchronous_mode(true); |
| 1907 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", |
| 1908 ""); |
| 1909 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); |
| 1910 AddressList address; |
| 1911 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(), |
| 1912 nullptr, net_log_.bound()); |
| 1913 |
| 1914 CreateSession(); |
| 1915 session_->quic_stream_factory()->set_require_confirmation(true); |
| 1916 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1917 |
| 1918 std::unique_ptr<HttpNetworkTransaction> trans( |
| 1919 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1920 TestCompletionCallback callback; |
| 1921 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1922 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1923 |
| 1924 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 1925 QuicSession::HANDSHAKE_CONFIRMED); |
| 1926 // Read the headers. |
| 1927 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1928 |
| 1929 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1930 ASSERT_TRUE(response != nullptr); |
| 1931 ASSERT_TRUE(response->headers.get() != nullptr); |
| 1932 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1933 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 1934 EXPECT_TRUE(response->was_npn_negotiated); |
| 1935 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
| 1936 response->connection_info); |
| 1937 |
| 1938 std::string response_data; |
| 1939 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 1940 ReadTransaction(trans.get(), &response_data)); |
| 1941 } |
| 1942 |
| 1943 TEST_P(QuicNetworkTransactionTest, RstSteamBeforeHeaders) { |
| 1944 MockQuicData mock_quic_data; |
| 1945 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 1946 1, kClientDataStreamId1, true, true, |
| 1947 GetRequestHeaders("GET", "https", "/"))); |
| 1948 mock_quic_data.AddRead(ConstructServerRstPacket( |
| 1949 1, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1950 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
| 1951 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1952 |
| 1953 // The non-alternate protocol job needs to hang in order to guarantee that |
| 1954 // the alternate-protocol job will "win". |
| 1955 AddHangingNonAlternateProtocolSocketData(); |
| 1956 |
| 1957 // In order for a new QUIC session to be established via alternate-protocol |
| 1958 // without racing an HTTP connection, we need the host resolution to happen |
| 1959 // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 1960 // connection to the the server, in this test we require confirmation |
| 1961 // before encrypting so the HTTP job will still start. |
| 1962 host_resolver_.set_synchronous_mode(true); |
| 1963 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", |
| 1964 ""); |
| 1965 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); |
| 1966 AddressList address; |
| 1967 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(), |
| 1968 nullptr, net_log_.bound()); |
| 1969 |
| 1970 CreateSession(); |
| 1971 session_->quic_stream_factory()->set_require_confirmation(true); |
| 1972 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1973 |
| 1974 std::unique_ptr<HttpNetworkTransaction> trans( |
| 1975 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1976 TestCompletionCallback callback; |
| 1977 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1978 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1979 |
| 1980 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 1981 QuicSession::HANDSHAKE_CONFIRMED); |
| 1982 // Read the headers. |
| 1983 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); |
| 1984 } |
| 1985 |
| 1883 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { | 1986 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
| 1884 // Alternate-protocol job | 1987 // Alternate-protocol job |
| 1885 std::unique_ptr<QuicEncryptedPacket> close( | 1988 std::unique_ptr<QuicEncryptedPacket> close( |
| 1886 ConstructServerConnectionClosePacket(1)); | 1989 ConstructServerConnectionClosePacket(1)); |
| 1887 MockRead quic_reads[] = { | 1990 MockRead quic_reads[] = { |
| 1888 MockRead(ASYNC, close->data(), close->length()), | 1991 MockRead(ASYNC, close->data(), close->length()), |
| 1889 MockRead(ASYNC, ERR_IO_PENDING), // No more data to read | 1992 MockRead(ASYNC, ERR_IO_PENDING), // No more data to read |
| 1890 MockRead(ASYNC, OK), // EOF | 1993 MockRead(ASYNC, OK), // EOF |
| 1891 }; | 1994 }; |
| 1892 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), nullptr, | 1995 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), nullptr, |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 AddHangingSocketData(); | 2671 AddHangingSocketData(); |
| 2569 | 2672 |
| 2570 SendRequestAndExpectQuicResponse(origin1_); | 2673 SendRequestAndExpectQuicResponse(origin1_); |
| 2571 SendRequestAndExpectQuicResponse(origin2_); | 2674 SendRequestAndExpectQuicResponse(origin2_); |
| 2572 | 2675 |
| 2573 EXPECT_TRUE(AllDataConsumed()); | 2676 EXPECT_TRUE(AllDataConsumed()); |
| 2574 } | 2677 } |
| 2575 | 2678 |
| 2576 } // namespace test | 2679 } // namespace test |
| 2577 } // namespace net | 2680 } // namespace net |
| OLD | NEW |