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