chromium/services/network/url_loader_unittest.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/url_loader.h"

#include <stdint.h>

#include <limits>
#include <list>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/auto_reset.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "mojo/public/cpp/system/wait.h"
#include "net/base/completion_repeating_callback.h"
#include "net/base/features.h"
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
#include "net/base/isolation_info.h"
#include "net/base/load_flags.h"
#include "net/base/mime_sniffer.h"
#include "net/base/net_errors.h"
#include "net/base/transport_info.h"
#include "net/cert/test_root_certs.h"
#include "net/cookies/cookie_access_result.h"
#include "net/cookies/cookie_change_dispatcher.h"
#include "net/cookies/cookie_inclusion_status.h"
#include "net/cookies/cookie_partition_key.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_info.h"
#include "net/http/http_status_code.h"
#include "net/http/http_transaction_test_util.h"
#include "net/log/net_log_event_type.h"
#include "net/log/test_net_log.h"
#include "net/proxy_resolution/configured_proxy_resolution_service.h"
#include "net/socket/socket_test_util.h"
#include "net/ssl/client_cert_identity_test_util.h"
#include "net/storage_access_api/status.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/gtest_util.h"
#include "net/test/quic_simple_test_server.h"
#include "net/test/test_data_directory.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "net/third_party/quiche/src/quiche/common/http/http_header_block.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_filter.h"
#include "net/url_request/url_request_interceptor.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_test_job.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/attribution/attribution_request_helper.h"
#include "services/network/public/cpp/cors/origin_access_list.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/ip_address_space_util.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/cookie_access_observer.mojom-forward.h"
#include "services/network/public/mojom/cookie_access_observer.mojom.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/http_raw_headers.mojom.h"
#include "services/network/public/mojom/ip_address_space.mojom-shared.h"
#include "services/network/public/mojom/ip_address_space.mojom.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/trust_tokens.mojom-shared.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/resource_scheduler/resource_scheduler_client.h"
#include "services/network/shared_dictionary/shared_dictionary_access_checker.h"
#include "services/network/shared_storage/shared_storage_header_utils.h"
#include "services/network/shared_storage/shared_storage_request_helper.h"
#include "services/network/shared_storage/shared_storage_test_url_loader_network_observer.h"
#include "services/network/shared_storage/shared_storage_test_utils.h"
#include "services/network/test/mock_devtools_observer.h"
#include "services/network/test/test_data_pipe_getter.h"
#include "services/network/test/test_network_context_client.h"
#include "services/network/test/test_url_loader_client.h"
#include "services/network/test/test_url_loader_network_observer.h"
#include "services/network/test/url_loader_context_for_tests.h"
#include "services/network/test_chunked_data_pipe_getter.h"
#include "services/network/trust_tokens/trust_token_key_commitment_getter.h"
#include "services/network/trust_tokens/trust_token_request_helper.h"
#include "services/network/trust_tokens/trust_token_request_helper_factory.h"
#include "services/network/url_request_context_owner.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace network {

namespace {

IsError;
IsOk;
ElementsAre;
Eq;
Optional;
Pointee;
SizeIs;
ValuesIn;

// Returns a URLLoader::DeleteCallback that destroys |url_loader| and quits
// |run_loop| when invoked. Tests must wait on the RunLoop to ensure nothing is
// leaked. Takes a std::unique_ptr<URLLoader>* instead of a unique_ptr because
// the callback must be created before the URLLoader is actually created.
URLLoader::DeleteCallback DeleteLoaderCallback(
    base::RunLoop* run_loop,
    std::unique_ptr<URLLoader>* url_loader) {}

// Returns a URLLoader::DeleteCallback that does nothing, but calls NOTREACHED.
// Tests that use a URLLoader that actually tries to delete itself shouldn't use
// this method, as URLLoaders don't expect to be alive after they invoke their
// delete callback.
URLLoader::DeleteCallback NeverInvokedDeleteLoaderCallback() {}

constexpr char kTestAuthURL[] =;

constexpr char kInsecureHost[] =;

constexpr char kHostnameWithAliases[] =;

constexpr char kHostnameWithoutAliases[] =;

static ResourceRequest CreateResourceRequest(const char* method,
                                             const GURL& url) {}

class URLRequestMultipleWritesJob : public net::URLRequestJob {};

class MultipleWritesInterceptor : public net::URLRequestInterceptor {};

// Every read completes synchronously.
class URLRequestEternalSyncReadsJob : public net::URLRequestJob {};

class EternalSyncReadsInterceptor : public net::URLRequestInterceptor {};

// Simulates handing over things to the disk to write before returning to the
// caller.
class URLRequestSimulatedCacheJob : public net::URLRequestJob {};

class SimulatedCacheInterceptor : public net::URLRequestInterceptor {};

// Observes net error results. Thread-compatible.
class ResultObserver {};

// Fakes the TransportInfo passed to `URLRequest::Delegate::OnConnected()`.
class URLRequestFakeTransportInfoJob : public net::URLRequestJob {};

// Intercepts URLRequestJob creation to a specific URL. All requests to this
// URL will report being connected with a fake TransportInfo struct.
class FakeTransportInfoInterceptor : public net::URLRequestInterceptor {};

// Returns a maximally-restrictive security state for use in tests.
mojom::ClientSecurityStatePtr NewSecurityState() {}

CorsErrorStatus InsecurePrivateNetworkCorsErrorStatus(
    mojom::IPAddressSpace resource_address_space) {}

std::string CookieOrLineToString(const mojom::CookieOrLinePtr& cookie_or_line) {}

MATCHER_P2(CookieOrLine, string, type, "") {}

// Permits simply constructing a URLLoader object specifying only those options
// which are non-default.
// Replace:
//   auto url_loader = std::make_unique<URLLoader>(context(), ...,
//                                                 /*some_option=*/true);
// With:
//   URLLoaderOptions options;
//   options.some_option = true;
//   auto url_loader = options.MakeURLLoader(context(), ...);
struct URLLoaderOptions {};

}  // namespace

class MockAcceptCHFrameObserver : public mojom::AcceptCHFrameObserver {};

class URLLoaderTest : public testing::Test {};

class URLLoaderMockSocketTest : public URLLoaderTest {};

constexpr int URLLoaderTest::kProcessId;
constexpr int URLLoaderTest::kRouteId;

TEST_F(URLLoaderTest, Basic) {}

TEST_F(URLLoaderTest, Empty) {}

TEST_F(URLLoaderTest, BasicSSL) {}

TEST_F(URLLoaderTest, SSLSentOnlyWhenRequested) {}

// This test verifies that when the request is same-origin and the origin is
// potentially trustworthy, the request is not blocked.
TEST_F(URLLoaderTest, PotentiallyTrustworthySameOriginIsOk) {}

// This test verifies that when the URLLoaderFactory's parameters are missing
// a client security state, requests to local network resources are authorized.
TEST_F(URLLoaderTest, MissingClientSecurityStateIsOk) {}

// This test verifies that when the request's `target_ip_address_space` matches
// the resource's IP address space, then the request is allowed even if it
// would otherwise be blocked by policy.
TEST_F(URLLoaderTest, MatchingTargetIPAddressSpaceIsOk) {}

// This test verifies that when the request's `target_ip_address_space` does not
// match the resource's IP address space, and the policy is `kPreflightWarn`,
// then the request is not blocked.
TEST_F(URLLoaderTest, MismatchingTargetIPAddressSpaceWarnIsNotBlocked) {}

// This test verifies that when the request's `target_ip_address_space` does not
// match the resource's IP address space, and the policy is `kPreflightBlock`,
// then the request is blocked.
TEST_F(URLLoaderTest, MismatchingTargetIPAddressSpaceIsBlocked) {}

// This test verifies that when the request's `target_ip_address_space` does not
// match the resource's IP address space, and the policy is `kPreflightBlock`,
// then `URLLoader::OnConnected()` returns the right error code. This error code
// causes any cache entry in use to be invalidated.
TEST_F(URLLoaderTest, MismatchingTargetIPAddressSpaceErrorCode) {}

// This test verifies that when the request calls `URLLoader::OnConnected()`
// twice with endpoints belonging to different IP address spaces, but the
// private network request policy is `kPreflightWarn`, then the request is not
// blocked.
TEST_F(URLLoaderTest, InconsistentIPAddressSpaceWarnIsNotBlocked) {}

// This test verifies that when the request calls `URLLoader::OnConnected()`
// twice with endpoints belonging to different IP address spaces, the request
// fails. In that case `URLLoader::OnConnected()` returns the right error code,
// which causes any cache entry in use to be invalidated.
TEST_F(URLLoaderTest, InconsistentIPAddressSpaceIsBlocked) {}

// These tests verify that requests from both secure and non-secure contexts to
// an IP in the `kLocal` address space are only blocked when the policy is
// `kBlock` and the initiator's address space is not `kLocal`.
//
// NOTE: These tests exercise the same codepath as
// URLLoaderFakeTransportInfoTest below, except they use real URLRequestJob and
// HttpTransaction implementations for higher confidence in the correctness of
// the whole stack. OTOH, using an embedded test server prevents us from mocking
// out the endpoint IP address.

TEST_F(URLLoaderTest, SecureUnknownToLocalBlock) {}

TEST_F(URLLoaderTest, SecureUnknownToLocalWarn) {}

TEST_F(URLLoaderTest, SecureUnknownToLocalAllow) {}

TEST_F(URLLoaderTest, SecureUnknownToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, SecureUnknownToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, NonSecureUnknownToLocalBlock) {}

TEST_F(URLLoaderTest, NonSecureUnknownToLocalWarn) {}

TEST_F(URLLoaderTest, NonSecureUnknownToLocalAllow) {}

TEST_F(URLLoaderTest, NonSecureUnknownToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, NonSecureUnknownToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, SecurePublicToLocalBlock) {}

TEST_F(URLLoaderTest, SecurePublicToLocalWarn) {}

TEST_F(URLLoaderTest, SecurePublicToLocalAllow) {}

TEST_F(URLLoaderTest, SecurePublicToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, SecurePublicToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, NonSecurePublicToLocalBlock) {}

TEST_F(URLLoaderTest, NonSecurePublicToLocalWarn) {}

TEST_F(URLLoaderTest, NonSecurePublicToLocalAllow) {}

TEST_F(URLLoaderTest, NonSecurePublicToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, NonSecurePublicToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, SecurePrivateToLocalBlock) {}

TEST_F(URLLoaderTest, SecurePrivateToLocalWarn) {}

TEST_F(URLLoaderTest, SecurePrivateToLocalAllow) {}

TEST_F(URLLoaderTest, SecurePrivateToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, SecurePrivateToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, NonSecurePrivateToLocalBlock) {}

TEST_F(URLLoaderTest, NonSecurePrivateToLocalWarn) {}

TEST_F(URLLoaderTest, NonSecurePrivateToLocalAllow) {}

TEST_F(URLLoaderTest, NonSecurePrivateToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, NonSecurePrivateToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, SecureLocalToLocalBlock) {}

TEST_F(URLLoaderTest, SecureLocalToLocalWarn) {}

TEST_F(URLLoaderTest, SecureLocalToLocalAllow) {}

TEST_F(URLLoaderTest, SecureLocalToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, SecureLocalToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, NonSecureLocalToLocalBlock) {}

TEST_F(URLLoaderTest, NonSecureLocalToLocalWarn) {}

TEST_F(URLLoaderTest, NonSecureLocalToLocalAllow) {}

TEST_F(URLLoaderTest, NonSecureLocalToLocalPreflightBlock) {}

TEST_F(URLLoaderTest, NonSecureLocalToLocalPreflightWarn) {}

TEST_F(URLLoaderTest, AddsNetLogEntryForPrivateNetworkAccessCheckSuccess) {}

TEST_F(URLLoaderTest, AddsNetLogEntryForPrivateNetworkAccessCheckFailure) {}

TEST_F(URLLoaderTest, AddsNetLogEntryForPrivateNetworkAccessCheckSameOrigin) {}

// Bundles together the inputs to a parameterized private network request test.
struct URLLoaderFakeTransportInfoTestParams {};

// For clarity when debugging parameterized test failures.
std::ostream& operator<<(std::ostream& out,
                         const URLLoaderFakeTransportInfoTestParams& params) {}

mojom::IPAddressSpace ResponseAddressSpace(
    const URLLoaderFakeTransportInfoTestParams& params) {}

class URLLoaderFakeTransportInfoTest
    : public URLLoaderTest,
      public testing::WithParamInterface<URLLoaderFakeTransportInfoTestParams> {};

// This test verifies that requests made from insecure contexts are handled
// appropriately when they go from a less-private address space to a
// more-private address space or not. The test is parameterized by
// (client address space, server address space, expected result) tuple.
TEST_P(URLLoaderFakeTransportInfoTest, PrivateNetworkRequestLoadsCorrectly) {}

// Lists all combinations we want to test in URLLoaderFakeTransportInfoTest.
constexpr URLLoaderFakeTransportInfoTestParams
    kURLLoaderFakeTransportInfoTestParamsList[] =;

INSTANTIATE_TEST_SUITE_P();

// Tests that auth challenge info is present on the response when a request
// receives an authentication challenge.
TEST_F(URLLoaderTest, AuthChallengeInfo) {}

// Tests that no auth challenge info is present on the response when a request
// does not receive an authentication challenge.
TEST_F(URLLoaderTest, NoAuthChallengeInfo) {}

// Test decoded_body_length / encoded_body_length when they're different.
TEST_F(URLLoaderTest, GzipTest) {}

TEST_F(URLLoaderTest, ErrorBeforeHeaders) {}

TEST_F(URLLoaderTest, SyncErrorWhileReadingBody) {}

TEST_F(URLLoaderTest, AsyncErrorWhileReadingBody) {}

TEST_F(URLLoaderTest, SyncErrorWhileReadingBodyAfterBytesReceived) {}

TEST_F(URLLoaderTest, AsyncErrorWhileReadingBodyAfterBytesReceived) {}

TEST_F(URLLoaderTest, DoNotSniffUnlessSpecified) {}

TEST_F(URLLoaderTest, SniffMimeType) {}

TEST_F(URLLoaderTest, RespectNoSniff) {}

TEST_F(URLLoaderTest, SniffTextPlainDoesNotResultInHTML) {}

TEST_F(URLLoaderTest, DoNotSniffHTMLFromImageGIF) {}

TEST_F(URLLoaderTest, EmptyHtmlIsTextPlain) {}

TEST_F(URLLoaderTest, EmptyHtmlIsTextPlainWithAsyncResponse) {}

// Tests the case where the first read doesn't have enough data to figure out
// the right mime type. The second read would have enough data even though the
// total bytes is still smaller than net::kMaxBytesToSniff.
TEST_F(URLLoaderTest, FirstReadNotEnoughToSniff1) {}

// Like above, except that the total byte count is > kMaxBytesToSniff.
TEST_F(URLLoaderTest, FirstReadNotEnoughToSniff2) {}

// Tests that even if the first and only read is smaller than the minimum number
// of bytes needed to sniff, the loader works correctly and returns the data.
TEST_F(URLLoaderTest, LoneReadNotEnoughToSniff) {}

// Tests the simple case where the first read is enough to sniff.
TEST_F(URLLoaderTest, FirstReadIsEnoughToSniff) {}

class NeverFinishedBodyHttpResponse : public net::test_server::HttpResponse {};

// Check that the URLLoader tears itself down when the URLLoader pipe is closed.
TEST_F(URLLoaderTest, DestroyOnURLLoaderPipeClosed) {}

// Make sure that the URLLoader is destroyed when the data pipe is closed.
// The pipe may either be closed in
// URLLoader::OnResponseBodyStreamConsumerClosed() or URLLoader::DidRead(),
// depending on whether the closed pipe is first noticed when trying to write to
// it, or when a mojo close notification is received, so if only one path
// breaks, this test may flakily fail.
TEST_F(URLLoaderTest, CloseResponseBodyConsumerBeforeProducer) {}

TEST_F(URLLoaderTest, PauseReadingBodyFromNetBeforeResponseHeaders) {}

TEST_F(URLLoaderTest, PauseReadingBodyFromNetWhenReadIsPending) {}

TEST_F(URLLoaderTest, ResumeReadingBodyFromNetAfterClosingConsumer) {}

TEST_F(URLLoaderTest, MultiplePauseResumeReadingBodyFromNet) {}

TEST_F(URLLoaderTest, UploadBytes) {}

TEST_F(URLLoaderTest, UploadFile) {}

TEST_F(URLLoaderTest, UploadFileWithRange) {}

TEST_F(URLLoaderTest, UploadTwoFiles) {}

TEST_F(URLLoaderTest, UploadTwoBatchesOfFiles) {}

TEST_F(URLLoaderTest, UploadTwoBatchesOfFilesWithRespondInvalidFile) {}

TEST_F(URLLoaderTest, UploadTwoBatchesOfFilesWithRespondDifferentNumOfFiles) {}

TEST_F(URLLoaderTest, UploadInvalidFile) {}

TEST_F(URLLoaderTest, UploadFileWithoutNetworkServiceClient) {}

class CallbackSavingNetworkContextClient : public TestNetworkContextClient {};

TEST_F(URLLoaderTest, UploadFileCanceled) {}

// Tests a request body with a data pipe element.
TEST_F(URLLoaderTest, UploadDataPipe) {}

// Same as above and tests that the body is sent after a 307 redirect.
TEST_F(URLLoaderTest, UploadDataPipe_Redirect307) {}

// Tests a large request body, which should result in multiple asynchronous
// reads.
TEST_F(URLLoaderTest, UploadDataPipeWithLotsOfData) {}

TEST_F(URLLoaderTest, UploadDataPipeError) {}

TEST_F(URLLoaderTest, UploadDataPipeClosedEarly) {}

// Tests a request body with a chunked data pipe element.
TEST_F(URLLoaderTest, UploadChunkedDataPipe) {}

TEST_F(URLLoaderTest, UploadChunkedDataPipeOverHTTP2) {}

TEST_F(URLLoaderTest, UploadChunkedDataPipeNotAllowHTTP1) {}

// Tests a request body with ReadOnceStream.
TEST_F(URLLoaderTest, UploadChunkedDataPipeReadOnceStream) {}

// Tests that SSLInfo is not attached to OnComplete messages or the
// URLResponseHead when there is no certificate error.
TEST_F(URLLoaderTest, NoSSLInfoWithoutCertificateError) {}

// Tests that SSLInfo is not attached to OnComplete messages when the
// corresponding option is not set.
TEST_F(URLLoaderTest, NoSSLInfoOnComplete) {}

// Tests that SSLInfo is attached to OnComplete messages when the corresponding
// option is set and the certificate error causes the load to fail.
TEST_F(URLLoaderTest, SSLInfoOnComplete) {}

// Tests that SSLInfo is attached to OnComplete messages and the URLResponseHead
// when the corresponding option is set and the certificate error doesn't cause
// the load to fail.
TEST_F(URLLoaderTest, SSLInfoOnResponseWithCertificateError) {}

// Tests that SSLInfo is attached to the URLResponseHead on redirects when the
// corresponding option is set and the certificate error doesn't cause the load
// to fail.
TEST_F(URLLoaderTest, SSLInfoOnRedirectWithCertificateError) {}

// Make sure the client can modify headers during a redirect.
TEST_F(URLLoaderTest, RedirectModifiedHeaders) {}

TEST_F(URLLoaderTest, RedirectFailsOnModifyUnsafeHeader) {}

// Test the client can remove headers during a redirect.
TEST_F(URLLoaderTest, RedirectRemoveHeader) {}

// Test the client can remove headers and add headers back during a redirect.
TEST_F(URLLoaderTest, RedirectRemoveHeaderAndAddItBack) {}

// Validate Sec- prefixed headers are handled properly when redirecting from
// insecure => secure urls. The Sec-Fetch-Site header should be re-added on the
// secure url.
TEST_F(URLLoaderTest, UpgradeAddsSecHeaders) {}

// Validate Sec- prefixed headers are properly handled when redirecting from
// secure => insecure urls. All Sec-CH- and Sec-Fetch- prefixed
// headers should be removed.
TEST_F(URLLoaderTest, DowngradeRemovesSecHeaders) {}

// Validate Sec- prefixed headers are properly handled when redirecting from
// secure => insecure => secure urls.The headers on insecure
// urls should be removed and Sec-Fetch-Site should be re-added on secure ones.
TEST_F(URLLoaderTest, RedirectChainRemovesAndAddsSecHeaders) {}

// Validate Sec-Fetch-User header is properly handled.
TEST_F(URLLoaderTest, RedirectSecHeadersUser) {}

// Validate Sec-Fetch-User header cannot be modified by manually set the value.
TEST_F(URLLoaderTest, RedirectDirectlyModifiedSecHeadersUser) {}

// A mock URLRequestJob which simulates an HTTPS request with a certificate
// error.
class MockHTTPSURLRequestJob : public net::URLRequestTestJob {};

class MockHTTPSJobURLRequestInterceptor : public net::URLRequestInterceptor {};

// Tests that |cert_status| is set on the resource response.
TEST_F(URLLoaderTest, CertStatusOnResponse) {}

// Verifies if URLLoader works well with ResourceScheduler.
// TODO(crbug.com/333723898): enable this test.
#if BUILDFLAG(IS_MAC)
#define MAYBE_ResourceSchedulerIntegration
#else
#define MAYBE_ResourceSchedulerIntegration
#endif
TEST_F(URLLoaderTest, MAYBE_ResourceSchedulerIntegration) {}

// This tests that case where a read pipe is closed while there's a post task to
// invoke ReadMore.
TEST_F(URLLoaderTest, ReadPipeClosedWhileReadTaskPosted) {}

class FakeSSLPrivateKeyImpl : public network::mojom::SSLPrivateKey {};

CookieAccessType;

class MockCookieObserver : public network::mojom::CookieAccessObserver {};

MATCHER_P3(MatchesCookieDetails, type, cookie_or_line, is_include, "") {}

class MockTrustTokenObserver : public network::mojom::TrustTokenAccessObserver {};

MATCHER_P3(MatchesTrustTokenDetails, origin, issuer, blocked, "") {}

// Responds certificate request with previously set responses.
class ClientCertAuthObserver : public TestURLLoaderNetworkObserver {};

TEST_F(URLLoaderTest, SetAuth) {}

TEST_F(URLLoaderTest, CancelAuth) {}

TEST_F(URLLoaderTest, TwoChallenges) {}

TEST_F(URLLoaderTest, NoAuthRequiredForFavicon) {}

TEST_F(URLLoaderTest, HttpAuthResponseHeadersAvailable) {}

// Make sure the client can't call FollowRedirect if there's no pending
// redirect.
TEST_F(URLLoaderTest, FollowRedirectTwice) {}

class TestSSLPrivateKey : public net::SSLPrivateKey {};

#if !BUILDFLAG(IS_IOS)
TEST_F(URLLoaderTest, ClientAuthRespondTwice) {}

TEST_F(URLLoaderTest, ClientAuthDestroyResponder) {}

TEST_F(URLLoaderTest, ClientAuthCancelConnection) {}

TEST_F(URLLoaderTest, ClientAuthCancelCertificateSelection) {}

TEST_F(URLLoaderTest, ClientAuthNoCertificate) {}

TEST_F(URLLoaderTest, ClientAuthCertificateWithValidSignature) {}

TEST_F(URLLoaderTest, ClientAuthCertificateWithInvalidSignature) {}

TEST_F(URLLoaderTest, BlockAllCookies) {}

TEST_F(URLLoaderTest, BlockOnlyThirdPartyCookies) {}

TEST_F(URLLoaderTest, AllowAllCookies) {}

class StorageAccessHeaderURLLoaderTest : public URLLoaderTest {};

TEST_F(StorageAccessHeaderURLLoaderTest, StorageAccessHeader_Load_NoStatus) {}

TEST_F(StorageAccessHeaderURLLoaderTest, StorageAccessHeader_Load_StatusNone) {}

TEST_F(StorageAccessHeaderURLLoaderTest,
       StorageAccessHeader_Load_StatusInactive) {}

TEST_F(StorageAccessHeaderURLLoaderTest,
       StorageAccessHeader_Load_StatusActive) {}

TEST_F(StorageAccessHeaderURLLoaderTest, StorageAccessHeader_RedirectWithLoad) {}

class URLLoaderCookieSettingOverridesTest
    : public URLLoaderTest,
      public ::testing::WithParamInterface<
          std::tuple<bool, bool, net::StorageAccessApiStatus, bool>> {};

TEST_P(URLLoaderCookieSettingOverridesTest, CookieSettingOverrides) {}

TEST_P(URLLoaderCookieSettingOverridesTest,
       CookieSettingOverrides_OnSameSiteRedirects) {}

TEST_P(URLLoaderCookieSettingOverridesTest,
       CookieSettingOverrides_OnCrossSiteRedirects) {}

TEST_P(URLLoaderCookieSettingOverridesTest,
       CookieSettingOverrides_OnCrossSiteToSameSite) {}
INSTANTIATE_TEST_SUITE_P();

namespace {

enum class TestMode {};

}  // namespace

class URLLoaderParameterTest : public URLLoaderTest,
                               public ::testing::WithParamInterface<TestMode> {};

INSTANTIATE_TEST_SUITE_P();

// Tests that a request with CredentialsMode::kOmit still sends client
// certificates when features::kOmitCorsClientCert is disabled, and when the
// feature is enabled client certificates are not sent. Also test that when
// CredentialsMode::kOmitBug_775438_Workaround is used client certificates are
// not sent as well. This should be removed when crbug.com/775438 is fixed.
TEST_P(URLLoaderParameterTest, CredentialsModeOmitRequireClientCert) {}

// Tests that a request with CredentialsMode::kOmitBug_775438_Workaround, and
// CredentialsMode::kOmit when features::kOmitCorsClientCert is enabled doesn't
// send client certificates with a server that optionally requires certificates.
TEST_P(URLLoaderParameterTest, CredentialsModeOmitOptionalClientCert) {}

#endif  // !BUILDFLAG(IS_IOS)

TEST_F(URLLoaderTest, CookieReporting) {}

TEST_F(URLLoaderTest, CookieReportingRedirect) {}

TEST_F(URLLoaderTest, CookieReportingAuth) {}

TEST_F(URLLoaderTest, RawRequestCookies) {}

TEST_F(URLLoaderTest, RawRequestCookiesFlagged) {}

TEST_F(URLLoaderTest, RawResponseCookies) {}

TEST_F(URLLoaderTest, RawResponseCookiesInvalid) {}

TEST_F(URLLoaderTest, RawResponseCookiesRedirect) {}

TEST_F(URLLoaderTest, RawResponseCookiesAuth) {}

TEST_F(URLLoaderTest, RawResponseQUIC) {}

TEST_F(URLLoaderTest, EarlyHints) {}

TEST_F(URLLoaderTest, CookieReportingCategories) {}

namespace {

enum class SyncOrAsync {};

class MockTrustTokenRequestHelper : public TrustTokenRequestHelper {};

class NoopTrustTokenKeyCommitmentGetter : public TrustTokenKeyCommitmentGetter {};

base::NoDestructor<NoopTrustTokenKeyCommitmentGetter>
    noop_key_commitment_getter{};

mojom::NetworkContextClient* ReturnNullNetworkContextClient() {}

class MockTrustTokenRequestHelperFactory
    : public TrustTokenRequestHelperFactory {};

class MockTrustTokenDevToolsObserver : public MockDevToolsObserver {};

class ExpectBypassCacheInterceptor : public net::URLRequestInterceptor {};

class ExpectCookieSettingOverridesURLRequestInterceptor
    : public net::URLRequestInterceptor {};

}  // namespace

class URLLoaderSyncOrAsyncTrustTokenOperationTest
    : public URLLoaderTest,
      public ::testing::WithParamInterface<SyncOrAsync> {};

INSTANTIATE_TEST_SUITE_P();

// An otherwise-successful request with an associated Trust Tokens operation
// whose Begin and Finalize steps are both successful should succeed overall.
TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenOperationSuccess) {}

// A request with an associated Trust Tokens operation whose Begin step returns
// kAlreadyExists should return a success result immediately, without completing
// the load.
//
// (This is the case exactly when the request is for token redemption, and the
// Trust Tokens logic determines that there is already a cached redemption
// record stored locally, obviating the need to execute a redemption
// operation.)
TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenRedemptionRecordCacheHit) {}

TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenFollowedByAttribution) {}

// When a request's associated Trust Tokens operation's Begin step fails, the
// request itself should fail immediately.
TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenBeginFailure) {}

// When a request's associated Trust Tokens operation's Begin step succeeds but
// its Finalize step fails, the request itself should fail.
TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenFinalizeFailure) {}

// When URLLoader receives a  request parameterized to perform a Trust Tokens
// operation but fails to create a trust token request helper (because a
// universal Trust Tokens precondition is violated, for instance), the request
// should fail entirely.
TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenRequestHelperCreationFailure) {}

// When URLLoader receives a request that is blocked by policy, the request
// should fail entirely and report a blocked event to the observer.
TEST_P(URLLoaderSyncOrAsyncTrustTokenOperationTest,
       HandlesTrustTokenRequestHelperCreationBlocked) {}

TEST_F(URLLoaderTest, OnRawRequestClientSecurityStateFactory) {}

TEST_F(URLLoaderTest, OnRawRequestClientSecurityStateRequest) {}

TEST_F(URLLoaderTest, OnRawRequestClientSecurityStateNotPresent) {}

TEST_F(URLLoaderTest, OnRawResponseIPAddressSpace) {}

TEST_F(URLLoaderMockSocketTest, OrbDoesNotCloseSocketsWhenResourcesNotBlocked) {}

TEST_F(URLLoaderMockSocketTest, OrbClosesSocketOnReceivingHeaders) {}

TEST_F(URLLoaderMockSocketTest,
       OrbDoesNotCloseSocketsWhenResourcesNotBlockedAfterSniffingMimeType) {}

TEST_F(URLLoaderMockSocketTest, OrbClosesSocketOnSniffingMimeType) {}

TEST_F(URLLoaderMockSocketTest, CorpClosesSocket) {}

class URLLoaderMockSocketAuctionOnlyTest
    : public URLLoaderMockSocketTest,
      public testing::WithParamInterface<std::string> {};

TEST_P(URLLoaderMockSocketAuctionOnlyTest,
       FetchAuctionOnlySignalsFromRendererClosesSocket) {}

TEST_P(URLLoaderMockSocketAuctionOnlyTest,
       FetchAuctionOnlySignalsFromBrowserProcessSucceeds) {}

// TODO(crbug.com/40269364): Remove old names once API users have migrated to
// new names.
INSTANTIATE_TEST_SUITE_P();

TEST_F(URLLoaderMockSocketTest, PrivateNetworkRequestPolicyDoesNotCloseSocket) {}

TEST_F(URLLoaderTest, WithDnsAliases) {}

TEST_F(URLLoaderTest, NoAdditionalDnsAliases) {}

TEST_F(URLLoaderTest,
       PrivateNetworkRequestPolicyReportsOnPrivateNetworkRequestWarn) {}

TEST_F(URLLoaderTest,
       PrivateNetworkRequestPolicyReportsOnPrivateNetworkRequestBlock) {}

TEST_F(URLLoaderTest,
       PrivateNetworkRequestPolicyReportsOnPrivateNetworkRequestAllow) {}

// An empty ACCEPT_CH frame should skip the client call.
TEST_F(URLLoaderFakeTransportInfoTest, AcceptCHFrameEmptyString) {}

TEST_F(URLLoaderFakeTransportInfoTest, AcceptCHFrameParseString) {}

TEST_F(URLLoaderFakeTransportInfoTest, AcceptCHFrameRemoveDuplicates) {}

TEST_F(URLLoaderFakeTransportInfoTest, AcceptCHFrameIgnoreMalformed) {}

TEST_F(URLLoaderTest, CookieSettingOverridesCopiedToURLRequest) {}

TEST_F(URLLoaderTest, ReadAndDiscardBody) {}

class SharedStorageRequestHelperURLLoaderTest : public URLLoaderTest {};

TEST_F(SharedStorageRequestHelperURLLoaderTest, SimpleRequest) {}

TEST_F(SharedStorageRequestHelperURLLoaderTest, SimpleRedirect) {}

TEST_F(SharedStorageRequestHelperURLLoaderTest, MultipleRedirects) {}

TEST_F(SharedStorageRequestHelperURLLoaderTest, CrossSiteRedirect) {}

TEST_F(SharedStorageRequestHelperURLLoaderTest, RedirectNoLongerEligible) {}

TEST_F(SharedStorageRequestHelperURLLoaderTest, RedirectBecomesEligible) {}

}  // namespace network