OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; | 168 EXPECT_TRUE(session_.IsClosedStream(i)) << " stream id: " << i; |
169 } | 169 } |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 void CloseStream(QuicStreamId id) { | 173 void CloseStream(QuicStreamId id) { |
174 session_.CloseStream(id); | 174 session_.CloseStream(id); |
175 closed_streams_.insert(id); | 175 closed_streams_.insert(id); |
176 } | 176 } |
177 | 177 |
| 178 QuicVersion version() const { return connection_->version(); } |
| 179 |
178 MockConnection* connection_; | 180 MockConnection* connection_; |
179 TestSession session_; | 181 TestSession session_; |
180 set<QuicStreamId> closed_streams_; | 182 set<QuicStreamId> closed_streams_; |
181 SpdyHeaderBlock headers_; | 183 SpdyHeaderBlock headers_; |
182 }; | 184 }; |
183 | 185 |
184 INSTANTIATE_TEST_CASE_P(Tests, QuicSessionTest, | 186 INSTANTIATE_TEST_CASE_P(Tests, QuicSessionTest, |
185 ::testing::ValuesIn(QuicSupportedVersions())); | 187 ::testing::ValuesIn(QuicSupportedVersions())); |
186 | 188 |
187 TEST_P(QuicSessionTest, PeerAddress) { | 189 TEST_P(QuicSessionTest, PeerAddress) { |
(...skipping 21 matching lines...) Expand all Loading... |
209 EXPECT_FALSE(session_.IsClosedStream(5)); | 211 EXPECT_FALSE(session_.IsClosedStream(5)); |
210 ASSERT_TRUE(session_.GetIncomingDataStream(5) != NULL); | 212 ASSERT_TRUE(session_.GetIncomingDataStream(5) != NULL); |
211 ASSERT_TRUE(session_.GetIncomingDataStream(3) != NULL); | 213 ASSERT_TRUE(session_.GetIncomingDataStream(3) != NULL); |
212 } | 214 } |
213 | 215 |
214 TEST_P(QuicSessionTest, IsClosedStreamLocallyCreated) { | 216 TEST_P(QuicSessionTest, IsClosedStreamLocallyCreated) { |
215 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 217 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
216 EXPECT_EQ(2u, stream2->id()); | 218 EXPECT_EQ(2u, stream2->id()); |
217 TestStream* stream4 = session_.CreateOutgoingDataStream(); | 219 TestStream* stream4 = session_.CreateOutgoingDataStream(); |
218 EXPECT_EQ(4u, stream4->id()); | 220 EXPECT_EQ(4u, stream4->id()); |
219 if (GetParam() <= QUIC_VERSION_12) { | 221 if (version() <= QUIC_VERSION_12) { |
220 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); | 222 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); |
221 QuicDataStreamPeer::SetHeadersDecompressed(stream4, true); | 223 QuicDataStreamPeer::SetHeadersDecompressed(stream4, true); |
222 } | 224 } |
223 | 225 |
224 CheckClosedStreams(); | 226 CheckClosedStreams(); |
225 CloseStream(4); | 227 CloseStream(4); |
226 CheckClosedStreams(); | 228 CheckClosedStreams(); |
227 CloseStream(2); | 229 CloseStream(2); |
228 CheckClosedStreams(); | 230 CheckClosedStreams(); |
229 } | 231 } |
230 | 232 |
231 TEST_P(QuicSessionTest, IsClosedStreamPeerCreated) { | 233 TEST_P(QuicSessionTest, IsClosedStreamPeerCreated) { |
232 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 234 QuicStreamId stream_id1 = version() > QUIC_VERSION_12 ? 5 : 3; |
233 QuicStreamId stream_id2 = stream_id1 + 2; | 235 QuicStreamId stream_id2 = stream_id1 + 2; |
234 QuicDataStream* stream1 = session_.GetIncomingDataStream(stream_id1); | 236 QuicDataStream* stream1 = session_.GetIncomingDataStream(stream_id1); |
235 QuicDataStreamPeer::SetHeadersDecompressed(stream1, true); | 237 QuicDataStreamPeer::SetHeadersDecompressed(stream1, true); |
236 QuicDataStream* stream2 = session_.GetIncomingDataStream(stream_id2); | 238 QuicDataStream* stream2 = session_.GetIncomingDataStream(stream_id2); |
237 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); | 239 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); |
238 | 240 |
239 CheckClosedStreams(); | 241 CheckClosedStreams(); |
240 CloseStream(stream_id1); | 242 CloseStream(stream_id1); |
241 CheckClosedStreams(); | 243 CheckClosedStreams(); |
242 CloseStream(stream_id2); | 244 CloseStream(stream_id2); |
243 // Create a stream explicitly, and another implicitly. | 245 // Create a stream explicitly, and another implicitly. |
244 QuicDataStream* stream3 = session_.GetIncomingDataStream(stream_id2 + 4); | 246 QuicDataStream* stream3 = session_.GetIncomingDataStream(stream_id2 + 4); |
245 QuicDataStreamPeer::SetHeadersDecompressed(stream3, true); | 247 QuicDataStreamPeer::SetHeadersDecompressed(stream3, true); |
246 CheckClosedStreams(); | 248 CheckClosedStreams(); |
247 // Close one, but make sure the other is still not closed | 249 // Close one, but make sure the other is still not closed |
248 CloseStream(stream3->id()); | 250 CloseStream(stream3->id()); |
249 CheckClosedStreams(); | 251 CheckClosedStreams(); |
250 } | 252 } |
251 | 253 |
252 TEST_P(QuicSessionTest, StreamIdTooLarge) { | 254 TEST_P(QuicSessionTest, StreamIdTooLarge) { |
253 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 255 QuicStreamId stream_id = version() > QUIC_VERSION_12 ? 5 : 3; |
254 session_.GetIncomingDataStream(stream_id); | 256 session_.GetIncomingDataStream(stream_id); |
255 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); | 257 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); |
256 session_.GetIncomingDataStream(stream_id + 102); | 258 session_.GetIncomingDataStream(stream_id + 102); |
257 } | 259 } |
258 | 260 |
259 TEST_P(QuicSessionTest, DecompressionError) { | 261 TEST_P(QuicSessionTest, DecompressionError) { |
260 if (GetParam() > QUIC_VERSION_12) { | 262 if (version() > QUIC_VERSION_12) { |
261 QuicHeadersStream* stream = QuicSessionPeer::GetHeadersStream(&session_); | 263 QuicHeadersStream* stream = QuicSessionPeer::GetHeadersStream(&session_); |
262 const unsigned char data[] = { | 264 const unsigned char data[] = { |
263 0x80, 0x03, 0x00, 0x01, // SPDY/3 SYN_STREAM frame | 265 0x80, 0x03, 0x00, 0x01, // SPDY/3 SYN_STREAM frame |
264 0x00, 0x00, 0x00, 0x25, // flags/length | 266 0x00, 0x00, 0x00, 0x25, // flags/length |
265 0x00, 0x00, 0x00, 0x05, // stream id | 267 0x00, 0x00, 0x00, 0x05, // stream id |
266 0x00, 0x00, 0x00, 0x00, // associated stream id | 268 0x00, 0x00, 0x00, 0x00, // associated stream id |
267 0x00, 0x00, | 269 0x00, 0x00, |
268 'a', 'b', 'c', 'd' // invalid compressed data | 270 'a', 'b', 'c', 'd' // invalid compressed data |
269 }; | 271 }; |
270 EXPECT_CALL(*connection_, | 272 EXPECT_CALL(*connection_, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { | 488 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { |
487 EXPECT_EQ(kDefaultInitialTimeoutSecs, | 489 EXPECT_EQ(kDefaultInitialTimeoutSecs, |
488 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 490 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
489 CryptoHandshakeMessage msg; | 491 CryptoHandshakeMessage msg; |
490 session_.crypto_stream_.OnHandshakeMessage(msg); | 492 session_.crypto_stream_.OnHandshakeMessage(msg); |
491 EXPECT_EQ(kDefaultTimeoutSecs, | 493 EXPECT_EQ(kDefaultTimeoutSecs, |
492 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 494 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
493 } | 495 } |
494 | 496 |
495 TEST_P(QuicSessionTest, ZombieStream) { | 497 TEST_P(QuicSessionTest, ZombieStream) { |
496 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 498 QuicStreamId stream_id1 = version() > QUIC_VERSION_12 ? 5 : 3; |
497 QuicStreamId stream_id2 = stream_id1 + 2; | 499 QuicStreamId stream_id2 = stream_id1 + 2; |
498 StrictMock<MockConnection>* connection = | 500 StrictMock<MockConnection>* connection = |
499 new StrictMock<MockConnection>(false, SupportedVersions(GetParam())); | 501 new StrictMock<MockConnection>(false, SupportedVersions(version())); |
500 TestSession session(connection); | 502 TestSession session(connection); |
501 | 503 |
502 TestStream* stream1 = session.CreateOutgoingDataStream(); | 504 TestStream* stream1 = session.CreateOutgoingDataStream(); |
503 EXPECT_EQ(stream_id1, stream1->id()); | 505 EXPECT_EQ(stream_id1, stream1->id()); |
504 TestStream* stream2 = session.CreateOutgoingDataStream(); | 506 TestStream* stream2 = session.CreateOutgoingDataStream(); |
505 EXPECT_EQ(stream_id2, stream2->id()); | 507 EXPECT_EQ(stream_id2, stream2->id()); |
506 EXPECT_EQ(2u, session.GetNumOpenStreams()); | 508 EXPECT_EQ(2u, session.GetNumOpenStreams()); |
507 | 509 |
508 // Reset the stream, but since the headers have not been decompressed | 510 // Reset the stream, but since the headers have not been decompressed |
509 // it will become a zombie and will continue to process data | 511 // it will become a zombie and will continue to process data |
(...skipping 18 matching lines...) Expand all Loading... |
528 frames.push_back(frame1); | 530 frames.push_back(frame1); |
529 EXPECT_FALSE(stream1->headers_decompressed()); | 531 EXPECT_FALSE(stream1->headers_decompressed()); |
530 | 532 |
531 session.OnStreamFrames(frames); | 533 session.OnStreamFrames(frames); |
532 EXPECT_EQ(1u, session.GetNumOpenStreams()); | 534 EXPECT_EQ(1u, session.GetNumOpenStreams()); |
533 | 535 |
534 EXPECT_TRUE(connection->connected()); | 536 EXPECT_TRUE(connection->connected()); |
535 } | 537 } |
536 | 538 |
537 TEST_P(QuicSessionTest, ZombieStreamConnectionClose) { | 539 TEST_P(QuicSessionTest, ZombieStreamConnectionClose) { |
538 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 540 QuicStreamId stream_id1 = version() > QUIC_VERSION_12 ? 5 : 3; |
539 QuicStreamId stream_id2 = stream_id1 + 2; | 541 QuicStreamId stream_id2 = stream_id1 + 2; |
540 StrictMock<MockConnection>* connection = | 542 StrictMock<MockConnection>* connection = |
541 new StrictMock<MockConnection>(false, SupportedVersions(GetParam())); | 543 new StrictMock<MockConnection>(false, SupportedVersions(version())); |
542 TestSession session(connection); | 544 TestSession session(connection); |
543 | 545 |
544 TestStream* stream1 = session.CreateOutgoingDataStream(); | 546 TestStream* stream1 = session.CreateOutgoingDataStream(); |
545 EXPECT_EQ(stream_id1, stream1->id()); | 547 EXPECT_EQ(stream_id1, stream1->id()); |
546 TestStream* stream2 = session.CreateOutgoingDataStream(); | 548 TestStream* stream2 = session.CreateOutgoingDataStream(); |
547 EXPECT_EQ(stream_id2, stream2->id()); | 549 EXPECT_EQ(stream_id2, stream2->id()); |
548 EXPECT_EQ(2u, session.GetNumOpenStreams()); | 550 EXPECT_EQ(2u, session.GetNumOpenStreams()); |
549 | 551 |
550 stream1->CloseWriteSide(); | 552 stream1->CloseWriteSide(); |
551 // Reset the stream, but since the headers have not been decompressed | 553 // Reset the stream, but since the headers have not been decompressed |
552 // it will become a zombie and will continue to process data | 554 // it will become a zombie and will continue to process data |
553 // until the headers are decompressed. | 555 // until the headers are decompressed. |
554 EXPECT_CALL(*connection, SendRstStream(stream_id1, QUIC_STREAM_CANCELLED, 0)); | 556 EXPECT_CALL(*connection, SendRstStream(stream_id1, QUIC_STREAM_CANCELLED, 0)); |
555 session.SendRstStream(stream_id1, QUIC_STREAM_CANCELLED, 0); | 557 session.SendRstStream(stream_id1, QUIC_STREAM_CANCELLED, 0); |
556 | 558 |
557 EXPECT_EQ(1u, session.GetNumOpenStreams()); | 559 EXPECT_EQ(1u, session.GetNumOpenStreams()); |
558 | 560 |
559 connection->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false); | 561 connection->CloseConnection(QUIC_CONNECTION_TIMED_OUT, false); |
560 | 562 |
561 EXPECT_EQ(0u, session.GetNumOpenStreams()); | 563 EXPECT_EQ(0u, session.GetNumOpenStreams()); |
562 } | 564 } |
563 | 565 |
564 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { | 566 TEST_P(QuicSessionTest, RstStreamBeforeHeadersDecompressed) { |
565 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 567 QuicStreamId stream_id1 = version() > QUIC_VERSION_12 ? 5 : 3; |
566 // Send two bytes of payload. | 568 // Send two bytes of payload. |
567 QuicStreamFrame data1(stream_id1, false, 0, MakeIOVector("HT")); | 569 QuicStreamFrame data1(stream_id1, false, 0, MakeIOVector("HT")); |
568 vector<QuicStreamFrame> frames; | 570 vector<QuicStreamFrame> frames; |
569 frames.push_back(data1); | 571 frames.push_back(data1); |
570 EXPECT_TRUE(session_.OnStreamFrames(frames)); | 572 EXPECT_TRUE(session_.OnStreamFrames(frames)); |
571 EXPECT_EQ(1u, session_.GetNumOpenStreams()); | 573 EXPECT_EQ(1u, session_.GetNumOpenStreams()); |
572 | 574 |
573 if (GetParam() <= QUIC_VERSION_12) { | 575 if (version() <= QUIC_VERSION_12) { |
574 // Send a reset before the headers have been decompressed. This causes | 576 // Send a reset before the headers have been decompressed. This causes |
575 // an unrecoverable compression context state. | 577 // an unrecoverable compression context state. |
576 EXPECT_CALL(*connection_, SendConnectionClose( | 578 EXPECT_CALL(*connection_, SendConnectionClose( |
577 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED)); | 579 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED)); |
578 } | 580 } |
579 | 581 |
580 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR, 0); | 582 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR, 0); |
581 session_.OnRstStream(rst1); | 583 session_.OnRstStream(rst1); |
582 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 584 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
583 } | 585 } |
584 | 586 |
585 } // namespace | 587 } // namespace |
586 } // namespace test | 588 } // namespace test |
587 } // namespace net | 589 } // namespace net |
OLD | NEW |