#include "net/spdy/spdy_proxy_client_socket.h"
#include <string_view>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "net/base/address_list.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_timing_info.h"
#include "net/base/proxy_chain.h"
#include "net/base/proxy_server.h"
#include "net/base/session_usage.h"
#include "net/base/test_completion_callback.h"
#include "net/base/winsock_init.h"
#include "net/dns/mock_host_resolver.h"
#include "net/dns/public/secure_dns_policy.h"
#include "net/http/http_proxy_connect_job.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/test_net_log.h"
#include "net/log/test_net_log_util.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/connect_job_params.h"
#include "net/socket/connect_job_test_util.h"
#include "net/socket/next_proto.h"
#include "net/socket/socket_tag.h"
#include "net/socket/socket_test_util.h"
#include "net/socket/socks_connect_job.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/ssl_connect_job.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_client_socket.h"
#include "net/socket/transport_connect_job.h"
#include "net/spdy/buffered_spdy_framer.h"
#include "net/spdy/spdy_http_utils.h"
#include "net/spdy/spdy_session_pool.h"
#include "net/spdy/spdy_test_util_common.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/spdy/core/spdy_protocol.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"
IsError;
IsOk;
namespace net {
namespace {
static const char kRequestUrl[] = …;
static const char kOriginHost[] = …;
static const int kOriginPort = …;
static const char kOriginHostPort[] = …;
static const char kProxyUrl[] = …;
static const char kProxyHost[] = …;
static const int kProxyPort = …;
static const char kUserAgent[] = …;
static const int kStreamId = …;
static const char kMsg1[] = …;
static const int kLen1 = …;
static const char kMsg2[] = …;
static const int kLen2 = …;
static const char kMsg3[] = …;
static const int kLen3 = …;
static const char kMsg33[] = …;
static const int kLen33 = …;
static const char kMsg333[] = …;
static const int kLen333 = …;
static const char kRedirectUrl[] = …;
base::WeakPtr<SpdySession> CreateSpdyProxySession(
const url::SchemeHostPort& destination,
HttpNetworkSession* http_session,
const SpdySessionKey& key,
const CommonConnectJobParams* common_connect_job_params) { … }
}
class SpdyProxyClientSocketTest : public PlatformTest,
public WithTaskEnvironment,
public ::testing::WithParamInterface<bool> { … };
SpdyProxyClientSocketTest::SpdyProxyClientSocketTest()
: … { … }
SpdyProxyClientSocketTest::~SpdyProxyClientSocketTest() { … }
void SpdyProxyClientSocketTest::TearDown() { … }
void SpdyProxyClientSocketTest::Initialize(base::span<const MockRead> reads,
base::span<const MockWrite> writes) { … }
scoped_refptr<IOBufferWithSize> SpdyProxyClientSocketTest::CreateBuffer(
const char* data, int size) { … }
void SpdyProxyClientSocketTest::AssertConnectSucceeds() { … }
void SpdyProxyClientSocketTest::AssertConnectFails(int result) { … }
void SpdyProxyClientSocketTest::AssertConnectionEstablished() { … }
void SpdyProxyClientSocketTest::AssertSyncReadEquals(const char* data,
int len) { … }
void SpdyProxyClientSocketTest::AssertSyncReadEOF() { … }
void SpdyProxyClientSocketTest::AssertAsyncReadEquals(const char* data,
int len,
bool fin) { … }
void SpdyProxyClientSocketTest::AssertReadStarts(const char* data, int len) { … }
void SpdyProxyClientSocketTest::AssertReadReturns(const char* data, int len) { … }
void SpdyProxyClientSocketTest::AssertAsyncWriteSucceeds(const char* data,
int len) { … }
void SpdyProxyClientSocketTest::AssertWriteReturns(const char* data,
int len,
int rv) { … }
void SpdyProxyClientSocketTest::AssertWriteLength(int len) { … }
void SpdyProxyClientSocketTest::PopulateConnectRequestIR(
quiche::HttpHeaderBlock* block) { … }
void SpdyProxyClientSocketTest::PopulateConnectReplyIR(
quiche::HttpHeaderBlock* block,
const char* status) { … }
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectRequestFrame(
RequestPriority priority) { … }
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() { … }
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectReplyFrame() { … }
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() { … }
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() { … }
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() { … }
spdy::SpdySerializedFrame SpdyProxyClientSocketTest::ConstructBodyFrame(
const char* data,
int length,
bool fin) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(SpdyProxyClientSocketTest, ConnectSendsCorrectRequest) { … }
TEST_P(SpdyProxyClientSocketTest, ConnectWithAuthRequested) { … }
TEST_P(SpdyProxyClientSocketTest, ConnectWithAuthCredentials) { … }
TEST_P(SpdyProxyClientSocketTest, ConnectRedirects) { … }
TEST_P(SpdyProxyClientSocketTest, ConnectFails) { … }
TEST_P(SpdyProxyClientSocketTest, SetStreamPriority) { … }
TEST_P(SpdyProxyClientSocketTest, WasEverUsedReturnsCorrectValues) { … }
TEST_P(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) { … }
TEST_P(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) { … }
TEST_P(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) { … }
TEST_P(SpdyProxyClientSocketTest, ReadReadsDataInDataFrame) { … }
TEST_P(SpdyProxyClientSocketTest, ReadDataFromBufferedFrames) { … }
TEST_P(SpdyProxyClientSocketTest, ReadDataMultipleBufferedFrames) { … }
TEST_P(SpdyProxyClientSocketTest, LargeReadWillMergeDataFromDifferentFrames) { … }
TEST_P(SpdyProxyClientSocketTest, MultipleShortReadsThenMoreRead) { … }
TEST_P(SpdyProxyClientSocketTest, ReadWillSplitDataFromLargeFrame) { … }
TEST_P(SpdyProxyClientSocketTest, MultipleReadsFromSameLargeFrame) { … }
TEST_P(SpdyProxyClientSocketTest, ReadAuthResponseBody) { … }
TEST_P(SpdyProxyClientSocketTest, ReadErrorResponseBody) { … }
TEST_P(SpdyProxyClientSocketTest, SocketDestroyedWhenReadIsPending) { … }
TEST_P(SpdyProxyClientSocketTest, AsyncReadAroundWrite) { … }
TEST_P(SpdyProxyClientSocketTest, AsyncWriteAroundReads) { … }
TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsZero) { … }
TEST_P(SpdyProxyClientSocketTest, PendingReadOnCloseReturnsZero) { … }
TEST_P(SpdyProxyClientSocketTest, ReadOnDisconnectSocketReturnsNotConnected) { … }
TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) { … }
TEST_P(SpdyProxyClientSocketTest, WriteOnClosedStream) { … }
TEST_P(SpdyProxyClientSocketTest, WriteOnDisconnectedSocket) { … }
TEST_P(SpdyProxyClientSocketTest, WritePendingOnClose) { … }
TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) { … }
TEST_P(SpdyProxyClientSocketTest, DisconnectWithReadPending) { … }
TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) { … }
TEST_P(SpdyProxyClientSocketTest, NetLog) { … }
class DeleteSockCallback : public TestCompletionCallbackBase { … };
TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) { … }
TEST_P(SpdyProxyClientSocketTest, CancelReadIfReady) { … }
TEST_P(SpdyProxyClientSocketTest, HandleEndStreamAsEOF) { … }
TEST_P(SpdyProxyClientSocketTest, SendEndStreamAfterWrite) { … }
TEST_P(SpdyProxyClientSocketTest, WriteAfterStreamEndSent) { … }
}