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

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
function createCanvas(width, height) {
    var canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;
    return canvas;
}

test(function() {
    var width = 50;
    var height = 50;
    var canvas1 = createCanvas(width, height);
    var offscreenCanvas1;
    try {
        offscreenCanvas1 = canvas1.transferControlToOffscreen();
        assert_equals(offscreenCanvas1.width, width);
        assert_equals(offscreenCanvas1.height, height);
    } catch (ex) {
        assert_false(ex.message);
    }
}, "Tests whether transferControlToOffscreen can be run correctly.");

test(function() {
    var canvas2a = createCanvas(50, 50);
    var offscreenCanvas2a;
    var ctx = canvas2a.getContext("2d");
    assert_throws_dom("InvalidStateError", function() {
        offscreenCanvas2a = canvas2a.transferControlToOffscreen();
        assert_false("transferControlToOffscreen from a canvas with context didn't throw an exception.");
    }, "transferControlToOffscreen from a canvas with context throws an exception");

    var canvas2b = createCanvas(10, 10);
    var offscreenCanvas2b = canvas2b.transferControlToOffscreen();
    assert_throws_dom("InvalidStateError", function() {
        var anotherOffscreenCanvas = canvas2b.transferControlToOffscreen();
    }, "canvas.transferControlToOffscreen() is not allowed to called more than once for the same canvas.");
}, "Tests whether transferControlToOffscreen throws exception correctly."); 

test(function() {
    var canvas4 = createCanvas(10, 10);
    var offscreenCanvas4 = canvas4.transferControlToOffscreen();
    assert_throws_dom("InvalidStateError", function() {
        canvas4.getContext("2d");
    }, "canvas.getContext() is not allowed after transferring control to offscreen.");
}, "Test that getContext throw an exception if called after transferControlToOffscreen.");

</script>
</body>
</html>