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 14 matching lines...) Expand all Loading... |
25 using std::vector; | 25 using std::vector; |
26 using testing::_; | 26 using testing::_; |
27 using testing::InSequence; | 27 using testing::InSequence; |
28 using testing::InvokeWithoutArgs; | 28 using testing::InvokeWithoutArgs; |
29 using testing::StrictMock; | 29 using testing::StrictMock; |
30 | 30 |
31 namespace net { | 31 namespace net { |
32 namespace test { | 32 namespace test { |
33 namespace { | 33 namespace { |
34 | 34 |
35 const QuicPriority kSomeMiddlePriority = 2; | 35 const QuicPriority kHighestPriority = 0; |
| 36 const QuicPriority kSomeMiddlePriority = 3; |
36 | 37 |
37 class TestCryptoStream : public QuicCryptoStream { | 38 class TestCryptoStream : public QuicCryptoStream { |
38 public: | 39 public: |
39 explicit TestCryptoStream(QuicSession* session) | 40 explicit TestCryptoStream(QuicSession* session) |
40 : QuicCryptoStream(session) { | 41 : QuicCryptoStream(session) { |
41 } | 42 } |
42 | 43 |
43 virtual void OnHandshakeMessage( | 44 virtual void OnHandshakeMessage( |
44 const CryptoHandshakeMessage& message) OVERRIDE { | 45 const CryptoHandshakeMessage& message) OVERRIDE { |
45 encryption_established_ = true; | 46 encryption_established_ = true; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const char data[] = | 273 const char data[] = |
273 "\0\0\0\0" // priority | 274 "\0\0\0\0" // priority |
274 "\1\0\0\0" // headers id | 275 "\1\0\0\0" // headers id |
275 "\0\0\0\4" // length | 276 "\0\0\0\4" // length |
276 "abcd"; // invalid compressed data | 277 "abcd"; // invalid compressed data |
277 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); | 278 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); |
278 stream->ProcessRawData(data, arraysize(data)); | 279 stream->ProcessRawData(data, arraysize(data)); |
279 } | 280 } |
280 } | 281 } |
281 | 282 |
| 283 TEST_P(QuicSessionTest, DebugDFatalIfMarkingClosedStreamWriteBlocked) { |
| 284 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
| 285 // Close the stream. |
| 286 stream2->Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| 287 // TODO(rtenneti): enable when chromium supports EXPECT_DEBUG_DFATAL. |
| 288 /* |
| 289 QuicStreamId kClosedStreamId = stream2->id(); |
| 290 EXPECT_DEBUG_DFATAL( |
| 291 session_.MarkWriteBlocked(kClosedStreamId, kSomeMiddlePriority), |
| 292 "Marking unknown stream 2 blocked."); |
| 293 */ |
| 294 } |
| 295 |
| 296 TEST_P(QuicSessionTest, DebugDFatalIfMarkWriteBlockedCalledWithWrongPriority) { |
| 297 const QuicPriority kDifferentPriority = 0; |
| 298 |
| 299 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
| 300 EXPECT_NE(kDifferentPriority, stream2->EffectivePriority()); |
| 301 // TODO(rtenneti): enable when chromium supports EXPECT_DEBUG_DFATAL. |
| 302 /* |
| 303 EXPECT_DEBUG_DFATAL( |
| 304 session_.MarkWriteBlocked(stream2->id(), kDifferentPriority), |
| 305 "Priorities do not match. Got: 0 Expected: 3"); |
| 306 */ |
| 307 } |
| 308 |
282 TEST_P(QuicSessionTest, OnCanWrite) { | 309 TEST_P(QuicSessionTest, OnCanWrite) { |
283 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 310 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
284 TestStream* stream4 = session_.CreateOutgoingDataStream(); | 311 TestStream* stream4 = session_.CreateOutgoingDataStream(); |
285 TestStream* stream6 = session_.CreateOutgoingDataStream(); | 312 TestStream* stream6 = session_.CreateOutgoingDataStream(); |
286 | 313 |
287 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); | 314 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); |
288 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); | 315 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); |
289 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority); | 316 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority); |
290 | 317 |
291 InSequence s; | 318 InSequence s; |
(...skipping 15 matching lines...) Expand all Loading... |
307 StreamBlocker stream2_blocker(&session_, stream2->id()); | 334 StreamBlocker stream2_blocker(&session_, stream2->id()); |
308 stream2_blocker.MarkWriteBlocked(); | 335 stream2_blocker.MarkWriteBlocked(); |
309 EXPECT_FALSE(session_.HasPendingHandshake()); | 336 EXPECT_FALSE(session_.HasPendingHandshake()); |
310 | 337 |
311 TestStream* stream3 = session_.CreateOutgoingDataStream(); | 338 TestStream* stream3 = session_.CreateOutgoingDataStream(); |
312 StreamBlocker stream3_blocker(&session_, stream3->id()); | 339 StreamBlocker stream3_blocker(&session_, stream3->id()); |
313 stream3_blocker.MarkWriteBlocked(); | 340 stream3_blocker.MarkWriteBlocked(); |
314 EXPECT_FALSE(session_.HasPendingHandshake()); | 341 EXPECT_FALSE(session_.HasPendingHandshake()); |
315 | 342 |
316 // Blocking (due to buffering of) the Crypto stream is detected. | 343 // Blocking (due to buffering of) the Crypto stream is detected. |
317 session_.MarkWriteBlocked(kCryptoStreamId, kSomeMiddlePriority); | 344 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority); |
318 EXPECT_TRUE(session_.HasPendingHandshake()); | 345 EXPECT_TRUE(session_.HasPendingHandshake()); |
319 | 346 |
320 TestStream* stream4 = session_.CreateOutgoingDataStream(); | 347 TestStream* stream4 = session_.CreateOutgoingDataStream(); |
321 StreamBlocker stream4_blocker(&session_, stream4->id()); | 348 StreamBlocker stream4_blocker(&session_, stream4->id()); |
322 stream4_blocker.MarkWriteBlocked(); | 349 stream4_blocker.MarkWriteBlocked(); |
323 EXPECT_TRUE(session_.HasPendingHandshake()); | 350 EXPECT_TRUE(session_.HasPendingHandshake()); |
324 | 351 |
325 InSequence s; | 352 InSequence s; |
326 // Force most streams to re-register, which is common scenario when we block | 353 // Force most streams to re-register, which is common scenario when we block |
327 // the Crypto stream, and only the crypto stream can "really" write. | 354 // the Crypto stream, and only the crypto stream can "really" write. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 531 } |
505 | 532 |
506 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR); | 533 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR); |
507 session_.OnRstStream(rst1); | 534 session_.OnRstStream(rst1); |
508 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 535 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
509 } | 536 } |
510 | 537 |
511 } // namespace | 538 } // namespace |
512 } // namespace test | 539 } // namespace test |
513 } // namespace net | 540 } // namespace net |
OLD | NEW |