OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // Test for FixRate sender and receiver. | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "net/quic/congestion_control/fix_rate_receiver.h" | |
10 #include "net/quic/congestion_control/fix_rate_sender.h" | |
11 #include "net/quic/congestion_control/rtt_stats.h" | |
12 #include "net/quic/quic_protocol.h" | |
13 #include "net/quic/test_tools/mock_clock.h" | |
14 #include "testing/gmock/include/gmock/gmock.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | |
16 | |
17 namespace net { | |
18 namespace test { | |
19 | |
20 // bytes_in_flight is unused by FixRateSender's OnPacketSent. | |
21 QuicByteCount kUnused = 0; | |
22 | |
23 class FixRateReceiverPeer : public FixRateReceiver { | |
24 public: | |
25 FixRateReceiverPeer() | |
26 : FixRateReceiver() { | |
27 } | |
28 void SetBitrate(QuicBandwidth fix_rate) { | |
29 FixRateReceiver::configured_rate_ = fix_rate; | |
30 } | |
31 }; | |
32 | |
33 class FixRateTest : public ::testing::Test { | |
34 protected: | |
35 FixRateTest() | |
36 : sender_(new FixRateSender(&rtt_stats_)), | |
37 receiver_(new FixRateReceiverPeer()), | |
38 start_(clock_.Now()) { | |
39 // Make sure clock does not start at 0. | |
40 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); | |
41 } | |
42 RttStats rtt_stats_; | |
43 MockClock clock_; | |
44 scoped_ptr<FixRateSender> sender_; | |
45 scoped_ptr<FixRateReceiverPeer> receiver_; | |
46 const QuicTime start_; | |
47 }; | |
48 | |
49 TEST_F(FixRateTest, ReceiverAPI) { | |
50 QuicCongestionFeedbackFrame feedback; | |
51 QuicTime timestamp(QuicTime::Zero()); | |
52 receiver_->SetBitrate(QuicBandwidth::FromKBytesPerSecond(300)); | |
53 receiver_->RecordIncomingPacket(1, 1, timestamp); | |
54 ASSERT_TRUE(receiver_->GenerateCongestionFeedback(&feedback)); | |
55 EXPECT_EQ(kFixRate, feedback.type); | |
56 EXPECT_EQ(300000u, feedback.fix_rate.bitrate.ToBytesPerSecond()); | |
57 } | |
58 | |
59 TEST_F(FixRateTest, SenderAPI) { | |
60 QuicCongestionFeedbackFrame feedback; | |
61 feedback.type = kFixRate; | |
62 feedback.fix_rate.bitrate = QuicBandwidth::FromKBytesPerSecond(300); | |
63 sender_->OnIncomingQuicCongestionFeedbackFrame(feedback, clock_.Now()); | |
64 EXPECT_EQ(300000, sender_->BandwidthEstimate().ToBytesPerSecond()); | |
65 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | |
66 0, | |
67 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
68 | |
69 sender_->OnPacketSent(clock_.Now(), kUnused, 1, kDefaultMaxPacketSize, | |
70 HAS_RETRANSMITTABLE_DATA); | |
71 EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), | |
72 kDefaultMaxPacketSize, | |
73 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
74 clock_.AdvanceTime(sender_->TimeUntilSend(clock_.Now(), | |
75 kDefaultMaxPacketSize, | |
76 HAS_RETRANSMITTABLE_DATA)); | |
77 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | |
78 kDefaultMaxPacketSize, | |
79 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
80 sender_->OnPacketSent(clock_.Now(), kUnused, 2, kDefaultMaxPacketSize, | |
81 HAS_RETRANSMITTABLE_DATA); | |
82 EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), | |
83 kDefaultMaxPacketSize, | |
84 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
85 // Advance the time twice as much and expect only one packet to be sent. | |
86 clock_.AdvanceTime(sender_->TimeUntilSend( | |
87 clock_.Now(), | |
88 kDefaultMaxPacketSize, | |
89 HAS_RETRANSMITTABLE_DATA).Multiply(2)); | |
90 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | |
91 kDefaultMaxPacketSize, | |
92 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
93 sender_->OnPacketSent(clock_.Now(), kUnused, 3, kDefaultMaxPacketSize, | |
94 HAS_RETRANSMITTABLE_DATA); | |
95 EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(), | |
96 kDefaultMaxPacketSize, | |
97 HAS_RETRANSMITTABLE_DATA).IsZero()); | |
98 } | |
99 | |
100 } // namespace test | |
101 } // namespace net | |
OLD | NEW |