chromium/third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_serializer_test.cc

// Copyright 2016 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/serialization/v8_script_value_serializer.h"

#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "gin/wrappable.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/platform/web_blob_info.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/trailer_reader.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/unpacked_serialized_script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/v8_script_value_deserializer.h"
#include "third_party/blink/renderer/bindings/core/v8/to_v8_traits.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_blob.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_matrix.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_matrix_init.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_matrix_read_only.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_point.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_point_init.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_point_read_only.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_quad.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_rect.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_rect_read_only.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_fenced_frame_config.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_file.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_file_list.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_data.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_message_port.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_mojo_handle.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_offscreen_canvas.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_readable_stream.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_string_resource.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_float32array_uint16array_uint8clampedarray.h"
#include "third_party/blink/renderer/core/context_features/context_feature_settings.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/fileapi/file.h"
#include "third_party/blink/renderer/core/fileapi/file_list.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/geometry/dom_matrix.h"
#include "third_party/blink/renderer/core/geometry/dom_matrix_read_only.h"
#include "third_party/blink/renderer/core/geometry/dom_point.h"
#include "third_party/blink/renderer/core/geometry/dom_point_read_only.h"
#include "third_party/blink/renderer/core/geometry/dom_quad.h"
#include "third_party/blink/renderer/core/geometry/dom_rect.h"
#include "third_party/blink/renderer/core/geometry/dom_rect_read_only.h"
#include "third_party/blink/renderer/core/html/canvas/image_data.h"
#include "third_party/blink/renderer/core/html/fenced_frame/fenced_frame_config.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/mojo/mojo_handle.h"
#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/streams/readable_stream.h"
#include "third_party/blink/renderer/core/streams/transform_stream.h"
#include "third_party/blink/renderer/core/testing/file_backed_blob_factory_test_helper.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/blob/blob_data.h"
#include "third_party/blink/renderer/platform/file_metadata.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"
#include "third_party/blink/renderer/platform/wtf/date_math.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"

namespace blink {
namespace {

v8::Local<v8::Value> RoundTrip(
    v8::Local<v8::Value> value,
    V8TestingScope& scope,
    ExceptionState* override_exception_state = nullptr,
    Transferables* transferables = nullptr,
    WebBlobInfoArray* blob_info = nullptr) {}

v8::Local<v8::Value> Eval(const String& source, V8TestingScope& scope) {}

String ToJSON(v8::Local<v8::Object> object, const V8TestingScope& scope) {}
}  // namespace

scoped_refptr<SerializedScriptValue> SerializedValue(
    const Vector<uint8_t>& bytes) {}

// Checks for a DOM exception, including a rethrown one.
testing::AssertionResult HadDOMExceptionInCoreTest(
    const StringView& name,
    ScriptState* script_state,
    ExceptionState& exception_state) {}

TEST(V8ScriptValueSerializerTest, RoundTripJSONLikeValue) {}

TEST(V8ScriptValueSerializerTest, ThrowsDataCloneError) {}

TEST(V8ScriptValueSerializerTest, RethrowsScriptError) {}

TEST(V8ScriptValueSerializerTest, DeserializationErrorReturnsNull) {}

TEST(V8ScriptValueSerializerTest, DetachHappensAfterSerialization) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMPoint) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMPoint) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMPointReadOnly) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMPointReadOnly) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMRect) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMRect) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMRectReadOnly) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMRectReadOnly) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMQuad) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMQuad) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrix2D) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMMatrix2D) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrixReadOnly2D) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMMatrixReadOnly2D) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrix) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMMatrix) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMMatrixReadOnly) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMMatrixReadOnly) {}

TEST(V8ScriptValueSerializerTest, RoundTripImageData) {}

TEST(V8ScriptValueSerializerTest, RoundTripDetachedImageData) {}

TEST(V8ScriptValueSerializerTest, RoundTripImageDataWithColorSpaceInfo) {}

TEST(V8ScriptValueSerializerTest, DecodeImageDataV9) {}

TEST(V8ScriptValueSerializerTest, DecodeImageDataV16) {}

TEST(V8ScriptValueSerializerTest, DecodeImageDataV18) {}

TEST(V8ScriptValueSerializerTest, InvalidImageDataDecodeV18) {}

MessagePort* MakeMessagePort(ExecutionContext* execution_context,
                             ::MojoHandle* unowned_handle_out = nullptr) {}

TEST(V8ScriptValueSerializerTest, RoundTripMessagePort) {}

TEST(V8ScriptValueSerializerTest, NeuteredMessagePortThrowsDataCloneError) {}

TEST(V8ScriptValueSerializerTest,
     UntransferredMessagePortThrowsDataCloneError) {}

TEST(V8ScriptValueSerializerTest, OutOfRangeMessagePortIndex) {}

TEST(V8ScriptValueSerializerTest, RoundTripMojoHandle) {}

TEST(V8ScriptValueSerializerTest, UntransferredMojoHandleThrowsDataCloneError) {}

// Decode tests for backward compatibility are not required for message ports
// and Mojo handles because they cannot be persisted to disk.

// A more exhaustive set of ImageBitmap cases are covered by web tests.
TEST(V8ScriptValueSerializerTest, RoundTripImageBitmap) {}

TEST(V8ScriptValueSerializerTest, ImageBitmapEXIFImageOrientation) {}

TEST(V8ScriptValueSerializerTest, RoundTripImageBitmapWithColorSpaceInfo) {}

TEST(V8ScriptValueSerializerTest, DecodeImageBitmap) {}

TEST(V8ScriptValueSerializerTest, DecodeImageBitmapV18) {}

TEST(V8ScriptValueSerializerTest, DecodeImageBitmapV20WithoutImageOrientation) {}

TEST(V8ScriptValueSerializerTest, DecodeImageBitmapV20WithImageOrientation) {}

TEST(V8ScriptValueSerializerTest, InvalidImageBitmapDecode) {}

TEST(V8ScriptValueSerializerTest, InvalidImageBitmapDecodeV18) {}

TEST(V8ScriptValueSerializerTest, TransferImageBitmap) {}

TEST(V8ScriptValueSerializerTest, TransferOffscreenCanvas) {}

TEST(V8ScriptValueSerializerTest, RoundTripBlob) {}

TEST(V8ScriptValueSerializerTest, DecodeBlob) {}

TEST(V8ScriptValueSerializerTest, RoundTripBlobIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeBlobIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeBlobIndexOutOfRange) {}

TEST(V8ScriptValueSerializerTest, RoundTripFileNative) {}

TEST(V8ScriptValueSerializerTest, RoundTripFileBackedByBlob) {}

TEST(V8ScriptValueSerializerTest, RoundTripFileNativeSnapshot) {}

TEST(V8ScriptValueSerializerTest, RoundTripFileNonNativeSnapshot) {}

// Used for checking that times provided are between now and the current time
// when the checker was constructed, according to base::Time::Now.
class TimeIntervalChecker {};

TEST(V8ScriptValueSerializerTest, DecodeFileV3) {}

TEST(V8ScriptValueSerializerTest, DecodeFileV4) {}

TEST(V8ScriptValueSerializerTest, DecodeFileV4WithSnapshot) {}

TEST(V8ScriptValueSerializerTest, DecodeFileV7) {}

TEST(V8ScriptValueSerializerTest, DecodeFileV8WithSnapshot) {}

TEST(V8ScriptValueSerializerTest, RoundTripFileIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeFileIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeFileIndexOutOfRange) {}

// Most of the logic for FileList is shared with File, so the tests here are
// fairly basic.

TEST(V8ScriptValueSerializerTest, RoundTripFileList) {}

TEST(V8ScriptValueSerializerTest, DecodeEmptyFileList) {}

TEST(V8ScriptValueSerializerTest, DecodeFileListWithInvalidLength) {}

TEST(V8ScriptValueSerializerTest, DecodeFileListV8WithoutSnapshot) {}

TEST(V8ScriptValueSerializerTest, RoundTripFileListIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeEmptyFileListIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeFileListIndexWithInvalidLength) {}

TEST(V8ScriptValueSerializerTest, DecodeFileListIndex) {}

TEST(V8ScriptValueSerializerTest, DecodeHardcodedNullValue) {}

// This is not the most efficient way to write a small version, but it's
// technically admissible. We should handle this in a consistent way to avoid
// DCHECK failure. Thus this is "true" encoded slightly strangely.
TEST(V8ScriptValueSerializerTest, DecodeWithInefficientVersionEnvelope) {}

// Sanity check for transferring ReadableStreams. This is mostly tested via
// web tests.
TEST(V8ScriptValueSerializerTest, RoundTripReadableStream) {}

TEST(V8ScriptValueSerializerTest, TransformStreamIntegerOverflow) {}

TEST(V8ScriptValueSerializerTest, RoundTripDOMException) {}

TEST(V8ScriptValueSerializerTest, DecodeDOMExceptionWithInvalidNameString) {}

TEST(V8ScriptValueSerializerTest, NoSharedValueConveyor) {}

TEST(V8ScriptValueSerializerTest, CanDeserializeIn_OldValues) {}

TEST(V8ScriptValueSerializerTest, RoundTripFencedFrameConfig) {}

TEST(V8ScriptValueSerializerTest, RoundTripFencedFrameConfigNullValues) {}

namespace {

class GinWrappable : public gin::Wrappable<GinWrappable> {};

gin::WrapperInfo GinWrappable::kWrapperInfo =;

}  // namespace

TEST(V8ScriptValueSerializerTest, CoexistWithGin) {}

}  // namespace blink