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