| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // Test of the full congestion control chain. | 5 // Test of the full congestion control chain. |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/quic/congestion_control/quic_congestion_manager.h" | 9 #include "net/quic/congestion_control/quic_congestion_manager.h" |
| 10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
| 11 #include "net/quic/test_tools/mock_clock.h" | 11 #include "net/quic/test_tools/mock_clock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using std::max; | 14 using std::max; |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 namespace test { | 17 namespace test { |
| 18 | 18 |
| 19 class QuicCongestionManagerPeer : public QuicCongestionManager { | 19 class QuicCongestionManagerPeer : public QuicCongestionManager { |
| 20 public: | 20 public: |
| 21 explicit QuicCongestionManagerPeer(const QuicClock* clock, | 21 explicit QuicCongestionManagerPeer(const QuicClock* clock, |
| 22 CongestionFeedbackType congestion_type) | 22 CongestionFeedbackType congestion_type) |
| 23 : QuicCongestionManager(clock, congestion_type) { | 23 : QuicCongestionManager(clock, congestion_type) { |
| 24 } | 24 } |
| 25 using QuicCongestionManager::SentBandwidth; | |
| 26 using QuicCongestionManager::BandwidthEstimate; | 25 using QuicCongestionManager::BandwidthEstimate; |
| 27 }; | 26 }; |
| 28 | 27 |
| 29 class QuicCongestionControlTest : public ::testing::Test { | 28 class QuicCongestionControlTest : public ::testing::Test { |
| 30 protected: | 29 protected: |
| 31 QuicCongestionControlTest() | 30 QuicCongestionControlTest() |
| 32 : start_(clock_.ApproximateNow()) { | 31 : start_(clock_.ApproximateNow()) { |
| 33 } | 32 } |
| 34 | 33 |
| 35 void SetUpCongestionType(CongestionFeedbackType congestion_type) { | 34 void SetUpCongestionType(CongestionFeedbackType congestion_type) { |
| 36 manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type)); | 35 manager_.reset(new QuicCongestionManagerPeer(&clock_, congestion_type)); |
| 37 } | 36 } |
| 38 | 37 |
| 39 MockClock clock_; | 38 MockClock clock_; |
| 40 QuicTime start_; | 39 QuicTime start_; |
| 41 scoped_ptr<QuicCongestionManagerPeer> manager_; | 40 scoped_ptr<QuicCongestionManagerPeer> manager_; |
| 42 }; | 41 }; |
| 43 | 42 |
| 44 TEST_F(QuicCongestionControlTest, FixedRateSenderAPI) { | 43 TEST_F(QuicCongestionControlTest, FixedRateSenderAPI) { |
| 45 SetUpCongestionType(kFixRate); | 44 SetUpCongestionType(kFixRate); |
| 46 QuicCongestionFeedbackFrame congestion_feedback; | 45 QuicCongestionFeedbackFrame congestion_feedback; |
| 47 congestion_feedback.type = kFixRate; | 46 congestion_feedback.type = kFixRate; |
| 48 congestion_feedback.fix_rate.bitrate = QuicBandwidth::FromKBytesPerSecond(30); | 47 congestion_feedback.fix_rate.bitrate = QuicBandwidth::FromKBytesPerSecond(30); |
| 49 manager_->OnIncomingQuicCongestionFeedbackFrame(congestion_feedback, | 48 manager_->OnIncomingQuicCongestionFeedbackFrame(congestion_feedback, |
| 50 clock_.Now()); | 49 clock_.Now()); |
| 51 EXPECT_TRUE(manager_->SentBandwidth(clock_.Now()).IsZero()); | |
| 52 EXPECT_TRUE(manager_->TimeUntilSend( | 50 EXPECT_TRUE(manager_->TimeUntilSend( |
| 53 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero()); | 51 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA).IsZero()); |
| 54 manager_->SentPacket(1, clock_.Now(), kMaxPacketSize, NOT_RETRANSMISSION); | 52 manager_->SentPacket(1, clock_.Now(), kMaxPacketSize, NOT_RETRANSMISSION); |
| 55 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(40), | 53 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(40), |
| 56 manager_->TimeUntilSend( | 54 manager_->TimeUntilSend( |
| 57 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)); | 55 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)); |
| 58 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(35)); | 56 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(35)); |
| 59 EXPECT_EQ(QuicTime::Delta::Infinite(), | 57 EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 60 manager_->TimeUntilSend( | 58 manager_->TimeUntilSend( |
| 61 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)); | 59 clock_.Now(), NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(120), | 127 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(120), |
| 130 acc_advance_time.Subtract(start_)); | 128 acc_advance_time.Subtract(start_)); |
| 131 } | 129 } |
| 132 | 130 |
| 133 // TODO(pwestin): add TCP tests. | 131 // TODO(pwestin): add TCP tests. |
| 134 | 132 |
| 135 // TODO(pwestin): add InterArrival tests. | 133 // TODO(pwestin): add InterArrival tests. |
| 136 | 134 |
| 137 } // namespace test | 135 } // namespace test |
| 138 } // namespace net | 136 } // namespace net |
| OLD | NEW |