Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / net / quic / congestion_control / available_channel_estimator_test.cc
blobb4a4b9c341c2e879a419c7534c0ce97a9dde6f9b
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"
11 namespace net {
12 namespace test {
14 class AvailableChannelEstimatorTest : public ::testing::Test {
15 protected:
16 virtual void SetUp() {
17 srand(1234);
18 packet_size_ = 1200;
19 sequence_number_ = 1;
20 QuicTime receive_time = receive_clock_.Now();
21 QuicTime sent_time = send_clock_.Now();
22 estimator_.reset(new AvailableChannelEstimator(sequence_number_,
23 sent_time,
24 receive_time));
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_,
43 packet_size_,
44 sent_time,
45 receive_time);
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_,
55 packet_size_,
56 sent_time,
57 receive_time);
58 EXPECT_EQ(kAvailableChannelEstimateUncertain,
59 estimator_->GetAvailableChannelEstimate(&bandwidth));
61 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
62 bandwidth);
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_,
76 packet_size_,
77 sent_time,
78 receive_time);
80 QuicBandwidth bandwidth = QuicBandwidth::Zero();
81 EXPECT_EQ(kAvailableChannelEstimateUncertain,
82 estimator_->GetAvailableChannelEstimate(&bandwidth));
83 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
84 bandwidth);
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_,
97 packet_size_,
98 sent_time,
99 receive_time);
101 QuicBandwidth bandwidth = QuicBandwidth::Zero();
102 EXPECT_EQ(kAvailableChannelEstimateGood,
103 estimator_->GetAvailableChannelEstimate(&bandwidth));
104 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
105 bandwidth);
108 } // namespace test
109 } // namespace net