| 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 2054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2065 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 2065 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 2066 QuicSession::HANDSHAKE_CONFIRMED); | 2066 QuicSession::HANDSHAKE_CONFIRMED); |
| 2067 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); | 2067 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); |
| 2068 NetErrorDetails details; | 2068 NetErrorDetails details; |
| 2069 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); | 2069 EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); |
| 2070 | 2070 |
| 2071 trans->PopulateNetErrorDetails(&details); | 2071 trans->PopulateNetErrorDetails(&details); |
| 2072 EXPECT_EQ(QUIC_INVALID_STREAM_ID, details.quic_connection_error); | 2072 EXPECT_EQ(QUIC_INVALID_STREAM_ID, details.quic_connection_error); |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 TEST_P(QuicNetworkTransactionTest, RstSteamErrorHandling) { |
| 2076 MockQuicData mock_quic_data; |
| 2077 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 2078 1, kClientDataStreamId1, true, true, |
| 2079 GetRequestHeaders("GET", "https", "/"))); |
| 2080 // Read the response headers, then a RST_STREAM frame. |
| 2081 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( |
| 2082 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 2083 mock_quic_data.AddRead(ConstructServerRstPacket( |
| 2084 2, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 2085 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1)); |
| 2086 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
| 2087 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 2088 |
| 2089 // The non-alternate protocol job needs to hang in order to guarantee that |
| 2090 // the alternate-protocol job will "win". |
| 2091 AddHangingNonAlternateProtocolSocketData(); |
| 2092 |
| 2093 // In order for a new QUIC session to be established via alternate-protocol |
| 2094 // without racing an HTTP connection, we need the host resolution to happen |
| 2095 // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 2096 // connection to the the server, in this test we require confirmation |
| 2097 // before encrypting so the HTTP job will still start. |
| 2098 host_resolver_.set_synchronous_mode(true); |
| 2099 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", |
| 2100 ""); |
| 2101 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); |
| 2102 AddressList address; |
| 2103 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(), |
| 2104 nullptr, net_log_.bound()); |
| 2105 |
| 2106 CreateSession(); |
| 2107 session_->quic_stream_factory()->set_require_confirmation(true); |
| 2108 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 2109 |
| 2110 std::unique_ptr<HttpNetworkTransaction> trans( |
| 2111 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 2112 TestCompletionCallback callback; |
| 2113 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 2114 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2115 |
| 2116 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 2117 QuicSession::HANDSHAKE_CONFIRMED); |
| 2118 // Read the headers. |
| 2119 EXPECT_EQ(OK, callback.WaitForResult()); |
| 2120 |
| 2121 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2122 ASSERT_TRUE(response != nullptr); |
| 2123 ASSERT_TRUE(response->headers.get() != nullptr); |
| 2124 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2125 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2126 EXPECT_TRUE(response->was_npn_negotiated); |
| 2127 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
| 2128 response->connection_info); |
| 2129 |
| 2130 std::string response_data; |
| 2131 ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 2132 ReadTransaction(trans.get(), &response_data)); |
| 2133 } |
| 2134 |
| 2135 TEST_P(QuicNetworkTransactionTest, RstSteamBeforeHeaders) { |
| 2136 MockQuicData mock_quic_data; |
| 2137 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( |
| 2138 1, kClientDataStreamId1, true, true, |
| 2139 GetRequestHeaders("GET", "https", "/"))); |
| 2140 mock_quic_data.AddRead(ConstructServerRstPacket( |
| 2141 1, false, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 2142 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
| 2143 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 2144 |
| 2145 // The non-alternate protocol job needs to hang in order to guarantee that |
| 2146 // the alternate-protocol job will "win". |
| 2147 AddHangingNonAlternateProtocolSocketData(); |
| 2148 |
| 2149 // In order for a new QUIC session to be established via alternate-protocol |
| 2150 // without racing an HTTP connection, we need the host resolution to happen |
| 2151 // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 2152 // connection to the the server, in this test we require confirmation |
| 2153 // before encrypting so the HTTP job will still start. |
| 2154 host_resolver_.set_synchronous_mode(true); |
| 2155 host_resolver_.rules()->AddIPLiteralRule("mail.example.org", "192.168.0.1", |
| 2156 ""); |
| 2157 HostResolver::RequestInfo info(HostPortPair("mail.example.org", 443)); |
| 2158 AddressList address; |
| 2159 host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, CompletionCallback(), |
| 2160 nullptr, net_log_.bound()); |
| 2161 |
| 2162 CreateSession(); |
| 2163 session_->quic_stream_factory()->set_require_confirmation(true); |
| 2164 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 2165 |
| 2166 std::unique_ptr<HttpNetworkTransaction> trans( |
| 2167 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 2168 TestCompletionCallback callback; |
| 2169 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 2170 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2171 |
| 2172 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 2173 QuicSession::HANDSHAKE_CONFIRMED); |
| 2174 // Read the headers. |
| 2175 EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback.WaitForResult()); |
| 2176 } |
| 2177 |
| 2075 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { | 2178 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
| 2076 // Alternate-protocol job | 2179 // Alternate-protocol job |
| 2077 std::unique_ptr<QuicEncryptedPacket> close( | 2180 std::unique_ptr<QuicEncryptedPacket> close( |
| 2078 ConstructServerConnectionClosePacket(1)); | 2181 ConstructServerConnectionClosePacket(1)); |
| 2079 MockRead quic_reads[] = { | 2182 MockRead quic_reads[] = { |
| 2080 MockRead(ASYNC, close->data(), close->length()), | 2183 MockRead(ASYNC, close->data(), close->length()), |
| 2081 MockRead(ASYNC, ERR_IO_PENDING), // No more data to read | 2184 MockRead(ASYNC, ERR_IO_PENDING), // No more data to read |
| 2082 MockRead(ASYNC, OK), // EOF | 2185 MockRead(ASYNC, OK), // EOF |
| 2083 }; | 2186 }; |
| 2084 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), nullptr, | 2187 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), nullptr, |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2757 AddHangingSocketData(); | 2860 AddHangingSocketData(); |
| 2758 | 2861 |
| 2759 SendRequestAndExpectQuicResponse(origin1_); | 2862 SendRequestAndExpectQuicResponse(origin1_); |
| 2760 SendRequestAndExpectQuicResponse(origin2_); | 2863 SendRequestAndExpectQuicResponse(origin2_); |
| 2761 | 2864 |
| 2762 EXPECT_TRUE(AllDataConsumed()); | 2865 EXPECT_TRUE(AllDataConsumed()); |
| 2763 } | 2866 } |
| 2764 | 2867 |
| 2765 } // namespace test | 2868 } // namespace test |
| 2766 } // namespace net | 2869 } // namespace net |
| OLD | NEW |