Index: net/quic/quic_connection_test.cc |
diff --git a/net/quic/quic_connection_test.cc b/net/quic/quic_connection_test.cc |
index 1c47f32ccfe8e369146450f9eb8bfe08f6c4d3e8..fddf22a32127c84de4f2434fcc69822ea528caea 100644 |
--- a/net/quic/quic_connection_test.cc |
+++ b/net/quic/quic_connection_test.cc |
@@ -19,6 +19,7 @@ |
#include "net/quic/quic_utils.h" |
#include "net/quic/test_tools/mock_clock.h" |
#include "net/quic/test_tools/mock_random.h" |
+#include "net/quic/test_tools/quic_config_peer.h" |
#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" |
@@ -1514,7 +1515,8 @@ TEST_P(QuicConnectionTest, FECSending) { |
// max_packet_length by 2 so that subsequent packets containing subsequent |
// stream frames with non-zero offets will fit within the packet length. |
size_t length = 2 + GetPacketLengthForOneStream( |
- connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
+ connection_.version(), kIncludeVersion, |
+ PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
IN_FEC_GROUP, &payload_length); |
creator->set_max_packet_length(length); |
@@ -1534,7 +1536,8 @@ TEST_P(QuicConnectionTest, FECQueueing) { |
QuicPacketCreator* creator = |
QuicConnectionPeer::GetPacketCreator(&connection_); |
size_t length = GetPacketLengthForOneStream( |
- connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
+ connection_.version(), kIncludeVersion, |
+ PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
IN_FEC_GROUP, &payload_length); |
creator->set_max_packet_length(length); |
EXPECT_TRUE(creator->IsFecEnabled()); |
@@ -2906,7 +2909,8 @@ TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
// All packets carry version info till version is negotiated. |
size_t payload_length; |
size_t length = GetPacketLengthForOneStream( |
- connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
+ connection_.version(), kIncludeVersion, |
+ PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
NOT_IN_FEC_GROUP, &payload_length); |
QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( |
length); |
@@ -2930,7 +2934,8 @@ TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
// max_packet_length by 2 so that subsequent packets containing subsequent |
// stream frames with non-zero offets will fit within the packet length. |
size_t length = 2 + GetPacketLengthForOneStream( |
- connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
+ connection_.version(), kIncludeVersion, |
+ PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
NOT_IN_FEC_GROUP, &payload_length); |
QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( |
length); |
@@ -2944,6 +2949,58 @@ TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
.bytes_consumed); |
} |
+TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { |
+ ValueRestore<bool> old_flag(&FLAGS_allow_truncated_connection_ids_for_quic, |
+ true); |
+ |
+ // Set up a larger payload than will fit in one packet. |
+ const string payload(connection_.max_packet_length(), 'a'); |
+ EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
+ |
+ // Now send some packets with no truncation. |
+ EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
+ EXPECT_EQ(payload.size(), |
+ connection_.SendStreamDataWithString( |
+ 3, payload, 0, !kFin, nullptr).bytes_consumed); |
+ // Track the size of the second packet here. The overhead will be the largest |
+ // we see in this test, due to the non-truncated CID. |
+ size_t non_truncated_packet_size = writer_->last_packet_size(); |
+ |
+ // Change to a 4 byte CID. |
+ QuicConfig config; |
+ QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4); |
+ connection_.SetFromConfig(config); |
+ EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
+ EXPECT_EQ(payload.size(), |
+ connection_.SendStreamDataWithString( |
+ 3, payload, 0, !kFin, nullptr).bytes_consumed); |
+ // Verify that we have 8 fewer bytes than in the non-truncated case. The |
+ // first packet got 4 bytes of extra payload due to the truncation, and the |
+ // headers here are also 4 byte smaller. |
+ EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8); |
+ |
+ |
+ // Change to a 1 byte CID. |
+ QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1); |
+ connection_.SetFromConfig(config); |
+ EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
+ EXPECT_EQ(payload.size(), |
+ connection_.SendStreamDataWithString( |
+ 3, payload, 0, !kFin, nullptr).bytes_consumed); |
+ // Just like above, we save 7 bytes on payload, and 7 on truncation. |
+ EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2); |
+ |
+ // Change to a 0 byte CID. |
+ QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); |
+ connection_.SetFromConfig(config); |
+ EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
+ EXPECT_EQ(payload.size(), |
+ connection_.SendStreamDataWithString( |
+ 3, payload, 0, !kFin, nullptr).bytes_consumed); |
+ // Just like above, we save 8 bytes on payload, and 8 on truncation. |
+ EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); |
+} |
+ |
TEST_P(QuicConnectionTest, SendDelayedAck) { |
QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); |
EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |