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