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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "net/quic/congestion_control/available_channel_estimator.h"
8 #include "net/quic/test_tools/mock_clock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
14 class AvailableChannelEstimatorTest
: public ::testing::Test
{
16 virtual void SetUp() {
20 QuicTime receive_time
= receive_clock_
.Now();
21 QuicTime sent_time
= send_clock_
.Now();
22 estimator_
.reset(new AvailableChannelEstimator(sequence_number_
,
27 MockClock send_clock_
;
28 MockClock receive_clock_
;
29 QuicPacketSequenceNumber sequence_number_
;
30 QuicByteCount packet_size_
;
31 scoped_ptr
<AvailableChannelEstimator
> estimator_
;
34 TEST_F(AvailableChannelEstimatorTest
, SimpleBasic
) {
35 QuicBandwidth bandwidth
= QuicBandwidth::Zero();
36 QuicTime::Delta received_delta
= QuicTime::Delta::FromMilliseconds(10);
37 QuicTime::Delta send_delta
= QuicTime::Delta::FromMilliseconds(1);
38 receive_clock_
.AdvanceTime(received_delta
);
39 send_clock_
.AdvanceTime(send_delta
);
40 QuicTime receive_time
= receive_clock_
.Now();
41 QuicTime sent_time
= send_clock_
.Now();
42 estimator_
->OnIncomingFeedback(++sequence_number_
,
46 EXPECT_EQ(kAvailableChannelEstimateUnknown
,
47 estimator_
->GetAvailableChannelEstimate(&bandwidth
));
49 receive_clock_
.AdvanceTime(received_delta
);
50 receive_time
= receive_clock_
.Now();
51 send_clock_
.AdvanceTime(send_delta
);
52 sent_time
= send_clock_
.Now();
54 estimator_
->OnIncomingFeedback(++sequence_number_
,
58 EXPECT_EQ(kAvailableChannelEstimateUncertain
,
59 estimator_
->GetAvailableChannelEstimate(&bandwidth
));
61 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_
, received_delta
),
65 // TODO(pwestin): simulate cross traffic.
66 TEST_F(AvailableChannelEstimatorTest
, SimpleUncertainEstimate
) {
67 QuicTime::Delta received_delta
= QuicTime::Delta::FromMilliseconds(10);
68 QuicTime::Delta send_delta
= QuicTime::Delta::FromMilliseconds(1);
70 for (int i
= 0; i
< 8; ++i
) {
71 receive_clock_
.AdvanceTime(received_delta
);
72 QuicTime receive_time
= receive_clock_
.Now();
73 send_clock_
.AdvanceTime(send_delta
);
74 QuicTime sent_time
= send_clock_
.Now();
75 estimator_
->OnIncomingFeedback(++sequence_number_
,
80 QuicBandwidth bandwidth
= QuicBandwidth::Zero();
81 EXPECT_EQ(kAvailableChannelEstimateUncertain
,
82 estimator_
->GetAvailableChannelEstimate(&bandwidth
));
83 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_
, received_delta
),
87 TEST_F(AvailableChannelEstimatorTest
, SimpleGoodEstimate
) {
88 QuicTime::Delta received_delta
= QuicTime::Delta::FromMilliseconds(10);
89 QuicTime::Delta send_delta
= QuicTime::Delta::FromMilliseconds(1);
91 for (int i
= 0; i
< 100; ++i
) {
92 receive_clock_
.AdvanceTime(received_delta
);
93 QuicTime receive_time
= receive_clock_
.Now();
94 send_clock_
.AdvanceTime(send_delta
);
95 QuicTime sent_time
= send_clock_
.Now();
96 estimator_
->OnIncomingFeedback(++sequence_number_
,
101 QuicBandwidth bandwidth
= QuicBandwidth::Zero();
102 EXPECT_EQ(kAvailableChannelEstimateGood
,
103 estimator_
->GetAvailableChannelEstimate(&bandwidth
));
104 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_
, received_delta
),