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