chromium/third_party/blink/renderer/bindings/modules/v8/serialization/v8_script_value_serializer_for_modules_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/modules/v8/serialization/v8_script_value_serializer_for_modules.h"

#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/filesystem/file_system.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_crypto_algorithm_params.h"
#include "third_party/blink/public/web/web_heap.h"
#include "third_party/blink/renderer/bindings/core/v8/dictionary.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.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_dom_exception.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_rect_read_only.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/modules/v8/serialization/v8_script_value_deserializer_for_modules.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_data.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_data_copy_to_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_browser_capture_media_stream_track.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_crop_target.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_crypto_key.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_dom_file_system.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_media_stream_track.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_restriction_target.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_rtc_certificate.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_rtc_data_channel.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_video_frame.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/modules/crypto/crypto_key.h"
#include "third_party/blink/renderer/modules/crypto/crypto_result_impl.h"
#include "third_party/blink/renderer/modules/filesystem/dom_file_system.h"
#include "third_party/blink/renderer/modules/mediastream/browser_capture_media_stream_track.h"
#include "third_party/blink/renderer/modules/mediastream/crop_target.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_track.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_track_impl.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_capturer_source.h"
#include "third_party/blink/renderer/modules/mediastream/media_stream_video_track.h"
#include "third_party/blink/renderer/modules/mediastream/mock_media_stream_video_source.h"
#include "third_party/blink/renderer/modules/mediastream/mock_video_capturer_source.h"
#include "third_party/blink/renderer/modules/mediastream/restriction_target.h"
#include "third_party/blink/renderer/modules/mediastream/test/transfer_test_utils.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_certificate.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_certificate_generator.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_data_channel.h"
#include "third_party/blink/renderer/modules/peerconnection/rtc_data_channel_transfer_list.h"
#include "third_party/blink/renderer/modules/peerconnection/testing/fake_webrtc_data_channel.h"
#include "third_party/blink/renderer/modules/webcodecs/array_buffer_util.h"
#include "third_party/blink/renderer/modules/webcodecs/audio_data.h"
#include "third_party/blink/renderer/modules/webcodecs/audio_data_transfer_list.h"
#include "third_party/blink/renderer/modules/webcodecs/video_frame.h"
#include "third_party/blink/renderer/modules/webcodecs/video_frame_transfer_list.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_source.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_audio_track.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_component_impl.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_source.h"
#include "third_party/blink/renderer/platform/testing/io_task_runner_testing_platform_support.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/testing/unit_test_helpers.h"

ElementsAre;
ElementsAreArray;
UnorderedElementsAre;

namespace blink {
namespace {

v8::Local<v8::Value> RoundTripForModules(
    v8::Local<v8::Value> value,
    V8TestingScope& scope,
    Transferables* transferables = nullptr) {}

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

static const char kEcdsaPrivateKey[] =;

static const char kEcdsaCertificate[] =;

static const uint8_t kEcdsaCertificateEncoded[] =;

TEST(V8ScriptValueSerializerForModulesTest, RoundTripRTCCertificate) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeRTCCertificate) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidRTCCertificate) {}

// A bunch of voodoo which allows the asynchronous WebCrypto operations to be
// called synchronously, with the resulting JavaScript values extracted.

CryptoKeyPair;

template <typename T>
T ConvertCryptoResult(v8::Isolate*, const ScriptValue&);
template <>
CryptoKey* ConvertCryptoResult<CryptoKey*>(v8::Isolate* isolate,
                                           const ScriptValue& value) {}
template <>
CryptoKeyPair ConvertCryptoResult<CryptoKeyPair>(v8::Isolate* isolate,
                                                 const ScriptValue& value) {}
template <>
DOMException* ConvertCryptoResult<DOMException*>(v8::Isolate* isolate,
                                                 const ScriptValue& value) {}
template <>
WebVector<unsigned char> ConvertCryptoResult<WebVector<unsigned char>>(
    v8::Isolate* isolate,
    const ScriptValue& value) {}
template <>
bool ConvertCryptoResult<bool>(v8::Isolate*, const ScriptValue& value) {}

template <typename T>
class WebCryptoResultAdapter : public ScriptFunction::Callable {};

template <typename IDLType, typename T>
WebCryptoResult ToWebCryptoResult(ScriptState* script_state,
                                  base::RepeatingCallback<void(T)> function) {}

template <typename T, typename IDLType, typename PMF, typename... Args>
T SubtleCryptoSync(ScriptState* script_state, PMF func, Args&&... args) {}

CryptoKey* SyncGenerateKey(ScriptState* script_state,
                           const WebCryptoAlgorithm& algorithm,
                           bool extractable,
                           WebCryptoKeyUsageMask usages) {}

CryptoKeyPair SyncGenerateKeyPair(ScriptState* script_state,
                                  const WebCryptoAlgorithm& algorithm,
                                  bool extractable,
                                  WebCryptoKeyUsageMask usages) {}

CryptoKey* SyncImportKey(ScriptState* script_state,
                         WebCryptoKeyFormat format,
                         WebVector<unsigned char> data,
                         const WebCryptoAlgorithm& algorithm,
                         bool extractable,
                         WebCryptoKeyUsageMask usages) {}

WebVector<uint8_t> SyncExportKey(ScriptState* script_state,
                                 WebCryptoKeyFormat format,
                                 const WebCryptoKey& key) {}

WebVector<uint8_t> SyncEncrypt(ScriptState* script_state,
                               const WebCryptoAlgorithm& algorithm,
                               const WebCryptoKey& key,
                               WebVector<unsigned char> data) {}

WebVector<uint8_t> SyncDecrypt(ScriptState* script_state,
                               const WebCryptoAlgorithm& algorithm,
                               const WebCryptoKey& key,
                               WebVector<unsigned char> data) {}

WebVector<uint8_t> SyncSign(ScriptState* script_state,
                            const WebCryptoAlgorithm& algorithm,
                            const WebCryptoKey& key,
                            WebVector<unsigned char> message) {}

bool SyncVerifySignature(ScriptState* script_state,
                         const WebCryptoAlgorithm& algorithm,
                         const WebCryptoKey& key,
                         WebVector<unsigned char> signature,
                         WebVector<unsigned char> message) {}

WebVector<uint8_t> SyncDeriveBits(ScriptState* script_state,
                                  const WebCryptoAlgorithm& algorithm,
                                  const WebCryptoKey& key,
                                  unsigned length) {}

// AES-128-CBC uses AES key params.
TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyAES) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyAES) {}

// HMAC-SHA256 uses HMAC key params.
TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyHMAC) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyHMAC) {}

// RSA-PSS-SHA256 uses RSA hashed key params.
TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyRSAHashed) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyRSAHashed) {}

// ECDSA uses EC key params.
TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEC) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyEC) {}

// Ed25519 uses no params.
TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyEd25519) {}

// Ed25519 uses no params.
TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyEd25519) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyX25519) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyX25519) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripCryptoKeyNoParams) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyNoParams) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeCryptoKeyInvalid) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystem) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripDOMFileSystemNotClonable) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeDOMFileSystem) {}

TEST(V8ScriptValueSerializerForModulesTest, DecodeInvalidDOMFileSystem) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripVideoFrame) {}

TEST(V8ScriptValueSerializerForModulesTest, TransferVideoFrame) {}

TEST(V8ScriptValueSerializerForModulesTest, ClosedVideoFrameThrows) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripAudioData) {}

TEST(V8ScriptValueSerializerForModulesTest, TransferAudioData) {}

TEST(V8ScriptValueSerializerForModulesTest, ClosedAudioDataThrows) {}

TEST(V8ScriptValueSerializerForModulesTest, TransferMediaStreamTrack) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferMediaStreamTrackRegionCaptureDisabled) {}

TEST(V8ScriptValueSerializerForModulesTest, TransferAudioMediaStreamTrack) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferClonedMediaStreamTrackFails) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferDeviceCaptureMediaStreamTrackFails) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferScreenCaptureMediaStreamTrackFails) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferWindowCaptureMediaStreamTrackFails) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferClosedMediaStreamTrackFails) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferMediaStreamTrackInvalidContentHintFails) {}

TEST(V8ScriptValueSerializerForModulesTest,
     TransferMediaStreamTrackNoSessionIdThrows) {}

TEST(V8ScriptValueSerializerForModulesTest, TransferRTCDataChannel) {}

#if !BUILDFLAG(IS_ANDROID)  // SubCaptureTargets are not exposed on Android.
TEST(V8ScriptValueSerializerForModulesTest, RoundTripCropTarget) {}

TEST(V8ScriptValueSerializerForModulesTest, RoundTripRestrictionTarget) {}
#endif

TEST(V8ScriptValueSerializerForModulesTest,
     ArrayBufferDetachKeyPreventsTransfer) {}

TEST(V8ScriptValueSerializerForModulesTest,
     ArrayBufferDetachKeyDoesNotPreventSerialize) {}

}  // namespace
}  // namespace blink