chromium/third_party/blink/renderer/core/fetch/fetch_manager_test.cc

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

#include "third_party/blink/renderer/core/fetch/fetch_manager.h"

#include <optional>

#include "base/memory/scoped_refptr.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gmock/include/gmock/gmock.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/frame/lifecycle.mojom-blink.h"
#include "third_party/blink/public/mojom/loader/fetch_later.mojom.h"
#include "third_party/blink/public/platform/url_conversion.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_request_init.h"
#include "third_party/blink/renderer/core/dom/abort_controller.h"
#include "third_party/blink/renderer/core/fetch/fetch_later_result.h"
#include "third_party/blink/renderer/core/fetch/fetch_request_data.h"
#include "third_party/blink/renderer/core/fetch/request.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_load_priority.h"
#include "third_party/blink/renderer/platform/mojo/heap_mojo_associated_receiver.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/url_loader_mock_factory.h"
#include "third_party/blink/renderer/platform/testing/url_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"

namespace blink {
namespace {

_;
Eq;
IsNull;
Not;

MATCHER_P(HasRangeError,
          expected_message,
          base::StrCat({}

MATCHER_P(HasAbortError,
          expected_message,
          base::StrCat({}

MATCHER_P(MatchNetworkResourceRequest,
          expected,
          base::StrCat({}

class MockFetchLaterLoaderFactory
    : public blink::mojom::FetchLaterLoaderFactory {};

// A fake LocalFrameClient that provides non-null ChildURLLoaderFactoryBundle.
class FakeLocalFrameClient : public EmptyLocalFrameClient {};

}  // namespace

class FetchLaterTest : public testing::Test {};

class FetchLaterTestingScope : public V8TestingScope {};

// A FetchLater request where its URL has same-origin as its execution context.
TEST_F(FetchLaterTest, CreateSameOriginFetchLaterRequest) {}

TEST_F(FetchLaterTest, NegativeActivateAfterThrowRangeError) {}

// Test to cover when a FetchLaterManager::FetchLater() call is provided with an
// AbortSignal that has been aborted.
TEST_F(FetchLaterTest, AbortBeforeFetchLater) {}

// Test to cover when a FetchLaterManager::FetchLater() is aborted after being
// called.
TEST_F(FetchLaterTest, AbortAfterFetchLater) {}

// Test to cover a FetchLaterManager::FetchLater() with custom activateAfter.
TEST_F(FetchLaterTest, ActivateAfter) {}

// Test to cover when a FetchLaterManager::FetchLater()'s execution context is
// destroyed.
TEST_F(FetchLaterTest, ContextDestroyed) {}

// Test to cover when a FetchLaterManager::DeferredLoader triggers its Process()
// method when its context enters BackForwardCache with BackgroundSync
// permission off.
TEST_F(FetchLaterTest, ForcedSendingWithBackgroundSyncOff) {}

// The default priority for FetchLater request without FetchPriorityHint or
// RenderBlockingBehavior should be kHigh.
TEST(FetchLaterLoadPriorityTest, DefaultHigh) {}

// The priority for FetchLater request with FetchPriorityHint::kAuto should be
// kHigh.
TEST(FetchLaterLoadPriorityTest, WithFetchPriorityHintAuto) {}

// The priority for FetchLater request with FetchPriorityHint::kLow should be
// kLow.
TEST(FetchLaterLoadPriorityTest, WithFetchPriorityHintLow) {}

// The priority for FetchLater request with RenderBlockingBehavior::kBlocking
// should be kHigh.
TEST(FetchLaterLoadPriorityTest,
     WithFetchPriorityHintLowAndRenderBlockingBehaviorBlocking) {}

}  // namespace blink