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

Side by Side Diff: net/quic/core/quic_connection_test.cc

Issue 2825083003: Landing Recent QUIC changes until Mon Apr 17 2017 (Closed)
Patch Set: Format Created 3 years, 8 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/quic/core/quic_connection.cc ('k') | net/quic/core/quic_constants.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/core/quic_connection.h" 5 #include "net/quic/core/quic_connection.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/quic/core/congestion_control/loss_detection_interface.h" 15 #include "net/quic/core/congestion_control/loss_detection_interface.h"
16 #include "net/quic/core/congestion_control/send_algorithm_interface.h" 16 #include "net/quic/core/congestion_control/send_algorithm_interface.h"
17 #include "net/quic/core/crypto/null_encrypter.h" 17 #include "net/quic/core/crypto/null_encrypter.h"
18 #include "net/quic/core/crypto/quic_decrypter.h" 18 #include "net/quic/core/crypto/quic_decrypter.h"
19 #include "net/quic/core/crypto/quic_encrypter.h" 19 #include "net/quic/core/crypto/quic_encrypter.h"
20 #include "net/quic/core/quic_flags.h"
21 #include "net/quic/core/quic_packets.h" 20 #include "net/quic/core/quic_packets.h"
22 #include "net/quic/core/quic_simple_buffer_allocator.h" 21 #include "net/quic/core/quic_simple_buffer_allocator.h"
23 #include "net/quic/core/quic_utils.h" 22 #include "net/quic/core/quic_utils.h"
23 #include "net/quic/platform/api/quic_flags.h"
24 #include "net/quic/platform/api/quic_logging.h" 24 #include "net/quic/platform/api/quic_logging.h"
25 #include "net/quic/platform/api/quic_reference_counted.h" 25 #include "net/quic/platform/api/quic_reference_counted.h"
26 #include "net/quic/platform/api/quic_str_cat.h" 26 #include "net/quic/platform/api/quic_str_cat.h"
27 #include "net/quic/test_tools/mock_clock.h" 27 #include "net/quic/test_tools/mock_clock.h"
28 #include "net/quic/test_tools/mock_random.h" 28 #include "net/quic/test_tools/mock_random.h"
29 #include "net/quic/test_tools/quic_config_peer.h" 29 #include "net/quic/test_tools/quic_config_peer.h"
30 #include "net/quic/test_tools/quic_connection_peer.h" 30 #include "net/quic/test_tools/quic_connection_peer.h"
31 #include "net/quic/test_tools/quic_framer_peer.h" 31 #include "net/quic/test_tools/quic_framer_peer.h"
32 #include "net/quic/test_tools/quic_packet_creator_peer.h" 32 #include "net/quic/test_tools/quic_packet_creator_peer.h"
33 #include "net/quic/test_tools/quic_packet_generator_peer.h" 33 #include "net/quic/test_tools/quic_packet_generator_peer.h"
(...skipping 18 matching lines...) Expand all
52 using testing::StrictMock; 52 using testing::StrictMock;
53 using testing::_; 53 using testing::_;
54 54
55 namespace net { 55 namespace net {
56 namespace test { 56 namespace test {
57 namespace { 57 namespace {
58 58
59 const char data1[] = "foo"; 59 const char data1[] = "foo";
60 const char data2[] = "bar"; 60 const char data2[] = "bar";
61 61
62 const bool kFin = true;
63 const bool kHasStopWaiting = true; 62 const bool kHasStopWaiting = true;
64 63
65 const int kDefaultRetransmissionTimeMs = 500; 64 const int kDefaultRetransmissionTimeMs = 500;
66 65
67 const QuicSocketAddress kPeerAddress = 66 const QuicSocketAddress kPeerAddress =
68 QuicSocketAddress(QuicIpAddress::Loopback6(), 67 QuicSocketAddress(QuicIpAddress::Loopback6(),
69 /*port=*/12345); 68 /*port=*/12345);
70 const QuicSocketAddress kSelfAddress = 69 const QuicSocketAddress kSelfAddress =
71 QuicSocketAddress(QuicIpAddress::Loopback6(), 70 QuicSocketAddress(QuicIpAddress::Loopback6(),
72 /*port=*/443); 71 /*port=*/443);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } 382 }
384 383
385 const std::vector<std::unique_ptr<QuicStreamFrame>>& stream_frames() const { 384 const std::vector<std::unique_ptr<QuicStreamFrame>>& stream_frames() const {
386 return framer_.stream_frames(); 385 return framer_.stream_frames();
387 } 386 }
388 387
389 const std::vector<QuicPingFrame>& ping_frames() const { 388 const std::vector<QuicPingFrame>& ping_frames() const {
390 return framer_.ping_frames(); 389 return framer_.ping_frames();
391 } 390 }
392 391
392 const std::vector<QuicPaddingFrame>& padding_frames() const {
393 return framer_.padding_frames();
394 }
395
393 size_t last_packet_size() { return last_packet_size_; } 396 size_t last_packet_size() { return last_packet_size_; }
394 397
395 const QuicVersionNegotiationPacket* version_negotiation_packet() { 398 const QuicVersionNegotiationPacket* version_negotiation_packet() {
396 return framer_.version_negotiation_packet(); 399 return framer_.version_negotiation_packet();
397 } 400 }
398 401
399 void set_is_write_blocked_data_buffered(bool buffered) { 402 void set_is_write_blocked_data_buffered(bool buffered) {
400 is_write_blocked_data_buffered_ = buffered; 403 is_write_blocked_data_buffered_ = buffered;
401 } 404 }
402 405
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 serialized_packet.retransmittable_frames.push_back( 507 serialized_packet.retransmittable_frames.push_back(
505 QuicFrame(new QuicStreamFrame())); 508 QuicFrame(new QuicStreamFrame()));
506 } 509 }
507 OnSerializedPacket(&serialized_packet); 510 OnSerializedPacket(&serialized_packet);
508 } 511 }
509 512
510 QuicConsumedData SendStreamDataWithString( 513 QuicConsumedData SendStreamDataWithString(
511 QuicStreamId id, 514 QuicStreamId id,
512 QuicStringPiece data, 515 QuicStringPiece data,
513 QuicStreamOffset offset, 516 QuicStreamOffset offset,
514 bool fin, 517 StreamSendingState state,
515 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { 518 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) {
516 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) { 519 if (id != kCryptoStreamId && this->encryption_level() == ENCRYPTION_NONE) {
517 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 520 this->SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
518 } 521 }
519 struct iovec iov; 522 struct iovec iov;
520 QuicIOVector data_iov(MakeIOVector(data, &iov)); 523 QuicIOVector data_iov(MakeIOVector(data, &iov));
521 return QuicConnection::SendStreamData(id, data_iov, offset, fin, 524 return QuicConnection::SendStreamData(id, data_iov, offset, state,
522 std::move(ack_listener)); 525 std::move(ack_listener));
523 } 526 }
524 527
525 QuicConsumedData SendStreamData3() { 528 QuicConsumedData SendStreamData3() {
526 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, !kFin, 529 return SendStreamDataWithString(kClientDataStreamId1, "food", 0, NO_FIN,
527 nullptr); 530 nullptr);
528 } 531 }
529 532
530 QuicConsumedData SendStreamData5() { 533 QuicConsumedData SendStreamData5() {
531 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, !kFin, 534 return SendStreamDataWithString(kClientDataStreamId2, "food2", 0, NO_FIN,
532 nullptr); 535 nullptr);
533 } 536 }
534 537
535 // Ensures the connection can write stream data before writing. 538 // Ensures the connection can write stream data before writing.
536 QuicConsumedData EnsureWritableAndSendStreamData5() { 539 QuicConsumedData EnsureWritableAndSendStreamData5() {
537 EXPECT_TRUE(CanWriteStreamData()); 540 EXPECT_TRUE(CanWriteStreamData());
538 return SendStreamData5(); 541 return SendStreamData5();
539 } 542 }
540 543
541 // The crypto stream has special semantics so that it is not blocked by a 544 // The crypto stream has special semantics so that it is not blocked by a
542 // congestion window limitation, and also so that it gets put into a separate 545 // congestion window limitation, and also so that it gets put into a separate
543 // packet (so that it is easier to reason about a crypto frame not being 546 // packet (so that it is easier to reason about a crypto frame not being
544 // split needlessly across packet boundaries). As a result, we have separate 547 // split needlessly across packet boundaries). As a result, we have separate
545 // tests for some cases for this stream. 548 // tests for some cases for this stream.
546 QuicConsumedData SendCryptoStreamData() { 549 QuicConsumedData SendCryptoStreamData() {
547 return SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, nullptr); 550 return SendStreamDataWithString(kCryptoStreamId, "chlo", 0, NO_FIN,
551 nullptr);
548 } 552 }
549 553
550 void set_version(QuicVersion version) { 554 void set_version(QuicVersion version) {
551 QuicConnectionPeer::GetFramer(this)->set_version(version); 555 QuicConnectionPeer::GetFramer(this)->set_version(version);
552 } 556 }
553 557
554 void SetSupportedVersions(const QuicVersionVector& versions) { 558 void SetSupportedVersions(const QuicVersionVector& versions) {
555 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); 559 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions);
556 writer()->SetSupportedVersions(versions); 560 writer()->SetSupportedVersions(versions);
557 } 561 }
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 size_t encrypted_length = peer_framer_.EncryptPayload( 882 size_t encrypted_length = peer_framer_.EncryptPayload(
879 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); 883 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize);
880 connection_.ProcessUdpPacket( 884 connection_.ProcessUdpPacket(
881 kSelfAddress, kPeerAddress, 885 kSelfAddress, kPeerAddress,
882 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); 886 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false));
883 } 887 }
884 888
885 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 889 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
886 QuicStringPiece data, 890 QuicStringPiece data,
887 QuicStreamOffset offset, 891 QuicStreamOffset offset,
888 bool fin, 892 StreamSendingState state,
889 QuicPacketNumber* last_packet) { 893 QuicPacketNumber* last_packet) {
890 QuicByteCount packet_size; 894 QuicByteCount packet_size;
891 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 895 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
892 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 896 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
893 connection_.SendStreamDataWithString(id, data, offset, fin, nullptr); 897 connection_.SendStreamDataWithString(id, data, offset, state, nullptr);
894 if (last_packet != nullptr) { 898 if (last_packet != nullptr) {
895 *last_packet = creator_->packet_number(); 899 *last_packet = creator_->packet_number();
896 } 900 }
897 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
898 .Times(AnyNumber()); 902 .Times(AnyNumber());
899 return packet_size; 903 return packet_size;
900 } 904 }
901 905
902 void SendAckPacketToPeer() { 906 void SendAckPacketToPeer() {
903 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 907 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1415 EXPECT_EQ(3u, writer_->packets_write_attempts());
1412 1416
1413 ProcessPacket(4); 1417 ProcessPacket(4);
1414 // Should not cause an ack. 1418 // Should not cause an ack.
1415 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1419 EXPECT_EQ(3u, writer_->packets_write_attempts());
1416 } 1420 }
1417 1421
1418 TEST_P(QuicConnectionTest, OutOfOrderAckReceiptCausesNoAck) { 1422 TEST_P(QuicConnectionTest, OutOfOrderAckReceiptCausesNoAck) {
1419 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1423 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1420 1424
1421 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1425 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1422 SendStreamDataToPeer(1, "bar", 3, !kFin, nullptr); 1426 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr);
1423 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1427 EXPECT_EQ(2u, writer_->packets_write_attempts());
1424 1428
1425 QuicAckFrame ack1 = InitAckFrame(1); 1429 QuicAckFrame ack1 = InitAckFrame(1);
1426 QuicAckFrame ack2 = InitAckFrame(2); 1430 QuicAckFrame ack2 = InitAckFrame(2);
1427 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1431 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1428 ProcessAckPacket(2, &ack2); 1432 ProcessAckPacket(2, &ack2);
1429 // Should ack immediately since we have missing packets. 1433 // Should ack immediately since we have missing packets.
1430 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1434 EXPECT_EQ(2u, writer_->packets_write_attempts());
1431 1435
1432 ProcessAckPacket(1, &ack1); 1436 ProcessAckPacket(1, &ack1);
1433 // Should not ack an ack filling a missing packet. 1437 // Should not ack an ack filling a missing packet.
1434 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1438 EXPECT_EQ(2u, writer_->packets_write_attempts());
1435 } 1439 }
1436 1440
1437 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { 1441 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) {
1438 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1442 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1439 QuicPacketNumber original; 1443 QuicPacketNumber original;
1440 QuicByteCount packet_size; 1444 QuicByteCount packet_size;
1441 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1442 .WillOnce( 1446 .WillOnce(
1443 DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true))); 1447 DoAll(SaveArg<2>(&original), SaveArg<3>(&packet_size), Return(true)));
1444 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 1448 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
1445 QuicAckFrame frame = InitAckFrame(original); 1449 QuicAckFrame frame = InitAckFrame(original);
1446 NackPacket(original, &frame); 1450 NackPacket(original, &frame);
1447 // First nack triggers early retransmit. 1451 // First nack triggers early retransmit.
1448 SendAlgorithmInterface::CongestionVector lost_packets; 1452 SendAlgorithmInterface::CongestionVector lost_packets;
1449 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 1453 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
1450 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 1454 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
1451 .WillOnce(SetArgPointee<4>(lost_packets)); 1455 .WillOnce(SetArgPointee<4>(lost_packets));
1452 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1456 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1453 QuicPacketNumber retransmission; 1457 QuicPacketNumber retransmission;
1454 EXPECT_CALL(*send_algorithm_, 1458 EXPECT_CALL(*send_algorithm_,
1455 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)) 1459 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _))
1456 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true))); 1460 .WillOnce(DoAll(SaveArg<2>(&retransmission), Return(true)));
1457 1461
1458 ProcessAckPacket(&frame); 1462 ProcessAckPacket(&frame);
1459 1463
1460 QuicAckFrame frame2 = InitAckFrame(retransmission); 1464 QuicAckFrame frame2 = InitAckFrame(retransmission);
1461 NackPacket(original, &frame2); 1465 NackPacket(original, &frame2);
1462 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1466 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1463 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 1467 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
1464 ProcessAckPacket(&frame2); 1468 ProcessAckPacket(&frame2);
1465 1469
1466 // Now if the peer sends an ack which still reports the retransmitted packet 1470 // Now if the peer sends an ack which still reports the retransmitted packet
1467 // as missing, that will bundle an ack with data after two acks in a row 1471 // as missing, that will bundle an ack with data after two acks in a row
1468 // indicate the high water mark needs to be raised. 1472 // indicate the high water mark needs to be raised.
1469 EXPECT_CALL(*send_algorithm_, 1473 EXPECT_CALL(*send_algorithm_,
1470 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)); 1474 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA));
1471 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1475 connection_.SendStreamDataWithString(3, "foo", 3, NO_FIN, nullptr);
1472 // No ack sent. 1476 // No ack sent.
1473 EXPECT_EQ(1u, writer_->frame_count()); 1477 EXPECT_EQ(1u, writer_->frame_count());
1474 EXPECT_EQ(1u, writer_->stream_frames().size()); 1478 EXPECT_EQ(1u, writer_->stream_frames().size());
1475 1479
1476 // No more packet loss for the rest of the test. 1480 // No more packet loss for the rest of the test.
1477 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)).Times(AnyNumber()); 1481 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)).Times(AnyNumber());
1478 ProcessAckPacket(&frame2); 1482 ProcessAckPacket(&frame2);
1479 EXPECT_CALL(*send_algorithm_, 1483 EXPECT_CALL(*send_algorithm_,
1480 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)); 1484 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA));
1481 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, nullptr); 1485 connection_.SendStreamDataWithString(3, "foo", 3, NO_FIN, nullptr);
1482 // Ack bundled. 1486 // Ack bundled.
1483 if (GetParam().no_stop_waiting) { 1487 if (GetParam().no_stop_waiting) {
1484 EXPECT_EQ(2u, writer_->frame_count()); 1488 EXPECT_EQ(2u, writer_->frame_count());
1485 } else { 1489 } else {
1486 EXPECT_EQ(3u, writer_->frame_count()); 1490 EXPECT_EQ(3u, writer_->frame_count());
1487 } 1491 }
1488 EXPECT_EQ(1u, writer_->stream_frames().size()); 1492 EXPECT_EQ(1u, writer_->stream_frames().size());
1489 EXPECT_FALSE(writer_->ack_frames().empty()); 1493 EXPECT_FALSE(writer_->ack_frames().empty());
1490 1494
1491 // But an ack with no missing packets will not send an ack. 1495 // But an ack with no missing packets will not send an ack.
1492 AckPacket(original, &frame2); 1496 AckPacket(original, &frame2);
1493 ProcessAckPacket(&frame2); 1497 ProcessAckPacket(&frame2);
1494 ProcessAckPacket(&frame2); 1498 ProcessAckPacket(&frame2);
1495 } 1499 }
1496 1500
1497 TEST_P(QuicConnectionTest, 20AcksCausesAckSend) { 1501 TEST_P(QuicConnectionTest, 20AcksCausesAckSend) {
1498 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1502 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1499 1503
1500 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1504 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1501 1505
1502 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 1506 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
1503 // But an ack with no missing packets will not send an ack. 1507 // But an ack with no missing packets will not send an ack.
1504 QuicAckFrame frame = InitAckFrame(1); 1508 QuicAckFrame frame = InitAckFrame(1);
1505 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1509 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1506 for (int i = 0; i < 19; ++i) { 1510 for (int i = 0; i < 19; ++i) {
1507 ProcessAckPacket(&frame); 1511 ProcessAckPacket(&frame);
1508 EXPECT_FALSE(ack_alarm->IsSet()); 1512 EXPECT_FALSE(ack_alarm->IsSet());
1509 } 1513 }
1510 EXPECT_EQ(1u, writer_->packets_write_attempts()); 1514 EXPECT_EQ(1u, writer_->packets_write_attempts());
1511 // The 20th ack packet will cause an ack to be sent. 1515 // The 20th ack packet will cause an ack to be sent.
1512 ProcessAckPacket(&frame); 1516 ProcessAckPacket(&frame);
1513 EXPECT_EQ(2u, writer_->packets_write_attempts()); 1517 EXPECT_EQ(2u, writer_->packets_write_attempts());
1514 } 1518 }
1515 1519
1516 TEST_P(QuicConnectionTest, LeastUnackedLower) { 1520 TEST_P(QuicConnectionTest, LeastUnackedLower) {
1517 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1521 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1518 1522
1519 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1523 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1520 SendStreamDataToPeer(1, "bar", 3, !kFin, nullptr); 1524 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr);
1521 SendStreamDataToPeer(1, "eep", 6, !kFin, nullptr); 1525 SendStreamDataToPeer(1, "eep", 6, NO_FIN, nullptr);
1522 1526
1523 // Start out saying the least unacked is 2. 1527 // Start out saying the least unacked is 2.
1524 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5); 1528 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 5);
1525 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); 1529 QuicStopWaitingFrame frame = InitStopWaitingFrame(2);
1526 ProcessStopWaitingPacket(&frame); 1530 ProcessStopWaitingPacket(&frame);
1527 1531
1528 // Change it to 1, but lower the packet number to fake out-of-order packets. 1532 // Change it to 1, but lower the packet number to fake out-of-order packets.
1529 // This should be fine. 1533 // This should be fine.
1530 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1); 1534 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1);
1531 // The scheduler will not process out of order acks, but all packet processing 1535 // The scheduler will not process out of order acks, but all packet processing
(...skipping 14 matching lines...) Expand all
1546 } 1550 }
1547 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1); 1551 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1);
1548 ProcessStopWaitingPacket(&frame3); 1552 ProcessStopWaitingPacket(&frame3);
1549 } 1553 }
1550 1554
1551 TEST_P(QuicConnectionTest, TooManySentPackets) { 1555 TEST_P(QuicConnectionTest, TooManySentPackets) {
1552 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1556 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1553 1557
1554 const int num_packets = kMaxTrackedPackets + 100; 1558 const int num_packets = kMaxTrackedPackets + 100;
1555 for (int i = 0; i < num_packets; ++i) { 1559 for (int i = 0; i < num_packets; ++i) {
1556 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); 1560 SendStreamDataToPeer(1, "foo", 3 * i, NO_FIN, nullptr);
1557 } 1561 }
1558 1562
1559 // Ack packet 1, which leaves more than the limit outstanding. 1563 // Ack packet 1, which leaves more than the limit outstanding.
1560 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1564 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1561 1565
1562 // Nack the first packet and ack the rest, leaving a huge gap. 1566 // Nack the first packet and ack the rest, leaving a huge gap.
1563 QuicAckFrame frame1 = InitAckFrame(num_packets); 1567 QuicAckFrame frame1 = InitAckFrame(num_packets);
1564 NackPacket(1, &frame1); 1568 NackPacket(1, &frame1);
1565 ProcessAckPacket(&frame1); 1569 ProcessAckPacket(&frame1);
1566 } 1570 }
1567 1571
1568 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { 1572 TEST_P(QuicConnectionTest, TooManyReceivedPackets) {
1569 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1573 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1570 // Miss 99 of every 100 packets for 5500 packets. 1574 // Miss 99 of every 100 packets for 5500 packets.
1571 for (QuicPacketNumber i = 1; i < kMaxTrackedPackets + 500; i += 100) { 1575 for (QuicPacketNumber i = 1; i < kMaxTrackedPackets + 500; i += 100) {
1572 ProcessPacket(i); 1576 ProcessPacket(i);
1573 if (!connection_.connected()) { 1577 if (!connection_.connected()) {
1574 break; 1578 break;
1575 } 1579 }
1576 } 1580 }
1577 } 1581 }
1578 1582
1579 TEST_P(QuicConnectionTest, LargestObservedLower) { 1583 TEST_P(QuicConnectionTest, LargestObservedLower) {
1580 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1584 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1581 1585
1582 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 1586 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
1583 SendStreamDataToPeer(1, "bar", 3, !kFin, nullptr); 1587 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr);
1584 SendStreamDataToPeer(1, "eep", 6, !kFin, nullptr); 1588 SendStreamDataToPeer(1, "eep", 6, NO_FIN, nullptr);
1585 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1589 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1586 1590
1587 // Start out saying the largest observed is 2. 1591 // Start out saying the largest observed is 2.
1588 QuicAckFrame frame1 = InitAckFrame(1); 1592 QuicAckFrame frame1 = InitAckFrame(1);
1589 QuicAckFrame frame2 = InitAckFrame(2); 1593 QuicAckFrame frame2 = InitAckFrame(2);
1590 ProcessAckPacket(&frame2); 1594 ProcessAckPacket(&frame2);
1591 1595
1592 // Now change it to 1, and it should cause a connection error. 1596 // Now change it to 1, and it should cause a connection error.
1593 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, _, 1597 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, _,
1594 ConnectionCloseSource::FROM_SELF)); 1598 ConnectionCloseSource::FROM_SELF));
(...skipping 17 matching lines...) Expand all
1612 ProcessPacket(1); 1616 ProcessPacket(1);
1613 1617
1614 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1); 1618 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 1);
1615 QuicAckFrame frame1 = InitAckFrame(0); 1619 QuicAckFrame frame1 = InitAckFrame(0);
1616 ProcessAckPacket(&frame1); 1620 ProcessAckPacket(&frame1);
1617 } 1621 }
1618 1622
1619 TEST_P(QuicConnectionTest, BasicSending) { 1623 TEST_P(QuicConnectionTest, BasicSending) {
1620 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1624 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1621 QuicPacketNumber last_packet; 1625 QuicPacketNumber last_packet;
1622 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1626 SendStreamDataToPeer(1, "foo", 0, NO_FIN, &last_packet); // Packet 1
1623 EXPECT_EQ(1u, last_packet); 1627 EXPECT_EQ(1u, last_packet);
1624 SendAckPacketToPeer(); // Packet 2 1628 SendAckPacketToPeer(); // Packet 2
1625 1629
1626 if (GetParam().no_stop_waiting) { 1630 if (GetParam().no_stop_waiting) {
1627 // Expect no stop waiting frame is sent. 1631 // Expect no stop waiting frame is sent.
1628 EXPECT_EQ(0u, least_unacked()); 1632 EXPECT_EQ(0u, least_unacked());
1629 } else { 1633 } else {
1630 EXPECT_EQ(1u, least_unacked()); 1634 EXPECT_EQ(1u, least_unacked());
1631 } 1635 }
1632 1636
1633 SendAckPacketToPeer(); // Packet 3 1637 SendAckPacketToPeer(); // Packet 3
1634 if (GetParam().no_stop_waiting) { 1638 if (GetParam().no_stop_waiting) {
1635 // Expect no stop waiting frame is sent. 1639 // Expect no stop waiting frame is sent.
1636 EXPECT_EQ(0u, least_unacked()); 1640 EXPECT_EQ(0u, least_unacked());
1637 } else { 1641 } else {
1638 EXPECT_EQ(1u, least_unacked()); 1642 EXPECT_EQ(1u, least_unacked());
1639 } 1643 }
1640 1644
1641 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); // Packet 4 1645 SendStreamDataToPeer(1, "bar", 3, NO_FIN, &last_packet); // Packet 4
1642 EXPECT_EQ(4u, last_packet); 1646 EXPECT_EQ(4u, last_packet);
1643 SendAckPacketToPeer(); // Packet 5 1647 SendAckPacketToPeer(); // Packet 5
1644 if (GetParam().no_stop_waiting) { 1648 if (GetParam().no_stop_waiting) {
1645 // Expect no stop waiting frame is sent. 1649 // Expect no stop waiting frame is sent.
1646 EXPECT_EQ(0u, least_unacked()); 1650 EXPECT_EQ(0u, least_unacked());
1647 } else { 1651 } else {
1648 EXPECT_EQ(1u, least_unacked()); 1652 EXPECT_EQ(1u, least_unacked());
1649 } 1653 }
1650 1654
1651 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1655 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 // If we force an ack, we shouldn't change our retransmit state. 1688 // If we force an ack, we shouldn't change our retransmit state.
1685 SendAckPacketToPeer(); // Packet 7 1689 SendAckPacketToPeer(); // Packet 7
1686 if (GetParam().no_stop_waiting) { 1690 if (GetParam().no_stop_waiting) {
1687 // Expect no stop waiting frame is sent. 1691 // Expect no stop waiting frame is sent.
1688 EXPECT_EQ(0u, least_unacked()); 1692 EXPECT_EQ(0u, least_unacked());
1689 } else { 1693 } else {
1690 EXPECT_EQ(7u, least_unacked()); 1694 EXPECT_EQ(7u, least_unacked());
1691 } 1695 }
1692 1696
1693 // But if we send more data it should. 1697 // But if we send more data it should.
1694 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 1698 SendStreamDataToPeer(1, "eep", 6, NO_FIN, &last_packet); // Packet 8
1695 EXPECT_EQ(8u, last_packet); 1699 EXPECT_EQ(8u, last_packet);
1696 SendAckPacketToPeer(); // Packet 9 1700 SendAckPacketToPeer(); // Packet 9
1697 if (GetParam().no_stop_waiting) { 1701 if (GetParam().no_stop_waiting) {
1698 // Expect no stop waiting frame is sent. 1702 // Expect no stop waiting frame is sent.
1699 EXPECT_EQ(0u, least_unacked()); 1703 EXPECT_EQ(0u, least_unacked());
1700 } else { 1704 } else {
1701 EXPECT_EQ(7u, least_unacked()); 1705 EXPECT_EQ(7u, least_unacked());
1702 } 1706 }
1703 } 1707 }
1704 1708
1705 // QuicConnection should record the the packet sent-time prior to sending the 1709 // QuicConnection should record the the packet sent-time prior to sending the
1706 // packet. 1710 // packet.
1707 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) { 1711 TEST_P(QuicConnectionTest, RecordSentTimeBeforePacketSent) {
1708 // We're using a MockClock for the tests, so we have complete control over the 1712 // We're using a MockClock for the tests, so we have complete control over the
1709 // time. 1713 // time.
1710 // Our recorded timestamp for the last packet sent time will be passed in to 1714 // Our recorded timestamp for the last packet sent time will be passed in to
1711 // the send_algorithm. Make sure that it is set to the correct value. 1715 // the send_algorithm. Make sure that it is set to the correct value.
1712 QuicTime actual_recorded_send_time = QuicTime::Zero(); 1716 QuicTime actual_recorded_send_time = QuicTime::Zero();
1713 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1717 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1714 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1718 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1715 1719
1716 // First send without any pause and check the result. 1720 // First send without any pause and check the result.
1717 QuicTime expected_recorded_send_time = clock_.Now(); 1721 QuicTime expected_recorded_send_time = clock_.Now();
1718 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 1722 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
1719 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1723 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1720 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1724 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1721 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); 1725 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1722 1726
1723 // Now pause during the write, and check the results. 1727 // Now pause during the write, and check the results.
1724 actual_recorded_send_time = QuicTime::Zero(); 1728 actual_recorded_send_time = QuicTime::Zero();
1725 const QuicTime::Delta write_pause_time_delta = 1729 const QuicTime::Delta write_pause_time_delta =
1726 QuicTime::Delta::FromMilliseconds(5000); 1730 QuicTime::Delta::FromMilliseconds(5000);
1727 SetWritePauseTimeDelta(write_pause_time_delta); 1731 SetWritePauseTimeDelta(write_pause_time_delta);
1728 expected_recorded_send_time = clock_.Now(); 1732 expected_recorded_send_time = clock_.Now();
1729 1733
1730 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 1734 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
1731 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); 1735 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true)));
1732 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); 1736 connection_.SendStreamDataWithString(2, "baz", 0, NO_FIN, nullptr);
1733 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) 1737 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time)
1734 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() 1738 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue()
1735 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); 1739 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue();
1736 } 1740 }
1737 1741
1738 TEST_P(QuicConnectionTest, FramePacking) { 1742 TEST_P(QuicConnectionTest, FramePacking) {
1739 // Send an ack and two stream frames in 1 packet by queueing them. 1743 // Send an ack and two stream frames in 1 packet by queueing them.
1740 { 1744 {
1741 QuicConnection::ScopedPacketBundler bundler(&connection_, 1745 QuicConnection::ScopedPacketBundler bundler(&connection_,
1742 QuicConnection::SEND_ACK); 1746 QuicConnection::SEND_ACK);
(...skipping 26 matching lines...) Expand all
1769 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1773 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1770 QuicConnection::ScopedPacketBundler bundler(&connection_, 1774 QuicConnection::ScopedPacketBundler bundler(&connection_,
1771 QuicConnection::SEND_ACK); 1775 QuicConnection::SEND_ACK);
1772 connection_.SendStreamData3(); 1776 connection_.SendStreamData3();
1773 connection_.SendCryptoStreamData(); 1777 connection_.SendCryptoStreamData();
1774 } 1778 }
1775 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1779 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1776 EXPECT_FALSE(connection_.HasQueuedData()); 1780 EXPECT_FALSE(connection_.HasQueuedData());
1777 1781
1778 // Parse the last packet and ensure it's the crypto stream frame. 1782 // Parse the last packet and ensure it's the crypto stream frame.
1779 EXPECT_EQ(1u, writer_->frame_count()); 1783 EXPECT_EQ(2u, writer_->frame_count());
1780 ASSERT_EQ(1u, writer_->stream_frames().size()); 1784 ASSERT_EQ(1u, writer_->stream_frames().size());
1785 ASSERT_EQ(1u, writer_->padding_frames().size());
1781 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0]->stream_id); 1786 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0]->stream_id);
1782 } 1787 }
1783 1788
1784 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { 1789 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) {
1785 // Send an ack and two stream frames (one crypto, then one non-crypto) in 2 1790 // Send an ack and two stream frames (one crypto, then one non-crypto) in 2
1786 // packets by queueing them. 1791 // packets by queueing them.
1787 { 1792 {
1788 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1793 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1789 QuicConnection::ScopedPacketBundler bundler(&connection_, 1794 QuicConnection::ScopedPacketBundler bundler(&connection_,
1790 QuicConnection::SEND_ACK); 1795 QuicConnection::SEND_ACK);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 // Send data in 1 packet by writing multiple blocks in a single iovector 1845 // Send data in 1 packet by writing multiple blocks in a single iovector
1841 // using writev. 1846 // using writev.
1842 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1847 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1843 1848
1844 char data[] = "ABCD"; 1849 char data[] = "ABCD";
1845 struct iovec iov[2]; 1850 struct iovec iov[2];
1846 iov[0].iov_base = data; 1851 iov[0].iov_base = data;
1847 iov[0].iov_len = 2; 1852 iov[0].iov_len = 2;
1848 iov[1].iov_base = data + 2; 1853 iov[1].iov_base = data + 2;
1849 iov[1].iov_len = 2; 1854 iov[1].iov_len = 2;
1850 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); 1855 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, NO_FIN, nullptr);
1851 1856
1852 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1857 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1853 EXPECT_FALSE(connection_.HasQueuedData()); 1858 EXPECT_FALSE(connection_.HasQueuedData());
1854 1859
1855 // Parse the last packet and ensure multiple iovector blocks have 1860 // Parse the last packet and ensure multiple iovector blocks have
1856 // been packed into a single stream frame from one stream. 1861 // been packed into a single stream frame from one stream.
1857 EXPECT_EQ(1u, writer_->frame_count()); 1862 EXPECT_EQ(2u, writer_->frame_count());
1858 EXPECT_EQ(1u, writer_->stream_frames().size()); 1863 EXPECT_EQ(1u, writer_->stream_frames().size());
1864 EXPECT_EQ(1u, writer_->padding_frames().size());
1859 QuicStreamFrame* frame = writer_->stream_frames()[0].get(); 1865 QuicStreamFrame* frame = writer_->stream_frames()[0].get();
1860 EXPECT_EQ(1u, frame->stream_id); 1866 EXPECT_EQ(1u, frame->stream_id);
1861 EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length)); 1867 EXPECT_EQ("ABCD", QuicStringPiece(frame->data_buffer, frame->data_length));
1862 } 1868 }
1863 1869
1864 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { 1870 TEST_P(QuicConnectionTest, FramePackingSendvQueued) {
1865 // Try to send two stream frames in 1 packet by using writev. 1871 // Try to send two stream frames in 1 packet by using writev.
1866 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1872 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1867 1873
1868 BlockOnNextWrite(); 1874 BlockOnNextWrite();
1869 char data[] = "ABCD"; 1875 char data[] = "ABCD";
1870 struct iovec iov[2]; 1876 struct iovec iov[2];
1871 iov[0].iov_base = data; 1877 iov[0].iov_base = data;
1872 iov[0].iov_len = 2; 1878 iov[0].iov_len = 2;
1873 iov[1].iov_base = data + 2; 1879 iov[1].iov_base = data + 2;
1874 iov[1].iov_len = 2; 1880 iov[1].iov_len = 2;
1875 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, !kFin, nullptr); 1881 connection_.SendStreamData(1, QuicIOVector(iov, 2, 4), 0, NO_FIN, nullptr);
1876 1882
1877 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 1883 EXPECT_EQ(1u, connection_.NumQueuedPackets());
1878 EXPECT_TRUE(connection_.HasQueuedData()); 1884 EXPECT_TRUE(connection_.HasQueuedData());
1879 1885
1880 // Unblock the writes and actually send. 1886 // Unblock the writes and actually send.
1881 writer_->SetWritable(); 1887 writer_->SetWritable();
1882 connection_.OnCanWrite(); 1888 connection_.OnCanWrite();
1883 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1889 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1884 1890
1885 // Parse the last packet and ensure it's one stream frame from one stream. 1891 // Parse the last packet and ensure it's one stream frame from one stream.
1886 EXPECT_EQ(1u, writer_->frame_count()); 1892 EXPECT_EQ(2u, writer_->frame_count());
1887 EXPECT_EQ(1u, writer_->stream_frames().size()); 1893 EXPECT_EQ(1u, writer_->stream_frames().size());
1894 EXPECT_EQ(1u, writer_->padding_frames().size());
1888 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id); 1895 EXPECT_EQ(1u, writer_->stream_frames()[0]->stream_id);
1889 } 1896 }
1890 1897
1891 TEST_P(QuicConnectionTest, SendingZeroBytes) { 1898 TEST_P(QuicConnectionTest, SendingZeroBytes) {
1892 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 1899 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
1893 // Send a zero byte write with a fin using writev. 1900 // Send a zero byte write with a fin using writev.
1894 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 1901 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
1895 QuicIOVector empty_iov(nullptr, 0, 0); 1902 QuicIOVector empty_iov(nullptr, 0, 0);
1896 connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, kFin, nullptr); 1903 connection_.SendStreamData(kHeadersStreamId, empty_iov, 0, FIN, nullptr);
1897 1904
1898 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1905 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1899 EXPECT_FALSE(connection_.HasQueuedData()); 1906 EXPECT_FALSE(connection_.HasQueuedData());
1900 1907
1901 // Parse the last packet and ensure it's one stream frame from one stream. 1908 // Parse the last packet and ensure it's one stream frame from one stream.
1902 EXPECT_EQ(1u, writer_->frame_count()); 1909 EXPECT_EQ(1u, writer_->frame_count());
1903 EXPECT_EQ(1u, writer_->stream_frames().size()); 1910 EXPECT_EQ(1u, writer_->stream_frames().size());
1904 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id); 1911 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id);
1905 EXPECT_TRUE(writer_->stream_frames()[0]->fin); 1912 EXPECT_TRUE(writer_->stream_frames()[0]->fin);
1906 } 1913 }
(...skipping 12 matching lines...) Expand all
1919 // Send data and ensure the ack is bundled. 1926 // Send data and ensure the ack is bundled.
1920 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(8); 1927 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(8);
1921 size_t len = 10000; 1928 size_t len = 10000;
1922 std::unique_ptr<char[]> data_array(new char[len]); 1929 std::unique_ptr<char[]> data_array(new char[len]);
1923 memset(data_array.get(), '?', len); 1930 memset(data_array.get(), '?', len);
1924 struct iovec iov; 1931 struct iovec iov;
1925 iov.iov_base = data_array.get(); 1932 iov.iov_base = data_array.get();
1926 iov.iov_len = len; 1933 iov.iov_len = len;
1927 QuicIOVector iovector(&iov, 1, len); 1934 QuicIOVector iovector(&iov, 1, len);
1928 QuicConsumedData consumed = 1935 QuicConsumedData consumed =
1929 connection_.SendStreamData(kHeadersStreamId, iovector, 0, true, nullptr); 1936 connection_.SendStreamData(kHeadersStreamId, iovector, 0, FIN, nullptr);
1930 EXPECT_EQ(len, consumed.bytes_consumed); 1937 EXPECT_EQ(len, consumed.bytes_consumed);
1931 EXPECT_TRUE(consumed.fin_consumed); 1938 EXPECT_TRUE(consumed.fin_consumed);
1932 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1939 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1933 EXPECT_FALSE(connection_.HasQueuedData()); 1940 EXPECT_FALSE(connection_.HasQueuedData());
1934 1941
1935 // Parse the last packet and ensure it's one stream frame with a fin. 1942 // Parse the last packet and ensure it's one stream frame with a fin.
1936 EXPECT_EQ(1u, writer_->frame_count()); 1943 EXPECT_EQ(1u, writer_->frame_count());
1937 EXPECT_EQ(1u, writer_->stream_frames().size()); 1944 EXPECT_EQ(1u, writer_->stream_frames().size());
1938 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id); 1945 EXPECT_EQ(kHeadersStreamId, writer_->stream_frames()[0]->stream_id);
1939 EXPECT_TRUE(writer_->stream_frames()[0]->fin); 1946 EXPECT_TRUE(writer_->stream_frames()[0]->fin);
(...skipping 24 matching lines...) Expand all
1964 // two different streams. 1971 // two different streams.
1965 EXPECT_EQ(2u, writer_->frame_count()); 1972 EXPECT_EQ(2u, writer_->frame_count());
1966 EXPECT_EQ(2u, writer_->stream_frames().size()); 1973 EXPECT_EQ(2u, writer_->stream_frames().size());
1967 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id); 1974 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0]->stream_id);
1968 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id); 1975 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1]->stream_id);
1969 } 1976 }
1970 1977
1971 TEST_P(QuicConnectionTest, RetransmitOnNack) { 1978 TEST_P(QuicConnectionTest, RetransmitOnNack) {
1972 QuicPacketNumber last_packet; 1979 QuicPacketNumber last_packet;
1973 QuicByteCount second_packet_size; 1980 QuicByteCount second_packet_size;
1974 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 1981 SendStreamDataToPeer(3, "foo", 0, NO_FIN, &last_packet); // Packet 1
1975 second_packet_size = 1982 second_packet_size =
1976 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 1983 SendStreamDataToPeer(3, "foos", 3, NO_FIN, &last_packet); // Packet 2
1977 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 1984 SendStreamDataToPeer(3, "fooos", 7, NO_FIN, &last_packet); // Packet 3
1978 1985
1979 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1986 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1980 1987
1981 // Don't lose a packet on an ack, and nothing is retransmitted. 1988 // Don't lose a packet on an ack, and nothing is retransmitted.
1982 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 1989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1983 QuicAckFrame ack_one = InitAckFrame(1); 1990 QuicAckFrame ack_one = InitAckFrame(1);
1984 ProcessAckPacket(&ack_one); 1991 ProcessAckPacket(&ack_one);
1985 1992
1986 // Lose a packet and ensure it triggers retransmission. 1993 // Lose a packet and ensure it triggers retransmission.
1987 QuicAckFrame nack_two = InitAckFrame(3); 1994 QuicAckFrame nack_two = InitAckFrame(3);
1988 NackPacket(2, &nack_two); 1995 NackPacket(2, &nack_two);
1989 SendAlgorithmInterface::CongestionVector lost_packets; 1996 SendAlgorithmInterface::CongestionVector lost_packets;
1990 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 1997 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
1991 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 1998 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
1992 .WillOnce(SetArgPointee<4>(lost_packets)); 1999 .WillOnce(SetArgPointee<4>(lost_packets));
1993 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2000 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
1994 EXPECT_CALL(*send_algorithm_, 2001 EXPECT_CALL(*send_algorithm_,
1995 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)) 2002 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _))
1996 .Times(1); 2003 .Times(1);
1997 ProcessAckPacket(&nack_two); 2004 ProcessAckPacket(&nack_two);
1998 } 2005 }
1999 2006
2000 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { 2007 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) {
2001 // Block the connection to queue the packet. 2008 // Block the connection to queue the packet.
2002 BlockOnNextWrite(); 2009 BlockOnNextWrite();
2003 2010
2004 QuicStreamId stream_id = 2; 2011 QuicStreamId stream_id = 2;
2005 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); 2012 connection_.SendStreamDataWithString(stream_id, "foo", 0, NO_FIN, nullptr);
2006 2013
2007 // Now that there is a queued packet, reset the stream. 2014 // Now that there is a queued packet, reset the stream.
2008 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2015 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2009 2016
2010 // Unblock the connection and verify that only the RST_STREAM is sent. 2017 // Unblock the connection and verify that only the RST_STREAM is sent.
2011 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2018 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2012 writer_->SetWritable(); 2019 writer_->SetWritable();
2013 connection_.OnCanWrite(); 2020 connection_.OnCanWrite();
2014 EXPECT_EQ(1u, writer_->frame_count()); 2021 EXPECT_EQ(1u, writer_->frame_count());
2015 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2022 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2016 } 2023 }
2017 2024
2018 TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) { 2025 TEST_P(QuicConnectionTest, SendQueuedPacketForQuicRstStreamNoError) {
2019 // Block the connection to queue the packet. 2026 // Block the connection to queue the packet.
2020 BlockOnNextWrite(); 2027 BlockOnNextWrite();
2021 2028
2022 QuicStreamId stream_id = 2; 2029 QuicStreamId stream_id = 2;
2023 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); 2030 connection_.SendStreamDataWithString(stream_id, "foo", 0, NO_FIN, nullptr);
2024 2031
2025 // Now that there is a queued packet, reset the stream. 2032 // Now that there is a queued packet, reset the stream.
2026 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2033 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2027 2034
2028 // Unblock the connection and verify that the RST_STREAM is sent and the data 2035 // Unblock the connection and verify that the RST_STREAM is sent and the data
2029 // packet is sent. 2036 // packet is sent.
2030 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2)); 2037 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2));
2031 writer_->SetWritable(); 2038 writer_->SetWritable();
2032 connection_.OnCanWrite(); 2039 connection_.OnCanWrite();
2033 EXPECT_EQ(1u, writer_->frame_count()); 2040 EXPECT_EQ(1u, writer_->frame_count());
2034 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2041 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2035 } 2042 }
2036 2043
2037 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) { 2044 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) {
2038 QuicStreamId stream_id = 2; 2045 QuicStreamId stream_id = 2;
2039 QuicPacketNumber last_packet; 2046 QuicPacketNumber last_packet;
2040 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2047 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2041 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2048 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2042 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2049 SendStreamDataToPeer(stream_id, "fooos", 7, NO_FIN, &last_packet);
2043 2050
2044 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2051 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2045 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2052 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2046 2053
2047 // Lose a packet and ensure it does not trigger retransmission. 2054 // Lose a packet and ensure it does not trigger retransmission.
2048 QuicAckFrame nack_two = InitAckFrame(last_packet); 2055 QuicAckFrame nack_two = InitAckFrame(last_packet);
2049 NackPacket(last_packet - 1, &nack_two); 2056 NackPacket(last_packet - 1, &nack_two);
2050 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2057 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2051 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 2058 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
2052 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2059 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2053 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2060 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2054 ProcessAckPacket(&nack_two); 2061 ProcessAckPacket(&nack_two);
2055 } 2062 }
2056 2063
2057 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) { 2064 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnNack) {
2058 QuicStreamId stream_id = 2; 2065 QuicStreamId stream_id = 2;
2059 QuicPacketNumber last_packet; 2066 QuicPacketNumber last_packet;
2060 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2067 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2061 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2068 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2062 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); 2069 SendStreamDataToPeer(stream_id, "fooos", 7, NO_FIN, &last_packet);
2063 2070
2064 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2071 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2065 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2072 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2066 2073
2067 // Lose a packet, ensure it triggers retransmission. 2074 // Lose a packet, ensure it triggers retransmission.
2068 QuicAckFrame nack_two = InitAckFrame(last_packet); 2075 QuicAckFrame nack_two = InitAckFrame(last_packet);
2069 NackPacket(last_packet - 1, &nack_two); 2076 NackPacket(last_packet - 1, &nack_two);
2070 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2077 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2071 SendAlgorithmInterface::CongestionVector lost_packets; 2078 SendAlgorithmInterface::CongestionVector lost_packets;
2072 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize)); 2079 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize));
2073 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2080 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2074 .WillOnce(SetArgPointee<4>(lost_packets)); 2081 .WillOnce(SetArgPointee<4>(lost_packets));
2075 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2082 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2076 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1)); 2083 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(1));
2077 ProcessAckPacket(&nack_two); 2084 ProcessAckPacket(&nack_two);
2078 } 2085 }
2079 2086
2080 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) { 2087 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) {
2081 QuicStreamId stream_id = 2; 2088 QuicStreamId stream_id = 2;
2082 QuicPacketNumber last_packet; 2089 QuicPacketNumber last_packet;
2083 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2090 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2084 2091
2085 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2092 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2086 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2093 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2087 2094
2088 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. 2095 // Fire the RTO and verify that the RST_STREAM is resent, not stream data.
2089 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2096 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2090 clock_.AdvanceTime(DefaultRetransmissionTime()); 2097 clock_.AdvanceTime(DefaultRetransmissionTime());
2091 connection_.GetRetransmissionAlarm()->Fire(); 2098 connection_.GetRetransmissionAlarm()->Fire();
2092 EXPECT_EQ(1u, writer_->frame_count()); 2099 EXPECT_EQ(1u, writer_->frame_count());
2093 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2100 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2094 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2101 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2095 } 2102 }
2096 2103
2097 // Ensure that if the only data in flight is non-retransmittable, the 2104 // Ensure that if the only data in flight is non-retransmittable, the
2098 // retransmission alarm is not set. 2105 // retransmission alarm is not set.
2099 TEST_P(QuicConnectionTest, CancelRetransmissionAlarmAfterResetStream) { 2106 TEST_P(QuicConnectionTest, CancelRetransmissionAlarmAfterResetStream) {
2100 QuicStreamId stream_id = 2; 2107 QuicStreamId stream_id = 2;
2101 QuicPacketNumber last_data_packet; 2108 QuicPacketNumber last_data_packet;
2102 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_data_packet); 2109 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_data_packet);
2103 2110
2104 // Cancel the stream. 2111 // Cancel the stream.
2105 const QuicPacketNumber rst_packet = last_data_packet + 1; 2112 const QuicPacketNumber rst_packet = last_data_packet + 1;
2106 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, rst_packet, _, _)).Times(1); 2113 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, rst_packet, _, _)).Times(1);
2107 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2114 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2108 2115
2109 // Ack the RST_STREAM frame (since it's retransmittable), but not the data 2116 // Ack the RST_STREAM frame (since it's retransmittable), but not the data
2110 // packet, which is no longer retransmittable since the stream was cancelled. 2117 // packet, which is no longer retransmittable since the stream was cancelled.
2111 QuicAckFrame nack_stream_data = InitAckFrame(rst_packet); 2118 QuicAckFrame nack_stream_data = InitAckFrame(rst_packet);
2112 NackPacket(last_data_packet, &nack_stream_data); 2119 NackPacket(last_data_packet, &nack_stream_data);
2113 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2120 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2114 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2121 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2115 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2122 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2116 ProcessAckPacket(&nack_stream_data); 2123 ProcessAckPacket(&nack_stream_data);
2117 2124
2118 // Ensure that the data is still in flight, but the retransmission alarm is no 2125 // Ensure that the data is still in flight, but the retransmission alarm is no
2119 // longer set. 2126 // longer set.
2120 EXPECT_GT(QuicSentPacketManagerPeer::GetBytesInFlight(manager_), 0u); 2127 EXPECT_GT(QuicSentPacketManagerPeer::GetBytesInFlight(manager_), 0u);
2121 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2128 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2122 } 2129 }
2123 2130
2124 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) { 2131 TEST_P(QuicConnectionTest, RetransmitForQuicRstStreamNoErrorOnRTO) {
2125 connection_.SetMaxTailLossProbes(0); 2132 connection_.SetMaxTailLossProbes(0);
2126 2133
2127 QuicStreamId stream_id = 2; 2134 QuicStreamId stream_id = 2;
2128 QuicPacketNumber last_packet; 2135 QuicPacketNumber last_packet;
2129 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2136 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2130 2137
2131 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2138 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2132 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2139 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2133 2140
2134 // Fire the RTO and verify that the RST_STREAM is resent, the stream data 2141 // Fire the RTO and verify that the RST_STREAM is resent, the stream data
2135 // is sent. 2142 // is sent.
2136 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2)); 2143 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2));
2137 clock_.AdvanceTime(DefaultRetransmissionTime()); 2144 clock_.AdvanceTime(DefaultRetransmissionTime());
2138 connection_.GetRetransmissionAlarm()->Fire(); 2145 connection_.GetRetransmissionAlarm()->Fire();
2139 EXPECT_EQ(1u, writer_->frame_count()); 2146 EXPECT_EQ(1u, writer_->frame_count());
2140 ASSERT_EQ(1u, writer_->rst_stream_frames().size()); 2147 ASSERT_EQ(1u, writer_->rst_stream_frames().size());
2141 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2148 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2142 } 2149 }
2143 2150
2144 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { 2151 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) {
2145 QuicStreamId stream_id = 2; 2152 QuicStreamId stream_id = 2;
2146 QuicPacketNumber last_packet; 2153 QuicPacketNumber last_packet;
2147 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2154 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2148 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2155 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2149 BlockOnNextWrite(); 2156 BlockOnNextWrite();
2150 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2157 connection_.SendStreamDataWithString(stream_id, "fooos", 7, NO_FIN, nullptr);
2151 2158
2152 // Lose a packet which will trigger a pending retransmission. 2159 // Lose a packet which will trigger a pending retransmission.
2153 QuicAckFrame ack = InitAckFrame(last_packet); 2160 QuicAckFrame ack = InitAckFrame(last_packet);
2154 NackPacket(last_packet - 1, &ack); 2161 NackPacket(last_packet - 1, &ack);
2155 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2156 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); 2163 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _));
2157 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2164 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2158 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2165 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2159 ProcessAckPacket(&ack); 2166 ProcessAckPacket(&ack);
2160 2167
2161 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14); 2168 connection_.SendRstStream(stream_id, QUIC_ERROR_PROCESSING_STREAM, 14);
2162 2169
2163 // Unblock the connection and verify that the RST_STREAM is sent but not the 2170 // Unblock the connection and verify that the RST_STREAM is sent but not the
2164 // second data packet nor a retransmit. 2171 // second data packet nor a retransmit.
2165 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2172 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2166 writer_->SetWritable(); 2173 writer_->SetWritable();
2167 connection_.OnCanWrite(); 2174 connection_.OnCanWrite();
2168 EXPECT_EQ(1u, writer_->frame_count()); 2175 EXPECT_EQ(1u, writer_->frame_count());
2169 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); 2176 EXPECT_EQ(1u, writer_->rst_stream_frames().size());
2170 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); 2177 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id);
2171 } 2178 }
2172 2179
2173 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) { 2180 TEST_P(QuicConnectionTest, SendPendingRetransmissionForQuicRstStreamNoError) {
2174 QuicStreamId stream_id = 2; 2181 QuicStreamId stream_id = 2;
2175 QuicPacketNumber last_packet; 2182 QuicPacketNumber last_packet;
2176 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); 2183 SendStreamDataToPeer(stream_id, "foo", 0, NO_FIN, &last_packet);
2177 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); 2184 SendStreamDataToPeer(stream_id, "foos", 3, NO_FIN, &last_packet);
2178 BlockOnNextWrite(); 2185 BlockOnNextWrite();
2179 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); 2186 connection_.SendStreamDataWithString(stream_id, "fooos", 7, NO_FIN, nullptr);
2180 2187
2181 // Lose a packet which will trigger a pending retransmission. 2188 // Lose a packet which will trigger a pending retransmission.
2182 QuicAckFrame ack = InitAckFrame(last_packet); 2189 QuicAckFrame ack = InitAckFrame(last_packet);
2183 NackPacket(last_packet - 1, &ack); 2190 NackPacket(last_packet - 1, &ack);
2184 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2191 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2185 SendAlgorithmInterface::CongestionVector lost_packets; 2192 SendAlgorithmInterface::CongestionVector lost_packets;
2186 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize)); 2193 lost_packets.push_back(std::make_pair(last_packet - 1, kMaxPacketSize));
2187 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2194 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2188 .WillOnce(SetArgPointee<4>(lost_packets)); 2195 .WillOnce(SetArgPointee<4>(lost_packets));
2189 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2196 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2190 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2197 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2191 ProcessAckPacket(&ack); 2198 ProcessAckPacket(&ack);
2192 2199
2193 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); 2200 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14);
2194 2201
2195 // Unblock the connection and verify that the RST_STREAM is sent and the 2202 // Unblock the connection and verify that the RST_STREAM is sent and the
2196 // second data packet or a retransmit is sent. 2203 // second data packet or a retransmit is sent.
2197 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2)); 2204 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AtLeast(2));
2198 writer_->SetWritable(); 2205 writer_->SetWritable();
2199 connection_.OnCanWrite(); 2206 connection_.OnCanWrite();
2200 EXPECT_EQ(1u, writer_->frame_count()); 2207 EXPECT_EQ(1u, writer_->frame_count());
2201 EXPECT_EQ(0u, writer_->rst_stream_frames().size()); 2208 EXPECT_EQ(0u, writer_->rst_stream_frames().size());
2202 } 2209 }
2203 2210
2204 TEST_P(QuicConnectionTest, RetransmitAckedPacket) { 2211 TEST_P(QuicConnectionTest, RetransmitAckedPacket) {
2205 QuicPacketNumber last_packet; 2212 QuicPacketNumber last_packet;
2206 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2213 SendStreamDataToPeer(1, "foo", 0, NO_FIN, &last_packet); // Packet 1
2207 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 2214 SendStreamDataToPeer(1, "foos", 3, NO_FIN, &last_packet); // Packet 2
2208 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 2215 SendStreamDataToPeer(1, "fooos", 7, NO_FIN, &last_packet); // Packet 3
2209 2216
2210 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2217 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2211 2218
2212 // Instigate a loss with an ack. 2219 // Instigate a loss with an ack.
2213 QuicAckFrame nack_two = InitAckFrame(3); 2220 QuicAckFrame nack_two = InitAckFrame(3);
2214 NackPacket(2, &nack_two); 2221 NackPacket(2, &nack_two);
2215 // The first nack should trigger a fast retransmission, but we'll be 2222 // The first nack should trigger a fast retransmission, but we'll be
2216 // write blocked, so the packet will be queued. 2223 // write blocked, so the packet will be queued.
2217 BlockOnNextWrite(); 2224 BlockOnNextWrite();
2218 2225
(...skipping 22 matching lines...) Expand all
2241 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 4)); 2248 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 4));
2242 } 2249 }
2243 2250
2244 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { 2251 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) {
2245 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2252 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2246 QuicPacketNumber largest_observed; 2253 QuicPacketNumber largest_observed;
2247 QuicByteCount packet_size; 2254 QuicByteCount packet_size;
2248 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2255 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2249 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size), 2256 .WillOnce(DoAll(SaveArg<2>(&largest_observed), SaveArg<3>(&packet_size),
2250 Return(true))); 2257 Return(true)));
2251 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2258 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
2252 2259
2253 QuicAckFrame frame = InitAckFrame(1); 2260 QuicAckFrame frame = InitAckFrame(1);
2254 NackPacket(largest_observed, &frame); 2261 NackPacket(largest_observed, &frame);
2255 // The first nack should retransmit the largest observed packet. 2262 // The first nack should retransmit the largest observed packet.
2256 SendAlgorithmInterface::CongestionVector lost_packets; 2263 SendAlgorithmInterface::CongestionVector lost_packets;
2257 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 2264 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
2258 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2265 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2259 .WillOnce(SetArgPointee<4>(lost_packets)); 2266 .WillOnce(SetArgPointee<4>(lost_packets));
2260 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2267 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2261 EXPECT_CALL(*send_algorithm_, 2268 EXPECT_CALL(*send_algorithm_,
2262 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); 2269 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _));
2263 ProcessAckPacket(&frame); 2270 ProcessAckPacket(&frame);
2264 } 2271 }
2265 2272
2266 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 2273 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) {
2267 connection_.SetMaxTailLossProbes(0); 2274 connection_.SetMaxTailLossProbes(0);
2268 2275
2269 for (int i = 0; i < 10; ++i) { 2276 for (int i = 0; i < 10; ++i) {
2270 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2277 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2271 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); 2278 connection_.SendStreamDataWithString(3, "foo", i * 3, NO_FIN, nullptr);
2272 } 2279 }
2273 2280
2274 // Block the writer and ensure they're queued. 2281 // Block the writer and ensure they're queued.
2275 BlockOnNextWrite(); 2282 BlockOnNextWrite();
2276 clock_.AdvanceTime(DefaultRetransmissionTime()); 2283 clock_.AdvanceTime(DefaultRetransmissionTime());
2277 // Only one packet should be retransmitted. 2284 // Only one packet should be retransmitted.
2278 connection_.GetRetransmissionAlarm()->Fire(); 2285 connection_.GetRetransmissionAlarm()->Fire();
2279 EXPECT_TRUE(connection_.HasQueuedData()); 2286 EXPECT_TRUE(connection_.HasQueuedData());
2280 2287
2281 // Unblock the writer. 2288 // Unblock the writer.
2282 writer_->SetWritable(); 2289 writer_->SetWritable();
2283 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2290 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2284 2 * DefaultRetransmissionTime().ToMicroseconds())); 2291 2 * DefaultRetransmissionTime().ToMicroseconds()));
2285 // Retransmit already retransmitted packets event though the packet number 2292 // Retransmit already retransmitted packets event though the packet number
2286 // greater than the largest observed. 2293 // greater than the largest observed.
2287 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2294 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2288 connection_.GetRetransmissionAlarm()->Fire(); 2295 connection_.GetRetransmissionAlarm()->Fire();
2289 connection_.OnCanWrite(); 2296 connection_.OnCanWrite();
2290 } 2297 }
2291 2298
2292 TEST_P(QuicConnectionTest, WriteBlockedBufferedThenSent) { 2299 TEST_P(QuicConnectionTest, WriteBlockedBufferedThenSent) {
2293 BlockOnNextWrite(); 2300 BlockOnNextWrite();
2294 writer_->set_is_write_blocked_data_buffered(true); 2301 writer_->set_is_write_blocked_data_buffered(true);
2295 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2302 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2296 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2303 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2297 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2304 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2298 2305
2299 writer_->SetWritable(); 2306 writer_->SetWritable();
2300 connection_.OnCanWrite(); 2307 connection_.OnCanWrite();
2301 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2308 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2302 } 2309 }
2303 2310
2304 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 2311 TEST_P(QuicConnectionTest, WriteBlockedThenSent) {
2305 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2312 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2306 BlockOnNextWrite(); 2313 BlockOnNextWrite();
2307 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2314 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2308 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2315 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2309 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2316 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2310 2317
2311 // The second packet should also be queued, in order to ensure packets are 2318 // The second packet should also be queued, in order to ensure packets are
2312 // never sent out of order. 2319 // never sent out of order.
2313 writer_->SetWritable(); 2320 writer_->SetWritable();
2314 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2321 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2315 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 2322 EXPECT_EQ(2u, connection_.NumQueuedPackets());
2316 2323
2317 // Now both are sent in order when we unblock. 2324 // Now both are sent in order when we unblock.
2318 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2325 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2319 connection_.OnCanWrite(); 2326 connection_.OnCanWrite();
2320 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2327 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2321 } 2328 }
2322 2329
2323 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { 2330 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
2324 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2331 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2325 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2332 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
2326 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2333 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2327 2334
2328 BlockOnNextWrite(); 2335 BlockOnNextWrite();
2329 writer_->set_is_write_blocked_data_buffered(true); 2336 writer_->set_is_write_blocked_data_buffered(true);
2330 // Simulate the retransmission alarm firing. 2337 // Simulate the retransmission alarm firing.
2331 clock_.AdvanceTime(DefaultRetransmissionTime()); 2338 clock_.AdvanceTime(DefaultRetransmissionTime());
2332 connection_.GetRetransmissionAlarm()->Fire(); 2339 connection_.GetRetransmissionAlarm()->Fire();
2333 2340
2334 // Ack the sent packet before the callback returns, which happens in 2341 // Ack the sent packet before the callback returns, which happens in
2335 // rare circumstances with write blocked sockets. 2342 // rare circumstances with write blocked sockets.
2336 QuicAckFrame ack = InitAckFrame(1); 2343 QuicAckFrame ack = InitAckFrame(1);
2337 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2344 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2338 ProcessAckPacket(&ack); 2345 ProcessAckPacket(&ack);
2339 2346
2340 writer_->SetWritable(); 2347 writer_->SetWritable();
2341 connection_.OnCanWrite(); 2348 connection_.OnCanWrite();
2342 // There is now a pending packet, but with no retransmittable frames. 2349 // There is now a pending packet, but with no retransmittable frames.
2343 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2350 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2344 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 2)); 2351 EXPECT_FALSE(QuicConnectionPeer::HasRetransmittableFrames(&connection_, 2));
2345 } 2352 }
2346 2353
2347 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { 2354 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) {
2348 // Block the connection. 2355 // Block the connection.
2349 BlockOnNextWrite(); 2356 BlockOnNextWrite();
2350 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2357 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
2351 EXPECT_EQ(1u, writer_->packets_write_attempts()); 2358 EXPECT_EQ(1u, writer_->packets_write_attempts());
2352 EXPECT_TRUE(writer_->IsWriteBlocked()); 2359 EXPECT_TRUE(writer_->IsWriteBlocked());
2353 2360
2354 // Set the send and resumption alarms. Fire the alarms and ensure they don't 2361 // Set the send and resumption alarms. Fire the alarms and ensure they don't
2355 // attempt to write. 2362 // attempt to write.
2356 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow()); 2363 connection_.GetResumeWritesAlarm()->Set(clock_.ApproximateNow());
2357 connection_.GetSendAlarm()->Set(clock_.ApproximateNow()); 2364 connection_.GetSendAlarm()->Set(clock_.ApproximateNow());
2358 connection_.GetResumeWritesAlarm()->Fire(); 2365 connection_.GetResumeWritesAlarm()->Fire();
2359 connection_.GetSendAlarm()->Fire(); 2366 connection_.GetSendAlarm()->Fire();
2360 EXPECT_TRUE(writer_->IsWriteBlocked()); 2367 EXPECT_TRUE(writer_->IsWriteBlocked());
2361 EXPECT_EQ(1u, writer_->packets_write_attempts()); 2368 EXPECT_EQ(1u, writer_->packets_write_attempts());
2362 } 2369 }
2363 2370
2364 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) { 2371 TEST_P(QuicConnectionTest, NoLimitPacketsPerNack) {
2365 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2372 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2366 int offset = 0; 2373 int offset = 0;
2367 // Send packets 1 to 15. 2374 // Send packets 1 to 15.
2368 for (int i = 0; i < 15; ++i) { 2375 for (int i = 0; i < 15; ++i) {
2369 SendStreamDataToPeer(1, "foo", offset, !kFin, nullptr); 2376 SendStreamDataToPeer(1, "foo", offset, NO_FIN, nullptr);
2370 offset += 3; 2377 offset += 3;
2371 } 2378 }
2372 2379
2373 // Ack 15, nack 1-14. 2380 // Ack 15, nack 1-14.
2374 2381
2375 QuicAckFrame nack = InitAckFrame(15); 2382 QuicAckFrame nack = InitAckFrame(15);
2376 for (int i = 1; i < 15; ++i) { 2383 for (int i = 1; i < 15; ++i) {
2377 NackPacket(i, &nack); 2384 NackPacket(i, &nack);
2378 } 2385 }
2379 2386
2380 // 14 packets have been NACK'd and lost. 2387 // 14 packets have been NACK'd and lost.
2381 SendAlgorithmInterface::CongestionVector lost_packets; 2388 SendAlgorithmInterface::CongestionVector lost_packets;
2382 for (int i = 1; i < 15; ++i) { 2389 for (int i = 1; i < 15; ++i) {
2383 lost_packets.push_back(std::make_pair(i, kMaxPacketSize)); 2390 lost_packets.push_back(std::make_pair(i, kMaxPacketSize));
2384 } 2391 }
2385 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 2392 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
2386 .WillOnce(SetArgPointee<4>(lost_packets)); 2393 .WillOnce(SetArgPointee<4>(lost_packets));
2387 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2394 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2388 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14); 2395 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(14);
2389 ProcessAckPacket(&nack); 2396 ProcessAckPacket(&nack);
2390 } 2397 }
2391 2398
2392 // Test sending multiple acks from the connection to the session. 2399 // Test sending multiple acks from the connection to the session.
2393 TEST_P(QuicConnectionTest, MultipleAcks) { 2400 TEST_P(QuicConnectionTest, MultipleAcks) {
2394 QuicPacketNumber last_packet; 2401 QuicPacketNumber last_packet;
2395 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2402 SendStreamDataToPeer(1, "foo", 0, NO_FIN, &last_packet); // Packet 1
2396 EXPECT_EQ(1u, last_packet); 2403 EXPECT_EQ(1u, last_packet);
2397 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 2404 SendStreamDataToPeer(3, "foo", 0, NO_FIN, &last_packet); // Packet 2
2398 EXPECT_EQ(2u, last_packet); 2405 EXPECT_EQ(2u, last_packet);
2399 SendAckPacketToPeer(); // Packet 3 2406 SendAckPacketToPeer(); // Packet 3
2400 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 2407 SendStreamDataToPeer(5, "foo", 0, NO_FIN, &last_packet); // Packet 4
2401 EXPECT_EQ(4u, last_packet); 2408 EXPECT_EQ(4u, last_packet);
2402 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 2409 SendStreamDataToPeer(1, "foo", 3, NO_FIN, &last_packet); // Packet 5
2403 EXPECT_EQ(5u, last_packet); 2410 EXPECT_EQ(5u, last_packet);
2404 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 2411 SendStreamDataToPeer(3, "foo", 3, NO_FIN, &last_packet); // Packet 6
2405 EXPECT_EQ(6u, last_packet); 2412 EXPECT_EQ(6u, last_packet);
2406 2413
2407 // Client will ack packets 1, 2, [!3], 4, 5. 2414 // Client will ack packets 1, 2, [!3], 4, 5.
2408 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2415 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2409 QuicAckFrame frame1 = InitAckFrame(5); 2416 QuicAckFrame frame1 = InitAckFrame(5);
2410 NackPacket(3, &frame1); 2417 NackPacket(3, &frame1);
2411 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2418 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2412 ProcessAckPacket(&frame1); 2419 ProcessAckPacket(&frame1);
2413 2420
2414 // Now the client implicitly acks 3, and explicitly acks 6. 2421 // Now the client implicitly acks 3, and explicitly acks 6.
2415 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2422 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2416 QuicAckFrame frame2 = InitAckFrame(6); 2423 QuicAckFrame frame2 = InitAckFrame(6);
2417 ProcessAckPacket(&frame2); 2424 ProcessAckPacket(&frame2);
2418 } 2425 }
2419 2426
2420 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { 2427 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) {
2421 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); // Packet 1; 2428 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr); // Packet 1;
2422 // From now on, we send acks, so the send algorithm won't mark them pending. 2429 // From now on, we send acks, so the send algorithm won't mark them pending.
2423 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2430 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2424 .WillByDefault(Return(false)); 2431 .WillByDefault(Return(false));
2425 SendAckPacketToPeer(); // Packet 2 2432 SendAckPacketToPeer(); // Packet 2
2426 2433
2427 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2434 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2428 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2435 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2429 QuicAckFrame frame = InitAckFrame(1); 2436 QuicAckFrame frame = InitAckFrame(1);
2430 ProcessAckPacket(&frame); 2437 ProcessAckPacket(&frame);
2431 2438
(...skipping 21 matching lines...) Expand all
2453 EXPECT_EQ(3u, least_unacked()); 2460 EXPECT_EQ(3u, least_unacked());
2454 } 2461 }
2455 2462
2456 // Ack the ack, which updates the rtt and raises the least unacked. 2463 // Ack the ack, which updates the rtt and raises the least unacked.
2457 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2464 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2458 frame = InitAckFrame(3); 2465 frame = InitAckFrame(3);
2459 ProcessAckPacket(&frame); 2466 ProcessAckPacket(&frame);
2460 2467
2461 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2468 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2462 .WillByDefault(Return(true)); 2469 .WillByDefault(Return(true));
2463 SendStreamDataToPeer(1, "bar", 3, false, nullptr); // Packet 4 2470 SendStreamDataToPeer(1, "bar", 3, NO_FIN, nullptr); // Packet 4
2464 EXPECT_EQ(4u, stop_waiting()->least_unacked); 2471 EXPECT_EQ(4u, stop_waiting()->least_unacked);
2465 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2472 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2466 .WillByDefault(Return(false)); 2473 .WillByDefault(Return(false));
2467 SendAckPacketToPeer(); // Packet 5 2474 SendAckPacketToPeer(); // Packet 5
2468 if (GetParam().no_stop_waiting) { 2475 if (GetParam().no_stop_waiting) {
2469 // Expect no stop waiting frame is sent. 2476 // Expect no stop waiting frame is sent.
2470 EXPECT_EQ(0u, least_unacked()); 2477 EXPECT_EQ(0u, least_unacked());
2471 } else { 2478 } else {
2472 EXPECT_EQ(4u, least_unacked()); 2479 EXPECT_EQ(4u, least_unacked());
2473 } 2480 }
2474 2481
2475 // Send two data packets at the end, and ensure if the last one is acked, 2482 // Send two data packets at the end, and ensure if the last one is acked,
2476 // the least unacked is raised above the ack packets. 2483 // the least unacked is raised above the ack packets.
2477 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2484 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2478 .WillByDefault(Return(true)); 2485 .WillByDefault(Return(true));
2479 SendStreamDataToPeer(1, "bar", 6, false, nullptr); // Packet 6 2486 SendStreamDataToPeer(1, "bar", 6, NO_FIN, nullptr); // Packet 6
2480 SendStreamDataToPeer(1, "bar", 9, false, nullptr); // Packet 7 2487 SendStreamDataToPeer(1, "bar", 9, NO_FIN, nullptr); // Packet 7
2481 2488
2482 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2489 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2483 frame = InitAckFrame(7); 2490 frame = InitAckFrame(7);
2484 NackPacket(5, &frame); 2491 NackPacket(5, &frame);
2485 NackPacket(6, &frame); 2492 NackPacket(6, &frame);
2486 ProcessAckPacket(&frame); 2493 ProcessAckPacket(&frame);
2487 2494
2488 EXPECT_EQ(6u, stop_waiting()->least_unacked); 2495 EXPECT_EQ(6u, stop_waiting()->least_unacked);
2489 } 2496 }
2490 2497
2491 TEST_P(QuicConnectionTest, TLP) { 2498 TEST_P(QuicConnectionTest, TLP) {
2492 connection_.SetMaxTailLossProbes(1); 2499 connection_.SetMaxTailLossProbes(1);
2493 2500
2494 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2501 SendStreamDataToPeer(3, "foo", 0, NO_FIN, nullptr);
2495 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2502 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2496 QuicTime retransmission_time = 2503 QuicTime retransmission_time =
2497 connection_.GetRetransmissionAlarm()->deadline(); 2504 connection_.GetRetransmissionAlarm()->deadline();
2498 EXPECT_NE(QuicTime::Zero(), retransmission_time); 2505 EXPECT_NE(QuicTime::Zero(), retransmission_time);
2499 2506
2500 EXPECT_EQ(1u, writer_->header().packet_number); 2507 EXPECT_EQ(1u, writer_->header().packet_number);
2501 // Simulate the retransmission alarm firing and sending a tlp, 2508 // Simulate the retransmission alarm firing and sending a tlp,
2502 // so send algorithm's OnRetransmissionTimeout is not called. 2509 // so send algorithm's OnRetransmissionTimeout is not called.
2503 clock_.AdvanceTime(retransmission_time - clock_.Now()); 2510 clock_.AdvanceTime(retransmission_time - clock_.Now());
2504 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2511 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2505 connection_.GetRetransmissionAlarm()->Fire(); 2512 connection_.GetRetransmissionAlarm()->Fire();
2506 EXPECT_EQ(2u, writer_->header().packet_number); 2513 EXPECT_EQ(2u, writer_->header().packet_number);
2507 // We do not raise the high water mark yet. 2514 // We do not raise the high water mark yet.
2508 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2515 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2509 } 2516 }
2510 2517
2511 TEST_P(QuicConnectionTest, RTO) { 2518 TEST_P(QuicConnectionTest, RTO) {
2512 connection_.SetMaxTailLossProbes(0); 2519 connection_.SetMaxTailLossProbes(0);
2513 2520
2514 QuicTime default_retransmission_time = 2521 QuicTime default_retransmission_time =
2515 clock_.ApproximateNow() + DefaultRetransmissionTime(); 2522 clock_.ApproximateNow() + DefaultRetransmissionTime();
2516 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2523 SendStreamDataToPeer(3, "foo", 0, NO_FIN, nullptr);
2517 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2524 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2518 2525
2519 EXPECT_EQ(1u, writer_->header().packet_number); 2526 EXPECT_EQ(1u, writer_->header().packet_number);
2520 EXPECT_EQ(default_retransmission_time, 2527 EXPECT_EQ(default_retransmission_time,
2521 connection_.GetRetransmissionAlarm()->deadline()); 2528 connection_.GetRetransmissionAlarm()->deadline());
2522 // Simulate the retransmission alarm firing. 2529 // Simulate the retransmission alarm firing.
2523 clock_.AdvanceTime(DefaultRetransmissionTime()); 2530 clock_.AdvanceTime(DefaultRetransmissionTime());
2524 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2531 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2525 connection_.GetRetransmissionAlarm()->Fire(); 2532 connection_.GetRetransmissionAlarm()->Fire();
2526 EXPECT_EQ(2u, writer_->header().packet_number); 2533 EXPECT_EQ(2u, writer_->header().packet_number);
2527 // We do not raise the high water mark yet. 2534 // We do not raise the high water mark yet.
2528 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2535 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2529 } 2536 }
2530 2537
2531 TEST_P(QuicConnectionTest, RetransmitWithSameEncryptionLevel) { 2538 TEST_P(QuicConnectionTest, RetransmitWithSameEncryptionLevel) {
2532 use_tagging_decrypter(); 2539 use_tagging_decrypter();
2533 2540
2534 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2541 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2535 // the end of the packet. We can test this to check which encrypter was used. 2542 // the end of the packet. We can test this to check which encrypter was used.
2536 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2543 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2537 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, !kFin, nullptr); 2544 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, NO_FIN, nullptr);
2538 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2545 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2539 2546
2540 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2547 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2541 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2548 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2542 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2549 SendStreamDataToPeer(3, "foo", 0, NO_FIN, nullptr);
2543 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2550 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2544 2551
2545 { 2552 {
2546 InSequence s; 2553 InSequence s;
2547 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _)); 2554 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _));
2548 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _)); 2555 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _));
2549 } 2556 }
2550 2557
2551 // Manually mark both packets for retransmission. 2558 // Manually mark both packets for retransmission.
2552 connection_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); 2559 connection_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION);
2553 2560
2554 // Packet should have been sent with ENCRYPTION_NONE. 2561 // Packet should have been sent with ENCRYPTION_NONE.
2555 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); 2562 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet());
2556 2563
2557 // Packet should have been sent with ENCRYPTION_INITIAL. 2564 // Packet should have been sent with ENCRYPTION_INITIAL.
2558 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2565 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2559 } 2566 }
2560 2567
2561 TEST_P(QuicConnectionTest, SendHandshakeMessages) { 2568 TEST_P(QuicConnectionTest, SendHandshakeMessages) {
2562 use_tagging_decrypter(); 2569 use_tagging_decrypter();
2563 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2570 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2564 // the end of the packet. We can test this to check which encrypter was used. 2571 // the end of the packet. We can test this to check which encrypter was used.
2565 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2572 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2566 2573
2567 // Attempt to send a handshake message and have the socket block. 2574 // Attempt to send a handshake message and have the socket block.
2568 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 2575 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2569 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2576 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2570 BlockOnNextWrite(); 2577 BlockOnNextWrite();
2571 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2578 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2572 // The packet should be serialized, but not queued. 2579 // The packet should be serialized, but not queued.
2573 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2580 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2574 2581
2575 // Switch to the new encrypter. 2582 // Switch to the new encrypter.
2576 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2583 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2577 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2584 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2578 2585
2579 // Now become writeable and flush the packets. 2586 // Now become writeable and flush the packets.
2580 writer_->SetWritable(); 2587 writer_->SetWritable();
2581 EXPECT_CALL(visitor_, OnCanWrite()); 2588 EXPECT_CALL(visitor_, OnCanWrite());
2582 connection_.OnCanWrite(); 2589 connection_.OnCanWrite();
2583 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2590 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2584 2591
2585 // Verify that the handshake packet went out at the null encryption. 2592 // Verify that the handshake packet went out at the null encryption.
2586 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2593 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2587 } 2594 }
2588 2595
2589 TEST_P(QuicConnectionTest, 2596 TEST_P(QuicConnectionTest,
2590 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 2597 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2591 use_tagging_decrypter(); 2598 use_tagging_decrypter();
2592 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2599 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2593 QuicPacketNumber packet_number; 2600 QuicPacketNumber packet_number;
2594 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, !kFin, &packet_number); 2601 SendStreamDataToPeer(kCryptoStreamId, "foo", 0, NO_FIN, &packet_number);
2595 2602
2596 // Simulate the retransmission alarm firing and the socket blocking. 2603 // Simulate the retransmission alarm firing and the socket blocking.
2597 BlockOnNextWrite(); 2604 BlockOnNextWrite();
2598 clock_.AdvanceTime(DefaultRetransmissionTime()); 2605 clock_.AdvanceTime(DefaultRetransmissionTime());
2599 connection_.GetRetransmissionAlarm()->Fire(); 2606 connection_.GetRetransmissionAlarm()->Fire();
2600 2607
2601 // Go forward secure. 2608 // Go forward secure.
2602 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2609 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2603 new TaggingEncrypter(0x02)); 2610 new TaggingEncrypter(0x02));
2604 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2611 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2605 connection_.NeuterUnencryptedPackets(); 2612 connection_.NeuterUnencryptedPackets();
2606 2613
2607 EXPECT_EQ(QuicTime::Zero(), connection_.GetRetransmissionAlarm()->deadline()); 2614 EXPECT_EQ(QuicTime::Zero(), connection_.GetRetransmissionAlarm()->deadline());
2608 // Unblock the socket and ensure that no packets are sent. 2615 // Unblock the socket and ensure that no packets are sent.
2609 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2616 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2610 writer_->SetWritable(); 2617 writer_->SetWritable();
2611 connection_.OnCanWrite(); 2618 connection_.OnCanWrite();
2612 } 2619 }
2613 2620
2614 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { 2621 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) {
2615 use_tagging_decrypter(); 2622 use_tagging_decrypter();
2616 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2623 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2617 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE); 2624 connection_.SetDefaultEncryptionLevel(ENCRYPTION_NONE);
2618 2625
2619 SendStreamDataToPeer(1, "foo", 0, !kFin, nullptr); 2626 SendStreamDataToPeer(1, "foo", 0, NO_FIN, nullptr);
2620 2627
2621 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2628 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2622 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2629 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2623 2630
2624 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); 2631 SendStreamDataToPeer(2, "bar", 0, NO_FIN, nullptr);
2625 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2632 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2626 2633
2627 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); 2634 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION);
2628 } 2635 }
2629 2636
2630 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { 2637 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) {
2631 // SetFromConfig is always called after construction from InitializeSession. 2638 // SetFromConfig is always called after construction from InitializeSession.
2632 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2639 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2633 QuicConfig config; 2640 QuicConfig config;
2634 connection_.SetFromConfig(config); 2641 connection_.SetFromConfig(config);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 ProcessDataPacketAtLevel(102, !kHasStopWaiting, ENCRYPTION_INITIAL); 2695 ProcessDataPacketAtLevel(102, !kHasStopWaiting, ENCRYPTION_INITIAL);
2689 } 2696 }
2690 2697
2691 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 2698 TEST_P(QuicConnectionTest, TestRetransmitOrder) {
2692 connection_.SetMaxTailLossProbes(0); 2699 connection_.SetMaxTailLossProbes(0);
2693 2700
2694 QuicByteCount first_packet_size; 2701 QuicByteCount first_packet_size;
2695 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2702 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2696 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); 2703 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2697 2704
2698 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2705 connection_.SendStreamDataWithString(3, "first_packet", 0, NO_FIN, nullptr);
2699 QuicByteCount second_packet_size; 2706 QuicByteCount second_packet_size;
2700 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2707 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2701 .WillOnce(DoAll(SaveArg<3>(&second_packet_size), Return(true))); 2708 .WillOnce(DoAll(SaveArg<3>(&second_packet_size), Return(true)));
2702 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); 2709 connection_.SendStreamDataWithString(3, "second_packet", 12, NO_FIN, nullptr);
2703 EXPECT_NE(first_packet_size, second_packet_size); 2710 EXPECT_NE(first_packet_size, second_packet_size);
2704 // Advance the clock by huge time to make sure packets will be retransmitted. 2711 // Advance the clock by huge time to make sure packets will be retransmitted.
2705 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2712 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2706 { 2713 {
2707 InSequence s; 2714 InSequence s;
2708 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _)); 2715 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _));
2709 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _)); 2716 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _));
2710 } 2717 }
2711 connection_.GetRetransmissionAlarm()->Fire(); 2718 connection_.GetRetransmissionAlarm()->Fire();
2712 2719
2713 // Advance again and expect the packets to be sent again in the same order. 2720 // Advance again and expect the packets to be sent again in the same order.
2714 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2721 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2715 { 2722 {
2716 InSequence s; 2723 InSequence s;
2717 EXPECT_CALL(visitor_, OnPathDegrading()); 2724 EXPECT_CALL(visitor_, OnPathDegrading());
2718 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _)); 2725 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, first_packet_size, _));
2719 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _)); 2726 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, second_packet_size, _));
2720 } 2727 }
2721 connection_.GetRetransmissionAlarm()->Fire(); 2728 connection_.GetRetransmissionAlarm()->Fire();
2722 } 2729 }
2723 2730
2724 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2731 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2725 BlockOnNextWrite(); 2732 BlockOnNextWrite();
2726 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2733 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2727 // Make sure that RTO is not started when the packet is queued. 2734 // Make sure that RTO is not started when the packet is queued.
2728 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2735 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2729 2736
2730 // Test that RTO is started once we write to the socket. 2737 // Test that RTO is started once we write to the socket.
2731 writer_->SetWritable(); 2738 writer_->SetWritable();
2732 connection_.OnCanWrite(); 2739 connection_.OnCanWrite();
2733 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2740 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2734 } 2741 }
2735 2742
2736 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { 2743 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) {
2737 connection_.SetMaxTailLossProbes(0); 2744 connection_.SetMaxTailLossProbes(0);
2738 2745
2739 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2746 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2740 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 2747 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2741 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, nullptr); 2748 connection_.SendStreamDataWithString(2, "foo", 0, NO_FIN, nullptr);
2742 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, nullptr); 2749 connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN, nullptr);
2743 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); 2750 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm();
2744 EXPECT_TRUE(retransmission_alarm->IsSet()); 2751 EXPECT_TRUE(retransmission_alarm->IsSet());
2745 EXPECT_EQ(clock_.Now() + DefaultRetransmissionTime(), 2752 EXPECT_EQ(clock_.Now() + DefaultRetransmissionTime(),
2746 retransmission_alarm->deadline()); 2753 retransmission_alarm->deadline());
2747 2754
2748 // Advance the time right before the RTO, then receive an ack for the first 2755 // Advance the time right before the RTO, then receive an ack for the first
2749 // packet to delay the RTO. 2756 // packet to delay the RTO.
2750 clock_.AdvanceTime(DefaultRetransmissionTime()); 2757 clock_.AdvanceTime(DefaultRetransmissionTime());
2751 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2758 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2752 QuicAckFrame ack = InitAckFrame(1); 2759 QuicAckFrame ack = InitAckFrame(1);
(...skipping 21 matching lines...) Expand all
2774 QuicTime expected_rto_time = 2781 QuicTime expected_rto_time =
2775 connection_.sent_packet_manager().GetRetransmissionTime(); 2782 connection_.sent_packet_manager().GetRetransmissionTime();
2776 EXPECT_EQ(next_rto_time, expected_rto_time); 2783 EXPECT_EQ(next_rto_time, expected_rto_time);
2777 } 2784 }
2778 2785
2779 TEST_P(QuicConnectionTest, TestQueued) { 2786 TEST_P(QuicConnectionTest, TestQueued) {
2780 connection_.SetMaxTailLossProbes(0); 2787 connection_.SetMaxTailLossProbes(0);
2781 2788
2782 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2789 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2783 BlockOnNextWrite(); 2790 BlockOnNextWrite();
2784 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2791 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
2785 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2792 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2786 2793
2787 // Unblock the writes and actually send. 2794 // Unblock the writes and actually send.
2788 writer_->SetWritable(); 2795 writer_->SetWritable();
2789 connection_.OnCanWrite(); 2796 connection_.OnCanWrite();
2790 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2797 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2791 } 2798 }
2792 2799
2793 TEST_P(QuicConnectionTest, InitialTimeout) { 2800 TEST_P(QuicConnectionTest, InitialTimeout) {
2794 EXPECT_TRUE(connection_.connected()); 2801 EXPECT_TRUE(connection_.connected());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 connection_.SetNetworkTimeouts(timeout, timeout); 2835 connection_.SetNetworkTimeouts(timeout, timeout);
2829 EXPECT_TRUE(connection_.connected()); 2836 EXPECT_TRUE(connection_.connected());
2830 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 2837 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
2831 2838
2832 QuicTime handshake_timeout = 2839 QuicTime handshake_timeout =
2833 clock_.ApproximateNow() + timeout - QuicTime::Delta::FromSeconds(1); 2840 clock_.ApproximateNow() + timeout - QuicTime::Delta::FromSeconds(1);
2834 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline()); 2841 EXPECT_EQ(handshake_timeout, connection_.GetTimeoutAlarm()->deadline());
2835 EXPECT_TRUE(connection_.connected()); 2842 EXPECT_TRUE(connection_.connected());
2836 2843
2837 // Send and ack new data 3 seconds later to lengthen the idle timeout. 2844 // Send and ack new data 3 seconds later to lengthen the idle timeout.
2838 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2845 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, FIN, nullptr);
2839 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3)); 2846 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(3));
2840 QuicAckFrame frame = InitAckFrame(1); 2847 QuicAckFrame frame = InitAckFrame(1);
2841 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2848 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2842 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2849 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2843 ProcessAckPacket(&frame); 2850 ProcessAckPacket(&frame);
2844 2851
2845 // Fire early to verify it wouldn't timeout yet. 2852 // Fire early to verify it wouldn't timeout yet.
2846 connection_.GetTimeoutAlarm()->Fire(); 2853 connection_.GetTimeoutAlarm()->Fire();
2847 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 2854 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
2848 EXPECT_TRUE(connection_.connected()); 2855 EXPECT_TRUE(connection_.connected());
(...skipping 17 matching lines...) Expand all
2866 2873
2867 TEST_P(QuicConnectionTest, PingAfterSend) { 2874 TEST_P(QuicConnectionTest, PingAfterSend) {
2868 EXPECT_TRUE(connection_.connected()); 2875 EXPECT_TRUE(connection_.connected());
2869 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); 2876 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true));
2870 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2877 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2871 2878
2872 // Advance to 5ms, and send a packet to the peer, which will set 2879 // Advance to 5ms, and send a packet to the peer, which will set
2873 // the ping alarm. 2880 // the ping alarm.
2874 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2881 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2875 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2882 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2876 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2883 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, FIN, nullptr);
2877 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); 2884 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2878 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15), 2885 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(15),
2879 connection_.GetPingAlarm()->deadline()); 2886 connection_.GetPingAlarm()->deadline());
2880 2887
2881 // Now recevie and ACK of the previous packet, which will move the 2888 // Now recevie and ACK of the previous packet, which will move the
2882 // ping alarm forward. 2889 // ping alarm forward.
2883 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2890 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2884 QuicAckFrame frame = InitAckFrame(1); 2891 QuicAckFrame frame = InitAckFrame(1);
2885 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2892 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2886 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2893 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
(...skipping 24 matching lines...) Expand all
2911 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true)); 2918 EXPECT_CALL(visitor_, HasOpenDynamicStreams()).WillRepeatedly(Return(true));
2912 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2919 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2913 2920
2914 // Use a reduced ping timeout for this connection. 2921 // Use a reduced ping timeout for this connection.
2915 connection_.set_ping_timeout(QuicTime::Delta::FromSeconds(10)); 2922 connection_.set_ping_timeout(QuicTime::Delta::FromSeconds(10));
2916 2923
2917 // Advance to 5ms, and send a packet to the peer, which will set 2924 // Advance to 5ms, and send a packet to the peer, which will set
2918 // the ping alarm. 2925 // the ping alarm.
2919 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2926 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2920 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2927 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2921 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, kFin, nullptr); 2928 SendStreamDataToPeer(kHeadersStreamId, "GET /", 0, FIN, nullptr);
2922 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet()); 2929 EXPECT_TRUE(connection_.GetPingAlarm()->IsSet());
2923 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(10), 2930 EXPECT_EQ(clock_.ApproximateNow() + QuicTime::Delta::FromSeconds(10),
2924 connection_.GetPingAlarm()->deadline()); 2931 connection_.GetPingAlarm()->deadline());
2925 2932
2926 // Now recevie and ACK of the previous packet, which will move the 2933 // Now recevie and ACK of the previous packet, which will move the
2927 // ping alarm forward. 2934 // ping alarm forward.
2928 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); 2935 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5));
2929 QuicAckFrame frame = InitAckFrame(1); 2936 QuicAckFrame frame = InitAckFrame(1);
2930 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2937 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2931 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2938 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 EXPECT_EQ(new_mtu, mtu_probe_size); 2972 EXPECT_EQ(new_mtu, mtu_probe_size);
2966 EXPECT_EQ(1u, creator_->packet_number()); 2973 EXPECT_EQ(1u, creator_->packet_number());
2967 2974
2968 // Send more than MTU worth of data. No acknowledgement was received so far, 2975 // Send more than MTU worth of data. No acknowledgement was received so far,
2969 // so the MTU should be at its old value. 2976 // so the MTU should be at its old value.
2970 const string data(kDefaultMaxPacketSize + 1, '.'); 2977 const string data(kDefaultMaxPacketSize + 1, '.');
2971 QuicByteCount size_before_mtu_change; 2978 QuicByteCount size_before_mtu_change;
2972 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 2979 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2973 .WillOnce(DoAll(SaveArg<3>(&size_before_mtu_change), Return(true))) 2980 .WillOnce(DoAll(SaveArg<3>(&size_before_mtu_change), Return(true)))
2974 .WillOnce(Return(true)); 2981 .WillOnce(Return(true));
2975 connection_.SendStreamDataWithString(3, data, 0, kFin, nullptr); 2982 connection_.SendStreamDataWithString(3, data, 0, FIN, nullptr);
2976 EXPECT_EQ(3u, creator_->packet_number()); 2983 EXPECT_EQ(3u, creator_->packet_number());
2977 EXPECT_EQ(kDefaultMaxPacketSize, size_before_mtu_change); 2984 EXPECT_EQ(kDefaultMaxPacketSize, size_before_mtu_change);
2978 2985
2979 // Acknowledge all packets so far. 2986 // Acknowledge all packets so far.
2980 QuicAckFrame probe_ack = InitAckFrame(3); 2987 QuicAckFrame probe_ack = InitAckFrame(3);
2981 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2988 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2982 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 2989 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
2983 ProcessAckPacket(&probe_ack); 2990 ProcessAckPacket(&probe_ack);
2984 EXPECT_EQ(new_mtu, connection_.max_packet_length()); 2991 EXPECT_EQ(new_mtu, connection_.max_packet_length());
2985 2992
2986 // Send the same data again. Check that it fits into a single packet now. 2993 // Send the same data again. Check that it fits into a single packet now.
2987 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2994 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2988 connection_.SendStreamDataWithString(3, data, 0, kFin, nullptr); 2995 connection_.SendStreamDataWithString(3, data, 0, FIN, nullptr);
2989 EXPECT_EQ(4u, creator_->packet_number()); 2996 EXPECT_EQ(4u, creator_->packet_number());
2990 } 2997 }
2991 2998
2992 // Tests whether MTU discovery does not happen when it is not explicitly enabled 2999 // Tests whether MTU discovery does not happen when it is not explicitly enabled
2993 // by the connection options. 3000 // by the connection options.
2994 TEST_P(QuicConnectionTest, MtuDiscoveryDisabled) { 3001 TEST_P(QuicConnectionTest, MtuDiscoveryDisabled) {
2995 EXPECT_TRUE(connection_.connected()); 3002 EXPECT_TRUE(connection_.connected());
2996 3003
2997 const QuicPacketCount number_of_packets = kPacketsBetweenMtuProbesBase * 2; 3004 const QuicPacketCount number_of_packets = kPacketsBetweenMtuProbesBase * 2;
2998 for (QuicPacketCount i = 0; i < number_of_packets; i++) { 3005 for (QuicPacketCount i = 0; i < number_of_packets; i++) {
2999 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3006 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3000 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3007 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3001 EXPECT_EQ(0u, connection_.mtu_probe_count()); 3008 EXPECT_EQ(0u, connection_.mtu_probe_count());
3002 } 3009 }
3003 } 3010 }
3004 3011
3005 // Tests whether MTU discovery works when the probe gets acknowledged on the 3012 // Tests whether MTU discovery works when the probe gets acknowledged on the
3006 // first try. 3013 // first try.
3007 TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) { 3014 TEST_P(QuicConnectionTest, MtuDiscoveryEnabled) {
3008 EXPECT_TRUE(connection_.connected()); 3015 EXPECT_TRUE(connection_.connected());
3009 3016
3010 connection_.EnablePathMtuDiscovery(send_algorithm_); 3017 connection_.EnablePathMtuDiscovery(send_algorithm_);
3011 3018
3012 // Send enough packets so that the next one triggers path MTU discovery. 3019 // Send enough packets so that the next one triggers path MTU discovery.
3013 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3020 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3014 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3021 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3015 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3022 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3016 } 3023 }
3017 3024
3018 // Trigger the probe. 3025 // Trigger the probe.
3019 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3026 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3020 /*fin=*/false, nullptr);
3021 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3027 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3022 QuicByteCount probe_size; 3028 QuicByteCount probe_size;
3023 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 3029 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
3024 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true))); 3030 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true)));
3025 connection_.GetMtuDiscoveryAlarm()->Fire(); 3031 connection_.GetMtuDiscoveryAlarm()->Fire();
3026 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, probe_size); 3032 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, probe_size);
3027 3033
3028 const QuicPacketCount probe_packet_number = kPacketsBetweenMtuProbesBase + 1; 3034 const QuicPacketCount probe_packet_number = kPacketsBetweenMtuProbesBase + 1;
3029 ASSERT_EQ(probe_packet_number, creator_->packet_number()); 3035 ASSERT_EQ(probe_packet_number, creator_->packet_number());
3030 3036
3031 // Acknowledge all packets sent so far. 3037 // Acknowledge all packets sent so far.
3032 QuicAckFrame probe_ack = InitAckFrame(probe_packet_number); 3038 QuicAckFrame probe_ack = InitAckFrame(probe_packet_number);
3033 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3039 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3034 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3040 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3035 ProcessAckPacket(&probe_ack); 3041 ProcessAckPacket(&probe_ack);
3036 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, connection_.max_packet_length()); 3042 EXPECT_EQ(kMtuDiscoveryTargetPacketSizeHigh, connection_.max_packet_length());
3037 EXPECT_EQ(0u, connection_.GetBytesInFlight()); 3043 EXPECT_EQ(0u, connection_.GetBytesInFlight());
3038 3044
3039 // Send more packets, and ensure that none of them sets the alarm. 3045 // Send more packets, and ensure that none of them sets the alarm.
3040 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) { 3046 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) {
3041 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3047 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3042 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3048 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3043 } 3049 }
3044 3050
3045 EXPECT_EQ(1u, connection_.mtu_probe_count()); 3051 EXPECT_EQ(1u, connection_.mtu_probe_count());
3046 } 3052 }
3047 3053
3048 // Tests whether MTU discovery works correctly when the probes never get 3054 // Tests whether MTU discovery works correctly when the probes never get
3049 // acknowledged. 3055 // acknowledged.
3050 TEST_P(QuicConnectionTest, MtuDiscoveryFailed) { 3056 TEST_P(QuicConnectionTest, MtuDiscoveryFailed) {
3051 EXPECT_TRUE(connection_.connected()); 3057 EXPECT_TRUE(connection_.connected());
(...skipping 17 matching lines...) Expand all
3069 // get caught as well. 3075 // get caught as well.
3070 const QuicPacketCount number_of_packets = 3076 const QuicPacketCount number_of_packets =
3071 packets_between_probes_base * (1 << (kMtuDiscoveryAttempts + 1)); 3077 packets_between_probes_base * (1 << (kMtuDiscoveryAttempts + 1));
3072 std::vector<QuicPacketNumber> mtu_discovery_packets; 3078 std::vector<QuicPacketNumber> mtu_discovery_packets;
3073 // Called by the first ack. 3079 // Called by the first ack.
3074 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3080 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3075 // Called on many acks. 3081 // Called on many acks.
3076 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)) 3082 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _))
3077 .Times(AnyNumber()); 3083 .Times(AnyNumber());
3078 for (QuicPacketCount i = 0; i < number_of_packets; i++) { 3084 for (QuicPacketCount i = 0; i < number_of_packets; i++) {
3079 SendStreamDataToPeer(3, "!", i, /*fin=*/false, nullptr); 3085 SendStreamDataToPeer(3, "!", i, NO_FIN, nullptr);
3080 clock_.AdvanceTime(rtt); 3086 clock_.AdvanceTime(rtt);
3081 3087
3082 // Receive an ACK, which marks all data packets as received, and all MTU 3088 // Receive an ACK, which marks all data packets as received, and all MTU
3083 // discovery packets as missing. 3089 // discovery packets as missing.
3084 QuicAckFrame ack = InitAckFrame(creator_->packet_number()); 3090 QuicAckFrame ack = InitAckFrame(creator_->packet_number());
3085 for (QuicPacketNumber& packet : mtu_discovery_packets) { 3091 for (QuicPacketNumber& packet : mtu_discovery_packets) {
3086 NackPacket(packet, &ack); 3092 NackPacket(packet, &ack);
3087 } 3093 }
3088 ProcessAckPacket(&ack); 3094 ProcessAckPacket(&ack);
3089 3095
(...skipping 30 matching lines...) Expand all
3120 // packet can be. 3126 // packet can be.
3121 TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { 3127 TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) {
3122 EXPECT_TRUE(connection_.connected()); 3128 EXPECT_TRUE(connection_.connected());
3123 3129
3124 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; 3130 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1;
3125 writer_->set_max_packet_size(mtu_limit); 3131 writer_->set_max_packet_size(mtu_limit);
3126 connection_.EnablePathMtuDiscovery(send_algorithm_); 3132 connection_.EnablePathMtuDiscovery(send_algorithm_);
3127 3133
3128 // Send enough packets so that the next one triggers path MTU discovery. 3134 // Send enough packets so that the next one triggers path MTU discovery.
3129 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3135 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3130 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3136 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3131 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3137 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3132 } 3138 }
3133 3139
3134 // Trigger the probe. 3140 // Trigger the probe.
3135 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3141 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3136 /*fin=*/false, nullptr);
3137 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3142 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3138 QuicByteCount probe_size; 3143 QuicByteCount probe_size;
3139 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 3144 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
3140 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true))); 3145 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true)));
3141 connection_.GetMtuDiscoveryAlarm()->Fire(); 3146 connection_.GetMtuDiscoveryAlarm()->Fire();
3142 EXPECT_EQ(mtu_limit, probe_size); 3147 EXPECT_EQ(mtu_limit, probe_size);
3143 3148
3144 const QuicPacketCount probe_sequence_number = 3149 const QuicPacketCount probe_sequence_number =
3145 kPacketsBetweenMtuProbesBase + 1; 3150 kPacketsBetweenMtuProbesBase + 1;
3146 ASSERT_EQ(probe_sequence_number, creator_->packet_number()); 3151 ASSERT_EQ(probe_sequence_number, creator_->packet_number());
3147 3152
3148 // Acknowledge all packets sent so far. 3153 // Acknowledge all packets sent so far.
3149 QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number); 3154 QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number);
3150 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3155 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3151 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3156 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3152 ProcessAckPacket(&probe_ack); 3157 ProcessAckPacket(&probe_ack);
3153 EXPECT_EQ(mtu_limit, connection_.max_packet_length()); 3158 EXPECT_EQ(mtu_limit, connection_.max_packet_length());
3154 EXPECT_EQ(0u, connection_.GetBytesInFlight()); 3159 EXPECT_EQ(0u, connection_.GetBytesInFlight());
3155 3160
3156 // Send more packets, and ensure that none of them sets the alarm. 3161 // Send more packets, and ensure that none of them sets the alarm.
3157 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) { 3162 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) {
3158 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3163 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3159 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3164 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3160 } 3165 }
3161 3166
3162 EXPECT_EQ(1u, connection_.mtu_probe_count()); 3167 EXPECT_EQ(1u, connection_.mtu_probe_count());
3163 } 3168 }
3164 3169
3165 // Tests whether MTU discovery works when the writer returns an error despite 3170 // Tests whether MTU discovery works when the writer returns an error despite
3166 // advertising higher packet length. 3171 // advertising higher packet length.
3167 TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) { 3172 TEST_P(QuicConnectionTest, MtuDiscoveryWriterFailed) {
3168 EXPECT_TRUE(connection_.connected()); 3173 EXPECT_TRUE(connection_.connected());
3169 3174
3170 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; 3175 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1;
3171 const QuicByteCount initial_mtu = connection_.max_packet_length(); 3176 const QuicByteCount initial_mtu = connection_.max_packet_length();
3172 EXPECT_LT(initial_mtu, mtu_limit); 3177 EXPECT_LT(initial_mtu, mtu_limit);
3173 writer_->set_max_packet_size(mtu_limit); 3178 writer_->set_max_packet_size(mtu_limit);
3174 connection_.EnablePathMtuDiscovery(send_algorithm_); 3179 connection_.EnablePathMtuDiscovery(send_algorithm_);
3175 3180
3176 // Send enough packets so that the next one triggers path MTU discovery. 3181 // Send enough packets so that the next one triggers path MTU discovery.
3177 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3182 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3178 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3183 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3179 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3184 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3180 } 3185 }
3181 3186
3182 // Trigger the probe. 3187 // Trigger the probe.
3183 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3188 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3184 /*fin=*/false, nullptr);
3185 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3189 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3186 writer_->SimulateNextPacketTooLarge(); 3190 writer_->SimulateNextPacketTooLarge();
3187 connection_.GetMtuDiscoveryAlarm()->Fire(); 3191 connection_.GetMtuDiscoveryAlarm()->Fire();
3188 ASSERT_TRUE(connection_.connected()); 3192 ASSERT_TRUE(connection_.connected());
3189 3193
3190 // Send more data. 3194 // Send more data.
3191 QuicPacketNumber probe_number = creator_->packet_number(); 3195 QuicPacketNumber probe_number = creator_->packet_number();
3192 QuicPacketCount extra_packets = kPacketsBetweenMtuProbesBase * 3; 3196 QuicPacketCount extra_packets = kPacketsBetweenMtuProbesBase * 3;
3193 for (QuicPacketCount i = 0; i < extra_packets; i++) { 3197 for (QuicPacketCount i = 0; i < extra_packets; i++) {
3194 connection_.EnsureWritableAndSendStreamData5(); 3198 connection_.EnsureWritableAndSendStreamData5();
(...skipping 18 matching lines...) Expand all
3213 EXPECT_EQ(1u, connection_.mtu_probe_count()); 3217 EXPECT_EQ(1u, connection_.mtu_probe_count());
3214 } 3218 }
3215 3219
3216 TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) { 3220 TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) {
3217 EXPECT_TRUE(connection_.connected()); 3221 EXPECT_TRUE(connection_.connected());
3218 3222
3219 connection_.EnablePathMtuDiscovery(send_algorithm_); 3223 connection_.EnablePathMtuDiscovery(send_algorithm_);
3220 3224
3221 // Send enough packets so that the next one triggers path MTU discovery. 3225 // Send enough packets so that the next one triggers path MTU discovery.
3222 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { 3226 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) {
3223 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); 3227 SendStreamDataToPeer(3, ".", i, NO_FIN, nullptr);
3224 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3228 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3225 } 3229 }
3226 3230
3227 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, 3231 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, NO_FIN, nullptr);
3228 /*fin=*/false, nullptr);
3229 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3232 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3230 3233
3231 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)); 3234 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _));
3232 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason", 3235 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason",
3233 ConnectionCloseBehavior::SILENT_CLOSE); 3236 ConnectionCloseBehavior::SILENT_CLOSE);
3234 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); 3237 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet());
3235 } 3238 }
3236 3239
3237 TEST_P(QuicConnectionTest, TimeoutAfterSend) { 3240 TEST_P(QuicConnectionTest, TimeoutAfterSend) {
3238 EXPECT_TRUE(connection_.connected()); 3241 EXPECT_TRUE(connection_.connected());
3239 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3242 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3240 QuicConfig config; 3243 QuicConfig config;
3241 connection_.SetFromConfig(config); 3244 connection_.SetFromConfig(config);
3242 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3245 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3243 3246
3244 const QuicTime::Delta initial_idle_timeout = 3247 const QuicTime::Delta initial_idle_timeout =
3245 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3248 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3246 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3249 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3247 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; 3250 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3248 3251
3249 // When we send a packet, the timeout will change to 5ms + 3252 // When we send a packet, the timeout will change to 5ms +
3250 // kInitialIdleTimeoutSecs. 3253 // kInitialIdleTimeoutSecs.
3251 clock_.AdvanceTime(five_ms); 3254 clock_.AdvanceTime(five_ms);
3252 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3255 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3253 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3256 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3254 3257
3255 // Now send more data. This will not move the timeout becase 3258 // Now send more data. This will not move the timeout becase
3256 // no data has been recieved since the previous write. 3259 // no data has been recieved since the previous write.
3257 clock_.AdvanceTime(five_ms); 3260 clock_.AdvanceTime(five_ms);
3258 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3261 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3259 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3262 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3260 3263
3261 // The original alarm will fire. We should not time out because we had a 3264 // The original alarm will fire. We should not time out because we had a
3262 // network event at t=5ms. The alarm will reregister. 3265 // network event at t=5ms. The alarm will reregister.
3263 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms); 3266 clock_.AdvanceTime(initial_idle_timeout - five_ms - five_ms);
3264 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3267 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3265 connection_.GetTimeoutAlarm()->Fire(); 3268 connection_.GetTimeoutAlarm()->Fire();
3266 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3269 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3267 EXPECT_TRUE(connection_.connected()); 3270 EXPECT_TRUE(connection_.connected());
3268 EXPECT_EQ(default_timeout + five_ms, 3271 EXPECT_EQ(default_timeout + five_ms,
(...skipping 28 matching lines...) Expand all
3297 start_time + DefaultRetransmissionTime(); 3300 start_time + DefaultRetransmissionTime();
3298 3301
3299 ASSERT_LT(default_retransmission_time, default_timeout); 3302 ASSERT_LT(default_retransmission_time, default_timeout);
3300 3303
3301 // When we send a packet, the timeout will change to 5 ms + 3304 // When we send a packet, the timeout will change to 5 ms +
3302 // kInitialIdleTimeoutSecs (but it will not reschedule the alarm). 3305 // kInitialIdleTimeoutSecs (but it will not reschedule the alarm).
3303 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3306 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3304 const QuicTime send_time = start_time + five_ms; 3307 const QuicTime send_time = start_time + five_ms;
3305 clock_.AdvanceTime(five_ms); 3308 clock_.AdvanceTime(five_ms);
3306 ASSERT_EQ(send_time, clock_.Now()); 3309 ASSERT_EQ(send_time, clock_.Now());
3307 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3310 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3308 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3311 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3309 3312
3310 // Move forward 5 ms and receive a packet, which will move the timeout 3313 // Move forward 5 ms and receive a packet, which will move the timeout
3311 // forward 5 ms more (but will not reschedule the alarm). 3314 // forward 5 ms more (but will not reschedule the alarm).
3312 const QuicTime receive_time = send_time + five_ms; 3315 const QuicTime receive_time = send_time + five_ms;
3313 clock_.AdvanceTime(receive_time - clock_.Now()); 3316 clock_.AdvanceTime(receive_time - clock_.Now());
3314 ASSERT_EQ(receive_time, clock_.Now()); 3317 ASSERT_EQ(receive_time, clock_.Now());
3315 ProcessPacket(1); 3318 ProcessPacket(1);
3316 3319
3317 // Now move forward to the retransmission time and retransmit the 3320 // Now move forward to the retransmission time and retransmit the
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
3379 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3382 EXPECT_TRUE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3380 3383
3381 const QuicTime::Delta default_idle_timeout = 3384 const QuicTime::Delta default_idle_timeout =
3382 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1); 3385 QuicTime::Delta::FromSeconds(kDefaultIdleTimeoutSecs - 1);
3383 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3386 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3384 QuicTime default_timeout = clock_.ApproximateNow() + default_idle_timeout; 3387 QuicTime default_timeout = clock_.ApproximateNow() + default_idle_timeout;
3385 3388
3386 // When we send a packet, the timeout will change to 5ms + 3389 // When we send a packet, the timeout will change to 5ms +
3387 // kInitialIdleTimeoutSecs. 3390 // kInitialIdleTimeoutSecs.
3388 clock_.AdvanceTime(five_ms); 3391 clock_.AdvanceTime(five_ms);
3389 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3392 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3390 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3393 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3391 3394
3392 // Now send more data. This will not move the timeout becase 3395 // Now send more data. This will not move the timeout becase
3393 // no data has been recieved since the previous write. 3396 // no data has been recieved since the previous write.
3394 clock_.AdvanceTime(five_ms); 3397 clock_.AdvanceTime(five_ms);
3395 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3398 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3396 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3399 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3397 3400
3398 // The original alarm will fire. We should not time out because we had a 3401 // The original alarm will fire. We should not time out because we had a
3399 // network event at t=5ms. The alarm will reregister. 3402 // network event at t=5ms. The alarm will reregister.
3400 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms); 3403 clock_.AdvanceTime(default_idle_timeout - five_ms - five_ms);
3401 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3404 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3402 connection_.GetTimeoutAlarm()->Fire(); 3405 connection_.GetTimeoutAlarm()->Fire();
3403 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3406 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3404 EXPECT_TRUE(connection_.connected()); 3407 EXPECT_TRUE(connection_.connected());
3405 EXPECT_EQ(default_timeout + five_ms, 3408 EXPECT_EQ(default_timeout + five_ms,
(...skipping 15 matching lines...) Expand all
3421 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3424 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3422 QuicConfig config; 3425 QuicConfig config;
3423 connection_.SetFromConfig(config); 3426 connection_.SetFromConfig(config);
3424 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); 3427 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_));
3425 3428
3426 const QuicTime::Delta initial_idle_timeout = 3429 const QuicTime::Delta initial_idle_timeout =
3427 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3430 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3428 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3431 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3429 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; 3432 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3430 3433
3431 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3434 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
3432 nullptr); 3435 nullptr);
3433 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 3436 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, NO_FIN,
3434 nullptr); 3437 nullptr);
3435 3438
3436 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3439 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3437 clock_.AdvanceTime(five_ms); 3440 clock_.AdvanceTime(five_ms);
3438 3441
3439 // When we receive a packet, the timeout will change to 5ms + 3442 // When we receive a packet, the timeout will change to 5ms +
3440 // kInitialIdleTimeoutSecs. 3443 // kInitialIdleTimeoutSecs.
3441 QuicAckFrame ack = InitAckFrame(2); 3444 QuicAckFrame ack = InitAckFrame(2);
3442 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3445 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3443 ProcessAckPacket(&ack); 3446 ProcessAckPacket(&ack);
(...skipping 29 matching lines...) Expand all
3473 3476
3474 const QuicTime::Delta initial_idle_timeout = 3477 const QuicTime::Delta initial_idle_timeout =
3475 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); 3478 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1);
3476 connection_.SetNetworkTimeouts( 3479 connection_.SetNetworkTimeouts(
3477 QuicTime::Delta::Infinite(), 3480 QuicTime::Delta::Infinite(),
3478 initial_idle_timeout + QuicTime::Delta::FromSeconds(1)); 3481 initial_idle_timeout + QuicTime::Delta::FromSeconds(1));
3479 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); 3482 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5);
3480 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; 3483 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout;
3481 3484
3482 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3485 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3483 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3486 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
3484 nullptr); 3487 nullptr);
3485 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3488 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3486 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 3489 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, NO_FIN,
3487 nullptr); 3490 nullptr);
3488 3491
3489 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 3492 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
3490 3493
3491 clock_.AdvanceTime(five_ms); 3494 clock_.AdvanceTime(five_ms);
3492 3495
3493 // When we receive a packet, the timeout will change to 5ms + 3496 // When we receive a packet, the timeout will change to 5ms +
3494 // kInitialIdleTimeoutSecs. 3497 // kInitialIdleTimeoutSecs.
3495 QuicAckFrame ack = InitAckFrame(2); 3498 QuicAckFrame ack = InitAckFrame(2);
3496 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 3499 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
3497 ProcessAckPacket(&ack); 3500 ProcessAckPacket(&ack);
3498 3501
3499 // The original alarm will fire. We should not time out because we had a 3502 // The original alarm will fire. We should not time out because we had a
3500 // network event at t=5ms. The alarm will reregister. 3503 // network event at t=5ms. The alarm will reregister.
3501 clock_.AdvanceTime(initial_idle_timeout - five_ms); 3504 clock_.AdvanceTime(initial_idle_timeout - five_ms);
3502 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); 3505 EXPECT_EQ(default_timeout, clock_.ApproximateNow());
3503 connection_.GetTimeoutAlarm()->Fire(); 3506 connection_.GetTimeoutAlarm()->Fire();
3504 EXPECT_TRUE(connection_.connected()); 3507 EXPECT_TRUE(connection_.connected());
3505 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3508 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3506 EXPECT_EQ(default_timeout + five_ms, 3509 EXPECT_EQ(default_timeout + five_ms,
3507 connection_.GetTimeoutAlarm()->deadline()); 3510 connection_.GetTimeoutAlarm()->deadline());
3508 3511
3509 // Now, send packets while advancing the time and verify that the connection 3512 // Now, send packets while advancing the time and verify that the connection
3510 // eventually times out. 3513 // eventually times out.
3511 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, 3514 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _,
3512 ConnectionCloseSource::FROM_SELF)); 3515 ConnectionCloseSource::FROM_SELF));
3513 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); 3516 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber());
3514 for (int i = 0; i < 100 && connection_.connected(); ++i) { 3517 for (int i = 0; i < 100 && connection_.connected(); ++i) {
3515 QUIC_LOG(INFO) << "sending data packet"; 3518 QUIC_LOG(INFO) << "sending data packet";
3516 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 3519 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
3517 nullptr); 3520 nullptr);
3518 connection_.GetTimeoutAlarm()->Fire(); 3521 connection_.GetTimeoutAlarm()->Fire();
3519 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); 3522 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1));
3520 } 3523 }
3521 EXPECT_FALSE(connection_.connected()); 3524 EXPECT_FALSE(connection_.connected());
3522 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 3525 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
3523 } 3526 }
3524 3527
3525 TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) { 3528 TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) {
3526 connection_.SetMaxTailLossProbes(2); 3529 connection_.SetMaxTailLossProbes(2);
3527 EXPECT_TRUE(connection_.connected()); 3530 EXPECT_TRUE(connection_.connected());
3528 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 3531 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
3529 QuicConfig config; 3532 QuicConfig config;
3530 QuicTagVector connection_options; 3533 QuicTagVector connection_options;
3531 connection_options.push_back(k5RTO); 3534 connection_options.push_back(k5RTO);
3532 config.SetConnectionOptionsToSend(connection_options); 3535 config.SetConnectionOptionsToSend(connection_options);
3533 connection_.SetFromConfig(config); 3536 connection_.SetFromConfig(config);
3534 3537
3535 // Send stream data. 3538 // Send stream data.
3536 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, kFin, nullptr); 3539 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr);
3537 3540
3538 EXPECT_CALL(visitor_, OnPathDegrading()); 3541 EXPECT_CALL(visitor_, OnPathDegrading());
3539 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO. 3542 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO.
3540 for (int i = 0; i < 6; ++i) { 3543 for (int i = 0; i < 6; ++i) {
3541 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 3544 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3542 connection_.GetRetransmissionAlarm()->Fire(); 3545 connection_.GetRetransmissionAlarm()->Fire();
3543 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); 3546 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet());
3544 EXPECT_TRUE(connection_.connected()); 3547 EXPECT_TRUE(connection_.connected());
3545 } 3548 }
3546 3549
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3589 size_t length = GetPacketLengthForOneStream( 3592 size_t length = GetPacketLengthForOneStream(
3590 connection_.version(), kIncludeVersion, !kIncludeDiversificationNonce, 3593 connection_.version(), kIncludeVersion, !kIncludeDiversificationNonce,
3591 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length); 3594 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_PACKET_NUMBER, &payload_length);
3592 connection_.SetMaxPacketLength(length); 3595 connection_.SetMaxPacketLength(length);
3593 3596
3594 // Queue the first packet. 3597 // Queue the first packet.
3595 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 3598 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
3596 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10))); 3599 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
3597 const string payload(payload_length, 'a'); 3600 const string payload(payload_length, 'a');
3598 EXPECT_EQ(0u, 3601 EXPECT_EQ(0u,
3599 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3602 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr)
3600 .bytes_consumed); 3603 .bytes_consumed);
3601 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 3604 EXPECT_EQ(0u, connection_.NumQueuedPackets());
3602 } 3605 }
3603 3606
3604 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 3607 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
3605 // All packets carry version info till version is negotiated. 3608 // All packets carry version info till version is negotiated.
3606 size_t payload_length; 3609 size_t payload_length;
3607 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 3610 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
3608 // packet length. The size of the offset field in a stream frame is 0 for 3611 // packet length. The size of the offset field in a stream frame is 0 for
3609 // offset 0, and 2 for non-zero offsets up through 16K. Increase 3612 // offset 0, and 2 for non-zero offsets up through 16K. Increase
3610 // max_packet_length by 2 so that subsequent packets containing subsequent 3613 // max_packet_length by 2 so that subsequent packets containing subsequent
3611 // stream frames with non-zero offets will fit within the packet length. 3614 // stream frames with non-zero offets will fit within the packet length.
3612 size_t length = 3615 size_t length =
3613 2 + GetPacketLengthForOneStream( 3616 2 + GetPacketLengthForOneStream(
3614 connection_.version(), kIncludeVersion, 3617 connection_.version(), kIncludeVersion,
3615 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID, 3618 !kIncludeDiversificationNonce, PACKET_8BYTE_CONNECTION_ID,
3616 PACKET_1BYTE_PACKET_NUMBER, &payload_length); 3619 PACKET_1BYTE_PACKET_NUMBER, &payload_length);
3617 connection_.SetMaxPacketLength(length); 3620 connection_.SetMaxPacketLength(length);
3618 3621
3619 // Queue the first packet. 3622 // Queue the first packet.
3620 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 3623 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
3621 // The first stream frame will have 2 fewer overhead bytes than the other six. 3624 // The first stream frame will have 2 fewer overhead bytes than the other six.
3622 const string payload(payload_length * 7 + 2, 'a'); 3625 const string payload(payload_length * 7 + 2, 'a');
3623 EXPECT_EQ(payload.size(), 3626 EXPECT_EQ(payload.size(),
3624 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 3627 connection_.SendStreamDataWithString(1, payload, 0, NO_FIN, nullptr)
3625 .bytes_consumed); 3628 .bytes_consumed);
3626 } 3629 }
3627 3630
3628 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { 3631 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) {
3629 // Set up a larger payload than will fit in one packet. 3632 // Set up a larger payload than will fit in one packet.
3630 const string payload(connection_.max_packet_length(), 'a'); 3633 const string payload(connection_.max_packet_length(), 'a');
3631 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); 3634 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber());
3632 3635
3633 // Now send some packets with no truncation. 3636 // Now send some packets with no truncation.
3634 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 3637 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
3635 EXPECT_EQ(payload.size(), 3638 EXPECT_EQ(payload.size(),
3636 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3639 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr)
3637 .bytes_consumed); 3640 .bytes_consumed);
3638 // Track the size of the second packet here. The overhead will be the largest 3641 // Track the size of the second packet here. The overhead will be the largest
3639 // we see in this test, due to the non-truncated connection id. 3642 // we see in this test, due to the non-truncated connection id.
3640 size_t non_truncated_packet_size = writer_->last_packet_size(); 3643 size_t non_truncated_packet_size = writer_->last_packet_size();
3641 3644
3642 // Change to a 0 byte connection id. 3645 // Change to a 0 byte connection id.
3643 QuicConfig config; 3646 QuicConfig config;
3644 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); 3647 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0);
3645 connection_.SetFromConfig(config); 3648 connection_.SetFromConfig(config);
3646 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 3649 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
3647 EXPECT_EQ(payload.size(), 3650 EXPECT_EQ(payload.size(),
3648 connection_.SendStreamDataWithString(3, payload, 0, !kFin, nullptr) 3651 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr)
3649 .bytes_consumed); 3652 .bytes_consumed);
3650 // Just like above, we save 8 bytes on payload, and 8 on truncation. 3653 // Just like above, we save 8 bytes on payload, and 8 on truncation.
3651 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); 3654 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2);
3652 } 3655 }
3653 3656
3654 TEST_P(QuicConnectionTest, SendDelayedAck) { 3657 TEST_P(QuicConnectionTest, SendDelayedAck) {
3655 QuicTime ack_time = clock_.ApproximateNow() + DefaultDelayedAckTime(); 3658 QuicTime ack_time = clock_.ApproximateNow() + DefaultDelayedAckTime();
3656 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3659 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3657 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3660 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3658 const uint8_t tag = 0x07; 3661 const uint8_t tag = 0x07;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
4146 writer_->Reset(); 4149 writer_->Reset();
4147 // Now only set the timer on the 6th packet, instead of sending another ack. 4150 // Now only set the timer on the 6th packet, instead of sending another ack.
4148 ProcessPacket(6); 4151 ProcessPacket(6);
4149 EXPECT_EQ(0u, writer_->frame_count()); 4152 EXPECT_EQ(0u, writer_->frame_count());
4150 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 4153 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
4151 } 4154 }
4152 4155
4153 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) { 4156 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingPacket) {
4154 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4157 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4155 ProcessPacket(1); 4158 ProcessPacket(1);
4156 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4159 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
4157 nullptr); 4160 nullptr);
4158 // Check that ack is bundled with outgoing data and that delayed ack 4161 // Check that ack is bundled with outgoing data and that delayed ack
4159 // alarm is reset. 4162 // alarm is reset.
4160 if (GetParam().no_stop_waiting) { 4163 if (GetParam().no_stop_waiting) {
4161 EXPECT_EQ(2u, writer_->frame_count()); 4164 EXPECT_EQ(2u, writer_->frame_count());
4162 EXPECT_TRUE(writer_->stop_waiting_frames().empty()); 4165 EXPECT_TRUE(writer_->stop_waiting_frames().empty());
4163 } else { 4166 } else {
4164 EXPECT_EQ(3u, writer_->frame_count()); 4167 EXPECT_EQ(3u, writer_->frame_count());
4165 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4168 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4166 } 4169 }
4167 EXPECT_FALSE(writer_->ack_frames().empty()); 4170 EXPECT_FALSE(writer_->ack_frames().empty());
4168 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4171 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4169 } 4172 }
4170 4173
4171 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) { 4174 TEST_P(QuicConnectionTest, SendDelayedAckOnOutgoingCryptoPacket) {
4172 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4175 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4173 ProcessPacket(1); 4176 ProcessPacket(1);
4174 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, 4177 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, NO_FIN,
4175 nullptr); 4178 nullptr);
4176 // Check that ack is bundled with outgoing crypto data. 4179 // Check that ack is bundled with outgoing crypto data.
4177 if (GetParam().no_stop_waiting) { 4180 if (GetParam().no_stop_waiting) {
4178 EXPECT_EQ(2u, writer_->frame_count()); 4181 EXPECT_EQ(3u, writer_->frame_count());
4179 EXPECT_TRUE(writer_->stop_waiting_frames().empty()); 4182 EXPECT_TRUE(writer_->stop_waiting_frames().empty());
4180 } else { 4183 } else {
4181 EXPECT_EQ(3u, writer_->frame_count()); 4184 EXPECT_EQ(4u, writer_->frame_count());
4182 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4185 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4183 } 4186 }
4184 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4187 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4185 } 4188 }
4186 4189
4187 TEST_P(QuicConnectionTest, BlockAndBufferOnFirstCHLOPacketOfTwo) { 4190 TEST_P(QuicConnectionTest, BlockAndBufferOnFirstCHLOPacketOfTwo) {
4188 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4191 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4189 ProcessPacket(1); 4192 ProcessPacket(1);
4190 BlockOnNextWrite(); 4193 BlockOnNextWrite();
4191 writer_->set_is_write_blocked_data_buffered(true); 4194 writer_->set_is_write_blocked_data_buffered(true);
4192 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, !kFin, 4195 connection_.SendStreamDataWithString(kCryptoStreamId, "foo", 0, NO_FIN,
4193 nullptr); 4196 nullptr);
4194 EXPECT_TRUE(writer_->IsWriteBlocked()); 4197 EXPECT_TRUE(writer_->IsWriteBlocked());
4195 EXPECT_FALSE(connection_.HasQueuedData()); 4198 EXPECT_FALSE(connection_.HasQueuedData());
4196 connection_.SendStreamDataWithString(kCryptoStreamId, "bar", 3, !kFin, 4199 connection_.SendStreamDataWithString(kCryptoStreamId, "bar", 3, NO_FIN,
4197 nullptr); 4200 nullptr);
4198 EXPECT_TRUE(writer_->IsWriteBlocked()); 4201 EXPECT_TRUE(writer_->IsWriteBlocked());
4199 EXPECT_TRUE(connection_.HasQueuedData()); 4202 EXPECT_TRUE(connection_.HasQueuedData());
4200 } 4203 }
4201 4204
4202 TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) { 4205 TEST_P(QuicConnectionTest, BundleAckForSecondCHLO) {
4203 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4206 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4204 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4207 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4205 EXPECT_CALL(visitor_, OnCanWrite()) 4208 EXPECT_CALL(visitor_, OnCanWrite())
4206 .WillOnce(IgnoreResult(InvokeWithoutArgs( 4209 .WillOnce(IgnoreResult(InvokeWithoutArgs(
4207 &connection_, &TestConnection::SendCryptoStreamData))); 4210 &connection_, &TestConnection::SendCryptoStreamData)));
4208 // Process a packet from the crypto stream, which is frame1_'s default. 4211 // Process a packet from the crypto stream, which is frame1_'s default.
4209 // Receiving the CHLO as packet 2 first will cause the connection to 4212 // Receiving the CHLO as packet 2 first will cause the connection to
4210 // immediately send an ack, due to the packet gap. 4213 // immediately send an ack, due to the packet gap.
4211 ProcessPacket(2); 4214 ProcessPacket(2);
4212 // Check that ack is sent and that delayed ack alarm is reset. 4215 // Check that ack is sent and that delayed ack alarm is reset.
4213 if (GetParam().no_stop_waiting) { 4216 if (GetParam().no_stop_waiting) {
4214 EXPECT_EQ(2u, writer_->frame_count()); 4217 EXPECT_EQ(3u, writer_->frame_count());
4215 EXPECT_TRUE(writer_->stop_waiting_frames().empty()); 4218 EXPECT_TRUE(writer_->stop_waiting_frames().empty());
4216 } else { 4219 } else {
4217 EXPECT_EQ(3u, writer_->frame_count()); 4220 EXPECT_EQ(4u, writer_->frame_count());
4218 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4221 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4219 } 4222 }
4220 EXPECT_EQ(1u, writer_->stream_frames().size()); 4223 EXPECT_EQ(1u, writer_->stream_frames().size());
4224 EXPECT_EQ(1u, writer_->padding_frames().size());
4221 EXPECT_FALSE(writer_->ack_frames().empty()); 4225 EXPECT_FALSE(writer_->ack_frames().empty());
4222 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); 4226 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed);
4223 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4227 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4224 } 4228 }
4225 4229
4226 TEST_P(QuicConnectionTest, BundleAckForSecondCHLOTwoPacketReject) { 4230 TEST_P(QuicConnectionTest, BundleAckForSecondCHLOTwoPacketReject) {
4227 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4231 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4228 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4232 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4229 4233
4230 // Process two packets from the crypto stream, which is frame1_'s default, 4234 // Process two packets from the crypto stream, which is frame1_'s default,
4231 // simulating a 2 packet reject. 4235 // simulating a 2 packet reject.
4232 { 4236 {
4233 ProcessPacket(1); 4237 ProcessPacket(1);
4234 // Send the new CHLO when the REJ is processed. 4238 // Send the new CHLO when the REJ is processed.
4235 EXPECT_CALL(visitor_, OnStreamFrame(_)) 4239 EXPECT_CALL(visitor_, OnStreamFrame(_))
4236 .WillOnce(IgnoreResult(InvokeWithoutArgs( 4240 .WillOnce(IgnoreResult(InvokeWithoutArgs(
4237 &connection_, &TestConnection::SendCryptoStreamData))); 4241 &connection_, &TestConnection::SendCryptoStreamData)));
4238 ProcessDataPacket(2); 4242 ProcessDataPacket(2);
4239 } 4243 }
4240 // Check that ack is sent and that delayed ack alarm is reset. 4244 // Check that ack is sent and that delayed ack alarm is reset.
4241 if (GetParam().no_stop_waiting) { 4245 if (GetParam().no_stop_waiting) {
4242 EXPECT_EQ(2u, writer_->frame_count()); 4246 EXPECT_EQ(3u, writer_->frame_count());
4243 EXPECT_TRUE(writer_->stop_waiting_frames().empty()); 4247 EXPECT_TRUE(writer_->stop_waiting_frames().empty());
4244 } else { 4248 } else {
4245 EXPECT_EQ(3u, writer_->frame_count()); 4249 EXPECT_EQ(4u, writer_->frame_count());
4246 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 4250 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
4247 } 4251 }
4248 EXPECT_EQ(1u, writer_->stream_frames().size()); 4252 EXPECT_EQ(1u, writer_->stream_frames().size());
4253 EXPECT_EQ(1u, writer_->padding_frames().size());
4249 EXPECT_FALSE(writer_->ack_frames().empty()); 4254 EXPECT_FALSE(writer_->ack_frames().empty());
4250 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed); 4255 EXPECT_EQ(2u, writer_->ack_frames().front().largest_observed);
4251 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 4256 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
4252 } 4257 }
4253 4258
4254 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) { 4259 TEST_P(QuicConnectionTest, BundleAckWithDataOnIncomingAck) {
4255 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4260 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4256 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4261 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
4257 nullptr); 4262 nullptr);
4258 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, !kFin, 4263 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 3, NO_FIN,
4259 nullptr); 4264 nullptr);
4260 // Ack the second packet, which will retransmit the first packet. 4265 // Ack the second packet, which will retransmit the first packet.
4261 QuicAckFrame ack = InitAckFrame(2); 4266 QuicAckFrame ack = InitAckFrame(2);
4262 NackPacket(1, &ack); 4267 NackPacket(1, &ack);
4263 SendAlgorithmInterface::CongestionVector lost_packets; 4268 SendAlgorithmInterface::CongestionVector lost_packets;
4264 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 4269 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
4265 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4270 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4266 .WillOnce(SetArgPointee<4>(lost_packets)); 4271 .WillOnce(SetArgPointee<4>(lost_packets));
4267 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4272 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4268 ProcessAckPacket(&ack); 4273 ProcessAckPacket(&ack);
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
4550 GetPeerInMemoryConnectionId(connection_id_), AllSupportedVersions())); 4555 GetPeerInMemoryConnectionId(connection_id_), AllSupportedVersions()));
4551 std::unique_ptr<QuicReceivedPacket> received( 4556 std::unique_ptr<QuicReceivedPacket> received(
4552 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); 4557 ConstructReceivedPacket(*encrypted, QuicTime::Zero()));
4553 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); 4558 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received);
4554 } 4559 }
4555 4560
4556 TEST_P(QuicConnectionTest, CheckSendStats) { 4561 TEST_P(QuicConnectionTest, CheckSendStats) {
4557 connection_.SetMaxTailLossProbes(0); 4562 connection_.SetMaxTailLossProbes(0);
4558 4563
4559 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4564 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4560 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); 4565 connection_.SendStreamDataWithString(3, "first", 0, NO_FIN, nullptr);
4561 size_t first_packet_size = writer_->last_packet_size(); 4566 size_t first_packet_size = writer_->last_packet_size();
4562 4567
4563 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4568 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
4564 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); 4569 connection_.SendStreamDataWithString(5, "second", 0, NO_FIN, nullptr);
4565 size_t second_packet_size = writer_->last_packet_size(); 4570 size_t second_packet_size = writer_->last_packet_size();
4566 4571
4567 // 2 retransmissions due to rto, 1 due to explicit nack. 4572 // 2 retransmissions due to rto, 1 due to explicit nack.
4568 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 4573 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
4569 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 4574 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
4570 4575
4571 // Retransmit due to RTO. 4576 // Retransmit due to RTO.
4572 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 4577 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
4573 connection_.GetRetransmissionAlarm()->Fire(); 4578 connection_.GetRetransmissionAlarm()->Fire();
4574 4579
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4657 // Shouldn't be able to find a mutually supported version. 4662 // Shouldn't be able to find a mutually supported version.
4658 QuicVersionVector unsupported_version; 4663 QuicVersionVector unsupported_version;
4659 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED); 4664 unsupported_version.push_back(QUIC_VERSION_UNSUPPORTED);
4660 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version)); 4665 EXPECT_FALSE(connection_.SelectMutualVersion(unsupported_version));
4661 } 4666 }
4662 4667
4663 TEST_P(QuicConnectionTest, ConnectionCloseWhenWritable) { 4668 TEST_P(QuicConnectionTest, ConnectionCloseWhenWritable) {
4664 EXPECT_FALSE(writer_->IsWriteBlocked()); 4669 EXPECT_FALSE(writer_->IsWriteBlocked());
4665 4670
4666 // Send a packet. 4671 // Send a packet.
4667 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4672 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
4668 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 4673 EXPECT_EQ(0u, connection_.NumQueuedPackets());
4669 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4674 EXPECT_EQ(1u, writer_->packets_write_attempts());
4670 4675
4671 TriggerConnectionClose(); 4676 TriggerConnectionClose();
4672 EXPECT_EQ(2u, writer_->packets_write_attempts()); 4677 EXPECT_EQ(2u, writer_->packets_write_attempts());
4673 } 4678 }
4674 4679
4675 TEST_P(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) { 4680 TEST_P(QuicConnectionTest, ConnectionCloseGettingWriteBlocked) {
4676 BlockOnNextWrite(); 4681 BlockOnNextWrite();
4677 TriggerConnectionClose(); 4682 TriggerConnectionClose();
4678 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4683 EXPECT_EQ(1u, writer_->packets_write_attempts());
4679 EXPECT_TRUE(writer_->IsWriteBlocked()); 4684 EXPECT_TRUE(writer_->IsWriteBlocked());
4680 } 4685 }
4681 4686
4682 TEST_P(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) { 4687 TEST_P(QuicConnectionTest, ConnectionCloseWhenWriteBlocked) {
4683 BlockOnNextWrite(); 4688 BlockOnNextWrite();
4684 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4689 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
4685 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 4690 EXPECT_EQ(1u, connection_.NumQueuedPackets());
4686 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4691 EXPECT_EQ(1u, writer_->packets_write_attempts());
4687 EXPECT_TRUE(writer_->IsWriteBlocked()); 4692 EXPECT_TRUE(writer_->IsWriteBlocked());
4688 TriggerConnectionClose(); 4693 TriggerConnectionClose();
4689 EXPECT_EQ(1u, writer_->packets_write_attempts()); 4694 EXPECT_EQ(1u, writer_->packets_write_attempts());
4690 } 4695 }
4691 4696
4692 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { 4697 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) {
4693 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4698 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4694 4699
4695 // Create a listener which we expect to be called. 4700 // Create a listener which we expect to be called.
4696 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4701 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4697 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1); 4702 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(1);
4698 4703
4699 // Send some data, which will register the listener to be notified. 4704 // Send some data, which will register the listener to be notified.
4700 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); 4705 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, listener);
4701 4706
4702 // Process an ACK from the server which should trigger the callback. 4707 // Process an ACK from the server which should trigger the callback.
4703 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4708 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4704 QuicAckFrame frame = InitAckFrame(1); 4709 QuicAckFrame frame = InitAckFrame(1);
4705 ProcessAckPacket(&frame); 4710 ProcessAckPacket(&frame);
4706 } 4711 }
4707 4712
4708 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { 4713 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) {
4709 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4714 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4710 4715
4711 // Create a listener which we don't expect to be called. 4716 // Create a listener which we don't expect to be called.
4712 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4717 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4713 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(0); 4718 EXPECT_CALL(*listener, OnPacketAcked(_, _)).Times(0);
4714 4719
4715 // Send some data, which will register the listener to be notified. This will 4720 // Send some data, which will register the listener to be notified. This will
4716 // not be ACKed and so the listener should never be called. 4721 // not be ACKed and so the listener should never be called.
4717 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, listener); 4722 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, listener);
4718 4723
4719 // Send some other data which we will ACK. 4724 // Send some other data which we will ACK.
4720 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 4725 connection_.SendStreamDataWithString(1, "foo", 0, NO_FIN, nullptr);
4721 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); 4726 connection_.SendStreamDataWithString(1, "bar", 0, NO_FIN, nullptr);
4722 4727
4723 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 4728 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1
4724 // which we registered to be notified about. 4729 // which we registered to be notified about.
4725 QuicAckFrame frame = InitAckFrame(3); 4730 QuicAckFrame frame = InitAckFrame(3);
4726 NackPacket(1, &frame); 4731 NackPacket(1, &frame);
4727 SendAlgorithmInterface::CongestionVector lost_packets; 4732 SendAlgorithmInterface::CongestionVector lost_packets;
4728 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); 4733 lost_packets.push_back(std::make_pair(1, kMaxPacketSize));
4729 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4734 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4730 .WillOnce(SetArgPointee<4>(lost_packets)); 4735 .WillOnce(SetArgPointee<4>(lost_packets));
4731 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4736 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4732 ProcessAckPacket(&frame); 4737 ProcessAckPacket(&frame);
4733 } 4738 }
4734 4739
4735 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { 4740 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) {
4736 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4741 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4737 4742
4738 // Create a listener which we expect to be called. 4743 // Create a listener which we expect to be called.
4739 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4744 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4740 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1); 4745 EXPECT_CALL(*listener, OnPacketRetransmitted(3)).Times(1);
4741 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1); 4746 EXPECT_CALL(*listener, OnPacketAcked(3, _)).Times(1);
4742 4747
4743 // Send four packets, and register to be notified on ACK of packet 2. 4748 // Send four packets, and register to be notified on ACK of packet 2.
4744 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 4749 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
4745 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); 4750 connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN, listener);
4746 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 4751 connection_.SendStreamDataWithString(3, "baz", 0, NO_FIN, nullptr);
4747 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 4752 connection_.SendStreamDataWithString(3, "qux", 0, NO_FIN, nullptr);
4748 4753
4749 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 4754 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
4750 QuicAckFrame frame = InitAckFrame(4); 4755 QuicAckFrame frame = InitAckFrame(4);
4751 NackPacket(2, &frame); 4756 NackPacket(2, &frame);
4752 SendAlgorithmInterface::CongestionVector lost_packets; 4757 SendAlgorithmInterface::CongestionVector lost_packets;
4753 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 4758 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
4754 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4759 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4755 .WillOnce(SetArgPointee<4>(lost_packets)); 4760 .WillOnce(SetArgPointee<4>(lost_packets));
4756 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _)); 4761 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _, _));
4757 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 4762 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
(...skipping 12 matching lines...) Expand all
4770 // different packet number. 4775 // different packet number.
4771 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { 4776 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) {
4772 connection_.SetMaxTailLossProbes(0); 4777 connection_.SetMaxTailLossProbes(0);
4773 4778
4774 // Create a listener which we expect to be called. 4779 // Create a listener which we expect to be called.
4775 QuicReferenceCountedPointer<MockAckListener> listener( 4780 QuicReferenceCountedPointer<MockAckListener> listener(
4776 new StrictMock<MockAckListener>); 4781 new StrictMock<MockAckListener>);
4777 4782
4778 QuicTime default_retransmission_time = 4783 QuicTime default_retransmission_time =
4779 clock_.ApproximateNow() + DefaultRetransmissionTime(); 4784 clock_.ApproximateNow() + DefaultRetransmissionTime();
4780 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, listener); 4785 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, listener);
4781 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4786 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4782 4787
4783 EXPECT_EQ(1u, writer_->header().packet_number); 4788 EXPECT_EQ(1u, writer_->header().packet_number);
4784 EXPECT_EQ(default_retransmission_time, 4789 EXPECT_EQ(default_retransmission_time,
4785 connection_.GetRetransmissionAlarm()->deadline()); 4790 connection_.GetRetransmissionAlarm()->deadline());
4786 // Simulate the retransmission alarm firing. 4791 // Simulate the retransmission alarm firing.
4787 clock_.AdvanceTime(DefaultRetransmissionTime()); 4792 clock_.AdvanceTime(DefaultRetransmissionTime());
4788 EXPECT_CALL(*listener, OnPacketRetransmitted(3)); 4793 EXPECT_CALL(*listener, OnPacketRetransmitted(3));
4789 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 4794 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
4790 connection_.GetRetransmissionAlarm()->Fire(); 4795 connection_.GetRetransmissionAlarm()->Fire();
(...skipping 16 matching lines...) Expand all
4807 4812
4808 // AckNotifierCallback is triggered by the ack of a packet that was 4813 // AckNotifierCallback is triggered by the ack of a packet that was
4809 // previously nacked, even though the retransmission has a different 4814 // previously nacked, even though the retransmission has a different
4810 // packet number. 4815 // packet number.
4811 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) { 4816 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckOfNackedPacket) {
4812 // Create a listener which we expect to be called. 4817 // Create a listener which we expect to be called.
4813 QuicReferenceCountedPointer<MockAckListener> listener( 4818 QuicReferenceCountedPointer<MockAckListener> listener(
4814 new StrictMock<MockAckListener>()); 4819 new StrictMock<MockAckListener>());
4815 4820
4816 // Send four packets, and register to be notified on ACK of packet 2. 4821 // Send four packets, and register to be notified on ACK of packet 2.
4817 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 4822 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
4818 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, listener); 4823 connection_.SendStreamDataWithString(3, "bar", 0, NO_FIN, listener);
4819 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); 4824 connection_.SendStreamDataWithString(3, "baz", 0, NO_FIN, nullptr);
4820 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); 4825 connection_.SendStreamDataWithString(3, "qux", 0, NO_FIN, nullptr);
4821 4826
4822 // Now we receive ACK for packets 1, 3, and 4 and lose 2. 4827 // Now we receive ACK for packets 1, 3, and 4 and lose 2.
4823 QuicAckFrame frame = InitAckFrame(4); 4828 QuicAckFrame frame = InitAckFrame(4);
4824 NackPacket(2, &frame); 4829 NackPacket(2, &frame);
4825 EXPECT_CALL(*listener, OnPacketRetransmitted(_)); 4830 EXPECT_CALL(*listener, OnPacketRetransmitted(_));
4826 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4831 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4827 SendAlgorithmInterface::CongestionVector lost_packets; 4832 SendAlgorithmInterface::CongestionVector lost_packets;
4828 lost_packets.push_back(std::make_pair(2, kMaxPacketSize)); 4833 lost_packets.push_back(std::make_pair(2, kMaxPacketSize));
4829 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)) 4834 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _))
4830 .WillOnce(SetArgPointee<4>(lost_packets)); 4835 .WillOnce(SetArgPointee<4>(lost_packets));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
4901 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 4906 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
4902 EXPECT_TRUE(ack_alarm->IsSet()); 4907 EXPECT_TRUE(ack_alarm->IsSet());
4903 } 4908 }
4904 4909
4905 TEST_P(QuicConnectionTest, NoDataNoFin) { 4910 TEST_P(QuicConnectionTest, NoDataNoFin) {
4906 // Make sure that a call to SendStreamWithData, with no data and no FIN, does 4911 // Make sure that a call to SendStreamWithData, with no data and no FIN, does
4907 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). 4912 // not result in a QuicAckNotifier being used-after-free (fail under ASAN).
4908 // Regression test for b/18594622 4913 // Regression test for b/18594622
4909 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener); 4914 QuicReferenceCountedPointer<MockAckListener> listener(new MockAckListener);
4910 EXPECT_QUIC_BUG( 4915 EXPECT_QUIC_BUG(
4911 connection_.SendStreamDataWithString(3, "", 0, !kFin, listener), 4916 connection_.SendStreamDataWithString(3, "", 0, NO_FIN, listener),
4912 "Attempt to send empty stream frame"); 4917 "Attempt to send empty stream frame");
4913 } 4918 }
4914 4919
4915 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) { 4920 TEST_P(QuicConnectionTest, DoNotSendGoAwayTwice) {
4916 EXPECT_FALSE(connection_.goaway_sent()); 4921 EXPECT_FALSE(connection_.goaway_sent());
4917 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 4922 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
4918 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 4923 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
4919 EXPECT_TRUE(connection_.goaway_sent()); 4924 EXPECT_TRUE(connection_.goaway_sent());
4920 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 4925 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
4921 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); 4926 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away.");
4922 } 4927 }
4923 4928
4924 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) { 4929 TEST_P(QuicConnectionTest, ReevaluateTimeUntilSendOnAck) {
4925 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4930 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4926 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, !kFin, 4931 connection_.SendStreamDataWithString(kClientDataStreamId1, "foo", 0, NO_FIN,
4927 nullptr); 4932 nullptr);
4928 4933
4929 // Evaluate CanWrite, and have it return a non-Zero value. 4934 // Evaluate CanWrite, and have it return a non-Zero value.
4930 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 4935 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
4931 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 4936 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1)));
4932 connection_.OnCanWrite(); 4937 connection_.OnCanWrite();
4933 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet()); 4938 EXPECT_TRUE(connection_.GetSendAlarm()->IsSet());
4934 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(1), 4939 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(1),
4935 connection_.GetSendAlarm()->deadline()); 4940 connection_.GetSendAlarm()->deadline());
4936 4941
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
4977 EXPECT_EQ(1u, connection_.GetStats().blocked_frames_sent); 4982 EXPECT_EQ(1u, connection_.GetStats().blocked_frames_sent);
4978 EXPECT_FALSE(connection_.HasQueuedData()); 4983 EXPECT_FALSE(connection_.HasQueuedData());
4979 } 4984 }
4980 4985
4981 TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) { 4986 TEST_P(QuicConnectionTest, SendingUnencryptedStreamDataFails) {
4982 EXPECT_CALL(visitor_, 4987 EXPECT_CALL(visitor_,
4983 OnConnectionClosed(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA, 4988 OnConnectionClosed(QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA,
4984 _, ConnectionCloseSource::FROM_SELF)); 4989 _, ConnectionCloseSource::FROM_SELF));
4985 struct iovec iov; 4990 struct iovec iov;
4986 QuicIOVector data_iov(MakeIOVector("", &iov)); 4991 QuicIOVector data_iov(MakeIOVector("", &iov));
4987 EXPECT_QUIC_BUG(connection_.SendStreamData(3, data_iov, 0, kFin, nullptr), 4992 EXPECT_QUIC_BUG(connection_.SendStreamData(3, data_iov, 0, FIN, nullptr),
4988 "Cannot send stream data without encryption."); 4993 "Cannot send stream data without encryption.");
4989 EXPECT_FALSE(connection_.connected()); 4994 EXPECT_FALSE(connection_.connected());
4990 } 4995 }
4991 4996
4992 TEST_P(QuicConnectionTest, OnPathDegrading) { 4997 TEST_P(QuicConnectionTest, OnPathDegrading) {
4993 QuicByteCount packet_size; 4998 QuicByteCount packet_size;
4994 const size_t kMinTimeoutsBeforePathDegrading = 2; 4999 const size_t kMinTimeoutsBeforePathDegrading = 2;
4995 5000
4996 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 5001 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
4997 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true))); 5002 .WillOnce(DoAll(SaveArg<3>(&packet_size), Return(true)));
4998 connection_.SendStreamDataWithString(3, "packet", 0, !kFin, nullptr); 5003 connection_.SendStreamDataWithString(3, "packet", 0, NO_FIN, nullptr);
4999 size_t num_timeouts = 5004 size_t num_timeouts =
5000 kMinTimeoutsBeforePathDegrading + 5005 kMinTimeoutsBeforePathDegrading +
5001 QuicSentPacketManagerPeer::GetMaxTailLossProbes( 5006 QuicSentPacketManagerPeer::GetMaxTailLossProbes(
5002 QuicConnectionPeer::GetSentPacketManager(&connection_)); 5007 QuicConnectionPeer::GetSentPacketManager(&connection_));
5003 for (size_t i = 1; i < num_timeouts; ++i) { 5008 for (size_t i = 1; i < num_timeouts; ++i) {
5004 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10 * i)); 5009 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10 * i));
5005 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _)); 5010 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, packet_size, _));
5006 connection_.GetRetransmissionAlarm()->Fire(); 5011 connection_.GetRetransmissionAlarm()->Fire();
5007 } 5012 }
5008 // Next RTO should cause OnPathDegrading to be called before the 5013 // Next RTO should cause OnPathDegrading to be called before the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
5064 ConnectionCloseSource::FROM_SELF)); 5069 ConnectionCloseSource::FROM_SELF));
5065 ForceProcessFramePacket(QuicFrame(&frame1_)); 5070 ForceProcessFramePacket(QuicFrame(&frame1_));
5066 } 5071 }
5067 5072
5068 TEST_P(QuicConnectionTest, CloseConnectionOnPacketTooLarge) { 5073 TEST_P(QuicConnectionTest, CloseConnectionOnPacketTooLarge) {
5069 SimulateNextPacketTooLarge(); 5074 SimulateNextPacketTooLarge();
5070 // A connection close packet is sent 5075 // A connection close packet is sent
5071 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, 5076 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _,
5072 ConnectionCloseSource::FROM_SELF)) 5077 ConnectionCloseSource::FROM_SELF))
5073 .Times(1); 5078 .Times(1);
5074 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5079 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
5075 } 5080 }
5076 5081
5077 TEST_P(QuicConnectionTest, AlwaysGetPacketTooLarge) { 5082 TEST_P(QuicConnectionTest, AlwaysGetPacketTooLarge) {
5078 // Test even we always get packet too large, we do not infinitely try to send 5083 // Test even we always get packet too large, we do not infinitely try to send
5079 // close packet. 5084 // close packet.
5080 AlwaysGetPacketTooLarge(); 5085 AlwaysGetPacketTooLarge();
5081 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, 5086 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _,
5082 ConnectionCloseSource::FROM_SELF)) 5087 ConnectionCloseSource::FROM_SELF))
5083 .Times(1); 5088 .Times(1);
5084 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5089 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
5085 } 5090 }
5086 5091
5087 // Verify that if connection has no outstanding data, it notifies the send 5092 // Verify that if connection has no outstanding data, it notifies the send
5088 // algorithm after the write. 5093 // algorithm after the write.
5089 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) { 5094 TEST_P(QuicConnectionTest, SendDataAndBecomeApplicationLimited) {
5090 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1); 5095 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(1);
5091 { 5096 {
5092 InSequence seq; 5097 InSequence seq;
5093 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); 5098 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true));
5094 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) 5099 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
5127 TEST_P(QuicConnectionTest, DonotForceSendingAckOnPacketTooLarge) { 5132 TEST_P(QuicConnectionTest, DonotForceSendingAckOnPacketTooLarge) {
5128 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 5133 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
5129 // Send an ack by simulating delayed ack alarm firing. 5134 // Send an ack by simulating delayed ack alarm firing.
5130 ProcessPacket(1); 5135 ProcessPacket(1);
5131 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 5136 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
5132 EXPECT_TRUE(ack_alarm->IsSet()); 5137 EXPECT_TRUE(ack_alarm->IsSet());
5133 connection_.GetAckAlarm()->Fire(); 5138 connection_.GetAckAlarm()->Fire();
5134 // Simulate data packet causes write error. 5139 // Simulate data packet causes write error.
5135 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, _)); 5140 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PACKET_WRITE_ERROR, _, _));
5136 SimulateNextPacketTooLarge(); 5141 SimulateNextPacketTooLarge();
5137 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 5142 connection_.SendStreamDataWithString(3, "foo", 0, NO_FIN, nullptr);
5138 EXPECT_EQ(1u, writer_->frame_count()); 5143 EXPECT_EQ(1u, writer_->frame_count());
5139 EXPECT_FALSE(writer_->connection_close_frames().empty()); 5144 EXPECT_FALSE(writer_->connection_close_frames().empty());
5140 // Ack frame is not bundled in connection close packet. 5145 // Ack frame is not bundled in connection close packet.
5141 EXPECT_TRUE(writer_->ack_frames().empty()); 5146 EXPECT_TRUE(writer_->ack_frames().empty());
5142 } 5147 }
5143 5148
5144 TEST_P(QuicConnectionTest, CloseConnectionForStatelessReject) { 5149 TEST_P(QuicConnectionTest, CloseConnectionForStatelessReject) {
5145 string error_details("stateless reject"); 5150 string error_details("stateless reject");
5146 EXPECT_CALL(visitor_, OnConnectionClosed( 5151 EXPECT_CALL(visitor_, OnConnectionClosed(
5147 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, 5152 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT,
5148 error_details, ConnectionCloseSource::FROM_PEER)); 5153 error_details, ConnectionCloseSource::FROM_PEER));
5149 connection_.set_perspective(Perspective::IS_CLIENT); 5154 connection_.set_perspective(Perspective::IS_CLIENT);
5150 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, 5155 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT,
5151 error_details, 5156 error_details,
5152 ConnectionCloseBehavior::SILENT_CLOSE); 5157 ConnectionCloseBehavior::SILENT_CLOSE);
5153 } 5158 }
5154 5159
5155 } // namespace 5160 } // namespace
5156 } // namespace test 5161 } // namespace test
5157 } // namespace net 5162 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_connection.cc ('k') | net/quic/core/quic_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698