[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 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 56 | static const char kQuicAlternateProtocolHttpHeader[] = |
[email protected] | 4ff6537 | 2013-06-21 05:45:46 | [diff] [blame] | 57 | "Alternate-Protocol: 80:quic\r\n\r\n"; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 58 | static const char kQuicAlternateProtocol50pctHttpHeader[] = |
| 59 | "Alternate-Protocol: 80:quic,p=.5\r\n\r\n"; |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 60 | static const char kQuicAlternateProtocolDifferentPortHttpHeader[] = |
| 61 | "Alternate-Protocol: 137:quic\r\n\r\n"; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 62 | static const char kQuicAlternateProtocolHttpsHeader[] = |
| 63 | "Alternate-Protocol: 443:quic\r\n\r\n"; |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 64 | static const char kQuicAlternativeServiceHttpHeader[] = |
| 65 | "Alt-Svc: quic=\":80\"\r\n\r\n"; |
| 66 | static const char kQuicAlternativeService50pctHttpHeader[] = |
| 67 | "Alt-Svc: quic=\":80\";p=.5\r\n\r\n"; |
| 68 | static const char kQuicAlternativeServiceDifferentPortHttpHeader[] = |
| 69 | "Alt-Svc: quic=\":137\"\r\n\r\n"; |
| 70 | static const char kQuicAlternativeServiceHttpsHeader[] = |
| 71 | "Alt-Svc: quic=\":443\"\r\n\r\n"; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 72 | |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 73 | const char kDefaultServerHostName[] = "www.google.com"; |
| 74 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 75 | } // namespace |
| 76 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 77 | // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 78 | // Simplify ownership issues and the interaction with the MockSocketFactory. |
| 79 | class MockQuicData { |
| 80 | public: |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 81 | MockQuicData() : sequence_number_(0) {} |
| 82 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 83 | ~MockQuicData() { |
| 84 | STLDeleteElements(&packets_); |
| 85 | } |
| 86 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 87 | void AddSynchronousRead(scoped_ptr<QuicEncryptedPacket> packet) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 88 | reads_.push_back(MockRead(SYNCHRONOUS, packet->data(), packet->length(), |
| 89 | sequence_number_++)); |
| 90 | packets_.push_back(packet.release()); |
| 91 | } |
| 92 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 93 | void AddRead(scoped_ptr<QuicEncryptedPacket> packet) { |
| 94 | reads_.push_back( |
| 95 | MockRead(ASYNC, packet->data(), packet->length(), sequence_number_++)); |
| 96 | packets_.push_back(packet.release()); |
| 97 | } |
| 98 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 99 | void AddRead(IoMode mode, int rv) { |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 100 | reads_.push_back(MockRead(mode, rv, sequence_number_++)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
| 104 | writes_.push_back(MockWrite(SYNCHRONOUS, packet->data(), packet->length(), |
| 105 | sequence_number_++)); |
| 106 | packets_.push_back(packet.release()); |
| 107 | } |
| 108 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 109 | void AddSocketDataToFactory(MockClientSocketFactory* factory) { |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 110 | MockRead* reads = reads_.empty() ? nullptr : &reads_[0]; |
| 111 | MockWrite* writes = writes_.empty() ? nullptr : &writes_[0]; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 112 | socket_data_.reset( |
| 113 | new SequencedSocketData(reads, reads_.size(), writes, writes_.size())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 114 | factory->AddSocketDataProvider(socket_data_.get()); |
| 115 | } |
| 116 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 117 | void CompleteRead() { socket_data_->CompleteRead(); } |
| 118 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 119 | private: |
| 120 | std::vector<QuicEncryptedPacket*> packets_; |
| 121 | std::vector<MockWrite> writes_; |
| 122 | std::vector<MockRead> reads_; |
| 123 | size_t sequence_number_; |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 124 | scoped_ptr<SequencedSocketData> socket_data_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 125 | }; |
| 126 | |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 127 | class ProxyHeadersHandler { |
| 128 | public: |
| 129 | ProxyHeadersHandler() : was_called_(false) {} |
| 130 | |
| 131 | bool was_called() { return was_called_; } |
| 132 | |
| 133 | void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, |
| 134 | HttpRequestHeaders* request_headers) { |
| 135 | was_called_ = true; |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | bool was_called_; |
| 140 | }; |
| 141 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 142 | class QuicNetworkTransactionTest |
| 143 | : public PlatformTest, |
[email protected] | 5d03bbd | 2014-03-07 16:19:16 | [diff] [blame] | 144 | public ::testing::WithParamInterface<QuicVersion> { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 145 | protected: |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 146 | QuicNetworkTransactionTest() |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 147 | : clock_(new MockClock), |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 148 | maker_(GetParam(), 0, clock_, kDefaultServerHostName), |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 149 | ssl_config_service_(new SSLConfigServiceDefaults), |
| 150 | proxy_service_(ProxyService::CreateDirect()), |
| 151 | auth_handler_factory_( |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 152 | HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 153 | random_generator_(0), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 154 | hanging_data_(nullptr, 0, nullptr, 0) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 155 | request_.method = "GET"; |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 156 | std::string url("http://"); |
| 157 | url.append(kDefaultServerHostName); |
| 158 | request_.url = GURL(url); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 159 | request_.load_flags = 0; |
[email protected] | 98a9d125 | 2014-04-04 00:43:59 | [diff] [blame] | 160 | clock_->AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 161 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 162 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 163 | void SetUp() override { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 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 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 168 | void TearDown() override { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 169 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 170 | // Empty the current queue. |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 171 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 172 | PlatformTest::TearDown(); |
| 173 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 174 | base::MessageLoop::current()->RunUntilIdle(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 175 | } |
| 176 | |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 177 | scoped_ptr<QuicEncryptedPacket> ConstructConnectionClosePacket( |
| 178 | QuicPacketSequenceNumber num) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 179 | return maker_.MakeConnectionClosePacket(num); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 182 | scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
| 183 | QuicPacketSequenceNumber largest_received, |
| 184 | QuicPacketSequenceNumber least_unacked) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 185 | return maker_.MakeAckPacket(2, largest_received, least_unacked, true); |
| 186 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 187 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 188 | SpdyHeaderBlock GetRequestHeaders(const std::string& method, |
| 189 | const std::string& scheme, |
| 190 | const std::string& path) { |
| 191 | return maker_.GetRequestHeaders(method, scheme, path); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 194 | SpdyHeaderBlock GetResponseHeaders(const std::string& status) { |
| 195 | return maker_.GetResponseHeaders(status); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 198 | scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 199 | QuicPacketSequenceNumber sequence_number, |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 200 | QuicStreamId stream_id, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 201 | bool should_include_version, |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 202 | bool fin, |
| 203 | QuicStreamOffset offset, |
| 204 | base::StringPiece data) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 205 | return maker_.MakeDataPacket( |
| 206 | sequence_number, stream_id, should_include_version, fin, offset, data); |
[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> ConstructRequestHeadersPacket( |
| 210 | QuicPacketSequenceNumber sequence_number, |
| 211 | QuicStreamId stream_id, |
| 212 | bool should_include_version, |
| 213 | bool fin, |
| 214 | const SpdyHeaderBlock& headers) { |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 215 | QuicPriority priority = |
| 216 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 217 | return maker_.MakeRequestHeadersPacket(sequence_number, stream_id, |
| 218 | should_include_version, fin, |
| 219 | priority, headers); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 222 | scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( |
| 223 | QuicPacketSequenceNumber sequence_number, |
| 224 | QuicStreamId stream_id, |
| 225 | bool should_include_version, |
| 226 | bool fin, |
| 227 | const SpdyHeaderBlock& headers) { |
| 228 | return maker_.MakeResponseHeadersPacket( |
| 229 | sequence_number, stream_id, should_include_version, fin, headers); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void CreateSession() { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 233 | CreateSessionWithFactory(&socket_factory_, false); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 236 | void CreateSessionWithNextProtos() { |
| 237 | CreateSessionWithFactory(&socket_factory_, true); |
| 238 | } |
| 239 | |
| 240 | // If |use_next_protos| is true, enables SPDY and QUIC. |
| 241 | void CreateSessionWithFactory(ClientSocketFactory* socket_factory, |
| 242 | bool use_next_protos) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 243 | params_.enable_quic = true; |
| 244 | params_.quic_clock = clock_; |
| 245 | params_.quic_random = &random_generator_; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 246 | params_.client_socket_factory = socket_factory; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 247 | params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 248 | params_.host_resolver = &host_resolver_; |
| 249 | params_.cert_verifier = &cert_verifier_; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 250 | params_.transport_security_state = &transport_security_state_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 251 | params_.proxy_service = proxy_service_.get(); |
| 252 | params_.ssl_config_service = ssl_config_service_.get(); |
| 253 | params_.http_auth_handler_factory = auth_handler_factory_.get(); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 254 | params_.http_server_properties = http_server_properties_.GetWeakPtr(); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 255 | params_.quic_supported_versions = SupportedVersions(GetParam()); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 256 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 257 | if (use_next_protos) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 258 | params_.use_alternative_services = true; |
bnc | 3bb2c23 | 2014-11-07 20:26:39 | [diff] [blame] | 259 | params_.next_protos = NextProtosWithSpdyAndQuic(true, true); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 260 | } |
| 261 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 262 | session_ = new HttpNetworkSession(params_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 263 | session_->quic_stream_factory()->set_require_confirmation(false); |
rch | 185ebee | 2015-07-14 23:56:22 | [diff] [blame] | 264 | ASSERT_EQ(params_.quic_socket_receive_buffer_size, |
| 265 | session_->quic_stream_factory()->socket_receive_buffer_size()); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 266 | } |
| 267 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 268 | void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 269 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 270 | ASSERT_TRUE(response != nullptr); |
| 271 | ASSERT_TRUE(response->headers.get() != nullptr); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 272 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 273 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 274 | EXPECT_TRUE(response->was_npn_negotiated); |
| 275 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, |
| 276 | response->connection_info); |
| 277 | } |
| 278 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 279 | void CheckResponsePort(const scoped_ptr<HttpNetworkTransaction>& trans, |
| 280 | uint16 port) { |
| 281 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 282 | ASSERT_TRUE(response != nullptr); |
| 283 | EXPECT_EQ(port, response->socket_address.port()); |
| 284 | } |
| 285 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 286 | void CheckWasHttpResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
| 287 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 288 | ASSERT_TRUE(response != nullptr); |
| 289 | ASSERT_TRUE(response->headers.get() != nullptr); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 290 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 291 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 292 | EXPECT_FALSE(response->was_npn_negotiated); |
| 293 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 294 | response->connection_info); |
| 295 | } |
| 296 | |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 297 | void CheckResponseData(const scoped_ptr<HttpNetworkTransaction>& trans, |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 298 | const std::string& expected) { |
| 299 | std::string response_data; |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 300 | ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 301 | EXPECT_EQ(expected, response_data); |
| 302 | } |
| 303 | |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 304 | void RunTransaction(const scoped_ptr<HttpNetworkTransaction>& trans) { |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 305 | TestCompletionCallback callback; |
| 306 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 307 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 308 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 309 | } |
| 310 | |
| 311 | void SendRequestAndExpectHttpResponse(const std::string& expected) { |
| 312 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 313 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 314 | RunTransaction(trans); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 315 | CheckWasHttpResponse(trans); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 316 | CheckResponseData(trans, expected); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | void SendRequestAndExpectQuicResponse(const std::string& expected) { |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 320 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, 80); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 321 | } |
| 322 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 323 | void SendRequestAndExpectQuicResponseOnPort(const std::string& expected, |
| 324 | uint16 port) { |
| 325 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, false, port); |
| 326 | } |
| 327 | |
| 328 | void SendRequestAndExpectQuicResponseFromProxyOnPort( |
| 329 | const std::string& expected, |
| 330 | uint16 port) { |
| 331 | SendRequestAndExpectQuicResponseMaybeFromProxy(expected, true, port); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void AddQuicAlternateProtocolMapping( |
| 335 | MockCryptoClientStream::HandshakeMode handshake_mode) { |
| 336 | crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 337 | HostPortPair host_port_pair = HostPortPair::FromURL(request_.url); |
| 338 | AlternativeService alternative_service(QUIC, host_port_pair.host(), 80); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 339 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 340 | http_server_properties_.SetAlternativeService( |
| 341 | host_port_pair, alternative_service, 1.0, expiration); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | void ExpectBrokenAlternateProtocolMapping() { |
bnc | 8445b300 | 2015-03-13 01:57:09 | [diff] [blame] | 345 | const HostPortPair origin = HostPortPair::FromURL(request_.url); |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 346 | const AlternativeServiceVector alternative_service_vector = |
| 347 | http_server_properties_.GetAlternativeServices(origin); |
| 348 | EXPECT_EQ(1u, alternative_service_vector.size()); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 349 | EXPECT_TRUE(http_server_properties_.IsAlternativeServiceBroken( |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 350 | alternative_service_vector[0])); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 353 | void ExpectQuicAlternateProtocolMapping() { |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 354 | const HostPortPair origin = HostPortPair::FromURL(request_.url); |
| 355 | const AlternativeServiceVector alternative_service_vector = |
| 356 | http_server_properties_.GetAlternativeServices(origin); |
| 357 | EXPECT_EQ(1u, alternative_service_vector.size()); |
| 358 | EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 361 | void AddHangingNonAlternateProtocolSocketData() { |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 362 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 363 | hanging_data_.set_connect_data(hanging_connect); |
| 364 | socket_factory_.AddSocketDataProvider(&hanging_data_); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 365 | } |
| 366 | |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 367 | MockClock* clock_; // Owned by QuicStreamFactory after CreateSession. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 368 | QuicTestPacketMaker maker_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 369 | scoped_refptr<HttpNetworkSession> session_; |
| 370 | MockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 371 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 372 | MockHostResolver host_resolver_; |
| 373 | MockCertVerifier cert_verifier_; |
[email protected] | b1c988b | 2013-06-13 06:48:11 | [diff] [blame] | 374 | TransportSecurityState transport_security_state_; |
[email protected] | 1c04f952 | 2013-02-21 20:32:43 | [diff] [blame] | 375 | scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 376 | scoped_ptr<ProxyService> proxy_service_; |
| 377 | scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 378 | MockRandom random_generator_; |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 379 | HttpServerPropertiesImpl http_server_properties_; |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 380 | HttpNetworkSession::Params params_; |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 381 | HttpRequestInfo request_; |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 382 | BoundTestNetLog net_log_; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 383 | StaticSocketDataProvider hanging_data_; |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 384 | |
| 385 | private: |
| 386 | void SendRequestAndExpectQuicResponseMaybeFromProxy( |
| 387 | const std::string& expected, |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 388 | bool used_proxy, |
| 389 | uint16 port) { |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 390 | scoped_ptr<HttpNetworkTransaction> trans( |
| 391 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 392 | ProxyHeadersHandler proxy_headers_handler; |
| 393 | trans->SetBeforeProxyHeadersSentCallback( |
| 394 | base::Bind(&ProxyHeadersHandler::OnBeforeProxyHeadersSent, |
| 395 | base::Unretained(&proxy_headers_handler))); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 396 | RunTransaction(trans); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 397 | CheckWasQuicResponse(trans); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 398 | CheckResponsePort(trans, port); |
bnc | ffc2fdf | 2015-05-14 18:29:49 | [diff] [blame] | 399 | CheckResponseData(trans, expected); |
tbansal | 7cec381 | 2015-02-05 21:25:12 | [diff] [blame] | 400 | EXPECT_EQ(used_proxy, proxy_headers_handler.was_called()); |
| 401 | } |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 402 | }; |
| 403 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 404 | INSTANTIATE_TEST_CASE_P(Version, QuicNetworkTransactionTest, |
| 405 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 406 | |
| 407 | TEST_P(QuicNetworkTransactionTest, ForceQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 408 | // TODO(rch): switch these tests to use secure QUIC. |
| 409 | params_.enable_insecure_quic = true; |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 410 | params_.origin_to_force_quic_on = |
| 411 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 412 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 413 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 414 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 415 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 416 | GetRequestHeaders("GET", "http", "/"))); |
| 417 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 418 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 419 | GetResponseHeaders("200 OK"))); |
| 420 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 421 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 422 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 423 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 424 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 425 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 426 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 427 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 428 | // the alternate-protocol job will "win". |
| 429 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 430 | |
| 431 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 432 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 433 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 434 | |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 435 | // Check that the NetLog was filled reasonably. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 436 | TestNetLogEntry::List entries; |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 437 | net_log_.GetEntries(&entries); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 438 | EXPECT_LT(0u, entries.size()); |
| 439 | |
| 440 | // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 441 | int pos = ExpectLogContainsSomewhere( |
| 442 | entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
| 443 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 444 | EXPECT_LT(0, pos); |
| 445 | |
rch | fd52721 | 2015-08-25 00:41:26 | [diff] [blame^] | 446 | // ... and also a TYPE_QUIC_SESSION_UNAUTHENTICATED_PACKET_HEADER_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 447 | pos = ExpectLogContainsSomewhere( |
rch | fd52721 | 2015-08-25 00:41:26 | [diff] [blame^] | 448 | entries, 0, |
| 449 | NetLog::TYPE_QUIC_SESSION_UNAUTHENTICATED_PACKET_HEADER_RECEIVED, |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 450 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 451 | EXPECT_LT(0, pos); |
| 452 | |
| 453 | std::string packet_sequence_number; |
| 454 | ASSERT_TRUE(entries[pos].GetStringValue( |
| 455 | "packet_sequence_number", &packet_sequence_number)); |
| 456 | EXPECT_EQ("1", packet_sequence_number); |
| 457 | |
rch | fd52721 | 2015-08-25 00:41:26 | [diff] [blame^] | 458 | // ... and also a TYPE_QUIC_SESSION_PACKET_AUTHENTICATED. |
| 459 | pos = ExpectLogContainsSomewhere( |
| 460 | entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_AUTHENTICATED, |
| 461 | NetLog::PHASE_NONE); |
| 462 | EXPECT_LT(0, pos); |
| 463 | |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 464 | // ... and also a QUIC_SESSION_STREAM_FRAME_RECEIVED. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 465 | pos = ExpectLogContainsSomewhere( |
| 466 | entries, 0, NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED, |
| 467 | NetLog::PHASE_NONE); |
[email protected] | 98b20ce | 2013-05-10 05:55:26 | [diff] [blame] | 468 | EXPECT_LT(0, pos); |
| 469 | |
| 470 | int log_stream_id; |
| 471 | ASSERT_TRUE(entries[pos].GetIntegerValue("stream_id", &log_stream_id)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 472 | EXPECT_EQ(3, log_stream_id); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 473 | } |
| 474 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 475 | TEST_P(QuicNetworkTransactionTest, QuicProxy) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 476 | params_.enable_insecure_quic = true; |
tbansal | ed0aecc | 2015-02-20 03:44:18 | [diff] [blame] | 477 | params_.enable_quic_for_proxies = true; |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 478 | proxy_service_.reset( |
| 479 | ProxyService::CreateFixedFromPacResult("QUIC myproxy:70")); |
| 480 | |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 481 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 482 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 483 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 484 | GetRequestHeaders("GET", "http", "/"))); |
| 485 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 486 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 487 | GetResponseHeaders("200 OK"))); |
| 488 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 489 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 490 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 491 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 492 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 493 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 494 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 495 | |
| 496 | // There is no need to set up an alternate protocol job, because |
| 497 | // no attempt will be made to speak to the proxy over TCP. |
| 498 | |
| 499 | CreateSession(); |
| 500 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 501 | SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
[email protected] | cf3e3cd6 | 2014-02-05 16:16:16 | [diff] [blame] | 502 | } |
| 503 | |
bnc | 313ba9c | 2015-06-11 15:42:31 | [diff] [blame] | 504 | // Regression test for https://crbug.com/492458. Test that for an HTTP |
| 505 | // connection through a QUIC proxy, the certificate exhibited by the proxy is |
| 506 | // checked against the proxy hostname, not the origin hostname. |
| 507 | TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
| 508 | const std::string origin_host = "news.example.com"; |
| 509 | const std::string proxy_host = "www.example.org"; |
| 510 | |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 511 | params_.enable_insecure_quic = true; |
bnc | 313ba9c | 2015-06-11 15:42:31 | [diff] [blame] | 512 | params_.enable_quic_for_proxies = true; |
| 513 | proxy_service_.reset( |
| 514 | ProxyService::CreateFixedFromPacResult("QUIC " + proxy_host + ":70")); |
| 515 | |
| 516 | maker_.set_hostname(origin_host); |
| 517 | MockQuicData mock_quic_data; |
| 518 | mock_quic_data.AddWrite( |
| 519 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 520 | GetRequestHeaders("GET", "http", "/"))); |
| 521 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 522 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 523 | mock_quic_data.AddRead( |
| 524 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 525 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 526 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
bnc | 313ba9c | 2015-06-11 15:42:31 | [diff] [blame] | 527 | mock_quic_data.AddRead(SYNCHRONOUS, 0); |
| 528 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 529 | |
| 530 | scoped_refptr<X509Certificate> cert( |
| 531 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 532 | ASSERT_TRUE(cert.get()); |
| 533 | // This certificate is valid for the proxy, but not for the origin. |
| 534 | bool common_name_fallback_used; |
| 535 | EXPECT_TRUE(cert->VerifyNameMatch(proxy_host, &common_name_fallback_used)); |
| 536 | EXPECT_FALSE(cert->VerifyNameMatch(origin_host, &common_name_fallback_used)); |
| 537 | ProofVerifyDetailsChromium verify_details; |
| 538 | verify_details.cert_verify_result.verified_cert = cert; |
| 539 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 540 | |
| 541 | request_.url = GURL("http://" + origin_host); |
| 542 | AddHangingNonAlternateProtocolSocketData(); |
| 543 | CreateSessionWithNextProtos(); |
| 544 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 545 | SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
| 546 | } |
| 547 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 548 | TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 549 | params_.enable_insecure_quic = true; |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 550 | params_.origin_to_force_quic_on = |
| 551 | HostPortPair::FromString("www.google.com:80"); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 552 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 553 | MockQuicData mock_quic_data; |
| 554 | mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 555 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 556 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 557 | |
| 558 | CreateSession(); |
| 559 | |
| 560 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 561 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 562 | TestCompletionCallback callback; |
| 563 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 565 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); |
[email protected] | cebe328 | 2013-05-22 23:49:30 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 568 | TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 569 | // Attempt to "force" quic on 443, which will not be honored. |
[email protected] | 49e8533 | 2013-06-04 04:18:03 | [diff] [blame] | 570 | params_.origin_to_force_quic_on = |
| 571 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 572 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 573 | MockRead http_reads[] = { |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 574 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 575 | MockRead("hello world"), |
| 576 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 577 | MockRead(ASYNC, OK) |
| 578 | }; |
| 579 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 580 | StaticSocketDataProvider data(http_reads, arraysize(http_reads), nullptr, 0); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 581 | socket_factory_.AddSocketDataProvider(&data); |
| 582 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 583 | socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 584 | |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 585 | CreateSession(); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 586 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 587 | SendRequestAndExpectHttpResponse("hello world"); |
[email protected] | 4dca587c | 2013-03-07 16:54:47 | [diff] [blame] | 588 | } |
| 589 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 590 | TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuic) { |
| 591 | params_.enable_insecure_quic = true; |
| 592 | |
| 593 | MockRead http_reads[] = { |
| 594 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 595 | MockRead(kQuicAlternativeServiceHttpHeader), MockRead("hello world"), |
| 596 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 597 | MockRead(ASYNC, OK)}; |
| 598 | |
| 599 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 600 | 0); |
| 601 | socket_factory_.AddSocketDataProvider(&http_data); |
| 602 | |
| 603 | MockQuicData mock_quic_data; |
| 604 | mock_quic_data.AddWrite( |
| 605 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 606 | GetRequestHeaders("GET", "http", "/"))); |
| 607 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 608 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 609 | mock_quic_data.AddRead( |
| 610 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 611 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 612 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 613 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 614 | |
| 615 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 616 | |
| 617 | AddHangingNonAlternateProtocolSocketData(); |
| 618 | CreateSessionWithNextProtos(); |
| 619 | |
| 620 | SendRequestAndExpectHttpResponse("hello world"); |
| 621 | SendRequestAndExpectQuicResponse("hello!"); |
| 622 | } |
| 623 | |
| 624 | // When multiple alternative services are advertised, |
| 625 | // HttpStreamFactoryImpl::RequestStreamInternal() only passes the first one to |
| 626 | // Job. This is what the following test verifies. |
| 627 | // TODO(bnc): Update this test when multiple alternative services are handled |
| 628 | // properly. |
| 629 | TEST_P(QuicNetworkTransactionTest, UseFirstAlternativeServiceForQuic) { |
| 630 | params_.enable_insecure_quic = true; |
| 631 | |
| 632 | MockRead http_reads[] = { |
| 633 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 634 | MockRead("Alt-Svc: quic=\":443\", quic=\":1234\"\r\n\r\n"), |
| 635 | MockRead("hello world"), |
| 636 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 637 | MockRead(ASYNC, OK)}; |
| 638 | |
| 639 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 640 | 0); |
| 641 | socket_factory_.AddSocketDataProvider(&http_data); |
| 642 | |
| 643 | MockQuicData mock_quic_data; |
| 644 | mock_quic_data.AddWrite( |
| 645 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 646 | GetRequestHeaders("GET", "http", "/"))); |
| 647 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 648 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 649 | mock_quic_data.AddRead( |
| 650 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 651 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 652 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 653 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 654 | |
| 655 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 656 | |
| 657 | AddHangingNonAlternateProtocolSocketData(); |
| 658 | CreateSessionWithNextProtos(); |
| 659 | |
| 660 | SendRequestAndExpectHttpResponse("hello world"); |
| 661 | SendRequestAndExpectQuicResponseOnPort("hello!", 443); |
| 662 | } |
| 663 | |
| 664 | TEST_P(QuicNetworkTransactionTest, AlternativeServiceDifferentPort) { |
| 665 | params_.enable_insecure_quic = true; |
| 666 | |
| 667 | MockRead http_reads[] = { |
| 668 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 669 | MockRead(kQuicAlternativeServiceDifferentPortHttpHeader), |
| 670 | MockRead("hello world"), |
| 671 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 672 | MockRead(ASYNC, OK)}; |
| 673 | |
| 674 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 675 | 0); |
| 676 | socket_factory_.AddSocketDataProvider(&http_data); |
| 677 | |
| 678 | MockQuicData mock_quic_data; |
| 679 | mock_quic_data.AddWrite( |
| 680 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 681 | GetRequestHeaders("GET", "http", "/"))); |
| 682 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 683 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 684 | mock_quic_data.AddRead( |
| 685 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 686 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 687 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 688 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 689 | |
| 690 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 691 | |
| 692 | AddHangingNonAlternateProtocolSocketData(); |
| 693 | CreateSessionWithNextProtos(); |
| 694 | |
| 695 | SendRequestAndExpectHttpResponse("hello world"); |
| 696 | SendRequestAndExpectQuicResponseOnPort("hello!", 137); |
| 697 | } |
| 698 | |
| 699 | TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) { |
| 700 | params_.enable_insecure_quic = true; |
| 701 | |
| 702 | MockRead http_reads[] = { |
| 703 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 704 | MockRead(kQuicAlternativeServiceHttpHeader), MockRead("hello world"), |
| 705 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 706 | MockRead(ASYNC, OK)}; |
| 707 | |
| 708 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 709 | 0); |
| 710 | socket_factory_.AddSocketDataProvider(&http_data); |
| 711 | |
| 712 | MockQuicData mock_quic_data; |
| 713 | mock_quic_data.AddWrite( |
| 714 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 715 | GetRequestHeaders("GET", "http", "/"))); |
| 716 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 717 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 718 | mock_quic_data.AddRead( |
| 719 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 720 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 721 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 722 | mock_quic_data.AddRead(ASYNC, 0); // EOF |
| 723 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 724 | |
| 725 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 726 | |
| 727 | AddHangingNonAlternateProtocolSocketData(); |
| 728 | CreateSessionWithNextProtos(); |
| 729 | |
| 730 | AlternativeService alternative_service(QUIC, |
| 731 | HostPortPair::FromURL(request_.url)); |
| 732 | http_server_properties_.MarkAlternativeServiceRecentlyBroken( |
| 733 | alternative_service); |
| 734 | EXPECT_TRUE(http_server_properties_.WasAlternativeServiceRecentlyBroken( |
| 735 | alternative_service)); |
| 736 | |
| 737 | SendRequestAndExpectHttpResponse("hello world"); |
| 738 | SendRequestAndExpectQuicResponse("hello!"); |
| 739 | |
| 740 | mock_quic_data.CompleteRead(); |
| 741 | |
| 742 | EXPECT_FALSE(http_server_properties_.WasAlternativeServiceRecentlyBroken( |
| 743 | alternative_service)); |
| 744 | } |
| 745 | |
| 746 | TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceProbabilityForQuic) { |
| 747 | params_.enable_insecure_quic = true; |
| 748 | |
| 749 | MockRead http_reads[] = { |
| 750 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 751 | MockRead(kQuicAlternativeService50pctHttpHeader), MockRead("hello world"), |
| 752 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 753 | MockRead(ASYNC, OK)}; |
| 754 | |
| 755 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 756 | 0); |
| 757 | socket_factory_.AddSocketDataProvider(&http_data); |
| 758 | |
| 759 | MockQuicData mock_quic_data; |
| 760 | mock_quic_data.AddWrite( |
| 761 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 762 | GetRequestHeaders("GET", "http", "/"))); |
| 763 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 764 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 765 | mock_quic_data.AddRead( |
| 766 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 767 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 768 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 769 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 770 | |
| 771 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 772 | |
| 773 | AddHangingNonAlternateProtocolSocketData(); |
| 774 | params_.alternative_service_probability_threshold = 0.25; |
| 775 | CreateSessionWithNextProtos(); |
| 776 | |
| 777 | SendRequestAndExpectHttpResponse("hello world"); |
| 778 | SendRequestAndExpectQuicResponse("hello!"); |
| 779 | } |
| 780 | |
| 781 | TEST_P(QuicNetworkTransactionTest, |
| 782 | DontUseAlternativeServiceProbabilityForQuic) { |
| 783 | params_.enable_insecure_quic = true; |
| 784 | |
| 785 | MockRead http_reads[] = { |
| 786 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 787 | MockRead(kQuicAlternativeService50pctHttpHeader), MockRead("hello world"), |
| 788 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 789 | MockRead(ASYNC, OK)}; |
| 790 | |
| 791 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 792 | 0); |
| 793 | socket_factory_.AddSocketDataProvider(&http_data); |
| 794 | socket_factory_.AddSocketDataProvider(&http_data); |
| 795 | |
| 796 | params_.alternative_service_probability_threshold = 0.75; |
| 797 | CreateSessionWithNextProtos(); |
| 798 | |
| 799 | SendRequestAndExpectHttpResponse("hello world"); |
| 800 | SendRequestAndExpectHttpResponse("hello world"); |
| 801 | } |
| 802 | |
| 803 | TEST_P(QuicNetworkTransactionTest, DontUseAlternativeServiceForInsecureQuic) { |
| 804 | params_.enable_insecure_quic = true; |
| 805 | |
| 806 | MockRead http_reads[] = {MockRead("HTTP/1.1 200 OK\r\n"), |
| 807 | MockRead("Content-length: 11\r\n"), |
| 808 | MockRead("Alt-Svc: quic=\":443\"\r\n\r\n"), |
| 809 | MockRead("hello world"), |
| 810 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 811 | MockRead("Content-length: 11\r\n"), |
| 812 | MockRead("Alt-Svc: quic=\":443\"\r\n\r\n"), |
| 813 | MockRead("hello world"), |
| 814 | MockRead(ASYNC, OK)}; |
| 815 | |
| 816 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 817 | 0); |
| 818 | socket_factory_.AddSocketDataProvider(&http_data); |
| 819 | socket_factory_.AddSocketDataProvider(&http_data); |
| 820 | |
| 821 | params_.enable_insecure_quic = false; |
| 822 | CreateSessionWithNextProtos(); |
| 823 | |
| 824 | SendRequestAndExpectHttpResponse("hello world"); |
| 825 | SendRequestAndExpectHttpResponse("hello world"); |
| 826 | } |
| 827 | |
| 828 | TEST_P(QuicNetworkTransactionTest, |
| 829 | DontUseAlternativeServiceWithBadProbabilityForQuic) { |
| 830 | params_.enable_insecure_quic = true; |
| 831 | |
| 832 | MockRead http_reads[] = { |
| 833 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 834 | MockRead("Alt-Svc: quic=\":443\";p=2\r\n\r\n"), MockRead("hello world"), |
| 835 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 836 | MockRead(ASYNC, OK)}; |
| 837 | |
| 838 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 839 | 0); |
| 840 | socket_factory_.AddSocketDataProvider(&http_data); |
| 841 | socket_factory_.AddSocketDataProvider(&http_data); |
| 842 | |
| 843 | params_.alternative_service_probability_threshold = 0.75; |
| 844 | CreateSessionWithNextProtos(); |
| 845 | |
| 846 | SendRequestAndExpectHttpResponse("hello world"); |
| 847 | SendRequestAndExpectHttpResponse("hello world"); |
| 848 | } |
| 849 | |
| 850 | TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuicForHttps) { |
| 851 | params_.enable_insecure_quic = true; |
| 852 | params_.origin_to_force_quic_on = |
| 853 | HostPortPair::FromString("www.google.com:443"); |
| 854 | |
| 855 | MockRead http_reads[] = { |
| 856 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 857 | MockRead(kQuicAlternativeServiceHttpsHeader), MockRead("hello world"), |
| 858 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 859 | MockRead(ASYNC, OK)}; |
| 860 | |
| 861 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 862 | 0); |
| 863 | socket_factory_.AddSocketDataProvider(&http_data); |
| 864 | |
| 865 | MockQuicData mock_quic_data; |
| 866 | mock_quic_data.AddWrite( |
| 867 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 868 | GetRequestHeaders("GET", "http", "/"))); |
| 869 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 870 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 871 | mock_quic_data.AddRead( |
| 872 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 873 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 874 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 875 | |
| 876 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 877 | |
| 878 | AddHangingNonAlternateProtocolSocketData(); |
| 879 | CreateSessionWithNextProtos(); |
| 880 | |
| 881 | // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 882 | SendRequestAndExpectHttpResponse("hello world"); |
| 883 | } |
| 884 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 885 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 886 | params_.enable_insecure_quic = true; |
| 887 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 888 | MockRead http_reads[] = { |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 889 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 890 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 891 | MockRead("hello world"), |
| 892 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 893 | MockRead(ASYNC, OK) |
| 894 | }; |
| 895 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 896 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 897 | nullptr, 0); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 898 | socket_factory_.AddSocketDataProvider(&http_data); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 899 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 900 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 901 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 902 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 903 | GetRequestHeaders("GET", "http", "/"))); |
| 904 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 905 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 906 | GetResponseHeaders("200 OK"))); |
| 907 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 908 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 909 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 910 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 911 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 912 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 913 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 914 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 915 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 916 | // the alternate-protocol job will "win". |
| 917 | AddHangingNonAlternateProtocolSocketData(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 918 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 919 | CreateSessionWithNextProtos(); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 920 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 921 | SendRequestAndExpectHttpResponse("hello world"); |
| 922 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 923 | } |
| 924 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 925 | TEST_P(QuicNetworkTransactionTest, AlternateProtocolDifferentPort) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 926 | params_.enable_insecure_quic = true; |
| 927 | |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 928 | MockRead http_reads[] = { |
| 929 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 930 | MockRead(kQuicAlternateProtocolDifferentPortHttpHeader), |
| 931 | MockRead("hello world"), |
| 932 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 933 | MockRead(ASYNC, OK)}; |
| 934 | |
| 935 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 936 | 0); |
| 937 | socket_factory_.AddSocketDataProvider(&http_data); |
| 938 | |
| 939 | MockQuicData mock_quic_data; |
| 940 | mock_quic_data.AddWrite( |
| 941 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 942 | GetRequestHeaders("GET", "http", "/"))); |
| 943 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 944 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 945 | mock_quic_data.AddRead( |
| 946 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 947 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 948 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 949 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 950 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 951 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | 62a44f02 | 2015-04-02 15:59:41 | [diff] [blame] | 952 | |
| 953 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 954 | // the alternate-protocol job will "win". |
| 955 | AddHangingNonAlternateProtocolSocketData(); |
| 956 | |
| 957 | CreateSessionWithNextProtos(); |
| 958 | |
| 959 | SendRequestAndExpectHttpResponse("hello world"); |
| 960 | SendRequestAndExpectQuicResponseOnPort("hello!", 137); |
| 961 | } |
| 962 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 963 | TEST_P(QuicNetworkTransactionTest, ConfirmAlternateProtocol) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 964 | params_.enable_insecure_quic = true; |
| 965 | |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 966 | MockRead http_reads[] = { |
| 967 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 968 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 969 | MockRead("hello world"), |
| 970 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 971 | MockRead(ASYNC, OK)}; |
| 972 | |
| 973 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 974 | 0); |
| 975 | socket_factory_.AddSocketDataProvider(&http_data); |
| 976 | |
| 977 | MockQuicData mock_quic_data; |
| 978 | mock_quic_data.AddWrite( |
| 979 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 980 | GetRequestHeaders("GET", "http", "/"))); |
| 981 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 982 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 983 | mock_quic_data.AddRead( |
| 984 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 985 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 986 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 987 | mock_quic_data.AddRead(ASYNC, 0); // EOF |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 988 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 989 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 990 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 991 | |
| 992 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 993 | // the alternate-protocol job will "win". |
| 994 | AddHangingNonAlternateProtocolSocketData(); |
| 995 | |
| 996 | CreateSessionWithNextProtos(); |
| 997 | |
| 998 | AlternativeService alternative_service(QUIC, |
| 999 | HostPortPair::FromURL(request_.url)); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 1000 | http_server_properties_.MarkAlternativeServiceRecentlyBroken( |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 1001 | alternative_service); |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 1002 | EXPECT_TRUE(http_server_properties_.WasAlternativeServiceRecentlyBroken( |
| 1003 | alternative_service)); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 1004 | |
| 1005 | SendRequestAndExpectHttpResponse("hello world"); |
| 1006 | SendRequestAndExpectQuicResponse("hello!"); |
| 1007 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1008 | mock_quic_data.CompleteRead(); |
| 1009 | |
bnc | 6be245c1 | 2015-05-15 11:24:07 | [diff] [blame] | 1010 | EXPECT_FALSE(http_server_properties_.WasAlternativeServiceRecentlyBroken( |
| 1011 | alternative_service)); |
bnc | ae8db840 | 2015-03-26 20:13:50 | [diff] [blame] | 1012 | } |
| 1013 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1014 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1015 | params_.enable_insecure_quic = true; |
| 1016 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1017 | MockRead http_reads[] = { |
| 1018 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1019 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 1020 | MockRead("hello world"), |
| 1021 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1022 | MockRead(ASYNC, OK) |
| 1023 | }; |
| 1024 | |
| 1025 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1026 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1027 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1028 | |
| 1029 | MockQuicData mock_quic_data; |
| 1030 | mock_quic_data.AddWrite( |
| 1031 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 1032 | GetRequestHeaders("GET", "http", "/"))); |
| 1033 | mock_quic_data.AddRead( |
| 1034 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
| 1035 | GetResponseHeaders("200 OK"))); |
| 1036 | mock_quic_data.AddRead( |
| 1037 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 1038 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1039 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1040 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
| 1041 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1042 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1043 | |
| 1044 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 1045 | // the alternate-protocol job will "win". |
| 1046 | AddHangingNonAlternateProtocolSocketData(); |
| 1047 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1048 | params_.alternative_service_probability_threshold = .25; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1049 | CreateSessionWithNextProtos(); |
| 1050 | |
| 1051 | SendRequestAndExpectHttpResponse("hello world"); |
| 1052 | SendRequestAndExpectQuicResponse("hello!"); |
| 1053 | } |
| 1054 | |
| 1055 | TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1056 | params_.enable_insecure_quic = true; |
| 1057 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1058 | MockRead http_reads[] = { |
| 1059 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1060 | MockRead(kQuicAlternateProtocol50pctHttpHeader), |
| 1061 | MockRead("hello world"), |
| 1062 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1063 | MockRead(ASYNC, OK) |
| 1064 | }; |
| 1065 | |
| 1066 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1067 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1068 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1069 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1070 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1071 | params_.alternative_service_probability_threshold = .75; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1072 | CreateSessionWithNextProtos(); |
| 1073 | |
| 1074 | SendRequestAndExpectHttpResponse("hello world"); |
| 1075 | SendRequestAndExpectHttpResponse("hello world"); |
| 1076 | } |
| 1077 | |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1078 | TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolForInsecureQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1079 | params_.enable_insecure_quic = true; |
| 1080 | |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1081 | MockRead http_reads[] = {MockRead("HTTP/1.1 200 OK\r\n"), |
| 1082 | MockRead("Content-length: 11\r\n"), |
| 1083 | MockRead("Alternate-Protocol: 443:quic\r\n\r\n"), |
| 1084 | MockRead("hello world"), |
| 1085 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1086 | MockRead("Content-length: 11\r\n"), |
| 1087 | MockRead("Alternate-Protocol: 443:quic\r\n\r\n"), |
| 1088 | MockRead("hello world"), |
| 1089 | MockRead(ASYNC, OK)}; |
| 1090 | |
| 1091 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), nullptr, |
| 1092 | 0); |
| 1093 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1094 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1095 | |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1096 | params_.enable_insecure_quic = false; |
rch | 405ed7a | 2015-05-12 01:10:16 | [diff] [blame] | 1097 | CreateSessionWithNextProtos(); |
| 1098 | |
| 1099 | SendRequestAndExpectHttpResponse("hello world"); |
| 1100 | SendRequestAndExpectHttpResponse("hello world"); |
| 1101 | } |
| 1102 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1103 | TEST_P(QuicNetworkTransactionTest, |
| 1104 | DontUseAlternateProtocolWithBadProbabilityForQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1105 | params_.enable_insecure_quic = true; |
| 1106 | |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1107 | MockRead http_reads[] = { |
| 1108 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1109 | MockRead("Alternate-Protocol: 443:quic,p=2\r\n\r\n"), |
| 1110 | MockRead("hello world"), |
| 1111 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1112 | MockRead(ASYNC, OK) |
| 1113 | }; |
| 1114 | |
| 1115 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1116 | nullptr, 0); |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1117 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1118 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1119 | |
bnc | 62891a5 | 2015-04-27 14:14:12 | [diff] [blame] | 1120 | params_.alternative_service_probability_threshold = .75; |
[email protected] | 287d941 | 2014-07-08 23:01:00 | [diff] [blame] | 1121 | CreateSessionWithNextProtos(); |
| 1122 | |
| 1123 | SendRequestAndExpectHttpResponse("hello world"); |
| 1124 | SendRequestAndExpectHttpResponse("hello world"); |
| 1125 | } |
| 1126 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1127 | TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1128 | params_.enable_insecure_quic = true; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 1129 | params_.origin_to_force_quic_on = |
| 1130 | HostPortPair::FromString("www.google.com:443"); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 1131 | |
| 1132 | MockRead http_reads[] = { |
| 1133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1134 | MockRead(kQuicAlternateProtocolHttpsHeader), |
| 1135 | MockRead("hello world"), |
| 1136 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1137 | MockRead(ASYNC, OK) |
| 1138 | }; |
| 1139 | |
| 1140 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1141 | nullptr, 0); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 1142 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1143 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1144 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1145 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1146 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1147 | GetRequestHeaders("GET", "http", "/"))); |
| 1148 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1149 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1150 | GetResponseHeaders("200 OK"))); |
| 1151 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1152 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1153 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1154 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1155 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 1156 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1157 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 1158 | |
| 1159 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 1160 | // the alternate-protocol job will "win". |
| 1161 | AddHangingNonAlternateProtocolSocketData(); |
| 1162 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1163 | CreateSessionWithNextProtos(); |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 1164 | |
| 1165 | // TODO(rtenneti): Test QUIC over HTTPS, GetSSLInfo(). |
| 1166 | SendRequestAndExpectHttpResponse("hello world"); |
| 1167 | } |
| 1168 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 1169 | class QuicAltSvcCertificateVerificationTest |
| 1170 | : public QuicNetworkTransactionTest { |
| 1171 | public: |
| 1172 | void Run(bool valid) { |
| 1173 | HostPortPair origin(valid ? "mail.example.org" : "invalid.example.org", |
| 1174 | 443); |
| 1175 | HostPortPair alternative("www.example.org", 443); |
| 1176 | std::string url("https://"); |
| 1177 | url.append(origin.host()); |
| 1178 | url.append(":443"); |
| 1179 | request_.url = GURL(url); |
| 1180 | |
| 1181 | maker_.set_hostname(origin.host()); |
| 1182 | MockQuicData mock_quic_data; |
| 1183 | mock_quic_data.AddWrite( |
| 1184 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 1185 | GetRequestHeaders("GET", "https", "/"))); |
| 1186 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 1187 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 1188 | mock_quic_data.AddRead( |
| 1189 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 1190 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1191 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 1192 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1193 | |
| 1194 | scoped_refptr<X509Certificate> cert( |
| 1195 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 1196 | ASSERT_TRUE(cert.get()); |
| 1197 | bool common_name_fallback_used; |
| 1198 | EXPECT_EQ(valid, |
| 1199 | cert->VerifyNameMatch(origin.host(), &common_name_fallback_used)); |
| 1200 | EXPECT_TRUE( |
| 1201 | cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used)); |
| 1202 | ProofVerifyDetailsChromium verify_details; |
| 1203 | verify_details.cert_verify_result.verified_cert = cert; |
| 1204 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 1205 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1206 | crypto_client_stream_factory_.set_handshake_mode( |
| 1207 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 1208 | |
| 1209 | // Connection to |origin| fails, so that success of |request| depends on |
| 1210 | // connection to |alternate| only. |
| 1211 | MockConnect refused_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 1212 | StaticSocketDataProvider refused_data; |
| 1213 | refused_data.set_connect_data(refused_connect); |
| 1214 | socket_factory_.AddSocketDataProvider(&refused_data); |
| 1215 | |
| 1216 | CreateSessionWithNextProtos(); |
| 1217 | AlternativeService alternative_service(QUIC, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 1218 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 1219 | session_->http_server_properties()->SetAlternativeService( |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 1220 | origin, alternative_service, 1.0, expiration); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 1221 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1222 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1223 | TestCompletionCallback callback; |
| 1224 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1225 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1226 | rv = callback.WaitForResult(); |
| 1227 | if (valid) { |
| 1228 | EXPECT_EQ(OK, rv); |
| 1229 | CheckWasQuicResponse(trans); |
| 1230 | CheckResponsePort(trans, 443); |
| 1231 | CheckResponseData(trans, "hello!"); |
| 1232 | } else { |
| 1233 | EXPECT_EQ(ERR_CONNECTION_REFUSED, rv); |
| 1234 | } |
| 1235 | } |
| 1236 | }; |
| 1237 | |
| 1238 | INSTANTIATE_TEST_CASE_P(Version, |
| 1239 | QuicAltSvcCertificateVerificationTest, |
| 1240 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 1241 | |
| 1242 | TEST_P(QuicAltSvcCertificateVerificationTest, |
| 1243 | RequestSucceedsWithValidCertificate) { |
| 1244 | Run(true); |
| 1245 | } |
| 1246 | |
| 1247 | TEST_P(QuicAltSvcCertificateVerificationTest, |
| 1248 | RequestFailsWithInvalidCertificate) { |
| 1249 | Run(false); |
| 1250 | } |
| 1251 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1252 | TEST_P(QuicNetworkTransactionTest, HungAlternateProtocol) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1253 | params_.enable_insecure_quic = true; |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 1254 | crypto_client_stream_factory_.set_handshake_mode( |
| 1255 | MockCryptoClientStream::COLD_START); |
| 1256 | |
| 1257 | MockWrite http_writes[] = { |
| 1258 | MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 1259 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 1260 | MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 1261 | }; |
| 1262 | |
| 1263 | MockRead http_reads[] = { |
| 1264 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 1265 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 1266 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 1267 | MockRead(SYNCHRONOUS, OK, 6) |
| 1268 | }; |
| 1269 | |
| 1270 | DeterministicMockClientSocketFactory socket_factory; |
| 1271 | |
| 1272 | DeterministicSocketData http_data(http_reads, arraysize(http_reads), |
| 1273 | http_writes, arraysize(http_writes)); |
| 1274 | socket_factory.AddSocketDataProvider(&http_data); |
| 1275 | |
| 1276 | // The QUIC transaction will not be allowed to complete. |
| 1277 | MockWrite quic_writes[] = { |
| 1278 | MockWrite(ASYNC, ERR_IO_PENDING, 0) |
| 1279 | }; |
| 1280 | MockRead quic_reads[] = { |
| 1281 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 1282 | }; |
| 1283 | DeterministicSocketData quic_data(quic_reads, arraysize(quic_reads), |
| 1284 | quic_writes, arraysize(quic_writes)); |
| 1285 | socket_factory.AddSocketDataProvider(&quic_data); |
| 1286 | |
| 1287 | // The HTTP transaction will complete. |
| 1288 | DeterministicSocketData http_data2(http_reads, arraysize(http_reads), |
| 1289 | http_writes, arraysize(http_writes)); |
| 1290 | socket_factory.AddSocketDataProvider(&http_data2); |
| 1291 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1292 | CreateSessionWithFactory(&socket_factory, true); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 1293 | |
| 1294 | // Run the first request. |
| 1295 | http_data.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 1296 | SendRequestAndExpectHttpResponse("hello world"); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1297 | ASSERT_TRUE(http_data.AllReadDataConsumed()); |
| 1298 | ASSERT_TRUE(http_data.AllWriteDataConsumed()); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 1299 | |
| 1300 | // Now run the second request in which the QUIC socket hangs, |
| 1301 | // and verify the the transaction continues over HTTP. |
| 1302 | http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 1303 | SendRequestAndExpectHttpResponse("hello world"); |
| 1304 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1305 | ASSERT_TRUE(http_data2.AllReadDataConsumed()); |
| 1306 | ASSERT_TRUE(http_data2.AllWriteDataConsumed()); |
| 1307 | ASSERT_TRUE(!quic_data.AllReadDataConsumed()); |
| 1308 | ASSERT_TRUE(!quic_data.AllWriteDataConsumed()); |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 1309 | } |
| 1310 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1311 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1312 | params_.enable_insecure_quic = true; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1313 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1314 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1315 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1316 | GetRequestHeaders("GET", "http", "/"))); |
| 1317 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1318 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1319 | GetResponseHeaders("200 OK"))); |
| 1320 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1321 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1322 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1323 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1324 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 1325 | |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1326 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 1327 | |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1328 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 1329 | // the alternate-protocol job will "win". |
[email protected] | dda75ab | 2013-06-22 22:43:30 | [diff] [blame] | 1330 | AddHangingNonAlternateProtocolSocketData(); |
| 1331 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1332 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1333 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1334 | SendRequestAndExpectQuicResponse("hello!"); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 1335 | } |
| 1336 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1337 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1338 | params_.enable_insecure_quic = true; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1339 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1340 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1341 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1342 | GetRequestHeaders("GET", "http", "/"))); |
| 1343 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1344 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1345 | GetResponseHeaders("200 OK"))); |
| 1346 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1347 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1348 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1349 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1350 | mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1351 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1352 | |
| 1353 | // In order for a new QUIC session to be established via alternate-protocol |
| 1354 | // without racing an HTTP connection, we need the host resolution to happen |
| 1355 | // synchronously. |
| 1356 | host_resolver_.set_synchronous_mode(true); |
| 1357 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1358 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1359 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1360 | host_resolver_.Resolve(info, |
| 1361 | DEFAULT_PRIORITY, |
| 1362 | &address, |
| 1363 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1364 | nullptr, |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1365 | net_log_.bound()); |
| 1366 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1367 | CreateSessionWithNextProtos(); |
[email protected] | 3a120a6b | 2013-06-25 01:08:27 | [diff] [blame] | 1368 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1369 | SendRequestAndExpectQuicResponse("hello!"); |
| 1370 | } |
| 1371 | |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1372 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1373 | params_.enable_insecure_quic = true; |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1374 | proxy_service_.reset( |
| 1375 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1376 | |
| 1377 | // Since we are using a proxy, the QUIC job will not succeed. |
| 1378 | MockWrite http_writes[] = { |
| 1379 | MockWrite(SYNCHRONOUS, 0, "GET http://www.google.com/ HTTP/1.1\r\n"), |
| 1380 | MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 1381 | MockWrite(SYNCHRONOUS, 2, "Proxy-Connection: keep-alive\r\n\r\n") |
| 1382 | }; |
| 1383 | |
| 1384 | MockRead http_reads[] = { |
| 1385 | MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 1386 | MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 1387 | MockRead(SYNCHRONOUS, 5, "hello world"), |
| 1388 | MockRead(SYNCHRONOUS, OK, 6) |
| 1389 | }; |
| 1390 | |
| 1391 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 1392 | http_writes, arraysize(http_writes)); |
| 1393 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1394 | |
| 1395 | // In order for a new QUIC session to be established via alternate-protocol |
| 1396 | // without racing an HTTP connection, we need the host resolution to happen |
| 1397 | // synchronously. |
| 1398 | host_resolver_.set_synchronous_mode(true); |
| 1399 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 1400 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 1401 | AddressList address; |
| 1402 | host_resolver_.Resolve(info, |
| 1403 | DEFAULT_PRIORITY, |
| 1404 | &address, |
| 1405 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1406 | nullptr, |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1407 | net_log_.bound()); |
| 1408 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1409 | CreateSessionWithNextProtos(); |
[email protected] | 0fc924b | 2014-03-31 04:34:15 | [diff] [blame] | 1410 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1411 | SendRequestAndExpectHttpResponse("hello world"); |
| 1412 | } |
| 1413 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1414 | TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1415 | params_.enable_insecure_quic = true; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1416 | MockQuicData mock_quic_data; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1417 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1418 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1419 | GetRequestHeaders("GET", "http", "/"))); |
| 1420 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1421 | ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1422 | GetResponseHeaders("200 OK"))); |
| 1423 | mock_quic_data.AddRead( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1424 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1425 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1426 | mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1427 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1428 | |
| 1429 | // The non-alternate protocol job needs to hang in order to guarantee that |
| 1430 | // the alternate-protocol job will "win". |
| 1431 | AddHangingNonAlternateProtocolSocketData(); |
| 1432 | |
| 1433 | // In order for a new QUIC session to be established via alternate-protocol |
| 1434 | // without racing an HTTP connection, we need the host resolution to happen |
| 1435 | // synchronously. Of course, even though QUIC *could* perform a 0-RTT |
| 1436 | // connection to the the server, in this test we require confirmation |
| 1437 | // before encrypting so the HTTP job will still start. |
| 1438 | host_resolver_.set_synchronous_mode(true); |
| 1439 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1440 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1441 | AddressList address; |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 1442 | host_resolver_.Resolve(info, DEFAULT_PRIORITY, &address, |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1443 | CompletionCallback(), nullptr, net_log_.bound()); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1444 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1445 | CreateSessionWithNextProtos(); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1446 | session_->quic_stream_factory()->set_require_confirmation(true); |
| 1447 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1448 | |
| 1449 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1450 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1451 | TestCompletionCallback callback; |
| 1452 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1453 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1454 | |
| 1455 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 1456 | QuicSession::HANDSHAKE_CONFIRMED); |
| 1457 | EXPECT_EQ(OK, callback.WaitForResult()); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1458 | |
| 1459 | CheckWasQuicResponse(trans); |
| 1460 | CheckResponseData(trans, "hello!"); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1463 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1464 | params_.enable_insecure_quic = true; |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1465 | // Alternate-protocol job |
| 1466 | scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
| 1467 | MockRead quic_reads[] = { |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1468 | MockRead(ASYNC, close->data(), close->length()), |
| 1469 | MockRead(ASYNC, ERR_IO_PENDING), // No more data to read |
| 1470 | MockRead(ASYNC, OK), // EOF |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1471 | }; |
| 1472 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1473 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1474 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1475 | |
| 1476 | // Main job which will succeed even though the alternate job fails. |
| 1477 | MockRead http_reads[] = { |
| 1478 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1479 | MockRead("hello from http"), |
| 1480 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1481 | MockRead(ASYNC, OK) |
| 1482 | }; |
| 1483 | |
| 1484 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1485 | nullptr, 0); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1486 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1487 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1488 | CreateSessionWithNextProtos(); |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1489 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1490 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1491 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 3316d42 | 2013-05-03 21:45:30 | [diff] [blame] | 1492 | } |
| 1493 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1494 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1495 | params_.enable_insecure_quic = true; |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1496 | // Alternate-protocol job |
| 1497 | MockRead quic_reads[] = { |
| 1498 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1499 | }; |
| 1500 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1501 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1502 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1503 | |
| 1504 | // Main job which will succeed even though the alternate job fails. |
| 1505 | MockRead http_reads[] = { |
| 1506 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1507 | MockRead("hello from http"), |
| 1508 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1509 | MockRead(ASYNC, OK) |
| 1510 | }; |
| 1511 | |
| 1512 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1513 | nullptr, 0); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1514 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1515 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1516 | CreateSessionWithNextProtos(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1517 | |
[email protected] | aa9b14d | 2013-05-10 23:45:19 | [diff] [blame] | 1518 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1519 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1520 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | d03a66d | 2013-05-06 12:55:59 | [diff] [blame] | 1521 | } |
| 1522 | |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1523 | TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1524 | params_.enable_insecure_quic = true; |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1525 | // Alternate-protocol job will fail when the session attempts to read. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1526 | MockRead quic_reads[] = { |
| 1527 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1528 | }; |
| 1529 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1530 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1531 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1532 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1533 | // Main job will also fail. |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1534 | MockRead http_reads[] = { |
| 1535 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1536 | }; |
| 1537 | |
| 1538 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1539 | nullptr, 0); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1540 | http_data.set_connect_data(MockConnect(ASYNC, ERR_SOCKET_NOT_CONNECTED)); |
| 1541 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1542 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1543 | CreateSessionWithNextProtos(); |
[email protected] | 00c159f | 2014-05-21 22:38:16 | [diff] [blame] | 1544 | |
| 1545 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1546 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1547 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1548 | TestCompletionCallback callback; |
| 1549 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1550 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1551 | EXPECT_EQ(ERR_SOCKET_NOT_CONNECTED, callback.WaitForResult()); |
| 1552 | ExpectQuicAlternateProtocolMapping(); |
| 1553 | } |
| 1554 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1555 | TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1556 | params_.enable_insecure_quic = true; |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1557 | // Alternate-protocol job |
| 1558 | MockRead quic_reads[] = { |
| 1559 | MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
| 1560 | }; |
| 1561 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1562 | nullptr, 0); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1563 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1564 | |
| 1565 | AddHangingNonAlternateProtocolSocketData(); |
| 1566 | |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1567 | // Second Alternate-protocol job which will race with the TCP job. |
| 1568 | StaticSocketDataProvider quic_data2(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1569 | nullptr, 0); |
[email protected] | c92c1b5 | 2014-05-31 04:16:06 | [diff] [blame] | 1570 | socket_factory_.AddSocketDataProvider(&quic_data2); |
| 1571 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1572 | // Final job that will proceed when the QUIC job fails. |
| 1573 | MockRead http_reads[] = { |
| 1574 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1575 | MockRead("hello from http"), |
| 1576 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1577 | MockRead(ASYNC, OK) |
| 1578 | }; |
| 1579 | |
| 1580 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1581 | nullptr, 0); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1582 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1583 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1584 | CreateSessionWithNextProtos(); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1585 | |
| 1586 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1587 | |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1588 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1589 | |
| 1590 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1591 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1592 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 1593 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
[email protected] | 77c6c16 | 2013-08-17 02:57:45 | [diff] [blame] | 1594 | } |
| 1595 | |
[email protected] | 93b3177 | 2014-06-19 08:03:35 | [diff] [blame] | 1596 | TEST_P(QuicNetworkTransactionTest, DISABLED_HangingZeroRttFallback) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1597 | params_.enable_insecure_quic = true; |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1598 | // Alternate-protocol job |
| 1599 | MockRead quic_reads[] = { |
| 1600 | MockRead(ASYNC, ERR_IO_PENDING), |
| 1601 | }; |
| 1602 | StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1603 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1604 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1605 | |
| 1606 | // Main job that will proceed when the QUIC job fails. |
| 1607 | MockRead http_reads[] = { |
| 1608 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1609 | MockRead("hello from http"), |
| 1610 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1611 | MockRead(ASYNC, OK) |
| 1612 | }; |
| 1613 | |
| 1614 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1615 | nullptr, 0); |
[email protected] | 6576844 | 2014-06-06 23:37:03 | [diff] [blame] | 1616 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1617 | |
| 1618 | CreateSessionWithNextProtos(); |
| 1619 | |
| 1620 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1621 | |
| 1622 | SendRequestAndExpectHttpResponse("hello from http"); |
| 1623 | } |
| 1624 | |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1625 | TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1626 | params_.enable_insecure_quic = true; |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1627 | // Alternate-protocol job will fail before creating a QUIC session. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1628 | StaticSocketDataProvider quic_data(nullptr, 0, nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1629 | quic_data.set_connect_data(MockConnect(SYNCHRONOUS, |
| 1630 | ERR_INTERNET_DISCONNECTED)); |
| 1631 | socket_factory_.AddSocketDataProvider(&quic_data); |
| 1632 | |
| 1633 | // Main job which will succeed even though the alternate job fails. |
| 1634 | MockRead http_reads[] = { |
| 1635 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 1636 | MockRead("hello from http"), |
| 1637 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1638 | MockRead(ASYNC, OK) |
| 1639 | }; |
| 1640 | |
| 1641 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1642 | nullptr, 0); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1643 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1644 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1645 | CreateSessionWithNextProtos(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1646 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 1647 | SendRequestAndExpectHttpResponse("hello from http"); |
[email protected] | eb71ab6 | 2014-05-23 07:57:53 | [diff] [blame] | 1648 | |
| 1649 | ExpectBrokenAlternateProtocolMapping(); |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 1650 | } |
| 1651 | |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1652 | TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1653 | params_.enable_insecure_quic = true; |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1654 | MockQuicData mock_quic_data; |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1655 | mock_quic_data.AddSynchronousRead(ConstructConnectionClosePacket(1)); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1656 | mock_quic_data.AddWrite( |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1657 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 1658 | GetRequestHeaders("GET", "http", "/"))); |
| 1659 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | a5399e0 | 2015-04-21 19:32:04 | [diff] [blame] | 1660 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1661 | |
| 1662 | // When the QUIC connection fails, we will try the request again over HTTP. |
| 1663 | MockRead http_reads[] = { |
| 1664 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1665 | MockRead(kQuicAlternateProtocolHttpHeader), |
| 1666 | MockRead("hello world"), |
| 1667 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 1668 | MockRead(ASYNC, OK) |
| 1669 | }; |
| 1670 | |
| 1671 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1672 | nullptr, 0); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1673 | socket_factory_.AddSocketDataProvider(&http_data); |
| 1674 | |
| 1675 | // In order for a new QUIC session to be established via alternate-protocol |
| 1676 | // without racing an HTTP connection, we need the host resolution to happen |
| 1677 | // synchronously. |
| 1678 | host_resolver_.set_synchronous_mode(true); |
| 1679 | host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", ""); |
| 1680 | HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); |
| 1681 | AddressList address; |
| 1682 | host_resolver_.Resolve(info, |
| 1683 | DEFAULT_PRIORITY, |
| 1684 | &address, |
| 1685 | CompletionCallback(), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1686 | nullptr, |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1687 | net_log_.bound()); |
| 1688 | |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1689 | CreateSessionWithNextProtos(); |
[email protected] | 4fee967 | 2014-01-08 14:47:15 | [diff] [blame] | 1690 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1691 | SendRequestAndExpectHttpResponse("hello world"); |
| 1692 | } |
| 1693 | |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1694 | // Test that a secure request over an insecure QUIC connection fails with |
| 1695 | // the appropriate error code. Note that this never happens in production, |
| 1696 | // because the handshake (which this test mocks) would fail in this scenario. |
| 1697 | TEST_P(QuicNetworkTransactionTest, SecureResourceOverInsecureQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1698 | params_.enable_insecure_quic = true; |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1699 | maker_.set_hostname("www.example.org"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1700 | MockQuicData mock_quic_data; |
| 1701 | mock_quic_data.AddWrite( |
| 1702 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 1703 | GetRequestHeaders("GET", "https", "/"))); |
| 1704 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 1705 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 1706 | mock_quic_data.AddRead( |
| 1707 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 1708 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
| 1709 | mock_quic_data.AddRead(SYNCHRONOUS, 0); |
| 1710 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1711 | |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1712 | request_.url = GURL("https://www.example.org:443"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1713 | AddHangingNonAlternateProtocolSocketData(); |
| 1714 | CreateSessionWithNextProtos(); |
| 1715 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 1716 | scoped_ptr<HttpNetworkTransaction> trans( |
| 1717 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 1718 | TestCompletionCallback callback; |
| 1719 | int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
| 1720 | EXPECT_EQ(ERR_REQUEST_FOR_SECURE_RESOURCE_OVER_INSECURE_QUIC, |
| 1721 | callback.GetResult(rv)); |
| 1722 | } |
| 1723 | |
| 1724 | TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
rch | ff01212 | 2015-07-27 20:01:40 | [diff] [blame] | 1725 | params_.enable_insecure_quic = true; |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1726 | maker_.set_hostname("www.example.org"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1727 | MockQuicData mock_quic_data; |
| 1728 | mock_quic_data.AddWrite( |
| 1729 | ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
| 1730 | GetRequestHeaders("GET", "https", "/"))); |
| 1731 | mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
| 1732 | 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
| 1733 | mock_quic_data.AddRead( |
| 1734 | ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
| 1735 | mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1736 | mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1737 | mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 1738 | |
| 1739 | scoped_refptr<X509Certificate> cert( |
| 1740 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 1741 | ASSERT_TRUE(cert.get()); |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1742 | bool common_name_fallback_used; |
| 1743 | EXPECT_TRUE( |
| 1744 | cert->VerifyNameMatch("www.example.org", &common_name_fallback_used)); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1745 | ProofVerifyDetailsChromium verify_details; |
| 1746 | verify_details.cert_verify_result.verified_cert = cert; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1747 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1748 | |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 1749 | request_.url = GURL("https://www.example.org:443"); |
bnc | 50883590 | 2015-05-12 20:10:29 | [diff] [blame] | 1750 | AddHangingNonAlternateProtocolSocketData(); |
| 1751 | CreateSessionWithNextProtos(); |
| 1752 | AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
| 1753 | SendRequestAndExpectQuicResponse("hello!"); |
| 1754 | } |
| 1755 | |
[email protected] | 61a52778 | 2013-02-21 03:58:00 | [diff] [blame] | 1756 | } // namespace test |
| 1757 | } // namespace net |