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

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

Issue 23691073: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compiler/unittests fix Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_connection_test.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/quic/quic_connection_helper.h" 5 #include "net/quic/quic_connection_helper.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "net/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/quic/crypto/quic_decrypter.h" 10 #include "net/quic/crypto/quic_decrypter.h"
11 #include "net/quic/crypto/quic_encrypter.h" 11 #include "net/quic/crypto/quic_encrypter.h"
12 #include "net/quic/quic_connection.h"
12 #include "net/quic/test_tools/mock_clock.h" 13 #include "net/quic/test_tools/mock_clock.h"
13 #include "net/quic/test_tools/quic_connection_peer.h" 14 #include "net/quic/test_tools/quic_connection_peer.h"
14 #include "net/quic/test_tools/quic_test_utils.h" 15 #include "net/quic/test_tools/quic_test_utils.h"
15 #include "net/quic/test_tools/test_task_runner.h" 16 #include "net/quic/test_tools/test_task_runner.h"
16 #include "net/socket/socket_test_util.h" 17 #include "net/socket/socket_test_util.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using testing::_; 21 using testing::_;
22 using testing::AnyNumber;
23 using testing::Return;
21 24
22 namespace net { 25 namespace net {
23 namespace test { 26 namespace test {
24 27
25 const char kData[] = "foo"; 28 const char kData[] = "foo";
26 const bool kFromPeer = true; 29 const bool kFromPeer = true;
27 30
28 class TestDelegate : public QuicAlarm::Delegate { 31 class TestDelegate : public QuicAlarm::Delegate {
29 public: 32 public:
30 TestDelegate() : fired_(false) {} 33 TestDelegate() : fired_(false) {}
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 writes_.size())); 116 writes_.size()));
114 117
115 socket_.reset(new MockUDPClientSocket(socket_data_.get(), 118 socket_.reset(new MockUDPClientSocket(socket_data_.get(),
116 net_log_.net_log())); 119 net_log_.net_log()));
117 socket_->Connect(IPEndPoint()); 120 socket_->Connect(IPEndPoint());
118 runner_ = new TestTaskRunner(&clock_); 121 runner_ = new TestTaskRunner(&clock_);
119 helper_ = new QuicConnectionHelper(runner_.get(), &clock_, 122 helper_ = new QuicConnectionHelper(runner_.get(), &clock_,
120 &random_generator_, socket_.get()); 123 &random_generator_, socket_.get());
121 send_algorithm_ = new testing::StrictMock<MockSendAlgorithm>(); 124 send_algorithm_ = new testing::StrictMock<MockSendAlgorithm>();
122 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)). 125 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)).
123 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 126 WillRepeatedly(Return(QuicTime::Delta::Zero()));
124 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly( 127 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(
125 testing::Return(QuicBandwidth::FromKBitsPerSecond(100))); 128 Return(QuicBandwidth::FromKBitsPerSecond(100)));
126 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly( 129 EXPECT_CALL(*send_algorithm_, SmoothedRtt()).WillRepeatedly(
127 testing::Return(QuicTime::Delta::FromMilliseconds(100))); 130 Return(QuicTime::Delta::FromMilliseconds(100)));
128 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)) 131 ON_CALL(*send_algorithm_, SentPacket(_, _, _, _, _))
129 .WillByDefault(testing::Return(true)); 132 .WillByDefault(Return(true));
133 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
130 connection_.reset(new TestConnection(guid_, IPEndPoint(), helper_)); 134 connection_.reset(new TestConnection(guid_, IPEndPoint(), helper_));
131 connection_->set_visitor(&visitor_); 135 connection_->set_visitor(&visitor_);
132 connection_->SetSendAlgorithm(send_algorithm_); 136 connection_->SetSendAlgorithm(send_algorithm_);
133 } 137 }
134 138
135 // Returns a newly created packet to send kData on stream 1. 139 // Returns a newly created packet to send kData on stream 1.
136 QuicEncryptedPacket* ConstructDataPacket( 140 QuicEncryptedPacket* ConstructDataPacket(
137 QuicPacketSequenceNumber sequence_number) { 141 QuicPacketSequenceNumber sequence_number) {
138 InitializeHeader(sequence_number); 142 InitializeHeader(sequence_number);
139 143
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 EXPECT_EQ(QuicTime::Zero().Add(new_delta), clock_.Now()); 308 EXPECT_EQ(QuicTime::Zero().Add(new_delta), clock_.Now());
305 EXPECT_TRUE(delegate->fired()); 309 EXPECT_TRUE(delegate->fired());
306 } 310 }
307 311
308 TEST_F(QuicConnectionHelperTest, TestRetransmission) { 312 TEST_F(QuicConnectionHelperTest, TestRetransmission) {
309 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 313 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
310 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); 314 AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
311 Initialize(); 315 Initialize();
312 316
313 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 317 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
314 testing::Return(QuicTime::Delta::Zero())); 318 Return(QuicTime::Delta::Zero()));
315 319
316 QuicTime::Delta kDefaultRetransmissionTime = 320 QuicTime::Delta kDefaultRetransmissionTime =
317 QuicTime::Delta::FromMilliseconds(500); 321 QuicTime::Delta::FromMilliseconds(500);
318 QuicTime start = clock_.ApproximateNow(); 322 QuicTime start = clock_.ApproximateNow();
319 323
320 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _)); 324 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
321 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)); 325 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _));
322 326
323 // Send a packet. 327 // Send a packet.
324 struct iovec iov = {const_cast<char*>(kData), 328 struct iovec iov = {const_cast<char*>(kData),
325 static_cast<size_t>(strlen(kData))}; 329 static_cast<size_t>(strlen(kData))};
326 connection_->SendvStreamData(1, &iov, 1, 0, false); 330 connection_->SendvStreamData(1, &iov, 1, 0, false);
327 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION, _)); 331 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION, _));
328 // Since no ack was received, the retransmission alarm will fire and 332 // Since no ack was received, the retransmission alarm will fire and
329 // retransmit it. 333 // retransmit it.
330 runner_->RunNextTask(); 334 runner_->RunNextTask();
331 335
332 EXPECT_EQ(kDefaultRetransmissionTime, 336 EXPECT_EQ(kDefaultRetransmissionTime,
333 clock_.ApproximateNow().Subtract(start)); 337 clock_.ApproximateNow().Subtract(start));
334 EXPECT_TRUE(AtEof()); 338 EXPECT_TRUE(AtEof());
335 } 339 }
336 340
337 TEST_F(QuicConnectionHelperTest, TestMultipleRetransmission) { 341 TEST_F(QuicConnectionHelperTest, TestMultipleRetransmission) {
338 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 342 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
339 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); 343 AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
340 AddWrite(SYNCHRONOUS, ConstructDataPacket(3)); 344 AddWrite(SYNCHRONOUS, ConstructDataPacket(3));
341 Initialize(); 345 Initialize();
342 346
343 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 347 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
344 testing::Return(QuicTime::Delta::Zero())); 348 Return(QuicTime::Delta::Zero()));
345 349
346 QuicTime::Delta kDefaultRetransmissionTime = 350 QuicTime::Delta kDefaultRetransmissionTime =
347 QuicTime::Delta::FromMilliseconds(500); 351 QuicTime::Delta::FromMilliseconds(500);
348 QuicTime start = clock_.ApproximateNow(); 352 QuicTime start = clock_.ApproximateNow();
349 353
350 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _)); 354 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _));
351 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)); 355 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _));
352 356
353 // Send a packet. 357 // Send a packet.
354 struct iovec iov = {const_cast<char*>(kData), 358 struct iovec iov = {const_cast<char*>(kData),
(...skipping 21 matching lines...) Expand all
376 380
377 TEST_F(QuicConnectionHelperTest, InitialTimeout) { 381 TEST_F(QuicConnectionHelperTest, InitialTimeout) {
378 AddWrite(SYNCHRONOUS, ConstructClosePacket(1, 0)); 382 AddWrite(SYNCHRONOUS, ConstructClosePacket(1, 0));
379 Initialize(); 383 Initialize();
380 384
381 // Verify that a single task was posted. 385 // Verify that a single task was posted.
382 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); 386 ASSERT_EQ(1u, runner_->GetPostedTasks().size());
383 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultInitialTimeoutSecs), 387 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultInitialTimeoutSecs),
384 runner_->GetPostedTasks().front().delay); 388 runner_->GetPostedTasks().front().delay);
385 389
386 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, _)); 390 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION,
391 HAS_RETRANSMITTABLE_DATA));
392 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillOnce(
393 Return(QuicTime::Delta::FromMicroseconds(1)));
387 // After we run the next task, we should close the connection. 394 // After we run the next task, we should close the connection.
388 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 395 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false));
389 396
390 runner_->RunNextTask(); 397 runner_->RunNextTask();
391 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds( 398 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(
392 kDefaultInitialTimeoutSecs)), 399 kDefaultInitialTimeoutSecs)),
393 clock_.ApproximateNow()); 400 clock_.ApproximateNow());
394 EXPECT_FALSE(connection_->connected()); 401 EXPECT_FALSE(connection_->connected());
395 EXPECT_TRUE(AtEof()); 402 EXPECT_TRUE(AtEof());
396 } 403 }
397 404
398 TEST_F(QuicConnectionHelperTest, WritePacketToWire) { 405 TEST_F(QuicConnectionHelperTest, WritePacketToWire) {
399 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 406 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
400 Initialize(); 407 Initialize();
401 408
402 int len = GetWrite(0)->length(); 409 int len = GetWrite(0)->length();
403 int error = 0; 410 int error = 0;
404 EXPECT_EQ(len, helper_->WritePacketToWire(*GetWrite(0), &error)); 411 EXPECT_EQ(len, helper_->WritePacketToWire(*GetWrite(0), &error));
405 EXPECT_EQ(0, error); 412 EXPECT_EQ(0, error);
406 EXPECT_TRUE(AtEof()); 413 EXPECT_TRUE(AtEof());
407 } 414 }
408 415
409 TEST_F(QuicConnectionHelperTest, WritePacketToWireAsync) { 416 TEST_F(QuicConnectionHelperTest, WritePacketToWireAsync) {
410 AddWrite(ASYNC, ConstructClosePacket(1, 0)); 417 AddWrite(ASYNC, ConstructClosePacket(1, 0));
411 Initialize(); 418 Initialize();
412 419
413 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 420 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true));
414 int error = 0; 421 int error = 0;
415 EXPECT_EQ(-1, helper_->WritePacketToWire(*GetWrite(0), &error)); 422 EXPECT_EQ(-1, helper_->WritePacketToWire(*GetWrite(0), &error));
416 EXPECT_EQ(ERR_IO_PENDING, error); 423 EXPECT_EQ(ERR_IO_PENDING, error);
417 base::MessageLoop::current()->RunUntilIdle(); 424 base::MessageLoop::current()->RunUntilIdle();
418 EXPECT_TRUE(AtEof()); 425 EXPECT_TRUE(AtEof());
419 } 426 }
420 427
421 TEST_F(QuicConnectionHelperTest, TimeoutAfterSend) { 428 TEST_F(QuicConnectionHelperTest, TimeoutAfterSend) {
422 AddWrite(SYNCHRONOUS, ConstructAckPacket(1)); 429 AddWrite(SYNCHRONOUS, ConstructAckPacket(1));
423 AddWrite(SYNCHRONOUS, ConstructClosePacket(2, 1)); 430 AddWrite(SYNCHRONOUS, ConstructClosePacket(2, 1));
(...skipping 16 matching lines...) Expand all
440 // network event at t=5000. The alarm will reregister. 447 // network event at t=5000. The alarm will reregister.
441 runner_->RunNextTask(); 448 runner_->RunNextTask();
442 449
443 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds( 450 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(
444 kDefaultInitialTimeoutSecs)), 451 kDefaultInitialTimeoutSecs)),
445 clock_.ApproximateNow()); 452 clock_.ApproximateNow());
446 EXPECT_TRUE(connection_->connected()); 453 EXPECT_TRUE(connection_->connected());
447 454
448 // This time, we should time out. 455 // This time, we should time out.
449 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer)); 456 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
450 EXPECT_CALL(*send_algorithm_, 457 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION,
451 SentPacket(_, 2, _, NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA)); 458 HAS_RETRANSMITTABLE_DATA));
459 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillOnce(
460 Return(QuicTime::Delta::FromMicroseconds(1)));
452 runner_->RunNextTask(); 461 runner_->RunNextTask();
453 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000, 462 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000,
454 clock_.ApproximateNow().Subtract( 463 clock_.ApproximateNow().Subtract(
455 QuicTime::Zero()).ToMicroseconds()); 464 QuicTime::Zero()).ToMicroseconds());
456 EXPECT_FALSE(connection_->connected()); 465 EXPECT_FALSE(connection_->connected());
457 EXPECT_TRUE(AtEof()); 466 EXPECT_TRUE(AtEof());
458 } 467 }
459 468
460 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { 469 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) {
461 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 470 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
462 Initialize(); 471 Initialize();
463 472
464 // Test that if we send a packet with a delay, it ends up queued. 473 // Test that if we send a packet with a delay, it ends up queued.
465 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 474 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
466 testing::Return(QuicTime::Delta::Zero())); 475 Return(QuicTime::Delta::Zero()));
467 EXPECT_CALL( 476 EXPECT_CALL(
468 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce( 477 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillOnce(
469 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 478 Return(QuicTime::Delta::FromMicroseconds(1)));
470 479
471 QuicPacket* packet = ConstructRawDataPacket(1); 480 QuicPacket* packet = ConstructRawDataPacket(1);
472 connection_->SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0, 481 connection_->SendOrQueuePacket(ENCRYPTION_NONE, 1, packet, 0,
473 HAS_RETRANSMITTABLE_DATA); 482 HAS_RETRANSMITTABLE_DATA,
483 QuicConnection::NO_FORCE);
474 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION, 484 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION,
475 _)); 485 _));
476 EXPECT_EQ(1u, connection_->NumQueuedPackets()); 486 EXPECT_EQ(1u, connection_->NumQueuedPackets());
477 487
478 // Advance the clock to fire the alarm, and configure the scheduler 488 // Advance the clock to fire the alarm, and configure the scheduler
479 // to permit the packet to be sent. 489 // to permit the packet to be sent.
480 EXPECT_CALL(*send_algorithm_, 490 EXPECT_CALL(*send_algorithm_,
481 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly( 491 TimeUntilSend(_, NOT_RETRANSMISSION, _, _)).WillRepeatedly(
482 testing::Return(QuicTime::Delta::Zero())); 492 Return(QuicTime::Delta::Zero()));
483 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 493 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true));
494 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
484 runner_->RunNextTask(); 495 runner_->RunNextTask();
485 EXPECT_EQ(0u, connection_->NumQueuedPackets()); 496 EXPECT_EQ(0u, connection_->NumQueuedPackets());
486 EXPECT_TRUE(AtEof()); 497 EXPECT_TRUE(AtEof());
487 } 498 }
488 499
489 } // namespace test 500 } // namespace test
490 } // namespace net 501 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_connection_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698