Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / net / quic / quic_session_test.cc
blob2d362fda0027fe008664efa8552fe5e180c4da8e
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>
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h"
12 #include "net/quic/crypto/crypto_protocol.h"
13 #include "net/quic/quic_crypto_stream.h"
14 #include "net/quic/quic_protocol.h"
15 #include "net/quic/reliable_quic_stream.h"
16 #include "net/quic/test_tools/quic_connection_peer.h"
17 #include "net/quic/test_tools/quic_data_stream_peer.h"
18 #include "net/quic/test_tools/quic_session_peer.h"
19 #include "net/quic/test_tools/quic_test_utils.h"
20 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
21 #include "net/spdy/spdy_framer.h"
22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h"
25 using base::hash_map;
26 using std::set;
27 using std::vector;
28 using testing::_;
29 using testing::InSequence;
30 using testing::InvokeWithoutArgs;
31 using testing::Return;
32 using testing::StrictMock;
34 namespace net {
35 namespace test {
36 namespace {
38 const QuicPriority kHighestPriority = 0;
39 const QuicPriority kSomeMiddlePriority = 3;
41 class TestCryptoStream : public QuicCryptoStream {
42 public:
43 explicit TestCryptoStream(QuicSession* session)
44 : QuicCryptoStream(session) {
47 virtual void OnHandshakeMessage(
48 const CryptoHandshakeMessage& message) OVERRIDE {
49 encryption_established_ = true;
50 handshake_confirmed_ = true;
51 CryptoHandshakeMessage msg;
52 string error_details;
53 session()->config()->ToHandshakeMessage(&msg);
54 const QuicErrorCode error = session()->config()->ProcessClientHello(
55 msg, &error_details);
56 EXPECT_EQ(QUIC_NO_ERROR, error);
57 session()->OnConfigNegotiated();
58 session()->OnCryptoHandshakeEvent(QuicSession::HANDSHAKE_CONFIRMED);
61 MOCK_METHOD0(OnCanWrite, void());
64 class TestStream : public QuicDataStream {
65 public:
66 TestStream(QuicStreamId id, QuicSession* session)
67 : QuicDataStream(id, session) {
70 using ReliableQuicStream::CloseWriteSide;
72 virtual uint32 ProcessData(const char* data, uint32 data_len) {
73 return data_len;
76 MOCK_METHOD0(OnCanWrite, void());
79 // Poor man's functor for use as callback in a mock.
80 class StreamBlocker {
81 public:
82 StreamBlocker(QuicSession* session, QuicStreamId stream_id)
83 : session_(session),
84 stream_id_(stream_id) {
87 void MarkWriteBlocked() {
88 session_->MarkWriteBlocked(stream_id_, kSomeMiddlePriority);
91 private:
92 QuicSession* const session_;
93 const QuicStreamId stream_id_;
96 class TestSession : public QuicSession {
97 public:
98 explicit TestSession(QuicConnection* connection)
99 : QuicSession(connection, DefaultQuicConfig()),
100 crypto_stream_(this) {
103 virtual TestCryptoStream* GetCryptoStream() OVERRIDE {
104 return &crypto_stream_;
107 virtual TestStream* CreateOutgoingDataStream() OVERRIDE {
108 TestStream* stream = new TestStream(GetNextStreamId(), this);
109 ActivateStream(stream);
110 return stream;
113 virtual TestStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE {
114 return new TestStream(id, this);
117 bool IsClosedStream(QuicStreamId id) {
118 return QuicSession::IsClosedStream(id);
121 QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id) {
122 return QuicSession::GetIncomingDataStream(stream_id);
125 TestCryptoStream crypto_stream_;
128 class QuicSessionTest : public ::testing::TestWithParam<QuicVersion> {
129 protected:
130 QuicSessionTest()
131 : connection_(new MockConnection(true, SupportedVersions(GetParam()))),
132 session_(connection_) {
133 headers_[":host"] = "www.google.com";
134 headers_[":path"] = "/index.hml";
135 headers_[":scheme"] = "http";
136 headers_["cookie"] =
137 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
138 "__utmc=160408618; "
139 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
140 "hoALMsy6HOdDad2Sz0flUByv7etmo3mLMidGrBoljqO9hSVA40SLqpG_iuKKSHX"
141 "RW3Np4bq0F0SDGDNsW0DSmTS9ufMRrlpARJDS7qAI6M3bghqJp4eABKZiRqebHT"
142 "pMU-RXvTI5D5oCF1vYxYofH_l1Kviuiy3oQ1kS1enqWgbhJ2t61_SNdv-1XJIS0"
143 "O3YeHLmVCs62O6zp89QwakfAWK9d3IDQvVSJzCQsvxvNIvaZFa567MawWlXg0Rh"
144 "1zFMi5vzcns38-8_Sns; "
145 "GA=v*2%2Fmem*57968640*47239936%2Fmem*57968640*47114716%2Fno-nm-"
146 "yj*15%2Fno-cc-yj*5%2Fpc-ch*133685%2Fpc-s-cr*133947%2Fpc-s-t*1339"
147 "47%2Fno-nm-yj*4%2Fno-cc-yj*1%2Fceft-as*1%2Fceft-nqas*0%2Fad-ra-c"
148 "v_p%2Fad-nr-cv_p-f*1%2Fad-v-cv_p*859%2Fad-ns-cv_p-f*1%2Ffn-v-ad%"
149 "2Fpc-t*250%2Fpc-cm*461%2Fpc-s-cr*722%2Fpc-s-t*722%2Fau_p*4"
150 "SICAID=AJKiYcHdKgxum7KMXG0ei2t1-W4OD1uW-ecNsCqC0wDuAXiDGIcT_HA2o1"
151 "3Rs1UKCuBAF9g8rWNOFbxt8PSNSHFuIhOo2t6bJAVpCsMU5Laa6lewuTMYI8MzdQP"
152 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
153 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
154 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
155 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
156 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
157 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
158 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
159 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
162 void CheckClosedStreams() {
163 for (int i = kCryptoStreamId; i < 100; i++) {
164 if (closed_streams_.count(i) == 0) {
165 EXPECT_FALSE(session_.IsClosedStream(i)) << " stream id: " << i;
166 } else {
167 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i;
172 void CloseStream(QuicStreamId id) {
173 session_.CloseStream(id);
174 closed_streams_.insert(id);
177 MockConnection* connection_;
178 TestSession session_;
179 set<QuicStreamId> closed_streams_;
180 SpdyHeaderBlock headers_;
183 INSTANTIATE_TEST_CASE_P(Tests, QuicSessionTest,
184 ::testing::ValuesIn(QuicSupportedVersions()));
186 TEST_P(QuicSessionTest, PeerAddress) {
187 EXPECT_EQ(IPEndPoint(Loopback4(), kTestPort), session_.peer_address());
190 TEST_P(QuicSessionTest, IsCryptoHandshakeConfirmed) {
191 EXPECT_FALSE(session_.IsCryptoHandshakeConfirmed());
192 CryptoHandshakeMessage message;
193 session_.crypto_stream_.OnHandshakeMessage(message);
194 EXPECT_TRUE(session_.IsCryptoHandshakeConfirmed());
197 TEST_P(QuicSessionTest, IsClosedStreamDefault) {
198 // Ensure that no streams are initially closed.
199 for (int i = kCryptoStreamId; i < 100; i++) {
200 EXPECT_FALSE(session_.IsClosedStream(i)) << "stream id: " << i;
204 TEST_P(QuicSessionTest, ImplicitlyCreatedStreams) {
205 ASSERT_TRUE(session_.GetIncomingDataStream(7) != NULL);
206 // Both 3 and 5 should be implicitly created.
207 EXPECT_FALSE(session_.IsClosedStream(3));
208 EXPECT_FALSE(session_.IsClosedStream(5));
209 ASSERT_TRUE(session_.GetIncomingDataStream(5) != NULL);
210 ASSERT_TRUE(session_.GetIncomingDataStream(3) != NULL);
213 TEST_P(QuicSessionTest, IsClosedStreamLocallyCreated) {
214 TestStream* stream2 = session_.CreateOutgoingDataStream();
215 EXPECT_EQ(2u, stream2->id());
216 TestStream* stream4 = session_.CreateOutgoingDataStream();
217 EXPECT_EQ(4u, stream4->id());
218 if (GetParam() <= QUIC_VERSION_12) {
219 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true);
220 QuicDataStreamPeer::SetHeadersDecompressed(stream4, true);
223 CheckClosedStreams();
224 CloseStream(4);
225 CheckClosedStreams();
226 CloseStream(2);
227 CheckClosedStreams();
230 TEST_P(QuicSessionTest, IsClosedStreamPeerCreated) {
231 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3;
232 QuicStreamId stream_id2 = stream_id1 + 2;
233 QuicDataStream* stream1 = session_.GetIncomingDataStream(stream_id1);
234 QuicDataStreamPeer::SetHeadersDecompressed(stream1, true);
235 QuicDataStream* stream2 = session_.GetIncomingDataStream(stream_id2);
236 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true);
238 CheckClosedStreams();
239 CloseStream(stream_id1);
240 CheckClosedStreams();
241 CloseStream(stream_id2);
242 // Create a stream explicitly, and another implicitly.
243 QuicDataStream* stream3 = session_.GetIncomingDataStream(stream_id2 + 4);
244 QuicDataStreamPeer::SetHeadersDecompressed(stream3, true);
245 CheckClosedStreams();
246 // Close one, but make sure the other is still not closed
247 CloseStream(stream3->id());
248 CheckClosedStreams();
251 TEST_P(QuicSessionTest, StreamIdTooLarge) {
252 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3;
253 session_.GetIncomingDataStream(stream_id);
254 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID));
255 session_.GetIncomingDataStream(stream_id + 102);
258 TEST_P(QuicSessionTest, DecompressionError) {
259 if (GetParam() > QUIC_VERSION_12) {
260 QuicHeadersStream* stream = QuicSessionPeer::GetHeadersStream(&session_);
261 const unsigned char data[] = {
262 0x80, 0x03, 0x00, 0x01, // SPDY/3 SYN_STREAM frame
263 0x00, 0x00, 0x00, 0x25, // flags/length
264 0x00, 0x00, 0x00, 0x05, // stream id
265 0x00, 0x00, 0x00, 0x00, // associated stream id
266 0x00, 0x00,
267 'a', 'b', 'c', 'd' // invalid compressed data
269 EXPECT_CALL(*connection_,
270 SendConnectionCloseWithDetails(QUIC_INVALID_HEADERS_STREAM_DATA,
271 "SPDY framing error."));
272 stream->ProcessRawData(reinterpret_cast<const char*>(data),
273 arraysize(data));
274 } else {
275 ReliableQuicStream* stream = session_.GetIncomingDataStream(3);
276 const char data[] =
277 "\0\0\0\0" // priority
278 "\1\0\0\0" // headers id
279 "\0\0\0\4" // length
280 "abcd"; // invalid compressed data
281 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE));
282 stream->ProcessRawData(data, arraysize(data));
286 TEST_P(QuicSessionTest, DebugDFatalIfMarkingClosedStreamWriteBlocked) {
287 TestStream* stream2 = session_.CreateOutgoingDataStream();
288 // Close the stream.
289 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD);
290 // TODO(rtenneti): enable when chromium supports EXPECT_DEBUG_DFATAL.
292 QuicStreamId kClosedStreamId = stream2->id();
293 EXPECT_DEBUG_DFATAL(
294 session_.MarkWriteBlocked(kClosedStreamId, kSomeMiddlePriority),
295 "Marking unknown stream 2 blocked.");
299 TEST_P(QuicSessionTest, DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) {
300 const QuicPriority kDifferentPriority = 0;
302 TestStream* stream2 = session_.CreateOutgoingDataStream();
303 EXPECT_NE(kDifferentPriority, stream2->EffectivePriority());
304 // TODO(rtenneti): enable when chromium supports EXPECT_DEBUG_DFATAL.
306 EXPECT_DEBUG_DFATAL(
307 session_.MarkWriteBlocked(stream2->id(), kDifferentPriority),
308 "Priorities do not match. Got: 0 Expected: 3");
312 TEST_P(QuicSessionTest, OnCanWrite) {
313 TestStream* stream2 = session_.CreateOutgoingDataStream();
314 TestStream* stream4 = session_.CreateOutgoingDataStream();
315 TestStream* stream6 = session_.CreateOutgoingDataStream();
317 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
318 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
319 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
321 InSequence s;
322 StreamBlocker stream2_blocker(&session_, stream2->id());
323 EXPECT_CALL(*stream2, OnCanWrite()).WillOnce(
324 // Reregister, to test the loop limit.
325 InvokeWithoutArgs(&stream2_blocker, &StreamBlocker::MarkWriteBlocked));
326 EXPECT_CALL(*stream6, OnCanWrite());
327 EXPECT_CALL(*stream4, OnCanWrite());
329 EXPECT_FALSE(session_.OnCanWrite());
332 TEST_P(QuicSessionTest, OnCanWriteCongestionControlBlocks) {
333 InSequence s;
335 // Drive congestion control manually.
336 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>;
337 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm);
339 TestStream* stream2 = session_.CreateOutgoingDataStream();
340 TestStream* stream4 = session_.CreateOutgoingDataStream();
341 TestStream* stream6 = session_.CreateOutgoingDataStream();
343 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
344 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
345 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
347 StreamBlocker stream2_blocker(&session_, stream2->id());
348 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _, _)).WillOnce(Return(
349 QuicTime::Delta::Zero()));
350 EXPECT_CALL(*stream2, OnCanWrite());
351 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _, _)).WillOnce(Return(
352 QuicTime::Delta::Zero()));
353 EXPECT_CALL(*stream6, OnCanWrite());
354 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _, _)).WillOnce(Return(
355 QuicTime::Delta::Infinite()));
356 // stream4->OnCanWrite is not called.
358 // TODO(avd) change return value to 'true', since the connection
359 // can't write because it is congestion control blocked.
360 EXPECT_FALSE(session_.OnCanWrite());
362 // Still congestion-control blocked.
363 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _, _)).WillOnce(Return(
364 QuicTime::Delta::Infinite()));
365 EXPECT_FALSE(session_.OnCanWrite());
367 // stream4->OnCanWrite is called once the connection stops being
368 // congestion-control blocked.
369 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _, _)).WillOnce(Return(
370 QuicTime::Delta::Zero()));
371 EXPECT_CALL(*stream4, OnCanWrite());
372 EXPECT_TRUE(session_.OnCanWrite());
375 TEST_P(QuicSessionTest, BufferedHandshake) {
376 EXPECT_FALSE(session_.HasPendingHandshake()); // Default value.
378 // Test that blocking other streams does not change our status.
379 TestStream* stream2 = session_.CreateOutgoingDataStream();
380 StreamBlocker stream2_blocker(&session_, stream2->id());
381 stream2_blocker.MarkWriteBlocked();
382 EXPECT_FALSE(session_.HasPendingHandshake());
384 TestStream* stream3 = session_.CreateOutgoingDataStream();
385 StreamBlocker stream3_blocker(&session_, stream3->id());
386 stream3_blocker.MarkWriteBlocked();
387 EXPECT_FALSE(session_.HasPendingHandshake());
389 // Blocking (due to buffering of) the Crypto stream is detected.
390 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority);
391 EXPECT_TRUE(session_.HasPendingHandshake());
393 TestStream* stream4 = session_.CreateOutgoingDataStream();
394 StreamBlocker stream4_blocker(&session_, stream4->id());
395 stream4_blocker.MarkWriteBlocked();
396 EXPECT_TRUE(session_.HasPendingHandshake());
398 InSequence s;
399 // Force most streams to re-register, which is common scenario when we block
400 // the Crypto stream, and only the crypto stream can "really" write.
402 // Due to prioritization, we *should* be asked to write the crypto stream
403 // first.
404 // Don't re-register the crypto stream (which signals complete writing).
405 TestCryptoStream* crypto_stream = session_.GetCryptoStream();
406 EXPECT_CALL(*crypto_stream, OnCanWrite());
408 // Re-register all other streams, to show they weren't able to proceed.
409 EXPECT_CALL(*stream2, OnCanWrite()).WillOnce(
410 InvokeWithoutArgs(&stream2_blocker, &StreamBlocker::MarkWriteBlocked));
412 EXPECT_CALL(*stream3, OnCanWrite()).WillOnce(
413 InvokeWithoutArgs(&stream3_blocker, &StreamBlocker::MarkWriteBlocked));
415 EXPECT_CALL(*stream4, OnCanWrite()).WillOnce(
416 InvokeWithoutArgs(&stream4_blocker, &StreamBlocker::MarkWriteBlocked));
418 EXPECT_FALSE(session_.OnCanWrite());
419 EXPECT_FALSE(session_.HasPendingHandshake()); // Crypto stream wrote.
422 TEST_P(QuicSessionTest, OnCanWriteWithClosedStream) {
423 TestStream* stream2 = session_.CreateOutgoingDataStream();
424 TestStream* stream4 = session_.CreateOutgoingDataStream();
425 TestStream* stream6 = session_.CreateOutgoingDataStream();
427 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority);
428 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority);
429 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority);
430 CloseStream(stream6->id());
432 InSequence s;
433 EXPECT_CALL(*stream2, OnCanWrite());
434 EXPECT_CALL(*stream4, OnCanWrite());
435 EXPECT_TRUE(session_.OnCanWrite());
438 // Regression test for http://crbug.com/248737
439 TEST_P(QuicSessionTest, OutOfOrderHeaders) {
440 QuicSpdyCompressor compressor;
441 vector<QuicStreamFrame> frames;
442 QuicPacketHeader header;
443 header.public_header.guid = session_.guid();
445 TestStream* stream2 = session_.CreateOutgoingDataStream();
446 TestStream* stream4 = session_.CreateOutgoingDataStream();
447 stream2->CloseWriteSide();
448 stream4->CloseWriteSide();
450 // Create frame with headers for stream2.
451 string compressed_headers1 = compressor.CompressHeaders(headers_);
452 QuicStreamFrame frame1(
453 stream2->id(), false, 0, MakeIOVector(compressed_headers1));
455 // Create frame with headers for stream4.
456 string compressed_headers2 = compressor.CompressHeaders(headers_);
457 QuicStreamFrame frame2(
458 stream4->id(), true, 0, MakeIOVector(compressed_headers2));
460 // Process the second frame first. This will cause the headers to
461 // be queued up and processed after the first frame is processed.
462 frames.push_back(frame2);
463 session_.OnStreamFrames(frames);
465 // Process the first frame, and un-cork the buffered headers.
466 frames[0] = frame1;
467 session_.OnStreamFrames(frames);
469 // Ensure that the streams actually close and we don't DCHECK.
470 connection_->CloseConnection(QUIC_CONNECTION_TIMED_OUT, true);
473 TEST_P(QuicSessionTest, SendGoAway) {
474 // After sending a GoAway, ensure new incoming streams cannot be created and
475 // result in a RST being sent.
476 EXPECT_CALL(*connection_,
477 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away."));
478 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away.");
479 EXPECT_TRUE(session_.goaway_sent());
481 EXPECT_CALL(*connection_, SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY));
482 EXPECT_FALSE(session_.GetIncomingDataStream(3u));
485 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) {
486 EXPECT_EQ(kDefaultInitialTimeoutSecs,
487 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
488 CryptoHandshakeMessage msg;
489 session_.crypto_stream_.OnHandshakeMessage(msg);
490 EXPECT_EQ(kDefaultTimeoutSecs,
491 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds());
494 TEST_P(QuicSessionTest, ZombieStream) {
495 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3;
496 QuicStreamId stream_id2 = stream_id1 + 2;
497 StrictMock<MockConnection>* connection =
498 new StrictMock<MockConnection>(false, SupportedVersions(GetParam()));
499 TestSession session(connection);
501 TestStream* stream1 = session.CreateOutgoingDataStream();
502 EXPECT_EQ(stream_id1, stream1->id());
503 TestStream* stream2 = session.CreateOutgoingDataStream();
504 EXPECT_EQ(stream_id2, stream2->id());
505 EXPECT_EQ(2u, session.GetNumOpenStreams());
507 // Reset the stream, but since the headers have not been decompressed
508 // it will become a zombie and will continue to process data
509 // until the headers are decompressed.
510 EXPECT_CALL(*connection, SendRstStream(stream_id1, QUIC_STREAM_CANCELLED));
511 session.SendRstStream(stream_id1, QUIC_STREAM_CANCELLED);
513 EXPECT_EQ(1u, session.GetNumOpenStreams());
515 vector<QuicStreamFrame> frames;
516 QuicPacketHeader header;
517 header.public_header.guid = session_.guid();
519 // Create frame with headers for stream2.
520 QuicSpdyCompressor compressor;
521 string compressed_headers1 = compressor.CompressHeaders(headers_);
522 QuicStreamFrame frame1(
523 stream1->id(), false, 0, MakeIOVector(compressed_headers1));
525 // Process the second frame first. This will cause the headers to
526 // be queued up and processed after the first frame is processed.
527 frames.push_back(frame1);
528 EXPECT_FALSE(stream1->headers_decompressed());
530 session.OnStreamFrames(frames);
531 EXPECT_EQ(1u, session.GetNumOpenStreams());
533 EXPECT_TRUE(connection->connected());
536 TEST_P(QuicSessionTest, ZombieStreamConnectionClose) {
537 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3;
538 QuicStreamId stream_id2 = stream_id1 + 2;
539 StrictMock<MockConnection>* connection =
540 new StrictMock<MockConnection>(false, SupportedVersions(GetParam()));
541 TestSession session(connection);
543 TestStream* stream1 = session.CreateOutgoingDataStream();
544 EXPECT_EQ(stream_id1, stream1->id());
545 TestStream* stream2 = session.CreateOutgoingDataStream();
546 EXPECT_EQ(stream_id2, stream2->id());
547 EXPECT_EQ(2u, session.GetNumOpenStreams());
549 stream1->CloseWriteSide();
550 // Reset the stream, but since the headers have not been decompressed
551 // it will become a zombie and will continue to process data
552 // until the headers are decompressed.
553 EXPECT_CALL(*connection, SendRstStream(stream_id1, QUIC_STREAM_CANCELLED));
554 session.SendRstStream(stream_id1, QUIC_STREAM_CANCELLED);
556 EXPECT_EQ(1u, session.GetNumOpenStreams());
558 connection->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false);
560 EXPECT_EQ(0u, session.GetNumOpenStreams());
563 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) {
564 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3;
565 // Send two bytes of payload.
566 QuicStreamFrame data1(stream_id1, false, 0, MakeIOVector("HT"));
567 vector<QuicStreamFrame> frames;
568 frames.push_back(data1);
569 EXPECT_TRUE(session_.OnStreamFrames(frames));
570 EXPECT_EQ(1u, session_.GetNumOpenStreams());
572 if (GetParam() <= QUIC_VERSION_12) {
573 // Send a reset before the headers have been decompressed. This causes
574 // an unrecoverable compression context state.
575 EXPECT_CALL(*connection_, SendConnectionClose(
576 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED));
579 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR);
580 session_.OnRstStream(rst1);
581 EXPECT_EQ(0u, session_.GetNumOpenStreams());
584 } // namespace
585 } // namespace test
586 } // namespace net