#include "net/url_request/url_request_test_util.h"
#include <memory>
#include <utility>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/supports_user_data.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "net/base/host_port_pair.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/do_nothing_ct_verifier.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/cookie_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_network_session.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_server_properties.h"
#include "net/http/transport_security_state.h"
#include "net/proxy_resolution/configured_proxy_resolution_service.h"
#include "net/proxy_resolution/proxy_retry_info.h"
#include "net/quic/quic_context.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_filter.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
const int kStageBeforeURLRequest = …;
const int kStageBeforeStartTransaction = …;
const int kStageHeadersReceived = …;
const int kStageBeforeRedirect = …;
const int kStageBeforeRetry = …;
const int kStageResponseStarted = …;
const int kStageCompletedSuccess = …;
const int kStageCompletedError = …;
const int kStageURLRequestDestroyed = …;
const int kStageDestruction = …;
const char kTestNetworkDelegateRequestIdKey[] = …;
class TestRequestId : public base::SupportsUserData::Data { … };
}
std::unique_ptr<URLRequestContextBuilder> CreateTestURLRequestContextBuilder() { … }
TestURLRequestContextGetter::TestURLRequestContextGetter(
const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner)
: … { … }
TestURLRequestContextGetter::TestURLRequestContextGetter(
const scoped_refptr<base::SingleThreadTaskRunner>& network_task_runner,
std::unique_ptr<URLRequestContext> context)
: … { … }
TestURLRequestContextGetter::~TestURLRequestContextGetter() = default;
URLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() { … }
void TestURLRequestContextGetter::NotifyContextShuttingDown() { … }
scoped_refptr<base::SingleThreadTaskRunner>
TestURLRequestContextGetter::GetNetworkTaskRunner() const { … }
const int TestDelegate::kBufferSize;
TestDelegate::TestDelegate()
: … { … }
TestDelegate::~TestDelegate() = default;
void TestDelegate::RunUntilComplete() { … }
void TestDelegate::RunUntilRedirect() { … }
void TestDelegate::RunUntilAuthRequired() { … }
int TestDelegate::OnConnected(URLRequest* request,
const TransportInfo& info,
CompletionOnceCallback callback) { … }
void TestDelegate::OnReceivedRedirect(URLRequest* request,
const RedirectInfo& redirect_info,
bool* defer_redirect) { … }
void TestDelegate::OnAuthRequired(URLRequest* request,
const AuthChallengeInfo& auth_info) { … }
void TestDelegate::OnSSLCertificateError(URLRequest* request,
int net_error,
const SSLInfo& ssl_info,
bool fatal) { … }
void TestDelegate::OnResponseStarted(URLRequest* request, int net_error) { … }
void TestDelegate::OnReadCompleted(URLRequest* request, int bytes_read) { … }
void TestDelegate::OnResponseCompleted(URLRequest* request) { … }
TestNetworkDelegate::TestNetworkDelegate() = default;
TestNetworkDelegate::~TestNetworkDelegate() { … }
bool TestNetworkDelegate::GetLoadTimingInfoBeforeRedirect(
LoadTimingInfo* load_timing_info_before_redirect) const { … }
void TestNetworkDelegate::InitRequestStatesIfNew(int request_id) { … }
int TestNetworkDelegate::OnBeforeURLRequest(URLRequest* request,
CompletionOnceCallback callback,
GURL* new_url) { … }
int TestNetworkDelegate::OnBeforeStartTransaction(
URLRequest* request,
const HttpRequestHeaders& headers,
OnBeforeStartTransactionCallback callback) { … }
int TestNetworkDelegate::OnHeadersReceived(
URLRequest* request,
CompletionOnceCallback callback,
const HttpResponseHeaders* original_response_headers,
scoped_refptr<HttpResponseHeaders>* override_response_headers,
const IPEndPoint& endpoint,
std::optional<GURL>* preserve_fragment_on_redirect_url) { … }
void TestNetworkDelegate::OnBeforeRedirect(URLRequest* request,
const GURL& new_location) { … }
void TestNetworkDelegate::OnBeforeRetry(URLRequest* request) { … }
void TestNetworkDelegate::OnResponseStarted(URLRequest* request,
int net_error) { … }
void TestNetworkDelegate::OnCompleted(URLRequest* request,
bool started,
int net_error) { … }
void TestNetworkDelegate::OnURLRequestDestroyed(URLRequest* request) { … }
bool TestNetworkDelegate::OnAnnotateAndMoveUserBlockedCookies(
const URLRequest& request,
const net::FirstPartySetMetadata& first_party_set_metadata,
net::CookieAccessResultList& maybe_included_cookies,
net::CookieAccessResultList& excluded_cookies) { … }
NetworkDelegate::PrivacySetting TestNetworkDelegate::OnForcePrivacyMode(
const URLRequest& request) const { … }
bool TestNetworkDelegate::OnCanSetCookie(
const URLRequest& request,
const net::CanonicalCookie& cookie,
CookieOptions* options,
const net::FirstPartySetMetadata& first_party_set_metadata,
CookieInclusionStatus* inclusion_status) { … }
bool TestNetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
const URLRequest& request,
const GURL& target_url,
const GURL& referrer_url) const { … }
int TestNetworkDelegate::GetRequestId(URLRequest* request) { … }
std::optional<cookie_util::StorageAccessStatus>
TestNetworkDelegate::OnGetStorageAccessStatus(const URLRequest& request) const { … }
FilteringTestNetworkDelegate::FilteringTestNetworkDelegate() = default;
FilteringTestNetworkDelegate::~FilteringTestNetworkDelegate() = default;
bool FilteringTestNetworkDelegate::OnCanSetCookie(
const URLRequest& request,
const net::CanonicalCookie& cookie,
CookieOptions* options,
const net::FirstPartySetMetadata& first_party_set_metadata,
CookieInclusionStatus* inclusion_status) { … }
NetworkDelegate::PrivacySetting
FilteringTestNetworkDelegate::OnForcePrivacyMode(
const URLRequest& request) const { … }
bool FilteringTestNetworkDelegate::OnAnnotateAndMoveUserBlockedCookies(
const URLRequest& request,
const net::FirstPartySetMetadata& first_party_set_metadata,
net::CookieAccessResultList& maybe_included_cookies,
net::CookieAccessResultList& excluded_cookies) { … }
class TestScopedURLInterceptor::TestRequestInterceptor
: public URLRequestInterceptor { … };
TestScopedURLInterceptor::TestScopedURLInterceptor(
const GURL& url,
std::unique_ptr<URLRequestJob> intercept_job)
: … { … }
TestScopedURLInterceptor::~TestScopedURLInterceptor() { … }
}