chromium/third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d_test.cc

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

#include "third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.h"

#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_bitmap_options.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_image_encode_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_begin_layer_options.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/html/canvas/image_data.h"
#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
#include "third_party/blink/renderer/modules/canvas/imagebitmap/image_bitmap_factories.h"
#include "third_party/blink/renderer/platform/testing/runtime_enabled_features_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"

namespace blink {
namespace {

OffscreenCanvasRenderingContext2D* GetContext(V8TestingScope& scope,
                                              OffscreenCanvas* host) {}

TEST(OffscreenCanvasHostTest,
     TransferToOffscreenThrowsErrorsProducedByContext) {}

TEST(OffscreenCanvasHostTest, TransferToOffscreenThrowsUnknownErrorAsFallback) {}

TEST(OffscreenCanvasRenderingContext2DTest, TransferToOffscreenThrowsInLayers) {}

// Checks `convertToBlob` throws an exception if called inside a layer.
TEST(OffscreenCanvasRenderingContext2DTest, UnclosedLayerConvertToBlob) {}

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

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

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

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

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

// Checks `transferToImageBitmap` throws an exception if called inside a layer.
TEST(OffscreenCanvasRenderingContext2DTest,
     UnclosedLayerTransferToImageBitmap) {}

// Regression test for https://crbug.com/1509382.
TEST(OffscreenCanvasRenderingContext2DTest, NoCrashOnDocumentShutdown) {}

}  // namespace
}  // namespace blink