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 10 matching lines...) Expand all Loading... |
21 #include "net/spdy/spdy_framer.h" | 21 #include "net/spdy/spdy_framer.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using base::hash_map; | 25 using base::hash_map; |
26 using std::set; | 26 using std::set; |
27 using std::vector; | 27 using std::vector; |
28 using testing::_; | 28 using testing::_; |
29 using testing::InSequence; | 29 using testing::InSequence; |
30 using testing::InvokeWithoutArgs; | 30 using testing::InvokeWithoutArgs; |
| 31 using testing::Return; |
31 using testing::StrictMock; | 32 using testing::StrictMock; |
32 | 33 |
33 namespace net { | 34 namespace net { |
34 namespace test { | 35 namespace test { |
35 namespace { | 36 namespace { |
36 | 37 |
37 const QuicPriority kHighestPriority = 0; | 38 const QuicPriority kHighestPriority = 0; |
38 const QuicPriority kSomeMiddlePriority = 3; | 39 const QuicPriority kSomeMiddlePriority = 3; |
39 | 40 |
40 class TestCryptoStream : public QuicCryptoStream { | 41 class TestCryptoStream : public QuicCryptoStream { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 StreamBlocker stream2_blocker(&session_, stream2->id()); | 322 StreamBlocker stream2_blocker(&session_, stream2->id()); |
322 EXPECT_CALL(*stream2, OnCanWrite()).WillOnce( | 323 EXPECT_CALL(*stream2, OnCanWrite()).WillOnce( |
323 // Reregister, to test the loop limit. | 324 // Reregister, to test the loop limit. |
324 InvokeWithoutArgs(&stream2_blocker, &StreamBlocker::MarkWriteBlocked)); | 325 InvokeWithoutArgs(&stream2_blocker, &StreamBlocker::MarkWriteBlocked)); |
325 EXPECT_CALL(*stream6, OnCanWrite()); | 326 EXPECT_CALL(*stream6, OnCanWrite()); |
326 EXPECT_CALL(*stream4, OnCanWrite()); | 327 EXPECT_CALL(*stream4, OnCanWrite()); |
327 | 328 |
328 EXPECT_FALSE(session_.OnCanWrite()); | 329 EXPECT_FALSE(session_.OnCanWrite()); |
329 } | 330 } |
330 | 331 |
| 332 TEST_P(QuicSessionTest, OnCanWriteCongestionControlBlocks) { |
| 333 InSequence s; |
| 334 |
| 335 // Drive congestion control manually. |
| 336 MockSendAlgorithm* send_algorithm = new StrictMock<MockSendAlgorithm>; |
| 337 QuicConnectionPeer::SetSendAlgorithm(session_.connection(), send_algorithm); |
| 338 |
| 339 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
| 340 TestStream* stream4 = session_.CreateOutgoingDataStream(); |
| 341 TestStream* stream6 = session_.CreateOutgoingDataStream(); |
| 342 |
| 343 session_.MarkWriteBlocked(stream2->id(), kSomeMiddlePriority); |
| 344 session_.MarkWriteBlocked(stream6->id(), kSomeMiddlePriority); |
| 345 session_.MarkWriteBlocked(stream4->id(), kSomeMiddlePriority); |
| 346 |
| 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. |
| 357 |
| 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()); |
| 361 |
| 362 // Still congestion-control blocked. |
| 363 EXPECT_CALL(*send_algorithm, TimeUntilSend(_, _, _, _)).WillOnce(Return( |
| 364 QuicTime::Delta::Infinite())); |
| 365 EXPECT_FALSE(session_.OnCanWrite()); |
| 366 |
| 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()); |
| 373 } |
| 374 |
331 TEST_P(QuicSessionTest, BufferedHandshake) { | 375 TEST_P(QuicSessionTest, BufferedHandshake) { |
332 EXPECT_FALSE(session_.HasPendingHandshake()); // Default value. | 376 EXPECT_FALSE(session_.HasPendingHandshake()); // Default value. |
333 | 377 |
334 // Test that blocking other streams does not change our status. | 378 // Test that blocking other streams does not change our status. |
335 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 379 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
336 StreamBlocker stream2_blocker(&session_, stream2->id()); | 380 StreamBlocker stream2_blocker(&session_, stream2->id()); |
337 stream2_blocker.MarkWriteBlocked(); | 381 stream2_blocker.MarkWriteBlocked(); |
338 EXPECT_FALSE(session_.HasPendingHandshake()); | 382 EXPECT_FALSE(session_.HasPendingHandshake()); |
339 | 383 |
340 TestStream* stream3 = session_.CreateOutgoingDataStream(); | 384 TestStream* stream3 = session_.CreateOutgoingDataStream(); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 } | 577 } |
534 | 578 |
535 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR); | 579 QuicRstStreamFrame rst1(stream_id1, QUIC_STREAM_NO_ERROR); |
536 session_.OnRstStream(rst1); | 580 session_.OnRstStream(rst1); |
537 EXPECT_EQ(0u, session_.GetNumOpenStreams()); | 581 EXPECT_EQ(0u, session_.GetNumOpenStreams()); |
538 } | 582 } |
539 | 583 |
540 } // namespace | 584 } // namespace |
541 } // namespace test | 585 } // namespace test |
542 } // namespace net | 586 } // namespace net |
OLD | NEW |