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 "net/quic/congestion_control/inter_arrival_receiver.h"
7 #include "net/quic/test_tools/mock_clock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
13 class InterArrivalReceiverTest
: public ::testing::Test
{
15 InterArrivalReceiver receiver_
;
19 TEST_F(InterArrivalReceiverTest
, SimpleReceiver
) {
20 QuicTime start
= clock_
.ApproximateNow();
21 QuicTime::Delta received_delta
= QuicTime::Delta::FromMilliseconds(10);
22 clock_
.AdvanceTime(received_delta
);
23 QuicTime receive_timestamp
= clock_
.ApproximateNow();
24 receiver_
.RecordIncomingPacket(1, 1, receive_timestamp
, false);
26 QuicCongestionFeedbackFrame feedback
;
27 ASSERT_FALSE(receiver_
.GenerateCongestionFeedback(&feedback
));
29 clock_
.AdvanceTime(received_delta
);
30 receive_timestamp
= clock_
.ApproximateNow();
31 // Packet not received; but rather revived by FEC.
32 receiver_
.RecordIncomingPacket(1, 2, receive_timestamp
, true);
33 clock_
.AdvanceTime(received_delta
);
34 receive_timestamp
= clock_
.ApproximateNow();
35 receiver_
.RecordIncomingPacket(1, 3, receive_timestamp
, false);
37 ASSERT_TRUE(receiver_
.GenerateCongestionFeedback(&feedback
));
39 EXPECT_EQ(kInterArrival
, feedback
.type
);
40 EXPECT_EQ(1, feedback
.inter_arrival
.accumulated_number_of_lost_packets
);
41 EXPECT_EQ(3u, feedback
.inter_arrival
.received_packet_times
.size());
42 TimeMap::iterator it
= feedback
.inter_arrival
.received_packet_times
.begin();
43 EXPECT_EQ(1u, it
->first
);
44 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(10), it
->second
.Subtract(start
));
45 it
= feedback
.inter_arrival
.received_packet_times
.begin();
47 EXPECT_EQ(2u, it
->first
);
48 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(20), it
->second
.Subtract(start
));
50 EXPECT_EQ(3u, it
->first
);
51 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(30), it
->second
.Subtract(start
));