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