Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / net / quic / quic_session_test.cc
blob4e79df15a336bbfaafabe266c6aead932d4fe732
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_session.h"
7 #include <set>
9 #include "base/basictypes.h"
10 #include "base/containers/hash_tables.h"
11 #include "base/rand_util.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string_number_conversions.h"
14 #include "net/quic/crypto/crypto_protocol.h"
15 #include "net/quic/quic_crypto_stream.h"
16 #include "net/quic/quic_flags.h"
17 #include "net/quic/quic_protocol.h"
18 #include "net/quic/quic_utils.h"
19 #include "net/quic/reliable_quic_stream.h"
20 #include "net/quic/test_tools/quic_config_peer.h"
21 #include "net/quic/test_tools/quic_connection_peer.h"
22 #include "net/quic/test_tools/quic_data_stream_peer.h"
23 #include "net/quic/test_tools/quic_flow_controller_peer.h"
24 #include "net/quic/test_tools/quic_session_peer.h"
25 #include "net/quic/test_tools/quic_test_utils.h"
26 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
27 #include "net/spdy/spdy_framer.h"
28 #include "net/test/gtest_util.h"
29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gmock_mutant.h"
31 #include "testing/gtest/include/gtest/gtest.h"
33 using base::hash_map;
34 using std::set;
35 using std::string;
36 using std::vector;
37 using testing::CreateFunctor;
38 using testing::InSequence;
39 using testing::Invoke;
40 using testing::Return;
41 using testing::StrictMock;
42 using testing::_;
44 namespace net {
45 namespace test {
46 namespace {
48 const QuicPriority kHighestPriority = 0;
49 const QuicPriority kSomeMiddlePriority = 3;
51 class TestCryptoStream : public QuicCryptoStream {
52 public:
53 explicit TestCryptoStream(QuicSession* session)
54 : QuicCryptoStream(session) {
57 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override {
58 encryption_established_ = true;
59 handshake_confirmed_ = true;
60 CryptoHandshakeMessage msg;
61 string error_details;
62 session()->config()->SetInitialStreamFlowControlWindowToSend(
63 kInitialStreamFlowControlWindowForTest);
64 session()->config()->SetInitialSessionFlowControlWindowToSend(
65 kInitialSessionFlowControlWindowForTest);
66 session()->config()->ToHandshakeMessage(&msg);
67 const QuicErrorCode error = session()->config()->ProcessPeerHello(
68 msg, CLIENT, &error_details);
69 EXPECT_EQ(QUIC_NO_ERROR, error);
70 session()->OnConfigNegotiated();
71 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
74 MOCK_METHOD0(OnCanWrite, void());
77 class TestHeadersStream : public QuicHeadersStream {
78 public:
79 explicit TestHeadersStream(QuicSession* session)
80 : QuicHeadersStream(session) {
83 MOCK_METHOD0(OnCanWrite, void());
86 class TestStream : public QuicDataStream {
87 public:
88 TestStream(QuicStreamId id, QuicSession* session)
89 : QuicDataStream(id, session) {
92 using ReliableQuicStream::CloseWriteSide;
94 uint32 ProcessData(const char* data, uint32 data_len) override {
95 return data_len;
98 void SendBody(const string& data, bool fin) {
99 WriteOrBufferData(data, fin, nullptr);
102 MOCK_METHOD0(OnCanWrite, void());
105 // Poor man's functor for use as callback in a mock.
106 class StreamBlocker {
107 public:
108 StreamBlocker(QuicSession* session, QuicStreamId stream_id)
109 : session_(session),
110 stream_id_(stream_id) {
113 void MarkWriteBlocked() {
114 session_->MarkWriteBlocked(stream_id_, kSomeMiddlePriority);
117 private:
118 QuicSession* const session_;
119 const QuicStreamId stream_id_;
122 class TestSession : public QuicSession {
123 public:
124 explicit TestSession(QuicConnection* connection)
125 : QuicSession(connection, DefaultQuicConfig()),
126 crypto_stream_(this),
127 writev_consumes_all_data_(false) {
128 InitializeSession();
131 TestCryptoStream* GetCryptoStream() override { return &crypto_stream_; }
133 TestStream* CreateOutgoingDataStream() override {
134 TestStream* stream = new TestStream(GetNextStreamId(), this);
135 ActivateStream(stream);
136 return stream;
139 TestStream* CreateIncomingDataStream(QuicStreamId id) override {
140 return new TestStream(id, this);
143 bool IsClosedStream(QuicStreamId id) {
144 return QuicSession::IsClosedStream(id);
147 QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id) {
148 return QuicSession::GetIncomingDataStream(stream_id);
151 QuicConsumedData WritevData(
152 QuicStreamId id,
153 const IOVector& data,
154 QuicStreamOffset offset,
155 bool fin,
156 FecProtection fec_protection,
157 QuicAckNotifier::DelegateInterface* ack_notifier_delegate) override {
158 // Always consumes everything.
159 if (writev_consumes_all_data_) {
160 return QuicConsumedData(data.TotalBufferSize(), fin);
161 } else {
162 return QuicSession::WritevData(id, data, offset, fin, fec_protection,
163 ack_notifier_delegate);
167 void set_writev_consumes_all_data(bool val) {
168 writev_consumes_all_data_ = val;
171 QuicConsumedData SendStreamData(QuicStreamId id) {
172 return WritevData(id, MakeIOVector("not empty"), 0, true, MAY_FEC_PROTECT,
173 nullptr);
176 using QuicSession::PostProcessAfterData;
178 private:
179 StrictMock<TestCryptoStream> crypto_stream_;
181 bool writev_consumes_all_data_;
184 class QuicSessionTestBase : public ::testing::TestWithParam<QuicVersion> {
185 protected:
186 explicit QuicSessionTestBase(Perspective perspective)
187 : connection_(
188 new StrictMock<MockConnection>(perspective,
189 SupportedVersions(GetParam()))),
190 session_(connection_) {
191 session_.config()->SetInitialStreamFlowControlWindowToSend(
192 kInitialStreamFlowControlWindowForTest);
193 session_.config()->SetInitialSessionFlowControlWindowToSend(
194 kInitialSessionFlowControlWindowForTest);
195 headers_[":host"] = "www.google.com";
196 headers_[":path"] = "/index.hml";
197 headers_[":scheme"] = "http";
198 headers_["cookie"] =
199 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
200 "__utmc=160408618; "
201 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
202 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX"
203 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT"
204 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0"
205 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh"
206 "1zFMi5vzcns38-8_Sns; "
207 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-"
208 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339"
209 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c"
210 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%"
211 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4"
212 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1"
213 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
214 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
215 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
216 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
217 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
218 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
219 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
220 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
221 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
222 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
225 void CheckClosedStreams() {
226 for (int i = kCryptoStreamId; i < 100; i++) {
227 if (!ContainsKey(closed_streams_, i)) {
228 EXPECT_FALSE(session_.IsClosedStream(i)) << " stream id: " << i;
229 } else {
230 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i;
235 void CloseStream(QuicStreamId id) {
236 EXPECT_CALL(*connection_, SendRstStream(id, _, _));
237 session_.CloseStream(id);
238 closed_streams_.insert(id);
241 QuicVersion version() const { return connection_->version(); }
243 StrictMock<MockConnection>* connection_;
244 TestSession session_;
245 set<QuicStreamId> closed_streams_;
246 SpdyHeaderBlock headers_;
249 class QuicSessionTestServer : public QuicSessionTestBase {
250 protected:
251 QuicSessionTestServer() : QuicSessionTestBase(Perspective::IS_SERVER) {}
254 INSTANTIATE_TEST_CASE_P(Tests,
255 QuicSessionTestServer,
256 ::testing::ValuesIn(QuicSupportedVersions()));
258 TEST_P(QuicSessionTestServer, PeerAddress) {
259 EXPECT_EQ(IPEndPoint(Loopback4(), kTestPort), session_.peer_address());
262 TEST_P(QuicSessionTestServer, IsCryptoHandshakeConfirmed) {
263 EXPECT_FALSE(session_.IsCryptoHandshakeConfirmed());
264 CryptoHandshakeMessage message;
265 session_.GetCryptoStream()->OnHandshakeMessage(message);
266 EXPECT_TRUE(session_.IsCryptoHandshakeConfirmed());
269 TEST_P(QuicSessionTestServer, IsClosedStreamDefault) {
270 // Ensure that no streams are initially closed.
271 for (int i = kCryptoStreamId; i < 100; i++) {
272 EXPECT_FALSE(session_.IsClosedStream(i)) << "stream id: " << i;
276 TEST_P(QuicSessionTestServer, ImplicitlyCreatedStreams) {
277 ASSERT_TRUE(session_.GetIncomingDataStream(9) != nullptr);
278 // Both 5 and 7 should be implicitly created.
279 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5));
280 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 7));
281 ASSERT_TRUE(session_.GetIncomingDataStream(7) != nullptr);
282 ASSERT_TRUE(session_.GetIncomingDataStream(5) != nullptr);
285 TEST_P(QuicSessionTestServer, IsClosedStreamLocallyCreated) {
286 TestStream* stream2 = session_.CreateOutgoingDataStream();
287 EXPECT_EQ(2u, stream2->id());
288 TestStream* stream4 = session_.CreateOutgoingDataStream();
289 EXPECT_EQ(4u, stream4->id());
291 CheckClosedStreams();
292 CloseStream(4);
293 CheckClosedStreams();
294 CloseStream(2);
295 CheckClosedStreams();
298 TEST_P(QuicSessionTestServer, IsClosedStreamPeerCreated) {
299 QuicStreamId stream_id1 = kClientDataStreamId1;
300 QuicStreamId stream_id2 = kClientDataStreamId2;
301 QuicDataStream* stream1 = session_.GetIncomingDataStream(stream_id1);
302 QuicDataStreamPeer::SetHeadersDecompressed(stream1, true);
303 QuicDataStream* stream2 = session_.GetIncomingDataStream(stream_id2);
304 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true);
306 CheckClosedStreams();
307 CloseStream(stream_id1);
308 CheckClosedStreams();
309 CloseStream(stream_id2);
310 // Create a stream explicitly, and another implicitly.
311 QuicDataStream* stream3 = session_.GetIncomingDataStream(stream_id2 + 4);
312 QuicDataStreamPeer::SetHeadersDecompressed(stream3, true);
313 CheckClosedStreams();
314 // Close one, but make sure the other is still not closed
315 CloseStream(stream3->id());
316 CheckClosedStreams();
319 TEST_P(QuicSessionTestServer, StreamIdTooLarge) {
320 QuicStreamId stream_id = kClientDataStreamId1;
321 session_.GetIncomingDataStream(stream_id);
322 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID));
323 session_.GetIncomingDataStream(stream_id + kMaxStreamIdDelta + 2);
326 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) {
327 TestStream* stream2 = session_.CreateOutgoingDataStream();
328 QuicStreamId kClosedStreamId = stream2->id();
329 // Close the stream.
330 EXPECT_CALL(*connection_, SendRstStream(kClosedStreamId, _, _));
331 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD);
332 EXPECT_DEBUG_DFATAL(
333 session_.MarkWriteBlocked(kClosedStreamId, kSomeMiddlePriority),
334 "Marking unknown stream 2 blocked.");
337 TEST_P(QuicSessionTestServer,
338 DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) {
339 const QuicPriority kDifferentPriority = 0;
341 TestStream* stream2 = session_.CreateOutgoingDataStream();
342 EXPECT_NE(kDifferentPriority, stream2->EffectivePriority());
343 EXPECT_DEBUG_DFATAL(
344 session_.MarkWriteBlocked(stream2->id(), kDifferentPriority),
345 "Priorities do not match. Got: 0 Expected: 3");
348 TEST_P(QuicSessionTestServer, OnCanWrite) {
349 TestStream* stream2 = session_.CreateOutgoingDataStream();
350 TestStream* stream4 = session_.CreateOutgoingDataStream();
351 TestStream* stream6 = session_.CreateOutgoingDataStream();
353 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
354 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
355 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
357 InSequence s;
358 StreamBlocker stream2_blocker(&session_, stream2->id());
359 // Reregister, to test the loop limit.
360 EXPECT_CALL(*stream2, OnCanWrite())
361 .WillOnce(Invoke(&stream2_blocker, &StreamBlocker::MarkWriteBlocked));
362 EXPECT_CALL(*stream6, OnCanWrite());
363 EXPECT_CALL(*stream4, OnCanWrite());
364 session_.OnCanWrite();
365 EXPECT_TRUE(session_.WillingAndAbleToWrite());
368 TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) {
369 // Drive congestion control manually.
370 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>;
371 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm);
373 TestStream* stream2 = session_.CreateOutgoingDataStream();
374 TestStream* stream4 = session_.CreateOutgoingDataStream();
375 TestStream* stream6 = session_.CreateOutgoingDataStream();
377 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
378 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
379 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
381 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillRepeatedly(
382 Return(QuicTime::Delta::Zero()));
383 EXPECT_CALL(*send_algorithm, GetCongestionWindow())
384 .WillRepeatedly(Return(kMaxPacketSize * 10));
385 EXPECT_CALL(*stream2, OnCanWrite())
386 .WillOnce(IgnoreResult(Invoke(CreateFunctor(
387 &session_, &TestSession::SendStreamData, stream2->id()))));
388 EXPECT_CALL(*stream4, OnCanWrite())
389 .WillOnce(IgnoreResult(Invoke(CreateFunctor(
390 &session_, &TestSession::SendStreamData, stream4->id()))));
391 EXPECT_CALL(*stream6, OnCanWrite())
392 .WillOnce(IgnoreResult(Invoke(CreateFunctor(
393 &session_, &TestSession::SendStreamData, stream6->id()))));
395 // Expect that we only send one packet, the writes from different streams
396 // should be bundled together.
397 MockPacketWriter* writer =
398 static_cast<MockPacketWriter*>(
399 QuicConnectionPeer::GetWriter(session_.connection()));
400 EXPECT_CALL(*writer, WritePacket(_, _, _, _)).WillOnce(
401 Return(WriteResult(WRITE_STATUS_OK, 0)));
402 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)).Times(1);
403 session_.OnCanWrite();
404 EXPECT_FALSE(session_.WillingAndAbleToWrite());
407 TEST_P(QuicSessionTestServer, OnCanWriteCongestionControlBlocks) {
408 InSequence s;
410 // Drive congestion control manually.
411 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>;
412 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm);
414 TestStream* stream2 = session_.CreateOutgoingDataStream();
415 TestStream* stream4 = session_.CreateOutgoingDataStream();
416 TestStream* stream6 = session_.CreateOutgoingDataStream();
418 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
419 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
420 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
422 StreamBlocker stream2_blocker(&session_, stream2->id());
423 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
424 QuicTime::Delta::Zero()));
425 EXPECT_CALL(*stream2, OnCanWrite());
426 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
427 QuicTime::Delta::Zero()));
428 EXPECT_CALL(*stream6, OnCanWrite());
429 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
430 QuicTime::Delta::Infinite()));
431 // stream4->OnCanWrite is not called.
433 session_.OnCanWrite();
434 EXPECT_TRUE(session_.WillingAndAbleToWrite());
436 // Still congestion-control blocked.
437 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
438 QuicTime::Delta::Infinite()));
439 session_.OnCanWrite();
440 EXPECT_TRUE(session_.WillingAndAbleToWrite());
442 // stream4->OnCanWrite is called once the connection stops being
443 // congestion-control blocked.
444 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
445 QuicTime::Delta::Zero()));
446 EXPECT_CALL(*stream4, OnCanWrite());
447 session_.OnCanWrite();
448 EXPECT_FALSE(session_.WillingAndAbleToWrite());
451 TEST_P(QuicSessionTestServer, BufferedHandshake) {
452 EXPECT_FALSE(session_.HasPendingHandshake()); // Default value.
454 // Test that blocking other streams does not change our status.
455 TestStream* stream2 = session_.CreateOutgoingDataStream();
456 StreamBlocker stream2_blocker(&session_, stream2->id());
457 stream2_blocker.MarkWriteBlocked();
458 EXPECT_FALSE(session_.HasPendingHandshake());
460 TestStream* stream3 = session_.CreateOutgoingDataStream();
461 StreamBlocker stream3_blocker(&session_, stream3->id());
462 stream3_blocker.MarkWriteBlocked();
463 EXPECT_FALSE(session_.HasPendingHandshake());
465 // Blocking (due to buffering of) the Crypto stream is detected.
466 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority);
467 EXPECT_TRUE(session_.HasPendingHandshake());
469 TestStream* stream4 = session_.CreateOutgoingDataStream();
470 StreamBlocker stream4_blocker(&session_, stream4->id());
471 stream4_blocker.MarkWriteBlocked();
472 EXPECT_TRUE(session_.HasPendingHandshake());
474 InSequence s;
475 // Force most streams to re-register, which is common scenario when we block
476 // the Crypto stream, and only the crypto stream can "really" write.
478 // Due to prioritization, we *should* be asked to write the crypto stream
479 // first.
480 // Don't re-register the crypto stream (which signals complete writing).
481 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
482 EXPECT_CALL(*crypto_stream, OnCanWrite());
484 // Re-register all other streams, to show they weren't able to proceed.
485 EXPECT_CALL(*stream2, OnCanWrite())
486 .WillOnce(Invoke(&stream2_blocker, &StreamBlocker::MarkWriteBlocked));
487 EXPECT_CALL(*stream3, OnCanWrite())
488 .WillOnce(Invoke(&stream3_blocker, &StreamBlocker::MarkWriteBlocked));
489 EXPECT_CALL(*stream4, OnCanWrite())
490 .WillOnce(Invoke(&stream4_blocker, &StreamBlocker::MarkWriteBlocked));
492 session_.OnCanWrite();
493 EXPECT_TRUE(session_.WillingAndAbleToWrite());
494 EXPECT_FALSE(session_.HasPendingHandshake()); // Crypto stream wrote.
497 TEST_P(QuicSessionTestServer, OnCanWriteWithClosedStream) {
498 TestStream* stream2 = session_.CreateOutgoingDataStream();
499 TestStream* stream4 = session_.CreateOutgoingDataStream();
500 TestStream* stream6 = session_.CreateOutgoingDataStream();
502 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
503 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
504 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
505 CloseStream(stream6->id());
507 InSequence s;
508 EXPECT_CALL(*stream2, OnCanWrite());
509 EXPECT_CALL(*stream4, OnCanWrite());
510 session_.OnCanWrite();
511 EXPECT_FALSE(session_.WillingAndAbleToWrite());
514 TEST_P(QuicSessionTestServer, OnCanWriteLimitsNumWritesIfFlowControlBlocked) {
515 // Ensure connection level flow control blockage.
516 QuicFlowControllerPeer::SetSendWindowOffset(session_.flow_controller(), 0);
517 EXPECT_TRUE(session_.flow_controller()->IsBlocked());
518 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked());
519 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
521 // Mark the crypto and headers streams as write blocked, we expect them to be
522 // allowed to write later.
523 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority);
524 session_.MarkWriteBlocked(kHeadersStreamId, kHighestPriority);
526 // Create a data stream, and although it is write blocked we never expect it
527 // to be allowed to write as we are connection level flow control blocked.
528 TestStream* stream = session_.CreateOutgoingDataStream();
529 session_.MarkWriteBlocked(stream->id(), kSomeMiddlePriority);
530 EXPECT_CALL(*stream, OnCanWrite()).Times(0);
532 // The crypto and headers streams should be called even though we are
533 // connection flow control blocked.
534 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
535 EXPECT_CALL(*crypto_stream, OnCanWrite()).Times(1);
536 TestHeadersStream* headers_stream = new TestHeadersStream(&session_);
537 QuicSessionPeer::SetHeadersStream(&session_, headers_stream);
538 EXPECT_CALL(*headers_stream, OnCanWrite()).Times(1);
540 session_.OnCanWrite();
541 EXPECT_FALSE(session_.WillingAndAbleToWrite());
544 TEST_P(QuicSessionTestServer, SendGoAway) {
545 EXPECT_CALL(*connection_,
546 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away."));
547 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
548 EXPECT_TRUE(session_.goaway_sent());
550 EXPECT_CALL(*connection_,
551 SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY, 0)).Times(0);
552 EXPECT_TRUE(session_.GetIncomingDataStream(3u));
555 TEST_P(QuicSessionTestServer, DoNotSendGoAwayTwice) {
556 EXPECT_CALL(*connection_,
557 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")).Times(1);
558 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
559 EXPECT_TRUE(session_.goaway_sent());
560 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
563 TEST_P(QuicSessionTestServer, IncreasedTimeoutAfterCryptoHandshake) {
564 EXPECT_EQ(kInitialIdleTimeoutSecs + 3,
565 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
566 CryptoHandshakeMessage msg;
567 session_.GetCryptoStream()->OnHandshakeMessage(msg);
568 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3,
569 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
572 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) {
573 // Send two bytes of payload.
574 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT"));
575 vector<QuicStreamFrame> frames;
576 frames.push_back(data1);
577 session_.OnStreamFrames(frames);
578 EXPECT_EQ(1u, session_.GetNumOpenStreams());
580 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _));
581 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0);
582 session_.OnRstStream(rst1);
583 EXPECT_EQ(0u, session_.GetNumOpenStreams());
584 // Connection should remain alive.
585 EXPECT_TRUE(connection_->connected());
588 TEST_P(QuicSessionTestServer, MultipleRstStreamsCauseSingleConnectionClose) {
589 // If multiple invalid reset stream frames arrive in a single packet, this
590 // should trigger a connection close. However there is no need to send
591 // multiple connection close frames.
593 // Create valid stream.
594 QuicStreamFrame data1(kClientDataStreamId1, false, 0, MakeIOVector("HT"));
595 vector<QuicStreamFrame> frames;
596 frames.push_back(data1);
597 session_.OnStreamFrames(frames);
598 EXPECT_EQ(1u, session_.GetNumOpenStreams());
600 // Process first invalid stream reset, resulting in the connection being
601 // closed.
602 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID))
603 .Times(1);
604 QuicStreamId kLargeInvalidStreamId = 99999999;
605 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0);
606 session_.OnRstStream(rst1);
607 QuicConnectionPeer::CloseConnection(connection_);
609 // Processing of second invalid stream reset should not result in the
610 // connection being closed for a second time.
611 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0);
612 session_.OnRstStream(rst2);
615 TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedStream) {
616 // Test that if a stream is flow control blocked, then on receipt of the SHLO
617 // containing a suitable send window offset, the stream becomes unblocked.
619 // Ensure that Writev consumes all the data it is given (simulate no socket
620 // blocking).
621 session_.set_writev_consumes_all_data(true);
623 // Create a stream, and send enough data to make it flow control blocked.
624 TestStream* stream2 = session_.CreateOutgoingDataStream();
625 string body(kMinimumFlowControlSendWindow, '.');
626 EXPECT_FALSE(stream2->flow_controller()->IsBlocked());
627 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
628 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
629 EXPECT_CALL(*connection_, SendBlocked(stream2->id()));
630 EXPECT_CALL(*connection_, SendBlocked(0));
631 stream2->SendBody(body, false);
632 EXPECT_TRUE(stream2->flow_controller()->IsBlocked());
633 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked());
634 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
636 // The handshake message will call OnCanWrite, so the stream can resume
637 // writing.
638 EXPECT_CALL(*stream2, OnCanWrite());
639 // Now complete the crypto handshake, resulting in an increased flow control
640 // send window.
641 CryptoHandshakeMessage msg;
642 session_.GetCryptoStream()->OnHandshakeMessage(msg);
644 // Stream is now unblocked.
645 EXPECT_FALSE(stream2->flow_controller()->IsBlocked());
646 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
647 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
650 TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedCryptoStream) {
651 // Test that if the crypto stream is flow control blocked, then if the SHLO
652 // contains a larger send window offset, the stream becomes unblocked.
653 session_.set_writev_consumes_all_data(true);
654 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
655 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
656 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
657 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
658 QuicHeadersStream* headers_stream =
659 QuicSessionPeer::GetHeadersStream(&session_);
660 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
661 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
662 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
663 // Write until the crypto stream is flow control blocked.
664 EXPECT_CALL(*connection_, SendBlocked(kCryptoStreamId));
665 int i = 0;
666 while (!crypto_stream->flow_controller()->IsBlocked() && i < 1000) {
667 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
668 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
669 QuicConfig config;
670 CryptoHandshakeMessage crypto_message;
671 config.ToHandshakeMessage(&crypto_message);
672 crypto_stream->SendHandshakeMessage(crypto_message);
673 ++i;
675 EXPECT_TRUE(crypto_stream->flow_controller()->IsBlocked());
676 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
677 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
678 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
679 EXPECT_FALSE(session_.HasDataToWrite());
680 EXPECT_TRUE(crypto_stream->HasBufferedData());
682 // The handshake message will call OnCanWrite, so the stream can
683 // resume writing.
684 EXPECT_CALL(*crypto_stream, OnCanWrite());
685 // Now complete the crypto handshake, resulting in an increased flow control
686 // send window.
687 CryptoHandshakeMessage msg;
688 session_.GetCryptoStream()->OnHandshakeMessage(msg);
690 // Stream is now unblocked and will no longer have buffered data.
691 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
692 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
693 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
696 TEST_P(QuicSessionTestServer,
697 HandshakeUnblocksFlowControlBlockedHeadersStream) {
698 // Test that if the header stream is flow control blocked, then if the SHLO
699 // contains a larger send window offset, the stream becomes unblocked.
700 session_.set_writev_consumes_all_data(true);
701 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
702 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
703 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
704 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
705 QuicHeadersStream* headers_stream =
706 QuicSessionPeer::GetHeadersStream(&session_);
707 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
708 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
709 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
710 QuicStreamId stream_id = 5;
711 // Write until the header stream is flow control blocked.
712 EXPECT_CALL(*connection_, SendBlocked(kHeadersStreamId));
713 SpdyHeaderBlock headers;
714 while (!headers_stream->flow_controller()->IsBlocked() && stream_id < 2000) {
715 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
716 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
717 headers["header"] = base::Uint64ToString(base::RandUint64()) +
718 base::Uint64ToString(base::RandUint64()) +
719 base::Uint64ToString(base::RandUint64());
720 headers_stream->WriteHeaders(stream_id, headers, true, 0, nullptr);
721 stream_id += 2;
723 // Write once more to ensure that the headers stream has buffered data. The
724 // random headers may have exactly filled the flow control window.
725 headers_stream->WriteHeaders(stream_id, headers, true, 0, nullptr);
726 EXPECT_TRUE(headers_stream->HasBufferedData());
728 EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
729 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
730 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
731 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
732 EXPECT_FALSE(session_.HasDataToWrite());
734 // Now complete the crypto handshake, resulting in an increased flow control
735 // send window.
736 CryptoHandshakeMessage msg;
737 session_.GetCryptoStream()->OnHandshakeMessage(msg);
739 // Stream is now unblocked and will no longer have buffered data.
740 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
741 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
742 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
743 EXPECT_FALSE(headers_stream->HasBufferedData());
746 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstOutOfOrder) {
747 // Test that when we receive an out of order stream RST we correctly adjust
748 // our connection level flow control receive window.
749 // On close, the stream should mark as consumed all bytes between the highest
750 // byte consumed so far and the final byte offset from the RST frame.
751 TestStream* stream = session_.CreateOutgoingDataStream();
753 const QuicStreamOffset kByteOffset =
754 1 + kInitialSessionFlowControlWindowForTest / 2;
756 // Expect no stream WINDOW_UPDATE frames, as stream read side closed.
757 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0);
758 // We do expect a connection level WINDOW_UPDATE when the stream is reset.
759 EXPECT_CALL(*connection_,
760 SendWindowUpdate(0, kInitialSessionFlowControlWindowForTest +
761 kByteOffset)).Times(1);
763 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
764 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
765 kByteOffset);
766 session_.OnRstStream(rst_frame);
767 session_.PostProcessAfterData();
768 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed());
771 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAndLocalReset) {
772 // Test the situation where we receive a FIN on a stream, and before we fully
773 // consume all the data from the sequencer buffer we locally RST the stream.
774 // The bytes between highest consumed byte, and the final byte offset that we
775 // determined when the FIN arrived, should be marked as consumed at the
776 // connection level flow controller when the stream is reset.
777 TestStream* stream = session_.CreateOutgoingDataStream();
779 const QuicStreamOffset kByteOffset =
780 kInitialSessionFlowControlWindowForTest / 2;
781 QuicStreamFrame frame(stream->id(), true, kByteOffset, IOVector());
782 vector<QuicStreamFrame> frames;
783 frames.push_back(frame);
784 session_.OnStreamFrames(frames);
785 session_.PostProcessAfterData();
786 EXPECT_TRUE(connection_->connected());
788 EXPECT_EQ(0u, stream->flow_controller()->bytes_consumed());
789 EXPECT_EQ(kByteOffset,
790 stream->flow_controller()->highest_received_byte_offset());
792 // Reset stream locally.
793 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
794 stream->Reset(QUIC_STREAM_CANCELLED);
795 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed());
798 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAfterRst) {
799 // Test that when we RST the stream (and tear down stream state), and then
800 // receive a FIN from the peer, we correctly adjust our connection level flow
801 // control receive window.
803 // Connection starts with some non-zero highest received byte offset,
804 // due to other active streams.
805 const uint64 kInitialConnectionBytesConsumed = 567;
806 const uint64 kInitialConnectionHighestReceivedOffset = 1234;
807 EXPECT_LT(kInitialConnectionBytesConsumed,
808 kInitialConnectionHighestReceivedOffset);
809 session_.flow_controller()->UpdateHighestReceivedOffset(
810 kInitialConnectionHighestReceivedOffset);
811 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed);
813 // Reset our stream: this results in the stream being closed locally.
814 TestStream* stream = session_.CreateOutgoingDataStream();
815 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
816 stream->Reset(QUIC_STREAM_CANCELLED);
818 // Now receive a response from the peer with a FIN. We should handle this by
819 // adjusting the connection level flow control receive window to take into
820 // account the total number of bytes sent by the peer.
821 const QuicStreamOffset kByteOffset = 5678;
822 string body = "hello";
823 IOVector data = MakeIOVector(body);
824 QuicStreamFrame frame(stream->id(), true, kByteOffset, data);
825 vector<QuicStreamFrame> frames;
826 frames.push_back(frame);
827 session_.OnStreamFrames(frames);
829 QuicStreamOffset total_stream_bytes_sent_by_peer =
830 kByteOffset + body.length();
831 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer,
832 session_.flow_controller()->bytes_consumed());
833 EXPECT_EQ(
834 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer,
835 session_.flow_controller()->highest_received_byte_offset());
838 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstAfterRst) {
839 // Test that when we RST the stream (and tear down stream state), and then
840 // receive a RST from the peer, we correctly adjust our connection level flow
841 // control receive window.
843 // Connection starts with some non-zero highest received byte offset,
844 // due to other active streams.
845 const uint64 kInitialConnectionBytesConsumed = 567;
846 const uint64 kInitialConnectionHighestReceivedOffset = 1234;
847 EXPECT_LT(kInitialConnectionBytesConsumed,
848 kInitialConnectionHighestReceivedOffset);
849 session_.flow_controller()->UpdateHighestReceivedOffset(
850 kInitialConnectionHighestReceivedOffset);
851 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed);
853 // Reset our stream: this results in the stream being closed locally.
854 TestStream* stream = session_.CreateOutgoingDataStream();
855 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
856 stream->Reset(QUIC_STREAM_CANCELLED);
858 // Now receive a RST from the peer. We should handle this by adjusting the
859 // connection level flow control receive window to take into account the total
860 // number of bytes sent by the peer.
861 const QuicStreamOffset kByteOffset = 5678;
862 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
863 kByteOffset);
864 session_.OnRstStream(rst_frame);
866 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset,
867 session_.flow_controller()->bytes_consumed());
868 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset,
869 session_.flow_controller()->highest_received_byte_offset());
872 TEST_P(QuicSessionTestServer, InvalidStreamFlowControlWindowInHandshake) {
873 // Test that receipt of an invalid (< default) stream flow control window from
874 // the peer results in the connection being torn down.
875 uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1;
876 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(),
877 kInvalidWindow);
879 EXPECT_CALL(*connection_,
880 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW));
881 session_.OnConfigNegotiated();
884 TEST_P(QuicSessionTestServer, InvalidSessionFlowControlWindowInHandshake) {
885 // Test that receipt of an invalid (< default) session flow control window
886 // from the peer results in the connection being torn down.
887 uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1;
888 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(),
889 kInvalidWindow);
891 EXPECT_CALL(*connection_,
892 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW));
893 session_.OnConfigNegotiated();
896 TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) {
897 // Test that if we receive a stream RST with a highest byte offset that
898 // violates flow control, that we close the connection.
899 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1;
900 EXPECT_CALL(*connection_,
901 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA))
902 .Times(2);
904 // Check that stream frame + FIN results in connection close.
905 TestStream* stream = session_.CreateOutgoingDataStream();
906 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
907 stream->Reset(QUIC_STREAM_CANCELLED);
908 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector());
909 vector<QuicStreamFrame> frames;
910 frames.push_back(frame);
911 session_.OnStreamFrames(frames);
913 // Check that RST results in connection close.
914 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
915 kLargeOffset);
916 session_.OnRstStream(rst_frame);
919 TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) {
920 // Test that a flow control blocked headers stream gets unblocked on recipt of
921 // a WINDOW_UPDATE frame. Regression test for b/17413860.
923 // Set the headers stream to be flow control blocked.
924 QuicHeadersStream* headers_stream =
925 QuicSessionPeer::GetHeadersStream(&session_);
926 QuicFlowControllerPeer::SetSendWindowOffset(headers_stream->flow_controller(),
928 EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
929 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
930 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
932 // Unblock the headers stream by supplying a WINDOW_UPDATE.
933 QuicWindowUpdateFrame window_update_frame(headers_stream->id(),
934 2 * kMinimumFlowControlSendWindow);
935 vector<QuicWindowUpdateFrame> frames;
936 frames.push_back(window_update_frame);
937 session_.OnWindowUpdateFrames(frames);
938 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
939 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
940 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
943 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseConnectionClose) {
944 // If a buggy/malicious peer creates too many streams that are not ended with
945 // a FIN or RST then we send a connection close.
946 EXPECT_CALL(*connection_,
947 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(1);
949 const int kMaxStreams = 5;
950 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams);
952 // Create kMaxStreams + 1 data streams, and close them all without receiving a
953 // FIN or a RST from the client.
954 const int kFirstStreamId = kClientDataStreamId1;
955 const int kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams + 1;
956 for (int i = kFirstStreamId; i < kFinalStreamId; i += 2) {
957 QuicStreamFrame data1(i, false, 0, MakeIOVector("HT"));
958 vector<QuicStreamFrame> frames;
959 frames.push_back(data1);
960 session_.OnStreamFrames(frames);
961 EXPECT_EQ(1u, session_.GetNumOpenStreams());
962 EXPECT_CALL(*connection_, SendRstStream(i, _, _));
963 session_.CloseStream(i);
966 // Called after any new data is received by the session, and triggers the call
967 // to close the connection.
968 session_.PostProcessAfterData();
971 class QuicSessionTestClient : public QuicSessionTestBase {
972 protected:
973 QuicSessionTestClient() : QuicSessionTestBase(Perspective::IS_CLIENT) {}
976 INSTANTIATE_TEST_CASE_P(Tests,
977 QuicSessionTestClient,
978 ::testing::ValuesIn(QuicSupportedVersions()));
980 TEST_P(QuicSessionTestClient, ImplicitlyCreatedStreamsClient) {
981 ASSERT_TRUE(session_.GetIncomingDataStream(6) != nullptr);
982 // Both 2 and 4 should be implicitly created.
983 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 2));
984 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4));
985 ASSERT_TRUE(session_.GetIncomingDataStream(2) != nullptr);
986 ASSERT_TRUE(session_.GetIncomingDataStream(4) != nullptr);
987 // And 5 should be not implicitly created.
988 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5));
991 } // namespace
992 } // namespace test
993 } // namespace net