1 // Copyright 2014 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 "net/quic/quic_connection_logger.h"
7 #include "net/quic/quic_protocol.h"
8 #include "net/quic/test_tools/quic_test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h"
14 class QuicConnectionLoggerPeer
{
16 static size_t num_truncated_acks_sent(const QuicConnectionLogger
& logger
) {
17 return logger
.num_truncated_acks_sent_
;
20 static void set_num_packets_received(QuicConnectionLogger
& logger
,
22 logger
.num_packets_received_
= value
;
25 static void set_largest_received_packet_sequence_number(
26 QuicConnectionLogger
& logger
,
28 logger
.largest_received_packet_sequence_number_
= value
;
32 class QuicConnectionLoggerTest
: public ::testing::Test
{
34 QuicConnectionLoggerTest()
35 : session_(new MockConnection(Perspective::IS_CLIENT
)),
36 logger_(&session_
, "CONNECTION_UNKNOWN", net_log_
) {}
39 MockQuicSpdySession session_
;
40 QuicConnectionLogger logger_
;
43 TEST_F(QuicConnectionLoggerTest
, TruncatedAcksSentNotChanged
) {
45 logger_
.OnFrameAddedToPacket(QuicFrame(&frame
));
46 EXPECT_EQ(0u, QuicConnectionLoggerPeer::num_truncated_acks_sent(logger_
));
48 for (QuicPacketSequenceNumber i
= 0; i
< 256; ++i
) {
49 frame
.missing_packets
.insert(i
);
51 logger_
.OnFrameAddedToPacket(QuicFrame(&frame
));
52 EXPECT_EQ(0u, QuicConnectionLoggerPeer::num_truncated_acks_sent(logger_
));
55 TEST_F(QuicConnectionLoggerTest
, TruncatedAcksSent
) {
57 for (QuicPacketSequenceNumber i
= 0; i
< 512; i
+= 2) {
58 frame
.missing_packets
.insert(i
);
60 logger_
.OnFrameAddedToPacket(QuicFrame(&frame
));
61 EXPECT_EQ(1u, QuicConnectionLoggerPeer::num_truncated_acks_sent(logger_
));
64 TEST_F(QuicConnectionLoggerTest
, ReceivedPacketLossRate
) {
65 QuicConnectionLoggerPeer::set_num_packets_received(logger_
, 1);
66 QuicConnectionLoggerPeer::set_largest_received_packet_sequence_number(logger_
,
68 EXPECT_EQ(0.5f
, logger_
.ReceivedPacketLossRate());