chromium/third_party/blink/renderer/platform/loader/fetch/url_loader/background_url_loader_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_url_loader.h"

#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_restrictions.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/navigation/renderer_eviction_reason.mojom-blink.h"
#include "third_party/blink/public/platform/resource_load_info_notifier_wrapper.h"
#include "third_party/blink/public/platform/web_background_resource_fetch_assets.h"
#include "third_party/blink/public/platform/web_runtime_features.h"
#include "third_party/blink/public/platform/web_url_error.h"
#include "third_party/blink/public/platform/web_url_response.h"
#include "third_party/blink/renderer/platform/back_forward_cache_buffer_limit_tracker.h"
#include "third_party/blink/renderer/platform/loader/fetch/back_forward_cache_loader_helper.h"
#include "third_party/blink/renderer/platform/loader/fetch/background_code_cache_host.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/background_response_processor.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader_client.h"
#include "third_party/blink/renderer/platform/loader/testing/fake_background_resource_fetch_assets.h"
#include "third_party/blink/renderer/platform/loader/testing/fake_url_loader_factory_for_background_thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/test/fake_task_runner.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_mojo.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "url/gurl.h"

namespace WTF {

template <>
struct CrossThreadCopier<network::mojom::URLResponseHeadPtr> {};

template <>
struct CrossThreadCopier<std::optional<mojo_base::BigBuffer>> {};

template <>
struct CrossThreadCopier<SegmentedBuffer> {};

}  // namespace WTF

namespace blink {
namespace {

constexpr char kTestURL[] =;
constexpr char kRedirectedURL[] =;
constexpr int kMaxBufferedBytesPerProcess =;
constexpr std::string kTestBodyString =;

MaybeStartFunction;

class BackgroundResponseProcessorTestUtil
    : public WTF::ThreadSafeRefCounted<BackgroundResponseProcessorTestUtil> {};

mojo::ScopedDataPipeConsumerHandle CreateDataPipeConsumerHandleFilledWithString(
    const std::string& string) {}

mojo::ScopedDataPipeConsumerHandle CreateTestBody() {}

SegmentedBuffer CreateTestBodyRawData() {}

mojo_base::BigBuffer CreateTestCachedMetaData() {}

std::unique_ptr<network::ResourceRequest> CreateTestRequest() {}

network::mojom::URLResponseHeadPtr CreateTestResponse() {}

class FakeBackForwardCacheLoaderHelper final
    : public BackForwardCacheLoaderHelper {};

class FakeURLLoaderClient : public URLLoaderClient {};

struct PriorityInfo {};

class FakeURLLoader : public network::mojom::URLLoader {};

// Sets up the message sender override for the unit test.
class BackgroundResourceFecherTest : public testing::Test {};

TEST_F(BackgroundResourceFecherTest, SimpleRequest) {}

TEST_F(BackgroundResourceFecherTest, FailedRequest) {}

TEST_F(BackgroundResourceFecherTest, Redirect) {}

TEST_F(BackgroundResourceFecherTest, RedirectDoNotFollow) {}

TEST_F(BackgroundResourceFecherTest, RedirectAndCancelDoNotCrash) {}

TEST_F(BackgroundResourceFecherTest, AbortWhileHandlingRedirectDoNotCrash) {}

TEST_F(BackgroundResourceFecherTest, CancelSoonAfterStart) {}

TEST_F(BackgroundResourceFecherTest, CancelAfterStart) {}

TEST_F(BackgroundResourceFecherTest, CancelAfterReceiveResponse) {}

TEST_F(BackgroundResourceFecherTest, FreezeThenUnfreeze) {}

TEST_F(BackgroundResourceFecherTest, FreezeCancelThenUnfreeze) {}

TEST_F(BackgroundResourceFecherTest, BufferIncomingFreezeAndResume) {}

TEST_F(BackgroundResourceFecherTest,
       BufferIncomingFreezeExceedMaxBufferedBytesPerProcess) {}

TEST_F(BackgroundResourceFecherTest,
       BufferIncomingFreezeAndResumeBeforeExecutingUnfreezableTask) {}

TEST_F(BackgroundResourceFecherTest, ChangePriority) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorSyncReturnFalse) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorFinishWithPipeBeforeOtherIpc) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorFinishWithRawDataBeforeOtherIpc) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorFinishAfterOnTransferSizeUpdatedIpc) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorFinishAfterOnCompleteIpc) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorFreezeBeforeReceiveResponse) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorFreezeAfterReceiveResponse) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorExceedMaxBufferedBytesPerProcess) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorCancelBeforeReceiveResponse) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorCancelAfterReceiveResponse) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorCancelAfterReceiveResponseAndCallFinish) {}

TEST_F(BackgroundResourceFecherTest,
       BackgroundResponseProcessorCompleteWithoutResponse) {}

}  // namespace
}  // namespace blink