chromium/third_party/blink/renderer/bindings/core/v8/script_streamer_test.cc

// Copyright 2014 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/bindings/core/v8/script_streamer.h"

#include <memory>
#include <utility>

#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.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/threading/thread_restrictions.h"
#include "mojo/public/cpp/base/big_buffer.h"
#include "mojo/public/cpp/system/data_pipe_utils.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/platform/platform.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/blink/public/platform/web_url_request_extra_data.h"
#include "third_party/blink/renderer/bindings/core/v8/referrer_script_info.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_code_cache.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_compile_hints_consumer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_local_compile_hints_consumer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_local_compile_hints_producer.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_script_runner.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/script/mock_script_element_base.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.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/thread_state.h"
#include "third_party/blink/renderer/platform/loader/fetch/cached_metadata.h"
#include "third_party/blink/renderer/platform/loader/fetch/cross_origin_attribute_value.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/response_body_loader.h"
#include "third_party/blink/renderer/platform/loader/fetch/script_cached_metadata_handler.h"
#include "third_party/blink/renderer/platform/loader/fetch/script_fetch_options.h"
#include "third_party/blink/renderer/platform/loader/fetch/url_loader/url_loader.h"
#include "third_party/blink/renderer/platform/loader/testing/mock_fetch_context.h"
#include "third_party/blink/renderer/platform/loader/testing/test_resource_fetcher_properties.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/testing/mock_context_lifecycle_notifier.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/testing/testing_platform_support_with_mock_scheduler.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/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
#include "v8/include/v8.h"

namespace blink {

namespace {

class TestResourceClient final : public GarbageCollected<TestResourceClient>,
                                 public ResourceClient {};

// TODO(leszeks): This class has a similar class in resource_loader_test.cc,
// the two should probably share the same class.
class NoopLoaderFactory final : public ResourceFetcher::LoaderFactory {};

void AppendDataToDataPipe(std::string_view data,
                          mojo::ScopedDataPipeProducerHandle& producer_handle) {}

const uint32_t kDataPipeSize =;

}  // namespace

class ScriptStreamingTest : public testing::Test {};

int ScriptStreamingTest::url_counter_ =;

TEST_F(ScriptStreamingTest, CompilingStreamedScript) {}

TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) {}

TEST_F(ScriptStreamingTest, CancellingStreaming) {}

TEST_F(ScriptStreamingTest, DataAfterCancelling) {}

TEST_F(ScriptStreamingTest, SuppressingStreaming) {}

TEST_F(ScriptStreamingTest, ConsumeLocalCompileHints) {}

TEST_F(ScriptStreamingTest, EmptyScripts) {}

TEST_F(ScriptStreamingTest, SmallScripts) {}

TEST_F(ScriptStreamingTest, ScriptsWithSmallFirstChunk) {}

TEST_F(ScriptStreamingTest, EncodingChanges) {}

TEST_F(ScriptStreamingTest, EncodingFromBOM) {}

// A test for crbug.com/711703. Should not crash.
TEST_F(ScriptStreamingTest, GarbageCollectDuringStreaming) {}

TEST_F(ScriptStreamingTest, ResourceSetRevalidatingRequest) {}

class InlineScriptStreamingTest
    : public ScriptStreamingTest,
      public ::testing::WithParamInterface<
          std::pair<bool /* 16 bit source */,
                    v8::ScriptCompiler::CompileOptions>> {};

TEST_P(InlineScriptStreamingTest, InlineScript) {}

TEST_F(ScriptStreamingTest, ProduceLocalCompileHintsForStreamedScript) {}

TEST_F(ScriptStreamingTest, NullCacheHandler) {}

INSTANTIATE_TEST_SUITE_P();

namespace {

// This is small enough to not start streaming (it is less than 4 bytes, so
// smaller than a UTF-8 BOM).
const char kTooSmallScript[] =;
// This script is large enough to start streaming (it is larger than 4 bytes, so
// larger than a UTF-8 BOM).
const char kLargeEnoughScript[] =;

// \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes
// for \uc481.
const char kScriptWithBOM[] =;

class DummyLoaderFactory final : public ResourceFetcher::LoaderFactory {};

class DummyBackgroundResponseProcessorClient
    : public BackgroundResponseProcessor::Client {};

class DummyCachedMetadataSender : public CachedMetadataSender {};

mojo_base::BigBuffer CreateDummyCodeCacheData() {}

mojo_base::BigBuffer CreateDummyTimeStampData() {}

network::mojom::URLResponseHeadPtr CreateURLResponseHead(
    const std::string& content_type = "text/javascript") {}

}  // namespace

class BackgroundResourceScriptStreamerTest : public testing::Test {};
int BackgroundResourceScriptStreamerTest::url_counter_ =;

TEST_F(BackgroundResourceScriptStreamerTest, UnsupportedModuleMimeType) {}

TEST_F(BackgroundResourceScriptStreamerTest, HasCodeCache) {}

class BackgroundResourceScriptStreamerCodeCacheDecodeStartTest
    : public BackgroundResourceScriptStreamerTest {};

TEST_F(BackgroundResourceScriptStreamerCodeCacheDecodeStartTest, HasCodeCache) {}

TEST_F(BackgroundResourceScriptStreamerTest, HasTimeStampData) {}

TEST_F(BackgroundResourceScriptStreamerTest, InvalidCachedMetadata) {}

TEST_F(BackgroundResourceScriptStreamerTest, SmallScript) {}

TEST_F(BackgroundResourceScriptStreamerTest, SmallScriptInFirstChunk) {}

TEST_F(BackgroundResourceScriptStreamerTest, EmptyScript) {}

TEST_F(BackgroundResourceScriptStreamerTest, EmptyScriptSyncCheckable) {}

TEST_F(BackgroundResourceScriptStreamerTest, EnoughData) {}

TEST_F(BackgroundResourceScriptStreamerTest, EnoughDataInFirstChunk) {}

TEST_F(BackgroundResourceScriptStreamerTest, EnoughDataModuleScript) {}

TEST_F(BackgroundResourceScriptStreamerTest, EncodingNotSupported) {}

TEST_F(BackgroundResourceScriptStreamerTest, EncodingFromBOM) {}

TEST_F(BackgroundResourceScriptStreamerTest, ScriptTypeMismatch) {}

TEST_F(BackgroundResourceScriptStreamerTest, CancelWhileWaitingForDataPipe) {}

TEST_F(BackgroundResourceScriptStreamerTest, CancelBeforeReceiveResponse) {}

TEST_F(BackgroundResourceScriptStreamerTest, CancelWhileRuningStreamingTask) {}

TEST_F(BackgroundResourceScriptStreamerTest, CompilingStreamedScript) {}

TEST_F(BackgroundResourceScriptStreamerTest,
       CompilingStreamedScriptWithParseError) {}

// Regression test for https://crbug.com/337998760.
TEST_F(BackgroundResourceScriptStreamerTest, DataPipeReadableAfterGC) {}

TEST_F(BackgroundResourceScriptStreamerTest,
       DataPipeReadableAfterProcessorIsDeleted) {}

// Regression test for https://crbug.com/341473518.
TEST_F(BackgroundResourceScriptStreamerTest,
       DeletingBackgroundProcessorWhileParsingShouldNotCrash) {}

}  // namespace blink