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