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

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

Issue 2132623002: Landing Recent QUIC changes until 2016-07-02 02:45 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing comment about RPCs 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 | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_epoll_alarm_factory.cc » ('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 <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",
645 "AEAD", "AESG", 646 "AEAD", "AESG",
646 "KEXS", "C255", 647 "KEXS", "C255",
647 "COPT", "SREJ", 648 "COPT", "SREJ",
648 "NONC", "1234567890123456789012", 649 "NONC", "1234567890123456789012",
649 "VER\0", "Q025", 650 "VER\0", "Q025",
650 "$padding", static_cast<int>(kClientHelloMinimumSize), 651 "$padding", static_cast<int>(kClientHelloMinimumSize),
651 nullptr); 652 nullptr);
652 // clang-format on 653 // clang-format on
653 654
654 ProcessPacket(client_address, connection_id, true, false, 655 ProcessPacket(client_address, connection_id, true, false,
655 client_hello.GetSerialized().AsStringPiece().as_string()); 656 client_hello.GetSerialized().AsStringPiece().as_string());
656 657
657 if (GetParam().enable_stateless_rejects_via_flag) { 658 if (GetParam().enable_stateless_rejects_via_flag) {
658 EXPECT_EQ(true, 659 EXPECT_EQ(true,
659 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 660 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
660 } 661 }
661 } 662 }
662 663
664 TEST_P(QuicDispatcherStatelessRejectTest, BufferNonChlo) {
665 FLAGS_quic_use_cheap_stateless_rejects = true;
666 CreateTimeWaitListManager();
667
668 const IPEndPoint client_address(net::test::Loopback4(), 1);
669 const QuicConnectionId connection_id = 1;
670
671 if (!GetParam().enable_stateless_rejects_via_flag) {
672 // If stateless rejects are not being used, then a connection will be
673 // created immediately.
674 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
675 .WillOnce(testing::Return(
676 CreateSessionBasedOnTestParams(connection_id, client_address)));
677 }
678 ProcessPacket(client_address, connection_id, true, false,
679 "NOT DATA FOR A CHLO");
680
681 // Process the first packet for the connection.
682 // clang-format off
683 CryptoHandshakeMessage client_hello = CryptoTestUtils::Message(
684 "CHLO",
685 "AEAD", "AESG",
686 "KEXS", "C255",
687 "NONC", "1234567890123456789012",
688 "VER\0", "Q025",
689 "$padding", static_cast<int>(kClientHelloMinimumSize),
690 nullptr);
691 // clang-format on
692
693 if (GetParam().enable_stateless_rejects_via_flag) {
694 // If stateless rejects are enabled then a connection will be created now
695 // and the buffered packet will be processed
696 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
697 .WillOnce(testing::Return(
698 CreateSessionBasedOnTestParams(connection_id, client_address)));
699 }
700 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
701 ProcessUdpPacket(_, client_address, _))
702 .RetiresOnSaturation();
703 ProcessPacket(client_address, connection_id, true, false,
704 client_hello.GetSerialized().AsStringPiece().as_string());
705 EXPECT_FALSE(
706 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
707 }
708
663 // Verify the stopgap test: Packets with truncated connection IDs should be 709 // Verify the stopgap test: Packets with truncated connection IDs should be
664 // dropped. 710 // dropped.
665 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; 711 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {};
666 712
667 // Packets with truncated connection IDs should be dropped. 713 // Packets with truncated connection IDs should be dropped.
668 TEST_F(QuicDispatcherTestStrayPacketConnectionId, 714 TEST_F(QuicDispatcherTestStrayPacketConnectionId,
669 StrayPacketTruncatedConnectionId) { 715 StrayPacketTruncatedConnectionId) {
670 CreateTimeWaitListManager(); 716 CreateTimeWaitListManager();
671 717
672 IPEndPoint client_address(net::test::Loopback4(), 1); 718 IPEndPoint client_address(net::test::Loopback4(), 1);
673 QuicConnectionId connection_id = 1; 719 QuicConnectionId connection_id = 1;
674 // Dispatcher drops this packet. 720 // Dispatcher drops this packet.
675 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); 721 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, _)).Times(0);
676 EXPECT_CALL(*time_wait_list_manager_, 722 EXPECT_CALL(*time_wait_list_manager_,
677 ProcessPacket(_, _, connection_id, _, _)) 723 ProcessPacket(_, _, connection_id, _, _))
678 .Times(0); 724 .Times(0);
679 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 725 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
680 .Times(0); 726 .Times(0);
681 ProcessPacket(client_address, connection_id, true, false, "data", 727 ProcessPacket(client_address, connection_id, true, false, "data",
682 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER); 728 PACKET_0BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER);
683 } 729 }
684 730
685 class BlockingWriter : public QuicPacketWriterWrapper { 731 class BlockingWriter : public QuicPacketWriterWrapper {
(...skipping 15 matching lines...) Expand all
701 return WriteResult(); 747 return WriteResult();
702 } 748 }
703 749
704 bool write_blocked_; 750 bool write_blocked_;
705 }; 751 };
706 752
707 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { 753 class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest {
708 public: 754 public:
709 void SetUp() override { 755 void SetUp() override {
710 writer_ = new BlockingWriter; 756 writer_ = new BlockingWriter;
711 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); 757 QuicDispatcherPeer::UseWriter(dispatcher_.get(), writer_);
712 758
713 IPEndPoint client_address(net::test::Loopback4(), 1); 759 IPEndPoint client_address(net::test::Loopback4(), 1);
714 760
715 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 761 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
716 .WillOnce(testing::Return(CreateSession( 762 .WillOnce(testing::Return(CreateSession(
717 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_, 763 dispatcher_.get(), config_, 1, client_address, &helper_,
718 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 764 &alarm_factory_, &crypto_config_,
719 &session1_))); 765 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
720 ProcessPacket(client_address, 1, true, false, SerializeCHLO()); 766 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
721 767
722 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 768 EXPECT_CALL(*dispatcher_, CreateQuicSession(_, client_address))
723 .WillOnce(testing::Return(CreateSession( 769 .WillOnce(testing::Return(CreateSession(
724 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_, 770 dispatcher_.get(), config_, 2, client_address, &helper_,
725 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 771 &alarm_factory_, &crypto_config_,
726 &session2_))); 772 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session2_)));
727 ProcessPacket(client_address, 2, true, false, SerializeCHLO()); 773 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
728 774
729 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); 775 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(dispatcher_.get());
730 } 776 }
731 777
732 void TearDown() override { 778 void TearDown() override {
733 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 779 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
734 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 780 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
735 dispatcher_.Shutdown(); 781 dispatcher_->Shutdown();
736 } 782 }
737 783
738 void SetBlocked() { writer_->write_blocked_ = true; } 784 void SetBlocked() { writer_->write_blocked_ = true; }
739 785
740 void BlockConnection2() { 786 void BlockConnection2() {
741 writer_->write_blocked_ = true; 787 writer_->write_blocked_ = true;
742 dispatcher_.OnWriteBlocked(connection2()); 788 dispatcher_->OnWriteBlocked(connection2());
743 } 789 }
744 790
745 protected: 791 protected:
746 MockQuicConnectionHelper helper_; 792 MockQuicConnectionHelper helper_;
747 MockAlarmFactory alarm_factory_; 793 MockAlarmFactory alarm_factory_;
748 BlockingWriter* writer_; 794 BlockingWriter* writer_;
749 QuicDispatcher::WriteBlockedList* blocked_list_; 795 QuicDispatcher::WriteBlockedList* blocked_list_;
750 }; 796 };
751 797
752 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) { 798 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) {
753 // No OnCanWrite calls because no connections are blocked. 799 // No OnCanWrite calls because no connections are blocked.
754 dispatcher_.OnCanWrite(); 800 dispatcher_->OnCanWrite();
755 801
756 // Register connection 1 for events, and make sure it's notified. 802 // Register connection 1 for events, and make sure it's notified.
757 SetBlocked(); 803 SetBlocked();
758 dispatcher_.OnWriteBlocked(connection1()); 804 dispatcher_->OnWriteBlocked(connection1());
759 EXPECT_CALL(*connection1(), OnCanWrite()); 805 EXPECT_CALL(*connection1(), OnCanWrite());
760 dispatcher_.OnCanWrite(); 806 dispatcher_->OnCanWrite();
761 807
762 // It should get only one notification. 808 // It should get only one notification.
763 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 809 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
764 dispatcher_.OnCanWrite(); 810 dispatcher_->OnCanWrite();
765 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 811 EXPECT_FALSE(dispatcher_->HasPendingWrites());
766 } 812 }
767 813
768 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteOrder) { 814 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteOrder) {
769 // Make sure we handle events in order. 815 // Make sure we handle events in order.
770 InSequence s; 816 InSequence s;
771 SetBlocked(); 817 SetBlocked();
772 dispatcher_.OnWriteBlocked(connection1()); 818 dispatcher_->OnWriteBlocked(connection1());
773 dispatcher_.OnWriteBlocked(connection2()); 819 dispatcher_->OnWriteBlocked(connection2());
774 EXPECT_CALL(*connection1(), OnCanWrite()); 820 EXPECT_CALL(*connection1(), OnCanWrite());
775 EXPECT_CALL(*connection2(), OnCanWrite()); 821 EXPECT_CALL(*connection2(), OnCanWrite());
776 dispatcher_.OnCanWrite(); 822 dispatcher_->OnCanWrite();
777 823
778 // Check the other ordering. 824 // Check the other ordering.
779 SetBlocked(); 825 SetBlocked();
780 dispatcher_.OnWriteBlocked(connection2()); 826 dispatcher_->OnWriteBlocked(connection2());
781 dispatcher_.OnWriteBlocked(connection1()); 827 dispatcher_->OnWriteBlocked(connection1());
782 EXPECT_CALL(*connection2(), OnCanWrite()); 828 EXPECT_CALL(*connection2(), OnCanWrite());
783 EXPECT_CALL(*connection1(), OnCanWrite()); 829 EXPECT_CALL(*connection1(), OnCanWrite());
784 dispatcher_.OnCanWrite(); 830 dispatcher_->OnCanWrite();
785 } 831 }
786 832
787 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteRemove) { 833 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteRemove) {
788 // Add and remove one connction. 834 // Add and remove one connction.
789 SetBlocked(); 835 SetBlocked();
790 dispatcher_.OnWriteBlocked(connection1()); 836 dispatcher_->OnWriteBlocked(connection1());
791 blocked_list_->erase(connection1()); 837 blocked_list_->erase(connection1());
792 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 838 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
793 dispatcher_.OnCanWrite(); 839 dispatcher_->OnCanWrite();
794 840
795 // 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.
796 SetBlocked(); 842 SetBlocked();
797 dispatcher_.OnWriteBlocked(connection1()); 843 dispatcher_->OnWriteBlocked(connection1());
798 dispatcher_.OnWriteBlocked(connection2()); 844 dispatcher_->OnWriteBlocked(connection2());
799 blocked_list_->erase(connection1()); 845 blocked_list_->erase(connection1());
800 EXPECT_CALL(*connection2(), OnCanWrite()); 846 EXPECT_CALL(*connection2(), OnCanWrite());
801 dispatcher_.OnCanWrite(); 847 dispatcher_->OnCanWrite();
802 848
803 // 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.
804 SetBlocked(); 850 SetBlocked();
805 dispatcher_.OnWriteBlocked(connection1()); 851 dispatcher_->OnWriteBlocked(connection1());
806 blocked_list_->erase(connection1()); 852 blocked_list_->erase(connection1());
807 dispatcher_.OnWriteBlocked(connection1()); 853 dispatcher_->OnWriteBlocked(connection1());
808 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); 854 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1);
809 dispatcher_.OnCanWrite(); 855 dispatcher_->OnCanWrite();
810 } 856 }
811 857
812 TEST_F(QuicDispatcherWriteBlockedListTest, DoubleAdd) { 858 TEST_F(QuicDispatcherWriteBlockedListTest, DoubleAdd) {
813 // Make sure a double add does not necessitate a double remove. 859 // Make sure a double add does not necessitate a double remove.
814 SetBlocked(); 860 SetBlocked();
815 dispatcher_.OnWriteBlocked(connection1()); 861 dispatcher_->OnWriteBlocked(connection1());
816 dispatcher_.OnWriteBlocked(connection1()); 862 dispatcher_->OnWriteBlocked(connection1());
817 blocked_list_->erase(connection1()); 863 blocked_list_->erase(connection1());
818 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); 864 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0);
819 dispatcher_.OnCanWrite(); 865 dispatcher_->OnCanWrite();
820 866
821 // 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.
822 SetBlocked(); 868 SetBlocked();
823 dispatcher_.OnWriteBlocked(connection1()); 869 dispatcher_->OnWriteBlocked(connection1());
824 dispatcher_.OnWriteBlocked(connection1()); 870 dispatcher_->OnWriteBlocked(connection1());
825 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); 871 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1);
826 dispatcher_.OnCanWrite(); 872 dispatcher_->OnCanWrite();
827 } 873 }
828 874
829 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlock) { 875 TEST_F(QuicDispatcherWriteBlockedListTest, OnCanWriteHandleBlock) {
830 // 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.
831 InSequence s; 877 InSequence s;
832 SetBlocked(); 878 SetBlocked();
833 dispatcher_.OnWriteBlocked(connection1()); 879 dispatcher_->OnWriteBlocked(connection1());
834 dispatcher_.OnWriteBlocked(connection2()); 880 dispatcher_->OnWriteBlocked(connection2());
835 EXPECT_CALL(*connection1(), OnCanWrite()) 881 EXPECT_CALL(*connection1(), OnCanWrite())
836 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked)); 882 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked));
837 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); 883 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0);
838 dispatcher_.OnCanWrite(); 884 dispatcher_->OnCanWrite();
839 885
840 // 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.
841 EXPECT_CALL(*connection2(), OnCanWrite()); 887 EXPECT_CALL(*connection2(), OnCanWrite());
842 dispatcher_.OnCanWrite(); 888 dispatcher_->OnCanWrite();
843 } 889 }
844 890
845 TEST_F(QuicDispatcherWriteBlockedListTest, LimitedWrites) { 891 TEST_F(QuicDispatcherWriteBlockedListTest, LimitedWrites) {
846 // 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
847 // but should not be immediately called due to limits. 893 // but should not be immediately called due to limits.
848 InSequence s; 894 InSequence s;
849 SetBlocked(); 895 SetBlocked();
850 dispatcher_.OnWriteBlocked(connection1()); 896 dispatcher_->OnWriteBlocked(connection1());
851 dispatcher_.OnWriteBlocked(connection2()); 897 dispatcher_->OnWriteBlocked(connection2());
852 EXPECT_CALL(*connection1(), OnCanWrite()); 898 EXPECT_CALL(*connection1(), OnCanWrite());
853 EXPECT_CALL(*connection2(), OnCanWrite()) 899 EXPECT_CALL(*connection2(), OnCanWrite())
854 .WillOnce( 900 .WillOnce(
855 Invoke(this, &QuicDispatcherWriteBlockedListTest::BlockConnection2)); 901 Invoke(this, &QuicDispatcherWriteBlockedListTest::BlockConnection2));
856 dispatcher_.OnCanWrite(); 902 dispatcher_->OnCanWrite();
857 EXPECT_TRUE(dispatcher_.HasPendingWrites()); 903 EXPECT_TRUE(dispatcher_->HasPendingWrites());
858 904
859 // Now call OnCanWrite again, and connection1 should get its second chance 905 // Now call OnCanWrite again, and connection1 should get its second chance
860 EXPECT_CALL(*connection2(), OnCanWrite()); 906 EXPECT_CALL(*connection2(), OnCanWrite());
861 dispatcher_.OnCanWrite(); 907 dispatcher_->OnCanWrite();
862 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 908 EXPECT_FALSE(dispatcher_->HasPendingWrites());
863 } 909 }
864 910
865 TEST_F(QuicDispatcherWriteBlockedListTest, TestWriteLimits) { 911 TEST_F(QuicDispatcherWriteBlockedListTest, TestWriteLimits) {
866 // 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.
867 InSequence s; 913 InSequence s;
868 SetBlocked(); 914 SetBlocked();
869 dispatcher_.OnWriteBlocked(connection1()); 915 dispatcher_->OnWriteBlocked(connection1());
870 dispatcher_.OnWriteBlocked(connection2()); 916 dispatcher_->OnWriteBlocked(connection2());
871 EXPECT_CALL(*connection1(), OnCanWrite()) 917 EXPECT_CALL(*connection1(), OnCanWrite())
872 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked)); 918 .WillOnce(Invoke(this, &QuicDispatcherWriteBlockedListTest::SetBlocked));
873 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); 919 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0);
874 dispatcher_.OnCanWrite(); 920 dispatcher_->OnCanWrite();
875 EXPECT_TRUE(dispatcher_.HasPendingWrites()); 921 EXPECT_TRUE(dispatcher_->HasPendingWrites());
876 922
877 // 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.
878 EXPECT_CALL(*connection2(), OnCanWrite()); 924 EXPECT_CALL(*connection2(), OnCanWrite());
879 dispatcher_.OnCanWrite(); 925 dispatcher_->OnCanWrite();
880 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 926 EXPECT_FALSE(dispatcher_->HasPendingWrites());
881 } 927 }
882 928
883 } // namespace 929 } // namespace
884 } // namespace test 930 } // namespace test
885 } // namespace net 931 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_epoll_alarm_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698