blob: 28fdcc96ef3eddd617257db686840bac15ea5364 [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 canvas2a = createCanvas(50, 50);
var offscreenCanvas2a;
var ctx = canvas2a.getContext("2d");
assert_throws("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("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("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.");
}, "Test if modifying canvas after it transfers controls to offscreen throw exceptions");
</script>
</body>
</html>