Snap pinch zoom gestures near the screen edge.
[chromium-blink-merge.git] / net / quic / quic_session_test.cc
blob26590c1002433b4558eeeea0ecf1941697d779b3
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_spdy_session_peer.h"
26 #include "net/quic/test_tools/quic_test_utils.h"
27 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
28 #include "net/spdy/spdy_framer.h"
29 #include "net/test/gtest_util.h"
30 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gmock_mutant.h"
32 #include "testing/gtest/include/gtest/gtest.h"
34 using base::hash_map;
35 using std::set;
36 using std::string;
37 using std::vector;
38 using testing::CreateFunctor;
39 using testing::InSequence;
40 using testing::Invoke;
41 using testing::Return;
42 using testing::StrictMock;
43 using testing::_;
45 namespace net {
46 namespace test {
47 namespace {
49 const QuicPriority kHighestPriority = 0;
50 const QuicPriority kSomeMiddlePriority = 3;
52 class TestCryptoStream : public QuicCryptoStream {
53 public:
54 explicit TestCryptoStream(QuicSession* session)
55 : QuicCryptoStream(session) {
58 void OnHandshakeMessage(const CryptoHandshakeMessage& message) override {
59 encryption_established_ = true;
60 handshake_confirmed_ = true;
61 CryptoHandshakeMessage msg;
62 string error_details;
63 session()->config()->SetInitialStreamFlowControlWindowToSend(
64 kInitialStreamFlowControlWindowForTest);
65 session()->config()->SetInitialSessionFlowControlWindowToSend(
66 kInitialSessionFlowControlWindowForTest);
67 session()->config()->ToHandshakeMessage(&msg);
68 const QuicErrorCode error = session()->config()->ProcessPeerHello(
69 msg, CLIENT, &error_details);
70 EXPECT_EQ(QUIC_NO_ERROR, error);
71 session()->OnConfigNegotiated();
72 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
75 MOCK_METHOD0(OnCanWrite, void());
78 class TestHeadersStream : public QuicHeadersStream {
79 public:
80 explicit TestHeadersStream(QuicSpdySession* session)
81 : QuicHeadersStream(session) {}
83 MOCK_METHOD0(OnCanWrite, void());
86 class TestStream : public QuicDataStream {
87 public:
88 TestStream(QuicStreamId id, QuicSpdySession* session)
89 : QuicDataStream(id, session) {}
91 using ReliableQuicStream::CloseWriteSide;
93 uint32 ProcessData(const char* data, uint32 data_len) override {
94 return data_len;
97 void SendBody(const string& data, bool fin) {
98 WriteOrBufferData(data, fin, nullptr);
101 MOCK_METHOD0(OnCanWrite, void());
104 // Poor man's functor for use as callback in a mock.
105 class StreamBlocker {
106 public:
107 StreamBlocker(QuicSession* session, QuicStreamId stream_id)
108 : session_(session),
109 stream_id_(stream_id) {
112 void MarkWriteBlocked() {
113 session_->MarkWriteBlocked(stream_id_, kSomeMiddlePriority);
116 private:
117 QuicSession* const session_;
118 const QuicStreamId stream_id_;
121 class TestSession : public QuicSpdySession {
122 public:
123 explicit TestSession(QuicConnection* connection)
124 : QuicSpdySession(connection, DefaultQuicConfig()),
125 crypto_stream_(this),
126 writev_consumes_all_data_(false) {
127 Initialize();
130 TestCryptoStream* GetCryptoStream() override { return &crypto_stream_; }
132 TestStream* CreateOutgoingDynamicStream() override {
133 TestStream* stream = new TestStream(GetNextStreamId(), this);
134 ActivateStream(stream);
135 return stream;
138 TestStream* CreateIncomingDynamicStream(QuicStreamId id) override {
139 return new TestStream(id, this);
142 bool IsClosedStream(QuicStreamId id) {
143 return QuicSession::IsClosedStream(id);
146 ReliableQuicStream* GetIncomingDynamicStream(QuicStreamId stream_id) {
147 return QuicSpdySession::GetIncomingDynamicStream(stream_id);
150 QuicConsumedData WritevData(
151 QuicStreamId id,
152 const QuicIOVector& data,
153 QuicStreamOffset offset,
154 bool fin,
155 FecProtection fec_protection,
156 QuicAckNotifier::DelegateInterface* ack_notifier_delegate) override {
157 // Always consumes everything.
158 if (writev_consumes_all_data_) {
159 return QuicConsumedData(data.total_length, fin);
160 } else {
161 return QuicSession::WritevData(id, data, offset, fin, fec_protection,
162 ack_notifier_delegate);
166 void set_writev_consumes_all_data(bool val) {
167 writev_consumes_all_data_ = val;
170 QuicConsumedData SendStreamData(QuicStreamId id) {
171 struct iovec iov;
172 return WritevData(id, MakeIOVector("not empty", &iov), 0, true,
173 MAY_FEC_PROTECT, 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_.GetIncomingDynamicStream(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_.GetIncomingDynamicStream(7) != nullptr);
282 ASSERT_TRUE(session_.GetIncomingDynamicStream(5) != nullptr);
285 TEST_P(QuicSessionTestServer, IsClosedStreamLocallyCreated) {
286 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
287 EXPECT_EQ(2u, stream2->id());
288 TestStream* stream4 = session_.CreateOutgoingDynamicStream();
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 session_.GetIncomingDynamicStream(stream_id1);
302 session_.GetIncomingDynamicStream(stream_id2);
304 CheckClosedStreams();
305 CloseStream(stream_id1);
306 CheckClosedStreams();
307 CloseStream(stream_id2);
308 // Create a stream explicitly, and another implicitly.
309 ReliableQuicStream* stream3 =
310 session_.GetIncomingDynamicStream(stream_id2 + 4);
311 CheckClosedStreams();
312 // Close one, but make sure the other is still not closed
313 CloseStream(stream3->id());
314 CheckClosedStreams();
317 TEST_P(QuicSessionTestServer, StreamIdTooLarge) {
318 QuicStreamId stream_id = kClientDataStreamId1;
319 session_.GetIncomingDynamicStream(stream_id);
320 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID));
321 session_.GetIncomingDynamicStream(stream_id + kMaxStreamIdDelta + 2);
324 TEST_P(QuicSessionTestServer, DebugDFatalIfMarkingClosedStreamWriteBlocked) {
325 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
326 QuicStreamId kClosedStreamId = stream2->id();
327 // Close the stream.
328 EXPECT_CALL(*connection_, SendRstStream(kClosedStreamId, _, _));
329 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD);
330 EXPECT_DEBUG_DFATAL(
331 session_.MarkWriteBlocked(kClosedStreamId, kSomeMiddlePriority),
332 "Marking unknown stream 2 blocked.");
335 TEST_P(QuicSessionTestServer,
336 DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) {
337 const QuicPriority kDifferentPriority = 0;
339 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
340 EXPECT_NE(kDifferentPriority, stream2->EffectivePriority());
341 EXPECT_DEBUG_DFATAL(
342 session_.MarkWriteBlocked(stream2->id(), kDifferentPriority),
343 "Priorities do not match. Got: 0 Expected: 3");
346 TEST_P(QuicSessionTestServer, OnCanWrite) {
347 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
348 TestStream* stream4 = session_.CreateOutgoingDynamicStream();
349 TestStream* stream6 = session_.CreateOutgoingDynamicStream();
351 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
352 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
353 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
355 InSequence s;
356 StreamBlocker stream2_blocker(&session_, stream2->id());
357 // Reregister, to test the loop limit.
358 EXPECT_CALL(*stream2, OnCanWrite())
359 .WillOnce(Invoke(&stream2_blocker, &StreamBlocker::MarkWriteBlocked));
360 EXPECT_CALL(*stream6, OnCanWrite());
361 EXPECT_CALL(*stream4, OnCanWrite());
362 session_.OnCanWrite();
363 EXPECT_TRUE(session_.WillingAndAbleToWrite());
366 TEST_P(QuicSessionTestServer, OnCanWriteBundlesStreams) {
367 // Drive congestion control manually.
368 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>;
369 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm);
371 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
372 TestStream* stream4 = session_.CreateOutgoingDynamicStream();
373 TestStream* stream6 = session_.CreateOutgoingDynamicStream();
375 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
376 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
377 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
379 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillRepeatedly(
380 Return(QuicTime::Delta::Zero()));
381 EXPECT_CALL(*send_algorithm, GetCongestionWindow())
382 .WillRepeatedly(Return(kMaxPacketSize * 10));
383 EXPECT_CALL(*stream2, OnCanWrite())
384 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor(
385 &session_, &TestSession::SendStreamData, stream2->id()))));
386 EXPECT_CALL(*stream4, OnCanWrite())
387 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor(
388 &session_, &TestSession::SendStreamData, stream4->id()))));
389 EXPECT_CALL(*stream6, OnCanWrite())
390 .WillOnce(testing::IgnoreResult(Invoke(CreateFunctor(
391 &session_, &TestSession::SendStreamData, stream6->id()))));
393 // Expect that we only send one packet, the writes from different streams
394 // should be bundled together.
395 MockPacketWriter* writer =
396 static_cast<MockPacketWriter*>(
397 QuicConnectionPeer::GetWriter(session_.connection()));
398 EXPECT_CALL(*writer, WritePacket(_, _, _, _)).WillOnce(
399 Return(WriteResult(WRITE_STATUS_OK, 0)));
400 EXPECT_CALL(*send_algorithm, OnPacketSent(_, _, _, _, _)).Times(1);
401 session_.OnCanWrite();
402 EXPECT_FALSE(session_.WillingAndAbleToWrite());
405 TEST_P(QuicSessionTestServer, OnCanWriteCongestionControlBlocks) {
406 InSequence s;
408 // Drive congestion control manually.
409 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>;
410 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm);
412 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
413 TestStream* stream4 = session_.CreateOutgoingDynamicStream();
414 TestStream* stream6 = session_.CreateOutgoingDynamicStream();
416 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
417 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
418 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
420 StreamBlocker stream2_blocker(&session_, stream2->id());
421 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
422 QuicTime::Delta::Zero()));
423 EXPECT_CALL(*stream2, OnCanWrite());
424 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
425 QuicTime::Delta::Zero()));
426 EXPECT_CALL(*stream6, OnCanWrite());
427 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
428 QuicTime::Delta::Infinite()));
429 // stream4->OnCanWrite is not called.
431 session_.OnCanWrite();
432 EXPECT_TRUE(session_.WillingAndAbleToWrite());
434 // Still congestion-control blocked.
435 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
436 QuicTime::Delta::Infinite()));
437 session_.OnCanWrite();
438 EXPECT_TRUE(session_.WillingAndAbleToWrite());
440 // stream4->OnCanWrite is called once the connection stops being
441 // congestion-control blocked.
442 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _)).WillOnce(Return(
443 QuicTime::Delta::Zero()));
444 EXPECT_CALL(*stream4, OnCanWrite());
445 session_.OnCanWrite();
446 EXPECT_FALSE(session_.WillingAndAbleToWrite());
449 TEST_P(QuicSessionTestServer, BufferedHandshake) {
450 EXPECT_FALSE(session_.HasPendingHandshake()); // Default value.
452 // Test that blocking other streams does not change our status.
453 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
454 StreamBlocker stream2_blocker(&session_, stream2->id());
455 stream2_blocker.MarkWriteBlocked();
456 EXPECT_FALSE(session_.HasPendingHandshake());
458 TestStream* stream3 = session_.CreateOutgoingDynamicStream();
459 StreamBlocker stream3_blocker(&session_, stream3->id());
460 stream3_blocker.MarkWriteBlocked();
461 EXPECT_FALSE(session_.HasPendingHandshake());
463 // Blocking (due to buffering of) the Crypto stream is detected.
464 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority);
465 EXPECT_TRUE(session_.HasPendingHandshake());
467 TestStream* stream4 = session_.CreateOutgoingDynamicStream();
468 StreamBlocker stream4_blocker(&session_, stream4->id());
469 stream4_blocker.MarkWriteBlocked();
470 EXPECT_TRUE(session_.HasPendingHandshake());
472 InSequence s;
473 // Force most streams to re-register, which is common scenario when we block
474 // the Crypto stream, and only the crypto stream can "really" write.
476 // Due to prioritization, we *should* be asked to write the crypto stream
477 // first.
478 // Don't re-register the crypto stream (which signals complete writing).
479 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
480 EXPECT_CALL(*crypto_stream, OnCanWrite());
482 // Re-register all other streams, to show they weren't able to proceed.
483 EXPECT_CALL(*stream2, OnCanWrite())
484 .WillOnce(Invoke(&stream2_blocker, &StreamBlocker::MarkWriteBlocked));
485 EXPECT_CALL(*stream3, OnCanWrite())
486 .WillOnce(Invoke(&stream3_blocker, &StreamBlocker::MarkWriteBlocked));
487 EXPECT_CALL(*stream4, OnCanWrite())
488 .WillOnce(Invoke(&stream4_blocker, &StreamBlocker::MarkWriteBlocked));
490 session_.OnCanWrite();
491 EXPECT_TRUE(session_.WillingAndAbleToWrite());
492 EXPECT_FALSE(session_.HasPendingHandshake()); // Crypto stream wrote.
495 TEST_P(QuicSessionTestServer, OnCanWriteWithClosedStream) {
496 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
497 TestStream* stream4 = session_.CreateOutgoingDynamicStream();
498 TestStream* stream6 = session_.CreateOutgoingDynamicStream();
500 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
501 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
502 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
503 CloseStream(stream6->id());
505 InSequence s;
506 EXPECT_CALL(*stream2, OnCanWrite());
507 EXPECT_CALL(*stream4, OnCanWrite());
508 session_.OnCanWrite();
509 EXPECT_FALSE(session_.WillingAndAbleToWrite());
512 TEST_P(QuicSessionTestServer, OnCanWriteLimitsNumWritesIfFlowControlBlocked) {
513 // Ensure connection level flow control blockage.
514 QuicFlowControllerPeer::SetSendWindowOffset(session_.flow_controller(), 0);
515 EXPECT_TRUE(session_.flow_controller()->IsBlocked());
516 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked());
517 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
519 // Mark the crypto and headers streams as write blocked, we expect them to be
520 // allowed to write later.
521 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority);
522 session_.MarkWriteBlocked(kHeadersStreamId, kHighestPriority);
524 // Create a data stream, and although it is write blocked we never expect it
525 // to be allowed to write as we are connection level flow control blocked.
526 TestStream* stream = session_.CreateOutgoingDynamicStream();
527 session_.MarkWriteBlocked(stream->id(), kSomeMiddlePriority);
528 EXPECT_CALL(*stream, OnCanWrite()).Times(0);
530 // The crypto and headers streams should be called even though we are
531 // connection flow control blocked.
532 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
533 EXPECT_CALL(*crypto_stream, OnCanWrite()).Times(1);
534 TestHeadersStream* headers_stream = new TestHeadersStream(&session_);
535 QuicSpdySessionPeer::SetHeadersStream(&session_, headers_stream);
536 EXPECT_CALL(*headers_stream, OnCanWrite()).Times(1);
538 session_.OnCanWrite();
539 EXPECT_FALSE(session_.WillingAndAbleToWrite());
542 TEST_P(QuicSessionTestServer, SendGoAway) {
543 EXPECT_CALL(*connection_,
544 SendGoAway(QUIC_PEER_GOING_AWAY, 3u, "Going Away."));
545 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
546 EXPECT_TRUE(session_.goaway_sent());
548 EXPECT_CALL(*connection_,
549 SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY, 0)).Times(0);
550 EXPECT_TRUE(session_.GetIncomingDynamicStream(3u));
553 TEST_P(QuicSessionTestServer, DoNotSendGoAwayTwice) {
554 EXPECT_CALL(*connection_, SendGoAway(QUIC_PEER_GOING_AWAY, 3u, "Going Away."))
555 .Times(1);
556 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
557 EXPECT_TRUE(session_.goaway_sent());
558 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
561 TEST_P(QuicSessionTestServer, IncreasedTimeoutAfterCryptoHandshake) {
562 EXPECT_EQ(kInitialIdleTimeoutSecs + 3,
563 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
564 CryptoHandshakeMessage msg;
565 session_.GetCryptoStream()->OnHandshakeMessage(msg);
566 EXPECT_EQ(kMaximumIdleTimeoutSecs + 3,
567 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
570 TEST_P(QuicSessionTestServer, RstStreamBeforeHeadersDecompressed) {
571 // Send two bytes of payload.
572 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT"));
573 vector<QuicStreamFrame> frames;
574 frames.push_back(data1);
575 session_.OnStreamFrames(frames);
576 EXPECT_EQ(1u, session_.GetNumOpenStreams());
578 EXPECT_CALL(*connection_, SendRstStream(kClientDataStreamId1, _, _));
579 QuicRstStreamFrame rst1(kClientDataStreamId1, QUIC_STREAM_NO_ERROR, 0);
580 session_.OnRstStream(rst1);
581 EXPECT_EQ(0u, session_.GetNumOpenStreams());
582 // Connection should remain alive.
583 EXPECT_TRUE(connection_->connected());
586 TEST_P(QuicSessionTestServer, MultipleRstStreamsCauseSingleConnectionClose) {
587 // If multiple invalid reset stream frames arrive in a single packet, this
588 // should trigger a connection close. However there is no need to send
589 // multiple connection close frames.
591 // Create valid stream.
592 QuicStreamFrame data1(kClientDataStreamId1, false, 0, StringPiece("HT"));
593 vector<QuicStreamFrame> frames;
594 frames.push_back(data1);
595 session_.OnStreamFrames(frames);
596 EXPECT_EQ(1u, session_.GetNumOpenStreams());
598 // Process first invalid stream reset, resulting in the connection being
599 // closed.
600 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID))
601 .Times(1);
602 QuicStreamId kLargeInvalidStreamId = 99999999;
603 QuicRstStreamFrame rst1(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0);
604 session_.OnRstStream(rst1);
605 QuicConnectionPeer::CloseConnection(connection_);
607 // Processing of second invalid stream reset should not result in the
608 // connection being closed for a second time.
609 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0);
610 session_.OnRstStream(rst2);
613 TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedStream) {
614 // Test that if a stream is flow control blocked, then on receipt of the SHLO
615 // containing a suitable send window offset, the stream becomes unblocked.
617 // Ensure that Writev consumes all the data it is given (simulate no socket
618 // blocking).
619 session_.set_writev_consumes_all_data(true);
621 // Create a stream, and send enough data to make it flow control blocked.
622 TestStream* stream2 = session_.CreateOutgoingDynamicStream();
623 string body(kMinimumFlowControlSendWindow, '.');
624 EXPECT_FALSE(stream2->flow_controller()->IsBlocked());
625 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
626 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
627 EXPECT_CALL(*connection_, SendBlocked(stream2->id()));
628 EXPECT_CALL(*connection_, SendBlocked(0));
629 stream2->SendBody(body, false);
630 EXPECT_TRUE(stream2->flow_controller()->IsBlocked());
631 EXPECT_TRUE(session_.IsConnectionFlowControlBlocked());
632 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
634 // The handshake message will call OnCanWrite, so the stream can resume
635 // writing.
636 EXPECT_CALL(*stream2, OnCanWrite());
637 // Now complete the crypto handshake, resulting in an increased flow control
638 // send window.
639 CryptoHandshakeMessage msg;
640 session_.GetCryptoStream()->OnHandshakeMessage(msg);
642 // Stream is now unblocked.
643 EXPECT_FALSE(stream2->flow_controller()->IsBlocked());
644 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
645 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
648 TEST_P(QuicSessionTestServer, HandshakeUnblocksFlowControlBlockedCryptoStream) {
649 // Test that if the crypto stream is flow control blocked, then if the SHLO
650 // contains a larger send window offset, the stream becomes unblocked.
651 session_.set_writev_consumes_all_data(true);
652 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
653 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
654 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
655 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
656 QuicHeadersStream* headers_stream =
657 QuicSpdySessionPeer::GetHeadersStream(&session_);
658 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
659 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
660 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
661 // Write until the crypto stream is flow control blocked.
662 EXPECT_CALL(*connection_, SendBlocked(kCryptoStreamId));
663 int i = 0;
664 while (!crypto_stream->flow_controller()->IsBlocked() && i < 1000) {
665 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
666 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
667 QuicConfig config;
668 CryptoHandshakeMessage crypto_message;
669 config.ToHandshakeMessage(&crypto_message);
670 crypto_stream->SendHandshakeMessage(crypto_message);
671 ++i;
673 EXPECT_TRUE(crypto_stream->flow_controller()->IsBlocked());
674 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
675 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
676 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
677 EXPECT_FALSE(session_.HasDataToWrite());
678 EXPECT_TRUE(crypto_stream->HasBufferedData());
680 // The handshake message will call OnCanWrite, so the stream can
681 // resume writing.
682 EXPECT_CALL(*crypto_stream, OnCanWrite());
683 // Now complete the crypto handshake, resulting in an increased flow control
684 // send window.
685 CryptoHandshakeMessage msg;
686 session_.GetCryptoStream()->OnHandshakeMessage(msg);
688 // Stream is now unblocked and will no longer have buffered data.
689 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
690 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
691 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
694 TEST_P(QuicSessionTestServer,
695 HandshakeUnblocksFlowControlBlockedHeadersStream) {
696 // Test that if the header stream is flow control blocked, then if the SHLO
697 // contains a larger send window offset, the stream becomes unblocked.
698 session_.set_writev_consumes_all_data(true);
699 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
700 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
701 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
702 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
703 QuicHeadersStream* headers_stream =
704 QuicSpdySessionPeer::GetHeadersStream(&session_);
705 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
706 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
707 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
708 QuicStreamId stream_id = 5;
709 // Write until the header stream is flow control blocked.
710 EXPECT_CALL(*connection_, SendBlocked(kHeadersStreamId));
711 SpdyHeaderBlock headers;
712 while (!headers_stream->flow_controller()->IsBlocked() && stream_id < 2000) {
713 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
714 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
715 headers["header"] = base::Uint64ToString(base::RandUint64()) +
716 base::Uint64ToString(base::RandUint64()) +
717 base::Uint64ToString(base::RandUint64());
718 headers_stream->WriteHeaders(stream_id, headers, true, 0, nullptr);
719 stream_id += 2;
721 // Write once more to ensure that the headers stream has buffered data. The
722 // random headers may have exactly filled the flow control window.
723 headers_stream->WriteHeaders(stream_id, headers, true, 0, nullptr);
724 EXPECT_TRUE(headers_stream->HasBufferedData());
726 EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
727 EXPECT_FALSE(crypto_stream->flow_controller()->IsBlocked());
728 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
729 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
730 EXPECT_FALSE(session_.HasDataToWrite());
732 // Now complete the crypto handshake, resulting in an increased flow control
733 // send window.
734 CryptoHandshakeMessage msg;
735 session_.GetCryptoStream()->OnHandshakeMessage(msg);
737 // Stream is now unblocked and will no longer have buffered data.
738 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
739 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
740 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
741 EXPECT_FALSE(headers_stream->HasBufferedData());
744 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstOutOfOrder) {
745 // Test that when we receive an out of order stream RST we correctly adjust
746 // our connection level flow control receive window.
747 // On close, the stream should mark as consumed all bytes between the highest
748 // byte consumed so far and the final byte offset from the RST frame.
749 TestStream* stream = session_.CreateOutgoingDynamicStream();
751 const QuicStreamOffset kByteOffset =
752 1 + kInitialSessionFlowControlWindowForTest / 2;
754 // Expect no stream WINDOW_UPDATE frames, as stream read side closed.
755 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0);
756 // We do expect a connection level WINDOW_UPDATE when the stream is reset.
757 EXPECT_CALL(*connection_,
758 SendWindowUpdate(0, kInitialSessionFlowControlWindowForTest +
759 kByteOffset)).Times(1);
761 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
762 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
763 kByteOffset);
764 session_.OnRstStream(rst_frame);
765 session_.PostProcessAfterData();
766 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed());
769 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAndLocalReset) {
770 // Test the situation where we receive a FIN on a stream, and before we fully
771 // consume all the data from the sequencer buffer we locally RST the stream.
772 // The bytes between highest consumed byte, and the final byte offset that we
773 // determined when the FIN arrived, should be marked as consumed at the
774 // connection level flow controller when the stream is reset.
775 TestStream* stream = session_.CreateOutgoingDynamicStream();
777 const QuicStreamOffset kByteOffset =
778 kInitialSessionFlowControlWindowForTest / 2;
779 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece());
780 vector<QuicStreamFrame> frames;
781 frames.push_back(frame);
782 session_.OnStreamFrames(frames);
783 session_.PostProcessAfterData();
784 EXPECT_TRUE(connection_->connected());
786 EXPECT_EQ(0u, stream->flow_controller()->bytes_consumed());
787 EXPECT_EQ(kByteOffset,
788 stream->flow_controller()->highest_received_byte_offset());
790 // Reset stream locally.
791 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
792 stream->Reset(QUIC_STREAM_CANCELLED);
793 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed());
796 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingFinAfterRst) {
797 // Test that when we RST the stream (and tear down stream state), and then
798 // receive a FIN from the peer, we correctly adjust our connection level flow
799 // control receive window.
801 // Connection starts with some non-zero highest received byte offset,
802 // due to other active streams.
803 const uint64 kInitialConnectionBytesConsumed = 567;
804 const uint64 kInitialConnectionHighestReceivedOffset = 1234;
805 EXPECT_LT(kInitialConnectionBytesConsumed,
806 kInitialConnectionHighestReceivedOffset);
807 session_.flow_controller()->UpdateHighestReceivedOffset(
808 kInitialConnectionHighestReceivedOffset);
809 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed);
811 // Reset our stream: this results in the stream being closed locally.
812 TestStream* stream = session_.CreateOutgoingDynamicStream();
813 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
814 stream->Reset(QUIC_STREAM_CANCELLED);
816 // Now receive a response from the peer with a FIN. We should handle this by
817 // adjusting the connection level flow control receive window to take into
818 // account the total number of bytes sent by the peer.
819 const QuicStreamOffset kByteOffset = 5678;
820 string body = "hello";
821 QuicStreamFrame frame(stream->id(), true, kByteOffset, StringPiece(body));
822 vector<QuicStreamFrame> frames;
823 frames.push_back(frame);
824 session_.OnStreamFrames(frames);
826 QuicStreamOffset total_stream_bytes_sent_by_peer =
827 kByteOffset + body.length();
828 EXPECT_EQ(kInitialConnectionBytesConsumed + total_stream_bytes_sent_by_peer,
829 session_.flow_controller()->bytes_consumed());
830 EXPECT_EQ(
831 kInitialConnectionHighestReceivedOffset + total_stream_bytes_sent_by_peer,
832 session_.flow_controller()->highest_received_byte_offset());
835 TEST_P(QuicSessionTestServer, ConnectionFlowControlAccountingRstAfterRst) {
836 // Test that when we RST the stream (and tear down stream state), and then
837 // receive a RST from the peer, we correctly adjust our connection level flow
838 // control receive window.
840 // Connection starts with some non-zero highest received byte offset,
841 // due to other active streams.
842 const uint64 kInitialConnectionBytesConsumed = 567;
843 const uint64 kInitialConnectionHighestReceivedOffset = 1234;
844 EXPECT_LT(kInitialConnectionBytesConsumed,
845 kInitialConnectionHighestReceivedOffset);
846 session_.flow_controller()->UpdateHighestReceivedOffset(
847 kInitialConnectionHighestReceivedOffset);
848 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed);
850 // Reset our stream: this results in the stream being closed locally.
851 TestStream* stream = session_.CreateOutgoingDynamicStream();
852 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
853 stream->Reset(QUIC_STREAM_CANCELLED);
855 // Now receive a RST from the peer. We should handle this by adjusting the
856 // connection level flow control receive window to take into account the total
857 // number of bytes sent by the peer.
858 const QuicStreamOffset kByteOffset = 5678;
859 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
860 kByteOffset);
861 session_.OnRstStream(rst_frame);
863 EXPECT_EQ(kInitialConnectionBytesConsumed + kByteOffset,
864 session_.flow_controller()->bytes_consumed());
865 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset,
866 session_.flow_controller()->highest_received_byte_offset());
869 TEST_P(QuicSessionTestServer, InvalidStreamFlowControlWindowInHandshake) {
870 // Test that receipt of an invalid (< default) stream flow control window from
871 // the peer results in the connection being torn down.
872 uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1;
873 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(),
874 kInvalidWindow);
876 EXPECT_CALL(*connection_,
877 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW));
878 session_.OnConfigNegotiated();
881 TEST_P(QuicSessionTestServer, InvalidSessionFlowControlWindowInHandshake) {
882 // Test that receipt of an invalid (< default) session flow control window
883 // from the peer results in the connection being torn down.
884 uint32 kInvalidWindow = kMinimumFlowControlSendWindow - 1;
885 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(),
886 kInvalidWindow);
888 EXPECT_CALL(*connection_,
889 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW));
890 session_.OnConfigNegotiated();
893 TEST_P(QuicSessionTestServer, FlowControlWithInvalidFinalOffset) {
894 // Test that if we receive a stream RST with a highest byte offset that
895 // violates flow control, that we close the connection.
896 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1;
897 EXPECT_CALL(*connection_,
898 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA))
899 .Times(2);
901 // Check that stream frame + FIN results in connection close.
902 TestStream* stream = session_.CreateOutgoingDynamicStream();
903 EXPECT_CALL(*connection_, SendRstStream(stream->id(), _, _));
904 stream->Reset(QUIC_STREAM_CANCELLED);
905 QuicStreamFrame frame(stream->id(), true, kLargeOffset, StringPiece());
906 vector<QuicStreamFrame> frames;
907 frames.push_back(frame);
908 session_.OnStreamFrames(frames);
910 // Check that RST results in connection close.
911 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED,
912 kLargeOffset);
913 session_.OnRstStream(rst_frame);
916 TEST_P(QuicSessionTestServer, WindowUpdateUnblocksHeadersStream) {
917 // Test that a flow control blocked headers stream gets unblocked on recipt of
918 // a WINDOW_UPDATE frame.
920 // Set the headers stream to be flow control blocked.
921 QuicHeadersStream* headers_stream =
922 QuicSpdySessionPeer::GetHeadersStream(&session_);
923 QuicFlowControllerPeer::SetSendWindowOffset(headers_stream->flow_controller(),
925 EXPECT_TRUE(headers_stream->flow_controller()->IsBlocked());
926 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
927 EXPECT_TRUE(session_.IsStreamFlowControlBlocked());
929 // Unblock the headers stream by supplying a WINDOW_UPDATE.
930 QuicWindowUpdateFrame window_update_frame(headers_stream->id(),
931 2 * kMinimumFlowControlSendWindow);
932 vector<QuicWindowUpdateFrame> frames;
933 frames.push_back(window_update_frame);
934 session_.OnWindowUpdateFrames(frames);
935 EXPECT_FALSE(headers_stream->flow_controller()->IsBlocked());
936 EXPECT_FALSE(session_.IsConnectionFlowControlBlocked());
937 EXPECT_FALSE(session_.IsStreamFlowControlBlocked());
940 TEST_P(QuicSessionTestServer, TooManyUnfinishedStreamsCauseConnectionClose) {
941 // If a buggy/malicious peer creates too many streams that are not ended with
942 // a FIN or RST then we send a connection close.
943 EXPECT_CALL(*connection_,
944 SendConnectionClose(QUIC_TOO_MANY_UNFINISHED_STREAMS)).Times(1);
946 const int kMaxStreams = 5;
947 QuicSessionPeer::SetMaxOpenStreams(&session_, kMaxStreams);
949 // Create kMaxStreams + 1 data streams, and close them all without receiving a
950 // FIN or a RST from the client.
951 const int kFirstStreamId = kClientDataStreamId1;
952 const int kFinalStreamId = kClientDataStreamId1 + 2 * kMaxStreams + 1;
953 for (int i = kFirstStreamId; i < kFinalStreamId; i += 2) {
954 QuicStreamFrame data1(i, false, 0, StringPiece("HT"));
955 vector<QuicStreamFrame> frames;
956 frames.push_back(data1);
957 session_.OnStreamFrames(frames);
958 EXPECT_EQ(1u, session_.GetNumOpenStreams());
959 EXPECT_CALL(*connection_, SendRstStream(i, _, _));
960 session_.CloseStream(i);
963 // Called after any new data is received by the session, and triggers the call
964 // to close the connection.
965 session_.PostProcessAfterData();
968 class QuicSessionTestClient : public QuicSessionTestBase {
969 protected:
970 QuicSessionTestClient() : QuicSessionTestBase(Perspective::IS_CLIENT) {}
973 INSTANTIATE_TEST_CASE_P(Tests,
974 QuicSessionTestClient,
975 ::testing::ValuesIn(QuicSupportedVersions()));
977 TEST_P(QuicSessionTestClient, ImplicitlyCreatedStreamsClient) {
978 ASSERT_TRUE(session_.GetIncomingDynamicStream(6) != nullptr);
979 // Both 2 and 4 should be implicitly created.
980 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 2));
981 EXPECT_TRUE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 4));
982 ASSERT_TRUE(session_.GetIncomingDynamicStream(2) != nullptr);
983 ASSERT_TRUE(session_.GetIncomingDynamicStream(4) != nullptr);
984 // And 5 should be not implicitly created.
985 EXPECT_FALSE(QuicSessionPeer::IsStreamImplicitlyCreated(&session_, 5));
988 } // namespace
989 } // namespace test
990 } // namespace net