Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: net/quic/quic_multipath_received_packet_manager_test.cc

Issue 1541263002: Landing Recent QUIC changes until 12/18/2015 13:57 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: replace -1 with 0xff for InvalidPathId Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_multipath_received_packet_manager.cc ('k') | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015 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_multipath_received_packet_manager.h"
6
7 #include "net/quic/quic_connection_stats.h"
8 #include "net/quic/test_tools/quic_test_utils.h"
9 #include "net/test/gtest_util.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 using testing::Return;
14 using testing::_;
15
16 namespace net {
17 namespace test {
18
19 class QuicMultipathReceivedPacketManagerPeer {
20 public:
21 static bool PathReceivedPacketManagerExists(
22 QuicMultipathReceivedPacketManager* multipath_manager,
23 QuicPathId path_id) {
24 return multipath_manager->path_managers_.count(path_id);
25 }
26
27 static void SetPathReceivedPacketManager(
28 QuicMultipathReceivedPacketManager* multipath_manager,
29 QuicPathId path_id,
30 QuicReceivedPacketManager* manager) {
31 delete multipath_manager->path_managers_[path_id];
32 multipath_manager->path_managers_[path_id] = manager;
33 }
34 };
35
36 namespace {
37
38 const QuicPathId kPathId1 = 1;
39 const QuicPathId kPathId2 = 2;
40 const QuicPathId kPathId3 = 3;
41 const QuicByteCount kBytes = 1350;
42
43 class QuicMultipathReceivedPacketManagerTest : public testing::Test {
44 public:
45 QuicMultipathReceivedPacketManagerTest()
46 : multipath_manager_(&stats_),
47 manager_0_(new MockReceivedPacketManager(&stats_)),
48 manager_1_(new MockReceivedPacketManager(&stats_)) {
49 QuicMultipathReceivedPacketManagerPeer::SetPathReceivedPacketManager(
50 &multipath_manager_, kDefaultPathId, manager_0_);
51 QuicMultipathReceivedPacketManagerPeer::SetPathReceivedPacketManager(
52 &multipath_manager_, kPathId1, manager_1_);
53 }
54
55 QuicConnectionStats stats_;
56 QuicMultipathReceivedPacketManager multipath_manager_;
57 MockReceivedPacketManager* manager_0_;
58 MockReceivedPacketManager* manager_1_;
59 QuicPacketHeader header_;
60 };
61
62 TEST_F(QuicMultipathReceivedPacketManagerTest, OnPathCreatedAndClosed) {
63 EXPECT_TRUE(
64 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
65 &multipath_manager_, kDefaultPathId));
66 EXPECT_TRUE(
67 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
68 &multipath_manager_, kPathId1));
69 EXPECT_DFATAL(multipath_manager_.OnPathCreated(kDefaultPathId, &stats_),
70 "Received packet manager of path already exists");
71 // Path 2 created.
72 multipath_manager_.OnPathCreated(kPathId2, &stats_);
73 EXPECT_TRUE(
74 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
75 &multipath_manager_, kPathId2));
76 EXPECT_FALSE(
77 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
78 &multipath_manager_, kPathId3));
79 // Path 3 created.
80 multipath_manager_.OnPathCreated(kPathId3, &stats_);
81 EXPECT_TRUE(
82 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
83 &multipath_manager_, kPathId3));
84
85 // Path 0 closed.
86 multipath_manager_.OnPathClosed(kDefaultPathId);
87 EXPECT_FALSE(
88 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
89 &multipath_manager_, kDefaultPathId));
90 EXPECT_DFATAL(multipath_manager_.OnPathClosed(kDefaultPathId),
91 "Received packet manager of path does not exist");
92 }
93
94 TEST_F(QuicMultipathReceivedPacketManagerTest, RecordPacketReceived) {
95 EXPECT_CALL(*manager_0_, RecordPacketReceived(_, _, _)).Times(1);
96 multipath_manager_.RecordPacketReceived(kDefaultPathId, kBytes, header_,
97 QuicTime::Zero());
98 EXPECT_DFATAL(multipath_manager_.RecordPacketReceived(
99 kPathId2, kBytes, header_, QuicTime::Zero()),
100 "Received a packet on a non-existent path");
101 }
102
103 TEST_F(QuicMultipathReceivedPacketManagerTest, RecordPacketRevived) {
104 EXPECT_CALL(*manager_0_, RecordPacketRevived(_)).Times(1);
105 multipath_manager_.RecordPacketRevived(kDefaultPathId, header_.packet_number);
106 EXPECT_DFATAL(
107 multipath_manager_.RecordPacketRevived(kPathId2, header_.packet_number),
108 "Revived a packet on a non-existent path");
109 }
110
111 TEST_F(QuicMultipathReceivedPacketManagerTest, IsMissing) {
112 EXPECT_CALL(*manager_0_, IsMissing(header_.packet_number))
113 .WillOnce(Return(true));
114 EXPECT_CALL(*manager_1_, IsMissing(header_.packet_number))
115 .WillOnce(Return(false));
116 EXPECT_TRUE(
117 multipath_manager_.IsMissing(kDefaultPathId, header_.packet_number));
118 EXPECT_FALSE(multipath_manager_.IsMissing(kPathId1, header_.packet_number));
119 EXPECT_DFATAL(multipath_manager_.IsMissing(kPathId2, header_.packet_number),
120 "Check whether a packet is missing on a non-existent path");
121 }
122
123 TEST_F(QuicMultipathReceivedPacketManagerTest, IsAwaitingPacket) {
124 EXPECT_CALL(*manager_0_, IsAwaitingPacket(header_.packet_number))
125 .WillOnce(Return(true));
126 EXPECT_CALL(*manager_1_, IsAwaitingPacket(header_.packet_number))
127 .WillOnce(Return(false));
128 EXPECT_TRUE(multipath_manager_.IsAwaitingPacket(kDefaultPathId,
129 header_.packet_number));
130 EXPECT_FALSE(
131 multipath_manager_.IsAwaitingPacket(kPathId1, header_.packet_number));
132 EXPECT_DFATAL(
133 multipath_manager_.IsAwaitingPacket(kPathId2, header_.packet_number),
134 "Check whether a packet is awaited on a non-existent path");
135 }
136
137 TEST_F(QuicMultipathReceivedPacketManagerTest, UpdateReceivedPacketInfo) {
138 std::vector<QuicAckFrame> ack_frames;
139 EXPECT_EQ(static_cast<size_t>(0), ack_frames.size());
140 EXPECT_CALL(*manager_0_, ack_frame_updated()).WillOnce(Return(false));
141 EXPECT_CALL(*manager_1_, ack_frame_updated()).WillRepeatedly(Return(false));
142 multipath_manager_.UpdateReceivedPacketInfo(&ack_frames, QuicTime::Zero(),
143 /*force_all_paths=*/false);
144 EXPECT_EQ(static_cast<size_t>(0), ack_frames.size());
145 EXPECT_CALL(*manager_0_, ack_frame_updated()).WillOnce(Return(true));
146 multipath_manager_.UpdateReceivedPacketInfo(&ack_frames, QuicTime::Zero(),
147 /*force_all_paths=*/false);
148 EXPECT_EQ(static_cast<size_t>(1), ack_frames.size());
149
150 std::vector<QuicAckFrame> ack_frames_all;
151 multipath_manager_.UpdateReceivedPacketInfo(&ack_frames_all, QuicTime::Zero(),
152 /*force_all_paths=*/true);
153 EXPECT_EQ(static_cast<size_t>(2), ack_frames_all.size());
154 }
155
156 TEST_F(QuicMultipathReceivedPacketManagerTest,
157 UpdatePacketInformationSentByPeer) {
158 std::vector<QuicStopWaitingFrame> stop_waitings;
159 QuicStopWaitingFrame stop_waiting_0;
160 QuicStopWaitingFrame stop_waiting_1;
161 QuicStopWaitingFrame stop_waiting_2;
162 stop_waiting_0.path_id = kDefaultPathId;
163 stop_waiting_1.path_id = kPathId1;
164 stop_waiting_2.path_id = kPathId2;
165 stop_waitings.push_back(stop_waiting_0);
166 stop_waitings.push_back(stop_waiting_1);
167 stop_waitings.push_back(stop_waiting_2);
168 EXPECT_CALL(*manager_0_, UpdatePacketInformationSentByPeer(_)).Times(1);
169 EXPECT_CALL(*manager_1_, UpdatePacketInformationSentByPeer(_)).Times(1);
170 multipath_manager_.UpdatePacketInformationSentByPeer(stop_waitings);
171 }
172
173 TEST_F(QuicMultipathReceivedPacketManagerTest, HasNewMissingPackets) {
174 EXPECT_CALL(*manager_0_, HasNewMissingPackets()).WillOnce(Return(true));
175 EXPECT_CALL(*manager_1_, HasNewMissingPackets()).WillOnce(Return(false));
176 EXPECT_TRUE(multipath_manager_.HasNewMissingPackets(kDefaultPathId));
177 EXPECT_FALSE(multipath_manager_.HasNewMissingPackets(kPathId1));
178 EXPECT_DFATAL(multipath_manager_.HasNewMissingPackets(kPathId2),
179 "Check whether has new missing packets on a non-existent path");
180 }
181
182 } // namespace
183 } // namespace test
184 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_multipath_received_packet_manager.cc ('k') | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698