#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <algorithm>
#include <ostream>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "net/base/chunked_upload_data_stream.h"
#include "net/base/completion_once_callback.h"
#include "net/base/features.h"
#include "net/base/ip_endpoint.h"
#include "net/base/mock_network_change_notifier.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_server.h"
#include "net/base/proxy_string_util.h"
#include "net/base/schemeful_site.h"
#include "net/base/test_completion_callback.h"
#include "net/base/test_proxy_delegate.h"
#include "net/cert/mock_cert_verifier.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_connection_info.h"
#include "net/http/http_network_session.h"
#include "net/http/http_network_transaction.h"
#include "net/http/http_proxy_connect_job.h"
#include "net/http/http_server_properties.h"
#include "net/http/http_stream.h"
#include "net/http/http_stream_factory.h"
#include "net/http/http_transaction_test_util.h"
#include "net/http/test_upload_data_stream_not_allow_http1.h"
#include "net/http/transport_security_state.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_util.h"
#include "net/proxy_resolution/configured_proxy_resolution_service.h"
#include "net/proxy_resolution/proxy_config_service_fixed.h"
#include "net/proxy_resolution/proxy_resolver.h"
#include "net/quic/crypto/proof_verifier_chromium.h"
#include "net/quic/mock_crypto_client_stream_factory.h"
#include "net/quic/mock_quic_context.h"
#include "net/quic/mock_quic_data.h"
#include "net/quic/quic_chromium_alarm_factory.h"
#include "net/quic/quic_context.h"
#include "net/quic/quic_http_stream.h"
#include "net/quic/quic_http_utils.h"
#include "net/quic/quic_session_pool_peer.h"
#include "net/quic/quic_socket_data_provider.h"
#include "net/quic/quic_test_packet_maker.h"
#include "net/quic/test_task_runner.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/mock_client_socket_pool_manager.h"
#include "net/socket/next_proto.h"
#include "net/socket/socket_performance_watcher.h"
#include "net/socket/socket_performance_watcher_factory.h"
#include "net/socket/socket_tag.h"
#include "net/socket/socket_test_util.h"
#include "net/spdy/spdy_test_util_common.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/test/cert_test_util.h"
#include "net/test/gtest_util.h"
#include "net/test/test_data_directory.h"
#include "net/test/test_with_task_environment.h"
#include "net/third_party/quiche/src/quiche/common/http/http_header_block.h"
#include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_decrypter.h"
#include "net/third_party/quiche/src/quiche/quic/core/crypto/quic_encrypter.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_framer.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_utils.h"
#include "net/third_party/quiche/src/quiche/quic/platform/api/quic_test.h"
#include "net/third_party/quiche/src/quiche/quic/test_tools/crypto_test_utils.h"
#include "net/third_party/quiche/src/quiche/quic/test_tools/mock_clock.h"
#include "net/third_party/quiche/src/quiche/quic/test_tools/mock_random.h"
#include "net/third_party/quiche/src/quiche/quic/test_tools/quic_spdy_session_peer.h"
#include "net/third_party/quiche/src/quiche/quic/test_tools/quic_test_utils.h"
#include "net/third_party/quiche/src/quiche/spdy/core/spdy_frame_builder.h"
#include "net/third_party/quiche/src/quiche/spdy/core/spdy_framer.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_test_util.h"
#include "net/websockets/websocket_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "url/gurl.h"
ElementsAre;
Key;
namespace net::test {
namespace {
enum DestinationType { … };
const char kDefaultServerHostName[] = …;
const char kDifferentHostname[] = …;
constexpr std::string_view kQuic200RespStatusLine = …;
constexpr std::string_view kQuicRespData = …;
const char kHttpRespData[] = …;
struct TestParams { … };
std::string PrintToString(const TestParams& p) { … }
struct PoolingTestParams { … };
std::string PrintToString(const PoolingTestParams& p) { … }
std::string GenerateQuicAltSvcHeaderValue(
const quic::ParsedQuicVersionVector& versions,
std::string host,
uint16_t port) { … }
std::string GenerateQuicAltSvcHeaderValue(
const quic::ParsedQuicVersionVector& versions,
uint16_t port) { … }
std::string GenerateQuicAltSvcHeader(
const quic::ParsedQuicVersionVector& versions) { … }
std::vector<TestParams> GetTestParams() { … }
std::vector<PoolingTestParams> GetPoolingTestParams() { … }
std::string ConstructDataFrameForVersion(std::string_view body,
quic::ParsedQuicVersion version) { … }
}
class TestSocketPerformanceWatcher : public SocketPerformanceWatcher { … };
class TestSocketPerformanceWatcherFactory
: public SocketPerformanceWatcherFactory { … };
class QuicNetworkTransactionTest
: public PlatformTest,
public ::testing::WithParamInterface<TestParams>,
public WithTaskEnvironment { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(QuicNetworkTransactionTest, BasicRequestAndResponse) { … }
TEST_P(QuicNetworkTransactionTest, HeaderDecodingDelayHistogram) { … }
TEST_P(QuicNetworkTransactionTest, BasicRequestAndResponseWithAsycWrites) { … }
TEST_P(QuicNetworkTransactionTest, BasicRequestAndResponseWithTrailers) { … }
TEST_P(QuicNetworkTransactionTest, BasicRequestAndResponseWithEmptyTrailers) { … }
TEST_P(QuicNetworkTransactionTest, WriteErrorHandshakeConfirmed) { … }
TEST_P(QuicNetworkTransactionTest, WriteErrorHandshakeConfirmedAsync) { … }
TEST_P(QuicNetworkTransactionTest, SocketWatcherEnabled) { … }
TEST_P(QuicNetworkTransactionTest, SocketWatcherDisabled) { … }
TEST_P(QuicNetworkTransactionTest, ForceQuic) { … }
TEST_P(QuicNetworkTransactionTest, ResetOnEmptyResponseHeaders) { … }
TEST_P(QuicNetworkTransactionTest, LargeResponseHeaders) { … }
TEST_P(QuicNetworkTransactionTest, TooLargeResponseHeaders) { … }
TEST_P(QuicNetworkTransactionTest, RedirectMultipleLocations) { … }
TEST_P(QuicNetworkTransactionTest, ForceQuicForAll) { … }
TEST_P(QuicNetworkTransactionTest, 408Response) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxy) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { … }
TEST_P(QuicNetworkTransactionTest, AlternativeServicesDifferentHost) { … }
TEST_P(QuicNetworkTransactionTest, DoNotUseQuicForUnsupportedVersion) { … }
TEST_P(QuicNetworkTransactionTest, RetryMisdirectedRequest) { … }
TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { … }
TEST_P(QuicNetworkTransactionTest, DoNotForceQuicForHttps) { … }
TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuic) { … }
TEST_P(QuicNetworkTransactionTest, UseIetfAlternativeServiceForQuic) { … }
TEST_P(QuicNetworkTransactionTest,
UseAlternativeServiceForQuicWithNetworkAnonymizationKey) { … }
TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceWithVersionForQuic1) { … }
TEST_P(QuicNetworkTransactionTest,
PickQuicVersionWhenMultipleVersionsAreSupported) { … }
TEST_P(QuicNetworkTransactionTest, SetAlternativeServiceWithScheme) { … }
TEST_P(QuicNetworkTransactionTest, DoNotGetAltSvcForDifferentOrigin) { … }
TEST_P(QuicNetworkTransactionTest,
StoreMutuallySupportedVersionsWhenProcessAltSvc) { … }
TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceAllSupportedVersion) { … }
TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmed) { … }
TEST_P(QuicNetworkTransactionTest, ProtocolErrorAfterHandshakeConfirmed) { … }
TEST_P(QuicNetworkTransactionTest, TimeoutAfterHandshakeConfirmedThenBroken2) { … }
TEST_P(QuicNetworkTransactionTest,
ProtocolErrorAfterHandshakeConfirmedThenBroken) { … }
TEST_P(QuicNetworkTransactionTest,
ProtocolErrorAfterHandshakeConfirmedThenBrokenWithNetworkIsolationKey) { … }
TEST_P(QuicNetworkTransactionTest,
ProtocolErrorAfterHandshakeConfirmedThenBrokenWithUseDnsHttpsSvcbAlpn) { … }
TEST_P(QuicNetworkTransactionTest, ResetAfterHandshakeConfirmedThenBroken) { … }
TEST_P(QuicNetworkTransactionTest, RemoteAltSvcWorkingWhileLocalAltSvcBroken) { … }
TEST_P(QuicNetworkTransactionTest, BrokenAlternativeOnlyRecordedOnce) { … }
TEST_P(QuicNetworkTransactionTest,
ResetPooledAfterHandshakeConfirmedThenBroken) { … }
TEST_P(QuicNetworkTransactionTest,
DoNotUseAlternativeServiceQuicUnsupportedVersion) { … }
TEST_P(QuicNetworkTransactionTest, UseExistingAlternativeServiceForQuic) { … }
TEST_P(QuicNetworkTransactionTest, PoolByOrigin) { … }
TEST_P(QuicNetworkTransactionTest, PoolByDestination) { … }
TEST_P(QuicNetworkTransactionTest,
UseSharedExistingAlternativeServiceForQuicWithValidCert) { … }
TEST_P(QuicNetworkTransactionTest, AlternativeServiceDifferentPort) { … }
TEST_P(QuicNetworkTransactionTest, ConfirmAlternativeService) { … }
TEST_P(QuicNetworkTransactionTest,
ConfirmAlternativeServiceWithNetworkIsolationKey) { … }
TEST_P(QuicNetworkTransactionTest, UseAlternativeServiceForQuicForHttps) { … }
TEST_P(QuicNetworkTransactionTest, HungAlternativeService) { … }
TEST_P(QuicNetworkTransactionTest, ZeroRTTWithHttpRace) { … }
TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { … }
TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { … }
TEST_P(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) { … }
TEST_P(QuicNetworkTransactionTest, ZeroRTTWithTooEarlyResponse) { … }
TEST_P(QuicNetworkTransactionTest, ZeroRTTWithMultipleTooEarlyResponse) { … }
TEST_P(QuicNetworkTransactionTest,
LogGranularQuicErrorCodeOnQuicProtocolErrorLocal) { … }
TEST_P(QuicNetworkTransactionTest,
LogGranularQuicErrorCodeOnQuicProtocolErrorRemote) { … }
TEST_P(QuicNetworkTransactionTest, RstStreamErrorHandling) { … }
TEST_P(QuicNetworkTransactionTest, RstStreamBeforeHeaders) { … }
TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocol) { … }
TEST_P(QuicNetworkTransactionTest,
BrokenAlternateProtocolWithNetworkIsolationKey) { … }
TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { … }
TEST_P(QuicNetworkTransactionTest, NoBrokenAlternateProtocolIfTcpFails) { … }
TEST_P(QuicNetworkTransactionTest, DelayTCPOnStartWithQuicSupportOnSameIP) { … }
TEST_P(QuicNetworkTransactionTest,
DelayTCPOnStartWithQuicSupportOnDifferentIP) { … }
TEST_P(QuicNetworkTransactionTest, NetErrorDetailsSetBeforeHandshake) { … }
TEST_P(QuicNetworkTransactionTest, FailedZeroRttBrokenAlternateProtocol) { … }
TEST_P(QuicNetworkTransactionTest,
FailedZeroRttBrokenAlternateProtocolWithNetworkIsolationKey) { … }
TEST_P(QuicNetworkTransactionTest, BrokenAlternateProtocolOnConnectFailure) { … }
TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnect) { … }
TEST_P(QuicNetworkTransactionTest, ConnectionCloseDuringConnectProxy) { … }
TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { … }
TEST_P(QuicNetworkTransactionTest, QuicUpload) { … }
TEST_P(QuicNetworkTransactionTest, QuicUploadWriteError) { … }
TEST_P(QuicNetworkTransactionTest, RetryAfterAsyncNoBufferSpace) { … }
TEST_P(QuicNetworkTransactionTest, RetryAfterSynchronousNoBufferSpace) { … }
TEST_P(QuicNetworkTransactionTest, MaxRetriesAfterAsyncNoBufferSpace) { … }
TEST_P(QuicNetworkTransactionTest, MaxRetriesAfterSynchronousNoBufferSpace) { … }
TEST_P(QuicNetworkTransactionTest, NoMigrationForMsgTooBig) { … }
TEST_P(QuicNetworkTransactionTest, QuicForceHolBlocking) { … }
TEST_P(QuicNetworkTransactionTest, HostInAllowlist) { … }
TEST_P(QuicNetworkTransactionTest, HostNotInAllowlist) { … }
class QuicNetworkTransactionWithDestinationTest
: public PlatformTest,
public ::testing::WithParamInterface<PoolingTestParams>,
public WithTaskEnvironment { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(QuicNetworkTransactionWithDestinationTest, InvalidCertificate) { … }
TEST_P(QuicNetworkTransactionWithDestinationTest, PoolIfCertificateValid) { … }
TEST_P(QuicNetworkTransactionWithDestinationTest,
DoNotPoolIfCertificateInvalid) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectHttpsServer) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectSpdyServer) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectQuicServer) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectHttpServer) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectReuseTransportSocket) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectReuseQuicSession) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectNoReuseDifferentChains) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectFailure) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyQuicConnectionError) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyConnectBadCertificate) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyUserAgent) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyRequestPriority) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyMultipleRequestsError) { … }
TEST_P(QuicNetworkTransactionTest, QuicProxyAuth) { … }
TEST_P(QuicNetworkTransactionTest, NetworkIsolation) { … }
TEST_P(QuicNetworkTransactionTest, NetworkIsolationTunnel) { … }
TEST_P(QuicNetworkTransactionTest, AllowHTTP1FalseProhibitsH1) { … }
TEST_P(QuicNetworkTransactionTest, AllowHTTP1MockTest) { … }
TEST_P(QuicNetworkTransactionTest, AllowHTTP1UploadPauseAndResume) { … }
TEST_P(QuicNetworkTransactionTest, AllowHTTP1UploadFailH1AndResumeQuic) { … }
TEST_P(QuicNetworkTransactionTest, IncorrectHttp3GoAway) { … }
TEST_P(QuicNetworkTransactionTest, RetryOnHttp3GoAway) { … }
#if BUILDFLAG(ENABLE_WEBSOCKETS)
TEST_P(QuicNetworkTransactionTest, WebsocketOpensNewConnectionWithHttp1) { … }
TEST_P(QuicNetworkTransactionTest,
WebsocketOpensNewConnectionWithHttp1AfterAltSvcQuic) { … }
TEST_P(QuicNetworkTransactionTest,
WebsocketOpensNewConnectionWithHttp1AfterDnsHttpsSvcbAlpn) { … }
#endif
}