chromium/third_party/blink/web_tests/fast/canvas-api/OffscreenCanvas-getContext.html

<!DOCTYPE html>
<title>Tests basic functionalities of OffscreenCanvas.getContext on the main thread.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
    // Tests constructor of OffscreenCanvas and height/width change.
    var aCanvas = new OffscreenCanvas(40, 60);
    assert_equals(aCanvas.width, 40);
    assert_equals(aCanvas.height, 60);

    aCanvas.width = 110;
    aCanvas.height = 90;
    assert_equals(aCanvas.width, 110);
    assert_equals(aCanvas.height, 90);

    aCanvas.width = 0; // Zero dimension is allowed.
    assert_equals(aCanvas.width, 0);

    assert_throws_js(TypeError, function() { aCanvas.getContext('bogus'); }); 

    // Tests object type of getContext('2d').
    var ctx = aCanvas.getContext('2d');
    assert_true(ctx instanceof OffscreenCanvasRenderingContext2D);
    // Calling getContext on a different context type will return null.
    var ctx2 = aCanvas.getContext("webgl");
    assert_equals(ctx2, null);

    // Calling getContext on the same context type will return the original context type.
    var ctx3 = aCanvas.getContext("2d");
    assert_not_equals(ctx3, null);
    assert_equals(ctx3, ctx);

    var bCanvas = new OffscreenCanvas(20, 20);
    var ctx4 = bCanvas.getContext("webgl");
    assert_true(ctx4 instanceof WebGLRenderingContext);

    var cCanvas = new OffscreenCanvas(20,20);
    var ctx5 = cCanvas.getContext("bitmaprenderer");
    assert_true(ctx5 instanceof ImageBitmapRenderingContext);
});
</script>