#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include <stdint.h>
#include <optional>
#include <string_view>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/values.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_timing_info.h"
#include "net/base/load_timing_info_test_util.h"
#include "net/base/net_errors.h"
#include "net/base/network_anonymization_key.h"
#include "net/base/privacy_mode.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_string_util.h"
#include "net/base/request_priority.h"
#include "net/base/schemeful_site.h"
#include "net/base/test_completion_callback.h"
#include "net/dns/public/resolve_error_info.h"
#include "net/dns/public/secure_dns_policy.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
#include "net/log/net_log.h"
#include "net/log/net_log_event_type.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_source_type.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_util.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/connect_job_factory.h"
#include "net/socket/datagram_client_socket.h"
#include "net/socket/socket_performance_watcher.h"
#include "net/socket/socket_tag.h"
#include "net/socket/socket_test_util.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/stream_socket.h"
#include "net/socket/transport_client_socket_pool.h"
#include "net/socket/transport_connect_job.h"
#include "net/ssl/ssl_cert_request_info.h"
#include "net/ssl/ssl_config.h"
#include "net/test/gtest_util.h"
#include "net/test/test_with_task_environment.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/scheme_host_port.h"
#include "url/url_constants.h"
IsError;
IsOk;
Invoke;
Return;
namespace net {
namespace {
const int kDefaultMaxSockets = …;
const int kDefaultMaxSocketsPerGroup = …;
constexpr base::TimeDelta kUnusedIdleSocketTimeout = …;
ClientSocketPool::GroupId TestGroupId(
std::string_view host,
int port = 80,
std::string_view scheme = url::kHttpScheme,
PrivacyMode privacy_mode = PrivacyMode::PRIVACY_MODE_DISABLED,
NetworkAnonymizationKey network_anonymization_key =
NetworkAnonymizationKey()) { … }
void TestLoadTimingInfoConnectedReused(const ClientSocketHandle& handle) { … }
void TestLoadTimingInfoConnectedNotReused(const ClientSocketHandle& handle) { … }
void TestLoadTimingInfoNotConnected(const ClientSocketHandle& handle) { … }
class MockClientSocket : public StreamSocket { … };
class TestConnectJob;
class MockClientSocketFactory : public ClientSocketFactory { … };
class TestConnectJob : public ConnectJob { … };
class TestConnectJobFactory : public ConnectJobFactory { … };
}
namespace {
void MockClientSocketFactory::SignalJobs() { … }
void MockClientSocketFactory::SignalJob(size_t job) { … }
void MockClientSocketFactory::SetJobLoadState(size_t job,
LoadState load_state) { … }
void MockClientSocketFactory::SetJobHasEstablishedConnection(size_t job) { … }
class ClientSocketPoolBaseTest : public TestWithTaskEnvironment { … };
TEST_F(ClientSocketPoolBaseTest, BasicSynchronous) { … }
TEST_F(ClientSocketPoolBaseTest, InitConnectionFailure) { … }
TEST_F(ClientSocketPoolBaseTest, ReleaseAndCloseConnection) { … }
TEST_F(ClientSocketPoolBaseTest, SocketWithUnreadDataReturnedToPool) { … }
TEST_F(ClientSocketPoolBaseTest, GroupSeparation) { … }
TEST_F(ClientSocketPoolBaseTest, TotalLimit) { … }
TEST_F(ClientSocketPoolBaseTest, TotalLimitReachedNewGroup) { … }
TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsPriority) { … }
TEST_F(ClientSocketPoolBaseTest, ReprioritizeOne) { … }
TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpReorder) { … }
TEST_F(ClientSocketPoolBaseTest, ReprioritizeUpNoReorder) { … }
TEST_F(ClientSocketPoolBaseTest, ReprioritizeDownReorder) { … }
TEST_F(ClientSocketPoolBaseTest, ReprioritizeResetFIFO) { … }
TEST_F(ClientSocketPoolBaseTest, TotalLimitRespectsGroupLimit) { … }
TEST_F(ClientSocketPoolBaseTest, TotalLimitCountsConnectingSockets) { … }
TEST_F(ClientSocketPoolBaseTest, CorrectlyCountStalledGroups) { … }
TEST_F(ClientSocketPoolBaseTest, StallAndThenCancelAndTriggerAvailableSocket) { … }
TEST_F(ClientSocketPoolBaseTest, CancelStalledSocketAtSocketLimit) { … }
TEST_F(ClientSocketPoolBaseTest, CancelPendingSocketAtSocketLimit) { … }
TEST_F(ClientSocketPoolBaseTest, WaitForStalledSocketAtSocketLimit) { … }
TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketAtSocketLimitDeleteGroup) { … }
TEST_F(ClientSocketPoolBaseTest, PendingRequests) { … }
TEST_F(ClientSocketPoolBaseTest, PendingRequests_NoKeepAlive) { … }
TEST_F(ClientSocketPoolBaseTest, ResetAndCloseSocket) { … }
TEST_F(ClientSocketPoolBaseTest, CancelRequestKeepsConnectJob) { … }
TEST_F(ClientSocketPoolBaseTest, CancelRequestAndCloseSocket) { … }
TEST_F(ClientSocketPoolBaseTest,
CancelRequestAndCloseSocketWhenMoreRequestsThanConnectJobs) { … }
TEST_F(ClientSocketPoolBaseTest, ConnectCancelConnect) { … }
TEST_F(ClientSocketPoolBaseTest, CancelRequest) { … }
void RequestSocketOnComplete(ClientSocketHandle* handle,
TransportClientSocketPool* pool,
TestConnectJobFactory* test_connect_job_factory,
TestConnectJob::JobType next_job_type,
TestCompletionCallback* nested_callback,
int first_request_result) { … }
TEST_F(ClientSocketPoolBaseTest, RequestPendingJobTwice) { … }
TEST_F(ClientSocketPoolBaseTest, RequestPendingJobThenSynchronous) { … }
TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestWithPendingRequests) { … }
TEST_F(ClientSocketPoolBaseTest, FailingActiveRequestWithPendingRequests) { … }
TEST_F(ClientSocketPoolBaseTest, HandleMultipleSyncFailuresAfterAsyncFailure) { … }
TEST_F(ClientSocketPoolBaseTest, CancelActiveRequestThenRequestSocket) { … }
TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsForced) { … }
TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsInGroupForced) { … }
TEST_F(ClientSocketPoolBaseTest, CleanUpUnusableIdleSockets) { … }
TEST_F(ClientSocketPoolBaseTest, GroupWithPendingRequestsIsNotEmpty) { … }
TEST_F(ClientSocketPoolBaseTest, BasicAsynchronous) { … }
TEST_F(ClientSocketPoolBaseTest, InitConnectionAsynchronousFailure) { … }
TEST_F(ClientSocketPoolBaseTest, AsyncFailureWithPendingRequestWithJob) { … }
TEST_F(ClientSocketPoolBaseTest, TwoRequestsCancelOne) { … }
TEST_F(ClientSocketPoolBaseTest, CancelRequestLimitsJobs) { … }
TEST_F(ClientSocketPoolBaseTest, ReleaseSockets) { … }
TEST_F(ClientSocketPoolBaseTest, PendingJobCompletionOrder) { … }
TEST_F(ClientSocketPoolBaseTest, LoadStateOneRequest) { … }
TEST_F(ClientSocketPoolBaseTest, LoadStateTwoRequests) { … }
TEST_F(ClientSocketPoolBaseTest, LoadStateGroupLimit) { … }
TEST_F(ClientSocketPoolBaseTest, LoadStatePoolLimit) { … }
TEST_F(ClientSocketPoolBaseTest, CertError) { … }
TEST_F(ClientSocketPoolBaseTest, AsyncCertError) { … }
TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateSynchronous) { … }
TEST_F(ClientSocketPoolBaseTest, AdditionalErrorStateAsynchronous) { … }
TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSocketsReuse) { … }
TEST_F(ClientSocketPoolBaseTest, CleanupTimedOutIdleSocketsNoReuse) { … }
TEST_F(ClientSocketPoolBaseTest, MultipleReleasingDisconnectedSockets) { … }
TEST_F(ClientSocketPoolBaseTest, SocketLimitReleasingSockets) { … }
TEST_F(ClientSocketPoolBaseTest,
ReleasingDisconnectedSocketsMaintainsPriorityOrder) { … }
class TestReleasingSocketRequest : public TestCompletionCallbackBase { … };
TEST_F(ClientSocketPoolBaseTest, AdditionalErrorSocketsDontUseSlot) { … }
TEST_F(ClientSocketPoolBaseTest, CallbackThatReleasesPool) { … }
TEST_F(ClientSocketPoolBaseTest, DoNotReuseSocketAfterFlush) { … }
class ConnectWithinCallback : public TestCompletionCallbackBase { … };
TEST_F(ClientSocketPoolBaseTest, AbortAllRequestsOnFlush) { … }
TEST_F(ClientSocketPoolBaseTest, BackupSocketWaitsForHostResolution) { … }
TEST_F(ClientSocketPoolBaseTest, NoBackupSocketWhenConnected) { … }
TEST_F(ClientSocketPoolBaseTest, BackupSocketCancelAtMaxSockets) { … }
TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterCancelingAllRequests) { … }
TEST_F(ClientSocketPoolBaseTest, CancelBackupSocketAfterFinishingAllRequests) { … }
TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingWaitingForConnect) { … }
TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtGroupCapacity) { … }
TEST_F(ClientSocketPoolBaseTest, DelayedSocketBindingAtStall) { … }
TEST_F(ClientSocketPoolBaseTest, SynchronouslyProcessOnePendingRequest) { … }
TEST_F(ClientSocketPoolBaseTest, PreferUsedSocketToUnusedSocket) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSockets) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsWhenAlreadyHaveAConnectJob) { … }
TEST_F(ClientSocketPoolBaseTest,
RequestSocketsWhenAlreadyHaveMultipleConnectJob) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsAtMaxSocketLimit) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsHitMaxSocketLimit) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountIdleSockets) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsCountActiveSockets) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsSynchronous) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsSynchronousError) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsMultipleTimesDoesNothing) { … }
TEST_F(ClientSocketPoolBaseTest, RequestSocketsDifferentNumSockets) { … }
TEST_F(ClientSocketPoolBaseTest, PreconnectJobsTakenByNormalRequests) { … }
TEST_F(ClientSocketPoolBaseTest, ConnectedPreconnectJobsHaveNoConnectTimes) { … }
TEST_F(ClientSocketPoolBaseTest, PreconnectClosesIdleSocketRemovesGroup) { … }
TEST_F(ClientSocketPoolBaseTest, PreconnectWithoutBackupJob) { … }
TEST_F(ClientSocketPoolBaseTest, PreconnectWithBackupJob) { … }
TEST_F(ClientSocketPoolBaseTest, PreconnectWithUnreadData) { … }
TEST_F(ClientSocketPoolBaseTest, RequestGetsAssignedJob) { … }
TEST_F(ClientSocketPoolBaseTest, MultipleRequestsGetAssignedJobs) { … }
TEST_F(ClientSocketPoolBaseTest, PreconnectJobGetsAssignedToRequest) { … }
TEST_F(ClientSocketPoolBaseTest, HigherPriorityRequestStealsJob) { … }
TEST_F(ClientSocketPoolBaseTest, RequestStealsJobFromLowestRequestWithJob) { … }
TEST_F(ClientSocketPoolBaseTest, ReprioritizeRequestStealsJob) { … }
TEST_F(ClientSocketPoolBaseTest, CancelRequestReassignsJob) { … }
TEST_F(ClientSocketPoolBaseTest, JobCompletionReassignsJob) { … }
class MockLayeredPool : public HigherLayeredPool { … };
TEST_F(ClientSocketPoolBaseTest, CloseIdleSocketsHeldByLayeredPoolWhenNeeded) { … }
TEST_F(ClientSocketPoolBaseTest,
CloseIdleSocketsHeldByLayeredPoolWhenNeededFails) { … }
TEST_F(ClientSocketPoolBaseTest,
CloseIdleSocketsHeldByLayeredPoolWhenNeededSameGroup) { … }
TEST_F(ClientSocketPoolBaseTest,
CloseIdleSocketsHeldByLayeredPoolInSameGroupWhenNeeded) { … }
TEST_F(ClientSocketPoolBaseTest,
CloseIdleSocketsHeldByLayeredPoolInSameGroupWhenNeeded2) { … }
TEST_F(ClientSocketPoolBaseTest,
CloseMultipleIdleSocketsHeldByLayeredPoolWhenNeeded) { … }
TEST_F(ClientSocketPoolBaseTest, IgnoreLimits) { … }
TEST_F(ClientSocketPoolBaseTest, IgnoreLimitsCancelOtherJob) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthNoAuthCallback) { … }
class TestAuthHelper { … };
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnce) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceSync) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceFails) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceSyncFails) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceDeleteHandle) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceDeleteHandleSync) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthOnceFlushWithError) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthTwice) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthTwiceFails) { … }
TEST_F(ClientSocketPoolBaseTest,
ProxyAuthCreateNewConnectJobOnDestroyBoundRequest) { … }
TEST_F(ClientSocketPoolBaseTest,
ProxyAuthCreateNewConnectJobOnDestroyBoundRequestDifferentGroups) { … }
TEST_F(ClientSocketPoolBaseTest, ProxyAuthStaysBound) { … }
enum class RefreshType { … };
class ClientSocketPoolBaseRefreshTest
: public ClientSocketPoolBaseTest,
public testing::WithParamInterface<RefreshType> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(ClientSocketPoolBaseRefreshTest, RefreshGroupCreatesNewConnectJobs) { … }
TEST_P(ClientSocketPoolBaseRefreshTest, RefreshGroupClosesIdleConnectJobs) { … }
TEST_F(ClientSocketPoolBaseTest,
RefreshGroupDoesNotCloseIdleConnectJobsInOtherGroup) { … }
TEST_P(ClientSocketPoolBaseRefreshTest, RefreshGroupPreventsSocketReuse) { … }
TEST_F(ClientSocketPoolBaseTest,
RefreshGroupDoesNotPreventSocketReuseInOtherGroup) { … }
TEST_P(ClientSocketPoolBaseRefreshTest,
RefreshGroupReplacesBoundConnectJobOnConnect) { … }
TEST_F(ClientSocketPoolBaseTest, RefreshProxyRefreshesAllGroups) { … }
TEST_F(ClientSocketPoolBaseTest, RefreshBothPrivacyAndNormalSockets) { … }
}
}