- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / quic_ack_notifier_test.cc
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.
4
5 #include "net/quic/quic_ack_notifier.h"
6
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"
10
11 namespace net {
12 namespace test {
13 namespace {
14
15 class QuicAckNotifierTest : public ::testing::Test {
16  protected:
17   virtual void SetUp() {
18     notifier_.reset(new QuicAckNotifier(&delegate_));
19
20     sequence_numbers_.insert(26);
21     sequence_numbers_.insert(99);
22     sequence_numbers_.insert(1234);
23     notifier_->AddSequenceNumbers(sequence_numbers_);
24   }
25
26   SequenceNumberSet sequence_numbers_;
27   MockAckNotifierDelegate delegate_;
28   scoped_ptr<QuicAckNotifier> notifier_;
29 };
30
31 // Should trigger callback when we receive acks for all the registered seqnums.
32 TEST_F(QuicAckNotifierTest, TriggerCallback) {
33   EXPECT_CALL(delegate_, OnAckNotification()).Times(1);
34   EXPECT_FALSE(notifier_->OnAck(26));
35   EXPECT_FALSE(notifier_->OnAck(99));
36   EXPECT_TRUE(notifier_->OnAck(1234));
37 }
38
39 // Should not trigger callback if we never provide all the seqnums.
40 TEST_F(QuicAckNotifierTest, DoesNotTrigger) {
41   // Should not trigger callback as not all packets have been seen.
42   EXPECT_CALL(delegate_, OnAckNotification()).Times(0);
43   EXPECT_FALSE(notifier_->OnAck(26));
44   EXPECT_FALSE(notifier_->OnAck(99));
45 }
46
47 // Should trigger even after updating sequence numbers and receiving ACKs for
48 // new sequeunce numbers.
49 TEST_F(QuicAckNotifierTest, UpdateSeqNums) {
50   // Update a couple of the sequence numbers (i.e. retransmitted packets)
51   notifier_->UpdateSequenceNumber(99, 3000);
52   notifier_->UpdateSequenceNumber(1234, 3001);
53
54   EXPECT_CALL(delegate_, OnAckNotification()).Times(1);
55   EXPECT_FALSE(notifier_->OnAck(26));  // original
56   EXPECT_FALSE(notifier_->OnAck(3000));  // updated
57   EXPECT_TRUE(notifier_->OnAck(3001));  // updated
58 }
59
60 }  // namespace
61 }  // namespace test
62 }  // namespace net