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

Side by Side Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 1034573002: Improve QUIC tests. Correct things clang_tidy complains about. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 | « no previous file | net/tools/quic/quic_time_wait_list_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tools/quic/quic_dispatcher.h" 5 #include "net/tools/quic/quic_dispatcher.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h" 10 #include "net/quic/crypto/crypto_handshake.h"
(...skipping 10 matching lines...) Expand all
21 #include "net/tools/quic/test_tools/quic_test_utils.h" 21 #include "net/tools/quic/test_tools/quic_test_utils.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 using base::StringPiece; 25 using base::StringPiece;
26 using net::EpollServer; 26 using net::EpollServer;
27 using net::test::ConstructEncryptedPacket; 27 using net::test::ConstructEncryptedPacket;
28 using net::test::MockConnection; 28 using net::test::MockConnection;
29 using net::test::MockSession; 29 using net::test::MockSession;
30 using net::test::ValueRestore; 30 using net::test::ValueRestore;
31 using std::make_pair;
32 using std::string; 31 using std::string;
33 using testing::DoAll; 32 using testing::DoAll;
34 using testing::InSequence; 33 using testing::InSequence;
35 using testing::Invoke; 34 using testing::Invoke;
36 using testing::WithoutArgs; 35 using testing::WithoutArgs;
37 using testing::_; 36 using testing::_;
38 37
39 namespace net { 38 namespace net {
40 namespace tools { 39 namespace tools {
41 namespace test { 40 namespace test {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 *session = new MockSession(connection); 89 *session = new MockSession(connection);
91 ON_CALL(*connection, SendConnectionClose(_)).WillByDefault( 90 ON_CALL(*connection, SendConnectionClose(_)).WillByDefault(
92 WithoutArgs(Invoke( 91 WithoutArgs(Invoke(
93 connection, &MockServerConnection::UnregisterOnConnectionClosed))); 92 connection, &MockServerConnection::UnregisterOnConnectionClosed)));
94 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()), 93 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()),
95 ProcessUdpPacket(_, client_address, _)); 94 ProcessUdpPacket(_, client_address, _));
96 95
97 return *session; 96 return *session;
98 } 97 }
99 98
100 class MockTimeWaitListManager : public QuicTimeWaitListManager {
101 public:
102 MockTimeWaitListManager(QuicPacketWriter* writer,
103 QuicServerSessionVisitor* visitor,
104 EpollServer* eps)
105 : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) {
106 }
107
108 MOCK_METHOD5(ProcessPacket,
109 void(const IPEndPoint& server_address,
110 const IPEndPoint& client_address,
111 QuicConnectionId connection_id,
112 QuicPacketSequenceNumber sequence_number,
113 const QuicEncryptedPacket& packet));
114 };
115
116 class QuicDispatcherTest : public ::testing::Test { 99 class QuicDispatcherTest : public ::testing::Test {
117 public: 100 public:
118 QuicDispatcherTest() 101 QuicDispatcherTest()
119 : crypto_config_(QuicCryptoServerConfig::TESTING, 102 : crypto_config_(QuicCryptoServerConfig::TESTING,
120 QuicRandom::GetInstance()), 103 QuicRandom::GetInstance()),
121 dispatcher_(config_, crypto_config_, &eps_), 104 dispatcher_(config_, crypto_config_, &eps_),
122 time_wait_list_manager_(nullptr), 105 time_wait_list_manager_(nullptr),
123 session1_(nullptr), 106 session1_(nullptr),
124 session2_(nullptr) { 107 session2_(nullptr) {
125 dispatcher_.Initialize(1); 108 dispatcher_.Initialize(1);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 .WillOnce(Invoke( 233 .WillOnce(Invoke(
251 reinterpret_cast<MockConnection*>(session1_->connection()), 234 reinterpret_cast<MockConnection*>(session1_->connection()),
252 &MockConnection::ReallyProcessUdpPacket)); 235 &MockConnection::ReallyProcessUdpPacket));
253 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *encrypted); 236 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *encrypted);
254 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 237 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
255 238
256 // Dispatcher forwards subsequent packets for this connection_id to the time 239 // Dispatcher forwards subsequent packets for this connection_id to the time
257 // wait list manager. 240 // wait list manager.
258 EXPECT_CALL(*time_wait_list_manager_, 241 EXPECT_CALL(*time_wait_list_manager_,
259 ProcessPacket(_, _, connection_id, _, _)).Times(1); 242 ProcessPacket(_, _, connection_id, _, _)).Times(1);
243 EXPECT_CALL(*time_wait_list_manager_,
244 AddConnectionIdToTimeWait(_, _, _)).Times(0);
260 ProcessPacket(client_address, connection_id, true, "foo"); 245 ProcessPacket(client_address, connection_id, true, "foo");
261 } 246 }
262 247
263 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { 248 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) {
264 CreateTimeWaitListManager(); 249 CreateTimeWaitListManager();
265 250
266 IPEndPoint client_address(net::test::Loopback4(), 1); 251 IPEndPoint client_address(net::test::Loopback4(), 1);
267 QuicConnectionId connection_id = 1; 252 QuicConnectionId connection_id = 1;
268 // Dispatcher forwards all packets for this connection_id to the time wait 253 // Dispatcher forwards all packets for this connection_id to the time wait
269 // list manager. 254 // list manager.
270 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); 255 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0);
271 EXPECT_CALL(*time_wait_list_manager_, 256 EXPECT_CALL(*time_wait_list_manager_,
272 ProcessPacket(_, _, connection_id, _, _)).Times(1); 257 ProcessPacket(_, _, connection_id, _, _)).Times(1);
258 EXPECT_CALL(*time_wait_list_manager_,
259 AddConnectionIdToTimeWait(_, _, _)).Times(1);
273 ProcessPacket(client_address, connection_id, false, "data"); 260 ProcessPacket(client_address, connection_id, false, "data");
274 } 261 }
275 262
276 TEST_F(QuicDispatcherTest, ProcessPacketWithBogusPort) { 263 TEST_F(QuicDispatcherTest, ProcessPacketWithBogusPort) {
277 CreateTimeWaitListManager(); 264 CreateTimeWaitListManager();
278 265
279 IPEndPoint client_address(net::test::Loopback4(), 0); 266 IPEndPoint client_address(net::test::Loopback4(), 0);
280 IPAddressNumber any4; 267 IPAddressNumber any4;
281 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); 268 CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4));
282 server_address_ = IPEndPoint(any4, 5); 269 server_address_ = IPEndPoint(any4, 5);
283 270
284 // dispatcher_ should drop this packet. 271 // dispatcher_ should drop this packet.
285 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)).Times(0); 272 EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)).Times(0);
286 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0); 273 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
274 EXPECT_CALL(*time_wait_list_manager_,
275 AddConnectionIdToTimeWait(_, _, _)).Times(0);
287 ProcessPacket(client_address, 1, true, "foo"); 276 ProcessPacket(client_address, 1, true, "foo");
288 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 277 EXPECT_EQ(client_address, dispatcher_.current_client_address());
289 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 278 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
290 } 279 }
291 280
292 class BlockingWriter : public QuicPacketWriterWrapper { 281 class BlockingWriter : public QuicPacketWriterWrapper {
293 public: 282 public:
294 BlockingWriter() : write_blocked_(false) {} 283 BlockingWriter() : write_blocked_(false) {}
295 284
296 bool IsWriteBlocked() const override { return write_blocked_; } 285 bool IsWriteBlocked() const override { return write_blocked_; }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 // And we'll resume where we left off when we get another call. 469 // And we'll resume where we left off when we get another call.
481 EXPECT_CALL(*connection2(), OnCanWrite()); 470 EXPECT_CALL(*connection2(), OnCanWrite());
482 dispatcher_.OnCanWrite(); 471 dispatcher_.OnCanWrite();
483 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 472 EXPECT_FALSE(dispatcher_.HasPendingWrites());
484 } 473 }
485 474
486 } // namespace 475 } // namespace
487 } // namespace test 476 } // namespace test
488 } // namespace tools 477 } // namespace tools
489 } // namespace net 478 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/tools/quic/quic_time_wait_list_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698