[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 5 | #include <vector> |
| 6 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 7 | #include "base/basictypes.h" |
| 8 | #include "base/compiler_specific.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 10 | #include "base/stl_util.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 11 | #include "net/base/test_completion_callback.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 12 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 13 | #include "net/dns/mock_host_resolver.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 14 | #include "net/http/http_auth_handler_factory.h" |
| 15 | #include "net/http/http_network_session.h" |
| 16 | #include "net/http/http_network_transaction.h" |
| 17 | #include "net/http/http_server_properties_impl.h" |
| 18 | #include "net/http/http_stream.h" |
| 19 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 20 | #include "net/http/http_transaction_test_util.h" |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 21 | #include "net/http/transport_security_state.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 22 | #include "net/log/net_log_unittest.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 23 | #include "net/log/test_net_log.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 24 | #include "net/proxy/proxy_config_service_fixed.h" |
| 25 | #include "net/proxy/proxy_resolver.h" |
| 26 | #include "net/proxy/proxy_service.h" |
| 27 | #include "net/quic/crypto/quic_decrypter.h" |
| 28 | #include "net/quic/crypto/quic_encrypter.h" |
| 29 | #include "net/quic/quic_framer.h" |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 30 | #include "net/quic/quic_http_utils.h" |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 31 | #include "net/quic/test_tools/crypto_test_utils.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 32 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 33 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 34 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 35 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 36 | #include "net/quic/test_tools/quic_test_utils.h" |
| 37 | #include "net/socket/client_socket_factory.h" |
| 38 | #include "net/socket/mock_client_socket_pool_manager.h" |
| 39 | #include "net/socket/socket_test_util.h" |
| 40 | #include "net/socket/ssl_client_socket.h" |
| 41 | #include "net/spdy/spdy_frame_builder.h" |
| 42 | #include "net/spdy/spdy_framer.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 43 | #include "net/ssl/ssl_config_service_defaults.h" |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 44 | #include "testing/gtest/include/gtest/gtest.h" |
| 45 | #include "testing/platform_test.h" |
| 46 | |
| 47 | //----------------------------------------------------------------------------- |
| 48 | |
| 49 | namespace { |
| 50 | |
| 51 | // This is the expected return from a current server advertising QUIC. |
| 52 | static const char kQuicAlternateProtocolHttpHeader[] = |
[email protected] | 4ff6537 | 2013-06-21 05:45:46 | [diff] [blame] | 53 | "Alternate-Protocol: 80:quic\r\n\r\n"; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 54 | static const char kQuicAlternateProtocol50pctHttpHeader[] = |
| 55 | "Alternate-Protocol: 80:quic,p=.5\r\n\r\n"; |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 56 | static const char kQuicAlternateProtocolDifferentPortHttpHeader[] = |
| 57 | "Alternate-Protocol: 137:quic\r\n\r\n"; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 58 | static const char kQuicAlternateProtocolHttpsHeader[] = |
| 59 | "Alternate-Protocol: 443:quic\r\n\r\n"; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 60 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 61 | } // namespace |
| 62 | |
| 63 | namespace net { |
| 64 | namespace test { |
| 65 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 66 | // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 67 | // Simplify ownership issues and the interaction with the MockSocketFactory. |
| 68 | class MockQuicData { |
| 69 | public: |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 70 | MockQuicData() : sequence_number_(0) {} |
| 71 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 72 | ~MockQuicData() { |
| 73 | STLDeleteElements(&packets_); |
| 74 | } |
| 75 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 76 | void AddSynchronousRead(scoped_ptr<QuicEncryptedPacket> packet) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 77 | reads_.push_back(MockRead(SYNCHRONOUS, packet->data(), packet->length(), |
| 78 | sequence_number_++)); |
| 79 | packets_.push_back(packet.release()); |
| 80 | } |
| 81 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 82 | void AddRead(scoped_ptr<QuicEncryptedPacket> packet) { |
| 83 | reads_.push_back( |
| 84 | MockRead(ASYNC, packet->data(), packet->length(), sequence_number_++)); |
| 85 | packets_.push_back(packet.release()); |
| 86 | } |
| 87 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 88 | void AddRead(IoMode mode, int rv) { |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 89 | reads_.push_back(MockRead(mode, rv, sequence_number_++)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
| 93 | writes_.push_back(MockWrite(SYNCHRONOUS, packet->data(), packet->length(), |
| 94 | sequence_number_++)); |
| 95 | packets_.push_back(packet.release()); |
| 96 | } |
| 97 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 98 | void AddSocketDataToFactory(MockClientSocketFactory* factory) { |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 99 | MockRead* reads = reads_.empty() ? nullptr : &reads_[0]; |
| 100 | MockWrite* writes = writes_.empty() ? nullptr : &writes_[0]; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 101 | socket_data_.reset( |
| 102 | new SequencedSocketData(reads, reads_.size(), writes, writes_.size())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 103 | factory->AddSocketDataProvider(socket_data_.get()); |
| 104 | } |
| 105 | |
| 106 | private: |
| 107 | std::vector<QuicEncryptedPacket*> packets_; |
| 108 | std::vector<MockWrite> writes_; |
| 109 | std::vector<MockRead> reads_; |
| 110 | size_t sequence_number_; |
| 111 | scoped_ptr<SocketDataProvider> socket_data_; |
| 112 | }; |
| 113 | |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 114 | class ProxyHeadersHandler { |
| 115 | public: |
| 116 | ProxyHeadersHandler() : was_called_(false) {} |
| 117 | |
| 118 | bool was_called() { return was_called_; } |
| 119 | |
| 120 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 121 | HttpRequestHeaders* request_headers) { |
| 122 | was_called_ = true; |
| 123 | } |
| 124 | |
| 125 | private: |
| 126 | bool was_called_; |
| 127 | }; |
| 128 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 129 | class QuicNetworkTransactionTest |
| 130 | : public PlatformTest, |
[email protected] | 5d03bbd | 2014-03-07 16:19:16 | [diff] [blame] | 131 | public ::testing::WithParamInterface<QuicVersion> { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 132 | protected: |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 133 | QuicNetworkTransactionTest() |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 134 | : clock_(new MockClock), |
| 135 | maker_(GetParam(), 0, clock_), |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 136 | ssl_config_service_(new SSLConfigServiceDefaults), |
| 137 | proxy_service_(ProxyService::CreateDirect()), |
| 138 | auth_handler_factory_( |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 139 | HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 140 | random_generator_(0), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 141 | hanging_data_(nullptr, 0, nullptr, 0) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 142 | request_.method = "GET"; |
| 143 | request_.url = GURL("http://www.google.com/"); |
| 144 | request_.load_flags = 0; |
[email protected] | 98a9d125 | 2014-04-04 00:43:59 | [diff] [blame] | 145 | clock_->AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 146 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 147 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 148 | void SetUp() override { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 149 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 150 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 151 | } |
| 152 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 153 | void TearDown() override { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 154 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 155 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 156 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 157 | PlatformTest::TearDown(); |
| 158 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 159 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 162 | scoped_ptr<QuicEncryptedPacket> ConstructConnectionClosePacket( |
| 163 | QuicPacketSequenceNumber num) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 164 | return maker_.MakeConnectionClosePacket(num); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 167 | scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
| 168 | QuicPacketSequenceNumber largest_received, |
| 169 | QuicPacketSequenceNumber least_unacked) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 170 | return maker_.MakeAckPacket(2, largest_received, least_unacked, true); |
| 171 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 172 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 173 | SpdyHeaderBlock GetRequestHeaders(const std::string& method, |
| 174 | const std::string& scheme, |
| 175 | const std::string& path) { |
| 176 | return maker_.GetRequestHeaders(method, scheme, path); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 179 | SpdyHeaderBlock GetResponseHeaders(const std::string& status) { |
| 180 | return maker_.GetResponseHeaders(status); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 181 | } |
| 182 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 183 | scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 184 | QuicPacketSequenceNumber sequence_number, |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 185 | QuicStreamId stream_id, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 186 | bool should_include_version, |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 187 | bool fin, |
| 188 | QuicStreamOffset offset, |
| 189 | base::StringPiece data) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 190 | return maker_.MakeDataPacket( |
| 191 | sequence_number, stream_id, should_include_version, fin, offset, data); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 194 | scoped_ptr<QuicEncryptedPacket> ConstructRequestHeadersPacket( |
| 195 | QuicPacketSequenceNumber sequence_number, |
| 196 | QuicStreamId stream_id, |
| 197 | bool should_include_version, |
| 198 | bool fin, |
| 199 | const SpdyHeaderBlock& headers) { |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 200 | QuicPriority priority = |
| 201 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 202 | return maker_.MakeRequestHeadersPacket(sequence_number, stream_id, |
| 203 | should_include_version, fin, |
| 204 | priority, headers); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 207 | scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( |
| 208 | QuicPacketSequenceNumber sequence_number, |
| 209 | QuicStreamId stream_id, |
| 210 | bool should_include_version, |
| 211 | bool fin, |
| 212 | const SpdyHeaderBlock& headers) { |
| 213 | return maker_.MakeResponseHeadersPacket( |
| 214 | sequence_number, stream_id, should_include_version, fin, headers); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void CreateSession() { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 218 | CreateSessionWithFactory(&socket_factory_, false); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 219 | } |
| 220 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 221 | void CreateSessionWithNextProtos() { |
| 222 | CreateSessionWithFactory(&socket_factory_, true); |
| 223 | } |
| 224 | |
| 225 | // If |use_next_protos| is true, enables SPDY and QUIC. |
| 226 | void CreateSessionWithFactory(ClientSocketFactory* socket_factory, |
| 227 | bool use_next_protos) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 228 | params_.enable_quic = true; |
| 229 | params_.quic_clock = clock_; |
| 230 | params_.quic_random = &random_generator_; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 231 | params_.client_socket_factory = socket_factory; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 232 | params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 233 | params_.host_resolver = &host_resolver_; |
| 234 | params_.cert_verifier = &cert_verifier_; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 235 | params_.transport_security_state = &transport_security_state_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 236 | params_.proxy_service = proxy_service_.get(); |
| 237 | params_.ssl_config_service = ssl_config_service_.get(); |
| 238 | params_.http_auth_handler_factory = auth_handler_factory_.get(); |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 239 | params_.http_server_properties = http_server_properties.GetWeakPtr(); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 240 | params_.quic_supported_versions = SupportedVersions(GetParam()); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 241 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 242 | if (use_next_protos) { |
| 243 | params_.use_alternate_protocols = true; |
bnc | 3bb2c23 | 2014-11-07 20:26:39 | [diff] [blame] | 244 | params_.next_protos = NextProtosWithSpdyAndQuic(true, true); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 245 | } |
| 246 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 247 | session_ = new HttpNetworkSession(params_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 248 | session_->quic_stream_factory()->set_require_confirmation(false); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 249 | } |
| 250 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 251 | void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 253 | ASSERT_TRUE(response != nullptr); |
| 254 | ASSERT_TRUE(response->headers.get() != nullptr); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 255 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 256 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 257 | EXPECT_TRUE(response->was_npn_negotiated); |
| 258 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
| 259 | response->connection_info); |
| 260 | } |
| 261 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 262 | void CheckResponsePort(const scoped_ptr<HttpNetworkTransaction>& trans, |
| 263 | uint16 port) { |
| 264 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 265 | ASSERT_TRUE(response != nullptr); |
| 266 | EXPECT_EQ(port, response->socket_address.port()); |
| 267 | } |
| 268 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 269 | void CheckWasHttpResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 270 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 271 | ASSERT_TRUE(response != nullptr); |
| 272 | ASSERT_TRUE(response->headers.get() != nullptr); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 273 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 274 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 275 | EXPECT_FALSE(response->was_npn_negotiated); |
| 276 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 277 | response->connection_info); |
| 278 | } |
| 279 | |
| 280 | void CheckResponseData(HttpNetworkTransaction* trans, |
| 281 | const std::string& expected) { |
| 282 | std::string response_data; |
| 283 | ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
| 284 | EXPECT_EQ(expected, response_data); |
| 285 | } |
| 286 | |
| 287 | void RunTransaction(HttpNetworkTransaction* trans) { |
| 288 | TestCompletionCallback callback; |
| 289 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 290 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 291 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 292 | } |
| 293 | |
| 294 | void SendRequestAndExpectHttpResponse(const std::string& expected) { |
| 295 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 296 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 297 | RunTransaction(trans.get()); |
| 298 | CheckWasHttpResponse(trans); |
| 299 | CheckResponseData(trans.get(), expected); |
| 300 | } |
| 301 | |
| 302 | void SendRequestAndExpectQuicResponse(const std::string& expected) { |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 303 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, 80); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 304 | } |
| 305 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 306 | void SendRequestAndExpectQuicResponseOnPort(const std::string& expected, |
| 307 | uint16 port) { |
| 308 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, port); |
| 309 | } |
| 310 | |
| 311 | void SendRequestAndExpectQuicResponseFromProxyOnPort( |
| 312 | const std::string& expected, |
| 313 | uint16 port) { |
| 314 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void AddQuicAlternateProtocolMapping( |
| 318 | MockCryptoClientStream::HandshakeMode handshake_mode) { |
| 319 | crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 320 | HostPortPair host_port_pair = HostPortPair::FromURL(request_.url); |
| 321 | AlternativeService alternative_service(QUIC, host_port_pair.host(), 80); |
| 322 | session_->http_server_properties()->SetAlternativeService( |
| 323 | host_port_pair, alternative_service, 1.0); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | void ExpectBrokenAlternateProtocolMapping() { |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 327 | const HostPortPair origin = HostPortPair::FromURL(request_.url); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 328 | const AlternativeService alternative_service = |
| 329 | session_->http_server_properties()->GetAlternativeService(origin); |
| 330 | EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 331 | EXPECT_TRUE(session_->http_server_properties()->IsAlternativeServiceBroken( |
| 332 | alternative_service)); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 335 | void ExpectQuicAlternateProtocolMapping() { |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 336 | const AlternativeService alternative_service = |
| 337 | session_->http_server_properties()->GetAlternativeService( |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 338 | HostPortPair::FromURL(request_.url)); |
bnc | 181b39a | 2015-03-17 21:36:47 | [diff] [blame] | 339 | EXPECT_EQ(QUIC, alternative_service.protocol); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 342 | void AddHangingNonAlternateProtocolSocketData() { |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 343 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 344 | hanging_data_.set_connect_data(hanging_connect); |
| 345 | socket_factory_.AddSocketDataProvider(&hanging_data_); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 346 | } |
| 347 | |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 348 | MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 349 | QuicTestPacketMaker maker_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 350 | scoped_refptr<HttpNetworkSession> session_; |
| 351 | MockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 352 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 353 | MockHostResolver host_resolver_; |
| 354 | MockCertVerifier cert_verifier_; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 355 | TransportSecurityState transport_security_state_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 356 | scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 357 | scoped_ptr<ProxyService> proxy_service_; |
| 358 | scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 359 | MockRandom random_generator_; |
| 360 | HttpServerPropertiesImpl http_server_properties; |
| 361 | HttpNetworkSession::Params params_; |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 362 | HttpRequestInfo request_; |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 363 | BoundTestNetLog net_log_; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 364 | StaticSocketDataProvider hanging_data_; |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 365 | |
| 366 | private: |
| 367 | void SendRequestAndExpectQuicResponseMaybeFromProxy( |
| 368 | const std::string& expected, |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 369 | bool used_proxy, |
| 370 | uint16 port) { |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 371 | scoped_ptr<HttpNetworkTransaction> trans( |
| 372 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 373 | ProxyHeadersHandler proxy_headers_handler; |
| 374 | trans->SetBeforeProxyHeadersSentCallback( |
| 375 | base::Bind(&ProxyHeadersHandler::OnBeforeProxyHeadersSent, |
| 376 | base::Unretained(&proxy_headers_handler))); |
| 377 | RunTransaction(trans.get()); |
| 378 | CheckWasQuicResponse(trans); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 379 | CheckResponsePort(trans, port); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 380 | CheckResponseData(trans.get(), expected); |
| 381 | EXPECT_EQ(used_proxy, proxy_headers_handler.was_called()); |
| 382 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 383 | }; |
| 384 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 385 | INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, |
| 386 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 387 | |
| 388 | TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 389 | params_.origin_to_force_quic_on = |
| 390 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 391 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 392 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 393 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 394 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 395 | GetRequestHeaders("GET", "http", "/"))); |
| 396 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 397 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 398 | GetResponseHeaders("200 OK"))); |
| 399 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 400 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 401 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 402 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 403 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 404 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 405 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 406 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 407 | // the alternate-protocol job will "win". |
| 408 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 409 | |
| 410 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 411 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 412 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 413 | |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 414 | // Check that the NetLog was filled reasonably. |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 415 | net::TestNetLog::CapturedEntryList entries; |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 416 | net_log_.GetEntries(&entries); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 417 | EXPECT_LT(0u, entries.size()); |
| 418 | |
| 419 | // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
| 420 | int pos = net::ExpectLogContainsSomewhere( |
| 421 | entries, 0, |
| 422 | net::NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
| 423 | net::NetLog::PHASE_NONE); |
| 424 | EXPECT_LT(0, pos); |
| 425 | |
| 426 | // ... and also a TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED. |
| 427 | pos = net::ExpectLogContainsSomewhere( |
| 428 | entries, 0, |
| 429 | net::NetLog::TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED, |
| 430 | net::NetLog::PHASE_NONE); |
| 431 | EXPECT_LT(0, pos); |
| 432 | |
| 433 | std::string packet_sequence_number; |
| 434 | ASSERT_TRUE(entries[pos].GetStringValue( |
| 435 | "packet_sequence_number", &packet_sequence_number)); |
| 436 | EXPECT_EQ("1", packet_sequence_number); |
| 437 | |
| 438 | // ... and also a QUIC_SESSION_STREAM_FRAME_RECEIVED. |
| 439 | pos = net::ExpectLogContainsSomewhere( |
| 440 | entries, 0, |
| 441 | net::NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED, |
| 442 | net::NetLog::PHASE_NONE); |
| 443 | EXPECT_LT(0, pos); |
| 444 | |
| 445 | int log_stream_id; |
| 446 | ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &log_stream_id)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 447 | EXPECT_EQ(3, log_stream_id); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 448 | } |
| 449 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 450 | TEST_P(QuicNetworkTransactionTest, QuicProxy) { |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 451 | params_.enable_quic_for_proxies = true; |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 452 | proxy_service_.reset( |
| 453 | ProxyService::CreateFixedFromPacResult("QUIC myproxy:70")); |
| 454 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 455 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 456 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 457 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 458 | GetRequestHeaders("GET", "http", "/"))); |
| 459 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 460 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 461 | GetResponseHeaders("200 OK"))); |
| 462 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 463 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 464 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 465 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 466 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 467 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 468 | |
| 469 | // There is no need to set up an alternate protocol job, because |
| 470 | // no attempt will be made to speak to the proxy over TCP. |
| 471 | |
| 472 | CreateSession(); |
| 473 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 474 | SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 475 | } |
| 476 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 477 | TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 478 | params_.origin_to_force_quic_on = |
| 479 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 480 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 481 | MockQuicData mock_quic_data; |
| 482 | mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 483 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 484 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 485 | |
| 486 | CreateSession(); |
| 487 | |
| 488 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 489 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 490 | TestCompletionCallback callback; |
| 491 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 492 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 493 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 494 | } |
| 495 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 496 | TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 497 | // Attempt to "force" quic on 443, which will not be honored. |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 498 | params_.origin_to_force_quic_on = |
| 499 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 500 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 501 | MockRead http_reads[] = { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 502 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 503 | MockRead("hello world"), |
| 504 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 505 | MockRead(ASYNC, OK) |
| 506 | }; |
| 507 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 508 | StaticSocketDataProvider data(http_reads, arraysize(http_reads), nullptr, 0); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 509 | socket_factory_.AddSocketDataProvider(&data); |
| 510 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 511 | socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 512 | |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 513 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 514 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 515 | SendRequestAndExpectHttpResponse("hello world"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 518 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 519 | MockRead http_reads[] = { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 520 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 521 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 522 | MockRead("hello world"), |
| 523 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 524 | MockRead(ASYNC, OK) |
| 525 | }; |
| 526 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 527 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 528 | nullptr, 0); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 529 | socket_factory_.AddSocketDataProvider(&http_data); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 530 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 531 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 532 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 533 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 534 | GetRequestHeaders("GET", "http", "/"))); |
| 535 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 536 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 537 | GetResponseHeaders("200 OK"))); |
| 538 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 539 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 540 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 541 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 542 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 543 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 544 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 545 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 546 | // the alternate-protocol job will "win". |
| 547 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 548 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 549 | CreateSessionWithNextProtos(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 550 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 551 | SendRequestAndExpectHttpResponse("hello world"); |
| 552 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 553 | } |
| 554 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 555 | TEST_P(QuicNetworkTransactionTest, AlternateProtocolDifferentPort) { |
| 556 | MockRead http_reads[] = { |
| 557 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 558 | MockRead(kQuicAlternateProtocolDifferentPortHttpHeader), |
| 559 | MockRead("hello world"), |
| 560 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 561 | MockRead(ASYNC, OK)}; |
| 562 | |
| 563 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 564 | 0); |
| 565 | socket_factory_.AddSocketDataProvider(&http_data); |
| 566 | |
| 567 | MockQuicData mock_quic_data; |
| 568 | mock_quic_data.AddWrite( |
| 569 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 570 | GetRequestHeaders("GET", "http", "/"))); |
| 571 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 572 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 573 | mock_quic_data.AddRead( |
| 574 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 575 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 576 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 577 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 578 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 579 | |
| 580 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 581 | // the alternate-protocol job will "win". |
| 582 | AddHangingNonAlternateProtocolSocketData(); |
| 583 | |
| 584 | CreateSessionWithNextProtos(); |
| 585 | |
| 586 | SendRequestAndExpectHttpResponse("hello world"); |
| 587 | SendRequestAndExpectQuicResponseOnPort("hello!", 137); |
| 588 | } |
| 589 | |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 590 | TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) { |
| 591 | MockRead http_reads[] = { |
| 592 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 593 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 594 | MockRead("hello world"), |
| 595 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 596 | MockRead(ASYNC, OK)}; |
| 597 | |
| 598 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 599 | 0); |
| 600 | socket_factory_.AddSocketDataProvider(&http_data); |
| 601 | |
| 602 | MockQuicData mock_quic_data; |
| 603 | mock_quic_data.AddWrite( |
| 604 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 605 | GetRequestHeaders("GET", "http", "/"))); |
| 606 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 607 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 608 | mock_quic_data.AddRead( |
| 609 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 610 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 611 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 612 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 613 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 614 | |
| 615 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 616 | // the alternate-protocol job will "win". |
| 617 | AddHangingNonAlternateProtocolSocketData(); |
| 618 | |
| 619 | CreateSessionWithNextProtos(); |
| 620 | |
| 621 | AlternativeService alternative_service(QUIC, |
| 622 | HostPortPair::FromURL(request_.url)); |
| 623 | session_->http_server_properties()->MarkAlternativeServiceRecentlyBroken( |
| 624 | alternative_service); |
| 625 | EXPECT_TRUE( |
| 626 | session_->http_server_properties()->WasAlternativeServiceRecentlyBroken( |
| 627 | alternative_service)); |
| 628 | |
| 629 | SendRequestAndExpectHttpResponse("hello world"); |
| 630 | SendRequestAndExpectQuicResponse("hello!"); |
| 631 | |
| 632 | EXPECT_FALSE( |
| 633 | session_->http_server_properties()->WasAlternativeServiceRecentlyBroken( |
| 634 | alternative_service)); |
| 635 | } |
| 636 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 637 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { |
| 638 | MockRead http_reads[] = { |
| 639 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 640 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 641 | MockRead("hello world"), |
| 642 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 643 | MockRead(ASYNC, OK) |
| 644 | }; |
| 645 | |
| 646 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 647 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 648 | socket_factory_.AddSocketDataProvider(&http_data); |
| 649 | |
| 650 | MockQuicData mock_quic_data; |
| 651 | mock_quic_data.AddWrite( |
| 652 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 653 | GetRequestHeaders("GET", "http", "/"))); |
| 654 | mock_quic_data.AddRead( |
| 655 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
| 656 | GetResponseHeaders("200 OK"))); |
| 657 | mock_quic_data.AddRead( |
| 658 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 659 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 660 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 661 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 662 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 663 | |
| 664 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 665 | // the alternate-protocol job will "win". |
| 666 | AddHangingNonAlternateProtocolSocketData(); |
| 667 | |
| 668 | params_.alternate_protocol_probability_threshold = .25; |
| 669 | CreateSessionWithNextProtos(); |
| 670 | |
| 671 | SendRequestAndExpectHttpResponse("hello world"); |
| 672 | SendRequestAndExpectQuicResponse("hello!"); |
| 673 | } |
| 674 | |
| 675 | TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { |
| 676 | MockRead http_reads[] = { |
| 677 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 678 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 679 | MockRead("hello world"), |
| 680 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 681 | MockRead(ASYNC, OK) |
| 682 | }; |
| 683 | |
| 684 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 685 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 686 | socket_factory_.AddSocketDataProvider(&http_data); |
| 687 | socket_factory_.AddSocketDataProvider(&http_data); |
| 688 | |
| 689 | params_.alternate_protocol_probability_threshold = .75; |
| 690 | CreateSessionWithNextProtos(); |
| 691 | |
| 692 | SendRequestAndExpectHttpResponse("hello world"); |
| 693 | SendRequestAndExpectHttpResponse("hello world"); |
| 694 | } |
| 695 | |
| 696 | TEST_P(QuicNetworkTransactionTest, |
| 697 | DontUseAlternateProtocolWithBadProbabilityForQuic) { |
| 698 | MockRead http_reads[] = { |
| 699 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 700 | MockRead("Alternate-Protocol: 443:quic,p=2\r\n\r\n"), |
| 701 | MockRead("hello world"), |
| 702 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 703 | MockRead(ASYNC, OK) |
| 704 | }; |
| 705 | |
| 706 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 707 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 708 | socket_factory_.AddSocketDataProvider(&http_data); |
| 709 | socket_factory_.AddSocketDataProvider(&http_data); |
| 710 | |
| 711 | params_.alternate_protocol_probability_threshold = .75; |
| 712 | CreateSessionWithNextProtos(); |
| 713 | |
| 714 | SendRequestAndExpectHttpResponse("hello world"); |
| 715 | SendRequestAndExpectHttpResponse("hello world"); |
| 716 | } |
| 717 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 718 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 719 | params_.origin_to_force_quic_on = |
| 720 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 721 | |
| 722 | MockRead http_reads[] = { |
| 723 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 724 | MockRead(kQuicAlternateProtocolHttpsHeader), |
| 725 | MockRead("hello world"), |
| 726 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 727 | MockRead(ASYNC, OK) |
| 728 | }; |
| 729 | |
| 730 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 731 | nullptr, 0); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 732 | socket_factory_.AddSocketDataProvider(&http_data); |
| 733 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 734 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 735 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 736 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 737 | GetRequestHeaders("GET", "http", "/"))); |
| 738 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 739 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 740 | GetResponseHeaders("200 OK"))); |
| 741 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 742 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 743 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 744 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 745 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 746 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 747 | |
| 748 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 749 | // the alternate-protocol job will "win". |
| 750 | AddHangingNonAlternateProtocolSocketData(); |
| 751 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 752 | CreateSessionWithNextProtos(); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 753 | |
| 754 | // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 755 | SendRequestAndExpectHttpResponse("hello world"); |
| 756 | } |
| 757 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 758 | TEST_P(QuicNetworkTransactionTest, HungAlternateProtocol) { |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 759 | crypto_client_stream_factory_.set_handshake_mode( |
| 760 | MockCryptoClientStream::COLD_START); |
| 761 | |
| 762 | MockWrite http_writes[] = { |
| 763 | MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 764 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 765 | MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 766 | }; |
| 767 | |
| 768 | MockRead http_reads[] = { |
| 769 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 770 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 771 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 772 | MockRead(SYNCHRONOUS, OK, 6) |
| 773 | }; |
| 774 | |
| 775 | DeterministicMockClientSocketFactory socket_factory; |
| 776 | |
| 777 | DeterministicSocketData http_data(http_reads, arraysize(http_reads), |
| 778 | http_writes, arraysize(http_writes)); |
| 779 | socket_factory.AddSocketDataProvider(&http_data); |
| 780 | |
| 781 | // The QUIC transaction will not be allowed to complete. |
| 782 | MockWrite quic_writes[] = { |
| 783 | MockWrite(ASYNC, ERR_IO_PENDING, 0) |
| 784 | }; |
| 785 | MockRead quic_reads[] = { |
| 786 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 787 | }; |
| 788 | DeterministicSocketData quic_data(quic_reads, arraysize(quic_reads), |
| 789 | quic_writes, arraysize(quic_writes)); |
| 790 | socket_factory.AddSocketDataProvider(&quic_data); |
| 791 | |
| 792 | // The HTTP transaction will complete. |
| 793 | DeterministicSocketData http_data2(http_reads, arraysize(http_reads), |
| 794 | http_writes, arraysize(http_writes)); |
| 795 | socket_factory.AddSocketDataProvider(&http_data2); |
| 796 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 797 | CreateSessionWithFactory(&socket_factory, true); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 798 | |
| 799 | // Run the first request. |
| 800 | http_data.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 801 | SendRequestAndExpectHttpResponse("hello world"); |
| 802 | ASSERT_TRUE(http_data.at_read_eof()); |
| 803 | ASSERT_TRUE(http_data.at_write_eof()); |
| 804 | |
| 805 | // Now run the second request in which the QUIC socket hangs, |
| 806 | // and verify the the transaction continues over HTTP. |
| 807 | http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 808 | SendRequestAndExpectHttpResponse("hello world"); |
| 809 | |
| 810 | ASSERT_TRUE(http_data2.at_read_eof()); |
| 811 | ASSERT_TRUE(http_data2.at_write_eof()); |
| 812 | ASSERT_TRUE(!quic_data.at_read_eof()); |
| 813 | ASSERT_TRUE(!quic_data.at_write_eof()); |
| 814 | } |
| 815 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 816 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 817 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 818 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 819 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 820 | GetRequestHeaders("GET", "http", "/"))); |
| 821 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 822 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 823 | GetResponseHeaders("200 OK"))); |
| 824 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 825 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 826 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 827 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 828 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 829 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 830 | |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 831 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 832 | // the alternate-protocol job will "win". |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 833 | AddHangingNonAlternateProtocolSocketData(); |
| 834 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 835 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 836 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 837 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 838 | } |
| 839 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 840 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 841 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 842 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 843 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 844 | GetRequestHeaders("GET", "http", "/"))); |
| 845 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 846 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 847 | GetResponseHeaders("200 OK"))); |
| 848 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 849 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 850 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 851 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 852 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 853 | |
| 854 | // In order for a new QUIC session to be established via alternate-protocol |
| 855 | // without racing an HTTP connection, we need the host resolution to happen |
| 856 | // synchronously. |
| 857 | host_resolver_.set_synchronous_mode(true); |
| 858 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 859 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 860 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 861 | host_resolver_.Resolve(info, |
| 862 | DEFAULT_PRIORITY, |
| 863 | &address, |
| 864 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 865 | nullptr, |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 866 | net_log_.bound()); |
| 867 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 868 | CreateSessionWithNextProtos(); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 869 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 870 | SendRequestAndExpectQuicResponse("hello!"); |
| 871 | } |
| 872 | |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 873 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { |
| 874 | proxy_service_.reset( |
| 875 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 876 | |
| 877 | // Since we are using a proxy, the QUIC job will not succeed. |
| 878 | MockWrite http_writes[] = { |
| 879 | MockWrite(SYNCHRONOUS, 0, "GET http://www.google.com/ HTTP/1.1\r\n"), |
| 880 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 881 | MockWrite(SYNCHRONOUS, 2, "Proxy-Connection: keep-alive\r\n\r\n") |
| 882 | }; |
| 883 | |
| 884 | MockRead http_reads[] = { |
| 885 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 886 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 887 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 888 | MockRead(SYNCHRONOUS, OK, 6) |
| 889 | }; |
| 890 | |
| 891 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 892 | http_writes, arraysize(http_writes)); |
| 893 | socket_factory_.AddSocketDataProvider(&http_data); |
| 894 | |
| 895 | // In order for a new QUIC session to be established via alternate-protocol |
| 896 | // without racing an HTTP connection, we need the host resolution to happen |
| 897 | // synchronously. |
| 898 | host_resolver_.set_synchronous_mode(true); |
| 899 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 900 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 901 | AddressList address; |
| 902 | host_resolver_.Resolve(info, |
| 903 | DEFAULT_PRIORITY, |
| 904 | &address, |
| 905 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 906 | nullptr, |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 907 | net_log_.bound()); |
| 908 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 909 | CreateSessionWithNextProtos(); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 910 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 911 | SendRequestAndExpectHttpResponse("hello world"); |
| 912 | } |
| 913 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 914 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 915 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 916 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 917 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 918 | GetRequestHeaders("GET", "http", "/"))); |
| 919 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 920 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 921 | GetResponseHeaders("200 OK"))); |
| 922 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 923 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 924 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 925 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 926 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 927 | |
| 928 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 929 | // the alternate-protocol job will "win". |
| 930 | AddHangingNonAlternateProtocolSocketData(); |
| 931 | |
| 932 | // In order for a new QUIC session to be established via alternate-protocol |
| 933 | // without racing an HTTP connection, we need the host resolution to happen |
| 934 | // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 935 | // connection to the the server, in this test we require confirmation |
| 936 | // before encrypting so the HTTP job will still start. |
| 937 | host_resolver_.set_synchronous_mode(true); |
| 938 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 939 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 940 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 941 | host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 942 | CompletionCallback(), nullptr, net_log_.bound()); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 943 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 944 | CreateSessionWithNextProtos(); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 945 | session_->quic_stream_factory()->set_require_confirmation(true); |
| 946 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 947 | |
| 948 | scoped_ptr<HttpNetworkTransaction> trans( |
| 949 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 950 | TestCompletionCallback callback; |
| 951 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 952 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 953 | |
| 954 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 955 | QuicSession::HANDSHAKE_CONFIRMED); |
| 956 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 957 | } |
| 958 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 959 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 960 | // Alternate-protocol job |
| 961 | scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| 962 | MockRead quic_reads[] = { |
| 963 | MockRead(ASYNC, close->data(), close->length()), |
| 964 | MockRead(ASYNC, OK), // EOF |
| 965 | }; |
| 966 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 967 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 968 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 969 | |
| 970 | // Main job which will succeed even though the alternate job fails. |
| 971 | MockRead http_reads[] = { |
| 972 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 973 | MockRead("hello from http"), |
| 974 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 975 | MockRead(ASYNC, OK) |
| 976 | }; |
| 977 | |
| 978 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 979 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 980 | socket_factory_.AddSocketDataProvider(&http_data); |
| 981 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 982 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 983 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 984 | SendRequestAndExpectHttpResponse("hello from http"); |
| 985 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 986 | } |
| 987 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 988 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 989 | // Alternate-protocol job |
| 990 | MockRead quic_reads[] = { |
| 991 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 992 | }; |
| 993 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 994 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 995 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 996 | |
| 997 | // Main job which will succeed even though the alternate job fails. |
| 998 | MockRead http_reads[] = { |
| 999 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1000 | MockRead("hello from http"), |
| 1001 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1002 | MockRead(ASYNC, OK) |
| 1003 | }; |
| 1004 | |
| 1005 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1006 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1007 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1008 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1009 | CreateSessionWithNextProtos(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1010 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1011 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1012 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1013 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1014 | } |
| 1015 | |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1016 | TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1017 | // Alternate-protocol job will fail when the session attempts to read. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1018 | MockRead quic_reads[] = { |
| 1019 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1020 | }; |
| 1021 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1022 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1023 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1024 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1025 | // Main job will also fail. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1026 | MockRead http_reads[] = { |
| 1027 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1028 | }; |
| 1029 | |
| 1030 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1031 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1032 | http_data.set_connect_data(MockConnect(ASYNC, ERR_SOCKET_NOT_CONNECTED)); |
| 1033 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1034 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1035 | CreateSessionWithNextProtos(); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1036 | |
| 1037 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1038 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1039 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1040 | TestCompletionCallback callback; |
| 1041 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1042 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1043 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); |
| 1044 | ExpectQuicAlternateProtocolMapping(); |
| 1045 | } |
| 1046 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1047 | TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1048 | // Alternate-protocol job |
| 1049 | MockRead quic_reads[] = { |
| 1050 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1051 | }; |
| 1052 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1053 | nullptr, 0); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1054 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1055 | |
| 1056 | AddHangingNonAlternateProtocolSocketData(); |
| 1057 | |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1058 | // Second Alternate-protocol job which will race with the TCP job. |
| 1059 | StaticSocketDataProvider quic_data2(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1060 | nullptr, 0); |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1061 | socket_factory_.AddSocketDataProvider(&quic_data2); |
| 1062 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1063 | // Final job that will proceed when the QUIC job fails. |
| 1064 | MockRead http_reads[] = { |
| 1065 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1066 | MockRead("hello from http"), |
| 1067 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1068 | MockRead(ASYNC, OK) |
| 1069 | }; |
| 1070 | |
| 1071 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1072 | nullptr, 0); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1073 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1074 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1075 | CreateSessionWithNextProtos(); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1076 | |
| 1077 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1078 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1079 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1080 | |
| 1081 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1082 | |
| 1083 | EXPECT_TRUE(quic_data.at_read_eof()); |
| 1084 | EXPECT_TRUE(quic_data.at_write_eof()); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1085 | } |
| 1086 | |
[email protected] | 93b3177 | 2014-06-19 08:03:35 | [diff] [blame] | 1087 | TEST_P(QuicNetworkTransactionTest, DISABLED_HangingZeroRttFallback) { |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1088 | // Alternate-protocol job |
| 1089 | MockRead quic_reads[] = { |
| 1090 | MockRead(ASYNC, ERR_IO_PENDING), |
| 1091 | }; |
| 1092 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1093 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1094 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1095 | |
| 1096 | // Main job that will proceed when the QUIC job fails. |
| 1097 | MockRead http_reads[] = { |
| 1098 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1099 | MockRead("hello from http"), |
| 1100 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1101 | MockRead(ASYNC, OK) |
| 1102 | }; |
| 1103 | |
| 1104 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1105 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1106 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1107 | |
| 1108 | CreateSessionWithNextProtos(); |
| 1109 | |
| 1110 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1111 | |
| 1112 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1113 | } |
| 1114 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1115 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1116 | // Alternate-protocol job will fail before creating a QUIC session. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1117 | StaticSocketDataProvider quic_data(nullptr, 0, nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1118 | quic_data.set_connect_data(MockConnect(SYNCHRONOUS, |
| 1119 | ERR_INTERNET_DISCONNECTED)); |
| 1120 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1121 | |
| 1122 | // Main job which will succeed even though the alternate job fails. |
| 1123 | MockRead http_reads[] = { |
| 1124 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1125 | MockRead("hello from http"), |
| 1126 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1127 | MockRead(ASYNC, OK) |
| 1128 | }; |
| 1129 | |
| 1130 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1131 | nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1132 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1133 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1134 | CreateSessionWithNextProtos(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1135 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1136 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1137 | |
| 1138 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1139 | } |
| 1140 | |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1141 | TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1142 | MockQuicData mock_quic_data; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 1143 | mock_quic_data.AddSynchronousRead(ConstructConnectionClosePacket(1)); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1144 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1145 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1146 | GetRequestHeaders("GET", "http", "/"))); |
| 1147 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame^] | 1148 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1149 | |
| 1150 | // When the QUIC connection fails, we will try the request again over HTTP. |
| 1151 | MockRead http_reads[] = { |
| 1152 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1153 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 1154 | MockRead("hello world"), |
| 1155 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1156 | MockRead(ASYNC, OK) |
| 1157 | }; |
| 1158 | |
| 1159 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1160 | nullptr, 0); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1161 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1162 | |
| 1163 | // In order for a new QUIC session to be established via alternate-protocol |
| 1164 | // without racing an HTTP connection, we need the host resolution to happen |
| 1165 | // synchronously. |
| 1166 | host_resolver_.set_synchronous_mode(true); |
| 1167 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 1168 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 1169 | AddressList address; |
| 1170 | host_resolver_.Resolve(info, |
| 1171 | DEFAULT_PRIORITY, |
| 1172 | &address, |
| 1173 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1174 | nullptr, |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1175 | net_log_.bound()); |
| 1176 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1177 | CreateSessionWithNextProtos(); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1178 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1179 | SendRequestAndExpectHttpResponse("hello world"); |
| 1180 | } |
| 1181 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 1182 | } // namespace test |
| 1183 | } // namespace net |