blob: e541808549b9485387e0a383c4e305a6bc0debf4 [file] [log] [blame]
<!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 canvas2 = createCanvas(50, 50);
var offscreenCanvas2;
var ctx = canvas2.getContext("2d");
assert_throws("InvalidStateError", function() {
offscreenCanvas2 = canvas2.transferControlToOffscreen();
assert_false("transferControlToOffscreen from a canvas with context didn't throw an exception.");
}, "transferControlToOffscreen from a canvas with context throws an exception");
}, "Tests whether transferControlToOffscreen throws exception correctly.");
test(function() {
var canvas3 = createCanvas(10, 10);
var offscreenCanvas3 = canvas3.transferControlToOffscreen();
assert_equals(offscreenCanvas3.width, 10);
assert_equals(offscreenCanvas3.height, 10);
assert_throws("InvalidStateError", function() { offscreenCanvas3.width = 20; });
assert_throws("InvalidStateError", function() { offscreenCanvas3.height = 20; });
}, "Test if resizing on offscreencanvas transferred from html canvas has thrown exceptions.");
test(function() {
var canvas4 = createCanvas(10, 10);
var offscreenCanvas4 = canvas4.transferControlToOffscreen();
assert_throws("InvalidStateError", function() {
canvas4.getContext("2d");
}, "canvas.getContext() is not allowed after transferring control to offscreen.");
assert_throws("InvalidStateError", function() {
canvas4.height = 20;
}, "canvas resizing height is not allowed after transferring control to offscreen.");
assert_throws("InvalidStateError", function() {
canvas4.width = 20;
}, "canvas resizing width is not allowed after transferring control to offscreen.");
assert_throws("InvalidStateError", function() {
canvas4.toBlob(function() {});
}, "canvas.toBlob is not allowed after transferring control to offscreen.");
assert_throws("InvalidStateError", function() {
canvas4.toDataURL();
}, "canvas.toDataURL is not allowed after transferring control to offscreen.");
}, "Test if modifying canvas after it transfers controls to offscreen throw exceptions");
</script>
</body>
</html>