chromium/net/spdy/spdy_proxy_client_socket_unittest.cc

// Copyright 2012 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/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[] =;

// Creates a SpdySession with a StreamSocket, instead of a ClientSocketHandle.
base::WeakPtr<SpdySession> CreateSpdyProxySession(
    const url::SchemeHostPort& destination,
    HttpNetworkSession* http_session,
    const SpdySessionKey& key,
    const CommonConnectJobParams* common_connect_job_params) {}

}  // namespace

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) {}

// Constructs a standard SPDY HEADERS frame for a CONNECT request.
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectRequestFrame(
    RequestPriority priority) {}

// Constructs a SPDY HEADERS frame for a CONNECT request which includes
// Proxy-Authorization headers.
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectAuthRequestFrame() {}

// Constructs a standard SPDY HEADERS frame to match the SPDY CONNECT.
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectReplyFrame() {}

// Constructs a standard SPDY HEADERS frame to match the SPDY CONNECT,
// including Proxy-Authenticate headers.
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectAuthReplyFrame() {}

// Constructs a SPDY HEADERS frame with an HTTP 302 redirect.
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectRedirectReplyFrame() {}

// Constructs a SPDY HEADERS frame with an HTTP 500 error.
spdy::SpdySerializedFrame
SpdyProxyClientSocketTest::ConstructConnectErrorReplyFrame() {}

spdy::SpdySerializedFrame SpdyProxyClientSocketTest::ConstructBodyFrame(
    const char* data,
    int length,
    bool fin) {}

// ----------- Connect

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) {}

// ----------- WasEverUsed

TEST_P(SpdyProxyClientSocketTest, WasEverUsedReturnsCorrectValues) {}

// ----------- GetPeerAddress

TEST_P(SpdyProxyClientSocketTest, GetPeerAddressReturnsCorrectValues) {}

// ----------- Write

TEST_P(SpdyProxyClientSocketTest, WriteSendsDataInDataFrame) {}

TEST_P(SpdyProxyClientSocketTest, WriteSplitsLargeDataIntoMultipleFrames) {}

// ----------- Read

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) {}

// ----------- Reads and Writes

TEST_P(SpdyProxyClientSocketTest, AsyncReadAroundWrite) {}

TEST_P(SpdyProxyClientSocketTest, AsyncWriteAroundReads) {}

// ----------- Reading/Writing on Closed socket

// Reading from an already closed socket should return 0
TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsZero) {}

// Read pending when socket is closed should return 0
TEST_P(SpdyProxyClientSocketTest, PendingReadOnCloseReturnsZero) {}

// Reading from a disconnected socket is an error
TEST_P(SpdyProxyClientSocketTest, ReadOnDisconnectSocketReturnsNotConnected) {}

// Reading buffered data from an already closed socket should return
// buffered data, then 0.
TEST_P(SpdyProxyClientSocketTest, ReadOnClosedSocketReturnsBufferedData) {}

// Calling Write() on a closed socket is an error
TEST_P(SpdyProxyClientSocketTest, WriteOnClosedStream) {}

// Calling Write() on a disconnected socket is an error.
TEST_P(SpdyProxyClientSocketTest, WriteOnDisconnectedSocket) {}

// If the socket is closed with a pending Write(), the callback
// should be called with ERR_CONNECTION_CLOSED.
TEST_P(SpdyProxyClientSocketTest, WritePendingOnClose) {}

// If the socket is Disconnected with a pending Write(), the callback
// should not be called.
TEST_P(SpdyProxyClientSocketTest, DisconnectWithWritePending) {}

// If the socket is Disconnected with a pending Read(), the callback
// should not be called.
TEST_P(SpdyProxyClientSocketTest, DisconnectWithReadPending) {}

// If the socket is Reset when both a read and write are pending,
// both should be called back.
TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePending) {}

// Makes sure the proxy client socket's source gets the expected NetLog events
// and only the expected NetLog events (No SpdySession events).
TEST_P(SpdyProxyClientSocketTest, NetLog) {}

// A helper class that will delete |sock| when the callback is invoked.
class DeleteSockCallback : public TestCompletionCallbackBase {};

// If the socket is Reset when both a read and write are pending, and the
// read callback causes the socket to be deleted, the write callback should
// not be called.
TEST_P(SpdyProxyClientSocketTest, RstWithReadAndWritePendingDelete) {}

// ----------- Canceling a ReadIfReady
TEST_P(SpdyProxyClientSocketTest, CancelReadIfReady) {}

// ----------- Handling END_STREAM from the peer

TEST_P(SpdyProxyClientSocketTest, HandleEndStreamAsEOF) {}

TEST_P(SpdyProxyClientSocketTest, SendEndStreamAfterWrite) {}

// Regression test for https://crbug.com/1320256
TEST_P(SpdyProxyClientSocketTest, WriteAfterStreamEndSent) {}

}  // namespace net