| 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> |
| 6 |
| 5 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 9 #include "net/base/capturing_net_log.h" | 11 #include "net/base/capturing_net_log.h" |
| 10 #include "net/base/net_log_unittest.h" | 12 #include "net/base/net_log_unittest.h" |
| 11 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 12 #include "net/cert/mock_cert_verifier.h" | 14 #include "net/cert/mock_cert_verifier.h" |
| 13 #include "net/dns/mock_host_resolver.h" | 15 #include "net/dns/mock_host_resolver.h" |
| 14 #include "net/http/http_auth_handler_factory.h" | 16 #include "net/http/http_auth_handler_factory.h" |
| 15 #include "net/http/http_network_session.h" | 17 #include "net/http/http_network_session.h" |
| 16 #include "net/http/http_network_transaction.h" | 18 #include "net/http/http_network_transaction.h" |
| 17 #include "net/http/http_server_properties_impl.h" | 19 #include "net/http/http_server_properties_impl.h" |
| 18 #include "net/http/http_stream.h" | 20 #include "net/http/http_stream.h" |
| 19 #include "net/http/http_stream_factory.h" | 21 #include "net/http/http_stream_factory.h" |
| 20 #include "net/http/http_transaction_unittest.h" | 22 #include "net/http/http_transaction_unittest.h" |
| 21 #include "net/http/transport_security_state.h" | 23 #include "net/http/transport_security_state.h" |
| 22 #include "net/proxy/proxy_config_service_fixed.h" | 24 #include "net/proxy/proxy_config_service_fixed.h" |
| 23 #include "net/proxy/proxy_resolver.h" | 25 #include "net/proxy/proxy_resolver.h" |
| 24 #include "net/proxy/proxy_service.h" | 26 #include "net/proxy/proxy_service.h" |
| 25 #include "net/quic/crypto/quic_decrypter.h" | 27 #include "net/quic/crypto/quic_decrypter.h" |
| 26 #include "net/quic/crypto/quic_encrypter.h" | 28 #include "net/quic/crypto/quic_encrypter.h" |
| 27 #include "net/quic/quic_framer.h" | 29 #include "net/quic/quic_framer.h" |
| 28 #include "net/quic/quic_http_utils.h" | 30 #include "net/quic/quic_http_utils.h" |
| 29 #include "net/quic/test_tools/crypto_test_utils.h" | 31 #include "net/quic/test_tools/crypto_test_utils.h" |
| 30 #include "net/quic/test_tools/mock_clock.h" | 32 #include "net/quic/test_tools/mock_clock.h" |
| 31 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" | 33 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
| 32 #include "net/quic/test_tools/mock_random.h" | 34 #include "net/quic/test_tools/mock_random.h" |
| 35 #include "net/quic/test_tools/quic_test_packet_maker.h" |
| 33 #include "net/quic/test_tools/quic_test_utils.h" | 36 #include "net/quic/test_tools/quic_test_utils.h" |
| 34 #include "net/socket/client_socket_factory.h" | 37 #include "net/socket/client_socket_factory.h" |
| 35 #include "net/socket/mock_client_socket_pool_manager.h" | 38 #include "net/socket/mock_client_socket_pool_manager.h" |
| 36 #include "net/socket/socket_test_util.h" | 39 #include "net/socket/socket_test_util.h" |
| 37 #include "net/socket/ssl_client_socket.h" | 40 #include "net/socket/ssl_client_socket.h" |
| 38 #include "net/spdy/spdy_frame_builder.h" | 41 #include "net/spdy/spdy_frame_builder.h" |
| 39 #include "net/spdy/spdy_framer.h" | 42 #include "net/spdy/spdy_framer.h" |
| 40 #include "net/ssl/ssl_config_service_defaults.h" | 43 #include "net/ssl/ssl_config_service_defaults.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "testing/platform_test.h" | 45 #include "testing/platform_test.h" |
| 43 | 46 |
| 44 //----------------------------------------------------------------------------- | 47 //----------------------------------------------------------------------------- |
| 45 | 48 |
| 46 namespace { | 49 namespace { |
| 47 | 50 |
| 48 // This is the expected return from a current server advertising QUIC. | 51 // This is the expected return from a current server advertising QUIC. |
| 49 static const char kQuicAlternateProtocolHttpHeader[] = | 52 static const char kQuicAlternateProtocolHttpHeader[] = |
| 50 "Alternate-Protocol: 80:quic\r\n\r\n"; | 53 "Alternate-Protocol: 80:quic\r\n\r\n"; |
| 51 static const char kQuicAlternateProtocolHttpsHeader[] = | 54 static const char kQuicAlternateProtocolHttpsHeader[] = |
| 52 "Alternate-Protocol: 443:quic\r\n\r\n"; | 55 "Alternate-Protocol: 443:quic\r\n\r\n"; |
| 56 |
| 53 } // namespace | 57 } // namespace |
| 54 | 58 |
| 55 namespace net { | 59 namespace net { |
| 56 namespace test { | 60 namespace test { |
| 57 | 61 |
| 58 class QuicNetworkTransactionTest : public PlatformTest { | 62 // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 63 // Simplify ownership issues and the interaction with the MockSocketFactory. |
| 64 class MockQuicData { |
| 65 public: |
| 66 ~MockQuicData() { |
| 67 STLDeleteElements(&packets_); |
| 68 } |
| 69 |
| 70 void AddRead(scoped_ptr<QuicEncryptedPacket> packet) { |
| 71 reads_.push_back(MockRead(SYNCHRONOUS, packet->data(), packet->length(), |
| 72 sequence_number_++)); |
| 73 packets_.push_back(packet.release()); |
| 74 } |
| 75 |
| 76 void AddRead(IoMode mode, int rv) { |
| 77 reads_.push_back(MockRead(mode, rv)); |
| 78 } |
| 79 |
| 80 void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
| 81 writes_.push_back(MockWrite(SYNCHRONOUS, packet->data(), packet->length(), |
| 82 sequence_number_++)); |
| 83 packets_.push_back(packet.release()); |
| 84 } |
| 85 |
| 86 void AddDelayedSocketDataToFactory(MockClientSocketFactory* factory, |
| 87 size_t delay) { |
| 88 MockRead* reads = reads_.empty() ? NULL : &reads_[0]; |
| 89 MockWrite* writes = writes_.empty() ? NULL : &writes_[0]; |
| 90 socket_data_.reset(new DelayedSocketData( |
| 91 delay, reads, reads_.size(), writes, writes_.size())); |
| 92 factory->AddSocketDataProvider(socket_data_.get()); |
| 93 } |
| 94 |
| 95 private: |
| 96 std::vector<QuicEncryptedPacket*> packets_; |
| 97 std::vector<MockWrite> writes_; |
| 98 std::vector<MockRead> reads_; |
| 99 size_t sequence_number_; |
| 100 scoped_ptr<SocketDataProvider> socket_data_; |
| 101 }; |
| 102 |
| 103 class QuicNetworkTransactionTest |
| 104 : public PlatformTest, |
| 105 public testing::WithParamInterface<QuicVersion> { |
| 59 protected: | 106 protected: |
| 60 QuicNetworkTransactionTest() | 107 QuicNetworkTransactionTest() |
| 61 : clock_(new MockClock), | 108 : maker_(GetParam(), 0), |
| 109 clock_(new MockClock), |
| 62 ssl_config_service_(new SSLConfigServiceDefaults), | 110 ssl_config_service_(new SSLConfigServiceDefaults), |
| 63 proxy_service_(ProxyService::CreateDirect()), | 111 proxy_service_(ProxyService::CreateDirect()), |
| 64 compressor_(new QuicSpdyCompressor()), | |
| 65 auth_handler_factory_( | 112 auth_handler_factory_( |
| 66 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), | 113 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
| 67 random_generator_(0), | 114 random_generator_(0), |
| 68 hanging_data_(NULL, 0, NULL, 0) { | 115 hanging_data_(NULL, 0, NULL, 0) { |
| 69 request_.method = "GET"; | 116 request_.method = "GET"; |
| 70 request_.url = GURL("http://www.google.com/"); | 117 request_.url = GURL("http://www.google.com/"); |
| 71 request_.load_flags = 0; | 118 request_.load_flags = 0; |
| 72 } | 119 } |
| 73 | 120 |
| 74 virtual void SetUp() { | 121 virtual void SetUp() { |
| 75 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 122 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 76 base::MessageLoop::current()->RunUntilIdle(); | 123 base::MessageLoop::current()->RunUntilIdle(); |
| 77 } | 124 } |
| 78 | 125 |
| 79 virtual void TearDown() { | 126 virtual void TearDown() { |
| 80 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 127 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 81 // Empty the current queue. | 128 // Empty the current queue. |
| 82 base::MessageLoop::current()->RunUntilIdle(); | 129 base::MessageLoop::current()->RunUntilIdle(); |
| 83 PlatformTest::TearDown(); | 130 PlatformTest::TearDown(); |
| 84 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 131 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 85 base::MessageLoop::current()->RunUntilIdle(); | 132 base::MessageLoop::current()->RunUntilIdle(); |
| 86 HttpStreamFactory::set_use_alternate_protocols(false); | 133 HttpStreamFactory::set_use_alternate_protocols(false); |
| 87 HttpStreamFactory::SetNextProtos(std::vector<NextProto>()); | 134 HttpStreamFactory::SetNextProtos(std::vector<NextProto>()); |
| 88 } | 135 } |
| 89 | 136 |
| 90 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket( | 137 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket( |
| 91 QuicPacketSequenceNumber num, | 138 QuicPacketSequenceNumber num, |
| 92 QuicStreamId stream_id) { | 139 QuicStreamId stream_id) { |
| 93 QuicPacketHeader header; | 140 return maker_.MakeRstPacket( |
| 94 header.public_header.guid = random_generator_.RandUint64(); | 141 num, false, stream_id, QUIC_STREAM_NO_ERROR); |
| 95 header.public_header.reset_flag = false; | |
| 96 header.public_header.version_flag = false; | |
| 97 header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; | |
| 98 header.packet_sequence_number = num; | |
| 99 header.entropy_flag = false; | |
| 100 header.fec_flag = false; | |
| 101 header.fec_group = 0; | |
| 102 | |
| 103 QuicRstStreamFrame rst(stream_id, QUIC_STREAM_NO_ERROR); | |
| 104 return scoped_ptr<QuicEncryptedPacket>( | |
| 105 ConstructPacket(header, QuicFrame(&rst))); | |
| 106 } | 142 } |
| 107 | 143 |
| 108 scoped_ptr<QuicEncryptedPacket> ConstructConnectionClosePacket( | 144 scoped_ptr<QuicEncryptedPacket> ConstructConnectionClosePacket( |
| 109 QuicPacketSequenceNumber num) { | 145 QuicPacketSequenceNumber num) { |
| 110 QuicPacketHeader header; | 146 return maker_.MakeConnectionClosePacket(num); |
| 111 header.public_header.guid = random_generator_.RandUint64(); | |
| 112 header.public_header.reset_flag = false; | |
| 113 header.public_header.version_flag = false; | |
| 114 header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; | |
| 115 header.packet_sequence_number = num; | |
| 116 header.entropy_flag = false; | |
| 117 header.fec_flag = false; | |
| 118 header.fec_group = 0; | |
| 119 | |
| 120 QuicConnectionCloseFrame close; | |
| 121 close.error_code = QUIC_CRYPTO_VERSION_NOT_SUPPORTED; | |
| 122 close.error_details = "Time to panic!"; | |
| 123 return scoped_ptr<QuicEncryptedPacket>( | |
| 124 ConstructPacket(header, QuicFrame(&close))); | |
| 125 } | 147 } |
| 126 | 148 |
| 127 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( | 149 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
| 128 QuicPacketSequenceNumber largest_received, | 150 QuicPacketSequenceNumber largest_received, |
| 129 QuicPacketSequenceNumber least_unacked) { | 151 QuicPacketSequenceNumber least_unacked) { |
| 130 QuicPacketHeader header; | 152 return maker_.MakeAckPacket(2, largest_received, least_unacked, true); |
| 131 header.public_header.guid = random_generator_.RandUint64(); | 153 } |
| 132 header.public_header.reset_flag = false; | |
| 133 header.public_header.version_flag = false; | |
| 134 header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; | |
| 135 header.packet_sequence_number = 2; | |
| 136 header.entropy_flag = false; | |
| 137 header.fec_flag = false; | |
| 138 header.fec_group = 0; | |
| 139 | 154 |
| 140 QuicAckFrame ack(largest_received, QuicTime::Zero(), least_unacked); | 155 SpdyHeaderBlock GetRequestHeaders(const std::string& method, |
| 141 | 156 const std::string& scheme, |
| 142 QuicCongestionFeedbackFrame feedback; | 157 const std::string& path) { |
| 143 feedback.type = kTCP; | 158 return maker_.GetRequestHeaders(method, scheme, path); |
| 144 feedback.tcp.accumulated_number_of_lost_packets = 0; | |
| 145 feedback.tcp.receive_window = 256000; | |
| 146 | |
| 147 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); | |
| 148 QuicFrames frames; | |
| 149 frames.push_back(QuicFrame(&ack)); | |
| 150 frames.push_back(QuicFrame(&feedback)); | |
| 151 scoped_ptr<QuicPacket> packet( | |
| 152 framer.BuildUnsizedDataPacket(header, frames).packet); | |
| 153 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket( | |
| 154 ENCRYPTION_NONE, header.packet_sequence_number, *packet)); | |
| 155 } | 159 } |
| 156 | 160 |
| 157 std::string GetRequestString(const std::string& method, | 161 std::string GetRequestString(const std::string& method, |
| 158 const std::string& scheme, | 162 const std::string& scheme, |
| 159 const std::string& path) { | 163 const std::string& path) { |
| 160 SpdyHeaderBlock headers; | 164 return maker_.GetRequestString(method, scheme, path); |
| 161 headers[":method"] = method; | 165 } |
| 162 headers[":host"] = "www.google.com"; | 166 |
| 163 headers[":path"] = path; | 167 SpdyHeaderBlock GetResponseHeaders(const std::string& status) { |
| 164 headers[":scheme"] = scheme; | 168 return maker_.GetResponseHeaders(status); |
| 165 headers[":version"] = "HTTP/1.1"; | |
| 166 return SerializeHeaderBlock(headers); | |
| 167 } | 169 } |
| 168 | 170 |
| 169 std::string GetResponseString(const std::string& status, | 171 std::string GetResponseString(const std::string& status, |
| 170 const std::string& body) { | 172 const std::string& body) { |
| 171 SpdyHeaderBlock headers; | 173 return maker_.GetResponseString(status, body); |
| 172 headers[":status"] = status; | |
| 173 headers[":version"] = "HTTP/1.1"; | |
| 174 headers["content-type"] = "text/plain"; | |
| 175 return compressor_->CompressHeaders(headers) + body; | |
| 176 } | 174 } |
| 177 | 175 |
| 178 std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers) { | 176 scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
| 179 QuicSpdyCompressor compressor; | |
| 180 return compressor.CompressHeadersWithPriority( | |
| 181 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY), headers); | |
| 182 } | |
| 183 | |
| 184 // Returns a newly created packet to send kData on stream 1. | |
| 185 QuicEncryptedPacket* ConstructDataPacket( | |
| 186 QuicPacketSequenceNumber sequence_number, | 177 QuicPacketSequenceNumber sequence_number, |
| 187 QuicStreamId stream_id, | 178 QuicStreamId stream_id, |
| 188 bool should_include_version, | 179 bool should_include_version, |
| 189 bool fin, | 180 bool fin, |
| 190 QuicStreamOffset offset, | 181 QuicStreamOffset offset, |
| 191 base::StringPiece data) { | 182 base::StringPiece data) { |
| 192 InitializeHeader(sequence_number, should_include_version); | 183 return maker_.MakeDataPacket( |
| 193 QuicStreamFrame frame(stream_id, fin, offset, MakeIOVector(data)); | 184 sequence_number, stream_id, should_include_version, fin, offset, data); |
| 194 return ConstructPacket(header_, QuicFrame(&frame)).release(); | |
| 195 } | 185 } |
| 196 | 186 |
| 197 scoped_ptr<QuicEncryptedPacket> ConstructPacket( | 187 scoped_ptr<QuicEncryptedPacket> ConstructRequestHeadersPacket( |
| 198 const QuicPacketHeader& header, | 188 QuicPacketSequenceNumber sequence_number, |
| 199 const QuicFrame& frame) { | 189 QuicStreamId stream_id, |
| 200 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false); | 190 bool should_include_version, |
| 201 QuicFrames frames; | 191 bool fin, |
| 202 frames.push_back(frame); | 192 const SpdyHeaderBlock& headers) { |
| 203 scoped_ptr<QuicPacket> packet( | 193 return maker_.MakeRequestHeadersPacket( |
| 204 framer.BuildUnsizedDataPacket(header, frames).packet); | 194 sequence_number, stream_id, should_include_version, fin, headers); |
| 205 return scoped_ptr<QuicEncryptedPacket>(framer.EncryptPacket( | |
| 206 ENCRYPTION_NONE, header.packet_sequence_number, *packet)); | |
| 207 } | 195 } |
| 208 | 196 |
| 209 void InitializeHeader(QuicPacketSequenceNumber sequence_number, | 197 scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( |
| 210 bool should_include_version) { | 198 QuicPacketSequenceNumber sequence_number, |
| 211 header_.public_header.guid = random_generator_.RandUint64(); | 199 QuicStreamId stream_id, |
| 212 header_.public_header.reset_flag = false; | 200 bool should_include_version, |
| 213 header_.public_header.version_flag = should_include_version; | 201 bool fin, |
| 214 header_.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; | 202 const SpdyHeaderBlock& headers) { |
| 215 header_.packet_sequence_number = sequence_number; | 203 return maker_.MakeResponseHeadersPacket( |
| 216 header_.fec_group = 0; | 204 sequence_number, stream_id, should_include_version, fin, headers); |
| 217 header_.entropy_flag = false; | |
| 218 header_.fec_flag = false; | |
| 219 } | 205 } |
| 220 | 206 |
| 221 void CreateSession() { | 207 void CreateSession() { |
| 222 CreateSessionWithFactory(&socket_factory_); | 208 CreateSessionWithFactory(&socket_factory_); |
| 223 } | 209 } |
| 224 | 210 |
| 225 void CreateSessionWithFactory(ClientSocketFactory* socket_factory) { | 211 void CreateSessionWithFactory(ClientSocketFactory* socket_factory) { |
| 226 params_.enable_quic = true; | 212 params_.enable_quic = true; |
| 227 params_.quic_clock = clock_; | 213 params_.quic_clock = clock_; |
| 228 params_.quic_random = &random_generator_; | 214 params_.quic_random = &random_generator_; |
| 229 params_.client_socket_factory = socket_factory; | 215 params_.client_socket_factory = socket_factory; |
| 230 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; | 216 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
| 231 params_.host_resolver = &host_resolver_; | 217 params_.host_resolver = &host_resolver_; |
| 232 params_.cert_verifier = &cert_verifier_; | 218 params_.cert_verifier = &cert_verifier_; |
| 233 params_.transport_security_state = &transport_security_state_; | 219 params_.transport_security_state = &transport_security_state_; |
| 234 params_.proxy_service = proxy_service_.get(); | 220 params_.proxy_service = proxy_service_.get(); |
| 235 params_.ssl_config_service = ssl_config_service_.get(); | 221 params_.ssl_config_service = ssl_config_service_.get(); |
| 236 params_.http_auth_handler_factory = auth_handler_factory_.get(); | 222 params_.http_auth_handler_factory = auth_handler_factory_.get(); |
| 237 params_.http_server_properties = http_server_properties.GetWeakPtr(); | 223 params_.http_server_properties = http_server_properties.GetWeakPtr(); |
| 224 params_.quic_supported_versions = SupportedVersions(GetParam()); |
| 238 | 225 |
| 239 session_ = new HttpNetworkSession(params_); | 226 session_ = new HttpNetworkSession(params_); |
| 240 session_->quic_stream_factory()->set_require_confirmation(false); | 227 session_->quic_stream_factory()->set_require_confirmation(false); |
| 241 } | 228 } |
| 242 | 229 |
| 243 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { | 230 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 244 const HttpResponseInfo* response = trans->GetResponseInfo(); | 231 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 245 ASSERT_TRUE(response != NULL); | 232 ASSERT_TRUE(response != NULL); |
| 246 ASSERT_TRUE(response->headers.get() != NULL); | 233 ASSERT_TRUE(response->headers.get() != NULL); |
| 247 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 234 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 HostPortPair::FromURL(request_.url)); | 294 HostPortPair::FromURL(request_.url)); |
| 308 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 295 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
| 309 } | 296 } |
| 310 | 297 |
| 311 void AddHangingNonAlternateProtocolSocketData() { | 298 void AddHangingNonAlternateProtocolSocketData() { |
| 312 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); | 299 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 313 hanging_data_.set_connect_data(hanging_connect); | 300 hanging_data_.set_connect_data(hanging_connect); |
| 314 socket_factory_.AddSocketDataProvider(&hanging_data_); | 301 socket_factory_.AddSocketDataProvider(&hanging_data_); |
| 315 } | 302 } |
| 316 | 303 |
| 317 QuicPacketHeader header_; | 304 QuicTestPacketMaker maker_; |
| 318 scoped_refptr<HttpNetworkSession> session_; | 305 scoped_refptr<HttpNetworkSession> session_; |
| 319 MockClientSocketFactory socket_factory_; | 306 MockClientSocketFactory socket_factory_; |
| 320 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 307 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 321 MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. | 308 MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. |
| 322 MockHostResolver host_resolver_; | 309 MockHostResolver host_resolver_; |
| 323 MockCertVerifier cert_verifier_; | 310 MockCertVerifier cert_verifier_; |
| 324 TransportSecurityState transport_security_state_; | 311 TransportSecurityState transport_security_state_; |
| 325 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 312 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 326 scoped_ptr<ProxyService> proxy_service_; | 313 scoped_ptr<ProxyService> proxy_service_; |
| 327 scoped_ptr<QuicSpdyCompressor> compressor_; | |
| 328 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 314 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
| 329 MockRandom random_generator_; | 315 MockRandom random_generator_; |
| 330 HttpServerPropertiesImpl http_server_properties; | 316 HttpServerPropertiesImpl http_server_properties; |
| 331 HttpNetworkSession::Params params_; | 317 HttpNetworkSession::Params params_; |
| 332 HttpRequestInfo request_; | 318 HttpRequestInfo request_; |
| 333 CapturingBoundNetLog net_log_; | 319 CapturingBoundNetLog net_log_; |
| 334 StaticSocketDataProvider hanging_data_; | 320 StaticSocketDataProvider hanging_data_; |
| 335 }; | 321 }; |
| 336 | 322 |
| 337 TEST_F(QuicNetworkTransactionTest, ForceQuic) { | 323 INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, |
| 324 ::testing::ValuesIn(QuicSupportedVersions())); |
| 325 |
| 326 TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
| 338 params_.origin_to_force_quic_on = | 327 params_.origin_to_force_quic_on = |
| 339 HostPortPair::FromString("www.google.com:80"); | 328 HostPortPair::FromString("www.google.com:80"); |
| 340 | 329 |
| 341 QuicStreamId stream_id = 3; | 330 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
| 342 scoped_ptr<QuicEncryptedPacket> req( | 331 MockQuicData mock_quic_data; |
| 343 ConstructDataPacket(1, stream_id, true, true, 0, | 332 if (GetParam() > QUIC_VERSION_12) { |
| 344 GetRequestString("GET", "http", "/"))); | 333 mock_quic_data.AddWrite( |
| 345 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 334 ConstructRequestHeadersPacket(1, stream_id, true, true, |
| 335 GetRequestHeaders("GET", "http", "/"))); |
| 336 mock_quic_data.AddRead( |
| 337 ConstructResponseHeadersPacket(1, stream_id, false, false, |
| 338 GetResponseHeaders("200 OK"))); |
| 339 mock_quic_data.AddRead( |
| 340 ConstructDataPacket(2, stream_id, false, true, 0, "hello!")); |
| 341 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 342 } else { |
| 343 mock_quic_data.AddWrite( |
| 344 ConstructDataPacket(1, stream_id, true, true, 0, |
| 345 GetRequestString("GET", "http", "/"))); |
| 346 mock_quic_data.AddRead( |
| 347 ConstructDataPacket(1, stream_id, false, true, 0, |
| 348 GetResponseString("200 OK", "hello!"))); |
| 349 mock_quic_data.AddWrite(ConstructAckPacket(1, 0)); |
| 350 } |
| 351 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 346 | 352 |
| 347 MockWrite quic_writes[] = { | 353 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
| 348 MockWrite(SYNCHRONOUS, req->data(), req->length()), | |
| 349 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | |
| 350 }; | |
| 351 | |
| 352 scoped_ptr<QuicEncryptedPacket> resp( | |
| 353 ConstructDataPacket( | |
| 354 1, stream_id, false, true, 0, GetResponseString("200 OK", "hello!"))); | |
| 355 MockRead quic_reads[] = { | |
| 356 MockRead(SYNCHRONOUS, resp->data(), resp->length()), | |
| 357 MockRead(ASYNC, OK), // EOF | |
| 358 }; | |
| 359 | |
| 360 DelayedSocketData quic_data( | |
| 361 1, // wait for one write to finish before reading. | |
| 362 quic_reads, arraysize(quic_reads), | |
| 363 quic_writes, arraysize(quic_writes)); | |
| 364 | |
| 365 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 366 | 354 |
| 367 // The non-alternate protocol job needs to hang in order to guarantee that | 355 // The non-alternate protocol job needs to hang in order to guarantee that |
| 368 // the alternate-protocol job will "win". | 356 // the alternate-protocol job will "win". |
| 369 AddHangingNonAlternateProtocolSocketData(); | 357 AddHangingNonAlternateProtocolSocketData(); |
| 370 | 358 |
| 371 CreateSession(); | 359 CreateSession(); |
| 372 | 360 |
| 373 SendRequestAndExpectQuicResponse("hello!"); | 361 SendRequestAndExpectQuicResponse("hello!"); |
| 374 | 362 |
| 375 // Check that the NetLog was filled reasonably. | 363 // Check that the NetLog was filled reasonably. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 398 | 386 |
| 399 // ... and also a QUIC_SESSION_STREAM_FRAME_RECEIVED. | 387 // ... and also a QUIC_SESSION_STREAM_FRAME_RECEIVED. |
| 400 pos = net::ExpectLogContainsSomewhere( | 388 pos = net::ExpectLogContainsSomewhere( |
| 401 entries, 0, | 389 entries, 0, |
| 402 net::NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED, | 390 net::NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED, |
| 403 net::NetLog::PHASE_NONE); | 391 net::NetLog::PHASE_NONE); |
| 404 EXPECT_LT(0, pos); | 392 EXPECT_LT(0, pos); |
| 405 | 393 |
| 406 int log_stream_id; | 394 int log_stream_id; |
| 407 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &log_stream_id)); | 395 ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &log_stream_id)); |
| 408 EXPECT_EQ(stream_id, static_cast<QuicStreamId>(log_stream_id)); | 396 EXPECT_EQ(3, log_stream_id); |
| 409 } | 397 } |
| 410 | 398 |
| 411 TEST_F(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { | 399 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
| 412 params_.origin_to_force_quic_on = | 400 params_.origin_to_force_quic_on = |
| 413 HostPortPair::FromString("www.google.com:80"); | 401 HostPortPair::FromString("www.google.com:80"); |
| 414 | 402 |
| 415 MockRead quic_reads[] = { | 403 MockQuicData mock_quic_data; |
| 416 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 404 mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 417 }; | 405 |
| 418 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 406 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 0); |
| 419 NULL, 0); | |
| 420 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 421 | 407 |
| 422 CreateSession(); | 408 CreateSession(); |
| 423 | 409 |
| 424 scoped_ptr<HttpNetworkTransaction> trans( | 410 scoped_ptr<HttpNetworkTransaction> trans( |
| 425 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 411 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 426 TestCompletionCallback callback; | 412 TestCompletionCallback callback; |
| 427 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 413 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 428 EXPECT_EQ(ERR_IO_PENDING, rv); | 414 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 429 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); | 415 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
| 430 } | 416 } |
| 431 | 417 |
| 432 TEST_F(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { | 418 TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
| 433 // Attempt to "force" quic on 443, which will not be honored. | 419 // Attempt to "force" quic on 443, which will not be honored. |
| 434 params_.origin_to_force_quic_on = | 420 params_.origin_to_force_quic_on = |
| 435 HostPortPair::FromString("www.google.com:443"); | 421 HostPortPair::FromString("www.google.com:443"); |
| 436 | 422 |
| 437 MockRead http_reads[] = { | 423 MockRead http_reads[] = { |
| 438 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 424 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 439 MockRead("hello world"), | 425 MockRead("hello world"), |
| 440 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 426 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 441 MockRead(ASYNC, OK) | 427 MockRead(ASYNC, OK) |
| 442 }; | 428 }; |
| 443 | 429 |
| 444 StaticSocketDataProvider data(http_reads, arraysize(http_reads), NULL, 0); | 430 StaticSocketDataProvider data(http_reads, arraysize(http_reads), NULL, 0); |
| 445 socket_factory_.AddSocketDataProvider(&data); | 431 socket_factory_.AddSocketDataProvider(&data); |
| 446 SSLSocketDataProvider ssl(ASYNC, OK); | 432 SSLSocketDataProvider ssl(ASYNC, OK); |
| 447 socket_factory_.AddSSLSocketDataProvider(&ssl); | 433 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 448 | 434 |
| 449 CreateSession(); | 435 CreateSession(); |
| 450 | 436 |
| 451 SendRequestAndExpectHttpResponse("hello world"); | 437 SendRequestAndExpectHttpResponse("hello world"); |
| 452 } | 438 } |
| 453 | 439 |
| 454 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { | 440 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
| 455 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 441 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 456 | 442 |
| 457 MockRead http_reads[] = { | 443 MockRead http_reads[] = { |
| 458 MockRead("HTTP/1.1 200 OK\r\n"), | 444 MockRead("HTTP/1.1 200 OK\r\n"), |
| 459 MockRead(kQuicAlternateProtocolHttpHeader), | 445 MockRead(kQuicAlternateProtocolHttpHeader), |
| 460 MockRead("hello world"), | 446 MockRead("hello world"), |
| 461 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 447 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 462 MockRead(ASYNC, OK) | 448 MockRead(ASYNC, OK) |
| 463 }; | 449 }; |
| 464 | 450 |
| 465 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 451 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 466 NULL, 0); | 452 NULL, 0); |
| 467 socket_factory_.AddSocketDataProvider(&http_data); | 453 socket_factory_.AddSocketDataProvider(&http_data); |
| 468 | 454 |
| 469 scoped_ptr<QuicEncryptedPacket> req( | 455 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
| 470 ConstructDataPacket(1, 3, true, true, 0, | 456 MockQuicData mock_quic_data; |
| 471 GetRequestString("GET", "http", "/"))); | 457 if (GetParam() > QUIC_VERSION_12) { |
| 472 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 458 mock_quic_data.AddWrite( |
| 459 ConstructRequestHeadersPacket(1, stream_id, true, true, |
| 460 GetRequestHeaders("GET", "http", "/"))); |
| 461 mock_quic_data.AddRead( |
| 462 ConstructResponseHeadersPacket(1, stream_id, false, false, |
| 463 GetResponseHeaders("200 OK"))); |
| 464 mock_quic_data.AddRead( |
| 465 ConstructDataPacket(2, stream_id, false, true, 0, "hello!")); |
| 466 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 467 } else { |
| 468 mock_quic_data.AddWrite( |
| 469 ConstructDataPacket(1, stream_id, true, true, 0, |
| 470 GetRequestString("GET", "http", "/"))); |
| 471 mock_quic_data.AddRead( |
| 472 ConstructDataPacket(1, stream_id, false, true, 0, |
| 473 GetResponseString("200 OK", "hello!"))); |
| 474 mock_quic_data.AddWrite(ConstructAckPacket(1, 0)); |
| 475 } |
| 476 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 473 | 477 |
| 474 MockWrite quic_writes[] = { | 478 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
| 475 MockWrite(SYNCHRONOUS, req->data(), req->length()), | |
| 476 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | |
| 477 }; | |
| 478 | |
| 479 scoped_ptr<QuicEncryptedPacket> resp( | |
| 480 ConstructDataPacket( | |
| 481 1, 3, false, true, 0, GetResponseString("200 OK", "hello!"))); | |
| 482 MockRead quic_reads[] = { | |
| 483 MockRead(SYNCHRONOUS, resp->data(), resp->length()), | |
| 484 MockRead(ASYNC, OK), // EOF | |
| 485 }; | |
| 486 | |
| 487 DelayedSocketData quic_data( | |
| 488 1, // wait for one write to finish before reading. | |
| 489 quic_reads, arraysize(quic_reads), | |
| 490 quic_writes, arraysize(quic_writes)); | |
| 491 | |
| 492 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 493 | 479 |
| 494 // The non-alternate protocol job needs to hang in order to guarantee that | 480 // The non-alternate protocol job needs to hang in order to guarantee that |
| 495 // the alternate-protocol job will "win". | 481 // the alternate-protocol job will "win". |
| 496 AddHangingNonAlternateProtocolSocketData(); | 482 AddHangingNonAlternateProtocolSocketData(); |
| 497 | 483 |
| 498 CreateSession(); | 484 CreateSession(); |
| 499 | 485 |
| 500 SendRequestAndExpectHttpResponse("hello world"); | 486 SendRequestAndExpectHttpResponse("hello world"); |
| 501 SendRequestAndExpectQuicResponse("hello!"); | 487 SendRequestAndExpectQuicResponse("hello!"); |
| 502 } | 488 } |
| 503 | 489 |
| 504 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { | 490 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
| 505 params_.origin_to_force_quic_on = | 491 params_.origin_to_force_quic_on = |
| 506 HostPortPair::FromString("www.google.com:443"); | 492 HostPortPair::FromString("www.google.com:443"); |
| 507 params_.enable_quic_https = true; | 493 params_.enable_quic_https = true; |
| 508 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 494 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 509 | 495 |
| 510 MockRead http_reads[] = { | 496 MockRead http_reads[] = { |
| 511 MockRead("HTTP/1.1 200 OK\r\n"), | 497 MockRead("HTTP/1.1 200 OK\r\n"), |
| 512 MockRead(kQuicAlternateProtocolHttpsHeader), | 498 MockRead(kQuicAlternateProtocolHttpsHeader), |
| 513 MockRead("hello world"), | 499 MockRead("hello world"), |
| 514 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 500 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 515 MockRead(ASYNC, OK) | 501 MockRead(ASYNC, OK) |
| 516 }; | 502 }; |
| 517 | 503 |
| 518 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 504 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 519 NULL, 0); | 505 NULL, 0); |
| 520 socket_factory_.AddSocketDataProvider(&http_data); | 506 socket_factory_.AddSocketDataProvider(&http_data); |
| 521 | 507 |
| 522 scoped_ptr<QuicEncryptedPacket> req( | 508 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
| 523 ConstructDataPacket(1, 3, true, true, 0, | 509 MockQuicData mock_quic_data; |
| 524 GetRequestString("GET", "https", "/"))); | 510 if (GetParam() > QUIC_VERSION_12) { |
| 525 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 511 mock_quic_data.AddWrite( |
| 512 ConstructRequestHeadersPacket(1, stream_id, true, true, |
| 513 GetRequestHeaders("GET", "http", "/"))); |
| 514 mock_quic_data.AddRead( |
| 515 ConstructResponseHeadersPacket(1, stream_id, false, false, |
| 516 GetResponseHeaders("200 OK"))); |
| 517 mock_quic_data.AddRead( |
| 518 ConstructDataPacket(2, stream_id, false, true, 0, "hello!")); |
| 519 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 520 } else { |
| 521 mock_quic_data.AddWrite( |
| 522 ConstructDataPacket(1, stream_id, true, true, 0, |
| 523 GetRequestString("GET", "http", "/"))); |
| 524 mock_quic_data.AddRead( |
| 525 ConstructDataPacket(1, stream_id, false, true, 0, |
| 526 GetResponseString("200 OK", "hello!"))); |
| 527 mock_quic_data.AddWrite(ConstructAckPacket(1, 0)); |
| 528 } |
| 529 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 526 | 530 |
| 527 MockWrite quic_writes[] = { | 531 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
| 528 MockWrite(SYNCHRONOUS, req->data(), req->length()), | |
| 529 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | |
| 530 }; | |
| 531 | |
| 532 scoped_ptr<QuicEncryptedPacket> resp( | |
| 533 ConstructDataPacket( | |
| 534 1, 3, false, true, 0, GetResponseString("200 OK", "hello!"))); | |
| 535 MockRead quic_reads[] = { | |
| 536 MockRead(SYNCHRONOUS, resp->data(), resp->length()), | |
| 537 MockRead(ASYNC, OK), // EOF | |
| 538 }; | |
| 539 | |
| 540 DelayedSocketData quic_data( | |
| 541 1, // wait for one write to finish before reading. | |
| 542 quic_reads, arraysize(quic_reads), | |
| 543 quic_writes, arraysize(quic_writes)); | |
| 544 | |
| 545 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 546 | 532 |
| 547 // The non-alternate protocol job needs to hang in order to guarantee that | 533 // The non-alternate protocol job needs to hang in order to guarantee that |
| 548 // the alternate-protocol job will "win". | 534 // the alternate-protocol job will "win". |
| 549 AddHangingNonAlternateProtocolSocketData(); | 535 AddHangingNonAlternateProtocolSocketData(); |
| 550 | 536 |
| 551 CreateSession(); | 537 CreateSession(); |
| 552 | 538 |
| 553 // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). | 539 // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 554 SendRequestAndExpectHttpResponse("hello world"); | 540 SendRequestAndExpectHttpResponse("hello world"); |
| 555 } | 541 } |
| 556 | 542 |
| 557 TEST_F(QuicNetworkTransactionTest, HungAlternateProtocol) { | 543 TEST_P(QuicNetworkTransactionTest, HungAlternateProtocol) { |
| 558 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 544 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 559 crypto_client_stream_factory_.set_handshake_mode( | 545 crypto_client_stream_factory_.set_handshake_mode( |
| 560 MockCryptoClientStream::COLD_START); | 546 MockCryptoClientStream::COLD_START); |
| 561 | 547 |
| 562 MockWrite http_writes[] = { | 548 MockWrite http_writes[] = { |
| 563 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), | 549 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 564 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), | 550 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 565 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") | 551 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 566 }; | 552 }; |
| 567 | 553 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 // and verify the the transaction continues over HTTP. | 592 // and verify the the transaction continues over HTTP. |
| 607 http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); | 593 http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 608 SendRequestAndExpectHttpResponse("hello world"); | 594 SendRequestAndExpectHttpResponse("hello world"); |
| 609 | 595 |
| 610 ASSERT_TRUE(http_data2.at_read_eof()); | 596 ASSERT_TRUE(http_data2.at_read_eof()); |
| 611 ASSERT_TRUE(http_data2.at_write_eof()); | 597 ASSERT_TRUE(http_data2.at_write_eof()); |
| 612 ASSERT_TRUE(!quic_data.at_read_eof()); | 598 ASSERT_TRUE(!quic_data.at_read_eof()); |
| 613 ASSERT_TRUE(!quic_data.at_write_eof()); | 599 ASSERT_TRUE(!quic_data.at_write_eof()); |
| 614 } | 600 } |
| 615 | 601 |
| 616 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { | 602 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { |
| 617 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 603 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 618 | 604 |
| 619 scoped_ptr<QuicEncryptedPacket> req( | 605 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
| 620 ConstructDataPacket(1, 3, true, true, 0, | 606 MockQuicData mock_quic_data; |
| 621 GetRequestString("GET", "http", "/"))); | 607 if (GetParam() > QUIC_VERSION_12) { |
| 622 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 608 mock_quic_data.AddWrite( |
| 609 ConstructRequestHeadersPacket(1, stream_id, true, true, |
| 610 GetRequestHeaders("GET", "http", "/"))); |
| 611 mock_quic_data.AddRead( |
| 612 ConstructResponseHeadersPacket(1, stream_id, false, false, |
| 613 GetResponseHeaders("200 OK"))); |
| 614 mock_quic_data.AddRead( |
| 615 ConstructDataPacket(2, stream_id, false, true, 0, "hello!")); |
| 616 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 617 } else { |
| 618 mock_quic_data.AddWrite( |
| 619 ConstructDataPacket(1, stream_id, true, true, 0, |
| 620 GetRequestString("GET", "http", "/"))); |
| 621 mock_quic_data.AddRead( |
| 622 ConstructDataPacket(1, stream_id, false, true, 0, |
| 623 GetResponseString("200 OK", "hello!"))); |
| 624 mock_quic_data.AddWrite(ConstructAckPacket(1, 0)); |
| 625 } |
| 626 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 623 | 627 |
| 624 MockWrite quic_writes[] = { | 628 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
| 625 MockWrite(SYNCHRONOUS, req->data(), req->length()), | |
| 626 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | |
| 627 }; | |
| 628 | |
| 629 scoped_ptr<QuicEncryptedPacket> resp( | |
| 630 ConstructDataPacket( | |
| 631 1, 3, false, true, 0, GetResponseString("200 OK", "hello!"))); | |
| 632 MockRead quic_reads[] = { | |
| 633 MockRead(SYNCHRONOUS, resp->data(), resp->length()), | |
| 634 MockRead(ASYNC, OK), // EOF | |
| 635 }; | |
| 636 | |
| 637 DelayedSocketData quic_data( | |
| 638 1, // wait for one write to finish before reading. | |
| 639 quic_reads, arraysize(quic_reads), | |
| 640 quic_writes, arraysize(quic_writes)); | |
| 641 | |
| 642 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 643 | 629 |
| 644 // The non-alternate protocol job needs to hang in order to guarantee that | 630 // The non-alternate protocol job needs to hang in order to guarantee that |
| 645 // the alternate-protocol job will "win". | 631 // the alternate-protocol job will "win". |
| 646 AddHangingNonAlternateProtocolSocketData(); | 632 AddHangingNonAlternateProtocolSocketData(); |
| 647 | 633 |
| 648 CreateSession(); | 634 CreateSession(); |
| 649 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 635 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 650 SendRequestAndExpectQuicResponse("hello!"); | 636 SendRequestAndExpectQuicResponse("hello!"); |
| 651 } | 637 } |
| 652 | 638 |
| 653 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { | 639 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
| 654 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 640 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 655 | 641 |
| 656 scoped_ptr<QuicEncryptedPacket> req( | 642 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
| 657 ConstructDataPacket(1, 3, true, true, 0, | 643 MockQuicData mock_quic_data; |
| 658 GetRequestString("GET", "http", "/"))); | 644 if (GetParam() > QUIC_VERSION_12) { |
| 659 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 645 mock_quic_data.AddWrite( |
| 660 | 646 ConstructRequestHeadersPacket(1, stream_id, true, true, |
| 661 MockWrite quic_writes[] = { | 647 GetRequestHeaders("GET", "http", "/"))); |
| 662 MockWrite(SYNCHRONOUS, req->data(), req->length()), | 648 mock_quic_data.AddRead( |
| 663 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | 649 ConstructResponseHeadersPacket(1, stream_id, false, false, |
| 664 }; | 650 GetResponseHeaders("200 OK"))); |
| 665 | 651 mock_quic_data.AddRead( |
| 666 scoped_ptr<QuicEncryptedPacket> resp( | 652 ConstructDataPacket(2, stream_id, false, true, 0, "hello!")); |
| 667 ConstructDataPacket( | 653 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 668 1, 3, false, true, 0, GetResponseString("200 OK", "hello!"))); | 654 } else { |
| 669 MockRead quic_reads[] = { | 655 mock_quic_data.AddWrite( |
| 670 MockRead(SYNCHRONOUS, resp->data(), resp->length()), | 656 ConstructDataPacket(1, stream_id, true, true, 0, |
| 671 MockRead(ASYNC, OK), // EOF | 657 GetRequestString("GET", "http", "/"))); |
| 672 }; | 658 mock_quic_data.AddRead( |
| 673 | 659 ConstructDataPacket(1, stream_id, false, true, 0, |
| 674 DelayedSocketData quic_data( | 660 GetResponseString("200 OK", "hello!"))); |
| 675 1, // wait for one write to finish before reading. | 661 mock_quic_data.AddWrite(ConstructAckPacket(1, 0)); |
| 676 quic_reads, arraysize(quic_reads), | 662 } |
| 677 quic_writes, arraysize(quic_writes)); | 663 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 678 | 664 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
| 679 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 680 | 665 |
| 681 // In order for a new QUIC session to be established via alternate-protocol | 666 // In order for a new QUIC session to be established via alternate-protocol |
| 682 // without racing an HTTP connection, we need the host resolution to happen | 667 // without racing an HTTP connection, we need the host resolution to happen |
| 683 // synchronously. | 668 // synchronously. |
| 684 host_resolver_.set_synchronous_mode(true); | 669 host_resolver_.set_synchronous_mode(true); |
| 685 host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); | 670 host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 686 HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); | 671 HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 687 AddressList address; | 672 AddressList address; |
| 688 host_resolver_.Resolve(info, | 673 host_resolver_.Resolve(info, |
| 689 DEFAULT_PRIORITY, | 674 DEFAULT_PRIORITY, |
| 690 &address, | 675 &address, |
| 691 CompletionCallback(), | 676 CompletionCallback(), |
| 692 NULL, | 677 NULL, |
| 693 net_log_.bound()); | 678 net_log_.bound()); |
| 694 | 679 |
| 695 CreateSession(); | 680 CreateSession(); |
| 696 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 681 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 697 SendRequestAndExpectQuicResponse("hello!"); | 682 SendRequestAndExpectQuicResponse("hello!"); |
| 698 } | 683 } |
| 699 | 684 |
| 700 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { | 685 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
| 701 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 686 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 702 | 687 |
| 703 scoped_ptr<QuicEncryptedPacket> req( | 688 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
| 704 ConstructDataPacket(1, 3, true, true, 0, | 689 MockQuicData mock_quic_data; |
| 705 GetRequestString("GET", "http", "/"))); | 690 if (GetParam() > QUIC_VERSION_12) { |
| 706 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 691 mock_quic_data.AddWrite( |
| 707 | 692 ConstructRequestHeadersPacket(1, stream_id, true, true, |
| 708 MockWrite quic_writes[] = { | 693 GetRequestHeaders("GET", "http", "/"))); |
| 709 MockWrite(SYNCHRONOUS, req->data(), req->length()), | 694 mock_quic_data.AddRead( |
| 710 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | 695 ConstructResponseHeadersPacket(1, stream_id, false, false, |
| 711 }; | 696 GetResponseHeaders("200 OK"))); |
| 712 | 697 mock_quic_data.AddRead( |
| 713 scoped_ptr<QuicEncryptedPacket> resp( | 698 ConstructDataPacket(2, stream_id, false, true, 0, "hello!")); |
| 714 ConstructDataPacket( | 699 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 715 1, 3, false, true, 0, GetResponseString("200 OK", "hello!"))); | 700 } else { |
| 716 MockRead quic_reads[] = { | 701 mock_quic_data.AddWrite( |
| 717 MockRead(SYNCHRONOUS, resp->data(), resp->length()), | 702 ConstructDataPacket(1, stream_id, true, true, 0, |
| 718 MockRead(ASYNC, OK), // EOF | 703 GetRequestString("GET", "http", "/"))); |
| 719 }; | 704 mock_quic_data.AddRead( |
| 720 | 705 ConstructDataPacket(1, stream_id, false, true, 0, |
| 721 DelayedSocketData quic_data( | 706 GetResponseString("200 OK", "hello!"))); |
| 722 1, // wait for one write to finish before reading. | 707 mock_quic_data.AddWrite(ConstructAckPacket(1, 0)); |
| 723 quic_reads, arraysize(quic_reads), | 708 } |
| 724 quic_writes, arraysize(quic_writes)); | 709 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 725 | 710 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
| 726 socket_factory_.AddSocketDataProvider(&quic_data); | |
| 727 | 711 |
| 728 // The non-alternate protocol job needs to hang in order to guarantee that | 712 // The non-alternate protocol job needs to hang in order to guarantee that |
| 729 // the alternate-protocol job will "win". | 713 // the alternate-protocol job will "win". |
| 730 AddHangingNonAlternateProtocolSocketData(); | 714 AddHangingNonAlternateProtocolSocketData(); |
| 731 | 715 |
| 732 // In order for a new QUIC session to be established via alternate-protocol | 716 // In order for a new QUIC session to be established via alternate-protocol |
| 733 // without racing an HTTP connection, we need the host resolution to happen | 717 // without racing an HTTP connection, we need the host resolution to happen |
| 734 // synchronously. Of course, even though QUIC *could* perform a 0-RTT | 718 // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 735 // connection to the the server, in this test we require confirmation | 719 // connection to the the server, in this test we require confirmation |
| 736 // before encrypting so the HTTP job will still start. | 720 // before encrypting so the HTTP job will still start. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 749 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 733 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 750 TestCompletionCallback callback; | 734 TestCompletionCallback callback; |
| 751 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 735 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 752 EXPECT_EQ(ERR_IO_PENDING, rv); | 736 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 753 | 737 |
| 754 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( | 738 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 755 QuicSession::HANDSHAKE_CONFIRMED); | 739 QuicSession::HANDSHAKE_CONFIRMED); |
| 756 EXPECT_EQ(OK, callback.WaitForResult()); | 740 EXPECT_EQ(OK, callback.WaitForResult()); |
| 757 } | 741 } |
| 758 | 742 |
| 759 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { | 743 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
| 760 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 744 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 761 | 745 |
| 762 // Alternate-protocol job | 746 // Alternate-protocol job |
| 763 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); | 747 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| 764 MockRead quic_reads[] = { | 748 MockRead quic_reads[] = { |
| 765 MockRead(ASYNC, close->data(), close->length()), | 749 MockRead(ASYNC, close->data(), close->length()), |
| 766 MockRead(ASYNC, OK), // EOF | 750 MockRead(ASYNC, OK), // EOF |
| 767 }; | 751 }; |
| 768 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 752 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
| 769 NULL, 0); | 753 NULL, 0); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 780 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 764 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 781 NULL, 0); | 765 NULL, 0); |
| 782 socket_factory_.AddSocketDataProvider(&http_data); | 766 socket_factory_.AddSocketDataProvider(&http_data); |
| 783 | 767 |
| 784 CreateSession(); | 768 CreateSession(); |
| 785 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 769 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 786 SendRequestAndExpectHttpResponse("hello from http"); | 770 SendRequestAndExpectHttpResponse("hello from http"); |
| 787 ExpectBrokenAlternateProtocolMapping(); | 771 ExpectBrokenAlternateProtocolMapping(); |
| 788 } | 772 } |
| 789 | 773 |
| 790 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { | 774 TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
| 791 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 775 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 792 | 776 |
| 793 // Alternate-protocol job | 777 // Alternate-protocol job |
| 794 MockRead quic_reads[] = { | 778 MockRead quic_reads[] = { |
| 795 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 779 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 796 }; | 780 }; |
| 797 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 781 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
| 798 NULL, 0); | 782 NULL, 0); |
| 799 socket_factory_.AddSocketDataProvider(&quic_data); | 783 socket_factory_.AddSocketDataProvider(&quic_data); |
| 800 | 784 |
| 801 // Main job which will succeed even though the alternate job fails. | 785 // Main job which will succeed even though the alternate job fails. |
| 802 MockRead http_reads[] = { | 786 MockRead http_reads[] = { |
| 803 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 787 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 804 MockRead("hello from http"), | 788 MockRead("hello from http"), |
| 805 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 789 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 806 MockRead(ASYNC, OK) | 790 MockRead(ASYNC, OK) |
| 807 }; | 791 }; |
| 808 | 792 |
| 809 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 793 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 810 NULL, 0); | 794 NULL, 0); |
| 811 socket_factory_.AddSocketDataProvider(&http_data); | 795 socket_factory_.AddSocketDataProvider(&http_data); |
| 812 | 796 |
| 813 CreateSession(); | 797 CreateSession(); |
| 814 | 798 |
| 815 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 799 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 816 SendRequestAndExpectHttpResponse("hello from http"); | 800 SendRequestAndExpectHttpResponse("hello from http"); |
| 817 ExpectBrokenAlternateProtocolMapping(); | 801 ExpectBrokenAlternateProtocolMapping(); |
| 818 } | 802 } |
| 819 | 803 |
| 820 TEST_F(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { | 804 TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { |
| 821 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. | 805 HttpStreamFactory::EnableNpnSpdy3(); // Enables QUIC too. |
| 822 | 806 |
| 823 // Alternate-protocol job | 807 // Alternate-protocol job |
| 824 MockRead quic_reads[] = { | 808 MockRead quic_reads[] = { |
| 825 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 809 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 826 }; | 810 }; |
| 827 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 811 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
| 828 NULL, 0); | 812 NULL, 0); |
| 829 socket_factory_.AddSocketDataProvider(&quic_data); | 813 socket_factory_.AddSocketDataProvider(&quic_data); |
| 830 | 814 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 849 SendRequestAndExpectHttpResponse("hello from http"); | 833 SendRequestAndExpectHttpResponse("hello from http"); |
| 850 | 834 |
| 851 ExpectBrokenAlternateProtocolMapping(); | 835 ExpectBrokenAlternateProtocolMapping(); |
| 852 | 836 |
| 853 EXPECT_TRUE(quic_data.at_read_eof()); | 837 EXPECT_TRUE(quic_data.at_read_eof()); |
| 854 EXPECT_TRUE(quic_data.at_write_eof()); | 838 EXPECT_TRUE(quic_data.at_write_eof()); |
| 855 } | 839 } |
| 856 | 840 |
| 857 } // namespace test | 841 } // namespace test |
| 858 } // namespace net | 842 } // namespace net |
| OLD | NEW |