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

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

Issue 2128043002: refactor quic_dispatcher_test.cc to make test extensible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@126326347
Patch Set: Created 4 years, 5 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 | no next file » | 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 <memory> 7 #include <memory>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 10
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 169 }
170 170
171 class QuicDispatcherTest : public ::testing::Test { 171 class QuicDispatcherTest : public ::testing::Test {
172 public: 172 public:
173 QuicDispatcherTest() 173 QuicDispatcherTest()
174 : helper_(&eps_, QuicAllocator::BUFFER_POOL), 174 : helper_(&eps_, QuicAllocator::BUFFER_POOL),
175 alarm_factory_(&eps_), 175 alarm_factory_(&eps_),
176 crypto_config_(QuicCryptoServerConfig::TESTING, 176 crypto_config_(QuicCryptoServerConfig::TESTING,
177 QuicRandom::GetInstance(), 177 QuicRandom::GetInstance(),
178 CryptoTestUtils::ProofSourceForTesting()), 178 CryptoTestUtils::ProofSourceForTesting()),
179 dispatcher_(config_, &crypto_config_, &eps_), 179 dispatcher_(new TestDispatcher(config_, &crypto_config_, &eps_)),
180 time_wait_list_manager_(nullptr), 180 time_wait_list_manager_(nullptr),
181 session1_(nullptr), 181 session1_(nullptr),
182 session2_(nullptr) { 182 session2_(nullptr) {
183 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1)); 183 dispatcher_->InitializeWithWriter(new QuicDefaultPacketWriter(1));
184 } 184 }
185 185
186 ~QuicDispatcherTest() override {} 186 ~QuicDispatcherTest() override {}
187 187
188 MockQuicConnection* connection1() { 188 MockQuicConnection* connection1() {
189 return reinterpret_cast<MockQuicConnection*>(session1_->connection()); 189 return reinterpret_cast<MockQuicConnection*>(session1_->connection());
190 } 190 }
191 191
192 MockQuicConnection* connection2() { 192 MockQuicConnection* connection2() {
193 return reinterpret_cast<MockQuicConnection*>(session2_->connection()); 193 return reinterpret_cast<MockQuicConnection*>(session2_->connection());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 QuicPacketNumberLength packet_number_length, 245 QuicPacketNumberLength packet_number_length,
246 QuicPacketNumber packet_number) { 246 QuicPacketNumber packet_number) {
247 QuicVersionVector versions(SupportedVersions(version)); 247 QuicVersionVector versions(SupportedVersions(version));
248 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( 248 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
249 connection_id, has_version_flag, false, false, 0, packet_number, data, 249 connection_id, has_version_flag, false, false, 0, packet_number, data,
250 connection_id_length, packet_number_length, &versions)); 250 connection_id_length, packet_number_length, &versions));
251 std::unique_ptr<QuicReceivedPacket> received_packet( 251 std::unique_ptr<QuicReceivedPacket> received_packet(
252 ConstructReceivedPacket(*packet, helper_.GetClock()->Now())); 252 ConstructReceivedPacket(*packet, helper_.GetClock()->Now()));
253 253
254 data_ = string(packet->data(), packet->length()); 254 data_ = string(packet->data(), packet->length());
255 dispatcher_.ProcessPacket(server_address_, client_address, 255 dispatcher_->ProcessPacket(server_address_, client_address,
256 *received_packet); 256 *received_packet);
257 } 257 }
258 258
259 void ValidatePacket(const QuicEncryptedPacket& packet) { 259 void ValidatePacket(const QuicEncryptedPacket& packet) {
260 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); 260 EXPECT_EQ(data_.length(), packet.AsStringPiece().length());
261 EXPECT_EQ(data_, packet.AsStringPiece()); 261 EXPECT_EQ(data_, packet.AsStringPiece());
262 } 262 }
263 263
264 void CreateTimeWaitListManager() { 264 void CreateTimeWaitListManager() {
265 time_wait_list_manager_ = 265 time_wait_list_manager_ = new MockTimeWaitListManager(
266 new MockTimeWaitListManager(QuicDispatcherPeer::GetWriter(&dispatcher_), 266 QuicDispatcherPeer::GetWriter(dispatcher_.get()), dispatcher_.get(),
267 &dispatcher_, &helper_, &alarm_factory_); 267 &helper_, &alarm_factory_);
268 // dispatcher_ takes the ownership of time_wait_list_manager_. 268 // dispatcher_ takes the ownership of time_wait_list_manager_.
269 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, 269 QuicDispatcherPeer::SetTimeWaitListManager(dispatcher_.get(),
270 time_wait_list_manager_); 270 time_wait_list_manager_);
271 } 271 }
272 272
273 string SerializeCHLO() { 273 string SerializeCHLO() {
274 CryptoHandshakeMessage client_hello; 274 CryptoHandshakeMessage client_hello;
275 client_hello.set_tag(kCHLO); 275 client_hello.set_tag(kCHLO);
276 return client_hello.GetSerialized().AsStringPiece().as_string(); 276 return client_hello.GetSerialized().AsStringPiece().as_string();
277 } 277 }
278 278
279 EpollServer eps_; 279 EpollServer eps_;
280 QuicEpollConnectionHelper helper_; 280 QuicEpollConnectionHelper helper_;
281 MockQuicConnectionHelper mock_helper_; 281 MockQuicConnectionHelper mock_helper_;
282 QuicEpollAlarmFactory alarm_factory_; 282 QuicEpollAlarmFactory alarm_factory_;
283 MockAlarmFactory mock_alarm_factory_; 283 MockAlarmFactory mock_alarm_factory_;
284 QuicConfig config_; 284 QuicConfig config_;
285 QuicCryptoServerConfig crypto_config_; 285 QuicCryptoServerConfig crypto_config_;
286 IPEndPoint server_address_; 286 IPEndPoint server_address_;
287 TestDispatcher dispatcher_; 287 std::unique_ptr<TestDispatcher> dispatcher_;
288 MockTimeWaitListManager* time_wait_list_manager_; 288 MockTimeWaitListManager* time_wait_list_manager_;
289 TestQuicSpdyServerSession* session1_; 289 TestQuicSpdyServerSession* session1_;
290 TestQuicSpdyServerSession* session2_; 290 TestQuicSpdyServerSession* session2_;
291 string data_; 291 string data_;
292 }; 292 };
293 293
294 TEST_F(QuicDispatcherTest, ProcessPackets) { 294 TEST_F(QuicDispatcherTest, ProcessPackets) {
295 IPEndPoint client_address(net::test::Loopback4(), 1); 295 IPEndPoint client_address(net::test::Loopback4(), 1);
296 server_address_ = IPEndPoint(net::test::Any4(), 5); 296 server_address_ = IPEndPoint(net::test::Any4(), 5);
297 297
298 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 298 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address))
299 .WillOnce(testing::Return(CreateSession( 299 .WillOnce(testing::Return(CreateSession(
300 &dispatcher_, config_, 1, client_address, &mock_helper_, 300 dispatcher_.get(), config_, 1, client_address, &mock_helper_,
301 &mock_alarm_factory_, &crypto_config_, 301 &mock_alarm_factory_, &crypto_config_,
302 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 302 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
303 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); 303 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
304 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 304 EXPECT_EQ(client_address, dispatcher_->current_client_address());
305 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 305 EXPECT_EQ(server_address_, dispatcher_->current_server_address());
306 306
307 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address)) 307 EXPECT_CALL(*dispatcher_, CreateQuicSession(2, client_address))
308 .WillOnce(testing::Return(CreateSession( 308 .WillOnce(testing::Return(CreateSession(
309 &dispatcher_, config_, 2, client_address, &mock_helper_, 309 dispatcher_.get(), config_, 2, client_address, &mock_helper_,
310 &mock_alarm_factory_, &crypto_config_, 310 &mock_alarm_factory_, &crypto_config_,
311 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_))); 311 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_)));
312 ProcessPacket(client_address, 2, true, false, SerializeCHLO()); 312 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
313 313
314 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 314 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
315 ProcessUdpPacket(_, _, _)) 315 ProcessUdpPacket(_, _, _))
316 .Times(1) 316 .Times(1)
317 .WillOnce(testing::WithArgs<2>( 317 .WillOnce(testing::WithArgs<2>(
318 Invoke(this, &QuicDispatcherTest::ValidatePacket))); 318 Invoke(this, &QuicDispatcherTest::ValidatePacket)));
319 ProcessPacket(client_address, 1, false, false, "data"); 319 ProcessPacket(client_address, 1, false, false, "data");
320 } 320 }
321 321
322 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { 322 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
323 IPEndPoint client_address(net::test::Loopback4(), 1); 323 IPEndPoint client_address(net::test::Loopback4(), 1);
324 server_address_ = IPEndPoint(net::test::Any4(), 5); 324 server_address_ = IPEndPoint(net::test::Any4(), 5);
325 325
326 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); 326 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0);
327 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); 327 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
328 ProcessPacket(client_address, 1, true, version, SerializeCHLO(), 328 ProcessPacket(client_address, 1, true, version, SerializeCHLO(),
329 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); 329 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
330 } 330 }
331 331
332 TEST_F(QuicDispatcherTest, Shutdown) { 332 TEST_F(QuicDispatcherTest, Shutdown) {
333 IPEndPoint client_address(net::test::Loopback4(), 1); 333 IPEndPoint client_address(net::test::Loopback4(), 1);
334 334
335 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 335 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
336 .WillOnce(testing::Return(CreateSession( 336 .WillOnce(testing::Return(CreateSession(
337 &dispatcher_, config_, 1, client_address, &mock_helper_, 337 dispatcher_.get(), config_, 1, client_address, &mock_helper_,
338 &mock_alarm_factory_, &crypto_config_, 338 &mock_alarm_factory_, &crypto_config_,
339 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 339 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
340 340
341 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); 341 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
342 342
343 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 343 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
344 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 344 CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
345 345
346 dispatcher_.Shutdown(); 346 dispatcher_->Shutdown();
347 } 347 }
348 348
349 TEST_F(QuicDispatcherTest, TimeWaitListManager) { 349 TEST_F(QuicDispatcherTest, TimeWaitListManager) {
350 CreateTimeWaitListManager(); 350 CreateTimeWaitListManager();
351 351
352 // Create a new session. 352 // Create a new session.
353 IPEndPoint client_address(net::test::Loopback4(), 1); 353 IPEndPoint client_address(net::test::Loopback4(), 1);
354 QuicConnectionId connection_id = 1; 354 QuicConnectionId connection_id = 1;
355 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 355 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
356 .WillOnce(testing::Return(CreateSession( 356 .WillOnce(testing::Return(CreateSession(
357 &dispatcher_, config_, connection_id, client_address, &mock_helper_, 357 dispatcher_.get(), config_, connection_id, client_address,
358 &mock_alarm_factory_, &crypto_config_, 358 &mock_helper_, &mock_alarm_factory_, &crypto_config_,
359 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 359 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
360 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO()); 360 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
361 361
362 // Close the connection by sending public reset packet. 362 // Close the connection by sending public reset packet.
363 QuicPublicResetPacket packet; 363 QuicPublicResetPacket packet;
364 packet.public_header.connection_id = connection_id; 364 packet.public_header.connection_id = connection_id;
365 packet.public_header.reset_flag = true; 365 packet.public_header.reset_flag = true;
366 packet.public_header.version_flag = false; 366 packet.public_header.version_flag = false;
367 packet.rejected_packet_number = 19191; 367 packet.rejected_packet_number = 19191;
368 packet.nonce_proof = 132232; 368 packet.nonce_proof = 132232;
369 std::unique_ptr<QuicEncryptedPacket> encrypted( 369 std::unique_ptr<QuicEncryptedPacket> encrypted(
370 QuicFramer::BuildPublicResetPacket(packet)); 370 QuicFramer::BuildPublicResetPacket(packet));
371 std::unique_ptr<QuicReceivedPacket> received( 371 std::unique_ptr<QuicReceivedPacket> received(
372 ConstructReceivedPacket(*encrypted, helper_.GetClock()->Now())); 372 ConstructReceivedPacket(*encrypted, helper_.GetClock()->Now()));
373 EXPECT_CALL(*session1_, OnConnectionClosed(QUIC_PUBLIC_RESET, _, 373 EXPECT_CALL(*session1_, OnConnectionClosed(QUIC_PUBLIC_RESET, _,
374 ConnectionCloseSource::FROM_PEER)) 374 ConnectionCloseSource::FROM_PEER))
375 .Times(1) 375 .Times(1)
376 .WillOnce(WithoutArgs(Invoke( 376 .WillOnce(WithoutArgs(Invoke(
377 reinterpret_cast<MockServerConnection*>(session1_->connection()), 377 reinterpret_cast<MockServerConnection*>(session1_->connection()),
378 &MockServerConnection::UnregisterOnConnectionClosed))); 378 &MockServerConnection::UnregisterOnConnectionClosed)));
379 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 379 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
380 ProcessUdpPacket(_, _, _)) 380 ProcessUdpPacket(_, _, _))
381 .WillOnce( 381 .WillOnce(
382 Invoke(reinterpret_cast<MockQuicConnection*>(session1_->connection()), 382 Invoke(reinterpret_cast<MockQuicConnection*>(session1_->connection()),
383 &MockQuicConnection::ReallyProcessUdpPacket)); 383 &MockQuicConnection::ReallyProcessUdpPacket));
384 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *received); 384 dispatcher_->ProcessPacket(IPEndPoint(), client_address, *received);
385 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 385 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
386 386
387 // Dispatcher forwards subsequent packets for this connection_id to the time 387 // Dispatcher forwards subsequent packets for this connection_id to the time
388 // wait list manager. 388 // wait list manager.
389 EXPECT_CALL(*time_wait_list_manager_, 389 EXPECT_CALL(*time_wait_list_manager_,
390 ProcessPacket(_, _, connection_id, _, _)) 390 ProcessPacket(_, _, connection_id, _, _))
391 .Times(1); 391 .Times(1);
392 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 392 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
393 .Times(0); 393 .Times(0);
394 ProcessPacket(client_address, connection_id, true, false, "data"); 394 ProcessPacket(client_address, connection_id, true, false, "data");
395 } 395 }
396 396
397 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) { 397 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) {
398 CreateTimeWaitListManager(); 398 CreateTimeWaitListManager();
399 399
400 IPEndPoint client_address(net::test::Loopback4(), 1); 400 IPEndPoint client_address(net::test::Loopback4(), 1);
401 QuicConnectionId connection_id = 1; 401 QuicConnectionId connection_id = 1;
402 // Dispatcher forwards all packets for this connection_id to the time wait 402 // Dispatcher forwards all packets for this connection_id to the time wait
403 // list manager. 403 // list manager.
404 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); 404 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
405 EXPECT_CALL(*time_wait_list_manager_, 405 EXPECT_CALL(*time_wait_list_manager_,
406 ProcessPacket(_, _, connection_id, _, _)) 406 ProcessPacket(_, _, connection_id, _, _))
407 .Times(1); 407 .Times(1);
408 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 408 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
409 .Times(1); 409 .Times(1);
410 ProcessPacket(client_address, connection_id, false, false, SerializeCHLO()); 410 ProcessPacket(client_address, connection_id, false, false, SerializeCHLO());
411 } 411 }
412 412
413 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) { 413 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
414 CreateTimeWaitListManager(); 414 CreateTimeWaitListManager();
415 415
416 IPEndPoint client_address(net::test::Loopback4(), 0); 416 IPEndPoint client_address(net::test::Loopback4(), 0);
417 server_address_ = IPEndPoint(net::test::Any4(), 5); 417 server_address_ = IPEndPoint(net::test::Any4(), 5);
418 418
419 // dispatcher_ should drop this packet. 419 // dispatcher_ should drop this packet.
420 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); 420 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address)).Times(0);
421 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0); 421 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
422 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 422 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
423 .Times(0); 423 .Times(0);
424 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); 424 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
425 } 425 }
426 426
427 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) { 427 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
428 IPEndPoint client_address(net::test::Loopback4(), 1); 428 IPEndPoint client_address(net::test::Loopback4(), 1);
429 QuicConnectionId connection_id = 1; 429 QuicConnectionId connection_id = 1;
430 server_address_ = IPEndPoint(net::test::Any4(), 5); 430 server_address_ = IPEndPoint(net::test::Any4(), 5);
431 431
432 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 432 EXPECT_CALL(*dispatcher_, CreateQuicSession(1, client_address))
433 .WillOnce(testing::Return(CreateSession( 433 .WillOnce(testing::Return(CreateSession(
434 &dispatcher_, config_, 1, client_address, &mock_helper_, 434 dispatcher_.get(), config_, 1, client_address, &mock_helper_,
435 &mock_alarm_factory_, &crypto_config_, 435 &mock_alarm_factory_, &crypto_config_,
436 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 436 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
437 // A packet whose packet number is the largest that is allowed to start a 437 // A packet whose packet number is the largest that is allowed to start a
438 // connection. 438 // connection.
439 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(), 439 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
440 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 440 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
441 kDefaultPathId, 441 kDefaultPathId,
442 QuicDispatcher::kMaxReasonableInitialPacketNumber); 442 QuicDispatcher::kMaxReasonableInitialPacketNumber);
443 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 443 EXPECT_EQ(client_address, dispatcher_->current_client_address());
444 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 444 EXPECT_EQ(server_address_, dispatcher_->current_server_address());
445 } 445 }
446 446
447 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) { 447 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
448 CreateTimeWaitListManager(); 448 CreateTimeWaitListManager();
449 449
450 IPEndPoint client_address(net::test::Loopback4(), 1); 450 IPEndPoint client_address(net::test::Loopback4(), 1);
451 QuicConnectionId connection_id = 1; 451 QuicConnectionId connection_id = 1;
452 // Dispatcher forwards this packet for this connection_id to the time wait 452 // Dispatcher forwards this packet for this connection_id to the time wait
453 // list manager. 453 // list manager.
454 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); 454 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
455 EXPECT_CALL(*time_wait_list_manager_, 455 EXPECT_CALL(*time_wait_list_manager_,
456 ProcessPacket(_, _, connection_id, _, _)) 456 ProcessPacket(_, _, connection_id, _, _))
457 .Times(1); 457 .Times(1);
458 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 458 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
459 .Times(1); 459 .Times(1);
460 // A packet whose packet number is one to large to be allowed to start a 460 // A packet whose packet number is one to large to be allowed to start a
461 // connection. 461 // connection.
462 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(), 462 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
463 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 463 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
464 kDefaultPathId, 464 kDefaultPathId,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return GetParam().enable_stateless_rejects_via_flag && 551 return GetParam().enable_stateless_rejects_via_flag &&
552 !GetParam().crypto_handshake_successful && 552 !GetParam().crypto_handshake_successful &&
553 GetParam().client_supports_statelesss_rejects; 553 GetParam().client_supports_statelesss_rejects;
554 } 554 }
555 555
556 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on 556 // Sets up dispatcher_, sesession1_, and crypto_stream1_ based on
557 // the test parameters. 557 // the test parameters.
558 QuicServerSessionBase* CreateSessionBasedOnTestParams( 558 QuicServerSessionBase* CreateSessionBasedOnTestParams(
559 QuicConnectionId connection_id, 559 QuicConnectionId connection_id,
560 const IPEndPoint& client_address) { 560 const IPEndPoint& client_address) {
561 CreateSession(&dispatcher_, config_, connection_id, client_address, 561 CreateSession(dispatcher_.get(), config_, connection_id, client_address,
562 &mock_helper_, &mock_alarm_factory_, &crypto_config_, 562 &mock_helper_, &mock_alarm_factory_, &crypto_config_,
563 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_); 563 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_);
564 564
565 crypto_stream1_ = new MockQuicCryptoServerStream( 565 crypto_stream1_ = new MockQuicCryptoServerStream(
566 crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), session1_); 566 crypto_config_, QuicDispatcherPeer::GetCache(dispatcher_.get()),
567 session1_);
567 session1_->SetCryptoStream(crypto_stream1_); 568 session1_->SetCryptoStream(crypto_stream1_);
568 crypto_stream1_->set_handshake_confirmed_for_testing( 569 crypto_stream1_->set_handshake_confirmed_for_testing(
569 GetParam().crypto_handshake_successful); 570 GetParam().crypto_handshake_successful);
570 crypto_stream1_->SetPeerSupportsStatelessRejects( 571 crypto_stream1_->SetPeerSupportsStatelessRejects(
571 GetParam().client_supports_statelesss_rejects); 572 GetParam().client_supports_statelesss_rejects);
572 return session1_; 573 return session1_;
573 } 574 }
574 575
575 MockQuicCryptoServerStream* crypto_stream1_; 576 MockQuicCryptoServerStream* crypto_stream1_;
576 }; 577 };
577 578
578 // Parameterized test for stateless rejects. Should test all 579 // Parameterized test for stateless rejects. Should test all
579 // combinations of enabling/disabling, reject/no-reject for stateless 580 // combinations of enabling/disabling, reject/no-reject for stateless
580 // rejects. 581 // rejects.
581 INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests, 582 INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests,
582 QuicDispatcherStatelessRejectTest, 583 QuicDispatcherStatelessRejectTest,
583 ::testing::ValuesIn(GetStatelessRejectTestParams())); 584 ::testing::ValuesIn(GetStatelessRejectTestParams()));
584 585
585 TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) { 586 TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
586 CreateTimeWaitListManager(); 587 CreateTimeWaitListManager();
587 588
588 IPEndPoint client_address(net::test::Loopback4(), 1); 589 IPEndPoint client_address(net::test::Loopback4(), 1);
589 QuicConnectionId connection_id = 1; 590 QuicConnectionId connection_id = 1;
590 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 591 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
591 .WillOnce(testing::Return( 592 .WillOnce(testing::Return(
592 CreateSessionBasedOnTestParams(connection_id, client_address))); 593 CreateSessionBasedOnTestParams(connection_id, client_address)));
593 594
594 // Process the first packet for the connection. 595 // Process the first packet for the connection.
595 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO()); 596 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
596 if (ExpectStatelessReject()) { 597 if (ExpectStatelessReject()) {
597 // If this is a stateless reject, the crypto stream will close the 598 // If this is a stateless reject, the crypto stream will close the
598 // connection. 599 // connection.
599 session1_->connection()->CloseConnection( 600 session1_->connection()->CloseConnection(
600 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", 601 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject",
(...skipping 20 matching lines...) Expand all
621 ProcessPacket(client_address, connection_id, true, false, "data"); 622 ProcessPacket(client_address, connection_id, true, false, "data");
622 } 623 }
623 624
624 TEST_P(QuicDispatcherStatelessRejectTest, CheapRejects) { 625 TEST_P(QuicDispatcherStatelessRejectTest, CheapRejects) {
625 FLAGS_quic_use_cheap_stateless_rejects = true; 626 FLAGS_quic_use_cheap_stateless_rejects = true;
626 CreateTimeWaitListManager(); 627 CreateTimeWaitListManager();
627 628
628 IPEndPoint client_address(net::test::Loopback4(), 1); 629 IPEndPoint client_address(net::test::Loopback4(), 1);
629 QuicConnectionId connection_id = 1; 630 QuicConnectionId connection_id = 1;
630 if (GetParam().enable_stateless_rejects_via_flag) { 631 if (GetParam().enable_stateless_rejects_via_flag) {
631 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 632 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
632 .Times(0); 633 .Times(0);
633 } else { 634 } else {
634 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 635 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
635 .WillOnce(testing::Return( 636 .WillOnce(testing::Return(
636 CreateSessionBasedOnTestParams(connection_id, client_address))); 637 CreateSessionBasedOnTestParams(connection_id, client_address)));
637 } 638 }
638 639
639 VLOG(1) << "ExpectStatelessReject: " << ExpectStatelessReject(); 640 VLOG(1) << "ExpectStatelessReject: " << ExpectStatelessReject();
640 VLOG(1) << "Params: " << GetParam(); 641 VLOG(1) << "Params: " << GetParam();
641 // Process the first packet for the connection. 642 // Process the first packet for the connection.
642 // clang-format off 643 // clang-format off
643 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( 644 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message(
644 "CHLO", 645 "CHLO",
(...skipping 18 matching lines...) Expand all
663 TEST_P(QuicDispatcherStatelessRejectTest, BufferNonChlo) { 664 TEST_P(QuicDispatcherStatelessRejectTest, BufferNonChlo) {
664 FLAGS_quic_use_cheap_stateless_rejects = true; 665 FLAGS_quic_use_cheap_stateless_rejects = true;
665 CreateTimeWaitListManager(); 666 CreateTimeWaitListManager();
666 667
667 const IPEndPoint client_address(net::test::Loopback4(), 1); 668 const IPEndPoint client_address(net::test::Loopback4(), 1);
668 const QuicConnectionId connection_id = 1; 669 const QuicConnectionId connection_id = 1;
669 670
670 if (!GetParam().enable_stateless_rejects_via_flag) { 671 if (!GetParam().enable_stateless_rejects_via_flag) {
671 // If stateless rejects are not being used, then a connection will be 672 // If stateless rejects are not being used, then a connection will be
672 // created immediately. 673 // created immediately.
673 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 674 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
674 .WillOnce(testing::Return( 675 .WillOnce(testing::Return(
675 CreateSessionBasedOnTestParams(connection_id, client_address))); 676 CreateSessionBasedOnTestParams(connection_id, client_address)));
676 } 677 }
677 ProcessPacket(client_address, connection_id, true, false, 678 ProcessPacket(client_address, connection_id, true, false,
678 "NOT DATA FOR A CHLO"); 679 "NOT DATA FOR A CHLO");
679 680
680 // Process the first packet for the connection. 681 // Process the first packet for the connection.
681 // clang-format off 682 // clang-format off
682 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message( 683 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message(
683 "CHLO", 684 "CHLO",
684 "AEAD", "AESG", 685 "AEAD", "AESG",
685 "KEXS", "C255", 686 "KEXS", "C255",
686 "NONC", "1234567890123456789012", 687 "NONC", "1234567890123456789012",
687 "VER\0", "Q025", 688 "VER\0", "Q025",
688 "$padding", static_cast<int>(kClientHelloMinimumSize), 689 "$padding", static_cast<int>(kClientHelloMinimumSize),
689 nullptr); 690 nullptr);
690 // clang-format on 691 // clang-format on
691 692
692 if (GetParam().enable_stateless_rejects_via_flag) { 693 if (GetParam().enable_stateless_rejects_via_flag) {
693 // If stateless rejects are enabled then a connection will be created now 694 // If stateless rejects are enabled then a connection will be created now
694 // and the buffered packet will be processed 695 // and the buffered packet will be processed
695 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 696 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
696 .WillOnce(testing::Return( 697 .WillOnce(testing::Return(
697 CreateSessionBasedOnTestParams(connection_id, client_address))); 698 CreateSessionBasedOnTestParams(connection_id, client_address)));
698 } 699 }
699 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 700 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
700 ProcessUdpPacket(_, client_address, _)) 701 ProcessUdpPacket(_, client_address, _))
701 .RetiresOnSaturation(); 702 .RetiresOnSaturation();
702 ProcessPacket(client_address, connection_id, true, false, 703 ProcessPacket(client_address, connection_id, true, false,
703 client_hello.GetSerialized().AsStringPiece().as_string()); 704 client_hello.GetSerialized().AsStringPiece().as_string());
704 EXPECT_FALSE( 705 EXPECT_FALSE(
705 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 706 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
706 } 707 }
707 708
708 // Verify the stopgap test: Packets with truncated connection IDs should be 709 // Verify the stopgap test: Packets with truncated connection IDs should be
709 // dropped. 710 // dropped.
710 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; 711 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {};
711 712
712 // Packets with truncated connection IDs should be dropped. 713 // Packets with truncated connection IDs should be dropped.
713 TEST_F(QuicDispatcherTestStrayPacketConnectionId, 714 TEST_F(QuicDispatcherTestStrayPacketConnectionId,
714 StrayPacketTruncatedConnectionId) { 715 StrayPacketTruncatedConnectionId) {
715 CreateTimeWaitListManager(); 716 CreateTimeWaitListManager();
716 717
717 IPEndPoint client_address(net::test::Loopback4(), 1); 718 IPEndPoint client_address(net::test::Loopback4(), 1);
718 QuicConnectionId connection_id = 1; 719 QuicConnectionId connection_id = 1;
719 // Dispatcher drops this packet. 720 // Dispatcher drops this packet.
720 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); 721 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
721 EXPECT_CALL(*time_wait_list_manager_, 722 EXPECT_CALL(*time_wait_list_manager_,
722 ProcessPacket(_, _, connection_id, _, _)) 723 ProcessPacket(_, _, connection_id, _, _))
723 .Times(0); 724 .Times(0);
724 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 725 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
725 .Times(0); 726 .Times(0);
726 ProcessPacket(client_address, connection_id, true, false, "data", 727 ProcessPacket(client_address, connection_id, true, false, "data",
727 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER); 728 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER);
728 } 729 }
729 730
730 class BlockingWriter : public QuicPacketWriterWrapper { 731 class BlockingWriter : public QuicPacketWriterWrapper {
(...skipping 15 matching lines...) Expand all
746 return WriteResult(); 747 return WriteResult();
747 } 748 }
748 749
749 bool write_blocked_; 750 bool write_blocked_;
750 }; 751 };
751 752
752 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { 753 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
753 public: 754 public:
754 void SetUp() override { 755 void SetUp() override {
755 writer_ = new BlockingWriter; 756 writer_ = new BlockingWriter;
756 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); 757 QuicDispatcherPeer::UseWriter(dispatcher_.get(), writer_);
757 758
758 IPEndPoint client_address(net::test::Loopback4(), 1); 759 IPEndPoint client_address(net::test::Loopback4(), 1);
759 760
760 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 761 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
761 .WillOnce(testing::Return(CreateSession( 762 .WillOnce(testing::Return(CreateSession(
762 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_, 763 dispatcher_.get(), config_, 1, client_address, &helper_,
763 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 764 &alarm_factory_, &crypto_config_,
764 &session1_))); 765 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
765 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); 766 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
766 767
767 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 768 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
768 .WillOnce(testing::Return(CreateSession( 769 .WillOnce(testing::Return(CreateSession(
769 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_, 770 dispatcher_.get(), config_, 2, client_address, &helper_,
770 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 771 &alarm_factory_, &crypto_config_,
771 &session2_))); 772 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_)));
772 ProcessPacket(client_address, 2, true, false, SerializeCHLO()); 773 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
773 774
774 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); 775 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(dispatcher_.get());
775 } 776 }
776 777
777 void TearDown() override { 778 void TearDown() override {
778 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 779 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
779 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 780 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
780 dispatcher_.Shutdown(); 781 dispatcher_->Shutdown();
781 } 782 }
782 783
783 void SetBlocked() { writer_->write_blocked_ = true; } 784 void SetBlocked() { writer_->write_blocked_ = true; }
784 785
785 void BlockConnection2() { 786 void BlockConnection2() {
786 writer_->write_blocked_ = true; 787 writer_->write_blocked_ = true;
787 dispatcher_.OnWriteBlocked(connection2()); 788 dispatcher_->OnWriteBlocked(connection2());
788 } 789 }
789 790
790 protected: 791 protected:
791 MockQuicConnectionHelper helper_; 792 MockQuicConnectionHelper helper_;
792 MockAlarmFactory alarm_factory_; 793 MockAlarmFactory alarm_factory_;
793 BlockingWriter* writer_; 794 BlockingWriter* writer_;
794 QuicDispatcher::WriteBlockedList* blocked_list_; 795 QuicDispatcher::WriteBlockedList* blocked_list_;
795 }; 796 };
796 797
797 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) { 798 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) {
798 // No OnCanWrite calls because no connections are blocked. 799 // No OnCanWrite calls because no connections are blocked.
799 dispatcher_.OnCanWrite(); 800 dispatcher_->OnCanWrite();
800 801
801 // Register connection 1 for events, and make sure it's notified. 802 // Register connection 1 for events, and make sure it's notified.
802 SetBlocked(); 803 SetBlocked();
803 dispatcher_.OnWriteBlocked(connection1()); 804 dispatcher_->OnWriteBlocked(connection1());
804 EXPECT_CALL(*connection1(), OnCanWrite()); 805 EXPECT_CALL(*connection1(), OnCanWrite());
805 dispatcher_.OnCanWrite(); 806 dispatcher_->OnCanWrite();
806 807
807 // It should get only one notification. 808 // It should get only one notification.
808 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 809 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
809 dispatcher_.OnCanWrite(); 810 dispatcher_->OnCanWrite();
810 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 811 EXPECT_FALSE(dispatcher_->HasPendingWrites());
811 } 812 }
812 813
813 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteOrder) { 814 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteOrder) {
814 // Make sure we handle events in order. 815 // Make sure we handle events in order.
815 InSequence s; 816 InSequence s;
816 SetBlocked(); 817 SetBlocked();
817 dispatcher_.OnWriteBlocked(connection1()); 818 dispatcher_->OnWriteBlocked(connection1());
818 dispatcher_.OnWriteBlocked(connection2()); 819 dispatcher_->OnWriteBlocked(connection2());
819 EXPECT_CALL(*connection1(), OnCanWrite()); 820 EXPECT_CALL(*connection1(), OnCanWrite());
820 EXPECT_CALL(*connection2(), OnCanWrite()); 821 EXPECT_CALL(*connection2(), OnCanWrite());
821 dispatcher_.OnCanWrite(); 822 dispatcher_->OnCanWrite();
822 823
823 // Check the other ordering. 824 // Check the other ordering.
824 SetBlocked(); 825 SetBlocked();
825 dispatcher_.OnWriteBlocked(connection2()); 826 dispatcher_->OnWriteBlocked(connection2());
826 dispatcher_.OnWriteBlocked(connection1()); 827 dispatcher_->OnWriteBlocked(connection1());
827 EXPECT_CALL(*connection2(), OnCanWrite()); 828 EXPECT_CALL(*connection2(), OnCanWrite());
828 EXPECT_CALL(*connection1(), OnCanWrite()); 829 EXPECT_CALL(*connection1(), OnCanWrite());
829 dispatcher_.OnCanWrite(); 830 dispatcher_->OnCanWrite();
830 } 831 }
831 832
832 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteRemove) { 833 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteRemove) {
833 // Add and remove one connction. 834 // Add and remove one connction.
834 SetBlocked(); 835 SetBlocked();
835 dispatcher_.OnWriteBlocked(connection1()); 836 dispatcher_->OnWriteBlocked(connection1());
836 blocked_list_->erase(connection1()); 837 blocked_list_->erase(connection1());
837 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 838 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
838 dispatcher_.OnCanWrite(); 839 dispatcher_->OnCanWrite();
839 840
840 // Add and remove one connction and make sure it doesn't affect others. 841 // Add and remove one connction and make sure it doesn't affect others.
841 SetBlocked(); 842 SetBlocked();
842 dispatcher_.OnWriteBlocked(connection1()); 843 dispatcher_->OnWriteBlocked(connection1());
843 dispatcher_.OnWriteBlocked(connection2()); 844 dispatcher_->OnWriteBlocked(connection2());
844 blocked_list_->erase(connection1()); 845 blocked_list_->erase(connection1());
845 EXPECT_CALL(*connection2(), OnCanWrite()); 846 EXPECT_CALL(*connection2(), OnCanWrite());
846 dispatcher_.OnCanWrite(); 847 dispatcher_->OnCanWrite();
847 848
848 // Add it, remove it, and add it back and make sure things are OK. 849 // Add it, remove it, and add it back and make sure things are OK.
849 SetBlocked(); 850 SetBlocked();
850 dispatcher_.OnWriteBlocked(connection1()); 851 dispatcher_->OnWriteBlocked(connection1());
851 blocked_list_->erase(connection1()); 852 blocked_list_->erase(connection1());
852 dispatcher_.OnWriteBlocked(connection1()); 853 dispatcher_->OnWriteBlocked(connection1());
853 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); 854 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1);
854 dispatcher_.OnCanWrite(); 855 dispatcher_->OnCanWrite();
855 } 856 }
856 857
857 TEST_F(QuicDispatcherWriteBlockedListTest, DoubleAdd) { 858 TEST_F(QuicDispatcherWriteBlockedListTest, DoubleAdd) {
858 // Make sure a double add does not necessitate a double remove. 859 // Make sure a double add does not necessitate a double remove.
859 SetBlocked(); 860 SetBlocked();
860 dispatcher_.OnWriteBlocked(connection1()); 861 dispatcher_->OnWriteBlocked(connection1());
861 dispatcher_.OnWriteBlocked(connection1()); 862 dispatcher_->OnWriteBlocked(connection1());
862 blocked_list_->erase(connection1()); 863 blocked_list_->erase(connection1());
863 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 864 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
864 dispatcher_.OnCanWrite(); 865 dispatcher_->OnCanWrite();
865 866
866 // Make sure a double add does not result in two OnCanWrite calls. 867 // Make sure a double add does not result in two OnCanWrite calls.
867 SetBlocked(); 868 SetBlocked();
868 dispatcher_.OnWriteBlocked(connection1()); 869 dispatcher_->OnWriteBlocked(connection1());
869 dispatcher_.OnWriteBlocked(connection1()); 870 dispatcher_->OnWriteBlocked(connection1());
870 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); 871 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1);
871 dispatcher_.OnCanWrite(); 872 dispatcher_->OnCanWrite();
872 } 873 }
873 874
874 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlock) { 875 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlock) {
875 // Finally make sure if we write block on a write call, we stop calling. 876 // Finally make sure if we write block on a write call, we stop calling.
876 InSequence s; 877 InSequence s;
877 SetBlocked(); 878 SetBlocked();
878 dispatcher_.OnWriteBlocked(connection1()); 879 dispatcher_->OnWriteBlocked(connection1());
879 dispatcher_.OnWriteBlocked(connection2()); 880 dispatcher_->OnWriteBlocked(connection2());
880 EXPECT_CALL(*connection1(), OnCanWrite()) 881 EXPECT_CALL(*connection1(), OnCanWrite())
881 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked)); 882 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked));
882 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); 883 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0);
883 dispatcher_.OnCanWrite(); 884 dispatcher_->OnCanWrite();
884 885
885 // And we'll resume where we left off when we get another call. 886 // And we'll resume where we left off when we get another call.
886 EXPECT_CALL(*connection2(), OnCanWrite()); 887 EXPECT_CALL(*connection2(), OnCanWrite());
887 dispatcher_.OnCanWrite(); 888 dispatcher_->OnCanWrite();
888 } 889 }
889 890
890 TEST_F(QuicDispatcherWriteBlockedListTest, LimitedWrites) { 891 TEST_F(QuicDispatcherWriteBlockedListTest, LimitedWrites) {
891 // Make sure we call both writers. The first will register for more writing 892 // Make sure we call both writers. The first will register for more writing
892 // but should not be immediately called due to limits. 893 // but should not be immediately called due to limits.
893 InSequence s; 894 InSequence s;
894 SetBlocked(); 895 SetBlocked();
895 dispatcher_.OnWriteBlocked(connection1()); 896 dispatcher_->OnWriteBlocked(connection1());
896 dispatcher_.OnWriteBlocked(connection2()); 897 dispatcher_->OnWriteBlocked(connection2());
897 EXPECT_CALL(*connection1(), OnCanWrite()); 898 EXPECT_CALL(*connection1(), OnCanWrite());
898 EXPECT_CALL(*connection2(), OnCanWrite()) 899 EXPECT_CALL(*connection2(), OnCanWrite())
899 .WillOnce( 900 .WillOnce(
900 Invoke(this, &QuicDispatcherWriteBlockedListTest::BlockConnection2)); 901 Invoke(this, &QuicDispatcherWriteBlockedListTest::BlockConnection2));
901 dispatcher_.OnCanWrite(); 902 dispatcher_->OnCanWrite();
902 EXPECT_TRUE(dispatcher_.HasPendingWrites()); 903 EXPECT_TRUE(dispatcher_->HasPendingWrites());
903 904
904 // Now call OnCanWrite again, and connection1 should get its second chance 905 // Now call OnCanWrite again, and connection1 should get its second chance
905 EXPECT_CALL(*connection2(), OnCanWrite()); 906 EXPECT_CALL(*connection2(), OnCanWrite());
906 dispatcher_.OnCanWrite(); 907 dispatcher_->OnCanWrite();
907 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 908 EXPECT_FALSE(dispatcher_->HasPendingWrites());
908 } 909 }
909 910
910 TEST_F(QuicDispatcherWriteBlockedListTest, TestWriteLimits) { 911 TEST_F(QuicDispatcherWriteBlockedListTest, TestWriteLimits) {
911 // Finally make sure if we write block on a write call, we stop calling. 912 // Finally make sure if we write block on a write call, we stop calling.
912 InSequence s; 913 InSequence s;
913 SetBlocked(); 914 SetBlocked();
914 dispatcher_.OnWriteBlocked(connection1()); 915 dispatcher_->OnWriteBlocked(connection1());
915 dispatcher_.OnWriteBlocked(connection2()); 916 dispatcher_->OnWriteBlocked(connection2());
916 EXPECT_CALL(*connection1(), OnCanWrite()) 917 EXPECT_CALL(*connection1(), OnCanWrite())
917 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked)); 918 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked));
918 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); 919 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0);
919 dispatcher_.OnCanWrite(); 920 dispatcher_->OnCanWrite();
920 EXPECT_TRUE(dispatcher_.HasPendingWrites()); 921 EXPECT_TRUE(dispatcher_->HasPendingWrites());
921 922
922 // And we'll resume where we left off when we get another call. 923 // And we'll resume where we left off when we get another call.
923 EXPECT_CALL(*connection2(), OnCanWrite()); 924 EXPECT_CALL(*connection2(), OnCanWrite());
924 dispatcher_.OnCanWrite(); 925 dispatcher_->OnCanWrite();
925 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 926 EXPECT_FALSE(dispatcher_->HasPendingWrites());
926 } 927 }
927 928
928 } // namespace 929 } // namespace
929 } // namespace test 930 } // namespace test
930 } // namespace net 931 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698