chromium/net/http/http_stream_pool_attempt_manager_unittest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/http/http_stream_pool_attempt_manager.h"

#include <list>
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "net/base/completion_once_callback.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_states.h"
#include "net/base/load_timing_info.h"
#include "net/base/net_error_details.h"
#include "net/base/net_errors.h"
#include "net/base/privacy_mode.h"
#include "net/base/request_priority.h"
#include "net/dns/host_resolver.h"
#include "net/dns/public/resolve_error_info.h"
#include "net/http/alternative_service.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_info.h"
#include "net/http/http_server_properties.h"
#include "net/http/http_stream_factory_test_util.h"
#include "net/http/http_stream_pool.h"
#include "net/http/http_stream_pool_group.h"
#include "net/http/http_stream_pool_handle.h"
#include "net/http/http_stream_pool_test_util.h"
#include "net/log/test_net_log.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_test_packet_maker.h"
#include "net/socket/next_proto.h"
#include "net/socket/socket_test_util.h"
#include "net/socket/stream_socket_handle.h"
#include "net/socket/tcp_stream_attempt.h"
#include "net/spdy/spdy_http_stream.h"
#include "net/spdy/spdy_test_util_common.h"
#include "net/ssl/ssl_cert_request_info.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/quic/core/quic_error_codes.h"
#include "net/third_party/quiche/src/quiche/quic/core/quic_versions.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "url/scheme_host_port.h"

_;
Optional;

namespace net {

IsError;
IsOk;
MockQuicData;
QuicTestPacketMaker;

Group;
AttemptManager;

namespace {

IPEndPoint MakeIPEndPoint(std::string_view addr, uint16_t port = 80) {}

void ValidateConnectTiming(LoadTimingInfo::ConnectTiming& connect_timing) {}

// A helper to create an HttpStreamKey.
class StreamKeyBuilder {};

class Preconnector {};

// A helper to request an HttpStream. On success, it keeps the provided
// HttpStream. On failure, it keeps error information.
class StreamRequester : public HttpStreamRequest::Delegate {};

constexpr std::string_view kDefaultServerName =;
constexpr std::string_view kDefaultDestination =;

}  // namespace

class HttpStreamPoolAttemptManagerTest : public TestWithTaskEnvironment {};

TEST_F(HttpStreamPoolAttemptManagerTest, ResolveEndpointFailedSync) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ResolveEndpointFailedMultipleRequests) {}

TEST_F(HttpStreamPoolAttemptManagerTest, LoadState) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ResolveErrorInfo) {}

TEST_F(HttpStreamPoolAttemptManagerTest, DnsAliases) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ConnectTiming) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ConnectTimingDnsResolutionNotFinished) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SetPriority) {}

TEST_F(HttpStreamPoolAttemptManagerTest, TcpFailSync) {}

TEST_F(HttpStreamPoolAttemptManagerTest, TcpFailAsync) {}

TEST_F(HttpStreamPoolAttemptManagerTest, TlsOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, TlsCryptoReadyDelayed) {}

TEST_F(HttpStreamPoolAttemptManagerTest, CertificateError) {}

TEST_F(HttpStreamPoolAttemptManagerTest, NeedsClientAuth) {}

// Tests that after a fatal error (e.g., the server required a client cert),
// following attempt failures are ignored and the existing requests get the
// same fatal error.
TEST_F(HttpStreamPoolAttemptManagerTest, TcpFailAfterNeedsClientAuth) {}

TEST_F(HttpStreamPoolAttemptManagerTest, RequestCancelledBeforeAttemptSuccess) {}

TEST_F(HttpStreamPoolAttemptManagerTest, OneIPEndPointFailed) {}

TEST_F(HttpStreamPoolAttemptManagerTest, IPEndPointTimedout) {}

TEST_F(HttpStreamPoolAttemptManagerTest, IPEndPointsSlow) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       PauseSlowTimerAfterTcpHandshakeForTls) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ReachedGroupLimit) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ReachedPoolLimit) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ReachedPoolLimitHighPriorityGroupFirst) {}

TEST_F(HttpStreamPoolAttemptManagerTest, RequestStreamIdleStreamSocket) {}

TEST_F(HttpStreamPoolAttemptManagerTest, UseIdleStreamSocketAfterRelease) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       CloseIdleStreamAttemptConnectionReachedPoolLimit) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ProcessPendingRequestDnsResolutionOngoing) {}

// Tests that all in-flight requests and connection attempts are canceled
// when an IP address change event happens.
TEST_F(HttpStreamPoolAttemptManagerTest,
       CancelAttemptAndRequestsOnIPAddressChange) {}

// Tests that the network change error is reported even when a different error
// has already happened.
TEST_F(HttpStreamPoolAttemptManagerTest, IPAddressChangeAfterNeedsClientAuth) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SSLConfigChangedCloseIdleStream) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       SSLConfigChangedReleasedStreamGenerationOutdated) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SSLConfigForServersChanged) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyAvailableSession) {}

// Test that setting the priority for a request that will be served via an
// existing SPDY session doesn't crash the network service.
TEST_F(HttpStreamPoolAttemptManagerTest, ChangePriorityForPooledStreamRequest) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyCreateSessionFail) {}

TEST_F(HttpStreamPoolAttemptManagerTest, RequireHttp11AfterSpdySessionCreated) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       RequireHttp11AfterSpdySessionCreatedRequestDestroyed) {}

TEST_F(HttpStreamPoolAttemptManagerTest, DoNotUseSpdySessionForHttpRequest) {}

TEST_F(HttpStreamPoolAttemptManagerTest, CloseIdleSpdySessionWhenPoolStalled) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       PreconnectRequireHttp11AfterSpdySessionCreated) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyReachedPoolLimit) {}

// In the following SPDY IP-based pooling tests, we use spdy_pooling.pem that
// has "www.example.org" and "example.test" as alternate names.

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyMatchingIpSessionOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyPreconnectMatchingIpSession) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       SpdyMatchingIpSessionAlreadyHaveSession) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       SpdyMatchingIpSessionDnsResolutionFinishSynchronously) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyMatchingIpSessionDisabled) {}

TEST_F(HttpStreamPoolAttemptManagerTest, SpdyMatchingIpSessionKeyMismatch) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       SpdyMatchingIpSessionVerifyDomainFailed) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ThrottleAttemptForSpdyBlockSecondAttempt) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ThrottleAttemptForSpdyDelayPassedHttp2) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       ThrottleAttemptForSpdyDelayPassedHttp1) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectSpdySessionAvailable) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectActiveStreamsAvailable) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectFail) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectMultipleStreamsHttp1) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectMultipleStreamsHttp2) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectRequireHttp1) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectMultipleStreamsOkAndFail) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectMultipleStreamsFailAndOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectMultipleRequests) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectReachedGroupLimit) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectReachedPoolLimit) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       RequestStreamAndPreconnectWhileFailing) {}

TEST_F(HttpStreamPoolAttemptManagerTest, PreconnectPriority) {}

// Tests that when an AttemptManager is failing, it's not treated as stalled.
TEST_F(HttpStreamPoolAttemptManagerTest, FailingIsNotStalled) {}

// Tests that when an AttemptManager has a SPDY session, it's not treated as
// stalled.
TEST_F(HttpStreamPoolAttemptManagerTest, HavingSpdySessionIsNotStalled) {}

// Tests that when an AttemptManager has a QUIC session, it's not treated as
// stalled.
TEST_F(HttpStreamPoolAttemptManagerTest, HavingQuicSessionIsNotStalled) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ReuseTypeUnused) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ReuseTypeUnusedIdle) {}

TEST_F(HttpStreamPoolAttemptManagerTest, ReuseTypeReusedIdle) {}

TEST_F(HttpStreamPoolAttemptManagerTest, QuicOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, QuicOkDnsAlpn) {}

TEST_F(HttpStreamPoolAttemptManagerTest, QuicCanUseExistingSession) {}

TEST_F(HttpStreamPoolAttemptManagerTest, AlternativeSerivcesDisabled) {}

// Tests that QUIC attempt fails when there is no known QUIC version and the
// DNS resolution indicates that the endpoint doesn't support QUIC.
TEST_F(HttpStreamPoolAttemptManagerTest, QuicEndpointNotFoundNoDnsAlpn) {}

TEST_F(HttpStreamPoolAttemptManagerTest, QuicPreconnect) {}

// Tests that two destinations that resolve to the same IP address share the
// same QUIC session if allowed.
TEST_F(HttpStreamPoolAttemptManagerTest, QuicMatchingIpSession) {}

// The same as above test, but the ServiceEndpointRequest provides two IP
// addresses separately, the first address does not match the existing session
// and the second address matches the existing session.
TEST_F(HttpStreamPoolAttemptManagerTest,
       QuicMatchingIpSessionOnEndpointsUpdated) {}

// Tests that preconnect completes when there is a QUIC session of which IP
// address matches to the service endpoint resolution of the preconnect.
TEST_F(HttpStreamPoolAttemptManagerTest, QuicPreconnectMatchingIpSession) {}

// Tests that when disabled IP-based pooling, QUIC attempts are also disabled.
// TODO(crbug.com/346835898): Make sure this behavior is what we actually want.
// In production code, we currently disable both IP-based pooling and QUIC at
// the same time.
TEST_F(HttpStreamPoolAttemptManagerTest, QuicMatchingIpSessionDisabled) {}

TEST_F(HttpStreamPoolAttemptManagerTest, DelayStreamAttemptQuicOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, DelayStreamAttemptQuicFail) {}

TEST_F(HttpStreamPoolAttemptManagerTest, DelayStreamAttemptDelayPassed) {}

TEST_F(HttpStreamPoolAttemptManagerTest,
       DelayStreamAttemptDisableAlternativeServicesLater) {}

TEST_F(HttpStreamPoolAttemptManagerTest, OriginsToForceQuicOnOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, OriginsToForceQuicOnFail) {}

TEST_F(HttpStreamPoolAttemptManagerTest, OriginsToForceQuicOnPreconnectOk) {}

TEST_F(HttpStreamPoolAttemptManagerTest, OriginsToForceQuicOnPreconnectFail) {}

TEST_F(HttpStreamPoolAttemptManagerTest, GetInfoAsValue) {}

}  // namespace net