chromium/third_party/blink/renderer/platform/loader/fetch/resource_fetcher_test.cc

/*
 * Copyright (c) 2013, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#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 {};

}  // namespace

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

// Verify that the ad bit is copied to WillSendRequest's request when the
// response is served from the memory cache.
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) {}

// TODO(crbug.com/850785): Reenable this.
#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 {};

// Regression test for http://crbug.com/594072.
// This emulates a modal dialog triggering a nested run loop inside
// ResourceLoader::Cancel(). If the ResourceLoader doesn't promptly cancel its
// URLLoader before notifying its clients, a nested run loop  may send a network
// response, leading to an invalid state transition in ResourceLoader.
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) {}

// TODO(crbug.com/850785): Reenable this.
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ContentTypeDataURL
#else
#define MAYBE_ContentTypeDataURL
#endif
TEST_F(ResourceFetcherTest, MAYBE_ContentTypeDataURL) {}

// Request with the Content-ID scheme must not be canceled, even if there is no
// MHTMLArchive to serve them.
// Note: Not blocking it is important because there are some embedders of
// Android WebView that are intercepting Content-ID URLs and serve their own
// resources. Please see https://crbug.com/739658.
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) {}

}  // namespace blink