[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. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame^] | 415 | 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. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame^] | 420 | int pos = ExpectLogContainsSomewhere( |
| 421 | entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
| 422 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 423 | EXPECT_LT(0, pos); |
| 424 | |
| 425 | // ... and also a TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame^] | 426 | pos = ExpectLogContainsSomewhere( |
| 427 | entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED, |
| 428 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 429 | EXPECT_LT(0, pos); |
| 430 | |
| 431 | std::string packet_sequence_number; |
| 432 | ASSERT_TRUE(entries[pos].GetStringValue( |
| 433 | "packet_sequence_number", &packet_sequence_number)); |
| 434 | EXPECT_EQ("1", packet_sequence_number); |
| 435 | |
| 436 | // ... and also a QUIC_SESSION_STREAM_FRAME_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame^] | 437 | pos = ExpectLogContainsSomewhere( |
| 438 | entries, 0, NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED, |
| 439 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 440 | EXPECT_LT(0, pos); |
| 441 | |
| 442 | int log_stream_id; |
| 443 | ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &log_stream_id)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 444 | EXPECT_EQ(3, log_stream_id); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 445 | } |
| 446 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 447 | TEST_P(QuicNetworkTransactionTest, QuicProxy) { |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 448 | params_.enable_quic_for_proxies = true; |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 449 | proxy_service_.reset( |
| 450 | ProxyService::CreateFixedFromPacResult("QUIC myproxy:70")); |
| 451 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 452 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 453 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 454 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 455 | GetRequestHeaders("GET", "http", "/"))); |
| 456 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 457 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 458 | GetResponseHeaders("200 OK"))); |
| 459 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 460 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 461 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 462 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 463 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 464 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 465 | |
| 466 | // There is no need to set up an alternate protocol job, because |
| 467 | // no attempt will be made to speak to the proxy over TCP. |
| 468 | |
| 469 | CreateSession(); |
| 470 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 471 | SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 472 | } |
| 473 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 474 | TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 475 | params_.origin_to_force_quic_on = |
| 476 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 477 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 478 | MockQuicData mock_quic_data; |
| 479 | mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 480 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 481 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 482 | |
| 483 | CreateSession(); |
| 484 | |
| 485 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 486 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 487 | TestCompletionCallback callback; |
| 488 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 489 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 490 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 491 | } |
| 492 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 493 | TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 494 | // Attempt to "force" quic on 443, which will not be honored. |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 495 | params_.origin_to_force_quic_on = |
| 496 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 497 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 498 | MockRead http_reads[] = { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 499 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 500 | MockRead("hello world"), |
| 501 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 502 | MockRead(ASYNC, OK) |
| 503 | }; |
| 504 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 505 | StaticSocketDataProvider data(http_reads, arraysize(http_reads), nullptr, 0); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 506 | socket_factory_.AddSocketDataProvider(&data); |
| 507 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 508 | socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 509 | |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 510 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 511 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 512 | SendRequestAndExpectHttpResponse("hello world"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 513 | } |
| 514 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 515 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 516 | MockRead http_reads[] = { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 517 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 518 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 519 | MockRead("hello world"), |
| 520 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 521 | MockRead(ASYNC, OK) |
| 522 | }; |
| 523 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 524 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 525 | nullptr, 0); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 526 | socket_factory_.AddSocketDataProvider(&http_data); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 527 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 528 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 529 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 530 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 531 | GetRequestHeaders("GET", "http", "/"))); |
| 532 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 533 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 534 | GetResponseHeaders("200 OK"))); |
| 535 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 536 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 537 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 538 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 539 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 540 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 541 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 542 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 543 | // the alternate-protocol job will "win". |
| 544 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 545 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 546 | CreateSessionWithNextProtos(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 547 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 548 | SendRequestAndExpectHttpResponse("hello world"); |
| 549 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 550 | } |
| 551 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 552 | TEST_P(QuicNetworkTransactionTest, AlternateProtocolDifferentPort) { |
| 553 | MockRead http_reads[] = { |
| 554 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 555 | MockRead(kQuicAlternateProtocolDifferentPortHttpHeader), |
| 556 | MockRead("hello world"), |
| 557 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 558 | MockRead(ASYNC, OK)}; |
| 559 | |
| 560 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 561 | 0); |
| 562 | socket_factory_.AddSocketDataProvider(&http_data); |
| 563 | |
| 564 | MockQuicData mock_quic_data; |
| 565 | mock_quic_data.AddWrite( |
| 566 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 567 | GetRequestHeaders("GET", "http", "/"))); |
| 568 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 569 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 570 | mock_quic_data.AddRead( |
| 571 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 572 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 573 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 574 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 575 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 576 | |
| 577 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 578 | // the alternate-protocol job will "win". |
| 579 | AddHangingNonAlternateProtocolSocketData(); |
| 580 | |
| 581 | CreateSessionWithNextProtos(); |
| 582 | |
| 583 | SendRequestAndExpectHttpResponse("hello world"); |
| 584 | SendRequestAndExpectQuicResponseOnPort("hello!", 137); |
| 585 | } |
| 586 | |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 587 | TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) { |
| 588 | MockRead http_reads[] = { |
| 589 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 590 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 591 | MockRead("hello world"), |
| 592 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 593 | MockRead(ASYNC, OK)}; |
| 594 | |
| 595 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 596 | 0); |
| 597 | socket_factory_.AddSocketDataProvider(&http_data); |
| 598 | |
| 599 | MockQuicData mock_quic_data; |
| 600 | mock_quic_data.AddWrite( |
| 601 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 602 | GetRequestHeaders("GET", "http", "/"))); |
| 603 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 604 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 605 | mock_quic_data.AddRead( |
| 606 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 607 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 608 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 609 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 610 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 611 | |
| 612 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 613 | // the alternate-protocol job will "win". |
| 614 | AddHangingNonAlternateProtocolSocketData(); |
| 615 | |
| 616 | CreateSessionWithNextProtos(); |
| 617 | |
| 618 | AlternativeService alternative_service(QUIC, |
| 619 | HostPortPair::FromURL(request_.url)); |
| 620 | session_->http_server_properties()->MarkAlternativeServiceRecentlyBroken( |
| 621 | alternative_service); |
| 622 | EXPECT_TRUE( |
| 623 | session_->http_server_properties()->WasAlternativeServiceRecentlyBroken( |
| 624 | alternative_service)); |
| 625 | |
| 626 | SendRequestAndExpectHttpResponse("hello world"); |
| 627 | SendRequestAndExpectQuicResponse("hello!"); |
| 628 | |
| 629 | EXPECT_FALSE( |
| 630 | session_->http_server_properties()->WasAlternativeServiceRecentlyBroken( |
| 631 | alternative_service)); |
| 632 | } |
| 633 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 634 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { |
| 635 | MockRead http_reads[] = { |
| 636 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 637 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 638 | MockRead("hello world"), |
| 639 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 640 | MockRead(ASYNC, OK) |
| 641 | }; |
| 642 | |
| 643 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 644 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 645 | socket_factory_.AddSocketDataProvider(&http_data); |
| 646 | |
| 647 | MockQuicData mock_quic_data; |
| 648 | mock_quic_data.AddWrite( |
| 649 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 650 | GetRequestHeaders("GET", "http", "/"))); |
| 651 | mock_quic_data.AddRead( |
| 652 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
| 653 | GetResponseHeaders("200 OK"))); |
| 654 | mock_quic_data.AddRead( |
| 655 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 656 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 657 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 658 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 659 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 660 | |
| 661 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 662 | // the alternate-protocol job will "win". |
| 663 | AddHangingNonAlternateProtocolSocketData(); |
| 664 | |
| 665 | params_.alternate_protocol_probability_threshold = .25; |
| 666 | CreateSessionWithNextProtos(); |
| 667 | |
| 668 | SendRequestAndExpectHttpResponse("hello world"); |
| 669 | SendRequestAndExpectQuicResponse("hello!"); |
| 670 | } |
| 671 | |
| 672 | TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { |
| 673 | MockRead http_reads[] = { |
| 674 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 675 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 676 | MockRead("hello world"), |
| 677 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 678 | MockRead(ASYNC, OK) |
| 679 | }; |
| 680 | |
| 681 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 682 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 683 | socket_factory_.AddSocketDataProvider(&http_data); |
| 684 | socket_factory_.AddSocketDataProvider(&http_data); |
| 685 | |
| 686 | params_.alternate_protocol_probability_threshold = .75; |
| 687 | CreateSessionWithNextProtos(); |
| 688 | |
| 689 | SendRequestAndExpectHttpResponse("hello world"); |
| 690 | SendRequestAndExpectHttpResponse("hello world"); |
| 691 | } |
| 692 | |
| 693 | TEST_P(QuicNetworkTransactionTest, |
| 694 | DontUseAlternateProtocolWithBadProbabilityForQuic) { |
| 695 | MockRead http_reads[] = { |
| 696 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 697 | MockRead("Alternate-Protocol: 443:quic,p=2\r\n\r\n"), |
| 698 | MockRead("hello world"), |
| 699 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 700 | MockRead(ASYNC, OK) |
| 701 | }; |
| 702 | |
| 703 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 704 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 705 | socket_factory_.AddSocketDataProvider(&http_data); |
| 706 | socket_factory_.AddSocketDataProvider(&http_data); |
| 707 | |
| 708 | params_.alternate_protocol_probability_threshold = .75; |
| 709 | CreateSessionWithNextProtos(); |
| 710 | |
| 711 | SendRequestAndExpectHttpResponse("hello world"); |
| 712 | SendRequestAndExpectHttpResponse("hello world"); |
| 713 | } |
| 714 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 715 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 716 | params_.origin_to_force_quic_on = |
| 717 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 718 | |
| 719 | MockRead http_reads[] = { |
| 720 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 721 | MockRead(kQuicAlternateProtocolHttpsHeader), |
| 722 | MockRead("hello world"), |
| 723 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 724 | MockRead(ASYNC, OK) |
| 725 | }; |
| 726 | |
| 727 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 728 | nullptr, 0); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 729 | socket_factory_.AddSocketDataProvider(&http_data); |
| 730 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 731 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 732 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 733 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 734 | GetRequestHeaders("GET", "http", "/"))); |
| 735 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 736 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 737 | GetResponseHeaders("200 OK"))); |
| 738 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 739 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 740 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 741 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 742 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 743 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 744 | |
| 745 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 746 | // the alternate-protocol job will "win". |
| 747 | AddHangingNonAlternateProtocolSocketData(); |
| 748 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 749 | CreateSessionWithNextProtos(); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 750 | |
| 751 | // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 752 | SendRequestAndExpectHttpResponse("hello world"); |
| 753 | } |
| 754 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 755 | TEST_P(QuicNetworkTransactionTest, HungAlternateProtocol) { |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 756 | crypto_client_stream_factory_.set_handshake_mode( |
| 757 | MockCryptoClientStream::COLD_START); |
| 758 | |
| 759 | MockWrite http_writes[] = { |
| 760 | MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 761 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 762 | MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 763 | }; |
| 764 | |
| 765 | MockRead http_reads[] = { |
| 766 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 767 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 768 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 769 | MockRead(SYNCHRONOUS, OK, 6) |
| 770 | }; |
| 771 | |
| 772 | DeterministicMockClientSocketFactory socket_factory; |
| 773 | |
| 774 | DeterministicSocketData http_data(http_reads, arraysize(http_reads), |
| 775 | http_writes, arraysize(http_writes)); |
| 776 | socket_factory.AddSocketDataProvider(&http_data); |
| 777 | |
| 778 | // The QUIC transaction will not be allowed to complete. |
| 779 | MockWrite quic_writes[] = { |
| 780 | MockWrite(ASYNC, ERR_IO_PENDING, 0) |
| 781 | }; |
| 782 | MockRead quic_reads[] = { |
| 783 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 784 | }; |
| 785 | DeterministicSocketData quic_data(quic_reads, arraysize(quic_reads), |
| 786 | quic_writes, arraysize(quic_writes)); |
| 787 | socket_factory.AddSocketDataProvider(&quic_data); |
| 788 | |
| 789 | // The HTTP transaction will complete. |
| 790 | DeterministicSocketData http_data2(http_reads, arraysize(http_reads), |
| 791 | http_writes, arraysize(http_writes)); |
| 792 | socket_factory.AddSocketDataProvider(&http_data2); |
| 793 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 794 | CreateSessionWithFactory(&socket_factory, true); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 795 | |
| 796 | // Run the first request. |
| 797 | http_data.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 798 | SendRequestAndExpectHttpResponse("hello world"); |
| 799 | ASSERT_TRUE(http_data.at_read_eof()); |
| 800 | ASSERT_TRUE(http_data.at_write_eof()); |
| 801 | |
| 802 | // Now run the second request in which the QUIC socket hangs, |
| 803 | // and verify the the transaction continues over HTTP. |
| 804 | http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 805 | SendRequestAndExpectHttpResponse("hello world"); |
| 806 | |
| 807 | ASSERT_TRUE(http_data2.at_read_eof()); |
| 808 | ASSERT_TRUE(http_data2.at_write_eof()); |
| 809 | ASSERT_TRUE(!quic_data.at_read_eof()); |
| 810 | ASSERT_TRUE(!quic_data.at_write_eof()); |
| 811 | } |
| 812 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 813 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 814 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 815 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 816 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 817 | GetRequestHeaders("GET", "http", "/"))); |
| 818 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 819 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 820 | GetResponseHeaders("200 OK"))); |
| 821 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 822 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 823 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 824 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 825 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 826 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 827 | |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 828 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 829 | // the alternate-protocol job will "win". |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 830 | AddHangingNonAlternateProtocolSocketData(); |
| 831 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 832 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 833 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 834 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 835 | } |
| 836 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 837 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 838 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 839 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 840 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 841 | GetRequestHeaders("GET", "http", "/"))); |
| 842 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 843 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 844 | GetResponseHeaders("200 OK"))); |
| 845 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 846 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 847 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 848 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 849 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 850 | |
| 851 | // In order for a new QUIC session to be established via alternate-protocol |
| 852 | // without racing an HTTP connection, we need the host resolution to happen |
| 853 | // synchronously. |
| 854 | host_resolver_.set_synchronous_mode(true); |
| 855 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 856 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 857 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 858 | host_resolver_.Resolve(info, |
| 859 | DEFAULT_PRIORITY, |
| 860 | &address, |
| 861 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 862 | nullptr, |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 863 | net_log_.bound()); |
| 864 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 865 | CreateSessionWithNextProtos(); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 866 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 867 | SendRequestAndExpectQuicResponse("hello!"); |
| 868 | } |
| 869 | |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 870 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { |
| 871 | proxy_service_.reset( |
| 872 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 873 | |
| 874 | // Since we are using a proxy, the QUIC job will not succeed. |
| 875 | MockWrite http_writes[] = { |
| 876 | MockWrite(SYNCHRONOUS, 0, "GET http://www.google.com/ HTTP/1.1\r\n"), |
| 877 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 878 | MockWrite(SYNCHRONOUS, 2, "Proxy-Connection: keep-alive\r\n\r\n") |
| 879 | }; |
| 880 | |
| 881 | MockRead http_reads[] = { |
| 882 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 883 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 884 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 885 | MockRead(SYNCHRONOUS, OK, 6) |
| 886 | }; |
| 887 | |
| 888 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 889 | http_writes, arraysize(http_writes)); |
| 890 | socket_factory_.AddSocketDataProvider(&http_data); |
| 891 | |
| 892 | // In order for a new QUIC session to be established via alternate-protocol |
| 893 | // without racing an HTTP connection, we need the host resolution to happen |
| 894 | // synchronously. |
| 895 | host_resolver_.set_synchronous_mode(true); |
| 896 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 897 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 898 | AddressList address; |
| 899 | host_resolver_.Resolve(info, |
| 900 | DEFAULT_PRIORITY, |
| 901 | &address, |
| 902 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 903 | nullptr, |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 904 | net_log_.bound()); |
| 905 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 906 | CreateSessionWithNextProtos(); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 907 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 908 | SendRequestAndExpectHttpResponse("hello world"); |
| 909 | } |
| 910 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 911 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 912 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 913 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 914 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 915 | GetRequestHeaders("GET", "http", "/"))); |
| 916 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 917 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 918 | GetResponseHeaders("200 OK"))); |
| 919 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 920 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 921 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 922 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 923 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 924 | |
| 925 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 926 | // the alternate-protocol job will "win". |
| 927 | AddHangingNonAlternateProtocolSocketData(); |
| 928 | |
| 929 | // In order for a new QUIC session to be established via alternate-protocol |
| 930 | // without racing an HTTP connection, we need the host resolution to happen |
| 931 | // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 932 | // connection to the the server, in this test we require confirmation |
| 933 | // before encrypting so the HTTP job will still start. |
| 934 | host_resolver_.set_synchronous_mode(true); |
| 935 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 936 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 937 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 938 | host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 939 | CompletionCallback(), nullptr, net_log_.bound()); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 940 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 941 | CreateSessionWithNextProtos(); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 942 | session_->quic_stream_factory()->set_require_confirmation(true); |
| 943 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 944 | |
| 945 | scoped_ptr<HttpNetworkTransaction> trans( |
| 946 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 947 | TestCompletionCallback callback; |
| 948 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 949 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 950 | |
| 951 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 952 | QuicSession::HANDSHAKE_CONFIRMED); |
| 953 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 954 | } |
| 955 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 956 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 957 | // Alternate-protocol job |
| 958 | scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| 959 | MockRead quic_reads[] = { |
| 960 | MockRead(ASYNC, close->data(), close->length()), |
| 961 | MockRead(ASYNC, OK), // EOF |
| 962 | }; |
| 963 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 964 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 965 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 966 | |
| 967 | // Main job which will succeed even though the alternate job fails. |
| 968 | MockRead http_reads[] = { |
| 969 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 970 | MockRead("hello from http"), |
| 971 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 972 | MockRead(ASYNC, OK) |
| 973 | }; |
| 974 | |
| 975 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 976 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 977 | socket_factory_.AddSocketDataProvider(&http_data); |
| 978 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 979 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 980 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 981 | SendRequestAndExpectHttpResponse("hello from http"); |
| 982 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 983 | } |
| 984 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 985 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 986 | // Alternate-protocol job |
| 987 | MockRead quic_reads[] = { |
| 988 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 989 | }; |
| 990 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 991 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 992 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 993 | |
| 994 | // Main job which will succeed even though the alternate job fails. |
| 995 | MockRead http_reads[] = { |
| 996 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 997 | MockRead("hello from http"), |
| 998 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 999 | MockRead(ASYNC, OK) |
| 1000 | }; |
| 1001 | |
| 1002 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1003 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1004 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1005 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1006 | CreateSessionWithNextProtos(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1007 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1008 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1009 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1010 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1011 | } |
| 1012 | |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1013 | TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1014 | // Alternate-protocol job will fail when the session attempts to read. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1015 | MockRead quic_reads[] = { |
| 1016 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1017 | }; |
| 1018 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1019 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1020 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1021 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1022 | // Main job will also fail. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1023 | MockRead http_reads[] = { |
| 1024 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1025 | }; |
| 1026 | |
| 1027 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1028 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1029 | http_data.set_connect_data(MockConnect(ASYNC, ERR_SOCKET_NOT_CONNECTED)); |
| 1030 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1031 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1032 | CreateSessionWithNextProtos(); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1033 | |
| 1034 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1035 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1036 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1037 | TestCompletionCallback callback; |
| 1038 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1039 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1040 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); |
| 1041 | ExpectQuicAlternateProtocolMapping(); |
| 1042 | } |
| 1043 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1044 | TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1045 | // Alternate-protocol job |
| 1046 | MockRead quic_reads[] = { |
| 1047 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1048 | }; |
| 1049 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1050 | nullptr, 0); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1051 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1052 | |
| 1053 | AddHangingNonAlternateProtocolSocketData(); |
| 1054 | |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1055 | // Second Alternate-protocol job which will race with the TCP job. |
| 1056 | StaticSocketDataProvider quic_data2(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1057 | nullptr, 0); |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1058 | socket_factory_.AddSocketDataProvider(&quic_data2); |
| 1059 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1060 | // Final job that will proceed when the QUIC job fails. |
| 1061 | MockRead http_reads[] = { |
| 1062 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1063 | MockRead("hello from http"), |
| 1064 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1065 | MockRead(ASYNC, OK) |
| 1066 | }; |
| 1067 | |
| 1068 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1069 | nullptr, 0); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1070 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1071 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1072 | CreateSessionWithNextProtos(); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1073 | |
| 1074 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1075 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1076 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1077 | |
| 1078 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1079 | |
| 1080 | EXPECT_TRUE(quic_data.at_read_eof()); |
| 1081 | EXPECT_TRUE(quic_data.at_write_eof()); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1082 | } |
| 1083 | |
[email protected] | 93b3177 | 2014-06-19 08:03:35 | [diff] [blame] | 1084 | TEST_P(QuicNetworkTransactionTest, DISABLED_HangingZeroRttFallback) { |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1085 | // Alternate-protocol job |
| 1086 | MockRead quic_reads[] = { |
| 1087 | MockRead(ASYNC, ERR_IO_PENDING), |
| 1088 | }; |
| 1089 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1090 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1091 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1092 | |
| 1093 | // Main job that will proceed when the QUIC job fails. |
| 1094 | MockRead http_reads[] = { |
| 1095 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1096 | MockRead("hello from http"), |
| 1097 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1098 | MockRead(ASYNC, OK) |
| 1099 | }; |
| 1100 | |
| 1101 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1102 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1103 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1104 | |
| 1105 | CreateSessionWithNextProtos(); |
| 1106 | |
| 1107 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1108 | |
| 1109 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1110 | } |
| 1111 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1112 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1113 | // Alternate-protocol job will fail before creating a QUIC session. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1114 | StaticSocketDataProvider quic_data(nullptr, 0, nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1115 | quic_data.set_connect_data(MockConnect(SYNCHRONOUS, |
| 1116 | ERR_INTERNET_DISCONNECTED)); |
| 1117 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1118 | |
| 1119 | // Main job which will succeed even though the alternate job fails. |
| 1120 | MockRead http_reads[] = { |
| 1121 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1122 | MockRead("hello from http"), |
| 1123 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1124 | MockRead(ASYNC, OK) |
| 1125 | }; |
| 1126 | |
| 1127 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1128 | nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1129 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1130 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1131 | CreateSessionWithNextProtos(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1132 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1133 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1134 | |
| 1135 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1136 | } |
| 1137 | |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1138 | TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1139 | MockQuicData mock_quic_data; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1140 | mock_quic_data.AddSynchronousRead(ConstructConnectionClosePacket(1)); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1141 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1142 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1143 | GetRequestHeaders("GET", "http", "/"))); |
| 1144 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1145 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1146 | |
| 1147 | // When the QUIC connection fails, we will try the request again over HTTP. |
| 1148 | MockRead http_reads[] = { |
| 1149 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1150 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 1151 | MockRead("hello world"), |
| 1152 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1153 | MockRead(ASYNC, OK) |
| 1154 | }; |
| 1155 | |
| 1156 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1157 | nullptr, 0); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1158 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1159 | |
| 1160 | // In order for a new QUIC session to be established via alternate-protocol |
| 1161 | // without racing an HTTP connection, we need the host resolution to happen |
| 1162 | // synchronously. |
| 1163 | host_resolver_.set_synchronous_mode(true); |
| 1164 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 1165 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 1166 | AddressList address; |
| 1167 | host_resolver_.Resolve(info, |
| 1168 | DEFAULT_PRIORITY, |
| 1169 | &address, |
| 1170 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1171 | nullptr, |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1172 | net_log_.bound()); |
| 1173 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1174 | CreateSessionWithNextProtos(); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1175 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1176 | SendRequestAndExpectHttpResponse("hello world"); |
| 1177 | } |
| 1178 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 1179 | } // namespace test |
| 1180 | } // namespace net |