chromium/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_api_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 <stddef.h>
#include <stdint.h>

#include <memory>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "cc/paint/refcounted_buffer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings.h"
#include "third_party/blink/public/common/privacy_budget/identifiability_study_settings_provider.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_surface.h"
#include "third_party/blink/public/common/privacy_budget/identifiable_token.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_blob_callback.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_data_settings.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_float32array_uint16array_uint8clampedarray.h"  // IWYU pragma: keep
#include "third_party/blink/renderer/bindings/modules/v8/v8_begin_layer_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_blob_htmlcanvaselement_htmlimageelement_htmlvideoelement_imagebitmap_imagedata_offscreencanvas_svgimageelement_videoframe.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_union_cssimagevalue_htmlcanvaselement_htmlimageelement_htmlvideoelement_imagebitmap_offscreencanvas_svgimageelement_videoframe.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_performance_monitor.h"
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h"
#include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
#include "third_party/blink/renderer/core/html/canvas/image_data.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_style_test_utils.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/identifiability_study_helper.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/mesh_2d_index_buffer.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/mesh_2d_uv_buffer.h"
#include "third_party/blink/renderer/modules/canvas/canvas2d/mesh_2d_vertex_buffer.h"
#include "third_party/blink/renderer/modules/canvas/imagebitmap/image_bitmap_factories.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.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/graphics/graphics_types.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/skia/include/private/base/SkPoint_impl.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-local-handle.h"

// GoogleTest expectation macros trigger a bug in IWYU:
// https://github.com/include-what-you-use/include-what-you-use/issues/1546
// IWYU pragma: no_include <string>
// IWYU pragma: no_include <tuple>

namespace v8 {
class Isolate;
}  // namespace v8

namespace blink {

class CanvasRenderingContext2DAPITest : public PageTestBase {};

CanvasRenderingContext2DAPITest::CanvasRenderingContext2DAPITest() = default;

CanvasRenderingContext2D* CanvasRenderingContext2DAPITest::Context2D() const {}

void CanvasRenderingContext2DAPITest::CreateContext(OpacityMode opacity_mode) {}

void CanvasRenderingContext2DAPITest::SetUp() {}

void CanvasRenderingContext2DAPITest::TearDown() {}

TEST_F(CanvasRenderingContext2DAPITest, SetShadowColor_Clamping) {}

String TrySettingStrokeStyle(CanvasRenderingContext2DAPITest* test,
                             const String& value) {}

String TrySettingFillStyle(CanvasRenderingContext2DAPITest* test,
                           const String& value) {}

String TrySettingShadowColor(CanvasRenderingContext2D* ctx,
                             const String& value) {}

void TrySettingColor(CanvasRenderingContext2DAPITest* test,
                     const String& value,
                     const String& expected) {}

TEST_F(CanvasRenderingContext2DAPITest, ColorSerialization) {}

TEST_F(CanvasRenderingContext2DAPITest, DefaultAttributeValues) {}

TEST_F(CanvasRenderingContext2DAPITest, LineDashStateSave) {}

TEST_F(CanvasRenderingContext2DAPITest, CreateImageData) {}

TEST_F(CanvasRenderingContext2DAPITest, CreateImageDataTooBig) {}

TEST_F(CanvasRenderingContext2DAPITest, GetImageDataTooBig) {}

TEST_F(CanvasRenderingContext2DAPITest,
       GetImageDataIntegerOverflowNegativeParams) {}

// Checks `CreateImageBitmap` throws an exception if called inside a layer.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerCreateImageBitmap) {}

// Checks `createPattern` throws an exception the source has unclosed layers.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerCreatePattern) {}

// Checks `drawImage` throws an exception the source has unclosed layers.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerDrawImage) {}

// Checks `getImageData` throws an exception if called inside a layer.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerGetImageData) {}

// Checks `putImageData` throws an exception if called inside a layer.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerPutImageData) {}

// Checks `toBlob` throws an exception if called inside a layer.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerToBlob) {}

// Checks `toDataURL` throws an exception if called inside a layer.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerToDataUrl) {}

// Checks `drawMesh` throws an exception if called inside a layer.
TEST_F(CanvasRenderingContext2DAPITest, UnclosedLayerDrawMesh) {}

void ResetCanvasForAccessibilityRectTest(Document& document) {}

// A IdentifiabilityStudySettingsProvider implementation that opts-into study
// participation.
class ActiveSettingsProvider : public IdentifiabilityStudySettingsProvider {};

// An RAII class that opts into study participation using
// ActiveSettingsProvider.
class StudyParticipationRaii {};

TEST_F(CanvasRenderingContext2DAPITest, IdentifiabilityStudyMaxOperations) {}

// TODO(crbug.com/1239374): Fix test on Android L and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_Font
#else
#define MAYBE_IdentifiabilityStudyDigest_Font
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest, MAYBE_IdentifiabilityStudyDigest_Font) {}

TEST_F(CanvasRenderingContext2DAPITest, IdentifiabilityStudyDisabled) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_StrokeText
#else
#define MAYBE_IdentifiabilityStudyDigest_StrokeText
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_StrokeText) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_FillText
#else
#define MAYBE_IdentifiabilityStudyDigest_FillText
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_FillText) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_TextAlign
#else
#define MAYBE_IdentifiabilityStudyDigest_TextAlign
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_TextAlign) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_TextBaseline
#else
#define MAYBE_IdentifiabilityStudyDigest_TextBaseline
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_TextBaseline) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_StrokeStyle
#else
#define MAYBE_IdentifiabilityStudyDigest_StrokeStyle
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_StrokeStyle) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_FillStyle
#else
#define MAYBE_IdentifiabilityStudyDigest_FillStyle
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_FillStyle) {}

// TODO(crbug.com/1239374): Fix test on Android and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_Combo
#else
#define MAYBE_IdentifiabilityStudyDigest_Combo
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_Combo) {}

// TODO(crbug.com/1239374): Fix test on Android L and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_putImageData
#else
#define MAYBE_IdentifiabilityStudyDigest_putImageData
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_putImageData) {}

// TODO(crbug.com/1239374): Fix test on Android L and re-enable.
// TODO(crbug.com/1258605): Fix test on Windows and re-enable.
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN)
#define MAYBE_IdentifiabilityStudyDigest_drawImage
#else
#define MAYBE_IdentifiabilityStudyDigest_drawImage
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(CanvasRenderingContext2DAPITest,
       MAYBE_IdentifiabilityStudyDigest_drawImage) {}

ElementsAre;
IsNull;
Pointee;

MATCHER_P(Mesh2dBufferIs, matcher, "") {}

NotShared<DOMFloat32Array> CreateFloat32Array(std::vector<float> array) {}

NotShared<DOMUint16Array> CreateUint16Array(std::vector<uint16_t> array) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DVertexBuffer0Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DVertexBuffer1Float) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DVertexBuffer2Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DVertexBuffer3Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DVertexBuffer4Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer0Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer1Float) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer2Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer3Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer4Floats) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DIndexBuffer0Uints) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DIndexBuffer1Uint) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DIndexBuffer2Uints) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer3Uints) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DIndexBuffer4Uints) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DIndexBuffer5Uints) {}

TEST_F(CanvasRenderingContext2DAPITest, Mesh2DUVBuffer6Uints) {}

TEST_F(CanvasRenderingContext2DAPITest, DrawMesh) {}

}  // namespace blink