blob: 73feff80fd9391055fbbe95e5475e6b0549c8344 [file] [log] [blame]
[email protected]e13201d82012-12-12 05:00:321// 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]e13201d82012-12-12 05:00:327#include "base/run_loop.h"
[email protected]fc9be5802013-06-11 10:56:518#include "base/strings/string_util.h"
[email protected]eed749f92013-12-23 18:57:389#include "net/base/test_data_directory.h"
[email protected]6d1b4ed2013-07-10 03:57:5410#include "net/cert/cert_verifier.h"
[email protected]f2cb3cf2013-03-21 01:40:5311#include "net/dns/mock_host_resolver.h"
[email protected]e13201d82012-12-12 05:00:3212#include "net/http/http_response_headers.h"
13#include "net/http/http_response_info.h"
14#include "net/http/http_util.h"
[email protected]080b77932014-08-04 01:22:4615#include "net/http/transport_security_state.h"
[email protected]c49ff182013-09-28 08:33:2616#include "net/quic/crypto/crypto_handshake.h"
[email protected]b694e48c2014-03-18 17:10:1317#include "net/quic/crypto/proof_verifier_chromium.h"
[email protected]4df69842013-02-27 06:32:1618#include "net/quic/crypto/quic_decrypter.h"
19#include "net/quic/crypto/quic_encrypter.h"
[email protected]e13201d82012-12-12 05:00:3220#include "net/quic/quic_http_stream.h"
[email protected]257f24f2014-04-01 09:15:3721#include "net/quic/quic_server_id.h"
[email protected]e13201d82012-12-12 05:00:3222#include "net/quic/test_tools/mock_clock.h"
[email protected]e8ff26842013-03-22 21:02:0523#include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
[email protected]9558c5d32012-12-22 00:08:1424#include "net/quic/test_tools/mock_random.h"
[email protected]1e960032013-12-20 19:00:2025#include "net/quic/test_tools/quic_test_packet_maker.h"
[email protected]e13201d82012-12-12 05:00:3226#include "net/quic/test_tools/quic_test_utils.h"
27#include "net/socket/socket_test_util.h"
[email protected]5db452202014-08-19 05:22:1528#include "net/spdy/spdy_test_utils.h"
[email protected]6b8a3c742014-07-25 00:25:3529#include "net/ssl/channel_id_service.h"
30#include "net/ssl/default_channel_id_store.h"
[email protected]eed749f92013-12-23 18:57:3831#include "net/test/cert_test_util.h"
[email protected]e13201d82012-12-12 05:00:3232#include "testing/gtest/include/gtest/gtest.h"
33
[email protected]6e12d702013-11-13 00:17:1734using base::StringPiece;
35using std::string;
36using std::vector;
37
[email protected]e13201d82012-12-12 05:00:3238namespace net {
[email protected]e13201d82012-12-12 05:00:3239namespace test {
40
[email protected]3c772402013-12-18 21:38:1141namespace {
42const char kDefaultServerHostName[] = "www.google.com";
43const int kDefaultServerPort = 443;
44} // namespace anonymous
45
[email protected]c49ff182013-09-28 08:33:2646class QuicStreamFactoryPeer {
47 public:
[email protected]59c0bbd2014-03-22 04:08:1248 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) {
49 return &factory->crypto_config_;
[email protected]c49ff182013-09-28 08:33:2650 }
[email protected]4d283b32013-10-17 12:57:2751
52 static bool HasActiveSession(QuicStreamFactory* factory,
[email protected]bf4ea2f2014-03-10 22:57:5353 const HostPortPair& host_port_pair,
[email protected]df157d9d2014-03-10 07:27:2754 bool is_https) {
[email protected]257f24f2014-04-01 09:15:3755 QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED);
56 return factory->HasActiveSession(server_id);
[email protected]4d283b32013-10-17 12:57:2757 }
58
59 static QuicClientSession* GetActiveSession(
60 QuicStreamFactory* factory,
[email protected]bf4ea2f2014-03-10 22:57:5361 const HostPortPair& host_port_pair,
[email protected]df157d9d2014-03-10 07:27:2762 bool is_https) {
[email protected]257f24f2014-04-01 09:15:3763 QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED);
64 DCHECK(factory->HasActiveSession(server_id));
65 return factory->active_sessions_[server_id];
[email protected]df157d9d2014-03-10 07:27:2766 }
67
68 static scoped_ptr<QuicHttpStream> CreateIfSessionExists(
69 QuicStreamFactory* factory,
[email protected]bf4ea2f2014-03-10 22:57:5370 const HostPortPair& host_port_pair,
[email protected]df157d9d2014-03-10 07:27:2771 bool is_https,
72 const BoundNetLog& net_log) {
[email protected]257f24f2014-04-01 09:15:3773 QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED);
74 return factory->CreateIfSessionExists(server_id, net_log);
[email protected]4d283b32013-10-17 12:57:2775 }
76
77 static bool IsLiveSession(QuicStreamFactory* factory,
78 QuicClientSession* session) {
[email protected]4d590c9c2014-05-02 05:14:3379 for (QuicStreamFactory::SessionIdMap::iterator it =
[email protected]4d283b32013-10-17 12:57:2780 factory->all_sessions_.begin();
81 it != factory->all_sessions_.end(); ++it) {
[email protected]4d590c9c2014-05-02 05:14:3382 if (it->first == session)
[email protected]4d283b32013-10-17 12:57:2783 return true;
84 }
85 return false;
86 }
[email protected]c49ff182013-09-28 08:33:2687};
88
[email protected]1e960032013-12-20 19:00:2089class QuicStreamFactoryTest : public ::testing::TestWithParam<QuicVersion> {
[email protected]e13201d82012-12-12 05:00:3290 protected:
91 QuicStreamFactoryTest()
[email protected]457d6952013-12-13 09:24:5892 : random_generator_(0),
[email protected]1e960032013-12-20 19:00:2093 maker_(GetParam(), 0),
[email protected]457d6952013-12-13 09:24:5894 clock_(new MockClock()),
[email protected]59c0bbd2014-03-22 04:08:1295 cert_verifier_(CertVerifier::CreateDefault()),
[email protected]6b8a3c742014-07-25 00:25:3596 channel_id_service_(new ChannelIDService(
97 new DefaultChannelIDStore(NULL),
[email protected]0cceb922014-07-01 02:00:5698 base::MessageLoopProxy::current())),
[email protected]872edd9e2013-01-16 08:51:1599 factory_(&host_resolver_, &socket_factory_,
[email protected]0c4017ca2014-06-06 03:30:45100 base::WeakPtr<HttpServerProperties>(), cert_verifier_.get(),
[email protected]080b77932014-08-04 01:22:46101 channel_id_service_.get(), &transport_security_state_,
[email protected]0c4017ca2014-06-06 03:30:45102 &crypto_client_stream_factory_, &random_generator_, clock_,
103 kDefaultMaxPacketSize, std::string(),
[email protected]648f81142014-08-15 21:38:46104 SupportedVersions(GetParam()), true, true, QuicTagVector()),
[email protected]bf4ea2f2014-03-10 22:57:53105 host_port_pair_(kDefaultServerHostName, kDefaultServerPort),
[email protected]9dd3ff0f2014-03-26 09:51:28106 is_https_(false),
[email protected]314b03992014-04-01 01:28:53107 privacy_mode_(PRIVACY_MODE_DISABLED) {
[email protected]11c05872013-08-20 02:04:12108 factory_.set_require_confirmation(false);
[email protected]e13201d82012-12-12 05:00:32109 }
110
[email protected]df157d9d2014-03-10 07:27:27111 scoped_ptr<QuicHttpStream> CreateIfSessionExists(
[email protected]bf4ea2f2014-03-10 22:57:53112 const HostPortPair& host_port_pair,
[email protected]df157d9d2014-03-10 07:27:27113 const BoundNetLog& net_log) {
114 return QuicStreamFactoryPeer::CreateIfSessionExists(
[email protected]bf4ea2f2014-03-10 22:57:53115 &factory_, host_port_pair, false, net_log_);
[email protected]df157d9d2014-03-10 07:27:27116 }
[email protected]e13201d82012-12-12 05:00:32117
[email protected]bf4ea2f2014-03-10 22:57:53118 int GetSourcePortForNewSession(const HostPortPair& destination) {
[email protected]d8e2abf82014-03-06 10:30:10119 return GetSourcePortForNewSessionInner(destination, false);
120 }
121
122 int GetSourcePortForNewSessionAndGoAway(
[email protected]bf4ea2f2014-03-10 22:57:53123 const HostPortPair& destination) {
[email protected]d8e2abf82014-03-06 10:30:10124 return GetSourcePortForNewSessionInner(destination, true);
125 }
126
[email protected]bf4ea2f2014-03-10 22:57:53127 int GetSourcePortForNewSessionInner(const HostPortPair& destination,
[email protected]d8e2abf82014-03-06 10:30:10128 bool goaway_received) {
[email protected]3c772402013-12-18 21:38:11129 // Should only be called if there is no active session for this destination.
[email protected]df157d9d2014-03-10 07:27:27130 EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get());
[email protected]3c772402013-12-18 21:38:11131 size_t socket_count = socket_factory_.udp_client_sockets().size();
132
133 MockRead reads[] = {
134 MockRead(ASYNC, OK, 0) // EOF
135 };
136 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
137 socket_data.StopAfter(1);
138 socket_factory_.AddSocketDataProvider(&socket_data);
139
140 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59141 EXPECT_EQ(ERR_IO_PENDING,
142 request.Request(destination,
143 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28144 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59145 "GET",
[email protected]974849d2014-02-06 01:32:59146 net_log_,
147 callback_.callback()));
[email protected]3c772402013-12-18 21:38:11148
149 EXPECT_EQ(OK, callback_.WaitForResult());
150 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
151 EXPECT_TRUE(stream.get());
152 stream.reset();
153
154 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
[email protected]df157d9d2014-03-10 07:27:27155 &factory_, destination, is_https_);
[email protected]3c772402013-12-18 21:38:11156
157 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
158 EXPECT_TRUE(false);
159 return 0;
160 }
161
162 IPEndPoint endpoint;
163 socket_factory_.
164 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
165 int port = endpoint.port();
[email protected]d8e2abf82014-03-06 10:30:10166 if (goaway_received) {
167 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, "");
168 session->OnGoAway(goaway);
169 }
[email protected]3c772402013-12-18 21:38:11170
171 factory_.OnSessionClosed(session);
[email protected]df157d9d2014-03-10 07:27:27172 EXPECT_EQ(NULL, CreateIfSessionExists(destination, net_log_).get());
[email protected]3c772402013-12-18 21:38:11173 EXPECT_TRUE(socket_data.at_read_eof());
174 EXPECT_TRUE(socket_data.at_write_eof());
175 return port;
176 }
177
[email protected]459a7402014-02-10 12:58:52178 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
[email protected]66ae5962014-05-22 11:13:05179 QuicStreamId stream_id = kClientDataStreamId1;
[email protected]51cc1342014-04-18 23:44:37180 return maker_.MakeRstPacket(
181 1, true, stream_id,
182 AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING, GetParam()));
[email protected]459a7402014-02-10 12:58:52183 }
184
[email protected]e13201d82012-12-12 05:00:32185 MockHostResolver host_resolver_;
[email protected]0edce6a2013-05-08 18:02:40186 DeterministicMockClientSocketFactory socket_factory_;
[email protected]e8ff26842013-03-22 21:02:05187 MockCryptoClientStreamFactory crypto_client_stream_factory_;
[email protected]9558c5d32012-12-22 00:08:14188 MockRandom random_generator_;
[email protected]1e960032013-12-20 19:00:20189 QuicTestPacketMaker maker_;
[email protected]872edd9e2013-01-16 08:51:15190 MockClock* clock_; // Owned by factory_.
[email protected]59c0bbd2014-03-22 04:08:12191 scoped_ptr<CertVerifier> cert_verifier_;
[email protected]6b8a3c742014-07-25 00:25:35192 scoped_ptr<ChannelIDService> channel_id_service_;
[email protected]080b77932014-08-04 01:22:46193 TransportSecurityState transport_security_state_;
[email protected]e13201d82012-12-12 05:00:32194 QuicStreamFactory factory_;
[email protected]bf4ea2f2014-03-10 22:57:53195 HostPortPair host_port_pair_;
[email protected]6d1b4ed2013-07-10 03:57:54196 bool is_https_;
[email protected]9dd3ff0f2014-03-26 09:51:28197 PrivacyMode privacy_mode_;
[email protected]e13201d82012-12-12 05:00:32198 BoundNetLog net_log_;
199 TestCompletionCallback callback_;
[email protected]e13201d82012-12-12 05:00:32200};
201
[email protected]1e960032013-12-20 19:00:20202INSTANTIATE_TEST_CASE_P(Version, QuicStreamFactoryTest,
203 ::testing::ValuesIn(QuicSupportedVersions()));
204
205TEST_P(QuicStreamFactoryTest, CreateIfSessionExists) {
[email protected]bf4ea2f2014-03-10 22:57:53206 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get());
[email protected]e13201d82012-12-12 05:00:32207}
208
[email protected]1e960032013-12-20 19:00:20209TEST_P(QuicStreamFactoryTest, Create) {
[email protected]69dfd1b2013-06-04 22:20:12210 MockRead reads[] = {
[email protected]25c31dc2013-06-05 17:56:04211 MockRead(ASYNC, OK, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12212 };
[email protected]25c31dc2013-06-05 17:56:04213 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
[email protected]e13201d82012-12-12 05:00:32214 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]25c31dc2013-06-05 17:56:04215 socket_data.StopAfter(1);
[email protected]e13201d82012-12-12 05:00:32216
217 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59218 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53219 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59220 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28221 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59222 "GET",
[email protected]974849d2014-02-06 01:32:59223 net_log_,
224 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32225
226 EXPECT_EQ(OK, callback_.WaitForResult());
227 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0edce6a2013-05-08 18:02:40228 EXPECT_TRUE(stream.get());
[email protected]e13201d82012-12-12 05:00:32229
230 // Will reset stream 3.
[email protected]bf4ea2f2014-03-10 22:57:53231 stream = CreateIfSessionExists(host_port_pair_, net_log_);
[email protected]e13201d82012-12-12 05:00:32232 EXPECT_TRUE(stream.get());
233
[email protected]6d1b4ed2013-07-10 03:57:54234 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
235 // in streams on different sessions.
[email protected]e13201d82012-12-12 05:00:32236 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59237 EXPECT_EQ(OK,
[email protected]bf4ea2f2014-03-10 22:57:53238 request2.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59239 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28240 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59241 "GET",
[email protected]974849d2014-02-06 01:32:59242 net_log_,
243 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32244 stream = request2.ReleaseStream(); // Will reset stream 5.
245 stream.reset(); // Will reset stream 7.
246
247 EXPECT_TRUE(socket_data.at_read_eof());
248 EXPECT_TRUE(socket_data.at_write_eof());
249}
250
[email protected]8bd2b812014-03-26 04:01:17251TEST_P(QuicStreamFactoryTest, CreateZeroRtt) {
252 MockRead reads[] = {
253 MockRead(ASYNC, OK, 0) // EOF
254 };
255 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
256 socket_factory_.AddSocketDataProvider(&socket_data);
257 socket_data.StopAfter(1);
258
259 crypto_client_stream_factory_.set_handshake_mode(
260 MockCryptoClientStream::ZERO_RTT);
261 host_resolver_.set_synchronous_mode(true);
262 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
263 "192.168.0.1", "");
264
265 QuicStreamRequest request(&factory_);
266 EXPECT_EQ(OK,
267 request.Request(host_port_pair_,
268 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28269 privacy_mode_,
[email protected]8bd2b812014-03-26 04:01:17270 "GET",
271 net_log_,
272 callback_.callback()));
273
274 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
275 EXPECT_TRUE(stream.get());
276 EXPECT_TRUE(socket_data.at_read_eof());
277 EXPECT_TRUE(socket_data.at_write_eof());
278}
279
280TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) {
281 MockRead reads[] = {
282 MockRead(ASYNC, OK, 0) // EOF
283 };
284 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
285 socket_factory_.AddSocketDataProvider(&socket_data);
286 socket_data.StopAfter(1);
287
288 crypto_client_stream_factory_.set_handshake_mode(
289 MockCryptoClientStream::ZERO_RTT);
290 host_resolver_.set_synchronous_mode(true);
291 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
292 "192.168.0.1", "");
293
294 QuicStreamRequest request(&factory_);
295 // Posts require handshake confirmation, so this will return asynchronously.
296 EXPECT_EQ(ERR_IO_PENDING,
297 request.Request(host_port_pair_,
298 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28299 privacy_mode_,
[email protected]8bd2b812014-03-26 04:01:17300 "POST",
301 net_log_,
302 callback_.callback()));
303
304 // Confirm the handshake and verify that the stream is created.
305 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
306 QuicSession::HANDSHAKE_CONFIRMED);
307
308 EXPECT_EQ(OK, callback_.WaitForResult());
309 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
310 EXPECT_TRUE(stream.get());
311 EXPECT_TRUE(socket_data.at_read_eof());
312 EXPECT_TRUE(socket_data.at_write_eof());
313}
314
[email protected]df157d9d2014-03-10 07:27:27315TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) {
316 MockRead reads[] = {
317 MockRead(ASYNC, OK, 0) // EOF
318 };
319 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
320 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
321 socket_factory_.AddSocketDataProvider(&socket_data1);
322 socket_factory_.AddSocketDataProvider(&socket_data2);
323 socket_data1.StopAfter(1);
324 socket_data2.StopAfter(1);
325
326 QuicStreamRequest request(&factory_);
327 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53328 request.Request(host_port_pair_,
[email protected]df157d9d2014-03-10 07:27:27329 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28330 privacy_mode_,
[email protected]df157d9d2014-03-10 07:27:27331 "GET",
[email protected]df157d9d2014-03-10 07:27:27332 net_log_,
333 callback_.callback()));
334
335 EXPECT_EQ(OK, callback_.WaitForResult());
336 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
337 EXPECT_TRUE(stream.get());
338
339 QuicStreamRequest request2(&factory_);
340 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53341 request2.Request(host_port_pair_,
[email protected]df157d9d2014-03-10 07:27:27342 !is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28343 privacy_mode_,
[email protected]df157d9d2014-03-10 07:27:27344 "GET",
[email protected]df157d9d2014-03-10 07:27:27345 net_log_,
346 callback_.callback()));
347 EXPECT_EQ(OK, callback_.WaitForResult());
348 stream = request2.ReleaseStream();
349 EXPECT_TRUE(stream.get());
350 stream.reset();
351
352 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53353 &factory_, host_port_pair_, is_https_),
[email protected]df157d9d2014-03-10 07:27:27354 QuicStreamFactoryPeer::GetActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53355 &factory_, host_port_pair_, !is_https_));
[email protected]df157d9d2014-03-10 07:27:27356
357 EXPECT_TRUE(socket_data1.at_read_eof());
358 EXPECT_TRUE(socket_data1.at_write_eof());
359 EXPECT_TRUE(socket_data2.at_read_eof());
360 EXPECT_TRUE(socket_data2.at_write_eof());
361}
362
[email protected]5db452202014-08-19 05:22:15363TEST_P(QuicStreamFactoryTest, Pooling) {
[email protected]eed749f92013-12-23 18:57:38364 MockRead reads[] = {
365 MockRead(ASYNC, OK, 0) // EOF
366 };
367 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
368 socket_factory_.AddSocketDataProvider(&socket_data);
369 socket_data.StopAfter(1);
370
[email protected]bf4ea2f2014-03-10 22:57:53371 HostPortPair server2("mail.google.com", kDefaultServerPort);
[email protected]eed749f92013-12-23 18:57:38372 host_resolver_.set_synchronous_mode(true);
373 host_resolver_.rules()->AddIPLiteralRule(
374 kDefaultServerHostName, "192.168.0.1", "");
375 host_resolver_.rules()->AddIPLiteralRule(
376 "mail.google.com", "192.168.0.1", "");
377
378 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59379 EXPECT_EQ(OK,
[email protected]bf4ea2f2014-03-10 22:57:53380 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59381 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28382 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59383 "GET",
[email protected]974849d2014-02-06 01:32:59384 net_log_,
385 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38386 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
387 EXPECT_TRUE(stream.get());
388
389 TestCompletionCallback callback;
390 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59391 EXPECT_EQ(OK,
392 request2.Request(server2,
393 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28394 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59395 "GET",
[email protected]974849d2014-02-06 01:32:59396 net_log_,
397 callback.callback()));
[email protected]eed749f92013-12-23 18:57:38398 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
399 EXPECT_TRUE(stream2.get());
400
401 EXPECT_EQ(
[email protected]df157d9d2014-03-10 07:27:27402 QuicStreamFactoryPeer::GetActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53403 &factory_, host_port_pair_, is_https_),
[email protected]df157d9d2014-03-10 07:27:27404 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_));
[email protected]eed749f92013-12-23 18:57:38405
406 EXPECT_TRUE(socket_data.at_read_eof());
407 EXPECT_TRUE(socket_data.at_write_eof());
408}
409
410TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) {
411 MockRead reads[] = {
412 MockRead(ASYNC, OK, 0) // EOF
413 };
414 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
415 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
416 socket_factory_.AddSocketDataProvider(&socket_data1);
417 socket_factory_.AddSocketDataProvider(&socket_data2);
418 socket_data1.StopAfter(1);
419 socket_data2.StopAfter(1);
420
[email protected]bf4ea2f2014-03-10 22:57:53421 HostPortPair server2("mail.google.com", kDefaultServerPort);
[email protected]eed749f92013-12-23 18:57:38422 host_resolver_.set_synchronous_mode(true);
423 host_resolver_.rules()->AddIPLiteralRule(
424 kDefaultServerHostName, "192.168.0.1", "");
425 host_resolver_.rules()->AddIPLiteralRule(
426 "mail.google.com", "192.168.0.1", "");
427
428 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59429 EXPECT_EQ(OK,
[email protected]bf4ea2f2014-03-10 22:57:53430 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59431 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28432 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59433 "GET",
[email protected]974849d2014-02-06 01:32:59434 net_log_,
435 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38436 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
437 EXPECT_TRUE(stream.get());
438
439 TestCompletionCallback callback;
440 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59441 EXPECT_EQ(OK,
442 request2.Request(server2,
443 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28444 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59445 "GET",
[email protected]974849d2014-02-06 01:32:59446 net_log_,
447 callback.callback()));
[email protected]eed749f92013-12-23 18:57:38448 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
449 EXPECT_TRUE(stream2.get());
450
[email protected]df157d9d2014-03-10 07:27:27451 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53452 &factory_, host_port_pair_, is_https_));
[email protected]df157d9d2014-03-10 07:27:27453 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53454 &factory_, host_port_pair_, is_https_));
[email protected]df157d9d2014-03-10 07:27:27455 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
456 &factory_, server2, is_https_));
[email protected]eed749f92013-12-23 18:57:38457
458 TestCompletionCallback callback3;
459 QuicStreamRequest request3(&factory_);
[email protected]974849d2014-02-06 01:32:59460 EXPECT_EQ(OK,
461 request3.Request(server2,
462 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28463 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59464 "GET",
[email protected]974849d2014-02-06 01:32:59465 net_log_,
466 callback3.callback()));
[email protected]eed749f92013-12-23 18:57:38467 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
468 EXPECT_TRUE(stream3.get());
469
[email protected]df157d9d2014-03-10 07:27:27470 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
471 &factory_, server2, is_https_));
[email protected]eed749f92013-12-23 18:57:38472
473 EXPECT_TRUE(socket_data1.at_read_eof());
474 EXPECT_TRUE(socket_data1.at_write_eof());
475 EXPECT_TRUE(socket_data2.at_read_eof());
476 EXPECT_TRUE(socket_data2.at_write_eof());
477}
478
[email protected]5db452202014-08-19 05:22:15479TEST_P(QuicStreamFactoryTest, HttpsPooling) {
[email protected]eed749f92013-12-23 18:57:38480 MockRead reads[] = {
481 MockRead(ASYNC, OK, 0) // EOF
482 };
483 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
484 socket_factory_.AddSocketDataProvider(&socket_data);
485 socket_data.StopAfter(1);
486
[email protected]bf4ea2f2014-03-10 22:57:53487 HostPortPair server1("www.example.org", 443);
488 HostPortPair server2("mail.example.org", 443);
[email protected]eed749f92013-12-23 18:57:38489
490 // Load a cert that is valid for:
491 // www.example.org (server1)
492 // mail.example.org (server2)
493 // www.example.com
494 base::FilePath certs_dir = GetTestCertsDirectory();
495 scoped_refptr<X509Certificate> test_cert(
496 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
497 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
[email protected]b694e48c2014-03-18 17:10:13498 ProofVerifyDetailsChromium verify_details;
499 verify_details.cert_verify_result.verified_cert = test_cert;
[email protected]5db452202014-08-19 05:22:15500 verify_details.cert_verify_result.is_issued_by_known_root = true;
[email protected]b694e48c2014-03-18 17:10:13501 crypto_client_stream_factory_.set_proof_verify_details(&verify_details);
[email protected]eed749f92013-12-23 18:57:38502
503 host_resolver_.set_synchronous_mode(true);
[email protected]bf4ea2f2014-03-10 22:57:53504 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
505 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
[email protected]eed749f92013-12-23 18:57:38506
507 QuicStreamRequest request(&factory_);
508 is_https_ = true;
[email protected]974849d2014-02-06 01:32:59509 EXPECT_EQ(OK,
510 request.Request(server1,
511 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28512 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59513 "GET",
[email protected]974849d2014-02-06 01:32:59514 net_log_,
515 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38516 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
517 EXPECT_TRUE(stream.get());
518
519 TestCompletionCallback callback;
520 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59521 EXPECT_EQ(OK,
522 request2.Request(server2,
523 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28524 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59525 "GET",
[email protected]974849d2014-02-06 01:32:59526 net_log_,
527 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38528 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
529 EXPECT_TRUE(stream2.get());
530
[email protected]df157d9d2014-03-10 07:27:27531 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
532 &factory_, server1, is_https_),
533 QuicStreamFactoryPeer::GetActiveSession(
534 &factory_, server2, is_https_));
[email protected]eed749f92013-12-23 18:57:38535
536 EXPECT_TRUE(socket_data.at_read_eof());
537 EXPECT_TRUE(socket_data.at_write_eof());
538}
539
540TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithCertMismatch) {
541 MockRead reads[] = {
542 MockRead(ASYNC, OK, 0) // EOF
543 };
544 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
545 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
546 socket_factory_.AddSocketDataProvider(&socket_data1);
547 socket_factory_.AddSocketDataProvider(&socket_data2);
548 socket_data1.StopAfter(1);
549 socket_data2.StopAfter(1);
550
[email protected]bf4ea2f2014-03-10 22:57:53551 HostPortPair server1("www.example.org", 443);
552 HostPortPair server2("mail.google.com", 443);
[email protected]eed749f92013-12-23 18:57:38553
554 // Load a cert that is valid for:
555 // www.example.org (server1)
556 // mail.example.org
557 // www.example.com
558 // But is not valid for mail.google.com (server2).
559 base::FilePath certs_dir = GetTestCertsDirectory();
560 scoped_refptr<X509Certificate> test_cert(
561 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
562 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
[email protected]b694e48c2014-03-18 17:10:13563 ProofVerifyDetailsChromium verify_details;
564 verify_details.cert_verify_result.verified_cert = test_cert;
565 crypto_client_stream_factory_.set_proof_verify_details(&verify_details);
566
[email protected]eed749f92013-12-23 18:57:38567
568 host_resolver_.set_synchronous_mode(true);
[email protected]bf4ea2f2014-03-10 22:57:53569 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
570 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
[email protected]eed749f92013-12-23 18:57:38571
572 QuicStreamRequest request(&factory_);
573 is_https_ = true;
[email protected]974849d2014-02-06 01:32:59574 EXPECT_EQ(OK,
575 request.Request(server1,
576 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28577 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59578 "GET",
[email protected]974849d2014-02-06 01:32:59579 net_log_,
580 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38581 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
582 EXPECT_TRUE(stream.get());
583
584 TestCompletionCallback callback;
585 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59586 EXPECT_EQ(OK,
587 request2.Request(server2,
588 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28589 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59590 "GET",
[email protected]974849d2014-02-06 01:32:59591 net_log_,
592 callback_.callback()));
[email protected]eed749f92013-12-23 18:57:38593 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
594 EXPECT_TRUE(stream2.get());
595
[email protected]df157d9d2014-03-10 07:27:27596 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
597 &factory_, server1, is_https_),
598 QuicStreamFactoryPeer::GetActiveSession(
599 &factory_, server2, is_https_));
[email protected]eed749f92013-12-23 18:57:38600
601 EXPECT_TRUE(socket_data1.at_read_eof());
602 EXPECT_TRUE(socket_data1.at_write_eof());
603 EXPECT_TRUE(socket_data2.at_read_eof());
604 EXPECT_TRUE(socket_data2.at_write_eof());
605}
606
[email protected]5db452202014-08-19 05:22:15607TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) {
608 MockRead reads[] = {
609 MockRead(ASYNC, OK, 0) // EOF
610 };
611 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
612 socket_factory_.AddSocketDataProvider(&socket_data);
613 socket_data.StopAfter(1);
614
615 HostPortPair server1("www.example.org", 443);
616 HostPortPair server2("mail.example.org", 443);
617 uint8 primary_pin = 1;
618 uint8 backup_pin = 2;
619 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
620 backup_pin);
621
622 // Load a cert that is valid for:
623 // www.example.org (server1)
624 // mail.example.org (server2)
625 base::FilePath certs_dir = GetTestCertsDirectory();
626 scoped_refptr<X509Certificate> test_cert(
627 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
628 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
629 ProofVerifyDetailsChromium verify_details;
630 verify_details.cert_verify_result.verified_cert = test_cert;
631 verify_details.cert_verify_result.is_issued_by_known_root = true;
632 verify_details.cert_verify_result.public_key_hashes.push_back(
633 test::GetTestHashValue(primary_pin));
634 crypto_client_stream_factory_.set_proof_verify_details(&verify_details);
635
636
637 host_resolver_.set_synchronous_mode(true);
638 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
639 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
640
641 QuicStreamRequest request(&factory_);
642 is_https_ = true;
643 EXPECT_EQ(OK,
644 request.Request(server1,
645 is_https_,
646 privacy_mode_,
647 "GET",
648 net_log_,
649 callback_.callback()));
650 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
651 EXPECT_TRUE(stream.get());
652
653 TestCompletionCallback callback;
654 QuicStreamRequest request2(&factory_);
655 EXPECT_EQ(OK,
656 request2.Request(server2,
657 is_https_,
658 privacy_mode_,
659 "GET",
660 net_log_,
661 callback_.callback()));
662 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
663 EXPECT_TRUE(stream2.get());
664
665 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
666 &factory_, server1, is_https_),
667 QuicStreamFactoryPeer::GetActiveSession(
668 &factory_, server2, is_https_));
669
670 EXPECT_TRUE(socket_data.at_read_eof());
671 EXPECT_TRUE(socket_data.at_write_eof());
672}
673
674TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) {
675 MockRead reads[] = {
676 MockRead(ASYNC, OK, 0) // EOF
677 };
678 DeterministicSocketData socket_data1(reads, arraysize(reads), NULL, 0);
679 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
680 socket_factory_.AddSocketDataProvider(&socket_data1);
681 socket_factory_.AddSocketDataProvider(&socket_data2);
682 socket_data1.StopAfter(1);
683 socket_data2.StopAfter(1);
684
685 HostPortPair server1("www.example.org", 443);
686 HostPortPair server2("mail.example.org", 443);
687 uint8 primary_pin = 1;
688 uint8 backup_pin = 2;
689 uint8 bad_pin = 3;
690 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
691 backup_pin);
692
693 // Load a cert that is valid for:
694 // www.example.org (server1)
695 // mail.example.org (server2)
696 base::FilePath certs_dir = GetTestCertsDirectory();
697 scoped_refptr<X509Certificate> test_cert(
698 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
699 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
700 ProofVerifyDetailsChromium verify_details;
701 verify_details.cert_verify_result.verified_cert = test_cert;
702 verify_details.cert_verify_result.is_issued_by_known_root = true;
703 verify_details.cert_verify_result.public_key_hashes.push_back(
704 test::GetTestHashValue(bad_pin));
705 crypto_client_stream_factory_.set_proof_verify_details(&verify_details);
706
707
708 host_resolver_.set_synchronous_mode(true);
709 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
710 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
711
712 QuicStreamRequest request(&factory_);
713 is_https_ = true;
714 EXPECT_EQ(OK,
715 request.Request(server1,
716 is_https_,
717 privacy_mode_,
718 "GET",
719 net_log_,
720 callback_.callback()));
721 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
722 EXPECT_TRUE(stream.get());
723
724 TestCompletionCallback callback;
725 QuicStreamRequest request2(&factory_);
726 EXPECT_EQ(OK,
727 request2.Request(server2,
728 is_https_,
729 privacy_mode_,
730 "GET",
731 net_log_,
732 callback_.callback()));
733 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
734 EXPECT_TRUE(stream2.get());
735
736 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
737 &factory_, server1, is_https_),
738 QuicStreamFactoryPeer::GetActiveSession(
739 &factory_, server2, is_https_));
740
741 EXPECT_TRUE(socket_data1.at_read_eof());
742 EXPECT_TRUE(socket_data1.at_write_eof());
743 EXPECT_TRUE(socket_data2.at_read_eof());
744 EXPECT_TRUE(socket_data2.at_write_eof());
745}
746
[email protected]1e960032013-12-20 19:00:20747TEST_P(QuicStreamFactoryTest, Goaway) {
[email protected]4d283b32013-10-17 12:57:27748 MockRead reads[] = {
749 MockRead(ASYNC, OK, 0) // EOF
750 };
751 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
752 socket_data.StopAfter(1);
753 socket_factory_.AddSocketDataProvider(&socket_data);
754 DeterministicSocketData socket_data2(reads, arraysize(reads), NULL, 0);
755 socket_data2.StopAfter(1);
756 socket_factory_.AddSocketDataProvider(&socket_data2);
757
758 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59759 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53760 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59761 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28762 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59763 "GET",
[email protected]974849d2014-02-06 01:32:59764 net_log_,
765 callback_.callback()));
[email protected]4d283b32013-10-17 12:57:27766
767 EXPECT_EQ(OK, callback_.WaitForResult());
768 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
769 EXPECT_TRUE(stream.get());
770
771 // Mark the session as going away. Ensure that while it is still alive
772 // that it is no longer active.
773 QuicClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53774 &factory_, host_port_pair_, is_https_);
[email protected]4d283b32013-10-17 12:57:27775 factory_.OnSessionGoingAway(session);
776 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
[email protected]df157d9d2014-03-10 07:27:27777 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53778 &factory_, host_port_pair_, is_https_));
779 EXPECT_EQ(NULL, CreateIfSessionExists(host_port_pair_, net_log_).get());
[email protected]4d283b32013-10-17 12:57:27780
781 // Create a new request for the same destination and verify that a
782 // new session is created.
783 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:59784 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53785 request2.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59786 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28787 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59788 "GET",
[email protected]974849d2014-02-06 01:32:59789 net_log_,
790 callback_.callback()));
[email protected]4d283b32013-10-17 12:57:27791 EXPECT_EQ(OK, callback_.WaitForResult());
792 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
793 EXPECT_TRUE(stream2.get());
794
795 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
[email protected]bf4ea2f2014-03-10 22:57:53796 host_port_pair_,
[email protected]df157d9d2014-03-10 07:27:27797 is_https_));
[email protected]4d283b32013-10-17 12:57:27798 EXPECT_NE(session,
799 QuicStreamFactoryPeer::GetActiveSession(
[email protected]bf4ea2f2014-03-10 22:57:53800 &factory_, host_port_pair_, is_https_));
[email protected]4d283b32013-10-17 12:57:27801 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
802
803 stream2.reset();
804 stream.reset();
805
806 EXPECT_TRUE(socket_data.at_read_eof());
807 EXPECT_TRUE(socket_data.at_write_eof());
[email protected]3c772402013-12-18 21:38:11808 EXPECT_TRUE(socket_data2.at_read_eof());
809 EXPECT_TRUE(socket_data2.at_write_eof());
[email protected]4d283b32013-10-17 12:57:27810}
811
[email protected]1e960032013-12-20 19:00:20812TEST_P(QuicStreamFactoryTest, MaxOpenStream) {
[email protected]0b2294d32013-08-02 00:46:36813 MockRead reads[] = {
814 MockRead(ASYNC, OK, 0) // EOF
815 };
[email protected]66ae5962014-05-22 11:13:05816 QuicStreamId stream_id = kClientDataStreamId1;
[email protected]1e960032013-12-20 19:00:20817 scoped_ptr<QuicEncryptedPacket> rst(
818 maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED));
[email protected]06ff5152013-08-29 01:03:05819 MockWrite writes[] = {
820 MockWrite(ASYNC, rst->data(), rst->length(), 1),
821 };
822 DeterministicSocketData socket_data(reads, arraysize(reads),
823 writes, arraysize(writes));
[email protected]0b2294d32013-08-02 00:46:36824 socket_factory_.AddSocketDataProvider(&socket_data);
825 socket_data.StopAfter(1);
826
827 HttpRequestInfo request_info;
828 std::vector<QuicHttpStream*> streams;
829 // The MockCryptoClientStream sets max_open_streams to be
830 // 2 * kDefaultMaxStreamsPerConnection.
831 for (size_t i = 0; i < 2 * kDefaultMaxStreamsPerConnection; i++) {
832 QuicStreamRequest request(&factory_);
[email protected]bf4ea2f2014-03-10 22:57:53833 int rv = request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59834 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28835 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59836 "GET",
[email protected]974849d2014-02-06 01:32:59837 net_log_,
[email protected]0b2294d32013-08-02 00:46:36838 callback_.callback());
839 if (i == 0) {
840 EXPECT_EQ(ERR_IO_PENDING, rv);
841 EXPECT_EQ(OK, callback_.WaitForResult());
842 } else {
843 EXPECT_EQ(OK, rv);
844 }
845 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
846 EXPECT_TRUE(stream);
847 EXPECT_EQ(OK, stream->InitializeStream(
848 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback()));
849 streams.push_back(stream.release());
850 }
851
852 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59853 EXPECT_EQ(OK,
[email protected]bf4ea2f2014-03-10 22:57:53854 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59855 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28856 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59857 "GET",
[email protected]974849d2014-02-06 01:32:59858 net_log_,
859 CompletionCallback()));
[email protected]0b2294d32013-08-02 00:46:36860 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
861 EXPECT_TRUE(stream);
862 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream(
863 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback()));
864
865 // Close the first stream.
866 streams.front()->Close(false);
867
868 ASSERT_TRUE(callback_.have_result());
869
870 EXPECT_EQ(OK, callback_.WaitForResult());
871
872 EXPECT_TRUE(socket_data.at_read_eof());
873 EXPECT_TRUE(socket_data.at_write_eof());
874 STLDeleteElements(&streams);
875}
876
[email protected]1e960032013-12-20 19:00:20877TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) {
[email protected]0edce6a2013-05-08 18:02:40878 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
[email protected]e13201d82012-12-12 05:00:32879 socket_factory_.AddSocketDataProvider(&socket_data);
880
[email protected]3c772402013-12-18 21:38:11881 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName);
[email protected]e13201d82012-12-12 05:00:32882
883 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59884 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53885 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59886 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28887 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59888 "GET",
[email protected]974849d2014-02-06 01:32:59889 net_log_,
890 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32891
892 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult());
893
894 EXPECT_TRUE(socket_data.at_read_eof());
895 EXPECT_TRUE(socket_data.at_write_eof());
896}
897
[email protected]1e960032013-12-20 19:00:20898TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) {
[email protected]3c772402013-12-18 21:38:11899 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE);
900 DeterministicSocketData socket_data(NULL, 0, NULL, 0);
901 socket_data.set_connect_data(connect);
902 socket_factory_.AddSocketDataProvider(&socket_data);
903 socket_data.StopAfter(1);
904
905 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59906 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53907 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59908 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28909 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59910 "GET",
[email protected]974849d2014-02-06 01:32:59911 net_log_,
912 callback_.callback()));
[email protected]3c772402013-12-18 21:38:11913
914 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult());
915
916 EXPECT_TRUE(socket_data.at_read_eof());
917 EXPECT_TRUE(socket_data.at_write_eof());
918}
919
[email protected]1e960032013-12-20 19:00:20920TEST_P(QuicStreamFactoryTest, CancelCreate) {
[email protected]69dfd1b2013-06-04 22:20:12921 MockRead reads[] = {
[email protected]25c31dc2013-06-05 17:56:04922 MockRead(ASYNC, OK, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12923 };
[email protected]25c31dc2013-06-05 17:56:04924 DeterministicSocketData socket_data(reads, arraysize(reads), NULL, 0);
[email protected]e13201d82012-12-12 05:00:32925 socket_factory_.AddSocketDataProvider(&socket_data);
926 {
927 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59928 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53929 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59930 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28931 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59932 "GET",
[email protected]974849d2014-02-06 01:32:59933 net_log_,
934 callback_.callback()));
[email protected]e13201d82012-12-12 05:00:32935 }
936
[email protected]25c31dc2013-06-05 17:56:04937 socket_data.StopAfter(1);
[email protected]e13201d82012-12-12 05:00:32938 base::RunLoop run_loop;
939 run_loop.RunUntilIdle();
940
941 scoped_ptr<QuicHttpStream> stream(
[email protected]bf4ea2f2014-03-10 22:57:53942 CreateIfSessionExists(host_port_pair_, net_log_));
[email protected]e13201d82012-12-12 05:00:32943 EXPECT_TRUE(stream.get());
944 stream.reset();
945
946 EXPECT_TRUE(socket_data.at_read_eof());
947 EXPECT_TRUE(socket_data.at_write_eof());
948}
949
[email protected]1e960032013-12-20 19:00:20950TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) {
[email protected]3c772402013-12-18 21:38:11951 // Sequentially connect to the default host, then another host, and then the
952 // default host. Verify that the default host gets a consistent ephemeral
953 // port, that is different from the other host's connection.
954
955 std::string other_server_name = "other.google.com";
956 EXPECT_NE(kDefaultServerHostName, other_server_name);
957 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort);
[email protected]3c772402013-12-18 21:38:11958
[email protected]bf4ea2f2014-03-10 22:57:53959 int original_port = GetSourcePortForNewSession(host_port_pair_);
960 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair2));
961 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_));
[email protected]3c772402013-12-18 21:38:11962}
963
[email protected]d8e2abf82014-03-06 10:30:10964TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) {
965 // Get a session to the host using the port suggester.
966 int original_port =
[email protected]bf4ea2f2014-03-10 22:57:53967 GetSourcePortForNewSessionAndGoAway(host_port_pair_);
[email protected]d8e2abf82014-03-06 10:30:10968 // Verify that the port is different after the goaway.
[email protected]bf4ea2f2014-03-10 22:57:53969 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair_));
[email protected]d8e2abf82014-03-06 10:30:10970 // Since the previous session did not goaway we should see the original port.
[email protected]bf4ea2f2014-03-10 22:57:53971 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_));
[email protected]d8e2abf82014-03-06 10:30:10972}
973
[email protected]1e960032013-12-20 19:00:20974TEST_P(QuicStreamFactoryTest, CloseAllSessions) {
[email protected]56dfb902013-01-03 23:17:55975 MockRead reads[] = {
[email protected]0edce6a2013-05-08 18:02:40976 MockRead(ASYNC, 0, 0) // EOF
[email protected]56dfb902013-01-03 23:17:55977 };
[email protected]459a7402014-02-10 12:58:52978 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
979 std::vector<MockWrite> writes;
[email protected]08da9adb2014-04-24 08:33:31980 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
[email protected]459a7402014-02-10 12:58:52981 DeterministicSocketData socket_data(reads, arraysize(reads),
982 writes.empty() ? NULL : &writes[0],
983 writes.size());
[email protected]56dfb902013-01-03 23:17:55984 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]0edce6a2013-05-08 18:02:40985 socket_data.StopAfter(1);
[email protected]56dfb902013-01-03 23:17:55986
[email protected]69dfd1b2013-06-04 22:20:12987 MockRead reads2[] = {
[email protected]25c31dc2013-06-05 17:56:04988 MockRead(ASYNC, 0, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:12989 };
[email protected]25c31dc2013-06-05 17:56:04990 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
[email protected]56dfb902013-01-03 23:17:55991 socket_factory_.AddSocketDataProvider(&socket_data2);
[email protected]0edce6a2013-05-08 18:02:40992 socket_data2.StopAfter(1);
[email protected]56dfb902013-01-03 23:17:55993
994 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:59995 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:53996 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:59997 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:28998 privacy_mode_,
[email protected]974849d2014-02-06 01:32:59999 "GET",
[email protected]974849d2014-02-06 01:32:591000 net_log_,
1001 callback_.callback()));
[email protected]56dfb902013-01-03 23:17:551002
1003 EXPECT_EQ(OK, callback_.WaitForResult());
1004 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:361005 HttpRequestInfo request_info;
1006 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1007 DEFAULT_PRIORITY,
1008 net_log_, CompletionCallback()));
[email protected]56dfb902013-01-03 23:17:551009
1010 // Close the session and verify that stream saw the error.
1011 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED);
1012 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
1013 stream->ReadResponseHeaders(callback_.callback()));
1014
1015 // Now attempting to request a stream to the same origin should create
1016 // a new session.
1017
1018 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:591019 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531020 request2.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591021 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281022 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591023 "GET",
[email protected]974849d2014-02-06 01:32:591024 net_log_,
1025 callback_.callback()));
[email protected]56dfb902013-01-03 23:17:551026
1027 EXPECT_EQ(OK, callback_.WaitForResult());
1028 stream = request2.ReleaseStream();
1029 stream.reset(); // Will reset stream 3.
1030
1031 EXPECT_TRUE(socket_data.at_read_eof());
1032 EXPECT_TRUE(socket_data.at_write_eof());
1033 EXPECT_TRUE(socket_data2.at_read_eof());
1034 EXPECT_TRUE(socket_data2.at_write_eof());
1035}
1036
[email protected]1e960032013-12-20 19:00:201037TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) {
[email protected]f698a012013-05-06 20:18:591038 MockRead reads[] = {
[email protected]0edce6a2013-05-08 18:02:401039 MockRead(ASYNC, 0, 0) // EOF
[email protected]f698a012013-05-06 20:18:591040 };
[email protected]459a7402014-02-10 12:58:521041 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1042 std::vector<MockWrite> writes;
[email protected]08da9adb2014-04-24 08:33:311043 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
[email protected]459a7402014-02-10 12:58:521044 DeterministicSocketData socket_data(reads, arraysize(reads),
1045 writes.empty() ? NULL : &writes[0],
1046 writes.size());
[email protected]f698a012013-05-06 20:18:591047 socket_factory_.AddSocketDataProvider(&socket_data);
[email protected]0edce6a2013-05-08 18:02:401048 socket_data.StopAfter(1);
[email protected]f698a012013-05-06 20:18:591049
[email protected]69dfd1b2013-06-04 22:20:121050 MockRead reads2[] = {
[email protected]25c31dc2013-06-05 17:56:041051 MockRead(ASYNC, 0, 0) // EOF
[email protected]69dfd1b2013-06-04 22:20:121052 };
[email protected]25c31dc2013-06-05 17:56:041053 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
[email protected]f698a012013-05-06 20:18:591054 socket_factory_.AddSocketDataProvider(&socket_data2);
[email protected]0edce6a2013-05-08 18:02:401055 socket_data2.StopAfter(1);
[email protected]f698a012013-05-06 20:18:591056
1057 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:591058 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531059 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591060 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281061 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591062 "GET",
[email protected]974849d2014-02-06 01:32:591063 net_log_,
1064 callback_.callback()));
[email protected]f698a012013-05-06 20:18:591065
1066 EXPECT_EQ(OK, callback_.WaitForResult());
1067 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
[email protected]0b2294d32013-08-02 00:46:361068 HttpRequestInfo request_info;
1069 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1070 DEFAULT_PRIORITY,
1071 net_log_, CompletionCallback()));
[email protected]f698a012013-05-06 20:18:591072
1073 // Change the IP address and verify that stream saw the error.
1074 factory_.OnIPAddressChanged();
1075 EXPECT_EQ(ERR_NETWORK_CHANGED,
1076 stream->ReadResponseHeaders(callback_.callback()));
[email protected]11c05872013-08-20 02:04:121077 EXPECT_TRUE(factory_.require_confirmation());
[email protected]f698a012013-05-06 20:18:591078
1079 // Now attempting to request a stream to the same origin should create
1080 // a new session.
1081
1082 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:591083 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531084 request2.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591085 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281086 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591087 "GET",
[email protected]974849d2014-02-06 01:32:591088 net_log_,
1089 callback_.callback()));
[email protected]f698a012013-05-06 20:18:591090
1091 EXPECT_EQ(OK, callback_.WaitForResult());
1092 stream = request2.ReleaseStream();
1093 stream.reset(); // Will reset stream 3.
1094
1095 EXPECT_TRUE(socket_data.at_read_eof());
1096 EXPECT_TRUE(socket_data.at_write_eof());
1097 EXPECT_TRUE(socket_data2.at_read_eof());
1098 EXPECT_TRUE(socket_data2.at_write_eof());
1099}
1100
[email protected]1e960032013-12-20 19:00:201101TEST_P(QuicStreamFactoryTest, OnCertAdded) {
[email protected]d7d1e50b2013-11-25 22:08:091102 MockRead reads[] = {
1103 MockRead(ASYNC, 0, 0) // EOF
1104 };
[email protected]459a7402014-02-10 12:58:521105 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1106 std::vector<MockWrite> writes;
[email protected]08da9adb2014-04-24 08:33:311107 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
[email protected]459a7402014-02-10 12:58:521108 DeterministicSocketData socket_data(reads, arraysize(reads),
1109 writes.empty() ? NULL : &writes[0],
1110 writes.size());
[email protected]d7d1e50b2013-11-25 22:08:091111 socket_factory_.AddSocketDataProvider(&socket_data);
1112 socket_data.StopAfter(1);
1113
1114 MockRead reads2[] = {
1115 MockRead(ASYNC, 0, 0) // EOF
1116 };
1117 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
1118 socket_factory_.AddSocketDataProvider(&socket_data2);
1119 socket_data2.StopAfter(1);
1120
1121 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:591122 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531123 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591124 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281125 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591126 "GET",
[email protected]974849d2014-02-06 01:32:591127 net_log_,
1128 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:091129
1130 EXPECT_EQ(OK, callback_.WaitForResult());
1131 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1132 HttpRequestInfo request_info;
1133 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1134 DEFAULT_PRIORITY,
1135 net_log_, CompletionCallback()));
1136
1137 // Add a cert and verify that stream saw the event.
1138 factory_.OnCertAdded(NULL);
1139 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
1140 stream->ReadResponseHeaders(callback_.callback()));
1141 EXPECT_FALSE(factory_.require_confirmation());
1142
1143 // Now attempting to request a stream to the same origin should create
1144 // a new session.
1145
1146 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:591147 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531148 request2.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591149 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281150 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591151 "GET",
[email protected]974849d2014-02-06 01:32:591152 net_log_,
1153 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:091154
1155 EXPECT_EQ(OK, callback_.WaitForResult());
1156 stream = request2.ReleaseStream();
1157 stream.reset(); // Will reset stream 3.
1158
1159 EXPECT_TRUE(socket_data.at_read_eof());
1160 EXPECT_TRUE(socket_data.at_write_eof());
1161 EXPECT_TRUE(socket_data2.at_read_eof());
1162 EXPECT_TRUE(socket_data2.at_write_eof());
1163}
1164
[email protected]1e960032013-12-20 19:00:201165TEST_P(QuicStreamFactoryTest, OnCACertChanged) {
[email protected]d7d1e50b2013-11-25 22:08:091166 MockRead reads[] = {
1167 MockRead(ASYNC, 0, 0) // EOF
1168 };
[email protected]459a7402014-02-10 12:58:521169 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1170 std::vector<MockWrite> writes;
[email protected]08da9adb2014-04-24 08:33:311171 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
[email protected]459a7402014-02-10 12:58:521172 DeterministicSocketData socket_data(reads, arraysize(reads),
1173 writes.empty() ? NULL : &writes[0],
1174 writes.size());
[email protected]d7d1e50b2013-11-25 22:08:091175 socket_factory_.AddSocketDataProvider(&socket_data);
1176 socket_data.StopAfter(1);
1177
1178 MockRead reads2[] = {
1179 MockRead(ASYNC, 0, 0) // EOF
1180 };
1181 DeterministicSocketData socket_data2(reads2, arraysize(reads2), NULL, 0);
1182 socket_factory_.AddSocketDataProvider(&socket_data2);
1183 socket_data2.StopAfter(1);
1184
1185 QuicStreamRequest request(&factory_);
[email protected]974849d2014-02-06 01:32:591186 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531187 request.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591188 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281189 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591190 "GET",
[email protected]974849d2014-02-06 01:32:591191 net_log_,
1192 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:091193
1194 EXPECT_EQ(OK, callback_.WaitForResult());
1195 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1196 HttpRequestInfo request_info;
1197 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1198 DEFAULT_PRIORITY,
1199 net_log_, CompletionCallback()));
1200
1201 // Change the CA cert and verify that stream saw the event.
1202 factory_.OnCACertChanged(NULL);
1203 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
1204 stream->ReadResponseHeaders(callback_.callback()));
1205 EXPECT_FALSE(factory_.require_confirmation());
1206
1207 // Now attempting to request a stream to the same origin should create
1208 // a new session.
1209
1210 QuicStreamRequest request2(&factory_);
[email protected]974849d2014-02-06 01:32:591211 EXPECT_EQ(ERR_IO_PENDING,
[email protected]bf4ea2f2014-03-10 22:57:531212 request2.Request(host_port_pair_,
[email protected]974849d2014-02-06 01:32:591213 is_https_,
[email protected]9dd3ff0f2014-03-26 09:51:281214 privacy_mode_,
[email protected]974849d2014-02-06 01:32:591215 "GET",
[email protected]974849d2014-02-06 01:32:591216 net_log_,
1217 callback_.callback()));
[email protected]d7d1e50b2013-11-25 22:08:091218
1219 EXPECT_EQ(OK, callback_.WaitForResult());
1220 stream = request2.ReleaseStream();
1221 stream.reset(); // Will reset stream 3.
1222
1223 EXPECT_TRUE(socket_data.at_read_eof());
1224 EXPECT_TRUE(socket_data.at_write_eof());
1225 EXPECT_TRUE(socket_data2.at_read_eof());
1226 EXPECT_TRUE(socket_data2.at_write_eof());
1227}
1228
[email protected]1e960032013-12-20 19:00:201229TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) {
[email protected]6e12d702013-11-13 00:17:171230 vector<string> cannoncial_suffixes;
1231 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1232 cannoncial_suffixes.push_back(string(".googlevideo.com"));
[email protected]c49ff182013-09-28 08:33:261233
[email protected]6e12d702013-11-13 00:17:171234 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1235 string r1_host_name("r1");
1236 string r2_host_name("r2");
1237 r1_host_name.append(cannoncial_suffixes[i]);
1238 r2_host_name.append(cannoncial_suffixes[i]);
[email protected]b70fdb792013-10-25 19:04:141239
[email protected]bf4ea2f2014-03-10 22:57:531240 HostPortPair host_port_pair1(r1_host_name, 80);
[email protected]59c0bbd2014-03-22 04:08:121241 QuicCryptoClientConfig* crypto_config =
1242 QuicStreamFactoryPeer::GetCryptoConfig(&factory_);
[email protected]257f24f2014-04-01 09:15:371243 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_);
[email protected]6e12d702013-11-13 00:17:171244 QuicCryptoClientConfig::CachedState* cached1 =
[email protected]257f24f2014-04-01 09:15:371245 crypto_config->LookupOrCreate(server_id1);
[email protected]6e12d702013-11-13 00:17:171246 EXPECT_FALSE(cached1->proof_valid());
1247 EXPECT_TRUE(cached1->source_address_token().empty());
1248
1249 // Mutate the cached1 to have different data.
1250 // TODO(rtenneti): mutate other members of CachedState.
1251 cached1->set_source_address_token(r1_host_name);
1252 cached1->SetProofValid();
1253
[email protected]bf4ea2f2014-03-10 22:57:531254 HostPortPair host_port_pair2(r2_host_name, 80);
[email protected]257f24f2014-04-01 09:15:371255 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_);
[email protected]6e12d702013-11-13 00:17:171256 QuicCryptoClientConfig::CachedState* cached2 =
[email protected]257f24f2014-04-01 09:15:371257 crypto_config->LookupOrCreate(server_id2);
[email protected]6e12d702013-11-13 00:17:171258 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token());
1259 EXPECT_TRUE(cached2->proof_valid());
1260 }
[email protected]b70fdb792013-10-25 19:04:141261}
1262
[email protected]1e960032013-12-20 19:00:201263TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) {
[email protected]6e12d702013-11-13 00:17:171264 vector<string> cannoncial_suffixes;
1265 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1266 cannoncial_suffixes.push_back(string(".googlevideo.com"));
[email protected]b70fdb792013-10-25 19:04:141267
[email protected]6e12d702013-11-13 00:17:171268 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1269 string r3_host_name("r3");
1270 string r4_host_name("r4");
1271 r3_host_name.append(cannoncial_suffixes[i]);
1272 r4_host_name.append(cannoncial_suffixes[i]);
[email protected]b70fdb792013-10-25 19:04:141273
[email protected]bf4ea2f2014-03-10 22:57:531274 HostPortPair host_port_pair1(r3_host_name, 80);
[email protected]59c0bbd2014-03-22 04:08:121275 QuicCryptoClientConfig* crypto_config =
1276 QuicStreamFactoryPeer::GetCryptoConfig(&factory_);
[email protected]257f24f2014-04-01 09:15:371277 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_);
[email protected]6e12d702013-11-13 00:17:171278 QuicCryptoClientConfig::CachedState* cached1 =
[email protected]257f24f2014-04-01 09:15:371279 crypto_config->LookupOrCreate(server_id1);
[email protected]6e12d702013-11-13 00:17:171280 EXPECT_FALSE(cached1->proof_valid());
1281 EXPECT_TRUE(cached1->source_address_token().empty());
1282
1283 // Mutate the cached1 to have different data.
1284 // TODO(rtenneti): mutate other members of CachedState.
1285 cached1->set_source_address_token(r3_host_name);
1286 cached1->SetProofInvalid();
1287
[email protected]bf4ea2f2014-03-10 22:57:531288 HostPortPair host_port_pair2(r4_host_name, 80);
[email protected]257f24f2014-04-01 09:15:371289 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_);
[email protected]6e12d702013-11-13 00:17:171290 QuicCryptoClientConfig::CachedState* cached2 =
[email protected]257f24f2014-04-01 09:15:371291 crypto_config->LookupOrCreate(server_id2);
[email protected]6e12d702013-11-13 00:17:171292 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1293 EXPECT_TRUE(cached2->source_address_token().empty());
1294 EXPECT_FALSE(cached2->proof_valid());
1295 }
[email protected]c49ff182013-09-28 08:33:261296}
1297
[email protected]e13201d82012-12-12 05:00:321298} // namespace test
[email protected]e13201d82012-12-12 05:00:321299} // namespace net