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