Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / quic / quic_stream_factory_test.cc
blobb91d4eb36b8f19b0d721d567d1e42206355ddb6e
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.
5 #include "net/quic/quic_stream_factory.h"
7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "net/base/test_data_directory.h"
11 #include "net/cert/cert_verifier.h"
12 #include "net/dns/mock_host_resolver.h"
13 #include "net/http/http_response_headers.h"
14 #include "net/http/http_response_info.h"
15 #include "net/http/http_util.h"
16 #include "net/http/transport_security_state.h"
17 #include "net/quic/crypto/crypto_handshake.h"
18 #include "net/quic/crypto/proof_verifier_chromium.h"
19 #include "net/quic/crypto/quic_decrypter.h"
20 #include "net/quic/crypto/quic_encrypter.h"
21 #include "net/quic/crypto/quic_server_info.h"
22 #include "net/quic/quic_http_stream.h"
23 #include "net/quic/quic_server_id.h"
24 #include "net/quic/test_tools/mock_clock.h"
25 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
26 #include "net/quic/test_tools/mock_random.h"
27 #include "net/quic/test_tools/quic_test_packet_maker.h"
28 #include "net/quic/test_tools/quic_test_utils.h"
29 #include "net/quic/test_tools/test_task_runner.h"
30 #include "net/socket/socket_test_util.h"
31 #include "net/spdy/spdy_test_utils.h"
32 #include "net/ssl/channel_id_service.h"
33 #include "net/ssl/default_channel_id_store.h"
34 #include "net/test/cert_test_util.h"
35 #include "testing/gtest/include/gtest/gtest.h"
37 using base::StringPiece;
38 using std::ostream;
39 using std::string;
40 using std::vector;
42 namespace net {
43 namespace test {
45 namespace {
46 const char kDefaultServerHostName[] = "www.google.com";
47 const int kDefaultServerPort = 443;
49 // Run all tests with all the combinations of versions and
50 // enable_connection_racing.
51 struct TestParams {
52 TestParams(const QuicVersion version, bool enable_connection_racing)
53 : version(version), enable_connection_racing(enable_connection_racing) {}
55 friend ostream& operator<<(ostream& os, const TestParams& p) {
56 os << "{ version: " << QuicVersionToString(p.version);
57 os << " enable_connection_racing: " << p.enable_connection_racing << " }";
58 return os;
61 QuicVersion version;
62 bool enable_connection_racing;
65 // Constructs various test permutations.
66 vector<TestParams> GetTestParams() {
67 vector<TestParams> params;
68 QuicVersionVector all_supported_versions = QuicSupportedVersions();
69 for (const QuicVersion version : all_supported_versions) {
70 params.push_back(TestParams(version, false));
71 params.push_back(TestParams(version, true));
73 return params;
76 } // namespace anonymous
78 class QuicStreamFactoryPeer {
79 public:
80 static QuicCryptoClientConfig* GetCryptoConfig(QuicStreamFactory* factory) {
81 return &factory->crypto_config_;
84 static bool HasActiveSession(QuicStreamFactory* factory,
85 const HostPortPair& host_port_pair,
86 bool is_https) {
87 QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED);
88 return factory->HasActiveSession(server_id);
91 static QuicChromiumClientSession* GetActiveSession(
92 QuicStreamFactory* factory,
93 const HostPortPair& host_port_pair,
94 bool is_https) {
95 QuicServerId server_id(host_port_pair, is_https, PRIVACY_MODE_DISABLED);
96 DCHECK(factory->HasActiveSession(server_id));
97 return factory->active_sessions_[server_id];
100 static scoped_ptr<QuicHttpStream> CreateFromSession(
101 QuicStreamFactory* factory,
102 QuicChromiumClientSession* session) {
103 return factory->CreateFromSession(session);
106 static bool IsLiveSession(QuicStreamFactory* factory,
107 QuicChromiumClientSession* session) {
108 for (QuicStreamFactory::SessionIdMap::iterator it =
109 factory->all_sessions_.begin();
110 it != factory->all_sessions_.end(); ++it) {
111 if (it->first == session)
112 return true;
114 return false;
117 static void DisableConnectionPooling(QuicStreamFactory* factory) {
118 factory->disable_connection_pooling_ = true;
121 static void SetTaskRunner(QuicStreamFactory* factory,
122 base::TaskRunner* task_runner) {
123 factory->task_runner_ = task_runner;
126 static void SetEnableConnectionRacing(QuicStreamFactory* factory,
127 bool enable_connection_racing) {
128 factory->enable_connection_racing_ = enable_connection_racing;
131 static void SetDisableDiskCache(QuicStreamFactory* factory,
132 bool disable_disk_cache) {
133 factory->disable_disk_cache_ = disable_disk_cache;
136 static void SetMaxNumberOfLossyConnections(
137 QuicStreamFactory* factory,
138 int max_number_of_lossy_connections) {
139 factory->max_number_of_lossy_connections_ = max_number_of_lossy_connections;
142 static int GetNumberOfLossyConnections(QuicStreamFactory* factory,
143 uint16 port) {
144 return factory->number_of_lossy_connections_[port];
147 static bool IsQuicDisabled(QuicStreamFactory* factory, uint16 port) {
148 return factory->IsQuicDisabled(port);
151 static size_t GetNumberOfActiveJobs(QuicStreamFactory* factory,
152 const QuicServerId& server_id) {
153 return (factory->active_jobs_[server_id]).size();
156 static void SetThresholdTimeoutsWithOpenStreams(
157 QuicStreamFactory* factory,
158 int threshold_timeouts_with_open_streams) {
159 factory->threshold_timeouts_with_open_streams_ =
160 threshold_timeouts_with_open_streams;
163 static int GetNumTimeoutsWithOpenStreams(QuicStreamFactory* factory) {
164 return factory->num_timeouts_with_open_streams_;
167 static void SetThresholdPublicResetsPostHandshake(
168 QuicStreamFactory* factory,
169 int threshold_public_resets_post_handshake) {
170 factory->threshold_public_resets_post_handshake_ =
171 threshold_public_resets_post_handshake;
174 static int GetNumPublicResetsPostHandshake(QuicStreamFactory* factory) {
175 return factory->num_public_resets_post_handshake_;
179 class MockQuicServerInfo : public QuicServerInfo {
180 public:
181 MockQuicServerInfo(const QuicServerId& server_id)
182 : QuicServerInfo(server_id) {}
183 ~MockQuicServerInfo() override {}
185 void Start() override {}
187 int WaitForDataReady(const CompletionCallback& callback) override {
188 return ERR_IO_PENDING;
191 void ResetWaitForDataReadyCallback() override {}
193 void CancelWaitForDataReadyCallback() override {}
195 bool IsDataReady() override { return false; }
197 bool IsReadyToPersist() override { return false; }
199 void Persist() override {}
201 void OnExternalCacheHit() override {}
204 class MockQuicServerInfoFactory : public QuicServerInfoFactory {
205 public:
206 MockQuicServerInfoFactory() {}
207 ~MockQuicServerInfoFactory() override {}
209 QuicServerInfo* GetForServer(const QuicServerId& server_id) override {
210 return new MockQuicServerInfo(server_id);
214 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> {
215 protected:
216 QuicStreamFactoryTest()
217 : random_generator_(0),
218 clock_(new MockClock()),
219 runner_(new TestTaskRunner(clock_)),
220 maker_(GetParam().version, 0, clock_, kDefaultServerHostName),
221 cert_verifier_(CertVerifier::CreateDefault()),
222 channel_id_service_(
223 new ChannelIDService(new DefaultChannelIDStore(nullptr),
224 base::ThreadTaskRunnerHandle::Get())),
225 factory_(&host_resolver_,
226 &socket_factory_,
227 base::WeakPtr<HttpServerProperties>(),
228 cert_verifier_.get(),
229 channel_id_service_.get(),
230 &transport_security_state_,
231 &crypto_client_stream_factory_,
232 &random_generator_,
233 clock_,
234 kDefaultMaxPacketSize,
235 std::string(),
236 SupportedVersions(GetParam().version),
237 /*enable_port_selection=*/true,
238 /*always_require_handshake_confirmation=*/false,
239 /*disable_connection_pooling=*/false,
240 /*load_server_info_timeout_srtt_multiplier=*/0.0f,
241 /*enable_connection_racing=*/false,
242 /*enable_non_blocking_io=*/true,
243 /*disable_disk_cache=*/false,
244 /*prefer_aes=*/false,
245 /*max_number_of_lossy_connections=*/0,
246 /*packet_loss_threshold=*/1.0f,
247 /*max_disabled_reasons=*/3,
248 /*threshold_timeouts_with_open_streams=*/2,
249 /*threshold_pulic_resets_post_handshake=*/2,
250 /*receive_buffer_size=*/0,
251 QuicTagVector()),
252 host_port_pair_(kDefaultServerHostName, kDefaultServerPort),
253 is_https_(false),
254 privacy_mode_(PRIVACY_MODE_DISABLED) {
255 factory_.set_require_confirmation(false);
256 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
257 QuicStreamFactoryPeer::SetEnableConnectionRacing(
258 &factory_, GetParam().enable_connection_racing);
261 bool HasActiveSession(const HostPortPair& host_port_pair) {
262 return QuicStreamFactoryPeer::HasActiveSession(&factory_, host_port_pair,
263 /*is_https_=*/false);
266 scoped_ptr<QuicHttpStream> CreateFromSession(
267 const HostPortPair& host_port_pair) {
268 QuicChromiumClientSession* session =
269 QuicStreamFactoryPeer::GetActiveSession(&factory_, host_port_pair,
270 /*is_https=*/false);
271 return QuicStreamFactoryPeer::CreateFromSession(&factory_, session);
274 int GetSourcePortForNewSession(const HostPortPair& destination) {
275 return GetSourcePortForNewSessionInner(destination, false);
278 int GetSourcePortForNewSessionAndGoAway(
279 const HostPortPair& destination) {
280 return GetSourcePortForNewSessionInner(destination, true);
283 int GetSourcePortForNewSessionInner(const HostPortPair& destination,
284 bool goaway_received) {
285 // Should only be called if there is no active session for this destination.
286 EXPECT_FALSE(HasActiveSession(destination));
287 size_t socket_count = socket_factory_.udp_client_sockets().size();
289 MockRead reads[] = {
290 MockRead(ASYNC, OK, 0) // EOF
292 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
293 socket_data.StopAfter(1);
294 socket_factory_.AddSocketDataProvider(&socket_data);
296 QuicStreamRequest request(&factory_);
297 EXPECT_EQ(ERR_IO_PENDING,
298 request.Request(destination, is_https_, privacy_mode_,
299 /*cert_verify_flags=*/0, destination.host(),
300 "GET", net_log_, callback_.callback()));
302 EXPECT_EQ(OK, callback_.WaitForResult());
303 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
304 EXPECT_TRUE(stream.get());
305 stream.reset();
307 QuicChromiumClientSession* session =
308 QuicStreamFactoryPeer::GetActiveSession(&factory_, destination,
309 is_https_);
311 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
312 EXPECT_TRUE(false);
313 return 0;
316 IPEndPoint endpoint;
317 socket_factory_.
318 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
319 int port = endpoint.port();
320 if (goaway_received) {
321 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, "");
322 session->OnGoAway(goaway);
325 factory_.OnSessionClosed(session);
326 EXPECT_FALSE(HasActiveSession(destination));
327 EXPECT_TRUE(socket_data.AllReadDataConsumed());
328 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
329 return port;
332 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
333 QuicStreamId stream_id = kClientDataStreamId1;
334 return maker_.MakeRstPacket(
335 1, true, stream_id,
336 AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam().version));
339 static ProofVerifyDetailsChromium DefaultProofVerifyDetails() {
340 // Load a certificate that is valid for www.example.org, mail.example.org,
341 // and mail.example.com.
342 scoped_refptr<X509Certificate> test_cert(
343 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"));
344 EXPECT_TRUE(test_cert.get());
345 ProofVerifyDetailsChromium verify_details;
346 verify_details.cert_verify_result.verified_cert = test_cert;
347 verify_details.cert_verify_result.is_issued_by_known_root = true;
348 return verify_details;
351 MockQuicServerInfoFactory quic_server_info_factory_;
352 MockHostResolver host_resolver_;
353 DeterministicMockClientSocketFactory socket_factory_;
354 MockCryptoClientStreamFactory crypto_client_stream_factory_;
355 MockRandom random_generator_;
356 MockClock* clock_; // Owned by factory_.
357 scoped_refptr<TestTaskRunner> runner_;
358 QuicTestPacketMaker maker_;
359 scoped_ptr<CertVerifier> cert_verifier_;
360 scoped_ptr<ChannelIDService> channel_id_service_;
361 TransportSecurityState transport_security_state_;
362 QuicStreamFactory factory_;
363 HostPortPair host_port_pair_;
364 bool is_https_;
365 PrivacyMode privacy_mode_;
366 BoundNetLog net_log_;
367 TestCompletionCallback callback_;
370 INSTANTIATE_TEST_CASE_P(Version,
371 QuicStreamFactoryTest,
372 ::testing::ValuesIn(GetTestParams()));
374 TEST_P(QuicStreamFactoryTest, Create) {
375 MockRead reads[] = {
376 MockRead(ASYNC, OK, 0) // EOF
378 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
379 socket_factory_.AddSocketDataProvider(&socket_data);
380 socket_data.StopAfter(1);
382 QuicStreamRequest request(&factory_);
383 EXPECT_EQ(ERR_IO_PENDING,
384 request.Request(host_port_pair_, is_https_, privacy_mode_,
385 /*cert_verify_flags=*/0, host_port_pair_.host(),
386 "GET", net_log_, callback_.callback()));
388 EXPECT_EQ(OK, callback_.WaitForResult());
389 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
390 EXPECT_TRUE(stream.get());
392 // Will reset stream 3.
393 stream = CreateFromSession(host_port_pair_);
394 EXPECT_TRUE(stream.get());
396 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
397 // in streams on different sessions.
398 QuicStreamRequest request2(&factory_);
399 EXPECT_EQ(OK,
400 request2.Request(host_port_pair_, is_https_, privacy_mode_,
401 /*cert_verify_flags=*/0, host_port_pair_.host(),
402 "GET", net_log_, callback_.callback()));
403 stream = request2.ReleaseStream(); // Will reset stream 5.
404 stream.reset(); // Will reset stream 7.
406 EXPECT_TRUE(socket_data.AllReadDataConsumed());
407 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
410 TEST_P(QuicStreamFactoryTest, CreateZeroRtt) {
411 MockRead reads[] = {
412 MockRead(ASYNC, OK, 0) // EOF
414 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
415 socket_factory_.AddSocketDataProvider(&socket_data);
416 socket_data.StopAfter(1);
418 crypto_client_stream_factory_.set_handshake_mode(
419 MockCryptoClientStream::ZERO_RTT);
420 host_resolver_.set_synchronous_mode(true);
421 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
422 "192.168.0.1", "");
424 QuicStreamRequest request(&factory_);
425 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
426 /*cert_verify_flags=*/0, host_port_pair_.host(),
427 "GET", net_log_, callback_.callback()));
429 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
430 EXPECT_TRUE(stream.get());
431 EXPECT_TRUE(socket_data.AllReadDataConsumed());
432 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
435 TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) {
436 MockRead reads[] = {
437 MockRead(ASYNC, OK, 0) // EOF
439 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
440 socket_factory_.AddSocketDataProvider(&socket_data);
441 socket_data.StopAfter(1);
443 crypto_client_stream_factory_.set_handshake_mode(
444 MockCryptoClientStream::ZERO_RTT);
445 host_resolver_.set_synchronous_mode(true);
446 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
447 "192.168.0.1", "");
449 QuicStreamRequest request(&factory_);
450 // Posts require handshake confirmation, so this will return asynchronously.
451 EXPECT_EQ(ERR_IO_PENDING,
452 request.Request(host_port_pair_, is_https_, privacy_mode_,
453 /*cert_verify_flags=*/0, host_port_pair_.host(),
454 "POST", net_log_, callback_.callback()));
456 // Confirm the handshake and verify that the stream is created.
457 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
458 QuicSession::HANDSHAKE_CONFIRMED);
460 EXPECT_EQ(OK, callback_.WaitForResult());
461 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
462 EXPECT_TRUE(stream.get());
463 EXPECT_TRUE(socket_data.AllReadDataConsumed());
464 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
467 TEST_P(QuicStreamFactoryTest, NoZeroRttForDifferentHost) {
468 MockRead reads[] = {
469 MockRead(ASYNC, OK, 0),
471 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
472 socket_factory_.AddSocketDataProvider(&socket_data);
473 socket_data.StopAfter(1);
475 crypto_client_stream_factory_.set_handshake_mode(
476 MockCryptoClientStream::ZERO_RTT);
477 host_resolver_.set_synchronous_mode(true);
478 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
479 "192.168.0.1", "");
481 QuicStreamRequest request(&factory_);
482 int rv = request.Request(
483 host_port_pair_, is_https_, privacy_mode_, /*cert_verify_flags=*/0,
484 "different.host.example.com", "GET", net_log_, callback_.callback());
485 // If server and origin have different hostnames, then handshake confirmation
486 // should be required, so Request will return asynchronously.
487 EXPECT_EQ(ERR_IO_PENDING, rv);
488 // Confirm handshake.
489 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
490 QuicSession::HANDSHAKE_CONFIRMED);
491 EXPECT_EQ(OK, callback_.WaitForResult());
493 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
494 EXPECT_TRUE(stream.get());
495 EXPECT_TRUE(socket_data.AllReadDataConsumed());
496 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
499 TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) {
500 MockRead reads[] = {
501 MockRead(ASYNC, OK, 0) // EOF
503 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
504 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
505 socket_factory_.AddSocketDataProvider(&socket_data1);
506 socket_factory_.AddSocketDataProvider(&socket_data2);
507 socket_data1.StopAfter(1);
508 socket_data2.StopAfter(1);
510 QuicStreamRequest request(&factory_);
511 EXPECT_EQ(ERR_IO_PENDING,
512 request.Request(host_port_pair_, is_https_, privacy_mode_,
513 /*cert_verify_flags=*/0, host_port_pair_.host(),
514 "GET", net_log_, callback_.callback()));
516 EXPECT_EQ(OK, callback_.WaitForResult());
517 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
518 EXPECT_TRUE(stream.get());
520 QuicStreamRequest request2(&factory_);
521 EXPECT_EQ(ERR_IO_PENDING,
522 request2.Request(host_port_pair_, !is_https_, privacy_mode_,
523 /*cert_verify_flags=*/0, host_port_pair_.host(),
524 "GET", net_log_, callback_.callback()));
525 EXPECT_EQ(OK, callback_.WaitForResult());
526 stream = request2.ReleaseStream();
527 EXPECT_TRUE(stream.get());
528 stream.reset();
530 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
531 &factory_, host_port_pair_, is_https_),
532 QuicStreamFactoryPeer::GetActiveSession(
533 &factory_, host_port_pair_, !is_https_));
535 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
536 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
537 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
538 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
541 TEST_P(QuicStreamFactoryTest, Pooling) {
542 MockRead reads[] = {
543 MockRead(ASYNC, OK, 0) // EOF
545 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
546 socket_factory_.AddSocketDataProvider(&socket_data);
547 socket_data.StopAfter(1);
549 HostPortPair server2("mail.google.com", kDefaultServerPort);
550 host_resolver_.set_synchronous_mode(true);
551 host_resolver_.rules()->AddIPLiteralRule(
552 kDefaultServerHostName, "192.168.0.1", "");
553 host_resolver_.rules()->AddIPLiteralRule(
554 "mail.google.com", "192.168.0.1", "");
556 QuicStreamRequest request(&factory_);
557 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
558 /*cert_verify_flags=*/0, host_port_pair_.host(),
559 "GET", net_log_, callback_.callback()));
560 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
561 EXPECT_TRUE(stream.get());
563 TestCompletionCallback callback;
564 QuicStreamRequest request2(&factory_);
565 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
566 /*cert_verify_flags=*/0, server2.host(), "GET",
567 net_log_, callback.callback()));
568 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
569 EXPECT_TRUE(stream2.get());
571 EXPECT_EQ(
572 QuicStreamFactoryPeer::GetActiveSession(
573 &factory_, host_port_pair_, is_https_),
574 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_));
576 EXPECT_TRUE(socket_data.AllReadDataConsumed());
577 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
580 TEST_P(QuicStreamFactoryTest, NoPoolingIfDisabled) {
581 MockRead reads[] = {
582 MockRead(ASYNC, OK, 0) // EOF
584 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
585 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
586 socket_factory_.AddSocketDataProvider(&socket_data1);
587 socket_factory_.AddSocketDataProvider(&socket_data2);
588 socket_data1.StopAfter(1);
589 socket_data2.StopAfter(1);
591 HostPortPair server2("mail.google.com", kDefaultServerPort);
592 host_resolver_.set_synchronous_mode(true);
593 host_resolver_.rules()->AddIPLiteralRule(
594 kDefaultServerHostName, "192.168.0.1", "");
595 host_resolver_.rules()->AddIPLiteralRule(
596 "mail.google.com", "192.168.0.1", "");
598 // Disable connection pooling.
599 QuicStreamFactoryPeer::DisableConnectionPooling(&factory_);
601 QuicStreamRequest request(&factory_);
602 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
603 /*cert_verify_flags=*/0, host_port_pair_.host(),
604 "GET", net_log_, callback_.callback()));
605 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
606 EXPECT_TRUE(stream.get());
608 TestCompletionCallback callback;
609 QuicStreamRequest request2(&factory_);
610 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
611 /*cert_verify_flags=*/0, server2.host(), "GET",
612 net_log_, callback.callback()));
613 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
614 EXPECT_TRUE(stream2.get());
616 EXPECT_NE(
617 QuicStreamFactoryPeer::GetActiveSession(
618 &factory_, host_port_pair_, is_https_),
619 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_));
621 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
622 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
623 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
624 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
627 TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) {
628 MockRead reads[] = {
629 MockRead(ASYNC, OK, 0) // EOF
631 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
632 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
633 socket_factory_.AddSocketDataProvider(&socket_data1);
634 socket_factory_.AddSocketDataProvider(&socket_data2);
635 socket_data1.StopAfter(1);
636 socket_data2.StopAfter(1);
638 HostPortPair server2("mail.google.com", kDefaultServerPort);
639 host_resolver_.set_synchronous_mode(true);
640 host_resolver_.rules()->AddIPLiteralRule(
641 kDefaultServerHostName, "192.168.0.1", "");
642 host_resolver_.rules()->AddIPLiteralRule(
643 "mail.google.com", "192.168.0.1", "");
645 QuicStreamRequest request(&factory_);
646 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
647 /*cert_verify_flags=*/0, host_port_pair_.host(),
648 "GET", net_log_, callback_.callback()));
649 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
650 EXPECT_TRUE(stream.get());
652 TestCompletionCallback callback;
653 QuicStreamRequest request2(&factory_);
654 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
655 /*cert_verify_flags=*/0, server2.host(), "GET",
656 net_log_, callback.callback()));
657 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
658 EXPECT_TRUE(stream2.get());
660 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession(
661 &factory_, host_port_pair_, is_https_));
662 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
663 &factory_, host_port_pair_, is_https_));
664 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
665 &factory_, server2, is_https_));
667 TestCompletionCallback callback3;
668 QuicStreamRequest request3(&factory_);
669 EXPECT_EQ(OK, request3.Request(server2, is_https_, privacy_mode_,
670 /*cert_verify_flags=*/0, server2.host(), "GET",
671 net_log_, callback3.callback()));
672 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
673 EXPECT_TRUE(stream3.get());
675 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
676 &factory_, server2, is_https_));
678 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
679 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
680 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
681 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
684 TEST_P(QuicStreamFactoryTest, HttpsPooling) {
685 MockRead reads[] = {
686 MockRead(ASYNC, OK, 0) // EOF
688 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
689 socket_factory_.AddSocketDataProvider(&socket_data);
690 socket_data.StopAfter(1);
692 HostPortPair server1("www.example.org", 443);
693 HostPortPair server2("mail.example.org", 443);
695 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
696 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
698 host_resolver_.set_synchronous_mode(true);
699 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
700 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
702 QuicStreamRequest request(&factory_);
703 is_https_ = true;
704 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
705 /*cert_verify_flags=*/0, server1.host(), "GET",
706 net_log_, callback_.callback()));
707 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
708 EXPECT_TRUE(stream.get());
710 TestCompletionCallback callback;
711 QuicStreamRequest request2(&factory_);
712 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
713 /*cert_verify_flags=*/0, server2.host(), "GET",
714 net_log_, callback_.callback()));
715 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
716 EXPECT_TRUE(stream2.get());
718 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
719 &factory_, server1, is_https_),
720 QuicStreamFactoryPeer::GetActiveSession(
721 &factory_, server2, is_https_));
723 EXPECT_TRUE(socket_data.AllReadDataConsumed());
724 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
727 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingIfDisabled) {
728 MockRead reads[] = {
729 MockRead(ASYNC, OK, 0) // EOF
731 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
732 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
733 socket_factory_.AddSocketDataProvider(&socket_data1);
734 socket_factory_.AddSocketDataProvider(&socket_data2);
735 socket_data1.StopAfter(1);
736 socket_data2.StopAfter(1);
738 HostPortPair server1("www.example.org", 443);
739 HostPortPair server2("mail.example.org", 443);
741 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
742 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
744 host_resolver_.set_synchronous_mode(true);
745 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
746 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
748 // Disable connection pooling.
749 QuicStreamFactoryPeer::DisableConnectionPooling(&factory_);
751 QuicStreamRequest request(&factory_);
752 is_https_ = true;
753 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
754 /*cert_verify_flags=*/0, server1.host(), "GET",
755 net_log_, callback_.callback()));
756 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
757 EXPECT_TRUE(stream.get());
759 TestCompletionCallback callback;
760 QuicStreamRequest request2(&factory_);
761 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
762 /*cert_verify_flags=*/0, server2.host(), "GET",
763 net_log_, callback_.callback()));
764 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
765 EXPECT_TRUE(stream2.get());
767 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
768 &factory_, server1, is_https_),
769 QuicStreamFactoryPeer::GetActiveSession(
770 &factory_, server2, is_https_));
772 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
773 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
774 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
775 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
778 class QuicAlternativeServiceCertificateValidationPooling
779 : public QuicStreamFactoryTest {
780 public:
781 void Run(bool valid) {
782 MockRead reads[] = {
783 MockRead(ASYNC, OK, 0) // EOF
785 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
786 socket_factory_.AddSocketDataProvider(&socket_data1);
787 socket_data1.StopAfter(1);
789 HostPortPair server1("www.example.org", 443);
790 HostPortPair server2("mail.example.org", 443);
792 std::string origin_host(valid ? "mail.example.org" : "invalid.example.org");
793 HostPortPair alternative("www.example.org", 443);
795 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
796 bool common_name_fallback_used;
797 EXPECT_EQ(valid,
798 verify_details.cert_verify_result.verified_cert->VerifyNameMatch(
799 origin_host, &common_name_fallback_used));
800 EXPECT_TRUE(
801 verify_details.cert_verify_result.verified_cert->VerifyNameMatch(
802 alternative.host(), &common_name_fallback_used));
803 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
805 host_resolver_.set_synchronous_mode(true);
806 host_resolver_.rules()->AddIPLiteralRule(alternative.host(), "192.168.0.1",
807 "");
809 // Open first stream to alternative.
810 QuicStreamRequest request1(&factory_);
811 is_https_ = true;
812 EXPECT_EQ(OK, request1.Request(alternative, is_https_, privacy_mode_,
813 /*cert_verify_flags=*/0, alternative.host(),
814 "GET", net_log_, callback_.callback()));
815 scoped_ptr<QuicHttpStream> stream1 = request1.ReleaseStream();
816 EXPECT_TRUE(stream1.get());
818 QuicStreamRequest request2(&factory_);
819 int rv = request2.Request(alternative, is_https_, privacy_mode_,
820 /*cert_verify_flags=*/0, origin_host, "GET",
821 net_log_, callback_.callback());
822 if (valid) {
823 // Alternative service of origin to |alternative| should pool to session
824 // of |stream1| even if origin is different. Since only one
825 // SocketDataProvider is set up, the second request succeeding means that
826 // it pooled to the session opened by the first one.
827 EXPECT_EQ(OK, rv);
828 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
829 EXPECT_TRUE(stream2.get());
830 } else {
831 EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv);
834 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
835 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
839 INSTANTIATE_TEST_CASE_P(Version,
840 QuicAlternativeServiceCertificateValidationPooling,
841 ::testing::ValuesIn(GetTestParams()));
843 TEST_P(QuicAlternativeServiceCertificateValidationPooling, Valid) {
844 Run(true);
847 TEST_P(QuicAlternativeServiceCertificateValidationPooling, Invalid) {
848 Run(false);
851 TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) {
852 MockRead reads[] = {
853 MockRead(ASYNC, OK, 0) // EOF
855 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
856 socket_factory_.AddSocketDataProvider(&socket_data);
857 socket_data.StopAfter(1);
859 HostPortPair server1("www.example.org", 443);
860 HostPortPair server2("mail.example.org", 443);
861 uint8 primary_pin = 1;
862 uint8 backup_pin = 2;
863 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
864 backup_pin);
866 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
867 verify_details.cert_verify_result.public_key_hashes.push_back(
868 test::GetTestHashValue(primary_pin));
869 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
871 host_resolver_.set_synchronous_mode(true);
872 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
873 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
875 QuicStreamRequest request(&factory_);
876 is_https_ = true;
877 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
878 /*cert_verify_flags=*/0, server1.host(), "GET",
879 net_log_, callback_.callback()));
880 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
881 EXPECT_TRUE(stream.get());
883 TestCompletionCallback callback;
884 QuicStreamRequest request2(&factory_);
885 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
886 /*cert_verify_flags=*/0, server2.host(), "GET",
887 net_log_, callback_.callback()));
888 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
889 EXPECT_TRUE(stream2.get());
891 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
892 &factory_, server1, is_https_),
893 QuicStreamFactoryPeer::GetActiveSession(
894 &factory_, server2, is_https_));
896 EXPECT_TRUE(socket_data.AllReadDataConsumed());
897 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
900 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithMatchingPinsIfDisabled) {
901 MockRead reads[] = {
902 MockRead(ASYNC, OK, 0) // EOF
904 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
905 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
906 socket_factory_.AddSocketDataProvider(&socket_data1);
907 socket_factory_.AddSocketDataProvider(&socket_data2);
908 socket_data1.StopAfter(1);
909 socket_data2.StopAfter(1);
911 HostPortPair server1("www.example.org", 443);
912 HostPortPair server2("mail.example.org", 443);
913 uint8 primary_pin = 1;
914 uint8 backup_pin = 2;
915 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
916 backup_pin);
918 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
919 verify_details.cert_verify_result.public_key_hashes.push_back(
920 test::GetTestHashValue(primary_pin));
921 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
923 host_resolver_.set_synchronous_mode(true);
924 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
925 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
927 // Disable connection pooling.
928 QuicStreamFactoryPeer::DisableConnectionPooling(&factory_);
930 QuicStreamRequest request(&factory_);
931 is_https_ = true;
932 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
933 /*cert_verify_flags=*/0, server1.host(), "GET",
934 net_log_, callback_.callback()));
935 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
936 EXPECT_TRUE(stream.get());
938 TestCompletionCallback callback;
939 QuicStreamRequest request2(&factory_);
940 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
941 /*cert_verify_flags=*/0, server2.host(), "GET",
942 net_log_, callback_.callback()));
943 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
944 EXPECT_TRUE(stream2.get());
946 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
947 &factory_, server1, is_https_),
948 QuicStreamFactoryPeer::GetActiveSession(
949 &factory_, server2, is_https_));
951 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
952 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
953 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
954 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
957 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) {
958 MockRead reads[] = {
959 MockRead(ASYNC, OK, 0) // EOF
961 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
962 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
963 socket_factory_.AddSocketDataProvider(&socket_data1);
964 socket_factory_.AddSocketDataProvider(&socket_data2);
965 socket_data1.StopAfter(1);
966 socket_data2.StopAfter(1);
968 HostPortPair server1("www.example.org", 443);
969 HostPortPair server2("mail.example.org", 443);
970 uint8 primary_pin = 1;
971 uint8 backup_pin = 2;
972 uint8 bad_pin = 3;
973 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
974 backup_pin);
976 ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails();
977 verify_details1.cert_verify_result.public_key_hashes.push_back(
978 test::GetTestHashValue(bad_pin));
979 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1);
981 ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails();
982 verify_details2.cert_verify_result.public_key_hashes.push_back(
983 test::GetTestHashValue(primary_pin));
984 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2);
986 host_resolver_.set_synchronous_mode(true);
987 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
988 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
990 QuicStreamRequest request(&factory_);
991 is_https_ = true;
992 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
993 /*cert_verify_flags=*/0, server1.host(), "GET",
994 net_log_, callback_.callback()));
995 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
996 EXPECT_TRUE(stream.get());
998 TestCompletionCallback callback;
999 QuicStreamRequest request2(&factory_);
1000 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1001 /*cert_verify_flags=*/0, server2.host(), "GET",
1002 net_log_, callback_.callback()));
1003 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1004 EXPECT_TRUE(stream2.get());
1006 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
1007 &factory_, server1, is_https_),
1008 QuicStreamFactoryPeer::GetActiveSession(
1009 &factory_, server2, is_https_));
1011 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
1012 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
1013 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1014 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1017 TEST_P(QuicStreamFactoryTest, Goaway) {
1018 MockRead reads[] = {
1019 MockRead(ASYNC, OK, 0) // EOF
1021 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1022 socket_data.StopAfter(1);
1023 socket_factory_.AddSocketDataProvider(&socket_data);
1024 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1025 socket_data2.StopAfter(1);
1026 socket_factory_.AddSocketDataProvider(&socket_data2);
1028 QuicStreamRequest request(&factory_);
1029 EXPECT_EQ(ERR_IO_PENDING,
1030 request.Request(host_port_pair_, is_https_, privacy_mode_,
1031 /*cert_verify_flags=*/0, host_port_pair_.host(),
1032 "GET", net_log_, callback_.callback()));
1034 EXPECT_EQ(OK, callback_.WaitForResult());
1035 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1036 EXPECT_TRUE(stream.get());
1038 // Mark the session as going away. Ensure that while it is still alive
1039 // that it is no longer active.
1040 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1041 &factory_, host_port_pair_, is_https_);
1042 factory_.OnSessionGoingAway(session);
1043 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
1044 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
1045 &factory_, host_port_pair_, is_https_));
1046 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1048 // Create a new request for the same destination and verify that a
1049 // new session is created.
1050 QuicStreamRequest request2(&factory_);
1051 EXPECT_EQ(ERR_IO_PENDING,
1052 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1053 /*cert_verify_flags=*/0, host_port_pair_.host(),
1054 "GET", net_log_, callback_.callback()));
1055 EXPECT_EQ(OK, callback_.WaitForResult());
1056 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1057 EXPECT_TRUE(stream2.get());
1059 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
1060 host_port_pair_,
1061 is_https_));
1062 EXPECT_NE(session,
1063 QuicStreamFactoryPeer::GetActiveSession(
1064 &factory_, host_port_pair_, is_https_));
1065 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
1067 stream2.reset();
1068 stream.reset();
1070 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1071 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1072 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1073 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1076 TEST_P(QuicStreamFactoryTest, MaxOpenStream) {
1077 MockRead reads[] = {
1078 MockRead(ASYNC, OK, 0) // EOF
1080 QuicStreamId stream_id = kClientDataStreamId1;
1081 scoped_ptr<QuicEncryptedPacket> rst(
1082 maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED));
1083 MockWrite writes[] = {
1084 MockWrite(ASYNC, rst->data(), rst->length(), 1),
1086 DeterministicSocketData socket_data(reads, arraysize(reads),
1087 writes, arraysize(writes));
1088 socket_factory_.AddSocketDataProvider(&socket_data);
1089 socket_data.StopAfter(1);
1091 HttpRequestInfo request_info;
1092 std::vector<QuicHttpStream*> streams;
1093 // The MockCryptoClientStream sets max_open_streams to be
1094 // kDefaultMaxStreamsPerConnection / 2.
1095 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection / 2; i++) {
1096 QuicStreamRequest request(&factory_);
1097 int rv = request.Request(host_port_pair_, is_https_, privacy_mode_,
1098 /*cert_verify_flags=*/0, host_port_pair_.host(),
1099 "GET", net_log_, callback_.callback());
1100 if (i == 0) {
1101 EXPECT_EQ(ERR_IO_PENDING, rv);
1102 EXPECT_EQ(OK, callback_.WaitForResult());
1103 } else {
1104 EXPECT_EQ(OK, rv);
1106 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1107 EXPECT_TRUE(stream);
1108 EXPECT_EQ(OK, stream->InitializeStream(
1109 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback()));
1110 streams.push_back(stream.release());
1113 QuicStreamRequest request(&factory_);
1114 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1115 /*cert_verify_flags=*/0, host_port_pair_.host(),
1116 "GET", net_log_, CompletionCallback()));
1117 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1118 EXPECT_TRUE(stream);
1119 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream(
1120 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback()));
1122 // Close the first stream.
1123 streams.front()->Close(false);
1125 ASSERT_TRUE(callback_.have_result());
1127 EXPECT_EQ(OK, callback_.WaitForResult());
1129 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1130 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1131 STLDeleteElements(&streams);
1134 TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) {
1135 DeterministicSocketData socket_data(nullptr, 0, nullptr, 0);
1136 socket_factory_.AddSocketDataProvider(&socket_data);
1138 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName);
1140 QuicStreamRequest request(&factory_);
1141 EXPECT_EQ(ERR_IO_PENDING,
1142 request.Request(host_port_pair_, is_https_, privacy_mode_,
1143 /*cert_verify_flags=*/0, host_port_pair_.host(),
1144 "GET", net_log_, callback_.callback()));
1146 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult());
1148 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1149 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1152 TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) {
1153 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE);
1154 DeterministicSocketData socket_data(nullptr, 0, nullptr, 0);
1155 socket_data.set_connect_data(connect);
1156 socket_factory_.AddSocketDataProvider(&socket_data);
1157 socket_data.StopAfter(1);
1159 QuicStreamRequest request(&factory_);
1160 EXPECT_EQ(ERR_IO_PENDING,
1161 request.Request(host_port_pair_, is_https_, privacy_mode_,
1162 /*cert_verify_flags=*/0, host_port_pair_.host(),
1163 "GET", net_log_, callback_.callback()));
1165 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult());
1167 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1168 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1171 TEST_P(QuicStreamFactoryTest, CancelCreate) {
1172 MockRead reads[] = {
1173 MockRead(ASYNC, OK, 0) // EOF
1175 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1176 socket_factory_.AddSocketDataProvider(&socket_data);
1178 QuicStreamRequest request(&factory_);
1179 EXPECT_EQ(ERR_IO_PENDING,
1180 request.Request(host_port_pair_, is_https_, privacy_mode_,
1181 /*cert_verify_flags=*/0, host_port_pair_.host(),
1182 "GET", net_log_, callback_.callback()));
1185 socket_data.StopAfter(1);
1186 base::RunLoop run_loop;
1187 run_loop.RunUntilIdle();
1189 scoped_ptr<QuicHttpStream> stream(CreateFromSession(host_port_pair_));
1190 EXPECT_TRUE(stream.get());
1191 stream.reset();
1193 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1194 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1197 TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) {
1198 // Sequentially connect to the default host, then another host, and then the
1199 // default host. Verify that the default host gets a consistent ephemeral
1200 // port, that is different from the other host's connection.
1202 std::string other_server_name = "other.google.com";
1203 EXPECT_NE(kDefaultServerHostName, other_server_name);
1204 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort);
1206 int original_port = GetSourcePortForNewSession(host_port_pair_);
1207 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair2));
1208 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_));
1211 TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) {
1212 // Get a session to the host using the port suggester.
1213 int original_port =
1214 GetSourcePortForNewSessionAndGoAway(host_port_pair_);
1215 // Verify that the port is different after the goaway.
1216 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair_));
1217 // Since the previous session did not goaway we should see the original port.
1218 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_));
1221 TEST_P(QuicStreamFactoryTest, CloseAllSessions) {
1222 MockRead reads[] = {
1223 MockRead(ASYNC, 0, 0) // EOF
1225 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1226 std::vector<MockWrite> writes;
1227 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1228 DeterministicSocketData socket_data(reads, arraysize(reads),
1229 writes.empty() ? nullptr : &writes[0],
1230 writes.size());
1231 socket_factory_.AddSocketDataProvider(&socket_data);
1232 socket_data.StopAfter(1);
1234 MockRead reads2[] = {
1235 MockRead(ASYNC, 0, 0) // EOF
1237 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1238 socket_factory_.AddSocketDataProvider(&socket_data2);
1239 socket_data2.StopAfter(1);
1241 QuicStreamRequest request(&factory_);
1242 EXPECT_EQ(ERR_IO_PENDING,
1243 request.Request(host_port_pair_, is_https_, privacy_mode_,
1244 /*cert_verify_flags=*/0, host_port_pair_.host(),
1245 "GET", net_log_, callback_.callback()));
1247 EXPECT_EQ(OK, callback_.WaitForResult());
1248 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1249 HttpRequestInfo request_info;
1250 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1251 DEFAULT_PRIORITY,
1252 net_log_, CompletionCallback()));
1254 // Close the session and verify that stream saw the error.
1255 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED);
1256 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
1257 stream->ReadResponseHeaders(callback_.callback()));
1259 // Now attempting to request a stream to the same origin should create
1260 // a new session.
1262 QuicStreamRequest request2(&factory_);
1263 EXPECT_EQ(ERR_IO_PENDING,
1264 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1265 /*cert_verify_flags=*/0, host_port_pair_.host(),
1266 "GET", net_log_, callback_.callback()));
1268 EXPECT_EQ(OK, callback_.WaitForResult());
1269 stream = request2.ReleaseStream();
1270 stream.reset(); // Will reset stream 3.
1272 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1273 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1274 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1275 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1278 TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) {
1279 MockRead reads[] = {
1280 MockRead(ASYNC, 0, 0) // EOF
1282 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1283 std::vector<MockWrite> writes;
1284 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1285 DeterministicSocketData socket_data(reads, arraysize(reads),
1286 writes.empty() ? nullptr : &writes[0],
1287 writes.size());
1288 socket_factory_.AddSocketDataProvider(&socket_data);
1289 socket_data.StopAfter(1);
1291 MockRead reads2[] = {
1292 MockRead(ASYNC, 0, 0) // EOF
1294 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1295 socket_factory_.AddSocketDataProvider(&socket_data2);
1296 socket_data2.StopAfter(1);
1298 QuicStreamRequest request(&factory_);
1299 EXPECT_EQ(ERR_IO_PENDING,
1300 request.Request(host_port_pair_, is_https_, privacy_mode_,
1301 /*cert_verify_flags=*/0, host_port_pair_.host(),
1302 "GET", net_log_, callback_.callback()));
1304 EXPECT_EQ(OK, callback_.WaitForResult());
1305 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1306 HttpRequestInfo request_info;
1307 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1308 DEFAULT_PRIORITY,
1309 net_log_, CompletionCallback()));
1311 // Change the IP address and verify that stream saw the error.
1312 factory_.OnIPAddressChanged();
1313 EXPECT_EQ(ERR_NETWORK_CHANGED,
1314 stream->ReadResponseHeaders(callback_.callback()));
1315 EXPECT_TRUE(factory_.require_confirmation());
1317 // Now attempting to request a stream to the same origin should create
1318 // a new session.
1320 QuicStreamRequest request2(&factory_);
1321 EXPECT_EQ(ERR_IO_PENDING,
1322 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1323 /*cert_verify_flags=*/0, host_port_pair_.host(),
1324 "GET", net_log_, callback_.callback()));
1326 EXPECT_EQ(OK, callback_.WaitForResult());
1327 stream = request2.ReleaseStream();
1328 stream.reset(); // Will reset stream 3.
1330 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1331 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1332 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1333 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1336 TEST_P(QuicStreamFactoryTest, OnCertAdded) {
1337 MockRead reads[] = {
1338 MockRead(ASYNC, 0, 0) // EOF
1340 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1341 std::vector<MockWrite> writes;
1342 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1343 DeterministicSocketData socket_data(reads, arraysize(reads),
1344 writes.empty() ? nullptr : &writes[0],
1345 writes.size());
1346 socket_factory_.AddSocketDataProvider(&socket_data);
1347 socket_data.StopAfter(1);
1349 MockRead reads2[] = {
1350 MockRead(ASYNC, 0, 0) // EOF
1352 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1353 socket_factory_.AddSocketDataProvider(&socket_data2);
1354 socket_data2.StopAfter(1);
1356 QuicStreamRequest request(&factory_);
1357 EXPECT_EQ(ERR_IO_PENDING,
1358 request.Request(host_port_pair_, is_https_, privacy_mode_,
1359 /*cert_verify_flags=*/0, host_port_pair_.host(),
1360 "GET", net_log_, callback_.callback()));
1362 EXPECT_EQ(OK, callback_.WaitForResult());
1363 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1364 HttpRequestInfo request_info;
1365 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1366 DEFAULT_PRIORITY,
1367 net_log_, CompletionCallback()));
1369 // Add a cert and verify that stream saw the event.
1370 factory_.OnCertAdded(nullptr);
1371 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
1372 stream->ReadResponseHeaders(callback_.callback()));
1373 EXPECT_FALSE(factory_.require_confirmation());
1375 // Now attempting to request a stream to the same origin should create
1376 // a new session.
1378 QuicStreamRequest request2(&factory_);
1379 EXPECT_EQ(ERR_IO_PENDING,
1380 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1381 /*cert_verify_flags=*/0, host_port_pair_.host(),
1382 "GET", net_log_, callback_.callback()));
1384 EXPECT_EQ(OK, callback_.WaitForResult());
1385 stream = request2.ReleaseStream();
1386 stream.reset(); // Will reset stream 3.
1388 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1389 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1390 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1391 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1394 TEST_P(QuicStreamFactoryTest, OnCACertChanged) {
1395 MockRead reads[] = {
1396 MockRead(ASYNC, 0, 0) // EOF
1398 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1399 std::vector<MockWrite> writes;
1400 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1401 DeterministicSocketData socket_data(reads, arraysize(reads),
1402 writes.empty() ? nullptr : &writes[0],
1403 writes.size());
1404 socket_factory_.AddSocketDataProvider(&socket_data);
1405 socket_data.StopAfter(1);
1407 MockRead reads2[] = {
1408 MockRead(ASYNC, 0, 0) // EOF
1410 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1411 socket_factory_.AddSocketDataProvider(&socket_data2);
1412 socket_data2.StopAfter(1);
1414 QuicStreamRequest request(&factory_);
1415 EXPECT_EQ(ERR_IO_PENDING,
1416 request.Request(host_port_pair_, is_https_, privacy_mode_,
1417 /*cert_verify_flags=*/0, host_port_pair_.host(),
1418 "GET", net_log_, callback_.callback()));
1420 EXPECT_EQ(OK, callback_.WaitForResult());
1421 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1422 HttpRequestInfo request_info;
1423 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1424 DEFAULT_PRIORITY,
1425 net_log_, CompletionCallback()));
1427 // Change the CA cert and verify that stream saw the event.
1428 factory_.OnCACertChanged(nullptr);
1429 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
1430 stream->ReadResponseHeaders(callback_.callback()));
1431 EXPECT_FALSE(factory_.require_confirmation());
1433 // Now attempting to request a stream to the same origin should create
1434 // a new session.
1436 QuicStreamRequest request2(&factory_);
1437 EXPECT_EQ(ERR_IO_PENDING,
1438 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1439 /*cert_verify_flags=*/0, host_port_pair_.host(),
1440 "GET", net_log_, callback_.callback()));
1442 EXPECT_EQ(OK, callback_.WaitForResult());
1443 stream = request2.ReleaseStream();
1444 stream.reset(); // Will reset stream 3.
1446 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1447 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1448 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1449 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1452 TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) {
1453 vector<string> cannoncial_suffixes;
1454 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1455 cannoncial_suffixes.push_back(string(".googlevideo.com"));
1457 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1458 string r1_host_name("r1");
1459 string r2_host_name("r2");
1460 r1_host_name.append(cannoncial_suffixes[i]);
1461 r2_host_name.append(cannoncial_suffixes[i]);
1463 HostPortPair host_port_pair1(r1_host_name, 80);
1464 QuicCryptoClientConfig* crypto_config =
1465 QuicStreamFactoryPeer::GetCryptoConfig(&factory_);
1466 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_);
1467 QuicCryptoClientConfig::CachedState* cached1 =
1468 crypto_config->LookupOrCreate(server_id1);
1469 EXPECT_FALSE(cached1->proof_valid());
1470 EXPECT_TRUE(cached1->source_address_token().empty());
1472 // Mutate the cached1 to have different data.
1473 // TODO(rtenneti): mutate other members of CachedState.
1474 cached1->set_source_address_token(r1_host_name);
1475 cached1->SetProofValid();
1477 HostPortPair host_port_pair2(r2_host_name, 80);
1478 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_);
1479 QuicCryptoClientConfig::CachedState* cached2 =
1480 crypto_config->LookupOrCreate(server_id2);
1481 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token());
1482 EXPECT_TRUE(cached2->proof_valid());
1486 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) {
1487 vector<string> cannoncial_suffixes;
1488 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1489 cannoncial_suffixes.push_back(string(".googlevideo.com"));
1491 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1492 string r3_host_name("r3");
1493 string r4_host_name("r4");
1494 r3_host_name.append(cannoncial_suffixes[i]);
1495 r4_host_name.append(cannoncial_suffixes[i]);
1497 HostPortPair host_port_pair1(r3_host_name, 80);
1498 QuicCryptoClientConfig* crypto_config =
1499 QuicStreamFactoryPeer::GetCryptoConfig(&factory_);
1500 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_);
1501 QuicCryptoClientConfig::CachedState* cached1 =
1502 crypto_config->LookupOrCreate(server_id1);
1503 EXPECT_FALSE(cached1->proof_valid());
1504 EXPECT_TRUE(cached1->source_address_token().empty());
1506 // Mutate the cached1 to have different data.
1507 // TODO(rtenneti): mutate other members of CachedState.
1508 cached1->set_source_address_token(r3_host_name);
1509 cached1->SetProofInvalid();
1511 HostPortPair host_port_pair2(r4_host_name, 80);
1512 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_);
1513 QuicCryptoClientConfig::CachedState* cached2 =
1514 crypto_config->LookupOrCreate(server_id2);
1515 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1516 EXPECT_TRUE(cached2->source_address_token().empty());
1517 EXPECT_FALSE(cached2->proof_valid());
1521 TEST_P(QuicStreamFactoryTest, RacingConnections) {
1522 if (!GetParam().enable_connection_racing)
1523 return;
1524 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1525 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1526 MockRead reads[] = {
1527 MockRead(ASYNC, OK, 0) // EOF
1529 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1530 socket_factory_.AddSocketDataProvider(&socket_data);
1531 socket_data.StopAfter(1);
1533 MockRead reads2[] = {
1534 MockRead(ASYNC, 0, 0) // EOF
1536 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1537 socket_factory_.AddSocketDataProvider(&socket_data2);
1538 socket_data2.StopAfter(1);
1540 crypto_client_stream_factory_.set_handshake_mode(
1541 MockCryptoClientStream::ZERO_RTT);
1542 host_resolver_.set_synchronous_mode(true);
1543 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1544 "192.168.0.1", "");
1546 QuicStreamRequest request(&factory_);
1547 QuicServerId server_id(host_port_pair_, is_https_, privacy_mode_);
1548 EXPECT_EQ(ERR_IO_PENDING,
1549 request.Request(host_port_pair_, is_https_, privacy_mode_,
1550 /*cert_verify_flags=*/0, host_port_pair_.host(),
1551 "GET", net_log_, callback_.callback()));
1552 EXPECT_EQ(2u,
1553 QuicStreamFactoryPeer::GetNumberOfActiveJobs(&factory_, server_id));
1555 runner_->RunNextTask();
1557 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1558 EXPECT_TRUE(stream.get());
1559 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1560 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1561 EXPECT_EQ(0u,
1562 QuicStreamFactoryPeer::GetNumberOfActiveJobs(&factory_, server_id));
1565 TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) {
1566 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1567 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1568 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1570 MockRead reads[] = {
1571 MockRead(ASYNC, OK, 0) // EOF
1573 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1574 socket_factory_.AddSocketDataProvider(&socket_data);
1575 socket_data.StopAfter(1);
1577 crypto_client_stream_factory_.set_handshake_mode(
1578 MockCryptoClientStream::ZERO_RTT);
1579 host_resolver_.set_synchronous_mode(true);
1580 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1581 "192.168.0.1", "");
1583 QuicStreamRequest request(&factory_);
1584 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1585 /*cert_verify_flags=*/0, host_port_pair_.host(),
1586 "GET", net_log_, callback_.callback()));
1588 // If we are waiting for disk cache, we would have posted a task. Verify that
1589 // the CancelWaitForDataReady task hasn't been posted.
1590 ASSERT_EQ(0u, runner_->GetPostedTasks().size());
1592 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1593 EXPECT_TRUE(stream.get());
1594 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1595 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1598 TEST_P(QuicStreamFactoryTest, BadPacketLoss) {
1599 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1600 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1601 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1602 QuicStreamFactoryPeer::SetMaxNumberOfLossyConnections(&factory_, 2);
1603 EXPECT_FALSE(
1604 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1605 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1606 &factory_, host_port_pair_.port()));
1608 MockRead reads[] = {
1609 MockRead(ASYNC, OK, 0) // EOF
1611 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1612 socket_factory_.AddSocketDataProvider(&socket_data);
1613 socket_data.StopAfter(1);
1615 DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
1616 socket_factory_.AddSocketDataProvider(&socket_data2);
1617 socket_data2.StopAfter(1);
1619 DeterministicSocketData socket_data3(nullptr, 0, nullptr, 0);
1620 socket_factory_.AddSocketDataProvider(&socket_data3);
1621 socket_data3.StopAfter(1);
1623 DeterministicSocketData socket_data4(nullptr, 0, nullptr, 0);
1624 socket_factory_.AddSocketDataProvider(&socket_data4);
1625 socket_data4.StopAfter(1);
1627 HostPortPair server2("mail.example.org", kDefaultServerPort);
1628 HostPortPair server3("docs.example.org", kDefaultServerPort);
1629 HostPortPair server4("images.example.org", kDefaultServerPort);
1631 crypto_client_stream_factory_.set_handshake_mode(
1632 MockCryptoClientStream::ZERO_RTT);
1633 host_resolver_.set_synchronous_mode(true);
1634 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1635 "192.168.0.1", "");
1636 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1637 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
1638 host_resolver_.rules()->AddIPLiteralRule(server4.host(), "192.168.0.1", "");
1640 QuicStreamRequest request(&factory_);
1641 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1642 /*cert_verify_flags=*/0, host_port_pair_.host(),
1643 "GET", net_log_, callback_.callback()));
1645 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1646 &factory_, host_port_pair_, is_https_);
1648 DVLOG(1) << "Create 1st session and test packet loss";
1650 // Set packet_loss_rate to a lower value than packet_loss_threshold.
1651 EXPECT_FALSE(
1652 factory_.OnHandshakeConfirmed(session, /*packet_loss_rate=*/0.9f));
1653 EXPECT_TRUE(session->connection()->connected());
1654 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
1655 &factory_, host_port_pair_, is_https_));
1656 EXPECT_FALSE(
1657 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1658 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1659 &factory_, host_port_pair_.port()));
1661 // Set packet_loss_rate to a higher value than packet_loss_threshold only once
1662 // and that shouldn't close the session and it shouldn't disable QUIC.
1663 EXPECT_FALSE(
1664 factory_.OnHandshakeConfirmed(session, /*packet_loss_rate=*/1.0f));
1665 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1666 &factory_, host_port_pair_.port()));
1667 EXPECT_TRUE(session->connection()->connected());
1668 EXPECT_FALSE(
1669 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1670 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
1671 &factory_, host_port_pair_, is_https_));
1673 // Test N-in-a-row high packet loss connections.
1675 DVLOG(1) << "Create 2nd session and test packet loss";
1677 TestCompletionCallback callback2;
1678 QuicStreamRequest request2(&factory_);
1679 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1680 /*cert_verify_flags=*/0, server2.host(), "GET",
1681 net_log_, callback2.callback()));
1682 QuicChromiumClientSession* session2 =
1683 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1685 // If there is no packet loss during handshake confirmation, number of lossy
1686 // connections for the port should be 0.
1687 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1688 &factory_, server2.port()));
1689 EXPECT_FALSE(
1690 factory_.OnHandshakeConfirmed(session2, /*packet_loss_rate=*/0.9f));
1691 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1692 &factory_, server2.port()));
1693 EXPECT_FALSE(
1694 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server2.port()));
1696 // Set packet_loss_rate to a higher value than packet_loss_threshold only once
1697 // and that shouldn't close the session and it shouldn't disable QUIC.
1698 EXPECT_FALSE(
1699 factory_.OnHandshakeConfirmed(session2, /*packet_loss_rate=*/1.0f));
1700 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1701 &factory_, server2.port()));
1702 EXPECT_TRUE(session2->connection()->connected());
1703 EXPECT_FALSE(
1704 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server2.port()));
1705 EXPECT_TRUE(
1706 QuicStreamFactoryPeer::HasActiveSession(&factory_, server2, is_https_));
1708 DVLOG(1) << "Create 3rd session which also has packet loss";
1710 TestCompletionCallback callback3;
1711 QuicStreamRequest request3(&factory_);
1712 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
1713 /*cert_verify_flags=*/0, server3.host(), "GET",
1714 net_log_, callback3.callback()));
1715 QuicChromiumClientSession* session3 =
1716 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
1718 DVLOG(1) << "Create 4th session with packet loss and test IsQuicDisabled()";
1719 TestCompletionCallback callback4;
1720 QuicStreamRequest request4(&factory_);
1721 EXPECT_EQ(OK, request4.Request(server4, is_https_, privacy_mode_,
1722 /*cert_verify_flags=*/0, server4.host(), "GET",
1723 net_log_, callback4.callback()));
1724 QuicChromiumClientSession* session4 =
1725 QuicStreamFactoryPeer::GetActiveSession(&factory_, server4, is_https_);
1727 // Set packet_loss_rate to higher value than packet_loss_threshold 2nd time in
1728 // a row and that should close the session and disable QUIC.
1729 EXPECT_TRUE(
1730 factory_.OnHandshakeConfirmed(session3, /*packet_loss_rate=*/1.0f));
1731 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1732 &factory_, server3.port()));
1733 EXPECT_FALSE(session3->connection()->connected());
1734 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server3.port()));
1735 EXPECT_FALSE(
1736 QuicStreamFactoryPeer::HasActiveSession(&factory_, server3, is_https_));
1737 EXPECT_FALSE(HasActiveSession(server3));
1739 // Set packet_loss_rate to higher value than packet_loss_threshold 3rd time in
1740 // a row and IsQuicDisabled() should close the session.
1741 EXPECT_TRUE(
1742 factory_.OnHandshakeConfirmed(session4, /*packet_loss_rate=*/1.0f));
1743 EXPECT_EQ(3, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1744 &factory_, server4.port()));
1745 EXPECT_FALSE(session4->connection()->connected());
1746 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server4.port()));
1747 EXPECT_FALSE(
1748 QuicStreamFactoryPeer::HasActiveSession(&factory_, server4, is_https_));
1749 EXPECT_FALSE(HasActiveSession(server4));
1751 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1752 EXPECT_TRUE(stream.get());
1753 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1754 EXPECT_TRUE(stream2.get());
1755 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
1756 EXPECT_TRUE(stream3.get());
1757 scoped_ptr<QuicHttpStream> stream4 = request4.ReleaseStream();
1758 EXPECT_TRUE(stream4.get());
1759 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1760 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1761 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1762 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1763 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
1764 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
1765 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
1766 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
1769 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfTwo) {
1770 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1771 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1772 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1773 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
1774 EXPECT_FALSE(
1775 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1776 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1777 &factory_, host_port_pair_.port()));
1779 MockRead reads[] = {
1780 MockRead(ASYNC, OK, 0) // EOF
1782 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1783 socket_factory_.AddSocketDataProvider(&socket_data);
1784 socket_data.StopAfter(1);
1786 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1787 socket_factory_.AddSocketDataProvider(&socket_data2);
1788 socket_data2.StopAfter(1);
1790 HostPortPair server2("mail.example.org", kDefaultServerPort);
1792 crypto_client_stream_factory_.set_handshake_mode(
1793 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1794 host_resolver_.set_synchronous_mode(true);
1795 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1796 "192.168.0.1", "");
1797 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1799 QuicStreamRequest request(&factory_);
1800 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1801 /*cert_verify_flags=*/0, host_port_pair_.host(),
1802 "GET", net_log_, callback_.callback()));
1804 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1805 &factory_, host_port_pair_, is_https_);
1807 DVLOG(1) << "Created 1st session. Now trigger public reset post handshake";
1808 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1809 // Need to spin the loop now to ensure that
1810 // QuicStreamFactory::OnSessionClosed() runs.
1811 base::RunLoop run_loop;
1812 run_loop.RunUntilIdle();
1814 EXPECT_EQ(1,
1815 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
1816 EXPECT_FALSE(
1817 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1819 // Test two-in-a-row public reset post handshakes..
1820 DVLOG(1) << "Create 2nd session and trigger public reset post handshake";
1821 TestCompletionCallback callback2;
1822 QuicStreamRequest request2(&factory_);
1823 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1824 /*cert_verify_flags=*/0, server2.host(), "GET",
1825 net_log_, callback2.callback()));
1826 QuicChromiumClientSession* session2 =
1827 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1829 session2->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1830 // Need to spin the loop now to ensure that
1831 // QuicStreamFactory::OnSessionClosed() runs.
1832 base::RunLoop run_loop2;
1833 run_loop2.RunUntilIdle();
1834 EXPECT_EQ(2,
1835 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
1836 EXPECT_TRUE(
1837 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1838 EXPECT_EQ(
1839 QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE,
1840 factory_.QuicDisabledReason(host_port_pair_.port()));
1842 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1843 EXPECT_TRUE(stream.get());
1844 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1845 EXPECT_TRUE(stream2.get());
1846 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1847 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1848 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1849 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1852 TEST_P(QuicStreamFactoryTest, TimeoutsWithOpenStreamsTwoOfTwo) {
1853 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1854 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1855 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1856 QuicStreamFactoryPeer::SetThresholdTimeoutsWithOpenStreams(&factory_, 2);
1857 EXPECT_FALSE(
1858 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1859 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1860 &factory_, host_port_pair_.port()));
1862 MockRead reads[] = {
1863 MockRead(ASYNC, OK, 0) // EOF
1865 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1866 socket_factory_.AddSocketDataProvider(&socket_data);
1867 socket_data.StopAfter(1);
1869 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1870 socket_factory_.AddSocketDataProvider(&socket_data2);
1871 socket_data2.StopAfter(1);
1873 HostPortPair server2("mail.example.org", kDefaultServerPort);
1875 crypto_client_stream_factory_.set_handshake_mode(
1876 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1877 host_resolver_.set_synchronous_mode(true);
1878 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1879 "192.168.0.1", "");
1880 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1882 QuicStreamRequest request(&factory_);
1883 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1884 /*cert_verify_flags=*/0, host_port_pair_.host(),
1885 "GET", net_log_, callback_.callback()));
1887 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1888 &factory_, host_port_pair_, is_https_);
1890 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1891 EXPECT_TRUE(stream.get());
1892 HttpRequestInfo request_info;
1893 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1894 net_log_, CompletionCallback()));
1896 DVLOG(1)
1897 << "Created 1st session and initialized a stream. Now trigger timeout";
1898 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
1899 // Need to spin the loop now to ensure that
1900 // QuicStreamFactory::OnSessionClosed() runs.
1901 base::RunLoop run_loop;
1902 run_loop.RunUntilIdle();
1904 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
1905 EXPECT_FALSE(
1906 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1908 // Test two-in-a-row timeouts with open streams.
1909 DVLOG(1) << "Create 2nd session and timeout with open stream";
1910 TestCompletionCallback callback2;
1911 QuicStreamRequest request2(&factory_);
1912 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1913 /*cert_verify_flags=*/0, server2.host(), "GET",
1914 net_log_, callback2.callback()));
1915 QuicChromiumClientSession* session2 =
1916 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1918 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1919 EXPECT_TRUE(stream2.get());
1920 EXPECT_EQ(OK, stream2->InitializeStream(&request_info, DEFAULT_PRIORITY,
1921 net_log_, CompletionCallback()));
1923 session2->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
1924 // Need to spin the loop now to ensure that
1925 // QuicStreamFactory::OnSessionClosed() runs.
1926 base::RunLoop run_loop2;
1927 run_loop2.RunUntilIdle();
1928 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
1929 EXPECT_TRUE(
1930 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1931 EXPECT_EQ(QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS,
1932 factory_.QuicDisabledReason(host_port_pair_.port()));
1934 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1935 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1936 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1937 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1940 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfThree) {
1941 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1942 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1943 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1944 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
1945 EXPECT_FALSE(
1946 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1947 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1948 &factory_, host_port_pair_.port()));
1950 MockRead reads[] = {
1951 MockRead(ASYNC, OK, 0) // EOF
1953 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1954 socket_factory_.AddSocketDataProvider(&socket_data);
1955 socket_data.StopAfter(1);
1957 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1958 socket_factory_.AddSocketDataProvider(&socket_data2);
1959 socket_data2.StopAfter(1);
1961 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
1962 socket_factory_.AddSocketDataProvider(&socket_data3);
1963 socket_data3.StopAfter(1);
1965 HostPortPair server2("mail.example.org", kDefaultServerPort);
1966 HostPortPair server3("docs.example.org", kDefaultServerPort);
1968 crypto_client_stream_factory_.set_handshake_mode(
1969 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1970 host_resolver_.set_synchronous_mode(true);
1971 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1972 "192.168.0.1", "");
1973 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1974 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
1976 // Test first and third out of three public reset post handshakes.
1977 QuicStreamRequest request(&factory_);
1978 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1979 /*cert_verify_flags=*/0, host_port_pair_.host(),
1980 "GET", net_log_, callback_.callback()));
1982 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1983 &factory_, host_port_pair_, is_https_);
1985 DVLOG(1) << "Created 1st session. Now trigger public reset post handshake";
1986 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1987 // Need to spin the loop now to ensure that
1988 // QuicStreamFactory::OnSessionClosed() runs.
1989 base::RunLoop run_loop;
1990 run_loop.RunUntilIdle();
1992 EXPECT_EQ(1,
1993 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
1994 EXPECT_FALSE(
1995 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1997 DVLOG(1) << "Create 2nd session without disable trigger";
1998 TestCompletionCallback callback2;
1999 QuicStreamRequest request2(&factory_);
2000 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2001 /*cert_verify_flags=*/0, server2.host(), "GET",
2002 net_log_, callback2.callback()));
2003 QuicChromiumClientSession* session2 =
2004 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2006 session2->connection()->CloseConnection(QUIC_NO_ERROR, false);
2007 // Need to spin the loop now to ensure that
2008 // QuicStreamFactory::OnSessionClosed() runs.
2009 base::RunLoop run_loop2;
2010 run_loop2.RunUntilIdle();
2011 EXPECT_EQ(1,
2012 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2013 EXPECT_FALSE(
2014 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2016 DVLOG(1) << "Create 3rd session with public reset post handshake,"
2017 << " will disable QUIC";
2018 TestCompletionCallback callback3;
2019 QuicStreamRequest request3(&factory_);
2020 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2021 /*cert_verify_flags=*/0, server3.host(), "GET",
2022 net_log_, callback3.callback()));
2023 QuicChromiumClientSession* session3 =
2024 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2026 session3->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
2027 // Need to spin the loop now to ensure that
2028 // QuicStreamFactory::OnSessionClosed() runs.
2029 base::RunLoop run_loop3;
2030 run_loop3.RunUntilIdle();
2031 EXPECT_EQ(2,
2032 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2033 EXPECT_TRUE(
2034 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2035 EXPECT_EQ(
2036 QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE,
2037 factory_.QuicDisabledReason(host_port_pair_.port()));
2039 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2040 EXPECT_TRUE(stream.get());
2041 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2042 EXPECT_TRUE(stream2.get());
2043 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2044 EXPECT_TRUE(stream3.get());
2046 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2047 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2048 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2049 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2050 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2051 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2054 TEST_P(QuicStreamFactoryTest, TimeoutsWithOpenStreamsTwoOfThree) {
2055 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
2056 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
2057 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
2058 QuicStreamFactoryPeer::SetThresholdTimeoutsWithOpenStreams(&factory_, 2);
2059 EXPECT_FALSE(
2060 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2061 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
2062 &factory_, host_port_pair_.port()));
2064 MockRead reads[] = {
2065 MockRead(ASYNC, OK, 0) // EOF
2067 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
2068 socket_factory_.AddSocketDataProvider(&socket_data);
2069 socket_data.StopAfter(1);
2071 // DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
2072 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
2073 socket_factory_.AddSocketDataProvider(&socket_data2);
2074 socket_data2.StopAfter(1);
2076 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
2077 socket_factory_.AddSocketDataProvider(&socket_data3);
2078 socket_data3.StopAfter(1);
2080 HostPortPair server2("mail.example.org", kDefaultServerPort);
2081 HostPortPair server3("docs.example.org", kDefaultServerPort);
2083 crypto_client_stream_factory_.set_handshake_mode(
2084 MockCryptoClientStream::CONFIRM_HANDSHAKE);
2085 host_resolver_.set_synchronous_mode(true);
2086 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
2087 "192.168.0.1", "");
2088 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
2089 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
2091 // Test first and third out of three timeouts with open streams.
2092 QuicStreamRequest request(&factory_);
2093 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
2094 /*cert_verify_flags=*/0, host_port_pair_.host(),
2095 "GET", net_log_, callback_.callback()));
2097 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
2098 &factory_, host_port_pair_, is_https_);
2100 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2101 EXPECT_TRUE(stream.get());
2102 HttpRequestInfo request_info;
2103 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2104 net_log_, CompletionCallback()));
2106 DVLOG(1)
2107 << "Created 1st session and initialized a stream. Now trigger timeout";
2108 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2109 // Need to spin the loop now to ensure that
2110 // QuicStreamFactory::OnSessionClosed() runs.
2111 base::RunLoop run_loop;
2112 run_loop.RunUntilIdle();
2114 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2115 EXPECT_FALSE(
2116 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2118 // Test two-in-a-row timeouts with open streams.
2119 DVLOG(1) << "Create 2nd session without timeout";
2120 TestCompletionCallback callback2;
2121 QuicStreamRequest request2(&factory_);
2122 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2123 /*cert_verify_flags=*/0, server2.host(), "GET",
2124 net_log_, callback2.callback()));
2125 QuicChromiumClientSession* session2 =
2126 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2128 session2->connection()->CloseConnection(QUIC_NO_ERROR, true);
2129 // Need to spin the loop now to ensure that
2130 // QuicStreamFactory::OnSessionClosed() runs.
2131 base::RunLoop run_loop2;
2132 run_loop2.RunUntilIdle();
2133 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2134 EXPECT_FALSE(
2135 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2137 DVLOG(1) << "Create 3rd session with timeout with open streams,"
2138 << " will disable QUIC";
2140 TestCompletionCallback callback3;
2141 QuicStreamRequest request3(&factory_);
2142 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2143 /*cert_verify_flags=*/0, server3.host(), "GET",
2144 net_log_, callback3.callback()));
2145 QuicChromiumClientSession* session3 =
2146 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2148 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2149 EXPECT_TRUE(stream3.get());
2150 EXPECT_EQ(OK, stream3->InitializeStream(&request_info, DEFAULT_PRIORITY,
2151 net_log_, CompletionCallback()));
2152 session3->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2153 // Need to spin the loop now to ensure that
2154 // QuicStreamFactory::OnSessionClosed() runs.
2155 base::RunLoop run_loop3;
2156 run_loop3.RunUntilIdle();
2157 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2158 EXPECT_TRUE(
2159 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2160 EXPECT_EQ(QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS,
2161 factory_.QuicDisabledReason(host_port_pair_.port()));
2163 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2164 EXPECT_TRUE(stream2.get());
2165 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2166 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2167 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2168 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2169 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2170 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2173 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfFour) {
2174 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
2175 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
2176 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
2177 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
2178 EXPECT_FALSE(
2179 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2180 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
2181 &factory_, host_port_pair_.port()));
2183 MockRead reads[] = {
2184 MockRead(ASYNC, OK, 0) // EOF
2186 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
2187 socket_factory_.AddSocketDataProvider(&socket_data);
2188 socket_data.StopAfter(1);
2190 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
2191 socket_factory_.AddSocketDataProvider(&socket_data2);
2192 socket_data2.StopAfter(1);
2194 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
2195 socket_factory_.AddSocketDataProvider(&socket_data3);
2196 socket_data3.StopAfter(1);
2198 DeterministicSocketData socket_data4(reads, arraysize(reads), nullptr, 0);
2199 socket_factory_.AddSocketDataProvider(&socket_data4);
2200 socket_data4.StopAfter(1);
2202 HostPortPair server2("mail.example.org", kDefaultServerPort);
2203 HostPortPair server3("docs.example.org", kDefaultServerPort);
2204 HostPortPair server4("images.example.org", kDefaultServerPort);
2206 crypto_client_stream_factory_.set_handshake_mode(
2207 MockCryptoClientStream::CONFIRM_HANDSHAKE);
2208 host_resolver_.set_synchronous_mode(true);
2209 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
2210 "192.168.0.1", "");
2211 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
2212 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
2213 host_resolver_.rules()->AddIPLiteralRule(server4.host(), "192.168.0.1", "");
2215 // Test first and fourth out of four public reset post handshakes.
2216 QuicStreamRequest request(&factory_);
2217 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
2218 /*cert_verify_flags=*/0, host_port_pair_.host(),
2219 "GET", net_log_, callback_.callback()));
2221 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
2222 &factory_, host_port_pair_, is_https_);
2224 DVLOG(1) << "Created 1st session. Now trigger public reset post handshake";
2225 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
2226 // Need to spin the loop now to ensure that
2227 // QuicStreamFactory::OnSessionClosed() runs.
2228 base::RunLoop run_loop;
2229 run_loop.RunUntilIdle();
2231 EXPECT_EQ(1,
2232 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2233 EXPECT_FALSE(
2234 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2236 DVLOG(1) << "Create 2nd and 3rd sessions without disable trigger";
2237 TestCompletionCallback callback2;
2238 QuicStreamRequest request2(&factory_);
2239 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2240 /*cert_verify_flags=*/0, server2.host(), "GET",
2241 net_log_, callback2.callback()));
2242 QuicChromiumClientSession* session2 =
2243 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2245 session2->connection()->CloseConnection(QUIC_NO_ERROR, false);
2246 // Need to spin the loop now to ensure that
2247 // QuicStreamFactory::OnSessionClosed() runs.
2248 base::RunLoop run_loop2;
2249 run_loop2.RunUntilIdle();
2250 EXPECT_EQ(1,
2251 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2252 EXPECT_FALSE(
2253 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2255 TestCompletionCallback callback3;
2256 QuicStreamRequest request3(&factory_);
2257 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2258 /*cert_verify_flags=*/0, server3.host(), "GET",
2259 net_log_, callback3.callback()));
2260 QuicChromiumClientSession* session3 =
2261 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2263 session3->connection()->CloseConnection(QUIC_NO_ERROR, false);
2264 // Need to spin the loop now to ensure that
2265 // QuicStreamFactory::OnSessionClosed() runs.
2266 base::RunLoop run_loop3;
2267 run_loop3.RunUntilIdle();
2268 EXPECT_EQ(1,
2269 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2270 EXPECT_FALSE(
2271 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2273 DVLOG(1) << "Create 4rd session with public reset post handshake,"
2274 << " will not disable QUIC";
2275 TestCompletionCallback callback4;
2276 QuicStreamRequest request4(&factory_);
2277 EXPECT_EQ(OK, request4.Request(server4, is_https_, privacy_mode_,
2278 /*cert_verify_flags=*/0, server4.host(), "GET",
2279 net_log_, callback4.callback()));
2280 QuicChromiumClientSession* session4 =
2281 QuicStreamFactoryPeer::GetActiveSession(&factory_, server4, is_https_);
2283 session4->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
2284 // Need to spin the loop now to ensure that
2285 // QuicStreamFactory::OnSessionClosed() runs.
2286 base::RunLoop run_loop4;
2287 run_loop4.RunUntilIdle();
2288 EXPECT_EQ(1,
2289 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2290 EXPECT_FALSE(
2291 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2293 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2294 EXPECT_TRUE(stream.get());
2295 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2296 EXPECT_TRUE(stream2.get());
2297 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2298 EXPECT_TRUE(stream3.get());
2299 scoped_ptr<QuicHttpStream> stream4 = request4.ReleaseStream();
2300 EXPECT_TRUE(stream4.get());
2302 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2303 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2304 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2305 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2306 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2307 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2308 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
2309 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
2312 TEST_P(QuicStreamFactoryTest, TimeoutsWithOpenStreamsTwoOfFour) {
2313 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
2314 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
2315 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
2316 QuicStreamFactoryPeer::SetThresholdTimeoutsWithOpenStreams(&factory_, 2);
2317 EXPECT_FALSE(
2318 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2319 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
2320 &factory_, host_port_pair_.port()));
2322 MockRead reads[] = {
2323 MockRead(ASYNC, OK, 0) // EOF
2325 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
2326 socket_factory_.AddSocketDataProvider(&socket_data);
2327 socket_data.StopAfter(1);
2329 // DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
2330 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
2331 socket_factory_.AddSocketDataProvider(&socket_data2);
2332 socket_data2.StopAfter(1);
2334 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
2335 socket_factory_.AddSocketDataProvider(&socket_data3);
2336 socket_data3.StopAfter(1);
2338 DeterministicSocketData socket_data4(reads, arraysize(reads), nullptr, 0);
2339 socket_factory_.AddSocketDataProvider(&socket_data4);
2340 socket_data4.StopAfter(1);
2342 HostPortPair server2("mail.example.org", kDefaultServerPort);
2343 HostPortPair server3("docs.example.org", kDefaultServerPort);
2344 HostPortPair server4("images.example.org", kDefaultServerPort);
2346 crypto_client_stream_factory_.set_handshake_mode(
2347 MockCryptoClientStream::CONFIRM_HANDSHAKE);
2348 host_resolver_.set_synchronous_mode(true);
2349 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
2350 "192.168.0.1", "");
2351 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
2352 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
2353 host_resolver_.rules()->AddIPLiteralRule(server4.host(), "192.168.0.1", "");
2355 // Test first and fourth out of three timeouts with open streams.
2356 QuicStreamRequest request(&factory_);
2357 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
2358 /*cert_verify_flags=*/0, host_port_pair_.host(),
2359 "GET", net_log_, callback_.callback()));
2361 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
2362 &factory_, host_port_pair_, is_https_);
2364 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2365 EXPECT_TRUE(stream.get());
2366 HttpRequestInfo request_info;
2367 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2368 net_log_, CompletionCallback()));
2370 DVLOG(1)
2371 << "Created 1st session and initialized a stream. Now trigger timeout";
2372 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2373 // Need to spin the loop now to ensure that
2374 // QuicStreamFactory::OnSessionClosed() runs.
2375 base::RunLoop run_loop;
2376 run_loop.RunUntilIdle();
2378 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2379 EXPECT_FALSE(
2380 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2382 DVLOG(1) << "Create 2nd and 3rd sessions without timeout";
2383 TestCompletionCallback callback2;
2384 QuicStreamRequest request2(&factory_);
2385 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2386 /*cert_verify_flags=*/0, server2.host(), "GET",
2387 net_log_, callback2.callback()));
2388 QuicChromiumClientSession* session2 =
2389 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2391 session2->connection()->CloseConnection(QUIC_NO_ERROR, true);
2392 // Need to spin the loop now to ensure that
2393 // QuicStreamFactory::OnSessionClosed() runs.
2394 base::RunLoop run_loop2;
2395 run_loop2.RunUntilIdle();
2396 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2397 EXPECT_FALSE(
2398 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2400 TestCompletionCallback callback3;
2401 QuicStreamRequest request3(&factory_);
2402 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2403 /*cert_verify_flags=*/0, server3.host(), "GET",
2404 net_log_, callback3.callback()));
2405 QuicChromiumClientSession* session3 =
2406 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2408 session3->connection()->CloseConnection(QUIC_NO_ERROR, true);
2409 // Need to spin the loop now to ensure that
2410 // QuicStreamFactory::OnSessionClosed() runs.
2411 base::RunLoop run_loop3;
2412 run_loop3.RunUntilIdle();
2413 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2414 EXPECT_FALSE(
2415 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2417 DVLOG(1) << "Create 4th session with timeout with open streams,"
2418 << " will not disable QUIC";
2420 TestCompletionCallback callback4;
2421 QuicStreamRequest request4(&factory_);
2422 EXPECT_EQ(OK, request4.Request(server4, is_https_, privacy_mode_,
2423 /*cert_verify_flags=*/0, server4.host(), "GET",
2424 net_log_, callback4.callback()));
2425 QuicChromiumClientSession* session4 =
2426 QuicStreamFactoryPeer::GetActiveSession(&factory_, server4, is_https_);
2428 scoped_ptr<QuicHttpStream> stream4 = request4.ReleaseStream();
2429 EXPECT_TRUE(stream4.get());
2430 EXPECT_EQ(OK, stream4->InitializeStream(&request_info, DEFAULT_PRIORITY,
2431 net_log_, CompletionCallback()));
2432 session4->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2433 // Need to spin the loop now to ensure that
2434 // QuicStreamFactory::OnSessionClosed() runs.
2435 base::RunLoop run_loop4;
2436 run_loop4.RunUntilIdle();
2437 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2438 EXPECT_FALSE(
2439 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2441 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2442 EXPECT_TRUE(stream2.get());
2443 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2444 EXPECT_TRUE(stream3.get());
2445 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2446 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2447 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2448 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2449 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2450 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2451 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
2452 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
2455 } // namespace test
2456 } // namespace net