[email protected] | e13201d8 | 2012-12-12 05:00:32 | [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 | |
| 5 | #include "net/quic/quic_stream_factory.h" |
| 6 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 7 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 8 | #include "base/strings/string_util.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 9 | #include "net/base/test_data_directory.h" |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 10 | #include "net/cert/cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 11 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 12 | #include "net/http/http_response_headers.h" |
| 13 | #include "net/http/http_response_info.h" |
| 14 | #include "net/http/http_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 15 | #include "net/http/transport_security_state.h" |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 16 | #include "net/quic/crypto/crypto_handshake.h" |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 17 | #include "net/quic/crypto/proof_verifier_chromium.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 18 | #include "net/quic/crypto/quic_decrypter.h" |
| 19 | #include "net/quic/crypto/quic_encrypter.h" |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 20 | #include "net/quic/crypto/quic_server_info.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 21 | #include "net/quic/quic_http_stream.h" |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 22 | #include "net/quic/quic_server_id.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 23 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 24 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 25 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 26 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 27 | #include "net/quic/test_tools/quic_test_utils.h" |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 28 | #include "net/quic/test_tools/test_task_runner.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 29 | #include "net/socket/socket_test_util.h" |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 30 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 31 | #include "net/ssl/channel_id_service.h" |
| 32 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 33 | #include "net/test/cert_test_util.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 34 | #include "testing/gtest/include/gtest/gtest.h" |
| 35 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 36 | using base::StringPiece; |
| 37 | using std::string; |
| 38 | using std::vector; |
| 39 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 40 | namespace net { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 41 | namespace test { |
| 42 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 43 | namespace { |
| 44 | const char kDefaultServerHostName[] = "www.google.com"; |
| 45 | const int kDefaultServerPort = 443; |
| 46 | } // namespace anonymous |
| 47 | |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 48 | class QuicStreamFactoryPeer { |
| 49 | public: |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 50 | static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) { |
| 51 | return &factory->crypto_config_; |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 52 | } |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 53 | |
| 54 | static bool HasActiveSession(QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 55 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 56 | bool is_https) { |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 57 | QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); |
| 58 | return factory->HasActiveSession(server_id); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static QuicClientSession* GetActiveSession( |
| 62 | QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 63 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 64 | bool is_https) { |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 65 | QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); |
| 66 | DCHECK(factory->HasActiveSession(server_id)); |
| 67 | return factory->active_sessions_[server_id]; |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
| 71 | QuicStreamFactory* factory, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 72 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 73 | bool is_https, |
| 74 | const BoundNetLog& net_log) { |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 75 | QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED); |
| 76 | return factory->CreateIfSessionExists(server_id, net_log); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static bool IsLiveSession(QuicStreamFactory* factory, |
| 80 | QuicClientSession* session) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 81 | for (QuicStreamFactory::SessionIdMap::iterator it = |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 82 | factory->all_sessions_.begin(); |
| 83 | it != factory->all_sessions_.end(); ++it) { |
[email protected] | 4d590c9c | 2014-05-02 05:14:33 | [diff] [blame] | 84 | if (it->first == session) |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 85 | return true; |
| 86 | } |
| 87 | return false; |
| 88 | } |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 89 | |
| 90 | static void DisableConnectionPooling(QuicStreamFactory* factory) { |
| 91 | factory->disable_connection_pooling_ = true; |
| 92 | } |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 93 | |
| 94 | static void SetTaskRunner(QuicStreamFactory* factory, |
| 95 | base::TaskRunner* task_runner) { |
| 96 | factory->task_runner_ = task_runner; |
| 97 | } |
| 98 | |
| 99 | static void SetLoadServerInfoTimeout(QuicStreamFactory* factory, |
| 100 | size_t load_server_info_timeout) { |
| 101 | factory->load_server_info_timeout_ms_ = load_server_info_timeout; |
| 102 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 103 | }; |
| 104 | |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 105 | class MockQuicServerInfo : public QuicServerInfo { |
| 106 | public: |
| 107 | MockQuicServerInfo(const QuicServerId& server_id) |
| 108 | : QuicServerInfo(server_id) {} |
| 109 | virtual ~MockQuicServerInfo() {} |
| 110 | |
| 111 | virtual void Start() override {}; |
| 112 | |
| 113 | virtual int WaitForDataReady(const CompletionCallback& callback) override { |
| 114 | return ERR_IO_PENDING; |
| 115 | } |
| 116 | |
| 117 | virtual void CancelWaitForDataReadyCallback() override {} |
| 118 | |
| 119 | virtual bool IsDataReady() override { return false; } |
| 120 | |
| 121 | virtual bool IsReadyToPersist() override { return false; } |
| 122 | |
| 123 | virtual void Persist() override {}; |
| 124 | }; |
| 125 | |
| 126 | class MockQuicServerInfoFactory : public QuicServerInfoFactory { |
| 127 | public: |
| 128 | MockQuicServerInfoFactory() {} |
| 129 | virtual ~MockQuicServerInfoFactory() {} |
| 130 | |
| 131 | virtual QuicServerInfo* GetForServer(const QuicServerId& server_id) override { |
| 132 | return new MockQuicServerInfo(server_id); |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 137 | class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 138 | protected: |
| 139 | QuicStreamFactoryTest() |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 140 | : random_generator_(0), |
| 141 | clock_(new MockClock()), |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 142 | runner_(new TestTaskRunner(clock_)), |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 143 | maker_(GetParam(), 0, clock_), |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 144 | cert_verifier_(CertVerifier::CreateDefault()), |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 145 | channel_id_service_( |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 146 | new ChannelIDService(new DefaultChannelIDStore(nullptr), |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 147 | base::MessageLoopProxy::current())), |
| 148 | factory_(&host_resolver_, |
| 149 | &socket_factory_, |
| 150 | base::WeakPtr<HttpServerProperties>(), |
| 151 | cert_verifier_.get(), |
| 152 | channel_id_service_.get(), |
| 153 | &transport_security_state_, |
| 154 | &crypto_client_stream_factory_, |
| 155 | &random_generator_, |
| 156 | clock_, |
| 157 | kDefaultMaxPacketSize, |
| 158 | std::string(), |
| 159 | SupportedVersions(GetParam()), |
| 160 | /*enable_port_selection=*/true, |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 161 | /*always_require_handshake_confirmation=*/false, |
| 162 | /*disable_connection_pooling=*/false, |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 163 | /*load_server_info_timeout=*/0u, |
jri | 2b966f2 | 2014-09-02 22:25:36 | [diff] [blame] | 164 | QuicTagVector()), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 165 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 166 | is_https_(false), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 167 | privacy_mode_(PRIVACY_MODE_DISABLED) { |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 168 | factory_.set_require_confirmation(false); |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 169 | clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 172 | scoped_ptr<QuicHttpStream> CreateIfSessionExists( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 173 | const HostPortPair& host_port_pair, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 174 | const BoundNetLog& net_log) { |
| 175 | return QuicStreamFactoryPeer::CreateIfSessionExists( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 176 | &factory_, host_port_pair, false, net_log_); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 177 | } |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 178 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 179 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 180 | return GetSourcePortForNewSessionInner(destination, false); |
| 181 | } |
| 182 | |
| 183 | int GetSourcePortForNewSessionAndGoAway( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 184 | const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 185 | return GetSourcePortForNewSessionInner(destination, true); |
| 186 | } |
| 187 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 188 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 189 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 190 | // Should only be called if there is no active session for this destination. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 191 | EXPECT_EQ(nullptr, CreateIfSessionExists(destination, net_log_).get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 192 | size_t socket_count = socket_factory_.udp_client_sockets().size(); |
| 193 | |
| 194 | MockRead reads[] = { |
| 195 | MockRead(ASYNC, OK, 0) // EOF |
| 196 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 197 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 198 | socket_data.StopAfter(1); |
| 199 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 200 | |
| 201 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 202 | EXPECT_EQ(ERR_IO_PENDING, |
| 203 | request.Request(destination, |
| 204 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 205 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 206 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 207 | net_log_, |
| 208 | callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 209 | |
| 210 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 211 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 212 | EXPECT_TRUE(stream.get()); |
| 213 | stream.reset(); |
| 214 | |
| 215 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 216 | &factory_, destination, is_https_); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 217 | |
| 218 | if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) { |
| 219 | EXPECT_TRUE(false); |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | IPEndPoint endpoint; |
| 224 | socket_factory_. |
| 225 | udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint); |
| 226 | int port = endpoint.port(); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 227 | if (goaway_received) { |
| 228 | QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, ""); |
| 229 | session->OnGoAway(goaway); |
| 230 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 231 | |
| 232 | factory_.OnSessionClosed(session); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 233 | EXPECT_EQ(nullptr, CreateIfSessionExists(destination, net_log_).get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 234 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 235 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 236 | return port; |
| 237 | } |
| 238 | |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 239 | scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() { |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 240 | QuicStreamId stream_id = kClientDataStreamId1; |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 241 | return maker_.MakeRstPacket( |
| 242 | 1, true, stream_id, |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 243 | AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam())); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 244 | } |
| 245 | |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 246 | MockQuicServerInfoFactory quic_server_info_factory_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 247 | MockHostResolver host_resolver_; |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 248 | DeterministicMockClientSocketFactory socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 249 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | 9558c5d3 | 2012-12-22 00:08:14 | [diff] [blame] | 250 | MockRandom random_generator_; |
[email protected] | 872edd9e | 2013-01-16 08:51:15 | [diff] [blame] | 251 | MockClock* clock_; // Owned by factory_. |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 252 | scoped_refptr<TestTaskRunner> runner_; |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 253 | QuicTestPacketMaker maker_; |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 254 | scoped_ptr<CertVerifier> cert_verifier_; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 255 | scoped_ptr<ChannelIDService> channel_id_service_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 256 | TransportSecurityState transport_security_state_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 257 | QuicStreamFactory factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 258 | HostPortPair host_port_pair_; |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 259 | bool is_https_; |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 260 | PrivacyMode privacy_mode_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 261 | BoundNetLog net_log_; |
| 262 | TestCompletionCallback callback_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 263 | }; |
| 264 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 265 | INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest, |
| 266 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 267 | |
| 268 | TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) { |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 269 | EXPECT_EQ(nullptr, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 270 | } |
| 271 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 272 | TEST_P(QuicStreamFactoryTest, Create) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 273 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 274 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 275 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 276 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 277 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 278 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 279 | |
| 280 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 281 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 282 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 283 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 284 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 285 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 286 | net_log_, |
| 287 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 288 | |
| 289 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 290 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 291 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 292 | |
| 293 | // Will reset stream 3. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 294 | stream = CreateIfSessionExists(host_port_pair_, net_log_); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 295 | EXPECT_TRUE(stream.get()); |
| 296 | |
[email protected] | 6d1b4ed | 2013-07-10 03:57:54 | [diff] [blame] | 297 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 298 | // in streams on different sessions. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 299 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 300 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 301 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 302 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 303 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 304 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 305 | net_log_, |
| 306 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 307 | stream = request2.ReleaseStream(); // Will reset stream 5. |
| 308 | stream.reset(); // Will reset stream 7. |
| 309 | |
| 310 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 311 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 312 | } |
| 313 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 314 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
| 315 | MockRead reads[] = { |
| 316 | MockRead(ASYNC, OK, 0) // EOF |
| 317 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 318 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 319 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 320 | socket_data.StopAfter(1); |
| 321 | |
| 322 | crypto_client_stream_factory_.set_handshake_mode( |
| 323 | MockCryptoClientStream::ZERO_RTT); |
| 324 | host_resolver_.set_synchronous_mode(true); |
| 325 | host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 326 | "192.168.0.1", ""); |
| 327 | |
| 328 | QuicStreamRequest request(&factory_); |
| 329 | EXPECT_EQ(OK, |
| 330 | request.Request(host_port_pair_, |
| 331 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 332 | privacy_mode_, |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 333 | "GET", |
| 334 | net_log_, |
| 335 | callback_.callback())); |
| 336 | |
| 337 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 338 | EXPECT_TRUE(stream.get()); |
| 339 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 340 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 341 | } |
| 342 | |
| 343 | TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) { |
| 344 | MockRead reads[] = { |
| 345 | MockRead(ASYNC, OK, 0) // EOF |
| 346 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 347 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 348 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 349 | socket_data.StopAfter(1); |
| 350 | |
| 351 | crypto_client_stream_factory_.set_handshake_mode( |
| 352 | MockCryptoClientStream::ZERO_RTT); |
| 353 | host_resolver_.set_synchronous_mode(true); |
| 354 | host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 355 | "192.168.0.1", ""); |
| 356 | |
| 357 | QuicStreamRequest request(&factory_); |
| 358 | // Posts require handshake confirmation, so this will return asynchronously. |
| 359 | EXPECT_EQ(ERR_IO_PENDING, |
| 360 | request.Request(host_port_pair_, |
| 361 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 362 | privacy_mode_, |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 363 | "POST", |
| 364 | net_log_, |
| 365 | callback_.callback())); |
| 366 | |
| 367 | // Confirm the handshake and verify that the stream is created. |
| 368 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 369 | QuicSession::HANDSHAKE_CONFIRMED); |
| 370 | |
| 371 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 372 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 373 | EXPECT_TRUE(stream.get()); |
| 374 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 375 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 376 | } |
| 377 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 378 | TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) { |
| 379 | MockRead reads[] = { |
| 380 | MockRead(ASYNC, OK, 0) // EOF |
| 381 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 382 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 383 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 384 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 385 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 386 | socket_data1.StopAfter(1); |
| 387 | socket_data2.StopAfter(1); |
| 388 | |
| 389 | QuicStreamRequest request(&factory_); |
| 390 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 391 | request.Request(host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 392 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 393 | privacy_mode_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 394 | "GET", |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 395 | net_log_, |
| 396 | callback_.callback())); |
| 397 | |
| 398 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 399 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 400 | EXPECT_TRUE(stream.get()); |
| 401 | |
| 402 | QuicStreamRequest request2(&factory_); |
| 403 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 404 | request2.Request(host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 405 | !is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 406 | privacy_mode_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 407 | "GET", |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 408 | net_log_, |
| 409 | callback_.callback())); |
| 410 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 411 | stream = request2.ReleaseStream(); |
| 412 | EXPECT_TRUE(stream.get()); |
| 413 | stream.reset(); |
| 414 | |
| 415 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 416 | &factory_, host_port_pair_, is_https_), |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 417 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 418 | &factory_, host_port_pair_, !is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 419 | |
| 420 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 421 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 422 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 423 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 424 | } |
| 425 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 426 | TEST_P(QuicStreamFactoryTest, Pooling) { |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 427 | MockRead reads[] = { |
| 428 | MockRead(ASYNC, OK, 0) // EOF |
| 429 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 430 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 431 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 432 | socket_data.StopAfter(1); |
| 433 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 434 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 435 | host_resolver_.set_synchronous_mode(true); |
| 436 | host_resolver_.rules()->AddIPLiteralRule( |
| 437 | kDefaultServerHostName, "192.168.0.1", ""); |
| 438 | host_resolver_.rules()->AddIPLiteralRule( |
| 439 | "mail.google.com", "192.168.0.1", ""); |
| 440 | |
| 441 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 442 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 443 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 444 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 445 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 446 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 447 | net_log_, |
| 448 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 449 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 450 | EXPECT_TRUE(stream.get()); |
| 451 | |
| 452 | TestCompletionCallback callback; |
| 453 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 454 | EXPECT_EQ(OK, |
| 455 | request2.Request(server2, |
| 456 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 457 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 458 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 459 | net_log_, |
| 460 | callback.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 461 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 462 | EXPECT_TRUE(stream2.get()); |
| 463 | |
| 464 | EXPECT_EQ( |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 465 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 466 | &factory_, host_port_pair_, is_https_), |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 467 | QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 468 | |
| 469 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 470 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 471 | } |
| 472 | |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 473 | TEST_P(QuicStreamFactoryTest, NoPoolingIfDisabled) { |
| 474 | MockRead reads[] = { |
| 475 | MockRead(ASYNC, OK, 0) // EOF |
| 476 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 477 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 478 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 479 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 480 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 481 | socket_data1.StopAfter(1); |
| 482 | socket_data2.StopAfter(1); |
| 483 | |
| 484 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
| 485 | host_resolver_.set_synchronous_mode(true); |
| 486 | host_resolver_.rules()->AddIPLiteralRule( |
| 487 | kDefaultServerHostName, "192.168.0.1", ""); |
| 488 | host_resolver_.rules()->AddIPLiteralRule( |
| 489 | "mail.google.com", "192.168.0.1", ""); |
| 490 | |
| 491 | // Disable connection pooling. |
| 492 | QuicStreamFactoryPeer::DisableConnectionPooling(&factory_); |
| 493 | |
| 494 | QuicStreamRequest request(&factory_); |
| 495 | EXPECT_EQ(OK, |
| 496 | request.Request(host_port_pair_, |
| 497 | is_https_, |
| 498 | privacy_mode_, |
| 499 | "GET", |
| 500 | net_log_, |
| 501 | callback_.callback())); |
| 502 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 503 | EXPECT_TRUE(stream.get()); |
| 504 | |
| 505 | TestCompletionCallback callback; |
| 506 | QuicStreamRequest request2(&factory_); |
| 507 | EXPECT_EQ(OK, |
| 508 | request2.Request(server2, |
| 509 | is_https_, |
| 510 | privacy_mode_, |
| 511 | "GET", |
| 512 | net_log_, |
| 513 | callback.callback())); |
| 514 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 515 | EXPECT_TRUE(stream2.get()); |
| 516 | |
| 517 | EXPECT_NE( |
| 518 | QuicStreamFactoryPeer::GetActiveSession( |
| 519 | &factory_, host_port_pair_, is_https_), |
| 520 | QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_)); |
| 521 | |
| 522 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 523 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 524 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 525 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 526 | } |
| 527 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 528 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
| 529 | MockRead reads[] = { |
| 530 | MockRead(ASYNC, OK, 0) // EOF |
| 531 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 532 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 533 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 534 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 535 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 536 | socket_data1.StopAfter(1); |
| 537 | socket_data2.StopAfter(1); |
| 538 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 539 | HostPortPair server2("mail.google.com", kDefaultServerPort); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 540 | host_resolver_.set_synchronous_mode(true); |
| 541 | host_resolver_.rules()->AddIPLiteralRule( |
| 542 | kDefaultServerHostName, "192.168.0.1", ""); |
| 543 | host_resolver_.rules()->AddIPLiteralRule( |
| 544 | "mail.google.com", "192.168.0.1", ""); |
| 545 | |
| 546 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 547 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 548 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 549 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 550 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 551 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 552 | net_log_, |
| 553 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 554 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 555 | EXPECT_TRUE(stream.get()); |
| 556 | |
| 557 | TestCompletionCallback callback; |
| 558 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 559 | EXPECT_EQ(OK, |
| 560 | request2.Request(server2, |
| 561 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 562 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 563 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 564 | net_log_, |
| 565 | callback.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 566 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 567 | EXPECT_TRUE(stream2.get()); |
| 568 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 569 | factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 570 | &factory_, host_port_pair_, is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 571 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 572 | &factory_, host_port_pair_, is_https_)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 573 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
| 574 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 575 | |
| 576 | TestCompletionCallback callback3; |
| 577 | QuicStreamRequest request3(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 578 | EXPECT_EQ(OK, |
| 579 | request3.Request(server2, |
| 580 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 581 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 582 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 583 | net_log_, |
| 584 | callback3.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 585 | scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream(); |
| 586 | EXPECT_TRUE(stream3.get()); |
| 587 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 588 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession( |
| 589 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 590 | |
| 591 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 592 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 593 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 594 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 595 | } |
| 596 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 597 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 598 | MockRead reads[] = { |
| 599 | MockRead(ASYNC, OK, 0) // EOF |
| 600 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 601 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 602 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 603 | socket_data.StopAfter(1); |
| 604 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 605 | HostPortPair server1("www.example.org", 443); |
| 606 | HostPortPair server2("mail.example.org", 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 607 | |
| 608 | // Load a cert that is valid for: |
| 609 | // www.example.org (server1) |
| 610 | // mail.example.org (server2) |
| 611 | // www.example.com |
| 612 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 613 | scoped_refptr<X509Certificate> test_cert( |
| 614 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 615 | ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 616 | ProofVerifyDetailsChromium verify_details; |
| 617 | verify_details.cert_verify_result.verified_cert = test_cert; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 618 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 619 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 620 | |
| 621 | host_resolver_.set_synchronous_mode(true); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 622 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 623 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 624 | |
| 625 | QuicStreamRequest request(&factory_); |
| 626 | is_https_ = true; |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 627 | EXPECT_EQ(OK, |
| 628 | request.Request(server1, |
| 629 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 630 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 631 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 632 | net_log_, |
| 633 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 634 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 635 | EXPECT_TRUE(stream.get()); |
| 636 | |
| 637 | TestCompletionCallback callback; |
| 638 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 639 | EXPECT_EQ(OK, |
| 640 | request2.Request(server2, |
| 641 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 642 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 643 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 644 | net_log_, |
| 645 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 646 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 647 | EXPECT_TRUE(stream2.get()); |
| 648 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 649 | EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
| 650 | &factory_, server1, is_https_), |
| 651 | QuicStreamFactoryPeer::GetActiveSession( |
| 652 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 653 | |
| 654 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 655 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 656 | } |
| 657 | |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 658 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingIfDisabled) { |
| 659 | MockRead reads[] = { |
| 660 | MockRead(ASYNC, OK, 0) // EOF |
| 661 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 662 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 663 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 664 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 665 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 666 | socket_data1.StopAfter(1); |
| 667 | socket_data2.StopAfter(1); |
| 668 | |
| 669 | HostPortPair server1("www.example.org", 443); |
| 670 | HostPortPair server2("mail.example.org", 443); |
| 671 | |
| 672 | // Load a cert that is valid for: |
| 673 | // www.example.org (server1) |
| 674 | // mail.example.org (server2) |
| 675 | // www.example.com |
| 676 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 677 | scoped_refptr<X509Certificate> test_cert( |
| 678 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 679 | ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 680 | ProofVerifyDetailsChromium verify_details; |
| 681 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 682 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 683 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 684 | |
| 685 | host_resolver_.set_synchronous_mode(true); |
| 686 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 687 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 688 | |
| 689 | // Disable connection pooling. |
| 690 | QuicStreamFactoryPeer::DisableConnectionPooling(&factory_); |
| 691 | |
| 692 | QuicStreamRequest request(&factory_); |
| 693 | is_https_ = true; |
| 694 | EXPECT_EQ(OK, |
| 695 | request.Request(server1, |
| 696 | is_https_, |
| 697 | privacy_mode_, |
| 698 | "GET", |
| 699 | net_log_, |
| 700 | callback_.callback())); |
| 701 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 702 | EXPECT_TRUE(stream.get()); |
| 703 | |
| 704 | TestCompletionCallback callback; |
| 705 | QuicStreamRequest request2(&factory_); |
| 706 | EXPECT_EQ(OK, |
| 707 | request2.Request(server2, |
| 708 | is_https_, |
| 709 | privacy_mode_, |
| 710 | "GET", |
| 711 | net_log_, |
| 712 | callback_.callback())); |
| 713 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 714 | EXPECT_TRUE(stream2.get()); |
| 715 | |
| 716 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 717 | &factory_, server1, is_https_), |
| 718 | QuicStreamFactoryPeer::GetActiveSession( |
| 719 | &factory_, server2, is_https_)); |
| 720 | |
| 721 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 722 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 723 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 724 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 725 | } |
| 726 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 727 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) { |
| 728 | MockRead reads[] = { |
| 729 | MockRead(ASYNC, OK, 0) // EOF |
| 730 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 731 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 732 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 733 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 734 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 735 | socket_data1.StopAfter(1); |
| 736 | socket_data2.StopAfter(1); |
| 737 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 738 | HostPortPair server1("www.example.org", 443); |
| 739 | HostPortPair server2("mail.google.com", 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 740 | |
| 741 | // Load a cert that is valid for: |
| 742 | // www.example.org (server1) |
| 743 | // mail.example.org |
| 744 | // www.example.com |
| 745 | // But is not valid for mail.google.com (server2). |
| 746 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 747 | scoped_refptr<X509Certificate> test_cert( |
| 748 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 749 | ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
[email protected] | b694e48c | 2014-03-18 17:10:13 | [diff] [blame] | 750 | ProofVerifyDetailsChromium verify_details; |
| 751 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 752 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 753 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 754 | |
| 755 | host_resolver_.set_synchronous_mode(true); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 756 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 757 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 758 | |
| 759 | QuicStreamRequest request(&factory_); |
| 760 | is_https_ = true; |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 761 | EXPECT_EQ(OK, |
| 762 | request.Request(server1, |
| 763 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 764 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 765 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 766 | net_log_, |
| 767 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 768 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 769 | EXPECT_TRUE(stream.get()); |
| 770 | |
| 771 | TestCompletionCallback callback; |
| 772 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 773 | EXPECT_EQ(OK, |
| 774 | request2.Request(server2, |
| 775 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 776 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 777 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 778 | net_log_, |
| 779 | callback_.callback())); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 780 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 781 | EXPECT_TRUE(stream2.get()); |
| 782 | |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 783 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 784 | &factory_, server1, is_https_), |
| 785 | QuicStreamFactoryPeer::GetActiveSession( |
| 786 | &factory_, server2, is_https_)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 787 | |
| 788 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 789 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 790 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 791 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 792 | } |
| 793 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 794 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
| 795 | MockRead reads[] = { |
| 796 | MockRead(ASYNC, OK, 0) // EOF |
| 797 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 798 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 799 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 800 | socket_data.StopAfter(1); |
| 801 | |
| 802 | HostPortPair server1("www.example.org", 443); |
| 803 | HostPortPair server2("mail.example.org", 443); |
| 804 | uint8 primary_pin = 1; |
| 805 | uint8 backup_pin = 2; |
| 806 | test::AddPin(&transport_security_state_, "mail.example.org", primary_pin, |
| 807 | backup_pin); |
| 808 | |
| 809 | // Load a cert that is valid for: |
| 810 | // www.example.org (server1) |
| 811 | // mail.example.org (server2) |
| 812 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 813 | scoped_refptr<X509Certificate> test_cert( |
| 814 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 815 | ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 816 | ProofVerifyDetailsChromium verify_details; |
| 817 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 818 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 819 | verify_details.cert_verify_result.public_key_hashes.push_back( |
| 820 | test::GetTestHashValue(primary_pin)); |
| 821 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 822 | |
| 823 | |
| 824 | host_resolver_.set_synchronous_mode(true); |
| 825 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 826 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 827 | |
| 828 | QuicStreamRequest request(&factory_); |
| 829 | is_https_ = true; |
| 830 | EXPECT_EQ(OK, |
| 831 | request.Request(server1, |
| 832 | is_https_, |
| 833 | privacy_mode_, |
| 834 | "GET", |
| 835 | net_log_, |
| 836 | callback_.callback())); |
| 837 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 838 | EXPECT_TRUE(stream.get()); |
| 839 | |
| 840 | TestCompletionCallback callback; |
| 841 | QuicStreamRequest request2(&factory_); |
| 842 | EXPECT_EQ(OK, |
| 843 | request2.Request(server2, |
| 844 | is_https_, |
| 845 | privacy_mode_, |
| 846 | "GET", |
| 847 | net_log_, |
| 848 | callback_.callback())); |
| 849 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 850 | EXPECT_TRUE(stream2.get()); |
| 851 | |
| 852 | EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession( |
| 853 | &factory_, server1, is_https_), |
| 854 | QuicStreamFactoryPeer::GetActiveSession( |
| 855 | &factory_, server2, is_https_)); |
| 856 | |
| 857 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 858 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 859 | } |
| 860 | |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 861 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithMatchingPinsIfDisabled) { |
| 862 | MockRead reads[] = { |
| 863 | MockRead(ASYNC, OK, 0) // EOF |
| 864 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 865 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 866 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 867 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 868 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 869 | socket_data1.StopAfter(1); |
| 870 | socket_data2.StopAfter(1); |
| 871 | |
| 872 | HostPortPair server1("www.example.org", 443); |
| 873 | HostPortPair server2("mail.example.org", 443); |
| 874 | uint8 primary_pin = 1; |
| 875 | uint8 backup_pin = 2; |
| 876 | test::AddPin(&transport_security_state_, "mail.example.org", primary_pin, |
| 877 | backup_pin); |
| 878 | |
| 879 | // Load a cert that is valid for: |
| 880 | // www.example.org (server1) |
| 881 | // mail.example.org (server2) |
| 882 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 883 | scoped_refptr<X509Certificate> test_cert( |
| 884 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 885 | ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
jri | 584002d1 | 2014-09-09 00:51:28 | [diff] [blame] | 886 | ProofVerifyDetailsChromium verify_details; |
| 887 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 888 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 889 | verify_details.cert_verify_result.public_key_hashes.push_back( |
| 890 | test::GetTestHashValue(primary_pin)); |
| 891 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 892 | |
| 893 | |
| 894 | host_resolver_.set_synchronous_mode(true); |
| 895 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 896 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 897 | |
| 898 | // Disable connection pooling. |
| 899 | QuicStreamFactoryPeer::DisableConnectionPooling(&factory_); |
| 900 | |
| 901 | QuicStreamRequest request(&factory_); |
| 902 | is_https_ = true; |
| 903 | EXPECT_EQ(OK, |
| 904 | request.Request(server1, |
| 905 | is_https_, |
| 906 | privacy_mode_, |
| 907 | "GET", |
| 908 | net_log_, |
| 909 | callback_.callback())); |
| 910 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 911 | EXPECT_TRUE(stream.get()); |
| 912 | |
| 913 | TestCompletionCallback callback; |
| 914 | QuicStreamRequest request2(&factory_); |
| 915 | EXPECT_EQ(OK, |
| 916 | request2.Request(server2, |
| 917 | is_https_, |
| 918 | privacy_mode_, |
| 919 | "GET", |
| 920 | net_log_, |
| 921 | callback_.callback())); |
| 922 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 923 | EXPECT_TRUE(stream2.get()); |
| 924 | |
| 925 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 926 | &factory_, server1, is_https_), |
| 927 | QuicStreamFactoryPeer::GetActiveSession( |
| 928 | &factory_, server2, is_https_)); |
| 929 | |
| 930 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 931 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 932 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 933 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 934 | } |
| 935 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 936 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
| 937 | MockRead reads[] = { |
| 938 | MockRead(ASYNC, OK, 0) // EOF |
| 939 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 940 | DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0); |
| 941 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 942 | socket_factory_.AddSocketDataProvider(&socket_data1); |
| 943 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 944 | socket_data1.StopAfter(1); |
| 945 | socket_data2.StopAfter(1); |
| 946 | |
| 947 | HostPortPair server1("www.example.org", 443); |
| 948 | HostPortPair server2("mail.example.org", 443); |
| 949 | uint8 primary_pin = 1; |
| 950 | uint8 backup_pin = 2; |
| 951 | uint8 bad_pin = 3; |
| 952 | test::AddPin(&transport_security_state_, "mail.example.org", primary_pin, |
| 953 | backup_pin); |
| 954 | |
| 955 | // Load a cert that is valid for: |
| 956 | // www.example.org (server1) |
| 957 | // mail.example.org (server2) |
| 958 | base::FilePath certs_dir = GetTestCertsDirectory(); |
| 959 | scoped_refptr<X509Certificate> test_cert( |
| 960 | ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 961 | ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 962 | ProofVerifyDetailsChromium verify_details; |
| 963 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 964 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 965 | verify_details.cert_verify_result.public_key_hashes.push_back( |
| 966 | test::GetTestHashValue(bad_pin)); |
| 967 | crypto_client_stream_factory_.set_proof_verify_details(&verify_details); |
| 968 | |
| 969 | |
| 970 | host_resolver_.set_synchronous_mode(true); |
| 971 | host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 972 | host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
| 973 | |
| 974 | QuicStreamRequest request(&factory_); |
| 975 | is_https_ = true; |
| 976 | EXPECT_EQ(OK, |
| 977 | request.Request(server1, |
| 978 | is_https_, |
| 979 | privacy_mode_, |
| 980 | "GET", |
| 981 | net_log_, |
| 982 | callback_.callback())); |
| 983 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 984 | EXPECT_TRUE(stream.get()); |
| 985 | |
| 986 | TestCompletionCallback callback; |
| 987 | QuicStreamRequest request2(&factory_); |
| 988 | EXPECT_EQ(OK, |
| 989 | request2.Request(server2, |
| 990 | is_https_, |
| 991 | privacy_mode_, |
| 992 | "GET", |
| 993 | net_log_, |
| 994 | callback_.callback())); |
| 995 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 996 | EXPECT_TRUE(stream2.get()); |
| 997 | |
| 998 | EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession( |
| 999 | &factory_, server1, is_https_), |
| 1000 | QuicStreamFactoryPeer::GetActiveSession( |
| 1001 | &factory_, server2, is_https_)); |
| 1002 | |
| 1003 | EXPECT_TRUE(socket_data1.at_read_eof()); |
| 1004 | EXPECT_TRUE(socket_data1.at_write_eof()); |
| 1005 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1006 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1007 | } |
| 1008 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1009 | TEST_P(QuicStreamFactoryTest, Goaway) { |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1010 | MockRead reads[] = { |
| 1011 | MockRead(ASYNC, OK, 0) // EOF |
| 1012 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1013 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1014 | socket_data.StopAfter(1); |
| 1015 | socket_factory_.AddSocketDataProvider(&socket_data); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1016 | DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1017 | socket_data2.StopAfter(1); |
| 1018 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1019 | |
| 1020 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1021 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1022 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1023 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1024 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1025 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1026 | net_log_, |
| 1027 | callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1028 | |
| 1029 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1030 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1031 | EXPECT_TRUE(stream.get()); |
| 1032 | |
| 1033 | // Mark the session as going away. Ensure that while it is still alive |
| 1034 | // that it is no longer active. |
| 1035 | QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1036 | &factory_, host_port_pair_, is_https_); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1037 | factory_.OnSessionGoingAway(session); |
| 1038 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 1039 | EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1040 | &factory_, host_port_pair_, is_https_)); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1041 | EXPECT_EQ(nullptr, CreateIfSessionExists(host_port_pair_, net_log_).get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1042 | |
| 1043 | // Create a new request for the same destination and verify that a |
| 1044 | // new session is created. |
| 1045 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1046 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1047 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1048 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1049 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1050 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1051 | net_log_, |
| 1052 | callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1053 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1054 | scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 1055 | EXPECT_TRUE(stream2.get()); |
| 1056 | |
| 1057 | EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1058 | host_port_pair_, |
[email protected] | df157d9d | 2014-03-10 07:27:27 | [diff] [blame] | 1059 | is_https_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1060 | EXPECT_NE(session, |
| 1061 | QuicStreamFactoryPeer::GetActiveSession( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1062 | &factory_, host_port_pair_, is_https_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1063 | EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session)); |
| 1064 | |
| 1065 | stream2.reset(); |
| 1066 | stream.reset(); |
| 1067 | |
| 1068 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1069 | EXPECT_TRUE(socket_data.at_write_eof()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1070 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1071 | EXPECT_TRUE(socket_data2.at_write_eof()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1072 | } |
| 1073 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1074 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1075 | MockRead reads[] = { |
| 1076 | MockRead(ASYNC, OK, 0) // EOF |
| 1077 | }; |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 1078 | QuicStreamId stream_id = kClientDataStreamId1; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1079 | scoped_ptr<QuicEncryptedPacket> rst( |
| 1080 | maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED)); |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 1081 | MockWrite writes[] = { |
| 1082 | MockWrite(ASYNC, rst->data(), rst->length(), 1), |
| 1083 | }; |
| 1084 | DeterministicSocketData socket_data(reads, arraysize(reads), |
| 1085 | writes, arraysize(writes)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1086 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1087 | socket_data.StopAfter(1); |
| 1088 | |
| 1089 | HttpRequestInfo request_info; |
| 1090 | std::vector<QuicHttpStream*> streams; |
| 1091 | // The MockCryptoClientStream sets max_open_streams to be |
| 1092 | // 2 * kDefaultMaxStreamsPerConnection. |
| 1093 | for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) { |
| 1094 | QuicStreamRequest request(&factory_); |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1095 | int rv = request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1096 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1097 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1098 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1099 | net_log_, |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1100 | callback_.callback()); |
| 1101 | if (i == 0) { |
| 1102 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1103 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1104 | } else { |
| 1105 | EXPECT_EQ(OK, rv); |
| 1106 | } |
| 1107 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1108 | EXPECT_TRUE(stream); |
| 1109 | EXPECT_EQ(OK, stream->InitializeStream( |
| 1110 | &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback())); |
| 1111 | streams.push_back(stream.release()); |
| 1112 | } |
| 1113 | |
| 1114 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1115 | EXPECT_EQ(OK, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1116 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1117 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1118 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1119 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1120 | net_log_, |
| 1121 | CompletionCallback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1122 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1123 | EXPECT_TRUE(stream); |
| 1124 | EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream( |
| 1125 | &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback())); |
| 1126 | |
| 1127 | // Close the first stream. |
| 1128 | streams.front()->Close(false); |
| 1129 | |
| 1130 | ASSERT_TRUE(callback_.have_result()); |
| 1131 | |
| 1132 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1133 | |
| 1134 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1135 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1136 | STLDeleteElements(&streams); |
| 1137 | } |
| 1138 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1139 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1140 | DeterministicSocketData socket_data(nullptr, 0, nullptr, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1141 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1142 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1143 | host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1144 | |
| 1145 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1146 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1147 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1148 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1149 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1150 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1151 | net_log_, |
| 1152 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1153 | |
| 1154 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 1155 | |
| 1156 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1157 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1158 | } |
| 1159 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1160 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1161 | MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1162 | DeterministicSocketData socket_data(nullptr, 0, nullptr, 0); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1163 | socket_data.set_connect_data(connect); |
| 1164 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1165 | socket_data.StopAfter(1); |
| 1166 | |
| 1167 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1168 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1169 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1170 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1171 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1172 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1173 | net_log_, |
| 1174 | callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1175 | |
| 1176 | EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult()); |
| 1177 | |
| 1178 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1179 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1180 | } |
| 1181 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1182 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1183 | MockRead reads[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 1184 | MockRead(ASYNC, OK, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1185 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1186 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1187 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1188 | { |
| 1189 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1190 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1191 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1192 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1193 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1194 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1195 | net_log_, |
| 1196 | callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1197 | } |
| 1198 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 1199 | socket_data.StopAfter(1); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1200 | base::RunLoop run_loop; |
| 1201 | run_loop.RunUntilIdle(); |
| 1202 | |
| 1203 | scoped_ptr<QuicHttpStream> stream( |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1204 | CreateIfSessionExists(host_port_pair_, net_log_)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1205 | EXPECT_TRUE(stream.get()); |
| 1206 | stream.reset(); |
| 1207 | |
| 1208 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1209 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1210 | } |
| 1211 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1212 | TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1213 | // Sequentially connect to the default host, then another host, and then the |
| 1214 | // default host. Verify that the default host gets a consistent ephemeral |
| 1215 | // port, that is different from the other host's connection. |
| 1216 | |
| 1217 | std::string other_server_name = "other.google.com"; |
| 1218 | EXPECT_NE(kDefaultServerHostName, other_server_name); |
| 1219 | HostPortPair host_port_pair2(other_server_name, kDefaultServerPort); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1220 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1221 | int original_port = GetSourcePortForNewSession(host_port_pair_); |
| 1222 | EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair2)); |
| 1223 | EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1224 | } |
| 1225 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 1226 | TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) { |
| 1227 | // Get a session to the host using the port suggester. |
| 1228 | int original_port = |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1229 | GetSourcePortForNewSessionAndGoAway(host_port_pair_); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 1230 | // Verify that the port is different after the goaway. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1231 | EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 1232 | // Since the previous session did not goaway we should see the original port. |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1233 | EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_)); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 1234 | } |
| 1235 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1236 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1237 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1238 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1239 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1240 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1241 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1242 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1243 | DeterministicSocketData socket_data(reads, arraysize(reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1244 | writes.empty() ? nullptr : &writes[0], |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1245 | writes.size()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1246 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1247 | socket_data.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1248 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1249 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 1250 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1251 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1252 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1253 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1254 | socket_data2.StopAfter(1); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1255 | |
| 1256 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1257 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1258 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1259 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1260 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1261 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1262 | net_log_, |
| 1263 | callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1264 | |
| 1265 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1266 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1267 | HttpRequestInfo request_info; |
| 1268 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1269 | DEFAULT_PRIORITY, |
| 1270 | net_log_, CompletionCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1271 | |
| 1272 | // Close the session and verify that stream saw the error. |
| 1273 | factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED); |
| 1274 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1275 | stream->ReadResponseHeaders(callback_.callback())); |
| 1276 | |
| 1277 | // Now attempting to request a stream to the same origin should create |
| 1278 | // a new session. |
| 1279 | |
| 1280 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1281 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1282 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1283 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1284 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1285 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1286 | net_log_, |
| 1287 | callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1288 | |
| 1289 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1290 | stream = request2.ReleaseStream(); |
| 1291 | stream.reset(); // Will reset stream 3. |
| 1292 | |
| 1293 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1294 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1295 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1296 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1297 | } |
| 1298 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1299 | TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) { |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1300 | MockRead reads[] = { |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1301 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1302 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1303 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1304 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1305 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1306 | DeterministicSocketData socket_data(reads, arraysize(reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1307 | writes.empty() ? nullptr : &writes[0], |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1308 | writes.size()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1309 | socket_factory_.AddSocketDataProvider(&socket_data); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1310 | socket_data.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1311 | |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1312 | MockRead reads2[] = { |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 1313 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 69dfd1b | 2013-06-04 22:20:12 | [diff] [blame] | 1314 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1315 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1316 | socket_factory_.AddSocketDataProvider(&socket_data2); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 1317 | socket_data2.StopAfter(1); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1318 | |
| 1319 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1320 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1321 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1322 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1323 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1324 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1325 | net_log_, |
| 1326 | callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1327 | |
| 1328 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1329 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1330 | HttpRequestInfo request_info; |
| 1331 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1332 | DEFAULT_PRIORITY, |
| 1333 | net_log_, CompletionCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1334 | |
| 1335 | // Change the IP address and verify that stream saw the error. |
| 1336 | factory_.OnIPAddressChanged(); |
| 1337 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 1338 | stream->ReadResponseHeaders(callback_.callback())); |
[email protected] | 11c0587 | 2013-08-20 02:04:12 | [diff] [blame] | 1339 | EXPECT_TRUE(factory_.require_confirmation()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1340 | |
| 1341 | // Now attempting to request a stream to the same origin should create |
| 1342 | // a new session. |
| 1343 | |
| 1344 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1345 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1346 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1347 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1348 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1349 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1350 | net_log_, |
| 1351 | callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 1352 | |
| 1353 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1354 | stream = request2.ReleaseStream(); |
| 1355 | stream.reset(); // Will reset stream 3. |
| 1356 | |
| 1357 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1358 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1359 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1360 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1361 | } |
| 1362 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1363 | TEST_P(QuicStreamFactoryTest, OnCertAdded) { |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1364 | MockRead reads[] = { |
| 1365 | MockRead(ASYNC, 0, 0) // EOF |
| 1366 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1367 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1368 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1369 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1370 | DeterministicSocketData socket_data(reads, arraysize(reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1371 | writes.empty() ? nullptr : &writes[0], |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1372 | writes.size()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1373 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1374 | socket_data.StopAfter(1); |
| 1375 | |
| 1376 | MockRead reads2[] = { |
| 1377 | MockRead(ASYNC, 0, 0) // EOF |
| 1378 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1379 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1380 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1381 | socket_data2.StopAfter(1); |
| 1382 | |
| 1383 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1384 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1385 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1386 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1387 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1388 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1389 | net_log_, |
| 1390 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1391 | |
| 1392 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1393 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1394 | HttpRequestInfo request_info; |
| 1395 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1396 | DEFAULT_PRIORITY, |
| 1397 | net_log_, CompletionCallback())); |
| 1398 | |
| 1399 | // Add a cert and verify that stream saw the event. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1400 | factory_.OnCertAdded(nullptr); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1401 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 1402 | stream->ReadResponseHeaders(callback_.callback())); |
| 1403 | EXPECT_FALSE(factory_.require_confirmation()); |
| 1404 | |
| 1405 | // Now attempting to request a stream to the same origin should create |
| 1406 | // a new session. |
| 1407 | |
| 1408 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1409 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1410 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1411 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1412 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1413 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1414 | net_log_, |
| 1415 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1416 | |
| 1417 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1418 | stream = request2.ReleaseStream(); |
| 1419 | stream.reset(); // Will reset stream 3. |
| 1420 | |
| 1421 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1422 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1423 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1424 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1425 | } |
| 1426 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1427 | TEST_P(QuicStreamFactoryTest, OnCACertChanged) { |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1428 | MockRead reads[] = { |
| 1429 | MockRead(ASYNC, 0, 0) // EOF |
| 1430 | }; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1431 | scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1432 | std::vector<MockWrite> writes; |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 1433 | writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1434 | DeterministicSocketData socket_data(reads, arraysize(reads), |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1435 | writes.empty() ? nullptr : &writes[0], |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1436 | writes.size()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1437 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1438 | socket_data.StopAfter(1); |
| 1439 | |
| 1440 | MockRead reads2[] = { |
| 1441 | MockRead(ASYNC, 0, 0) // EOF |
| 1442 | }; |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1443 | DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1444 | socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1445 | socket_data2.StopAfter(1); |
| 1446 | |
| 1447 | QuicStreamRequest request(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1448 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1449 | request.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1450 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1451 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1452 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1453 | net_log_, |
| 1454 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1455 | |
| 1456 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1457 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1458 | HttpRequestInfo request_info; |
| 1459 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, |
| 1460 | DEFAULT_PRIORITY, |
| 1461 | net_log_, CompletionCallback())); |
| 1462 | |
| 1463 | // Change the CA cert and verify that stream saw the event. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1464 | factory_.OnCACertChanged(nullptr); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1465 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 1466 | stream->ReadResponseHeaders(callback_.callback())); |
| 1467 | EXPECT_FALSE(factory_.require_confirmation()); |
| 1468 | |
| 1469 | // Now attempting to request a stream to the same origin should create |
| 1470 | // a new session. |
| 1471 | |
| 1472 | QuicStreamRequest request2(&factory_); |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1473 | EXPECT_EQ(ERR_IO_PENDING, |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1474 | request2.Request(host_port_pair_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1475 | is_https_, |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 1476 | privacy_mode_, |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1477 | "GET", |
[email protected] | 974849d | 2014-02-06 01:32:59 | [diff] [blame] | 1478 | net_log_, |
| 1479 | callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 1480 | |
| 1481 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1482 | stream = request2.ReleaseStream(); |
| 1483 | stream.reset(); // Will reset stream 3. |
| 1484 | |
| 1485 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1486 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1487 | EXPECT_TRUE(socket_data2.at_read_eof()); |
| 1488 | EXPECT_TRUE(socket_data2.at_write_eof()); |
| 1489 | } |
| 1490 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1491 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1492 | vector<string> cannoncial_suffixes; |
| 1493 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1494 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 1495 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1496 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1497 | string r1_host_name("r1"); |
| 1498 | string r2_host_name("r2"); |
| 1499 | r1_host_name.append(cannoncial_suffixes[i]); |
| 1500 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1501 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1502 | HostPortPair host_port_pair1(r1_host_name, 80); |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 1503 | QuicCryptoClientConfig* crypto_config = |
| 1504 | QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1505 | QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1506 | QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1507 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1508 | EXPECT_FALSE(cached1->proof_valid()); |
| 1509 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1510 | |
| 1511 | // Mutate the cached1 to have different data. |
| 1512 | // TODO(rtenneti): mutate other members of CachedState. |
| 1513 | cached1->set_source_address_token(r1_host_name); |
| 1514 | cached1->SetProofValid(); |
| 1515 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1516 | HostPortPair host_port_pair2(r2_host_name, 80); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1517 | QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1518 | QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1519 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1520 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 1521 | EXPECT_TRUE(cached2->proof_valid()); |
| 1522 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1523 | } |
| 1524 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1525 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1526 | vector<string> cannoncial_suffixes; |
| 1527 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 1528 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1529 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1530 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 1531 | string r3_host_name("r3"); |
| 1532 | string r4_host_name("r4"); |
| 1533 | r3_host_name.append(cannoncial_suffixes[i]); |
| 1534 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 1535 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1536 | HostPortPair host_port_pair1(r3_host_name, 80); |
[email protected] | 59c0bbd | 2014-03-22 04:08:12 | [diff] [blame] | 1537 | QuicCryptoClientConfig* crypto_config = |
| 1538 | QuicStreamFactoryPeer::GetCryptoConfig(&factory_); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1539 | QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1540 | QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1541 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1542 | EXPECT_FALSE(cached1->proof_valid()); |
| 1543 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 1544 | |
| 1545 | // Mutate the cached1 to have different data. |
| 1546 | // TODO(rtenneti): mutate other members of CachedState. |
| 1547 | cached1->set_source_address_token(r3_host_name); |
| 1548 | cached1->SetProofInvalid(); |
| 1549 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 1550 | HostPortPair host_port_pair2(r4_host_name, 80); |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1551 | QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1552 | QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 1553 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 1554 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 1555 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 1556 | EXPECT_FALSE(cached2->proof_valid()); |
| 1557 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 1558 | } |
| 1559 | |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 1560 | TEST_P(QuicStreamFactoryTest, CancelWaitForDataReady) { |
| 1561 | factory_.set_quic_server_info_factory(&quic_server_info_factory_); |
| 1562 | QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get()); |
| 1563 | const size_t kLoadServerInfoTimeoutMs = 50; |
| 1564 | QuicStreamFactoryPeer::SetLoadServerInfoTimeout( |
| 1565 | &factory_, kLoadServerInfoTimeoutMs); |
| 1566 | |
| 1567 | MockRead reads[] = { |
| 1568 | MockRead(ASYNC, OK, 0) // EOF |
| 1569 | }; |
| 1570 | DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0); |
| 1571 | socket_factory_.AddSocketDataProvider(&socket_data); |
| 1572 | socket_data.StopAfter(1); |
| 1573 | |
| 1574 | crypto_client_stream_factory_.set_handshake_mode( |
| 1575 | MockCryptoClientStream::ZERO_RTT); |
| 1576 | host_resolver_.set_synchronous_mode(true); |
| 1577 | host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1578 | "192.168.0.1", ""); |
| 1579 | |
| 1580 | QuicStreamRequest request(&factory_); |
| 1581 | EXPECT_EQ(ERR_IO_PENDING, |
| 1582 | request.Request(host_port_pair_, |
| 1583 | is_https_, |
| 1584 | privacy_mode_, |
| 1585 | "GET", |
| 1586 | net_log_, |
| 1587 | callback_.callback())); |
| 1588 | |
| 1589 | // Verify that the CancelWaitForDataReady task has been posted. |
| 1590 | ASSERT_EQ(1u, runner_->GetPostedTasks().size()); |
| 1591 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(kLoadServerInfoTimeoutMs), |
| 1592 | runner_->GetPostedTasks()[0].delay); |
| 1593 | |
| 1594 | runner_->RunNextTask(); |
| 1595 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 1596 | |
| 1597 | scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1598 | EXPECT_TRUE(stream.get()); |
| 1599 | EXPECT_TRUE(socket_data.at_read_eof()); |
| 1600 | EXPECT_TRUE(socket_data.at_write_eof()); |
| 1601 | } |
| 1602 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1603 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1604 | } // namespace net |