Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / quic / quic_ack_notifier_test.cc
blobd57235f91c9abc02e355d988ab616735b8e8661a
1 // Copyright 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 "net/quic/quic_ack_notifier.h"
7 #include "net/quic/test_tools/quic_test_utils.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 using testing::_;
13 namespace net {
14 namespace test {
15 namespace {
17 class QuicAckNotifierTest : public ::testing::Test {
18 protected:
19 QuicAckNotifierTest() : zero_(QuicTime::Delta::Zero()) {}
21 void SetUp() override {
22 delegate_ = new MockAckNotifierDelegate;
23 notifier_.reset(new QuicAckNotifier(delegate_));
25 notifier_->OnSerializedPacket();
26 notifier_->OnSerializedPacket();
27 notifier_->OnSerializedPacket();
30 MockAckNotifierDelegate* delegate_;
31 scoped_ptr<QuicAckNotifier> notifier_;
32 QuicTime::Delta zero_;
35 // Should trigger callback when we receive acks for all the registered packet
36 // numbers.
37 TEST_F(QuicAckNotifierTest, TriggerCallback) {
38 EXPECT_CALL(*delegate_, OnAckNotification(0, 0, zero_)).Times(1);
39 EXPECT_FALSE(notifier_->OnAck(zero_));
40 EXPECT_FALSE(notifier_->OnAck(zero_));
41 EXPECT_TRUE(notifier_->OnAck(zero_));
44 // Should not trigger callback if we never provide all the packet numbers.
45 TEST_F(QuicAckNotifierTest, DoesNotTrigger) {
46 // Should not trigger callback as not all packets have been seen.
47 EXPECT_CALL(*delegate_, OnAckNotification(_, _, _)).Times(0);
48 EXPECT_FALSE(notifier_->OnAck(zero_));
49 EXPECT_FALSE(notifier_->OnAck(zero_));
52 // Should not trigger callback if we abandon all three packets.
53 TEST_F(QuicAckNotifierTest, AbandonDoesNotTrigger) {
54 // Should not trigger callback as not all packets have been seen.
55 EXPECT_CALL(*delegate_, OnAckNotification(_, _, _)).Times(0);
56 EXPECT_FALSE(notifier_->OnPacketAbandoned());
57 EXPECT_FALSE(notifier_->OnPacketAbandoned());
58 EXPECT_TRUE(notifier_->OnPacketAbandoned());
61 // Should trigger even after updating packet numbers and receiving ACKs for
62 // new packet numbers.
63 TEST_F(QuicAckNotifierTest, UpdatePacketNumbers) {
64 // Update a couple of the packet numbers (i.e. retransmitted packets)
65 notifier_->OnPacketRetransmitted(20);
66 notifier_->OnPacketRetransmitted(3);
68 EXPECT_CALL(*delegate_, OnAckNotification(2, 20 + 3, _)).Times(1);
69 EXPECT_FALSE(notifier_->OnAck(zero_)); // original
70 EXPECT_FALSE(notifier_->OnAck(zero_)); // updated
71 EXPECT_TRUE(notifier_->OnAck(zero_)); // updated
74 // Make sure the delegate is called with the delta time from the last ACK.
75 TEST_F(QuicAckNotifierTest, DeltaTime) {
76 const QuicTime::Delta first_delta = QuicTime::Delta::FromSeconds(5);
77 const QuicTime::Delta second_delta = QuicTime::Delta::FromSeconds(33);
78 const QuicTime::Delta third_delta = QuicTime::Delta::FromSeconds(10);
80 EXPECT_CALL(*delegate_, OnAckNotification(0, 0, third_delta)).Times(1);
81 EXPECT_FALSE(notifier_->OnAck(first_delta));
82 EXPECT_FALSE(notifier_->OnAck(second_delta));
83 EXPECT_TRUE(notifier_->OnAck(third_delta));
86 } // namespace
87 } // namespace test
88 } // namespace net