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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 virtual TestStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE { | 109 virtual TestStream* CreateIncomingDataStream(QuicStreamId id) OVERRIDE { |
110 return new TestStream(id, this); | 110 return new TestStream(id, this); |
111 } | 111 } |
112 | 112 |
113 bool IsClosedStream(QuicStreamId id) { | 113 bool IsClosedStream(QuicStreamId id) { |
114 return QuicSession::IsClosedStream(id); | 114 return QuicSession::IsClosedStream(id); |
115 } | 115 } |
116 | 116 |
117 QuicDataStream* GetIncomingReliableStream(QuicStreamId stream_id) { | 117 QuicDataStream* GetIncomingDataStream(QuicStreamId stream_id) { |
118 return QuicSession::GetIncomingReliableStream(stream_id); | 118 return QuicSession::GetIncomingDataStream(stream_id); |
119 } | 119 } |
120 | 120 |
121 TestCryptoStream crypto_stream_; | 121 TestCryptoStream crypto_stream_; |
122 }; | 122 }; |
123 | 123 |
124 class QuicSessionTest : public ::testing::TestWithParam<QuicVersion> { | 124 class QuicSessionTest : public ::testing::TestWithParam<QuicVersion> { |
125 protected: | 125 protected: |
126 QuicSessionTest() | 126 QuicSessionTest() |
127 : connection_(new MockConnection(true, SupportedVersions(GetParam()))), | 127 : connection_(new MockConnection(true, SupportedVersions(GetParam()))), |
128 session_(connection_) { | 128 session_(connection_) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 | 192 |
193 TEST_P(QuicSessionTest, IsClosedStreamDefault) { | 193 TEST_P(QuicSessionTest, IsClosedStreamDefault) { |
194 // Ensure that no streams are initially closed. | 194 // Ensure that no streams are initially closed. |
195 for (int i = kCryptoStreamId; i < 100; i++) { | 195 for (int i = kCryptoStreamId; i < 100; i++) { |
196 EXPECT_FALSE(session_.IsClosedStream(i)) << "stream id: " << i; | 196 EXPECT_FALSE(session_.IsClosedStream(i)) << "stream id: " << i; |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 TEST_P(QuicSessionTest, ImplicitlyCreatedStreams) { | 200 TEST_P(QuicSessionTest, ImplicitlyCreatedStreams) { |
201 ASSERT_TRUE(session_.GetIncomingReliableStream(7) != NULL); | 201 ASSERT_TRUE(session_.GetIncomingDataStream(7) != NULL); |
202 // Both 3 and 5 should be implicitly created. | 202 // Both 3 and 5 should be implicitly created. |
203 EXPECT_FALSE(session_.IsClosedStream(3)); | 203 EXPECT_FALSE(session_.IsClosedStream(3)); |
204 EXPECT_FALSE(session_.IsClosedStream(5)); | 204 EXPECT_FALSE(session_.IsClosedStream(5)); |
205 ASSERT_TRUE(session_.GetIncomingReliableStream(5) != NULL); | 205 ASSERT_TRUE(session_.GetIncomingDataStream(5) != NULL); |
206 ASSERT_TRUE(session_.GetIncomingReliableStream(3) != NULL); | 206 ASSERT_TRUE(session_.GetIncomingDataStream(3) != NULL); |
207 } | 207 } |
208 | 208 |
209 TEST_P(QuicSessionTest, IsClosedStreamLocallyCreated) { | 209 TEST_P(QuicSessionTest, IsClosedStreamLocallyCreated) { |
210 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 210 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
211 EXPECT_EQ(2u, stream2->id()); | 211 EXPECT_EQ(2u, stream2->id()); |
212 TestStream* stream4 = session_.CreateOutgoingDataStream(); | 212 TestStream* stream4 = session_.CreateOutgoingDataStream(); |
213 EXPECT_EQ(4u, stream4->id()); | 213 EXPECT_EQ(4u, stream4->id()); |
214 if (GetParam() <= QUIC_VERSION_12) { | 214 if (GetParam() <= QUIC_VERSION_12) { |
215 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); | 215 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); |
216 QuicDataStreamPeer::SetHeadersDecompressed(stream4, true); | 216 QuicDataStreamPeer::SetHeadersDecompressed(stream4, true); |
217 } | 217 } |
218 | 218 |
219 CheckClosedStreams(); | 219 CheckClosedStreams(); |
220 CloseStream(4); | 220 CloseStream(4); |
221 CheckClosedStreams(); | 221 CheckClosedStreams(); |
222 CloseStream(2); | 222 CloseStream(2); |
223 CheckClosedStreams(); | 223 CheckClosedStreams(); |
224 } | 224 } |
225 | 225 |
226 TEST_P(QuicSessionTest, IsClosedStreamPeerCreated) { | 226 TEST_P(QuicSessionTest, IsClosedStreamPeerCreated) { |
227 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 227 QuicStreamId stream_id1 = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
228 QuicStreamId stream_id2 = stream_id1 + 2; | 228 QuicStreamId stream_id2 = stream_id1 + 2; |
229 QuicDataStream* stream1 = session_.GetIncomingReliableStream(stream_id1); | 229 QuicDataStream* stream1 = session_.GetIncomingDataStream(stream_id1); |
230 QuicDataStreamPeer::SetHeadersDecompressed(stream1, true); | 230 QuicDataStreamPeer::SetHeadersDecompressed(stream1, true); |
231 QuicDataStream* stream2 = session_.GetIncomingReliableStream(stream_id2); | 231 QuicDataStream* stream2 = session_.GetIncomingDataStream(stream_id2); |
232 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); | 232 QuicDataStreamPeer::SetHeadersDecompressed(stream2, true); |
233 | 233 |
234 CheckClosedStreams(); | 234 CheckClosedStreams(); |
235 CloseStream(stream_id1); | 235 CloseStream(stream_id1); |
236 CheckClosedStreams(); | 236 CheckClosedStreams(); |
237 CloseStream(stream_id2); | 237 CloseStream(stream_id2); |
238 // Create a stream explicitly, and another implicitly. | 238 // Create a stream explicitly, and another implicitly. |
239 QuicDataStream* stream3 = session_.GetIncomingReliableStream(stream_id2 + 4); | 239 QuicDataStream* stream3 = session_.GetIncomingDataStream(stream_id2 + 4); |
240 QuicDataStreamPeer::SetHeadersDecompressed(stream3, true); | 240 QuicDataStreamPeer::SetHeadersDecompressed(stream3, true); |
241 CheckClosedStreams(); | 241 CheckClosedStreams(); |
242 // Close one, but make sure the other is still not closed | 242 // Close one, but make sure the other is still not closed |
243 CloseStream(stream3->id()); | 243 CloseStream(stream3->id()); |
244 CheckClosedStreams(); | 244 CheckClosedStreams(); |
245 } | 245 } |
246 | 246 |
247 TEST_P(QuicSessionTest, StreamIdTooLarge) { | 247 TEST_P(QuicSessionTest, StreamIdTooLarge) { |
248 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; | 248 QuicStreamId stream_id = GetParam() > QUIC_VERSION_12 ? 5 : 3; |
249 session_.GetIncomingReliableStream(stream_id); | 249 session_.GetIncomingDataStream(stream_id); |
250 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); | 250 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_STREAM_ID)); |
251 session_.GetIncomingReliableStream(stream_id + 102); | 251 session_.GetIncomingDataStream(stream_id + 102); |
252 } | 252 } |
253 | 253 |
254 TEST_P(QuicSessionTest, DecompressionError) { | 254 TEST_P(QuicSessionTest, DecompressionError) { |
255 if (GetParam() > QUIC_VERSION_12) { | 255 if (GetParam() > QUIC_VERSION_12) { |
256 QuicHeadersStream* stream = QuicSessionPeer::GetHeadersStream(&session_); | 256 QuicHeadersStream* stream = QuicSessionPeer::GetHeadersStream(&session_); |
257 const unsigned char data[] = { | 257 const unsigned char data[] = { |
258 0x80, 0x03, 0x00, 0x01, // SPDY/3 SYN_STREAM frame | 258 0x80, 0x03, 0x00, 0x01, // SPDY/3 SYN_STREAM frame |
259 0x00, 0x00, 0x00, 0x25, // flags/length | 259 0x00, 0x00, 0x00, 0x25, // flags/length |
260 0x00, 0x00, 0x00, 0x05, // stream id | 260 0x00, 0x00, 0x00, 0x05, // stream id |
261 0x00, 0x00, 0x00, 0x00, // associated stream id | 261 0x00, 0x00, 0x00, 0x00, // associated stream id |
262 0x00, 0x00, | 262 0x00, 0x00, |
263 'a', 'b', 'c', 'd' // invalid compressed data | 263 'a', 'b', 'c', 'd' // invalid compressed data |
264 }; | 264 }; |
265 EXPECT_CALL(*connection_, | 265 EXPECT_CALL(*connection_, |
266 SendConnectionCloseWithDetails(QUIC_INVALID_HEADERS_STREAM_DATA, | 266 SendConnectionCloseWithDetails(QUIC_INVALID_HEADERS_STREAM_DATA, |
267 "SPDY framing error.")); | 267 "SPDY framing error.")); |
268 stream->ProcessRawData(reinterpret_cast<const char*>(data), | 268 stream->ProcessRawData(reinterpret_cast<const char*>(data), |
269 arraysize(data)); | 269 arraysize(data)); |
270 } else { | 270 } else { |
271 ReliableQuicStream* stream = session_.GetIncomingReliableStream(3); | 271 ReliableQuicStream* stream = session_.GetIncomingDataStream(3); |
272 const char data[] = | 272 const char data[] = |
273 "\0\0\0\0" // priority | 273 "\0\0\0\0" // priority |
274 "\1\0\0\0" // headers id | 274 "\1\0\0\0" // headers id |
275 "\0\0\0\4" // length | 275 "\0\0\0\4" // length |
276 "abcd"; // invalid compressed data | 276 "abcd"; // invalid compressed data |
277 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); | 277 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); |
278 stream->ProcessRawData(data, arraysize(data)); | 278 stream->ProcessRawData(data, arraysize(data)); |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 399 |
400 TEST_P(QuicSessionTest, SendGoAway) { | 400 TEST_P(QuicSessionTest, SendGoAway) { |
401 // After sending a GoAway, ensure new incoming streams cannot be created and | 401 // After sending a GoAway, ensure new incoming streams cannot be created and |
402 // result in a RST being sent. | 402 // result in a RST being sent. |
403 EXPECT_CALL(*connection_, | 403 EXPECT_CALL(*connection_, |
404 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")); | 404 SendGoAway(QUIC_PEER_GOING_AWAY, 0u, "Going Away.")); |
405 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); | 405 session_.SendGoAway(QUIC_PEER_GOING_AWAY, "Going Away."); |
406 EXPECT_TRUE(session_.goaway_sent()); | 406 EXPECT_TRUE(session_.goaway_sent()); |
407 | 407 |
408 EXPECT_CALL(*connection_, SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY)); | 408 EXPECT_CALL(*connection_, SendRstStream(3u, QUIC_STREAM_PEER_GOING_AWAY)); |
409 EXPECT_FALSE(session_.GetIncomingReliableStream(3u)); | 409 EXPECT_FALSE(session_.GetIncomingDataStream(3u)); |
410 } | 410 } |
411 | 411 |
412 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { | 412 TEST_P(QuicSessionTest, IncreasedTimeoutAfterCryptoHandshake) { |
413 EXPECT_EQ(kDefaultInitialTimeoutSecs, | 413 EXPECT_EQ(kDefaultInitialTimeoutSecs, |
414 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 414 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
415 CryptoHandshakeMessage msg; | 415 CryptoHandshakeMessage msg; |
416 session_.crypto_stream_.OnHandshakeMessage(msg); | 416 session_.crypto_stream_.OnHandshakeMessage(msg); |
417 EXPECT_EQ(kDefaultTimeoutSecs, | 417 EXPECT_EQ(kDefaultTimeoutSecs, |
418 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); | 418 QuicConnectionPeer::GetNetworkTimeout(connection_).ToSeconds()); |
419 } | 419 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 504 } |
505 | 505 |
506 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR); | 506 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR); |
507 session_.OnRstStream(rst1); | 507 session_.OnRstStream(rst1); |
508 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 508 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
509 } | 509 } |
510 | 510 |
511 } // namespace | 511 } // namespace |
512 } // namespace test | 512 } // namespace test |
513 } // namespace net | 513 } // namespace net |
OLD | NEW |