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