#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include <memory>
#include <optional>
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "services/network/public/mojom/ip_address_space.mojom-blink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom-blink.h"
#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/platform/exported/wrapped_resource_response.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/loader/fetch/console_logger.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_info.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_initiator_type_names.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/loader/fetch/raw_resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_error.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_load_observer.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_request.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_timing_utils.h"
#include "third_party/blink/renderer/platform/loader/fetch/unique_identifier.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader.h"
#include "third_party/blink/renderer/platform/loader/testing/fetch_testing_platform_support.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_fetch_context.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_resource.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_resource_client.h"
#include "third_party/blink/renderer/platform/loader/testing/test_loader_factory.h"
#include "third_party/blink/renderer/platform/loader/testing/test_resource_fetcher_properties.h"
#include "third_party/blink/renderer/platform/testing/mock_context_lifecycle_notifier.h"
#include "third_party/blink/renderer/platform/testing/scoped_mocked_url.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory_impl.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink {
namespace {
constexpr char kTestResourceFilename[] = …;
constexpr char kTestResourceMimeType[] = …;
class PartialResourceRequest { … };
}
class ResourceFetcherTest : public testing::Test { … };
TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) { … }
TEST_F(ResourceFetcherTest, UseExistingResource) { … }
TEST_F(ResourceFetcherTest, MemoryCachePerContextUseExistingResource) { … }
TEST_F(ResourceFetcherTest, MetricsPerTopFrameSite) { … }
TEST_F(ResourceFetcherTest, MetricsPerTopFrameSiteOpaqueOrigins) { … }
TEST_F(ResourceFetcherTest, WillSendRequestAdBit) { … }
TEST_F(ResourceFetcherTest, Vary) { … }
TEST_F(ResourceFetcherTest, VaryOnBack) { … }
TEST_F(ResourceFetcherTest, VaryResource) { … }
class RequestSameResourceOnComplete
: public GarbageCollected<RequestSameResourceOnComplete>,
public RawResourceClient { … };
TEST_F(ResourceFetcherTest, DISABLED_RevalidateWhileFinishingLoading) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_DontReuseMediaDataUrl …
#else
#define MAYBE_DontReuseMediaDataUrl …
#endif
TEST_F(ResourceFetcherTest, MAYBE_DontReuseMediaDataUrl) { … }
class ServeRequestsOnCompleteClient final
: public GarbageCollected<ServeRequestsOnCompleteClient>,
public RawResourceClient { … };
TEST_F(ResourceFetcherTest, ResponseOnCancel) { … }
class ScopedMockRedirectRequester { … };
TEST_F(ResourceFetcherTest, SynchronousRequest) { … }
TEST_F(ResourceFetcherTest, PingPriority) { … }
TEST_F(ResourceFetcherTest, PreloadResourceTwice) { … }
TEST_F(ResourceFetcherTest, LinkPreloadResourceAndUse) { … }
TEST_F(ResourceFetcherTest, PreloadMatchWithBypassingCache) { … }
TEST_F(ResourceFetcherTest, CrossFramePreloadMatchIsNotAllowed) { … }
TEST_F(ResourceFetcherTest, RepetitiveLinkPreloadShouldBeMerged) { … }
TEST_F(ResourceFetcherTest, RepetitiveSpeculativePreloadShouldBeMerged) { … }
TEST_F(ResourceFetcherTest, SpeculativePreloadShouldBePromotedToLinkPreload) { … }
TEST_F(ResourceFetcherTest, Revalidate304) { … }
TEST_F(ResourceFetcherTest, LinkPreloadResourceMultipleFetchersAndMove) { … }
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ContentTypeDataURL …
#else
#define MAYBE_ContentTypeDataURL …
#endif
TEST_F(ResourceFetcherTest, MAYBE_ContentTypeDataURL) { … }
TEST_F(ResourceFetcherTest, ContentIdURL) { … }
TEST_F(ResourceFetcherTest, StaleWhileRevalidate) { … }
TEST_F(ResourceFetcherTest, CachedResourceShouldNotCrashByNullURL) { … }
TEST_F(ResourceFetcherTest, DeprioritizeSubframe) { … }
TEST_F(ResourceFetcherTest, BoostImagePriority) { … }
TEST_F(ResourceFetcherTest, IsPotentiallyLCPElement) { … }
TEST_F(ResourceFetcherTest, Detach) { … }
TEST_F(ResourceFetcherTest, DuplicatePreloadAllowsPriorityChange) { … }
TEST_F(ResourceFetcherTest, StrongReferenceThreshold) { … }
TEST_F(ResourceFetcherTest,
EmulateLoadStartedForInspectorOncePerResourceDisabled) { … }
TEST_F(ResourceFetcherTest,
EmulateLoadStartedForInspectorOncePerResourceEnabled) { … }
class DeferUnusedPreloadResourceFetcherTest : public ResourceFetcherTest { … };
TEST_F(DeferUnusedPreloadResourceFetcherTest, IsPotentiallyUnusedPreload) { … }
class DeferUnusedPreloadWithPreloadedReasonResourceFetcherTest
: public DeferUnusedPreloadResourceFetcherTest,
public testing::WithParamInterface<
features::LcppDeferUnusedPreloadPreloadedReason> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(DeferUnusedPreloadWithPreloadedReasonResourceFetcherTest, NotPreload) { … }
TEST_P(DeferUnusedPreloadWithPreloadedReasonResourceFetcherTest, LinkPreload) { … }
TEST_P(DeferUnusedPreloadWithPreloadedReasonResourceFetcherTest,
SpeculativePreload) { … }
class DeferUnusedPreloadWithExcludedResourceTypeResourceFetcherTest
: public DeferUnusedPreloadResourceFetcherTest,
public testing::WithParamInterface<
features::LcppDeferUnusedPreloadExcludedResourceType> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(DeferUnusedPreloadWithExcludedResourceTypeResourceFetcherTest,
LinkPreload) { … }
class TransparentPlaceholderResourceFetcherTest
: public ResourceFetcherTest,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(TransparentPlaceholderResourceFetcherTest, InspectorAttached) { … }
TEST_P(TransparentPlaceholderResourceFetcherTest, InspectorNotAttached) { … }
}