#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/spdy/spdy_test_util_common.h"
#include <cstddef>
#include <optional>
#include <string_view>
#include <utility>
#include "base/base64.h"
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "build/build_config.h"
#include "net/base/features.h"
#include "net/base/host_port_pair.h"
#include "net/base/http_user_agent_settings.h"
#include "net/base/proxy_delegate.h"
#include "net/cert/ct_policy_status.h"
#include "net/cert/mock_cert_verifier.h"
#include "net/cert/signed_certificate_timestamp_and_status.h"
#include "net/dns/host_resolver.h"
#include "net/dns/public/secure_dns_policy.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_transaction.h"
#include "net/http/http_proxy_connect_job.h"
#include "net/log/net_log_with_source.h"
#include "net/proxy_resolution/configured_proxy_resolution_service.h"
#include "net/quic/quic_context.h"
#include "net/quic/quic_crypto_client_stream_factory.h"
#include "net/quic/quic_http_utils.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/next_proto.h"
#include "net/socket/socket_tag.h"
#include "net/socket/socks_connect_job.h"
#include "net/socket/ssl_client_socket.h"
#include "net/socket/transport_client_socket_pool.h"
#include "net/spdy/buffered_spdy_framer.h"
#include "net/spdy/spdy_http_utils.h"
#include "net/spdy/spdy_stream.h"
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/test/gtest_util.h"
#include "net/third_party/quiche/src/quiche/spdy/core/spdy_alt_svc_wire_format.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_context_builder.h"
#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "url/scheme_host_port.h"
#include "url/url_constants.h"
IsError;
IsOk;
namespace net {
namespace {
void ParseUrl(std::string_view url,
std::string* scheme,
std::string* host,
std::string* path) { … }
}
std::unique_ptr<MockWrite[]> ChopWriteFrame(
const spdy::SpdySerializedFrame& frame,
int num_chunks) { … }
void AppendToHeaderBlock(const char* const extra_headers[],
int extra_header_count,
quiche::HttpHeaderBlock* headers) { … }
MockWrite CreateMockWrite(const spdy::SpdySerializedFrame& req) { … }
MockWrite CreateMockWrite(const spdy::SpdySerializedFrame& req, int seq) { … }
MockWrite CreateMockWrite(const spdy::SpdySerializedFrame& req,
int seq,
IoMode mode) { … }
MockRead CreateMockRead(const spdy::SpdySerializedFrame& resp) { … }
MockRead CreateMockRead(const spdy::SpdySerializedFrame& resp, int seq) { … }
MockRead CreateMockRead(const spdy::SpdySerializedFrame& resp,
int seq,
IoMode mode) { … }
spdy::SpdySerializedFrame CombineFrames(
std::vector<const spdy::SpdySerializedFrame*> frames) { … }
namespace {
class PriorityGetter : public BufferedSpdyFramerVisitorInterface { … };
}
bool GetSpdyPriority(const spdy::SpdySerializedFrame& frame,
spdy::SpdyPriority* priority) { … }
base::WeakPtr<SpdyStream> CreateStreamSynchronously(
SpdyStreamType type,
const base::WeakPtr<SpdySession>& session,
const GURL& url,
RequestPriority priority,
const NetLogWithSource& net_log,
bool detect_broken_connection,
base::TimeDelta heartbeat_interval) { … }
StreamReleaserCallback::StreamReleaserCallback() = default;
StreamReleaserCallback::~StreamReleaserCallback() = default;
CompletionOnceCallback StreamReleaserCallback::MakeCallback(
SpdyStreamRequest* request) { … }
void StreamReleaserCallback::OnComplete(
SpdyStreamRequest* request, int result) { … }
SpdySessionDependencies::SpdySessionDependencies()
: … { … }
SpdySessionDependencies::SpdySessionDependencies(
std::unique_ptr<ProxyResolutionService> proxy_resolution_service)
: … { … }
SpdySessionDependencies::SpdySessionDependencies(SpdySessionDependencies&&) =
default;
SpdySessionDependencies::~SpdySessionDependencies() = default;
SpdySessionDependencies& SpdySessionDependencies::operator=(
SpdySessionDependencies&&) = default;
std::unique_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession(
SpdySessionDependencies* session_deps) { … }
std::unique_ptr<HttpNetworkSession>
SpdySessionDependencies::SpdyCreateSessionWithSocketFactory(
SpdySessionDependencies* session_deps,
ClientSocketFactory* factory) { … }
HttpNetworkSessionParams SpdySessionDependencies::CreateSessionParams(
SpdySessionDependencies* session_deps) { … }
HttpNetworkSessionContext SpdySessionDependencies::CreateSessionContext(
SpdySessionDependencies* session_deps) { … }
std::unique_ptr<URLRequestContextBuilder>
CreateSpdyTestURLRequestContextBuilder(
ClientSocketFactory* client_socket_factory) { … }
bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { … }
namespace {
base::WeakPtr<SpdySession> CreateSpdySessionHelper(
HttpNetworkSession* http_session,
const SpdySessionKey& key,
const NetLogWithSource& net_log,
bool enable_ip_based_pooling) { … }
}
base::WeakPtr<SpdySession> CreateSpdySession(HttpNetworkSession* http_session,
const SpdySessionKey& key,
const NetLogWithSource& net_log) { … }
base::WeakPtr<SpdySession> CreateSpdySessionWithIpBasedPoolingDisabled(
HttpNetworkSession* http_session,
const SpdySessionKey& key,
const NetLogWithSource& net_log) { … }
namespace {
class FakeSpdySessionClientSocket : public MockClientSocket { … };
}
base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool,
const SpdySessionKey& key) { … }
SpdySessionPoolPeer::SpdySessionPoolPeer(SpdySessionPool* pool) : … { … }
void SpdySessionPoolPeer::RemoveAliases(const SpdySessionKey& key) { … }
void SpdySessionPoolPeer::SetEnableSendingInitialData(bool enabled) { … }
SpdyTestUtil::SpdyTestUtil(bool use_priority_header)
: … { … }
SpdyTestUtil::~SpdyTestUtil() = default;
void SpdyTestUtil::AddUrlToHeaderBlock(std::string_view url,
quiche::HttpHeaderBlock* headers) const { … }
void SpdyTestUtil::AddPriorityToHeaderBlock(
RequestPriority request_priority,
bool priority_incremental,
quiche::HttpHeaderBlock* headers) const { … }
quiche::HttpHeaderBlock SpdyTestUtil::ConstructGetHeaderBlock(
std::string_view url) { … }
quiche::HttpHeaderBlock SpdyTestUtil::ConstructGetHeaderBlockForProxy(
std::string_view url) { … }
quiche::HttpHeaderBlock SpdyTestUtil::ConstructHeadHeaderBlock(
std::string_view url,
int64_t content_length) { … }
quiche::HttpHeaderBlock SpdyTestUtil::ConstructPostHeaderBlock(
std::string_view url,
int64_t content_length) { … }
quiche::HttpHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock(
std::string_view url,
int64_t content_length) { … }
std::string SpdyTestUtil::ConstructSpdyReplyString(
const quiche::HttpHeaderBlock& headers) const { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdySettings(
const spdy::SettingsMap& settings) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdySettingsAck() { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyPing(uint32_t ping_id,
bool is_ack) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway(
spdy::SpdyStreamId last_good_stream_id) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyGoAway(
spdy::SpdyStreamId last_good_stream_id,
spdy::SpdyErrorCode error_code,
const std::string& desc) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyWindowUpdate(
const spdy::SpdyStreamId stream_id,
uint32_t delta_window_size) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyRstStream(
spdy::SpdyStreamId stream_id,
spdy::SpdyErrorCode error_code) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyPriority(
spdy::SpdyStreamId stream_id,
spdy::SpdyStreamId parent_stream_id,
RequestPriority request_priority,
bool exclusive) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet(
const char* const url,
spdy::SpdyStreamId stream_id,
RequestPriority request_priority,
bool priority_incremental,
std::optional<RequestPriority> header_request_priority) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyGet(
const char* const extra_headers[],
int extra_header_count,
int stream_id,
RequestPriority request_priority,
bool priority_incremental,
std::optional<RequestPriority> header_request_priority) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyConnect(
const char* const extra_headers[],
int extra_header_count,
int stream_id,
RequestPriority priority,
const HostPortPair& host_port_pair) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyPushPromise(
spdy::SpdyStreamId associated_stream_id,
spdy::SpdyStreamId stream_id,
quiche::HttpHeaderBlock headers) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyResponseHeaders(
int stream_id,
quiche::HttpHeaderBlock headers,
bool fin) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyHeaders(
int stream_id,
quiche::HttpHeaderBlock block,
RequestPriority priority,
bool fin,
bool priority_incremental,
std::optional<RequestPriority> header_request_priority) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyReply(
int stream_id,
quiche::HttpHeaderBlock headers) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyReplyError(
const char* const status,
const char* const* const extra_headers,
int extra_header_count,
int stream_id) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyReplyError(int stream_id) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyGetReply(
const char* const extra_headers[],
int extra_header_count,
int stream_id) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyPost(
const char* url,
spdy::SpdyStreamId stream_id,
int64_t content_length,
RequestPriority request_priority,
const char* const extra_headers[],
int extra_header_count,
bool priority_incremental) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructChunkedSpdyPost(
const char* const extra_headers[],
int extra_header_count,
RequestPriority request_priority,
bool priority_incremental) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyPostReply(
const char* const extra_headers[],
int extra_header_count) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(int stream_id,
bool fin) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(
int stream_id,
std::string_view data,
bool fin) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructSpdyDataFrame(
int stream_id,
std::string_view data,
bool fin,
int padding_length) { … }
spdy::SpdySerializedFrame SpdyTestUtil::ConstructWrappedSpdyFrame(
const spdy::SpdySerializedFrame& frame,
int stream_id) { … }
spdy::SpdySerializedFrame SpdyTestUtil::SerializeFrame(
const spdy::SpdyFrameIR& frame_ir) { … }
void SpdyTestUtil::UpdateWithStreamDestruction(int stream_id) { … }
quiche::HttpHeaderBlock SpdyTestUtil::ConstructHeaderBlock(
std::string_view method,
std::string_view url,
int64_t* content_length) { … }
namespace test {
HashValue GetTestHashValue(uint8_t label) { … }
}
}