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

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

Issue 20227003: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Land Recent QUIC changes Created 7 years, 4 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_logger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/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"
(...skipping 12 matching lines...) Expand all
23 namespace test { 23 namespace test {
24 24
25 const char kData[] = "foo"; 25 const char kData[] = "foo";
26 const bool kFromPeer = 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, QuicVersionMax()) {
34 } 34 }
35 35
36 void SendAck() { 36 void SendAck() {
37 QuicConnectionPeer::SendAck(this); 37 QuicConnectionPeer::SendAck(this);
38 } 38 }
39 39
40 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { 40 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) {
41 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); 41 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm);
42 } 42 }
43 43
44 using QuicConnection::SendOrQueuePacket; 44 using QuicConnection::SendOrQueuePacket;
45 }; 45 };
46 46
47 class QuicConnectionHelperTest : public ::testing::Test { 47 class QuicConnectionHelperTest : public ::testing::Test {
48 protected: 48 protected:
49 // Holds a packet to be written to the wire, and the IO mode that should 49 // Holds a packet to be written to the wire, and the IO mode that should
50 // be used by the mock socket when performing the write. 50 // be used by the mock socket when performing the write.
51 struct PacketToWrite { 51 struct PacketToWrite {
52 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet) 52 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet)
53 : mode(mode), 53 : mode(mode),
54 packet(packet) { 54 packet(packet) {
55 } 55 }
56 IoMode mode; 56 IoMode mode;
57 QuicEncryptedPacket* packet; 57 QuicEncryptedPacket* packet;
58 }; 58 };
59 59
60 QuicConnectionHelperTest() 60 QuicConnectionHelperTest()
61 : guid_(2), 61 : guid_(2),
62 framer_(kQuicVersion1, QuicTime::Zero(), false), 62 framer_(QuicVersionMax(), QuicTime::Zero(), false),
63 net_log_(BoundNetLog()), 63 net_log_(BoundNetLog()),
64 frame_(1, false, 0, kData) { 64 frame_(1, false, 0, kData) {
65 Initialize(); 65 Initialize();
66 } 66 }
67 67
68 ~QuicConnectionHelperTest() { 68 ~QuicConnectionHelperTest() {
69 for (size_t i = 0; i < writes_.size(); i++) { 69 for (size_t i = 0; i < writes_.size(); i++) {
70 delete writes_[i].packet; 70 delete writes_[i].packet;
71 } 71 }
72 } 72 }
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 297 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
298 runner_->RunNextTask(); 298 runner_->RunNextTask();
299 EXPECT_EQ(QuicTime::Zero().Add(delta2), clock_.ApproximateNow()); 299 EXPECT_EQ(QuicTime::Zero().Add(delta2), clock_.ApproximateNow());
300 } 300 }
301 301
302 TEST_F(QuicConnectionHelperTest, TestRetransmission) { 302 TEST_F(QuicConnectionHelperTest, TestRetransmission) {
303 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 303 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
304 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); 304 AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
305 Initialize(); 305 Initialize();
306 306
307 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
308 testing::Return(QuicTime::Delta::Zero()));
309
307 QuicTime::Delta kDefaultRetransmissionTime = 310 QuicTime::Delta kDefaultRetransmissionTime =
308 QuicTime::Delta::FromMilliseconds(500); 311 QuicTime::Delta::FromMilliseconds(500);
309 QuicTime start = clock_.ApproximateNow(); 312 QuicTime start = clock_.ApproximateNow();
310 313
311 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 314 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
312 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)); 315 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _));
313 // Send a packet. 316 // Send a packet.
314 connection_->SendStreamData(1, kData, 0, false); 317 connection_->SendStreamData(1, kData, 0, false);
315 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION)); 318 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION));
316 // Since no ack was received, the retransmission alarm will fire and 319 // Since no ack was received, the retransmission alarm will fire and
317 // retransmit it. 320 // retransmit it.
318 runner_->RunNextTask(); 321 runner_->RunNextTask();
319 322
320 EXPECT_EQ(kDefaultRetransmissionTime, 323 EXPECT_EQ(kDefaultRetransmissionTime,
321 clock_.ApproximateNow().Subtract(start)); 324 clock_.ApproximateNow().Subtract(start));
322 EXPECT_TRUE(AtEof()); 325 EXPECT_TRUE(AtEof());
323 } 326 }
324 327
325 TEST_F(QuicConnectionHelperTest, TestMultipleRetransmission) { 328 TEST_F(QuicConnectionHelperTest, TestMultipleRetransmission) {
326 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 329 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
327 AddWrite(SYNCHRONOUS, ConstructDataPacket(2)); 330 AddWrite(SYNCHRONOUS, ConstructDataPacket(2));
328 AddWrite(SYNCHRONOUS, ConstructDataPacket(3)); 331 AddWrite(SYNCHRONOUS, ConstructDataPacket(3));
329 Initialize(); 332 Initialize();
330 333
334 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
335 testing::Return(QuicTime::Delta::Zero()));
336
331 QuicTime::Delta kDefaultRetransmissionTime = 337 QuicTime::Delta kDefaultRetransmissionTime =
332 QuicTime::Delta::FromMilliseconds(500); 338 QuicTime::Delta::FromMilliseconds(500);
333 QuicTime start = clock_.ApproximateNow(); 339 QuicTime start = clock_.ApproximateNow();
334 340
335 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 341 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
336 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _)); 342 EXPECT_CALL(*send_algorithm_, AbandoningPacket(1, _));
337 // Send a packet. 343 // Send a packet.
338 connection_->SendStreamData(1, kData, 0, false); 344 connection_->SendStreamData(1, kData, 0, false);
339 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION)); 345 EXPECT_CALL(*send_algorithm_, SentPacket(_, 2, _, IS_RETRANSMISSION));
340 // Since no ack was received, the retransmission alarm will fire and 346 // Since no ack was received, the retransmission alarm will fire and
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 QuicTime::Zero()).ToMicroseconds()); 441 QuicTime::Zero()).ToMicroseconds());
436 EXPECT_FALSE(connection_->connected()); 442 EXPECT_FALSE(connection_->connected());
437 EXPECT_TRUE(AtEof()); 443 EXPECT_TRUE(AtEof());
438 } 444 }
439 445
440 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) { 446 TEST_F(QuicConnectionHelperTest, SendSchedulerDelayThenSend) {
441 AddWrite(SYNCHRONOUS, ConstructDataPacket(1)); 447 AddWrite(SYNCHRONOUS, ConstructDataPacket(1));
442 Initialize(); 448 Initialize();
443 449
444 // Test that if we send a packet with a delay, it ends up queued. 450 // Test that if we send a packet with a delay, it ends up queued.
451 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
452 testing::Return(QuicTime::Delta::Zero()));
445 EXPECT_CALL( 453 EXPECT_CALL(
446 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce( 454 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillOnce(
447 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 455 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
448 456
449 QuicPacket* packet = ConstructRawDataPacket(1); 457 QuicPacket* packet = ConstructRawDataPacket(1);
450 connection_->SendOrQueuePacket( 458 connection_->SendOrQueuePacket(
451 ENCRYPTION_NONE, 1, packet, 0, HAS_RETRANSMITTABLE_DATA); 459 ENCRYPTION_NONE, 1, packet, 0, HAS_RETRANSMITTABLE_DATA);
452 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION)); 460 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, NOT_RETRANSMISSION));
453 EXPECT_EQ(1u, connection_->NumQueuedPackets()); 461 EXPECT_EQ(1u, connection_->NumQueuedPackets());
454 462
455 // Advance the clock to fire the alarm, and configure the scheduler 463 // Advance the clock to fire the alarm, and configure the scheduler
456 // to permit the packet to be sent. 464 // to permit the packet to be sent.
457 EXPECT_CALL( 465 EXPECT_CALL(
458 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly( 466 *send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _)).WillRepeatedly(
459 testing::Return(QuicTime::Delta::Zero())); 467 testing::Return(QuicTime::Delta::Zero()));
460 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true)); 468 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(testing::Return(true));
461 runner_->RunNextTask(); 469 runner_->RunNextTask();
462 EXPECT_EQ(0u, connection_->NumQueuedPackets()); 470 EXPECT_EQ(0u, connection_->NumQueuedPackets());
463 EXPECT_TRUE(AtEof()); 471 EXPECT_TRUE(AtEof());
464 } 472 }
465 473
466 } // namespace test 474 } // namespace test
467 } // namespace net 475 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_connection_logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698