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