| Index: net/quic/quic_connection_test.cc
|
| diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc
|
| index ff50b01010615909a57b43f97e0e5b34e2cf678b..b3291b25f3330845b197a6072ed1196a9a5a4e1a 100644
|
| --- a/net/quic/quic_connection_test.cc
|
| +++ b/net/quic/quic_connection_test.cc
|
| @@ -22,7 +22,6 @@
|
| #include "net/quic/test_tools/quic_connection_peer.h"
|
| #include "net/quic/test_tools/quic_framer_peer.h"
|
| #include "net/quic/test_tools/quic_packet_creator_peer.h"
|
| -#include "net/quic/test_tools/quic_packet_generator_peer.h"
|
| #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
|
| #include "net/quic/test_tools/quic_test_utils.h"
|
| #include "net/quic/test_tools/simple_quic_framer.h"
|
| @@ -461,11 +460,33 @@ class TestConnection : public QuicConnection {
|
| QuicStreamOffset offset,
|
| bool fin,
|
| QuicAckNotifier::DelegateInterface* delegate) {
|
| + return SendStreamDataWithStringHelper(id, data, offset, fin,
|
| + MAY_FEC_PROTECT, delegate);
|
| + }
|
| +
|
| + QuicConsumedData SendStreamDataWithStringWithFec(
|
| + QuicStreamId id,
|
| + StringPiece data,
|
| + QuicStreamOffset offset,
|
| + bool fin,
|
| + QuicAckNotifier::DelegateInterface* delegate) {
|
| + return SendStreamDataWithStringHelper(id, data, offset, fin,
|
| + MUST_FEC_PROTECT, delegate);
|
| + }
|
| +
|
| + QuicConsumedData SendStreamDataWithStringHelper(
|
| + QuicStreamId id,
|
| + StringPiece data,
|
| + QuicStreamOffset offset,
|
| + bool fin,
|
| + FecProtection fec_protection,
|
| + QuicAckNotifier::DelegateInterface* delegate) {
|
| IOVector data_iov;
|
| if (!data.empty()) {
|
| data_iov.Append(const_cast<char*>(data.data()), data.size());
|
| }
|
| - return QuicConnection::SendStreamData(id, data_iov, offset, fin, delegate);
|
| + return QuicConnection::SendStreamData(id, data_iov, offset, fin,
|
| + fec_protection, delegate);
|
| }
|
|
|
| QuicConsumedData SendStreamData3() {
|
| @@ -473,11 +494,20 @@ class TestConnection : public QuicConnection {
|
| NULL);
|
| }
|
|
|
| + QuicConsumedData SendStreamData3WithFec() {
|
| + return SendStreamDataWithStringWithFec(kClientDataStreamId1, "food", 0,
|
| + !kFin, NULL);
|
| + }
|
| +
|
| QuicConsumedData SendStreamData5() {
|
| return SendStreamDataWithString(kClientDataStreamId2, "food2", 0,
|
| !kFin, NULL);
|
| }
|
|
|
| + QuicConsumedData SendStreamData5WithFec() {
|
| + return SendStreamDataWithStringWithFec(kClientDataStreamId2, "food2", 0,
|
| + !kFin, NULL);
|
| + }
|
| // Ensures the connection can write stream data before writing.
|
| QuicConsumedData EnsureWritableAndSendStreamData5() {
|
| EXPECT_TRUE(CanWriteStreamData());
|
| @@ -1460,18 +1490,17 @@ TEST_P(QuicConnectionTest, FECSending) {
|
| IN_FEC_GROUP, &payload_length);
|
| creator->set_max_packet_length(length);
|
|
|
| - // And send FEC every two packets.
|
| - QuicPacketGeneratorPeer::SwitchFecProtectionOn(
|
| - QuicConnectionPeer::GetPacketGenerator(&connection_), 2);
|
| + // Enable FEC.
|
| + creator->set_max_packets_per_fec_group(2);
|
|
|
| - // Send 4 data packets and 2 FEC packets.
|
| + // Send 4 protected data packets, which will also trigger 2 FEC packets.
|
| EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
|
| // The first stream frame will have 2 fewer overhead bytes than the other 3.
|
| const string payload(payload_length * 4 + 2, 'a');
|
| - connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL);
|
| // Expect the FEC group to be closed after SendStreamDataWithString.
|
| - EXPECT_FALSE(creator->ShouldSendFec(true));
|
| - EXPECT_TRUE(creator->IsFecProtected());
|
| + EXPECT_FALSE(creator->IsFecGroupOpen());
|
| + EXPECT_FALSE(creator->IsFecProtected());
|
| }
|
|
|
| TEST_P(QuicConnectionTest, FECQueueing) {
|
| @@ -1483,27 +1512,27 @@ TEST_P(QuicConnectionTest, FECQueueing) {
|
| connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER,
|
| IN_FEC_GROUP, &payload_length);
|
| creator->set_max_packet_length(length);
|
| - // And send FEC every two packets.
|
| - QuicPacketGeneratorPeer::SwitchFecProtectionOn(
|
| - QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
|
| + // Enable FEC.
|
| + creator->set_max_packets_per_fec_group(1);
|
|
|
| EXPECT_EQ(0u, connection_.NumQueuedPackets());
|
| BlockOnNextWrite();
|
| const string payload(payload_length, 'a');
|
| - connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
|
| - EXPECT_FALSE(creator->ShouldSendFec(true));
|
| - EXPECT_TRUE(creator->IsFecProtected());
|
| + connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, NULL);
|
| + EXPECT_FALSE(creator->IsFecGroupOpen());
|
| + EXPECT_FALSE(creator->IsFecProtected());
|
| // Expect the first data packet and the fec packet to be queued.
|
| EXPECT_EQ(2u, connection_.NumQueuedPackets());
|
| }
|
|
|
| TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) {
|
| - QuicPacketGeneratorPeer::SwitchFecProtectionOn(
|
| - QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
|
| + // Enable FEC.
|
| + QuicConnectionPeer::GetPacketCreator(
|
| + &connection_)->set_max_packets_per_fec_group(1);
|
|
|
| // 1 Data and 1 FEC packet.
|
| EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
|
| - connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
|
|
|
| const QuicTime::Delta retransmission_time =
|
| QuicTime::Delta::FromMilliseconds(5000);
|
| @@ -1518,15 +1547,16 @@ TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) {
|
|
|
| TEST_P(QuicConnectionTest, DontAbandonAckedFEC) {
|
| EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
|
| - QuicPacketGeneratorPeer::SwitchFecProtectionOn(
|
| - QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
|
| + // Enable FEC.
|
| + QuicConnectionPeer::GetPacketCreator(
|
| + &connection_)->set_max_packets_per_fec_group(1);
|
|
|
| // 1 Data and 1 FEC packet.
|
| EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
|
| - connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
|
| // Send some more data afterwards to ensure early retransmit doesn't trigger.
|
| - connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
|
| - connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL);
|
|
|
| QuicAckFrame ack_fec = InitAckFrame(2, 1);
|
| // Data packet missing.
|
| @@ -1546,17 +1576,18 @@ TEST_P(QuicConnectionTest, DontAbandonAckedFEC) {
|
|
|
| TEST_P(QuicConnectionTest, AbandonAllFEC) {
|
| EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
|
| - QuicPacketGeneratorPeer::SwitchFecProtectionOn(
|
| - QuicConnectionPeer::GetPacketGenerator(&connection_), 1);
|
| + // Enable FEC.
|
| + QuicConnectionPeer::GetPacketCreator(
|
| + &connection_)->set_max_packets_per_fec_group(1);
|
|
|
| // 1 Data and 1 FEC packet.
|
| EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
|
| - connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 0, !kFin, NULL);
|
| // Send some more data afterwards to ensure early retransmit doesn't trigger.
|
| - connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 3, !kFin, NULL);
|
| // Advance the time so not all the FEC packets are abandoned.
|
| clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
|
| - connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
|
| + connection_.SendStreamDataWithStringWithFec(3, "foo", 6, !kFin, NULL);
|
|
|
| QuicAckFrame ack_fec = InitAckFrame(5, 1);
|
| // Ack all data packets, but no fec packets.
|
| @@ -1662,28 +1693,29 @@ TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) {
|
| }
|
|
|
| TEST_P(QuicConnectionTest, FramePackingFEC) {
|
| - // Enable fec.
|
| - QuicPacketGeneratorPeer::SwitchFecProtectionOn(
|
| - QuicConnectionPeer::GetPacketGenerator(&connection_), 6);
|
| + // Enable FEC.
|
| + QuicConnectionPeer::GetPacketCreator(
|
| + &connection_)->set_max_packets_per_fec_group(6);
|
|
|
| CongestionBlockWrites();
|
|
|
| - // Send an ack and two stream frames in 1 packet by queueing them.
|
| - connection_.SendAck();
|
| + // Queue an ack and two stream frames. Ack gets flushed when FEC is turned on
|
| + // for sending protected data; two stream frames are packing in 1 packet.
|
| EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
|
| - IgnoreResult(InvokeWithoutArgs(&connection_,
|
| - &TestConnection::SendStreamData3)),
|
| - IgnoreResult(InvokeWithoutArgs(&connection_,
|
| - &TestConnection::SendStreamData5))));
|
| + IgnoreResult(InvokeWithoutArgs(
|
| + &connection_, &TestConnection::SendStreamData3WithFec)),
|
| + IgnoreResult(InvokeWithoutArgs(
|
| + &connection_, &TestConnection::SendStreamData5WithFec))));
|
| + connection_.SendAck();
|
|
|
| - EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
|
| + EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
|
| CongestionUnblockWrites();
|
| connection_.GetSendAlarm()->Fire();
|
| EXPECT_EQ(0u, connection_.NumQueuedPackets());
|
| EXPECT_FALSE(connection_.HasQueuedData());
|
|
|
| // Parse the last packet and ensure it's in an fec group.
|
| - EXPECT_EQ(1u, writer_->header().fec_group);
|
| + EXPECT_EQ(2u, writer_->header().fec_group);
|
| EXPECT_EQ(0u, writer_->frame_count());
|
| }
|
|
|
| @@ -1732,7 +1764,7 @@ TEST_P(QuicConnectionTest, FramePackingSendv) {
|
| IOVector data_iov;
|
| data_iov.AppendNoCoalesce(data, 2);
|
| data_iov.AppendNoCoalesce(data + 2, 2);
|
| - connection_.SendStreamData(1, data_iov, 0, !kFin, NULL);
|
| + connection_.SendStreamData(1, data_iov, 0, !kFin, MAY_FEC_PROTECT, NULL);
|
|
|
| EXPECT_EQ(0u, connection_.NumQueuedPackets());
|
| EXPECT_FALSE(connection_.HasQueuedData());
|
| @@ -1757,7 +1789,7 @@ TEST_P(QuicConnectionTest, FramePackingSendvQueued) {
|
| IOVector data_iov;
|
| data_iov.AppendNoCoalesce(data, 2);
|
| data_iov.AppendNoCoalesce(data + 2, 2);
|
| - connection_.SendStreamData(1, data_iov, 0, !kFin, NULL);
|
| + connection_.SendStreamData(1, data_iov, 0, !kFin, MAY_FEC_PROTECT, NULL);
|
|
|
| EXPECT_EQ(1u, connection_.NumQueuedPackets());
|
| EXPECT_TRUE(connection_.HasQueuedData());
|
| @@ -1777,7 +1809,7 @@ TEST_P(QuicConnectionTest, SendingZeroBytes) {
|
| // Send a zero byte write with a fin using writev.
|
| EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
|
| IOVector empty_iov;
|
| - connection_.SendStreamData(1, empty_iov, 0, kFin, NULL);
|
| + connection_.SendStreamData(1, empty_iov, 0, kFin, MAY_FEC_PROTECT, NULL);
|
|
|
| EXPECT_EQ(0u, connection_.NumQueuedPackets());
|
| EXPECT_FALSE(connection_.HasQueuedData());
|
|
|