chromium/net/third_party/quiche/src/quiche/quic/core/quic_packet_creator_test.cc

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "quiche/quic/core/quic_packet_creator.h"

#include <cstdint>
#include <limits>
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>

#include "absl/base/macros.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "quiche/quic/core/crypto/quic_decrypter.h"
#include "quiche/quic/core/crypto/quic_encrypter.h"
#include "quiche/quic/core/frames/quic_frame.h"
#include "quiche/quic/core/frames/quic_stream_frame.h"
#include "quiche/quic/core/quic_connection_id.h"
#include "quiche/quic/core/quic_data_writer.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/platform/api/quic_expect_bug.h"
#include "quiche/quic/platform/api/quic_flags.h"
#include "quiche/quic/platform/api/quic_socket_address.h"
#include "quiche/quic/platform/api/quic_test.h"
#include "quiche/quic/test_tools/quic_framer_peer.h"
#include "quiche/quic/test_tools/quic_packet_creator_peer.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/quic/test_tools/simple_data_producer.h"
#include "quiche/quic/test_tools/simple_quic_framer.h"
#include "quiche/common/simple_buffer_allocator.h"
#include "quiche/common/test_tools/quiche_test_utils.h"

_;
AtLeast;
DoAll;
InSequence;
Invoke;
Return;
SaveArg;
StrictMock;

namespace quic {
namespace test {
namespace {

const QuicPacketNumber kPacketNumber =;
// Use fields in which each byte is distinct to ensure that every byte is
// framed correctly. The values are otherwise arbitrary.
QuicConnectionId CreateTestConnectionId() {}

// Run tests with combinations of {ParsedQuicVersion,
// ToggleVersionSerialization}.
struct TestParams {};

// Used by ::testing::PrintToStringParamName().
std::string PrintToString(const TestParams& p) {}

// Constructs various test permutations.
std::vector<TestParams> GetTestParams() {}

class MockDebugDelegate : public QuicPacketCreator::DebugDelegate {};

class TestPacketCreator : public QuicPacketCreator {};

class QuicPacketCreatorTest : public QuicTestWithParam<TestParams> {};

// Run all packet creator tests with all supported versions of QUIC, and with
// and without version in the packet header, as well as doing a run for each
// length of truncated connection id.
INSTANTIATE_TEST_SUITE_P();

TEST_P(QuicPacketCreatorTest, SerializeFrames) {}

TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) {}

TEST_P(QuicPacketCreatorTest, SerializePacketWithPadding) {}

TEST_P(QuicPacketCreatorTest, SerializeLargerPacketWithPadding) {}

TEST_P(QuicPacketCreatorTest, IncreaseMaxPacketLengthWithFramesPending) {}

TEST_P(QuicPacketCreatorTest, ConsumeCryptoDataToFillCurrentPacket) {}

TEST_P(QuicPacketCreatorTest, ConsumeDataToFillCurrentPacket) {}

TEST_P(QuicPacketCreatorTest, ConsumeDataFin) {}

TEST_P(QuicPacketCreatorTest, ConsumeDataFinOnly) {}

TEST_P(QuicPacketCreatorTest, CreateAllFreeBytesForStreamFrames) {}

TEST_P(QuicPacketCreatorTest, StreamFrameConsumption) {}

TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) {}

TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) {}

// Test that the path challenge connectivity probing packet is serialized
// correctly as a padded PATH CHALLENGE packet.
TEST_P(QuicPacketCreatorTest, BuildPathChallengePacket) {}

TEST_P(QuicPacketCreatorTest, BuildConnectivityProbingPacket) {}

// Several tests that the path response connectivity probing packet is
// serialized correctly as either a padded and unpadded PATH RESPONSE
// packet. Also generates packets with 1 and 3 PATH_RESPONSES in them to
// exercised the single- and multiple- payload cases.
TEST_P(QuicPacketCreatorTest, BuildPathResponsePacket1ResponseUnpadded) {}

TEST_P(QuicPacketCreatorTest, BuildPathResponsePacket1ResponsePadded) {}

TEST_P(QuicPacketCreatorTest, BuildPathResponsePacket3ResponsesUnpadded) {}

TEST_P(QuicPacketCreatorTest, BuildPathResponsePacket3ResponsesPadded) {}

TEST_P(QuicPacketCreatorTest, SerializeConnectivityProbingPacket) {}

TEST_P(QuicPacketCreatorTest, SerializePathChallengeProbePacket) {}

TEST_P(QuicPacketCreatorTest, SerializePathResponseProbePacket1PayloadPadded) {}

TEST_P(QuicPacketCreatorTest,
       SerializePathResponseProbePacket1PayloadUnPadded) {}

TEST_P(QuicPacketCreatorTest, SerializePathResponseProbePacket2PayloadsPadded) {}

TEST_P(QuicPacketCreatorTest,
       SerializePathResponseProbePacket2PayloadsUnPadded) {}

TEST_P(QuicPacketCreatorTest, SerializePathResponseProbePacket3PayloadsPadded) {}

TEST_P(QuicPacketCreatorTest,
       SerializePathResponseProbePacket3PayloadsUnpadded) {}

TEST_P(QuicPacketCreatorTest, SerializeLargePacketNumberConnectionClosePacket) {}

TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthLeastAwaiting) {}

TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthCwnd) {}

TEST_P(QuicPacketCreatorTest, SkipNPacketNumbers) {}

TEST_P(QuicPacketCreatorTest, SerializeFrame) {}

TEST_P(QuicPacketCreatorTest, SerializeFrameShortData) {}

void QuicPacketCreatorTest::TestChaosProtection(bool enabled) {}

TEST_P(QuicPacketCreatorTest, ChaosProtectionEnabled) {}

TEST_P(QuicPacketCreatorTest, ChaosProtectionDisabled) {}

TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) {}

TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) {}

TEST_P(QuicPacketCreatorTest, SerializeAndSendStreamFrame) {}

TEST_P(QuicPacketCreatorTest, SerializeStreamFrameWithPadding) {}

TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) {}

TEST_P(QuicPacketCreatorTest, SendStreamDataWithEncryptionHandshake) {}

TEST_P(QuicPacketCreatorTest, ChloTooLarge) {}

TEST_P(QuicPacketCreatorTest, PendingPadding) {}

TEST_P(QuicPacketCreatorTest, FullPaddingDoesNotConsumePendingPadding) {}

TEST_P(QuicPacketCreatorTest, ConsumeDataAndRandomPadding) {}

TEST_P(QuicPacketCreatorTest, FlushWithExternalBuffer) {}

// Test for error found in
// https://bugs.chromium.org/p/chromium/issues/detail?id=859949 where a gap
// length that crosses an IETF VarInt length boundary would cause a
// failure. While this test is not applicable to versions other than version 99,
// it should still work. Hence, it is not made version-specific.
TEST_P(QuicPacketCreatorTest, IetfAckGapErrorRegression) {}

TEST_P(QuicPacketCreatorTest, AddMessageFrame) {}

TEST_P(QuicPacketCreatorTest, MessageFrameConsumption) {}

TEST_P(QuicPacketCreatorTest, GetGuaranteedLargestMessagePayload) {}

TEST_P(QuicPacketCreatorTest, GetCurrentLargestMessagePayload) {}

TEST_P(QuicPacketCreatorTest, PacketTransmissionType) {}

TEST_P(QuicPacketCreatorTest,
       PacketBytesRetransmitted_AddFrame_Retransmission) {}

TEST_P(QuicPacketCreatorTest,
       PacketBytesRetransmitted_AddFrame_NotRetransmission) {}

TEST_P(QuicPacketCreatorTest, PacketBytesRetransmitted_AddFrame_MixedFrames) {}

TEST_P(QuicPacketCreatorTest,
       PacketBytesRetransmitted_CreateAndSerializeStreamFrame_Retransmission) {}

TEST_P(
    QuicPacketCreatorTest,
    PacketBytesRetransmitted_CreateAndSerializeStreamFrame_NotRetransmission) {}

TEST_P(QuicPacketCreatorTest, RetryToken) {}

TEST_P(QuicPacketCreatorTest, GetConnectionId) {}

TEST_P(QuicPacketCreatorTest, ClientConnectionId) {}

TEST_P(QuicPacketCreatorTest, CoalesceStreamFrames) {}

TEST_P(QuicPacketCreatorTest, SaveNonRetransmittableFrames) {}

TEST_P(QuicPacketCreatorTest, SerializeCoalescedPacket) {}

TEST_P(QuicPacketCreatorTest, SoftMaxPacketLength) {}

TEST_P(QuicPacketCreatorTest,
       ChangingEncryptionLevelRemovesSoftMaxPacketLength) {}

TEST_P(QuicPacketCreatorTest, MinPayloadLength) {}

// A variant of StreamFrameConsumption that tests when expansion of the stream
// frame puts it at or over the max length, but the packet is supposed to be
// padded to max length.
TEST_P(QuicPacketCreatorTest, PadWhenAlmostMaxLength) {}

TEST_P(QuicPacketCreatorTest, MorePendingPaddingThanBytesFree) {}

class MockDelegate : public QuicPacketCreator::DelegateInterface {};

// Simple struct for describing the contents of a packet.
// Useful in conjunction with a SimpleQuicFrame for validating that a packet
// contains the expected frames.
struct PacketContents {};

class MultiplePacketsTestPacketCreator : public QuicPacketCreator {};

class QuicPacketCreatorMultiplePacketsTest : public QuicTest {};

TEST_F(QuicPacketCreatorMultiplePacketsTest, AddControlFrame_NotWritable) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       WrongEncryptionLevelForStreamDataFastPath) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, AddControlFrame_OnlyAckWritable) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       AddControlFrame_WritableAndShouldNotFlush) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       AddControlFrame_NotWritableBatchThenFlush) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       AddControlFrame_WritableAndShouldFlush) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeCryptoData) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeCryptoDataCheckShouldGeneratePacket) {}

// Tests the case that after bundling data, send window reduced to be shorter
// than data.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeDataAdjustWriteLengthAfterBundledData) {}

// Tests the case that after bundling data, send window is exactly as big as
// data length.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeDataDoesNotAdjustWriteLengthAfterBundledData) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeData_NotWritable) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeData_WritableAndShouldNotFlush) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeData_WritableAndShouldFlush) {}

// Test the behavior of ConsumeData when the data consumed is for the crypto
// handshake stream.  Ensure that the packet is always sent and padded even if
// the creator operates in batch mode.
TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeData_Handshake) {}

// Test the behavior of ConsumeData when the data is for the crypto handshake
// stream, but padding is disabled.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeData_Handshake_PaddingDisabled) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeData_EmptyData) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeDataMultipleTimes_WritableAndShouldNotFlush) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeData_BatchOperations) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConsumeData_FramesPreviouslyQueued) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeDataFastPath) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeDataLarge) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeDataLargeSendAckFalse) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConsumeDataLargeSendAckTrue) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, NotWritableThenBatchOperations) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, NotWritableThenBatchOperations2) {}

// Regression test of b/120493795.
TEST_F(QuicPacketCreatorMultiplePacketsTest, PacketTransmissionType) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, TestConnectionIdLength) {}

// Test whether SetMaxPacketLength() works in the situation when the queue is
// empty, and we send three packets worth of data.
TEST_F(QuicPacketCreatorMultiplePacketsTest, SetMaxPacketLength_Initial) {}

// Test whether SetMaxPacketLength() works in the situation when we first write
// data, then change packet size, then write data again.
TEST_F(QuicPacketCreatorMultiplePacketsTest, SetMaxPacketLength_Middle) {}

// Test whether SetMaxPacketLength() works correctly when we force the change of
// the packet size in the middle of the batched packet.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       SetMaxPacketLength_MidpacketFlush) {}

// Test sending a connectivity probing packet.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       GenerateConnectivityProbingPacket) {}

// Test sending an MTU probe, without any surrounding data.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       GenerateMtuDiscoveryPacket_Simple) {}

// Test sending an MTU probe.  Surround it with data, to ensure that it resets
// the MTU to the value before the probe was sent.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       GenerateMtuDiscoveryPacket_SurroundedByData) {}

// Regression test for b/31486443.
TEST_F(QuicPacketCreatorMultiplePacketsTest,
       ConnectionCloseFrameLargerThanPacketSize) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       RandomPaddingAfterFinSingleStreamSinglePacket) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       RandomPaddingAfterFinSingleStreamMultiplePackets) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       RandomPaddingAfterFinMultipleStreamsMultiplePackets) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, AddMessageFrame) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest, ConnectionId) {}

// Regresstion test for b/159812345.
TEST_F(QuicPacketCreatorMultiplePacketsTest, ExtraPaddingNeeded) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       PeerAddressContextWithSameAddress) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       PeerAddressContextWithDifferentAddress) {}

TEST_F(QuicPacketCreatorMultiplePacketsTest,
       NestedPeerAddressContextWithDifferentAddress) {}

}  // namespace
}  // namespace test
}  // namespace quic