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

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

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 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
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/quic_flags.h"
9 #include "net/quic/test_tools/quic_test_utils.h"
10 #include "net/test/gtest_util.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using testing::Return;
15 using testing::_;
16
17 namespace net {
18 namespace test {
19
20 class QuicMultipathReceivedPacketManagerPeer {
21 public:
22 static bool PathReceivedPacketManagerExists(
23 QuicMultipathReceivedPacketManager* multipath_manager,
24 QuicPathId path_id) {
25 return multipath_manager->path_managers_.count(path_id);
26 }
27
28 static void SetPathReceivedPacketManager(
29 QuicMultipathReceivedPacketManager* multipath_manager,
30 QuicPathId path_id,
31 QuicReceivedPacketManager* manager) {
32 delete multipath_manager->path_managers_[path_id];
33 multipath_manager->path_managers_[path_id] = manager;
34 }
35 };
36
37 namespace {
38
39 const QuicPathId kPathId1 = 1;
40 const QuicPathId kPathId2 = 2;
41 const QuicPathId kPathId3 = 3;
42 const QuicByteCount kBytes = 1350;
43
44 class QuicMultipathReceivedPacketManagerTest : public testing::Test {
45 public:
46 QuicMultipathReceivedPacketManagerTest()
47 : multipath_manager_(&stats_),
48 manager_0_(new MockReceivedPacketManager(&stats_)),
49 manager_1_(new MockReceivedPacketManager(&stats_)) {
50 QuicMultipathReceivedPacketManagerPeer::SetPathReceivedPacketManager(
51 &multipath_manager_, kDefaultPathId, manager_0_);
52 QuicMultipathReceivedPacketManagerPeer::SetPathReceivedPacketManager(
53 &multipath_manager_, kPathId1, manager_1_);
54 }
55
56 QuicConnectionStats stats_;
57 QuicMultipathReceivedPacketManager multipath_manager_;
58 MockReceivedPacketManager* manager_0_;
59 MockReceivedPacketManager* manager_1_;
60 QuicPacketHeader header_;
61 };
62
63 TEST_F(QuicMultipathReceivedPacketManagerTest, OnPathCreatedAndClosed) {
64 EXPECT_TRUE(
65 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
66 &multipath_manager_, kDefaultPathId));
67 EXPECT_TRUE(
68 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
69 &multipath_manager_, kPathId1));
70 EXPECT_DFATAL(multipath_manager_.OnPathCreated(kDefaultPathId, &stats_),
71 "Received packet manager of path already exists");
72 // Path 2 created.
73 multipath_manager_.OnPathCreated(kPathId2, &stats_);
74 EXPECT_TRUE(
75 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
76 &multipath_manager_, kPathId2));
77 EXPECT_FALSE(
78 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
79 &multipath_manager_, kPathId3));
80 // Path 3 created.
81 multipath_manager_.OnPathCreated(kPathId3, &stats_);
82 EXPECT_TRUE(
83 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
84 &multipath_manager_, kPathId3));
85
86 // Path 0 closed.
87 multipath_manager_.OnPathClosed(kDefaultPathId);
88 EXPECT_FALSE(
89 QuicMultipathReceivedPacketManagerPeer::PathReceivedPacketManagerExists(
90 &multipath_manager_, kDefaultPathId));
91 EXPECT_DFATAL(multipath_manager_.OnPathClosed(kDefaultPathId),
92 "Received packet manager of path does not exist");
93 }
94
95 TEST_F(QuicMultipathReceivedPacketManagerTest, RecordPacketReceived) {
96 EXPECT_CALL(*manager_0_, RecordPacketReceived(_, _, _)).Times(1);
97 multipath_manager_.RecordPacketReceived(kDefaultPathId, kBytes, header_,
98 QuicTime::Zero());
99 EXPECT_DFATAL(multipath_manager_.RecordPacketReceived(
100 kPathId2, kBytes, header_, QuicTime::Zero()),
101 "Received a packet on a non-existent path");
102 }
103
104 TEST_F(QuicMultipathReceivedPacketManagerTest, IsMissing) {
105 EXPECT_CALL(*manager_0_, IsMissing(header_.packet_number))
106 .WillOnce(Return(true));
107 EXPECT_CALL(*manager_1_, IsMissing(header_.packet_number))
108 .WillOnce(Return(false));
109 EXPECT_TRUE(
110 multipath_manager_.IsMissing(kDefaultPathId, header_.packet_number));
111 EXPECT_FALSE(multipath_manager_.IsMissing(kPathId1, header_.packet_number));
112 EXPECT_DFATAL(multipath_manager_.IsMissing(kPathId2, header_.packet_number),
113 "Check whether a packet is missing on a non-existent path");
114 }
115
116 TEST_F(QuicMultipathReceivedPacketManagerTest, IsAwaitingPacket) {
117 EXPECT_CALL(*manager_0_, IsAwaitingPacket(header_.packet_number))
118 .WillOnce(Return(true));
119 EXPECT_CALL(*manager_1_, IsAwaitingPacket(header_.packet_number))
120 .WillOnce(Return(false));
121 EXPECT_TRUE(multipath_manager_.IsAwaitingPacket(kDefaultPathId,
122 header_.packet_number));
123 EXPECT_FALSE(
124 multipath_manager_.IsAwaitingPacket(kPathId1, header_.packet_number));
125 EXPECT_DFATAL(
126 multipath_manager_.IsAwaitingPacket(kPathId2, header_.packet_number),
127 "Check whether a packet is awaited on a non-existent path");
128 }
129
130 TEST_F(QuicMultipathReceivedPacketManagerTest,
131 UpdatePacketInformationSentByPeer) {
132 std::vector<QuicStopWaitingFrame> stop_waitings;
133 QuicStopWaitingFrame stop_waiting_0;
134 QuicStopWaitingFrame stop_waiting_1;
135 QuicStopWaitingFrame stop_waiting_2;
136 stop_waiting_0.path_id = kDefaultPathId;
137 stop_waiting_1.path_id = kPathId1;
138 stop_waiting_2.path_id = kPathId2;
139 stop_waitings.push_back(stop_waiting_0);
140 stop_waitings.push_back(stop_waiting_1);
141 stop_waitings.push_back(stop_waiting_2);
142 EXPECT_CALL(*manager_0_, UpdatePacketInformationSentByPeer(_)).Times(1);
143 EXPECT_CALL(*manager_1_, UpdatePacketInformationSentByPeer(_)).Times(1);
144 multipath_manager_.UpdatePacketInformationSentByPeer(stop_waitings);
145 }
146
147 TEST_F(QuicMultipathReceivedPacketManagerTest, HasNewMissingPackets) {
148 EXPECT_CALL(*manager_0_, HasNewMissingPackets()).WillOnce(Return(true));
149 EXPECT_CALL(*manager_1_, HasNewMissingPackets()).WillOnce(Return(false));
150 EXPECT_TRUE(multipath_manager_.HasNewMissingPackets(kDefaultPathId));
151 EXPECT_FALSE(multipath_manager_.HasNewMissingPackets(kPathId1));
152 EXPECT_DFATAL(multipath_manager_.HasNewMissingPackets(kPathId2),
153 "Check whether has new missing packets on a non-existent path");
154 }
155
156 } // namespace
157 } // namespace test
158 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_multipath_received_packet_manager.cc ('k') | net/quic/quic_multipath_sent_packet_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698