OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_ack_notifier.h" | 5 #include "net/quic/quic_ack_notifier.h" |
6 | 6 |
7 #include "net/quic/test_tools/quic_test_utils.h" | 7 #include "net/quic/test_tools/quic_test_utils.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 using testing::_; | 11 using testing::_; |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 namespace test { | 14 namespace test { |
15 namespace { | 15 namespace { |
16 | 16 |
17 class QuicAckNotifierTest : public ::testing::Test { | 17 class QuicAckNotifierTest : public ::testing::Test { |
18 protected: | 18 protected: |
| 19 QuicAckNotifierTest() : zero_(QuicTime::Delta::Zero()) {} |
| 20 |
19 virtual void SetUp() { | 21 virtual void SetUp() { |
20 delegate_ = new MockAckNotifierDelegate; | 22 delegate_ = new MockAckNotifierDelegate; |
21 notifier_.reset(new QuicAckNotifier(delegate_)); | 23 notifier_.reset(new QuicAckNotifier(delegate_)); |
22 | 24 |
23 notifier_->AddSequenceNumber(26, 100); | 25 notifier_->AddSequenceNumber(26, 100); |
24 notifier_->AddSequenceNumber(99, 20); | 26 notifier_->AddSequenceNumber(99, 20); |
25 notifier_->AddSequenceNumber(1234, 3); | 27 notifier_->AddSequenceNumber(1234, 3); |
26 } | 28 } |
27 | 29 |
28 MockAckNotifierDelegate* delegate_; | 30 MockAckNotifierDelegate* delegate_; |
29 scoped_ptr<QuicAckNotifier> notifier_; | 31 scoped_ptr<QuicAckNotifier> notifier_; |
| 32 QuicTime::Delta zero_; |
30 }; | 33 }; |
31 | 34 |
32 // Should trigger callback when we receive acks for all the registered seqnums. | 35 // Should trigger callback when we receive acks for all the registered seqnums. |
33 TEST_F(QuicAckNotifierTest, TriggerCallback) { | 36 TEST_F(QuicAckNotifierTest, TriggerCallback) { |
34 EXPECT_CALL(*delegate_, OnAckNotification(3, 123, 0, 0)).Times(1); | 37 EXPECT_CALL(*delegate_, OnAckNotification(3, 123, 0, 0, zero_)).Times(1); |
35 EXPECT_FALSE(notifier_->OnAck(26)); | 38 EXPECT_FALSE(notifier_->OnAck(26, zero_)); |
36 EXPECT_FALSE(notifier_->OnAck(99)); | 39 EXPECT_FALSE(notifier_->OnAck(99, zero_)); |
37 EXPECT_TRUE(notifier_->OnAck(1234)); | 40 EXPECT_TRUE(notifier_->OnAck(1234, zero_)); |
38 } | 41 } |
39 | 42 |
40 // Should not trigger callback if we never provide all the seqnums. | 43 // Should not trigger callback if we never provide all the seqnums. |
41 TEST_F(QuicAckNotifierTest, DoesNotTrigger) { | 44 TEST_F(QuicAckNotifierTest, DoesNotTrigger) { |
42 // Should not trigger callback as not all packets have been seen. | 45 // Should not trigger callback as not all packets have been seen. |
43 EXPECT_CALL(*delegate_, OnAckNotification(_, _, _, _)).Times(0); | 46 EXPECT_CALL(*delegate_, OnAckNotification(_, _, _, _, _)).Times(0); |
44 EXPECT_FALSE(notifier_->OnAck(26)); | 47 EXPECT_FALSE(notifier_->OnAck(26, zero_)); |
45 EXPECT_FALSE(notifier_->OnAck(99)); | 48 EXPECT_FALSE(notifier_->OnAck(99, zero_)); |
46 } | 49 } |
47 | 50 |
48 // Should trigger even after updating sequence numbers and receiving ACKs for | 51 // Should trigger even after updating sequence numbers and receiving ACKs for |
49 // new sequeunce numbers. | 52 // new sequeunce numbers. |
50 TEST_F(QuicAckNotifierTest, UpdateSeqNums) { | 53 TEST_F(QuicAckNotifierTest, UpdateSeqNums) { |
51 // Update a couple of the sequence numbers (i.e. retransmitted packets) | 54 // Update a couple of the sequence numbers (i.e. retransmitted packets) |
52 notifier_->UpdateSequenceNumber(99, 3000); | 55 notifier_->UpdateSequenceNumber(99, 3000); |
53 notifier_->UpdateSequenceNumber(1234, 3001); | 56 notifier_->UpdateSequenceNumber(1234, 3001); |
54 | 57 |
55 EXPECT_CALL(*delegate_, OnAckNotification(3, 123, 2, 20 + 3)).Times(1); | 58 EXPECT_CALL(*delegate_, OnAckNotification(3, 123, 2, 20 + 3, _)).Times(1); |
56 EXPECT_FALSE(notifier_->OnAck(26)); // original | 59 EXPECT_FALSE(notifier_->OnAck(26, zero_)); // original |
57 EXPECT_FALSE(notifier_->OnAck(3000)); // updated | 60 EXPECT_FALSE(notifier_->OnAck(3000, zero_)); // updated |
58 EXPECT_TRUE(notifier_->OnAck(3001)); // updated | 61 EXPECT_TRUE(notifier_->OnAck(3001, zero_)); // updated |
| 62 } |
| 63 |
| 64 // Make sure the delegate is called with the delta time from the last ACK. |
| 65 TEST_F(QuicAckNotifierTest, DeltaTime) { |
| 66 const QuicTime::Delta first_delta = QuicTime::Delta::FromSeconds(5); |
| 67 const QuicTime::Delta second_delta = QuicTime::Delta::FromSeconds(33); |
| 68 const QuicTime::Delta third_delta = QuicTime::Delta::FromSeconds(10); |
| 69 |
| 70 EXPECT_CALL(*delegate_, |
| 71 OnAckNotification(3, 123, 0, 0, third_delta)) |
| 72 .Times(1); |
| 73 EXPECT_FALSE(notifier_->OnAck(26, first_delta)); |
| 74 EXPECT_FALSE(notifier_->OnAck(99, second_delta)); |
| 75 EXPECT_TRUE(notifier_->OnAck(1234, third_delta)); |
59 } | 76 } |
60 | 77 |
61 } // namespace | 78 } // namespace |
62 } // namespace test | 79 } // namespace test |
63 } // namespace net | 80 } // namespace net |
OLD | NEW |