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

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

Issue 15074007: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for windows Created 7 years, 7 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/test_tools/mock_clock.h" 12 #include "net/quic/test_tools/mock_clock.h"
13 #include "net/quic/test_tools/quic_connection_peer.h" 13 #include "net/quic/test_tools/quic_connection_peer.h"
14 #include "net/quic/test_tools/quic_test_utils.h" 14 #include "net/quic/test_tools/quic_test_utils.h"
15 #include "net/quic/test_tools/test_task_runner.h" 15 #include "net/quic/test_tools/test_task_runner.h"
16 #include "net/socket/socket_test_util.h" 16 #include "net/socket/socket_test_util.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using testing::_; 20 using testing::_;
21 21
22 namespace net { 22 namespace net {
23 namespace test { 23 namespace test {
24 24
25 const char kData[] = "foo"; 25 const char kData[] = "foo";
26 const bool kHasData = true; 26 const bool kFromPeer = true;
27 27
28 class TestConnection : public QuicConnection { 28 class TestConnection : public QuicConnection {
29 public: 29 public:
30 TestConnection(QuicGuid guid, 30 TestConnection(QuicGuid guid,
31 IPEndPoint address, 31 IPEndPoint address,
32 QuicConnectionHelper* helper) 32 QuicConnectionHelper* helper)
33 : QuicConnection(guid, address, helper, false) { 33 : QuicConnection(guid, address, helper, false) {
34 } 34 }
35 35
36 void SendAck() { 36 void SendAck() {
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 clock_.ApproximateNow().Subtract(start)); 321 clock_.ApproximateNow().Subtract(start));
322 EXPECT_TRUE(AtEof()); 322 EXPECT_TRUE(AtEof());
323 } 323 }
324 324
325 TEST_F(QuicConnectionHelperTest, InitialTimeout) { 325 TEST_F(QuicConnectionHelperTest, InitialTimeout) {
326 AddWrite(SYNCHRONOUS, ConstructClosePacket(1, 0)); 326 AddWrite(SYNCHRONOUS, ConstructClosePacket(1, 0));
327 Initialize(); 327 Initialize();
328 328
329 // Verify that a single task was posted. 329 // Verify that a single task was posted.
330 ASSERT_EQ(1u, runner_->GetPostedTasks().size()); 330 ASSERT_EQ(1u, runner_->GetPostedTasks().size());
331 EXPECT_EQ(base::TimeDelta::FromMicroseconds(kDefaultTimeoutUs), 331 EXPECT_EQ(base::TimeDelta::FromSeconds(kDefaultInitialTimeoutSecs),
332 runner_->GetPostedTasks().front().delay); 332 runner_->GetPostedTasks().front().delay);
333 333
334 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 334 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
335 // After we run the next task, we should close the connection. 335 // After we run the next task, we should close the connection.
336 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 336 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false));
337 337
338 runner_->RunNextTask(); 338 runner_->RunNextTask();
339 EXPECT_EQ(QuicTime::Zero().Add( 339 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(
340 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)), 340 kDefaultInitialTimeoutSecs)),
341 clock_.ApproximateNow()); 341 clock_.ApproximateNow());
342 EXPECT_FALSE(connection_->connected()); 342 EXPECT_FALSE(connection_->connected());
343 EXPECT_TRUE(AtEof()); 343 EXPECT_TRUE(AtEof());
344 } 344 }
345 345
346 TEST_F(QuicConnectionHelperTest, WritePacketToWire) { 346 TEST_F(QuicConnectionHelperTest, WritePacketToWire) {
347 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 347 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
348 Initialize(); 348 Initialize();
349 349
350 int len = GetWrite(0)->length(); 350 int len = GetWrite(0)->length();
(...skipping 16 matching lines...) Expand all
367 } 367 }
368 368
369 TEST_F(QuicConnectionHelperTest, TimeoutAfterSend) { 369 TEST_F(QuicConnectionHelperTest, TimeoutAfterSend) {
370 AddWrite(SYNCHRONOUS, ConstructAckPacket(1)); 370 AddWrite(SYNCHRONOUS, ConstructAckPacket(1));
371 AddWrite(SYNCHRONOUS, ConstructClosePacket(2, 1)); 371 AddWrite(SYNCHRONOUS, ConstructClosePacket(2, 1));
372 Initialize(); 372 Initialize();
373 373
374 EXPECT_TRUE(connection_->connected()); 374 EXPECT_TRUE(connection_->connected());
375 QuicTime start = clock_.ApproximateNow(); 375 QuicTime start = clock_.ApproximateNow();
376 376
377 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. 377 // When we send a packet, the timeout will change to 5000 +
378 // kDefaultInitialTimeoutSecs.
378 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(5000)); 379 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(5000));
379 EXPECT_EQ(5000u, clock_.ApproximateNow().Subtract(start).ToMicroseconds()); 380 EXPECT_EQ(5000u, clock_.ApproximateNow().Subtract(start).ToMicroseconds());
380 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 381 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
381 382
382 // Send an ack so we don't set the retransmission alarm. 383 // Send an ack so we don't set the retransmission alarm.
383 connection_->SendAck(); 384 connection_->SendAck();
384 385
385 // The original alarm will fire. We should not time out because we had a 386 // The original alarm will fire. We should not time out because we had a
386 // network event at t=5000. The alarm will reregister. 387 // network event at t=5000. The alarm will reregister.
387 runner_->RunNextTask(); 388 runner_->RunNextTask();
388 389
389 EXPECT_EQ(QuicTime::Zero().Add( 390 EXPECT_EQ(QuicTime::Zero().Add(QuicTime::Delta::FromSeconds(
390 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)), 391 kDefaultInitialTimeoutSecs)),
391 clock_.ApproximateNow()); 392 clock_.ApproximateNow());
392 EXPECT_TRUE(connection_->connected()); 393 EXPECT_TRUE(connection_->connected());
393 394
394 // This time, we should time out. 395 // This time, we should time out.
395 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); 396 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, !kFromPeer));
396 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION)); 397 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, NOT_RETRANSMISSION));
397 runner_->RunNextTask(); 398 runner_->RunNextTask();
398 EXPECT_EQ(kDefaultTimeoutUs + 5000, clock_.ApproximateNow().Subtract( 399 EXPECT_EQ(kDefaultInitialTimeoutSecs * 1000000 + 5000,
399 QuicTime::Zero()).ToMicroseconds()); 400 clock_.ApproximateNow().Subtract(
401 QuicTime::Zero()).ToMicroseconds());
400 EXPECT_FALSE(connection_->connected()); 402 EXPECT_FALSE(connection_->connected());
401 EXPECT_TRUE(AtEof()); 403 EXPECT_TRUE(AtEof());
402 } 404 }
403 405
404 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { 406 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) {
405 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 407 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
406 Initialize(); 408 Initialize();
407 409
408 // Test that if we send a packet with a delay, it ends up queued. 410 // Test that if we send a packet with a delay, it ends up queued.
409 EXPECT_CALL( 411 EXPECT_CALL(
(...skipping 12 matching lines...) Expand all
422 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( 424 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly(
423 testing::Return(QuicTime::Delta::Zero())); 425 testing::Return(QuicTime::Delta::Zero()));
424 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 426 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true));
425 runner_->RunNextTask(); 427 runner_->RunNextTask();
426 EXPECT_EQ(0u, connection_->NumQueuedPackets()); 428 EXPECT_EQ(0u, connection_->NumQueuedPackets());
427 EXPECT_TRUE(AtEof()); 429 EXPECT_TRUE(AtEof());
428 } 430 }
429 431
430 } // namespace test 432 } // namespace test
431 } // namespace net 433 } // 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