telemetry: Compute multiple first gesture scroll updates if there were multiple gestures
[chromium-blink-merge.git] / net / quic / quic_stream_factory_test.cc
blob407e24e22d8938544e8d6464452a76d3978d1ac5
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 nullptr,
230 channel_id_service_.get(),
231 &transport_security_state_,
232 &crypto_client_stream_factory_,
233 &random_generator_,
234 clock_,
235 kDefaultMaxPacketSize,
236 std::string(),
237 SupportedVersions(GetParam().version),
238 /*enable_port_selection=*/true,
239 /*always_require_handshake_confirmation=*/false,
240 /*disable_connection_pooling=*/false,
241 /*load_server_info_timeout_srtt_multiplier=*/0.0f,
242 /*enable_connection_racing=*/false,
243 /*enable_non_blocking_io=*/true,
244 /*disable_disk_cache=*/false,
245 /*prefer_aes=*/false,
246 /*max_number_of_lossy_connections=*/0,
247 /*packet_loss_threshold=*/1.0f,
248 /*max_disabled_reasons=*/3,
249 /*threshold_timeouts_with_open_streams=*/2,
250 /*threshold_pulic_resets_post_handshake=*/2,
251 /*receive_buffer_size=*/0,
252 QuicTagVector()),
253 host_port_pair_(kDefaultServerHostName, kDefaultServerPort),
254 is_https_(false),
255 privacy_mode_(PRIVACY_MODE_DISABLED) {
256 factory_.set_require_confirmation(false);
257 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
258 QuicStreamFactoryPeer::SetEnableConnectionRacing(
259 &factory_, GetParam().enable_connection_racing);
262 bool HasActiveSession(const HostPortPair& host_port_pair) {
263 return QuicStreamFactoryPeer::HasActiveSession(&factory_, host_port_pair,
264 /*is_https_=*/false);
267 scoped_ptr<QuicHttpStream> CreateFromSession(
268 const HostPortPair& host_port_pair) {
269 QuicChromiumClientSession* session =
270 QuicStreamFactoryPeer::GetActiveSession(&factory_, host_port_pair,
271 /*is_https=*/false);
272 return QuicStreamFactoryPeer::CreateFromSession(&factory_, session);
275 int GetSourcePortForNewSession(const HostPortPair& destination) {
276 return GetSourcePortForNewSessionInner(destination, false);
279 int GetSourcePortForNewSessionAndGoAway(
280 const HostPortPair& destination) {
281 return GetSourcePortForNewSessionInner(destination, true);
284 int GetSourcePortForNewSessionInner(const HostPortPair& destination,
285 bool goaway_received) {
286 // Should only be called if there is no active session for this destination.
287 EXPECT_FALSE(HasActiveSession(destination));
288 size_t socket_count = socket_factory_.udp_client_sockets().size();
290 MockRead reads[] = {
291 MockRead(ASYNC, OK, 0) // EOF
293 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
294 socket_data.StopAfter(1);
295 socket_factory_.AddSocketDataProvider(&socket_data);
297 QuicStreamRequest request(&factory_);
298 EXPECT_EQ(ERR_IO_PENDING,
299 request.Request(destination, is_https_, privacy_mode_,
300 /*cert_verify_flags=*/0, destination.host(),
301 "GET", net_log_, callback_.callback()));
303 EXPECT_EQ(OK, callback_.WaitForResult());
304 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
305 EXPECT_TRUE(stream.get());
306 stream.reset();
308 QuicChromiumClientSession* session =
309 QuicStreamFactoryPeer::GetActiveSession(&factory_, destination,
310 is_https_);
312 if (socket_count + 1 != socket_factory_.udp_client_sockets().size()) {
313 EXPECT_TRUE(false);
314 return 0;
317 IPEndPoint endpoint;
318 socket_factory_.
319 udp_client_sockets()[socket_count]->GetLocalAddress(&endpoint);
320 int port = endpoint.port();
321 if (goaway_received) {
322 QuicGoAwayFrame goaway(QUIC_NO_ERROR, 1, "");
323 session->OnGoAway(goaway);
326 factory_.OnSessionClosed(session);
327 EXPECT_FALSE(HasActiveSession(destination));
328 EXPECT_TRUE(socket_data.AllReadDataConsumed());
329 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
330 return port;
333 scoped_ptr<QuicEncryptedPacket> ConstructRstPacket() {
334 QuicStreamId stream_id = kClientDataStreamId1;
335 return maker_.MakeRstPacket(
336 1, true, stream_id,
337 AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam().version));
340 static ProofVerifyDetailsChromium DefaultProofVerifyDetails() {
341 // Load a certificate that is valid for www.example.org, mail.example.org,
342 // and mail.example.com.
343 scoped_refptr<X509Certificate> test_cert(
344 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"));
345 EXPECT_TRUE(test_cert.get());
346 ProofVerifyDetailsChromium verify_details;
347 verify_details.cert_verify_result.verified_cert = test_cert;
348 verify_details.cert_verify_result.is_issued_by_known_root = true;
349 return verify_details;
352 MockQuicServerInfoFactory quic_server_info_factory_;
353 MockHostResolver host_resolver_;
354 DeterministicMockClientSocketFactory socket_factory_;
355 MockCryptoClientStreamFactory crypto_client_stream_factory_;
356 MockRandom random_generator_;
357 MockClock* clock_; // Owned by factory_.
358 scoped_refptr<TestTaskRunner> runner_;
359 QuicTestPacketMaker maker_;
360 scoped_ptr<CertVerifier> cert_verifier_;
361 scoped_ptr<ChannelIDService> channel_id_service_;
362 TransportSecurityState transport_security_state_;
363 QuicStreamFactory factory_;
364 HostPortPair host_port_pair_;
365 bool is_https_;
366 PrivacyMode privacy_mode_;
367 BoundNetLog net_log_;
368 TestCompletionCallback callback_;
371 INSTANTIATE_TEST_CASE_P(Version,
372 QuicStreamFactoryTest,
373 ::testing::ValuesIn(GetTestParams()));
375 TEST_P(QuicStreamFactoryTest, Create) {
376 MockRead reads[] = {
377 MockRead(ASYNC, OK, 0) // EOF
379 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
380 socket_factory_.AddSocketDataProvider(&socket_data);
381 socket_data.StopAfter(1);
383 QuicStreamRequest request(&factory_);
384 EXPECT_EQ(ERR_IO_PENDING,
385 request.Request(host_port_pair_, is_https_, privacy_mode_,
386 /*cert_verify_flags=*/0, host_port_pair_.host(),
387 "GET", net_log_, callback_.callback()));
389 EXPECT_EQ(OK, callback_.WaitForResult());
390 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
391 EXPECT_TRUE(stream.get());
393 // Will reset stream 3.
394 stream = CreateFromSession(host_port_pair_);
395 EXPECT_TRUE(stream.get());
397 // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result
398 // in streams on different sessions.
399 QuicStreamRequest request2(&factory_);
400 EXPECT_EQ(OK,
401 request2.Request(host_port_pair_, is_https_, privacy_mode_,
402 /*cert_verify_flags=*/0, host_port_pair_.host(),
403 "GET", net_log_, callback_.callback()));
404 stream = request2.ReleaseStream(); // Will reset stream 5.
405 stream.reset(); // Will reset stream 7.
407 EXPECT_TRUE(socket_data.AllReadDataConsumed());
408 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
411 TEST_P(QuicStreamFactoryTest, CreateZeroRtt) {
412 MockRead reads[] = {
413 MockRead(ASYNC, OK, 0) // EOF
415 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
416 socket_factory_.AddSocketDataProvider(&socket_data);
417 socket_data.StopAfter(1);
419 crypto_client_stream_factory_.set_handshake_mode(
420 MockCryptoClientStream::ZERO_RTT);
421 host_resolver_.set_synchronous_mode(true);
422 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
423 "192.168.0.1", "");
425 QuicStreamRequest request(&factory_);
426 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
427 /*cert_verify_flags=*/0, host_port_pair_.host(),
428 "GET", net_log_, callback_.callback()));
430 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
431 EXPECT_TRUE(stream.get());
432 EXPECT_TRUE(socket_data.AllReadDataConsumed());
433 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
436 TEST_P(QuicStreamFactoryTest, CreateZeroRttPost) {
437 MockRead reads[] = {
438 MockRead(ASYNC, OK, 0) // EOF
440 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
441 socket_factory_.AddSocketDataProvider(&socket_data);
442 socket_data.StopAfter(1);
444 crypto_client_stream_factory_.set_handshake_mode(
445 MockCryptoClientStream::ZERO_RTT);
446 host_resolver_.set_synchronous_mode(true);
447 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
448 "192.168.0.1", "");
450 QuicStreamRequest request(&factory_);
451 // Posts require handshake confirmation, so this will return asynchronously.
452 EXPECT_EQ(ERR_IO_PENDING,
453 request.Request(host_port_pair_, is_https_, privacy_mode_,
454 /*cert_verify_flags=*/0, host_port_pair_.host(),
455 "POST", net_log_, callback_.callback()));
457 // Confirm the handshake and verify that the stream is created.
458 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
459 QuicSession::HANDSHAKE_CONFIRMED);
461 EXPECT_EQ(OK, callback_.WaitForResult());
462 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
463 EXPECT_TRUE(stream.get());
464 EXPECT_TRUE(socket_data.AllReadDataConsumed());
465 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
468 TEST_P(QuicStreamFactoryTest, NoZeroRttForDifferentHost) {
469 MockRead reads[] = {
470 MockRead(ASYNC, OK, 0),
472 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
473 socket_factory_.AddSocketDataProvider(&socket_data);
474 socket_data.StopAfter(1);
476 crypto_client_stream_factory_.set_handshake_mode(
477 MockCryptoClientStream::ZERO_RTT);
478 host_resolver_.set_synchronous_mode(true);
479 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
480 "192.168.0.1", "");
482 QuicStreamRequest request(&factory_);
483 int rv = request.Request(
484 host_port_pair_, is_https_, privacy_mode_, /*cert_verify_flags=*/0,
485 "different.host.example.com", "GET", net_log_, callback_.callback());
486 // If server and origin have different hostnames, then handshake confirmation
487 // should be required, so Request will return asynchronously.
488 EXPECT_EQ(ERR_IO_PENDING, rv);
489 // Confirm handshake.
490 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
491 QuicSession::HANDSHAKE_CONFIRMED);
492 EXPECT_EQ(OK, callback_.WaitForResult());
494 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
495 EXPECT_TRUE(stream.get());
496 EXPECT_TRUE(socket_data.AllReadDataConsumed());
497 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
500 TEST_P(QuicStreamFactoryTest, CreateHttpVsHttps) {
501 MockRead reads[] = {
502 MockRead(ASYNC, OK, 0) // EOF
504 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
505 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
506 socket_factory_.AddSocketDataProvider(&socket_data1);
507 socket_factory_.AddSocketDataProvider(&socket_data2);
508 socket_data1.StopAfter(1);
509 socket_data2.StopAfter(1);
511 QuicStreamRequest request(&factory_);
512 EXPECT_EQ(ERR_IO_PENDING,
513 request.Request(host_port_pair_, is_https_, privacy_mode_,
514 /*cert_verify_flags=*/0, host_port_pair_.host(),
515 "GET", net_log_, callback_.callback()));
517 EXPECT_EQ(OK, callback_.WaitForResult());
518 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
519 EXPECT_TRUE(stream.get());
521 QuicStreamRequest request2(&factory_);
522 EXPECT_EQ(ERR_IO_PENDING,
523 request2.Request(host_port_pair_, !is_https_, privacy_mode_,
524 /*cert_verify_flags=*/0, host_port_pair_.host(),
525 "GET", net_log_, callback_.callback()));
526 EXPECT_EQ(OK, callback_.WaitForResult());
527 stream = request2.ReleaseStream();
528 EXPECT_TRUE(stream.get());
529 stream.reset();
531 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
532 &factory_, host_port_pair_, is_https_),
533 QuicStreamFactoryPeer::GetActiveSession(
534 &factory_, host_port_pair_, !is_https_));
536 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
537 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
538 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
539 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
542 TEST_P(QuicStreamFactoryTest, Pooling) {
543 MockRead reads[] = {
544 MockRead(ASYNC, OK, 0) // EOF
546 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
547 socket_factory_.AddSocketDataProvider(&socket_data);
548 socket_data.StopAfter(1);
550 HostPortPair server2("mail.google.com", kDefaultServerPort);
551 host_resolver_.set_synchronous_mode(true);
552 host_resolver_.rules()->AddIPLiteralRule(
553 kDefaultServerHostName, "192.168.0.1", "");
554 host_resolver_.rules()->AddIPLiteralRule(
555 "mail.google.com", "192.168.0.1", "");
557 QuicStreamRequest request(&factory_);
558 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
559 /*cert_verify_flags=*/0, host_port_pair_.host(),
560 "GET", net_log_, callback_.callback()));
561 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
562 EXPECT_TRUE(stream.get());
564 TestCompletionCallback callback;
565 QuicStreamRequest request2(&factory_);
566 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
567 /*cert_verify_flags=*/0, server2.host(), "GET",
568 net_log_, callback.callback()));
569 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
570 EXPECT_TRUE(stream2.get());
572 EXPECT_EQ(
573 QuicStreamFactoryPeer::GetActiveSession(
574 &factory_, host_port_pair_, is_https_),
575 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_));
577 EXPECT_TRUE(socket_data.AllReadDataConsumed());
578 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
581 TEST_P(QuicStreamFactoryTest, NoPoolingIfDisabled) {
582 MockRead reads[] = {
583 MockRead(ASYNC, OK, 0) // EOF
585 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
586 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
587 socket_factory_.AddSocketDataProvider(&socket_data1);
588 socket_factory_.AddSocketDataProvider(&socket_data2);
589 socket_data1.StopAfter(1);
590 socket_data2.StopAfter(1);
592 HostPortPair server2("mail.google.com", kDefaultServerPort);
593 host_resolver_.set_synchronous_mode(true);
594 host_resolver_.rules()->AddIPLiteralRule(
595 kDefaultServerHostName, "192.168.0.1", "");
596 host_resolver_.rules()->AddIPLiteralRule(
597 "mail.google.com", "192.168.0.1", "");
599 // Disable connection pooling.
600 QuicStreamFactoryPeer::DisableConnectionPooling(&factory_);
602 QuicStreamRequest request(&factory_);
603 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
604 /*cert_verify_flags=*/0, host_port_pair_.host(),
605 "GET", net_log_, callback_.callback()));
606 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
607 EXPECT_TRUE(stream.get());
609 TestCompletionCallback callback;
610 QuicStreamRequest request2(&factory_);
611 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
612 /*cert_verify_flags=*/0, server2.host(), "GET",
613 net_log_, callback.callback()));
614 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
615 EXPECT_TRUE(stream2.get());
617 EXPECT_NE(
618 QuicStreamFactoryPeer::GetActiveSession(
619 &factory_, host_port_pair_, is_https_),
620 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_));
622 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
623 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
624 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
625 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
628 TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) {
629 MockRead reads[] = {
630 MockRead(ASYNC, OK, 0) // EOF
632 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
633 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
634 socket_factory_.AddSocketDataProvider(&socket_data1);
635 socket_factory_.AddSocketDataProvider(&socket_data2);
636 socket_data1.StopAfter(1);
637 socket_data2.StopAfter(1);
639 HostPortPair server2("mail.google.com", kDefaultServerPort);
640 host_resolver_.set_synchronous_mode(true);
641 host_resolver_.rules()->AddIPLiteralRule(
642 kDefaultServerHostName, "192.168.0.1", "");
643 host_resolver_.rules()->AddIPLiteralRule(
644 "mail.google.com", "192.168.0.1", "");
646 QuicStreamRequest request(&factory_);
647 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
648 /*cert_verify_flags=*/0, host_port_pair_.host(),
649 "GET", net_log_, callback_.callback()));
650 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
651 EXPECT_TRUE(stream.get());
653 TestCompletionCallback callback;
654 QuicStreamRequest request2(&factory_);
655 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
656 /*cert_verify_flags=*/0, server2.host(), "GET",
657 net_log_, callback.callback()));
658 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
659 EXPECT_TRUE(stream2.get());
661 factory_.OnSessionGoingAway(QuicStreamFactoryPeer::GetActiveSession(
662 &factory_, host_port_pair_, is_https_));
663 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
664 &factory_, host_port_pair_, is_https_));
665 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
666 &factory_, server2, is_https_));
668 TestCompletionCallback callback3;
669 QuicStreamRequest request3(&factory_);
670 EXPECT_EQ(OK, request3.Request(server2, is_https_, privacy_mode_,
671 /*cert_verify_flags=*/0, server2.host(), "GET",
672 net_log_, callback3.callback()));
673 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
674 EXPECT_TRUE(stream3.get());
676 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
677 &factory_, server2, is_https_));
679 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
680 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
681 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
682 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
685 TEST_P(QuicStreamFactoryTest, HttpsPooling) {
686 MockRead reads[] = {
687 MockRead(ASYNC, OK, 0) // EOF
689 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
690 socket_factory_.AddSocketDataProvider(&socket_data);
691 socket_data.StopAfter(1);
693 HostPortPair server1("www.example.org", 443);
694 HostPortPair server2("mail.example.org", 443);
696 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
697 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
699 host_resolver_.set_synchronous_mode(true);
700 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
701 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
703 QuicStreamRequest request(&factory_);
704 is_https_ = true;
705 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
706 /*cert_verify_flags=*/0, server1.host(), "GET",
707 net_log_, callback_.callback()));
708 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
709 EXPECT_TRUE(stream.get());
711 TestCompletionCallback callback;
712 QuicStreamRequest request2(&factory_);
713 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
714 /*cert_verify_flags=*/0, server2.host(), "GET",
715 net_log_, callback_.callback()));
716 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
717 EXPECT_TRUE(stream2.get());
719 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
720 &factory_, server1, is_https_),
721 QuicStreamFactoryPeer::GetActiveSession(
722 &factory_, server2, is_https_));
724 EXPECT_TRUE(socket_data.AllReadDataConsumed());
725 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
728 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingIfDisabled) {
729 MockRead reads[] = {
730 MockRead(ASYNC, OK, 0) // EOF
732 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
733 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
734 socket_factory_.AddSocketDataProvider(&socket_data1);
735 socket_factory_.AddSocketDataProvider(&socket_data2);
736 socket_data1.StopAfter(1);
737 socket_data2.StopAfter(1);
739 HostPortPair server1("www.example.org", 443);
740 HostPortPair server2("mail.example.org", 443);
742 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
743 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
745 host_resolver_.set_synchronous_mode(true);
746 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
747 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
749 // Disable connection pooling.
750 QuicStreamFactoryPeer::DisableConnectionPooling(&factory_);
752 QuicStreamRequest request(&factory_);
753 is_https_ = true;
754 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
755 /*cert_verify_flags=*/0, server1.host(), "GET",
756 net_log_, callback_.callback()));
757 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
758 EXPECT_TRUE(stream.get());
760 TestCompletionCallback callback;
761 QuicStreamRequest request2(&factory_);
762 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
763 /*cert_verify_flags=*/0, server2.host(), "GET",
764 net_log_, callback_.callback()));
765 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
766 EXPECT_TRUE(stream2.get());
768 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
769 &factory_, server1, is_https_),
770 QuicStreamFactoryPeer::GetActiveSession(
771 &factory_, server2, is_https_));
773 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
774 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
775 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
776 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
779 class QuicAlternativeServiceCertificateValidationPooling
780 : public QuicStreamFactoryTest {
781 public:
782 void Run(bool valid) {
783 MockRead reads[] = {
784 MockRead(ASYNC, OK, 0) // EOF
786 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
787 socket_factory_.AddSocketDataProvider(&socket_data1);
788 socket_data1.StopAfter(1);
790 HostPortPair server1("www.example.org", 443);
791 HostPortPair server2("mail.example.org", 443);
793 std::string origin_host(valid ? "mail.example.org" : "invalid.example.org");
794 HostPortPair alternative("www.example.org", 443);
796 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
797 bool common_name_fallback_used;
798 EXPECT_EQ(valid,
799 verify_details.cert_verify_result.verified_cert->VerifyNameMatch(
800 origin_host, &common_name_fallback_used));
801 EXPECT_TRUE(
802 verify_details.cert_verify_result.verified_cert->VerifyNameMatch(
803 alternative.host(), &common_name_fallback_used));
804 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
806 host_resolver_.set_synchronous_mode(true);
807 host_resolver_.rules()->AddIPLiteralRule(alternative.host(), "192.168.0.1",
808 "");
810 // Open first stream to alternative.
811 QuicStreamRequest request1(&factory_);
812 is_https_ = true;
813 EXPECT_EQ(OK, request1.Request(alternative, is_https_, privacy_mode_,
814 /*cert_verify_flags=*/0, alternative.host(),
815 "GET", net_log_, callback_.callback()));
816 scoped_ptr<QuicHttpStream> stream1 = request1.ReleaseStream();
817 EXPECT_TRUE(stream1.get());
819 QuicStreamRequest request2(&factory_);
820 int rv = request2.Request(alternative, is_https_, privacy_mode_,
821 /*cert_verify_flags=*/0, origin_host, "GET",
822 net_log_, callback_.callback());
823 if (valid) {
824 // Alternative service of origin to |alternative| should pool to session
825 // of |stream1| even if origin is different. Since only one
826 // SocketDataProvider is set up, the second request succeeding means that
827 // it pooled to the session opened by the first one.
828 EXPECT_EQ(OK, rv);
829 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
830 EXPECT_TRUE(stream2.get());
831 } else {
832 EXPECT_EQ(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN, rv);
835 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
836 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
840 INSTANTIATE_TEST_CASE_P(Version,
841 QuicAlternativeServiceCertificateValidationPooling,
842 ::testing::ValuesIn(GetTestParams()));
844 TEST_P(QuicAlternativeServiceCertificateValidationPooling, Valid) {
845 Run(true);
848 TEST_P(QuicAlternativeServiceCertificateValidationPooling, Invalid) {
849 Run(false);
852 TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) {
853 MockRead reads[] = {
854 MockRead(ASYNC, OK, 0) // EOF
856 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
857 socket_factory_.AddSocketDataProvider(&socket_data);
858 socket_data.StopAfter(1);
860 HostPortPair server1("www.example.org", 443);
861 HostPortPair server2("mail.example.org", 443);
862 uint8 primary_pin = 1;
863 uint8 backup_pin = 2;
864 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
865 backup_pin);
867 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
868 verify_details.cert_verify_result.public_key_hashes.push_back(
869 test::GetTestHashValue(primary_pin));
870 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
872 host_resolver_.set_synchronous_mode(true);
873 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
874 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
876 QuicStreamRequest request(&factory_);
877 is_https_ = true;
878 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
879 /*cert_verify_flags=*/0, server1.host(), "GET",
880 net_log_, callback_.callback()));
881 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
882 EXPECT_TRUE(stream.get());
884 TestCompletionCallback callback;
885 QuicStreamRequest request2(&factory_);
886 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
887 /*cert_verify_flags=*/0, server2.host(), "GET",
888 net_log_, callback_.callback()));
889 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
890 EXPECT_TRUE(stream2.get());
892 EXPECT_EQ(QuicStreamFactoryPeer::GetActiveSession(
893 &factory_, server1, is_https_),
894 QuicStreamFactoryPeer::GetActiveSession(
895 &factory_, server2, is_https_));
897 EXPECT_TRUE(socket_data.AllReadDataConsumed());
898 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
901 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithMatchingPinsIfDisabled) {
902 MockRead reads[] = {
903 MockRead(ASYNC, OK, 0) // EOF
905 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
906 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
907 socket_factory_.AddSocketDataProvider(&socket_data1);
908 socket_factory_.AddSocketDataProvider(&socket_data2);
909 socket_data1.StopAfter(1);
910 socket_data2.StopAfter(1);
912 HostPortPair server1("www.example.org", 443);
913 HostPortPair server2("mail.example.org", 443);
914 uint8 primary_pin = 1;
915 uint8 backup_pin = 2;
916 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
917 backup_pin);
919 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
920 verify_details.cert_verify_result.public_key_hashes.push_back(
921 test::GetTestHashValue(primary_pin));
922 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
924 host_resolver_.set_synchronous_mode(true);
925 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
926 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
928 // Disable connection pooling.
929 QuicStreamFactoryPeer::DisableConnectionPooling(&factory_);
931 QuicStreamRequest request(&factory_);
932 is_https_ = true;
933 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
934 /*cert_verify_flags=*/0, server1.host(), "GET",
935 net_log_, callback_.callback()));
936 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
937 EXPECT_TRUE(stream.get());
939 TestCompletionCallback callback;
940 QuicStreamRequest request2(&factory_);
941 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
942 /*cert_verify_flags=*/0, server2.host(), "GET",
943 net_log_, callback_.callback()));
944 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
945 EXPECT_TRUE(stream2.get());
947 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
948 &factory_, server1, is_https_),
949 QuicStreamFactoryPeer::GetActiveSession(
950 &factory_, server2, is_https_));
952 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
953 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
954 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
955 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
958 TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) {
959 MockRead reads[] = {
960 MockRead(ASYNC, OK, 0) // EOF
962 DeterministicSocketData socket_data1(reads, arraysize(reads), nullptr, 0);
963 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
964 socket_factory_.AddSocketDataProvider(&socket_data1);
965 socket_factory_.AddSocketDataProvider(&socket_data2);
966 socket_data1.StopAfter(1);
967 socket_data2.StopAfter(1);
969 HostPortPair server1("www.example.org", 443);
970 HostPortPair server2("mail.example.org", 443);
971 uint8 primary_pin = 1;
972 uint8 backup_pin = 2;
973 uint8 bad_pin = 3;
974 test::AddPin(&transport_security_state_, "mail.example.org", primary_pin,
975 backup_pin);
977 ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails();
978 verify_details1.cert_verify_result.public_key_hashes.push_back(
979 test::GetTestHashValue(bad_pin));
980 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1);
982 ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails();
983 verify_details2.cert_verify_result.public_key_hashes.push_back(
984 test::GetTestHashValue(primary_pin));
985 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2);
987 host_resolver_.set_synchronous_mode(true);
988 host_resolver_.rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", "");
989 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
991 QuicStreamRequest request(&factory_);
992 is_https_ = true;
993 EXPECT_EQ(OK, request.Request(server1, is_https_, privacy_mode_,
994 /*cert_verify_flags=*/0, server1.host(), "GET",
995 net_log_, callback_.callback()));
996 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
997 EXPECT_TRUE(stream.get());
999 TestCompletionCallback callback;
1000 QuicStreamRequest request2(&factory_);
1001 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1002 /*cert_verify_flags=*/0, server2.host(), "GET",
1003 net_log_, callback_.callback()));
1004 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1005 EXPECT_TRUE(stream2.get());
1007 EXPECT_NE(QuicStreamFactoryPeer::GetActiveSession(
1008 &factory_, server1, is_https_),
1009 QuicStreamFactoryPeer::GetActiveSession(
1010 &factory_, server2, is_https_));
1012 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
1013 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
1014 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1015 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1018 TEST_P(QuicStreamFactoryTest, Goaway) {
1019 MockRead reads[] = {
1020 MockRead(ASYNC, OK, 0) // EOF
1022 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1023 socket_data.StopAfter(1);
1024 socket_factory_.AddSocketDataProvider(&socket_data);
1025 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1026 socket_data2.StopAfter(1);
1027 socket_factory_.AddSocketDataProvider(&socket_data2);
1029 QuicStreamRequest request(&factory_);
1030 EXPECT_EQ(ERR_IO_PENDING,
1031 request.Request(host_port_pair_, is_https_, privacy_mode_,
1032 /*cert_verify_flags=*/0, host_port_pair_.host(),
1033 "GET", net_log_, callback_.callback()));
1035 EXPECT_EQ(OK, callback_.WaitForResult());
1036 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1037 EXPECT_TRUE(stream.get());
1039 // Mark the session as going away. Ensure that while it is still alive
1040 // that it is no longer active.
1041 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1042 &factory_, host_port_pair_, is_https_);
1043 factory_.OnSessionGoingAway(session);
1044 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
1045 EXPECT_FALSE(QuicStreamFactoryPeer::HasActiveSession(
1046 &factory_, host_port_pair_, is_https_));
1047 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1049 // Create a new request for the same destination and verify that a
1050 // new session is created.
1051 QuicStreamRequest request2(&factory_);
1052 EXPECT_EQ(ERR_IO_PENDING,
1053 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1054 /*cert_verify_flags=*/0, host_port_pair_.host(),
1055 "GET", net_log_, callback_.callback()));
1056 EXPECT_EQ(OK, callback_.WaitForResult());
1057 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1058 EXPECT_TRUE(stream2.get());
1060 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(&factory_,
1061 host_port_pair_,
1062 is_https_));
1063 EXPECT_NE(session,
1064 QuicStreamFactoryPeer::GetActiveSession(
1065 &factory_, host_port_pair_, is_https_));
1066 EXPECT_EQ(true, QuicStreamFactoryPeer::IsLiveSession(&factory_, session));
1068 stream2.reset();
1069 stream.reset();
1071 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1072 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1073 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1074 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1077 TEST_P(QuicStreamFactoryTest, MaxOpenStream) {
1078 MockRead reads[] = {
1079 MockRead(ASYNC, OK, 0) // EOF
1081 QuicStreamId stream_id = kClientDataStreamId1;
1082 scoped_ptr<QuicEncryptedPacket> rst(
1083 maker_.MakeRstPacket(1, true, stream_id, QUIC_STREAM_CANCELLED));
1084 MockWrite writes[] = {
1085 MockWrite(ASYNC, rst->data(), rst->length(), 1),
1087 DeterministicSocketData socket_data(reads, arraysize(reads),
1088 writes, arraysize(writes));
1089 socket_factory_.AddSocketDataProvider(&socket_data);
1090 socket_data.StopAfter(1);
1092 HttpRequestInfo request_info;
1093 std::vector<QuicHttpStream*> streams;
1094 // The MockCryptoClientStream sets max_open_streams to be
1095 // kDefaultMaxStreamsPerConnection / 2.
1096 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection / 2; i++) {
1097 QuicStreamRequest request(&factory_);
1098 int rv = request.Request(host_port_pair_, is_https_, privacy_mode_,
1099 /*cert_verify_flags=*/0, host_port_pair_.host(),
1100 "GET", net_log_, callback_.callback());
1101 if (i == 0) {
1102 EXPECT_EQ(ERR_IO_PENDING, rv);
1103 EXPECT_EQ(OK, callback_.WaitForResult());
1104 } else {
1105 EXPECT_EQ(OK, rv);
1107 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1108 EXPECT_TRUE(stream);
1109 EXPECT_EQ(OK, stream->InitializeStream(
1110 &request_info, DEFAULT_PRIORITY, net_log_, CompletionCallback()));
1111 streams.push_back(stream.release());
1114 QuicStreamRequest request(&factory_);
1115 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1116 /*cert_verify_flags=*/0, host_port_pair_.host(),
1117 "GET", net_log_, CompletionCallback()));
1118 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1119 EXPECT_TRUE(stream);
1120 EXPECT_EQ(ERR_IO_PENDING, stream->InitializeStream(
1121 &request_info, DEFAULT_PRIORITY, net_log_, callback_.callback()));
1123 // Close the first stream.
1124 streams.front()->Close(false);
1126 ASSERT_TRUE(callback_.have_result());
1128 EXPECT_EQ(OK, callback_.WaitForResult());
1130 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1131 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1132 STLDeleteElements(&streams);
1135 TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) {
1136 DeterministicSocketData socket_data(nullptr, 0, nullptr, 0);
1137 socket_factory_.AddSocketDataProvider(&socket_data);
1139 host_resolver_.rules()->AddSimulatedFailure(kDefaultServerHostName);
1141 QuicStreamRequest request(&factory_);
1142 EXPECT_EQ(ERR_IO_PENDING,
1143 request.Request(host_port_pair_, is_https_, privacy_mode_,
1144 /*cert_verify_flags=*/0, host_port_pair_.host(),
1145 "GET", net_log_, callback_.callback()));
1147 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult());
1149 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1150 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1153 TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) {
1154 MockConnect connect(SYNCHRONOUS, ERR_ADDRESS_IN_USE);
1155 DeterministicSocketData socket_data(nullptr, 0, nullptr, 0);
1156 socket_data.set_connect_data(connect);
1157 socket_factory_.AddSocketDataProvider(&socket_data);
1158 socket_data.StopAfter(1);
1160 QuicStreamRequest request(&factory_);
1161 EXPECT_EQ(ERR_IO_PENDING,
1162 request.Request(host_port_pair_, is_https_, privacy_mode_,
1163 /*cert_verify_flags=*/0, host_port_pair_.host(),
1164 "GET", net_log_, callback_.callback()));
1166 EXPECT_EQ(ERR_ADDRESS_IN_USE, callback_.WaitForResult());
1168 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1169 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1172 TEST_P(QuicStreamFactoryTest, CancelCreate) {
1173 MockRead reads[] = {
1174 MockRead(ASYNC, OK, 0) // EOF
1176 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1177 socket_factory_.AddSocketDataProvider(&socket_data);
1179 QuicStreamRequest request(&factory_);
1180 EXPECT_EQ(ERR_IO_PENDING,
1181 request.Request(host_port_pair_, is_https_, privacy_mode_,
1182 /*cert_verify_flags=*/0, host_port_pair_.host(),
1183 "GET", net_log_, callback_.callback()));
1186 socket_data.StopAfter(1);
1187 base::RunLoop run_loop;
1188 run_loop.RunUntilIdle();
1190 scoped_ptr<QuicHttpStream> stream(CreateFromSession(host_port_pair_));
1191 EXPECT_TRUE(stream.get());
1192 stream.reset();
1194 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1195 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1198 TEST_P(QuicStreamFactoryTest, CreateConsistentEphemeralPort) {
1199 // Sequentially connect to the default host, then another host, and then the
1200 // default host. Verify that the default host gets a consistent ephemeral
1201 // port, that is different from the other host's connection.
1203 std::string other_server_name = "other.google.com";
1204 EXPECT_NE(kDefaultServerHostName, other_server_name);
1205 HostPortPair host_port_pair2(other_server_name, kDefaultServerPort);
1207 int original_port = GetSourcePortForNewSession(host_port_pair_);
1208 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair2));
1209 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_));
1212 TEST_P(QuicStreamFactoryTest, GoAwayDisablesConsistentEphemeralPort) {
1213 // Get a session to the host using the port suggester.
1214 int original_port =
1215 GetSourcePortForNewSessionAndGoAway(host_port_pair_);
1216 // Verify that the port is different after the goaway.
1217 EXPECT_NE(original_port, GetSourcePortForNewSession(host_port_pair_));
1218 // Since the previous session did not goaway we should see the original port.
1219 EXPECT_EQ(original_port, GetSourcePortForNewSession(host_port_pair_));
1222 TEST_P(QuicStreamFactoryTest, CloseAllSessions) {
1223 MockRead reads[] = {
1224 MockRead(ASYNC, 0, 0) // EOF
1226 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1227 std::vector<MockWrite> writes;
1228 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1229 DeterministicSocketData socket_data(reads, arraysize(reads),
1230 writes.empty() ? nullptr : &writes[0],
1231 writes.size());
1232 socket_factory_.AddSocketDataProvider(&socket_data);
1233 socket_data.StopAfter(1);
1235 MockRead reads2[] = {
1236 MockRead(ASYNC, 0, 0) // EOF
1238 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1239 socket_factory_.AddSocketDataProvider(&socket_data2);
1240 socket_data2.StopAfter(1);
1242 QuicStreamRequest request(&factory_);
1243 EXPECT_EQ(ERR_IO_PENDING,
1244 request.Request(host_port_pair_, is_https_, privacy_mode_,
1245 /*cert_verify_flags=*/0, host_port_pair_.host(),
1246 "GET", net_log_, callback_.callback()));
1248 EXPECT_EQ(OK, callback_.WaitForResult());
1249 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1250 HttpRequestInfo request_info;
1251 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1252 DEFAULT_PRIORITY,
1253 net_log_, CompletionCallback()));
1255 // Close the session and verify that stream saw the error.
1256 factory_.CloseAllSessions(ERR_INTERNET_DISCONNECTED);
1257 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
1258 stream->ReadResponseHeaders(callback_.callback()));
1260 // Now attempting to request a stream to the same origin should create
1261 // a new session.
1263 QuicStreamRequest request2(&factory_);
1264 EXPECT_EQ(ERR_IO_PENDING,
1265 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1266 /*cert_verify_flags=*/0, host_port_pair_.host(),
1267 "GET", net_log_, callback_.callback()));
1269 EXPECT_EQ(OK, callback_.WaitForResult());
1270 stream = request2.ReleaseStream();
1271 stream.reset(); // Will reset stream 3.
1273 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1274 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1275 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1276 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1279 TEST_P(QuicStreamFactoryTest, OnIPAddressChanged) {
1280 MockRead reads[] = {
1281 MockRead(ASYNC, 0, 0) // EOF
1283 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1284 std::vector<MockWrite> writes;
1285 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1286 DeterministicSocketData socket_data(reads, arraysize(reads),
1287 writes.empty() ? nullptr : &writes[0],
1288 writes.size());
1289 socket_factory_.AddSocketDataProvider(&socket_data);
1290 socket_data.StopAfter(1);
1292 MockRead reads2[] = {
1293 MockRead(ASYNC, 0, 0) // EOF
1295 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1296 socket_factory_.AddSocketDataProvider(&socket_data2);
1297 socket_data2.StopAfter(1);
1299 QuicStreamRequest request(&factory_);
1300 EXPECT_EQ(ERR_IO_PENDING,
1301 request.Request(host_port_pair_, is_https_, privacy_mode_,
1302 /*cert_verify_flags=*/0, host_port_pair_.host(),
1303 "GET", net_log_, callback_.callback()));
1305 EXPECT_EQ(OK, callback_.WaitForResult());
1306 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1307 HttpRequestInfo request_info;
1308 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1309 DEFAULT_PRIORITY,
1310 net_log_, CompletionCallback()));
1312 // Change the IP address and verify that stream saw the error.
1313 factory_.OnIPAddressChanged();
1314 EXPECT_EQ(ERR_NETWORK_CHANGED,
1315 stream->ReadResponseHeaders(callback_.callback()));
1316 EXPECT_TRUE(factory_.require_confirmation());
1318 // Now attempting to request a stream to the same origin should create
1319 // a new session.
1321 QuicStreamRequest request2(&factory_);
1322 EXPECT_EQ(ERR_IO_PENDING,
1323 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1324 /*cert_verify_flags=*/0, host_port_pair_.host(),
1325 "GET", net_log_, callback_.callback()));
1327 EXPECT_EQ(OK, callback_.WaitForResult());
1328 stream = request2.ReleaseStream();
1329 stream.reset(); // Will reset stream 3.
1331 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1332 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1333 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1334 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1337 TEST_P(QuicStreamFactoryTest, OnCertAdded) {
1338 MockRead reads[] = {
1339 MockRead(ASYNC, 0, 0) // EOF
1341 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1342 std::vector<MockWrite> writes;
1343 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1344 DeterministicSocketData socket_data(reads, arraysize(reads),
1345 writes.empty() ? nullptr : &writes[0],
1346 writes.size());
1347 socket_factory_.AddSocketDataProvider(&socket_data);
1348 socket_data.StopAfter(1);
1350 MockRead reads2[] = {
1351 MockRead(ASYNC, 0, 0) // EOF
1353 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1354 socket_factory_.AddSocketDataProvider(&socket_data2);
1355 socket_data2.StopAfter(1);
1357 QuicStreamRequest request(&factory_);
1358 EXPECT_EQ(ERR_IO_PENDING,
1359 request.Request(host_port_pair_, is_https_, privacy_mode_,
1360 /*cert_verify_flags=*/0, host_port_pair_.host(),
1361 "GET", net_log_, callback_.callback()));
1363 EXPECT_EQ(OK, callback_.WaitForResult());
1364 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1365 HttpRequestInfo request_info;
1366 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1367 DEFAULT_PRIORITY,
1368 net_log_, CompletionCallback()));
1370 // Add a cert and verify that stream saw the event.
1371 factory_.OnCertAdded(nullptr);
1372 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
1373 stream->ReadResponseHeaders(callback_.callback()));
1374 EXPECT_FALSE(factory_.require_confirmation());
1376 // Now attempting to request a stream to the same origin should create
1377 // a new session.
1379 QuicStreamRequest request2(&factory_);
1380 EXPECT_EQ(ERR_IO_PENDING,
1381 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1382 /*cert_verify_flags=*/0, host_port_pair_.host(),
1383 "GET", net_log_, callback_.callback()));
1385 EXPECT_EQ(OK, callback_.WaitForResult());
1386 stream = request2.ReleaseStream();
1387 stream.reset(); // Will reset stream 3.
1389 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1390 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1391 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1392 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1395 TEST_P(QuicStreamFactoryTest, OnCACertChanged) {
1396 MockRead reads[] = {
1397 MockRead(ASYNC, 0, 0) // EOF
1399 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1400 std::vector<MockWrite> writes;
1401 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
1402 DeterministicSocketData socket_data(reads, arraysize(reads),
1403 writes.empty() ? nullptr : &writes[0],
1404 writes.size());
1405 socket_factory_.AddSocketDataProvider(&socket_data);
1406 socket_data.StopAfter(1);
1408 MockRead reads2[] = {
1409 MockRead(ASYNC, 0, 0) // EOF
1411 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1412 socket_factory_.AddSocketDataProvider(&socket_data2);
1413 socket_data2.StopAfter(1);
1415 QuicStreamRequest request(&factory_);
1416 EXPECT_EQ(ERR_IO_PENDING,
1417 request.Request(host_port_pair_, is_https_, privacy_mode_,
1418 /*cert_verify_flags=*/0, host_port_pair_.host(),
1419 "GET", net_log_, callback_.callback()));
1421 EXPECT_EQ(OK, callback_.WaitForResult());
1422 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1423 HttpRequestInfo request_info;
1424 EXPECT_EQ(OK, stream->InitializeStream(&request_info,
1425 DEFAULT_PRIORITY,
1426 net_log_, CompletionCallback()));
1428 // Change the CA cert and verify that stream saw the event.
1429 factory_.OnCACertChanged(nullptr);
1430 EXPECT_EQ(ERR_CERT_DATABASE_CHANGED,
1431 stream->ReadResponseHeaders(callback_.callback()));
1432 EXPECT_FALSE(factory_.require_confirmation());
1434 // Now attempting to request a stream to the same origin should create
1435 // a new session.
1437 QuicStreamRequest request2(&factory_);
1438 EXPECT_EQ(ERR_IO_PENDING,
1439 request2.Request(host_port_pair_, is_https_, privacy_mode_,
1440 /*cert_verify_flags=*/0, host_port_pair_.host(),
1441 "GET", net_log_, callback_.callback()));
1443 EXPECT_EQ(OK, callback_.WaitForResult());
1444 stream = request2.ReleaseStream();
1445 stream.reset(); // Will reset stream 3.
1447 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1448 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1449 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1450 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1453 TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) {
1454 vector<string> cannoncial_suffixes;
1455 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1456 cannoncial_suffixes.push_back(string(".googlevideo.com"));
1458 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1459 string r1_host_name("r1");
1460 string r2_host_name("r2");
1461 r1_host_name.append(cannoncial_suffixes[i]);
1462 r2_host_name.append(cannoncial_suffixes[i]);
1464 HostPortPair host_port_pair1(r1_host_name, 80);
1465 QuicCryptoClientConfig* crypto_config =
1466 QuicStreamFactoryPeer::GetCryptoConfig(&factory_);
1467 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_);
1468 QuicCryptoClientConfig::CachedState* cached1 =
1469 crypto_config->LookupOrCreate(server_id1);
1470 EXPECT_FALSE(cached1->proof_valid());
1471 EXPECT_TRUE(cached1->source_address_token().empty());
1473 // Mutate the cached1 to have different data.
1474 // TODO(rtenneti): mutate other members of CachedState.
1475 cached1->set_source_address_token(r1_host_name);
1476 cached1->SetProofValid();
1478 HostPortPair host_port_pair2(r2_host_name, 80);
1479 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_);
1480 QuicCryptoClientConfig::CachedState* cached2 =
1481 crypto_config->LookupOrCreate(server_id2);
1482 EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token());
1483 EXPECT_TRUE(cached2->proof_valid());
1487 TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) {
1488 vector<string> cannoncial_suffixes;
1489 cannoncial_suffixes.push_back(string(".c.youtube.com"));
1490 cannoncial_suffixes.push_back(string(".googlevideo.com"));
1492 for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) {
1493 string r3_host_name("r3");
1494 string r4_host_name("r4");
1495 r3_host_name.append(cannoncial_suffixes[i]);
1496 r4_host_name.append(cannoncial_suffixes[i]);
1498 HostPortPair host_port_pair1(r3_host_name, 80);
1499 QuicCryptoClientConfig* crypto_config =
1500 QuicStreamFactoryPeer::GetCryptoConfig(&factory_);
1501 QuicServerId server_id1(host_port_pair1, is_https_, privacy_mode_);
1502 QuicCryptoClientConfig::CachedState* cached1 =
1503 crypto_config->LookupOrCreate(server_id1);
1504 EXPECT_FALSE(cached1->proof_valid());
1505 EXPECT_TRUE(cached1->source_address_token().empty());
1507 // Mutate the cached1 to have different data.
1508 // TODO(rtenneti): mutate other members of CachedState.
1509 cached1->set_source_address_token(r3_host_name);
1510 cached1->SetProofInvalid();
1512 HostPortPair host_port_pair2(r4_host_name, 80);
1513 QuicServerId server_id2(host_port_pair2, is_https_, privacy_mode_);
1514 QuicCryptoClientConfig::CachedState* cached2 =
1515 crypto_config->LookupOrCreate(server_id2);
1516 EXPECT_NE(cached1->source_address_token(), cached2->source_address_token());
1517 EXPECT_TRUE(cached2->source_address_token().empty());
1518 EXPECT_FALSE(cached2->proof_valid());
1522 TEST_P(QuicStreamFactoryTest, RacingConnections) {
1523 if (!GetParam().enable_connection_racing)
1524 return;
1525 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1526 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1527 MockRead reads[] = {
1528 MockRead(ASYNC, OK, 0) // EOF
1530 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1531 socket_factory_.AddSocketDataProvider(&socket_data);
1532 socket_data.StopAfter(1);
1534 MockRead reads2[] = {
1535 MockRead(ASYNC, 0, 0) // EOF
1537 DeterministicSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1538 socket_factory_.AddSocketDataProvider(&socket_data2);
1539 socket_data2.StopAfter(1);
1541 crypto_client_stream_factory_.set_handshake_mode(
1542 MockCryptoClientStream::ZERO_RTT);
1543 host_resolver_.set_synchronous_mode(true);
1544 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1545 "192.168.0.1", "");
1547 QuicStreamRequest request(&factory_);
1548 QuicServerId server_id(host_port_pair_, is_https_, privacy_mode_);
1549 EXPECT_EQ(ERR_IO_PENDING,
1550 request.Request(host_port_pair_, is_https_, privacy_mode_,
1551 /*cert_verify_flags=*/0, host_port_pair_.host(),
1552 "GET", net_log_, callback_.callback()));
1553 EXPECT_EQ(2u,
1554 QuicStreamFactoryPeer::GetNumberOfActiveJobs(&factory_, server_id));
1556 runner_->RunNextTask();
1558 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1559 EXPECT_TRUE(stream.get());
1560 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1561 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1562 EXPECT_EQ(0u,
1563 QuicStreamFactoryPeer::GetNumberOfActiveJobs(&factory_, server_id));
1566 TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) {
1567 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1568 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1569 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1571 MockRead reads[] = {
1572 MockRead(ASYNC, OK, 0) // EOF
1574 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1575 socket_factory_.AddSocketDataProvider(&socket_data);
1576 socket_data.StopAfter(1);
1578 crypto_client_stream_factory_.set_handshake_mode(
1579 MockCryptoClientStream::ZERO_RTT);
1580 host_resolver_.set_synchronous_mode(true);
1581 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1582 "192.168.0.1", "");
1584 QuicStreamRequest request(&factory_);
1585 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1586 /*cert_verify_flags=*/0, host_port_pair_.host(),
1587 "GET", net_log_, callback_.callback()));
1589 // If we are waiting for disk cache, we would have posted a task. Verify that
1590 // the CancelWaitForDataReady task hasn't been posted.
1591 ASSERT_EQ(0u, runner_->GetPostedTasks().size());
1593 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1594 EXPECT_TRUE(stream.get());
1595 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1596 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1599 TEST_P(QuicStreamFactoryTest, BadPacketLoss) {
1600 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1601 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1602 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1603 QuicStreamFactoryPeer::SetMaxNumberOfLossyConnections(&factory_, 2);
1604 EXPECT_FALSE(
1605 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1606 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1607 &factory_, host_port_pair_.port()));
1609 MockRead reads[] = {
1610 MockRead(ASYNC, OK, 0) // EOF
1612 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1613 socket_factory_.AddSocketDataProvider(&socket_data);
1614 socket_data.StopAfter(1);
1616 DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
1617 socket_factory_.AddSocketDataProvider(&socket_data2);
1618 socket_data2.StopAfter(1);
1620 DeterministicSocketData socket_data3(nullptr, 0, nullptr, 0);
1621 socket_factory_.AddSocketDataProvider(&socket_data3);
1622 socket_data3.StopAfter(1);
1624 DeterministicSocketData socket_data4(nullptr, 0, nullptr, 0);
1625 socket_factory_.AddSocketDataProvider(&socket_data4);
1626 socket_data4.StopAfter(1);
1628 HostPortPair server2("mail.example.org", kDefaultServerPort);
1629 HostPortPair server3("docs.example.org", kDefaultServerPort);
1630 HostPortPair server4("images.example.org", kDefaultServerPort);
1632 crypto_client_stream_factory_.set_handshake_mode(
1633 MockCryptoClientStream::ZERO_RTT);
1634 host_resolver_.set_synchronous_mode(true);
1635 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1636 "192.168.0.1", "");
1637 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1638 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
1639 host_resolver_.rules()->AddIPLiteralRule(server4.host(), "192.168.0.1", "");
1641 QuicStreamRequest request(&factory_);
1642 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1643 /*cert_verify_flags=*/0, host_port_pair_.host(),
1644 "GET", net_log_, callback_.callback()));
1646 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1647 &factory_, host_port_pair_, is_https_);
1649 DVLOG(1) << "Create 1st session and test packet loss";
1651 // Set packet_loss_rate to a lower value than packet_loss_threshold.
1652 EXPECT_FALSE(
1653 factory_.OnHandshakeConfirmed(session, /*packet_loss_rate=*/0.9f));
1654 EXPECT_TRUE(session->connection()->connected());
1655 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
1656 &factory_, host_port_pair_, is_https_));
1657 EXPECT_FALSE(
1658 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1659 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1660 &factory_, host_port_pair_.port()));
1662 // Set packet_loss_rate to a higher value than packet_loss_threshold only once
1663 // and that shouldn't close the session and it shouldn't disable QUIC.
1664 EXPECT_FALSE(
1665 factory_.OnHandshakeConfirmed(session, /*packet_loss_rate=*/1.0f));
1666 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1667 &factory_, host_port_pair_.port()));
1668 EXPECT_TRUE(session->connection()->connected());
1669 EXPECT_FALSE(
1670 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1671 EXPECT_TRUE(QuicStreamFactoryPeer::HasActiveSession(
1672 &factory_, host_port_pair_, is_https_));
1674 // Test N-in-a-row high packet loss connections.
1676 DVLOG(1) << "Create 2nd session and test packet loss";
1678 TestCompletionCallback callback2;
1679 QuicStreamRequest request2(&factory_);
1680 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1681 /*cert_verify_flags=*/0, server2.host(), "GET",
1682 net_log_, callback2.callback()));
1683 QuicChromiumClientSession* session2 =
1684 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1686 // If there is no packet loss during handshake confirmation, number of lossy
1687 // connections for the port should be 0.
1688 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1689 &factory_, server2.port()));
1690 EXPECT_FALSE(
1691 factory_.OnHandshakeConfirmed(session2, /*packet_loss_rate=*/0.9f));
1692 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1693 &factory_, server2.port()));
1694 EXPECT_FALSE(
1695 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server2.port()));
1697 // Set packet_loss_rate to a higher value than packet_loss_threshold only once
1698 // and that shouldn't close the session and it shouldn't disable QUIC.
1699 EXPECT_FALSE(
1700 factory_.OnHandshakeConfirmed(session2, /*packet_loss_rate=*/1.0f));
1701 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1702 &factory_, server2.port()));
1703 EXPECT_TRUE(session2->connection()->connected());
1704 EXPECT_FALSE(
1705 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server2.port()));
1706 EXPECT_TRUE(
1707 QuicStreamFactoryPeer::HasActiveSession(&factory_, server2, is_https_));
1709 DVLOG(1) << "Create 3rd session which also has packet loss";
1711 TestCompletionCallback callback3;
1712 QuicStreamRequest request3(&factory_);
1713 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
1714 /*cert_verify_flags=*/0, server3.host(), "GET",
1715 net_log_, callback3.callback()));
1716 QuicChromiumClientSession* session3 =
1717 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
1719 DVLOG(1) << "Create 4th session with packet loss and test IsQuicDisabled()";
1720 TestCompletionCallback callback4;
1721 QuicStreamRequest request4(&factory_);
1722 EXPECT_EQ(OK, request4.Request(server4, is_https_, privacy_mode_,
1723 /*cert_verify_flags=*/0, server4.host(), "GET",
1724 net_log_, callback4.callback()));
1725 QuicChromiumClientSession* session4 =
1726 QuicStreamFactoryPeer::GetActiveSession(&factory_, server4, is_https_);
1728 // Set packet_loss_rate to higher value than packet_loss_threshold 2nd time in
1729 // a row and that should close the session and disable QUIC.
1730 EXPECT_TRUE(
1731 factory_.OnHandshakeConfirmed(session3, /*packet_loss_rate=*/1.0f));
1732 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1733 &factory_, server3.port()));
1734 EXPECT_FALSE(session3->connection()->connected());
1735 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server3.port()));
1736 EXPECT_FALSE(
1737 QuicStreamFactoryPeer::HasActiveSession(&factory_, server3, is_https_));
1738 EXPECT_FALSE(HasActiveSession(server3));
1740 // Set packet_loss_rate to higher value than packet_loss_threshold 3rd time in
1741 // a row and IsQuicDisabled() should close the session.
1742 EXPECT_TRUE(
1743 factory_.OnHandshakeConfirmed(session4, /*packet_loss_rate=*/1.0f));
1744 EXPECT_EQ(3, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1745 &factory_, server4.port()));
1746 EXPECT_FALSE(session4->connection()->connected());
1747 EXPECT_TRUE(QuicStreamFactoryPeer::IsQuicDisabled(&factory_, server4.port()));
1748 EXPECT_FALSE(
1749 QuicStreamFactoryPeer::HasActiveSession(&factory_, server4, is_https_));
1750 EXPECT_FALSE(HasActiveSession(server4));
1752 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1753 EXPECT_TRUE(stream.get());
1754 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1755 EXPECT_TRUE(stream2.get());
1756 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
1757 EXPECT_TRUE(stream3.get());
1758 scoped_ptr<QuicHttpStream> stream4 = request4.ReleaseStream();
1759 EXPECT_TRUE(stream4.get());
1760 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1761 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1762 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1763 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1764 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
1765 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
1766 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
1767 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
1770 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfTwo) {
1771 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1772 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1773 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1774 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
1775 EXPECT_FALSE(
1776 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1777 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1778 &factory_, host_port_pair_.port()));
1780 MockRead reads[] = {
1781 MockRead(ASYNC, OK, 0) // EOF
1783 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1784 socket_factory_.AddSocketDataProvider(&socket_data);
1785 socket_data.StopAfter(1);
1787 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1788 socket_factory_.AddSocketDataProvider(&socket_data2);
1789 socket_data2.StopAfter(1);
1791 HostPortPair server2("mail.example.org", kDefaultServerPort);
1793 crypto_client_stream_factory_.set_handshake_mode(
1794 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1795 host_resolver_.set_synchronous_mode(true);
1796 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1797 "192.168.0.1", "");
1798 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1800 QuicStreamRequest request(&factory_);
1801 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1802 /*cert_verify_flags=*/0, host_port_pair_.host(),
1803 "GET", net_log_, callback_.callback()));
1805 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1806 &factory_, host_port_pair_, is_https_);
1808 DVLOG(1) << "Created 1st session. Now trigger public reset post handshake";
1809 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1810 // Need to spin the loop now to ensure that
1811 // QuicStreamFactory::OnSessionClosed() runs.
1812 base::RunLoop run_loop;
1813 run_loop.RunUntilIdle();
1815 EXPECT_EQ(1,
1816 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
1817 EXPECT_FALSE(
1818 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1820 // Test two-in-a-row public reset post handshakes..
1821 DVLOG(1) << "Create 2nd session and trigger public reset post handshake";
1822 TestCompletionCallback callback2;
1823 QuicStreamRequest request2(&factory_);
1824 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1825 /*cert_verify_flags=*/0, server2.host(), "GET",
1826 net_log_, callback2.callback()));
1827 QuicChromiumClientSession* session2 =
1828 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1830 session2->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1831 // Need to spin the loop now to ensure that
1832 // QuicStreamFactory::OnSessionClosed() runs.
1833 base::RunLoop run_loop2;
1834 run_loop2.RunUntilIdle();
1835 EXPECT_EQ(2,
1836 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
1837 EXPECT_TRUE(
1838 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1839 EXPECT_EQ(
1840 QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE,
1841 factory_.QuicDisabledReason(host_port_pair_.port()));
1843 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1844 EXPECT_TRUE(stream.get());
1845 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1846 EXPECT_TRUE(stream2.get());
1847 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1848 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1849 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1850 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1853 TEST_P(QuicStreamFactoryTest, TimeoutsWithOpenStreamsTwoOfTwo) {
1854 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1855 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1856 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1857 QuicStreamFactoryPeer::SetThresholdTimeoutsWithOpenStreams(&factory_, 2);
1858 EXPECT_FALSE(
1859 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1860 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1861 &factory_, host_port_pair_.port()));
1863 MockRead reads[] = {
1864 MockRead(ASYNC, OK, 0) // EOF
1866 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1867 socket_factory_.AddSocketDataProvider(&socket_data);
1868 socket_data.StopAfter(1);
1870 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1871 socket_factory_.AddSocketDataProvider(&socket_data2);
1872 socket_data2.StopAfter(1);
1874 HostPortPair server2("mail.example.org", kDefaultServerPort);
1876 crypto_client_stream_factory_.set_handshake_mode(
1877 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1878 host_resolver_.set_synchronous_mode(true);
1879 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1880 "192.168.0.1", "");
1881 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1883 QuicStreamRequest request(&factory_);
1884 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1885 /*cert_verify_flags=*/0, host_port_pair_.host(),
1886 "GET", net_log_, callback_.callback()));
1888 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1889 &factory_, host_port_pair_, is_https_);
1891 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1892 EXPECT_TRUE(stream.get());
1893 HttpRequestInfo request_info;
1894 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1895 net_log_, CompletionCallback()));
1897 DVLOG(1)
1898 << "Created 1st session and initialized a stream. Now trigger timeout";
1899 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
1900 // Need to spin the loop now to ensure that
1901 // QuicStreamFactory::OnSessionClosed() runs.
1902 base::RunLoop run_loop;
1903 run_loop.RunUntilIdle();
1905 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
1906 EXPECT_FALSE(
1907 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1909 // Test two-in-a-row timeouts with open streams.
1910 DVLOG(1) << "Create 2nd session and timeout with open stream";
1911 TestCompletionCallback callback2;
1912 QuicStreamRequest request2(&factory_);
1913 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
1914 /*cert_verify_flags=*/0, server2.host(), "GET",
1915 net_log_, callback2.callback()));
1916 QuicChromiumClientSession* session2 =
1917 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
1919 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1920 EXPECT_TRUE(stream2.get());
1921 EXPECT_EQ(OK, stream2->InitializeStream(&request_info, DEFAULT_PRIORITY,
1922 net_log_, CompletionCallback()));
1924 session2->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
1925 // Need to spin the loop now to ensure that
1926 // QuicStreamFactory::OnSessionClosed() runs.
1927 base::RunLoop run_loop2;
1928 run_loop2.RunUntilIdle();
1929 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
1930 EXPECT_TRUE(
1931 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1932 EXPECT_EQ(QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS,
1933 factory_.QuicDisabledReason(host_port_pair_.port()));
1935 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1936 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1937 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1938 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1941 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfThree) {
1942 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
1943 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
1944 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
1945 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
1946 EXPECT_FALSE(
1947 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1948 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
1949 &factory_, host_port_pair_.port()));
1951 MockRead reads[] = {
1952 MockRead(ASYNC, OK, 0) // EOF
1954 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
1955 socket_factory_.AddSocketDataProvider(&socket_data);
1956 socket_data.StopAfter(1);
1958 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
1959 socket_factory_.AddSocketDataProvider(&socket_data2);
1960 socket_data2.StopAfter(1);
1962 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
1963 socket_factory_.AddSocketDataProvider(&socket_data3);
1964 socket_data3.StopAfter(1);
1966 HostPortPair server2("mail.example.org", kDefaultServerPort);
1967 HostPortPair server3("docs.example.org", kDefaultServerPort);
1969 crypto_client_stream_factory_.set_handshake_mode(
1970 MockCryptoClientStream::CONFIRM_HANDSHAKE);
1971 host_resolver_.set_synchronous_mode(true);
1972 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
1973 "192.168.0.1", "");
1974 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
1975 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
1977 // Test first and third out of three public reset post handshakes.
1978 QuicStreamRequest request(&factory_);
1979 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
1980 /*cert_verify_flags=*/0, host_port_pair_.host(),
1981 "GET", net_log_, callback_.callback()));
1983 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
1984 &factory_, host_port_pair_, is_https_);
1986 DVLOG(1) << "Created 1st session. Now trigger public reset post handshake";
1987 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
1988 // Need to spin the loop now to ensure that
1989 // QuicStreamFactory::OnSessionClosed() runs.
1990 base::RunLoop run_loop;
1991 run_loop.RunUntilIdle();
1993 EXPECT_EQ(1,
1994 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
1995 EXPECT_FALSE(
1996 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
1998 DVLOG(1) << "Create 2nd session without disable trigger";
1999 TestCompletionCallback callback2;
2000 QuicStreamRequest request2(&factory_);
2001 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2002 /*cert_verify_flags=*/0, server2.host(), "GET",
2003 net_log_, callback2.callback()));
2004 QuicChromiumClientSession* session2 =
2005 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2007 session2->connection()->CloseConnection(QUIC_NO_ERROR, false);
2008 // Need to spin the loop now to ensure that
2009 // QuicStreamFactory::OnSessionClosed() runs.
2010 base::RunLoop run_loop2;
2011 run_loop2.RunUntilIdle();
2012 EXPECT_EQ(1,
2013 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2014 EXPECT_FALSE(
2015 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2017 DVLOG(1) << "Create 3rd session with public reset post handshake,"
2018 << " will disable QUIC";
2019 TestCompletionCallback callback3;
2020 QuicStreamRequest request3(&factory_);
2021 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2022 /*cert_verify_flags=*/0, server3.host(), "GET",
2023 net_log_, callback3.callback()));
2024 QuicChromiumClientSession* session3 =
2025 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2027 session3->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
2028 // Need to spin the loop now to ensure that
2029 // QuicStreamFactory::OnSessionClosed() runs.
2030 base::RunLoop run_loop3;
2031 run_loop3.RunUntilIdle();
2032 EXPECT_EQ(2,
2033 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2034 EXPECT_TRUE(
2035 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2036 EXPECT_EQ(
2037 QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE,
2038 factory_.QuicDisabledReason(host_port_pair_.port()));
2040 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2041 EXPECT_TRUE(stream.get());
2042 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2043 EXPECT_TRUE(stream2.get());
2044 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2045 EXPECT_TRUE(stream3.get());
2047 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2048 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2049 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2050 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2051 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2052 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2055 TEST_P(QuicStreamFactoryTest, TimeoutsWithOpenStreamsTwoOfThree) {
2056 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
2057 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
2058 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
2059 QuicStreamFactoryPeer::SetThresholdTimeoutsWithOpenStreams(&factory_, 2);
2060 EXPECT_FALSE(
2061 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2062 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
2063 &factory_, host_port_pair_.port()));
2065 MockRead reads[] = {
2066 MockRead(ASYNC, OK, 0) // EOF
2068 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
2069 socket_factory_.AddSocketDataProvider(&socket_data);
2070 socket_data.StopAfter(1);
2072 // DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
2073 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
2074 socket_factory_.AddSocketDataProvider(&socket_data2);
2075 socket_data2.StopAfter(1);
2077 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
2078 socket_factory_.AddSocketDataProvider(&socket_data3);
2079 socket_data3.StopAfter(1);
2081 HostPortPair server2("mail.example.org", kDefaultServerPort);
2082 HostPortPair server3("docs.example.org", kDefaultServerPort);
2084 crypto_client_stream_factory_.set_handshake_mode(
2085 MockCryptoClientStream::CONFIRM_HANDSHAKE);
2086 host_resolver_.set_synchronous_mode(true);
2087 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
2088 "192.168.0.1", "");
2089 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
2090 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
2092 // Test first and third out of three timeouts with open streams.
2093 QuicStreamRequest request(&factory_);
2094 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
2095 /*cert_verify_flags=*/0, host_port_pair_.host(),
2096 "GET", net_log_, callback_.callback()));
2098 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
2099 &factory_, host_port_pair_, is_https_);
2101 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2102 EXPECT_TRUE(stream.get());
2103 HttpRequestInfo request_info;
2104 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2105 net_log_, CompletionCallback()));
2107 DVLOG(1)
2108 << "Created 1st session and initialized a stream. Now trigger timeout";
2109 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2110 // Need to spin the loop now to ensure that
2111 // QuicStreamFactory::OnSessionClosed() runs.
2112 base::RunLoop run_loop;
2113 run_loop.RunUntilIdle();
2115 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2116 EXPECT_FALSE(
2117 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2119 // Test two-in-a-row timeouts with open streams.
2120 DVLOG(1) << "Create 2nd session without timeout";
2121 TestCompletionCallback callback2;
2122 QuicStreamRequest request2(&factory_);
2123 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2124 /*cert_verify_flags=*/0, server2.host(), "GET",
2125 net_log_, callback2.callback()));
2126 QuicChromiumClientSession* session2 =
2127 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2129 session2->connection()->CloseConnection(QUIC_NO_ERROR, true);
2130 // Need to spin the loop now to ensure that
2131 // QuicStreamFactory::OnSessionClosed() runs.
2132 base::RunLoop run_loop2;
2133 run_loop2.RunUntilIdle();
2134 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2135 EXPECT_FALSE(
2136 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2138 DVLOG(1) << "Create 3rd session with timeout with open streams,"
2139 << " will disable QUIC";
2141 TestCompletionCallback callback3;
2142 QuicStreamRequest request3(&factory_);
2143 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2144 /*cert_verify_flags=*/0, server3.host(), "GET",
2145 net_log_, callback3.callback()));
2146 QuicChromiumClientSession* session3 =
2147 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2149 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2150 EXPECT_TRUE(stream3.get());
2151 EXPECT_EQ(OK, stream3->InitializeStream(&request_info, DEFAULT_PRIORITY,
2152 net_log_, CompletionCallback()));
2153 session3->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2154 // Need to spin the loop now to ensure that
2155 // QuicStreamFactory::OnSessionClosed() runs.
2156 base::RunLoop run_loop3;
2157 run_loop3.RunUntilIdle();
2158 EXPECT_EQ(2, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2159 EXPECT_TRUE(
2160 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2161 EXPECT_EQ(QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS,
2162 factory_.QuicDisabledReason(host_port_pair_.port()));
2164 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2165 EXPECT_TRUE(stream2.get());
2166 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2167 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2168 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2169 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2170 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2171 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2174 TEST_P(QuicStreamFactoryTest, PublicResetPostHandshakeTwoOfFour) {
2175 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
2176 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
2177 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
2178 QuicStreamFactoryPeer::SetThresholdPublicResetsPostHandshake(&factory_, 2);
2179 EXPECT_FALSE(
2180 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2181 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
2182 &factory_, host_port_pair_.port()));
2184 MockRead reads[] = {
2185 MockRead(ASYNC, OK, 0) // EOF
2187 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
2188 socket_factory_.AddSocketDataProvider(&socket_data);
2189 socket_data.StopAfter(1);
2191 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
2192 socket_factory_.AddSocketDataProvider(&socket_data2);
2193 socket_data2.StopAfter(1);
2195 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
2196 socket_factory_.AddSocketDataProvider(&socket_data3);
2197 socket_data3.StopAfter(1);
2199 DeterministicSocketData socket_data4(reads, arraysize(reads), nullptr, 0);
2200 socket_factory_.AddSocketDataProvider(&socket_data4);
2201 socket_data4.StopAfter(1);
2203 HostPortPair server2("mail.example.org", kDefaultServerPort);
2204 HostPortPair server3("docs.example.org", kDefaultServerPort);
2205 HostPortPair server4("images.example.org", kDefaultServerPort);
2207 crypto_client_stream_factory_.set_handshake_mode(
2208 MockCryptoClientStream::CONFIRM_HANDSHAKE);
2209 host_resolver_.set_synchronous_mode(true);
2210 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
2211 "192.168.0.1", "");
2212 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
2213 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
2214 host_resolver_.rules()->AddIPLiteralRule(server4.host(), "192.168.0.1", "");
2216 // Test first and fourth out of four public reset post handshakes.
2217 QuicStreamRequest request(&factory_);
2218 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
2219 /*cert_verify_flags=*/0, host_port_pair_.host(),
2220 "GET", net_log_, callback_.callback()));
2222 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
2223 &factory_, host_port_pair_, is_https_);
2225 DVLOG(1) << "Created 1st session. Now trigger public reset post handshake";
2226 session->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
2227 // Need to spin the loop now to ensure that
2228 // QuicStreamFactory::OnSessionClosed() runs.
2229 base::RunLoop run_loop;
2230 run_loop.RunUntilIdle();
2232 EXPECT_EQ(1,
2233 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2234 EXPECT_FALSE(
2235 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2237 DVLOG(1) << "Create 2nd and 3rd sessions without disable trigger";
2238 TestCompletionCallback callback2;
2239 QuicStreamRequest request2(&factory_);
2240 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2241 /*cert_verify_flags=*/0, server2.host(), "GET",
2242 net_log_, callback2.callback()));
2243 QuicChromiumClientSession* session2 =
2244 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2246 session2->connection()->CloseConnection(QUIC_NO_ERROR, false);
2247 // Need to spin the loop now to ensure that
2248 // QuicStreamFactory::OnSessionClosed() runs.
2249 base::RunLoop run_loop2;
2250 run_loop2.RunUntilIdle();
2251 EXPECT_EQ(1,
2252 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2253 EXPECT_FALSE(
2254 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2256 TestCompletionCallback callback3;
2257 QuicStreamRequest request3(&factory_);
2258 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2259 /*cert_verify_flags=*/0, server3.host(), "GET",
2260 net_log_, callback3.callback()));
2261 QuicChromiumClientSession* session3 =
2262 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2264 session3->connection()->CloseConnection(QUIC_NO_ERROR, false);
2265 // Need to spin the loop now to ensure that
2266 // QuicStreamFactory::OnSessionClosed() runs.
2267 base::RunLoop run_loop3;
2268 run_loop3.RunUntilIdle();
2269 EXPECT_EQ(1,
2270 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2271 EXPECT_FALSE(
2272 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2274 DVLOG(1) << "Create 4rd session with public reset post handshake,"
2275 << " will not disable QUIC";
2276 TestCompletionCallback callback4;
2277 QuicStreamRequest request4(&factory_);
2278 EXPECT_EQ(OK, request4.Request(server4, is_https_, privacy_mode_,
2279 /*cert_verify_flags=*/0, server4.host(), "GET",
2280 net_log_, callback4.callback()));
2281 QuicChromiumClientSession* session4 =
2282 QuicStreamFactoryPeer::GetActiveSession(&factory_, server4, is_https_);
2284 session4->connection()->CloseConnection(QUIC_PUBLIC_RESET, true);
2285 // Need to spin the loop now to ensure that
2286 // QuicStreamFactory::OnSessionClosed() runs.
2287 base::RunLoop run_loop4;
2288 run_loop4.RunUntilIdle();
2289 EXPECT_EQ(1,
2290 QuicStreamFactoryPeer::GetNumPublicResetsPostHandshake(&factory_));
2291 EXPECT_FALSE(
2292 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2294 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2295 EXPECT_TRUE(stream.get());
2296 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2297 EXPECT_TRUE(stream2.get());
2298 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2299 EXPECT_TRUE(stream3.get());
2300 scoped_ptr<QuicHttpStream> stream4 = request4.ReleaseStream();
2301 EXPECT_TRUE(stream4.get());
2303 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2304 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2305 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2306 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2307 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2308 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2309 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
2310 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
2313 TEST_P(QuicStreamFactoryTest, TimeoutsWithOpenStreamsTwoOfFour) {
2314 factory_.set_quic_server_info_factory(&quic_server_info_factory_);
2315 QuicStreamFactoryPeer::SetTaskRunner(&factory_, runner_.get());
2316 QuicStreamFactoryPeer::SetDisableDiskCache(&factory_, true);
2317 QuicStreamFactoryPeer::SetThresholdTimeoutsWithOpenStreams(&factory_, 2);
2318 EXPECT_FALSE(
2319 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2320 EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumberOfLossyConnections(
2321 &factory_, host_port_pair_.port()));
2323 MockRead reads[] = {
2324 MockRead(ASYNC, OK, 0) // EOF
2326 DeterministicSocketData socket_data(reads, arraysize(reads), nullptr, 0);
2327 socket_factory_.AddSocketDataProvider(&socket_data);
2328 socket_data.StopAfter(1);
2330 // DeterministicSocketData socket_data2(nullptr, 0, nullptr, 0);
2331 DeterministicSocketData socket_data2(reads, arraysize(reads), nullptr, 0);
2332 socket_factory_.AddSocketDataProvider(&socket_data2);
2333 socket_data2.StopAfter(1);
2335 DeterministicSocketData socket_data3(reads, arraysize(reads), nullptr, 0);
2336 socket_factory_.AddSocketDataProvider(&socket_data3);
2337 socket_data3.StopAfter(1);
2339 DeterministicSocketData socket_data4(reads, arraysize(reads), nullptr, 0);
2340 socket_factory_.AddSocketDataProvider(&socket_data4);
2341 socket_data4.StopAfter(1);
2343 HostPortPair server2("mail.example.org", kDefaultServerPort);
2344 HostPortPair server3("docs.example.org", kDefaultServerPort);
2345 HostPortPair server4("images.example.org", kDefaultServerPort);
2347 crypto_client_stream_factory_.set_handshake_mode(
2348 MockCryptoClientStream::CONFIRM_HANDSHAKE);
2349 host_resolver_.set_synchronous_mode(true);
2350 host_resolver_.rules()->AddIPLiteralRule(host_port_pair_.host(),
2351 "192.168.0.1", "");
2352 host_resolver_.rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", "");
2353 host_resolver_.rules()->AddIPLiteralRule(server3.host(), "192.168.0.1", "");
2354 host_resolver_.rules()->AddIPLiteralRule(server4.host(), "192.168.0.1", "");
2356 // Test first and fourth out of three timeouts with open streams.
2357 QuicStreamRequest request(&factory_);
2358 EXPECT_EQ(OK, request.Request(host_port_pair_, is_https_, privacy_mode_,
2359 /*cert_verify_flags=*/0, host_port_pair_.host(),
2360 "GET", net_log_, callback_.callback()));
2362 QuicChromiumClientSession* session = QuicStreamFactoryPeer::GetActiveSession(
2363 &factory_, host_port_pair_, is_https_);
2365 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2366 EXPECT_TRUE(stream.get());
2367 HttpRequestInfo request_info;
2368 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
2369 net_log_, CompletionCallback()));
2371 DVLOG(1)
2372 << "Created 1st session and initialized a stream. Now trigger timeout";
2373 session->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2374 // Need to spin the loop now to ensure that
2375 // QuicStreamFactory::OnSessionClosed() runs.
2376 base::RunLoop run_loop;
2377 run_loop.RunUntilIdle();
2379 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2380 EXPECT_FALSE(
2381 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2383 DVLOG(1) << "Create 2nd and 3rd sessions without timeout";
2384 TestCompletionCallback callback2;
2385 QuicStreamRequest request2(&factory_);
2386 EXPECT_EQ(OK, request2.Request(server2, is_https_, privacy_mode_,
2387 /*cert_verify_flags=*/0, server2.host(), "GET",
2388 net_log_, callback2.callback()));
2389 QuicChromiumClientSession* session2 =
2390 QuicStreamFactoryPeer::GetActiveSession(&factory_, server2, is_https_);
2392 session2->connection()->CloseConnection(QUIC_NO_ERROR, true);
2393 // Need to spin the loop now to ensure that
2394 // QuicStreamFactory::OnSessionClosed() runs.
2395 base::RunLoop run_loop2;
2396 run_loop2.RunUntilIdle();
2397 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2398 EXPECT_FALSE(
2399 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2401 TestCompletionCallback callback3;
2402 QuicStreamRequest request3(&factory_);
2403 EXPECT_EQ(OK, request3.Request(server3, is_https_, privacy_mode_,
2404 /*cert_verify_flags=*/0, server3.host(), "GET",
2405 net_log_, callback3.callback()));
2406 QuicChromiumClientSession* session3 =
2407 QuicStreamFactoryPeer::GetActiveSession(&factory_, server3, is_https_);
2409 session3->connection()->CloseConnection(QUIC_NO_ERROR, true);
2410 // Need to spin the loop now to ensure that
2411 // QuicStreamFactory::OnSessionClosed() runs.
2412 base::RunLoop run_loop3;
2413 run_loop3.RunUntilIdle();
2414 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2415 EXPECT_FALSE(
2416 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2418 DVLOG(1) << "Create 4th session with timeout with open streams,"
2419 << " will not disable QUIC";
2421 TestCompletionCallback callback4;
2422 QuicStreamRequest request4(&factory_);
2423 EXPECT_EQ(OK, request4.Request(server4, is_https_, privacy_mode_,
2424 /*cert_verify_flags=*/0, server4.host(), "GET",
2425 net_log_, callback4.callback()));
2426 QuicChromiumClientSession* session4 =
2427 QuicStreamFactoryPeer::GetActiveSession(&factory_, server4, is_https_);
2429 scoped_ptr<QuicHttpStream> stream4 = request4.ReleaseStream();
2430 EXPECT_TRUE(stream4.get());
2431 EXPECT_EQ(OK, stream4->InitializeStream(&request_info, DEFAULT_PRIORITY,
2432 net_log_, CompletionCallback()));
2433 session4->connection()->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
2434 // Need to spin the loop now to ensure that
2435 // QuicStreamFactory::OnSessionClosed() runs.
2436 base::RunLoop run_loop4;
2437 run_loop4.RunUntilIdle();
2438 EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumTimeoutsWithOpenStreams(&factory_));
2439 EXPECT_FALSE(
2440 QuicStreamFactoryPeer::IsQuicDisabled(&factory_, host_port_pair_.port()));
2442 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
2443 EXPECT_TRUE(stream2.get());
2444 scoped_ptr<QuicHttpStream> stream3 = request3.ReleaseStream();
2445 EXPECT_TRUE(stream3.get());
2446 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2447 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2448 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
2449 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
2450 EXPECT_TRUE(socket_data3.AllReadDataConsumed());
2451 EXPECT_TRUE(socket_data3.AllWriteDataConsumed());
2452 EXPECT_TRUE(socket_data4.AllReadDataConsumed());
2453 EXPECT_TRUE(socket_data4.AllWriteDataConsumed());
2456 } // namespace test
2457 } // namespace net