Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / net / quic / congestion_control / inter_arrival_probe_test.cc
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.
4
5 #include "net/quic/congestion_control/inter_arrival_probe.h"
6
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace net {
12 namespace test {
13
14 class InterArrivalProbeTest : public ::testing::Test {
15  protected:
16   InterArrivalProbeTest()
17       : probe_(kDefaultMaxPacketSize),
18         start_(QuicTime::Zero()) {
19   }
20
21   InterArrivalProbe probe_;
22   QuicTime start_;
23 };
24
25 TEST_F(InterArrivalProbeTest, CongestionWindow) {
26   for (size_t i = 0; i < 10; i++) {
27     probe_.OnPacketSent(kDefaultMaxPacketSize);
28     EXPECT_EQ((9 - i) * kDefaultMaxPacketSize,
29               probe_.GetAvailableCongestionWindow());
30   }
31   probe_.OnAcknowledgedPacket(kDefaultMaxPacketSize);
32   EXPECT_EQ(kDefaultMaxPacketSize, probe_.GetAvailableCongestionWindow());
33
34   probe_.OnPacketSent(kDefaultMaxPacketSize);
35   EXPECT_EQ(0u, probe_.GetAvailableCongestionWindow());
36 }
37
38 TEST_F(InterArrivalProbeTest, Estimate) {
39   QuicPacketSequenceNumber sequence_number = 1;
40   QuicByteCount bytes_sent = kDefaultMaxPacketSize;
41   QuicTime time_received = start_.Add(QuicTime::Delta::FromMilliseconds(10));
42   QuicTime time_sent = start_.Add(QuicTime::Delta::FromMilliseconds(1));
43   QuicBandwidth available_channel_estimate = QuicBandwidth::Zero();
44
45   for (size_t i = 0; i < 10; ++i) {
46     EXPECT_FALSE(probe_.GetEstimate(&available_channel_estimate));
47
48     probe_.OnIncomingFeedback(sequence_number++,
49                               bytes_sent,
50                               time_sent,
51                               time_received);
52     time_sent = time_sent.Add(QuicTime::Delta::FromMilliseconds(1));
53     time_received = time_received.Add(QuicTime::Delta::FromMilliseconds(10));
54   }
55   EXPECT_TRUE(probe_.GetEstimate(&available_channel_estimate));
56   EXPECT_EQ(kDefaultMaxPacketSize * 100,
57             static_cast<uint64>(available_channel_estimate.ToBytesPerSecond()));
58 }
59
60 TEST_F(InterArrivalProbeTest, EstimateWithLoss) {
61   QuicPacketSequenceNumber sequence_number = 1;
62   QuicByteCount bytes_sent = kDefaultMaxPacketSize;
63   QuicTime time_received = start_.Add(QuicTime::Delta::FromMilliseconds(10));
64   QuicTime time_sent = start_.Add(QuicTime::Delta::FromMilliseconds(1));
65   QuicBandwidth available_channel_estimate = QuicBandwidth::Zero();
66
67   for (size_t i = 0; i < 6; ++i) {
68     EXPECT_FALSE(probe_.GetEstimate(&available_channel_estimate));
69
70     probe_.OnIncomingFeedback(sequence_number,
71                               bytes_sent,
72                               time_sent,
73                               time_received);
74     sequence_number += 2;
75     time_sent = time_sent.Add(QuicTime::Delta::FromMilliseconds(1));
76     time_received = time_received.Add(QuicTime::Delta::FromMilliseconds(10));
77   }
78   EXPECT_TRUE(probe_.GetEstimate(&available_channel_estimate));
79   EXPECT_EQ(kDefaultMaxPacketSize * 50,
80             static_cast<uint64>(available_channel_estimate.ToBytesPerSecond()));
81 }
82
83 }  // namespace test
84 }  // namespace net