blob: e495f04099b439c1a3a5f312608adafaf452f7b1 [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<title>Tests that the OffscreenCanvas can handle invalid arguments</title>
<script>
test(function() {
// Since blink uses signed int internally, this case tests how the constructor
// responds to the arguments that are larger than INT_MAX which would cause
// overflow. The current implementation is expected to clamp.
var setWidth = Math.pow(2, 31);
var setHeight = Math.pow(2, 31);
var obj = {Name: "John Doe", Age: 30};
var canvas1 = new OffscreenCanvas(setWidth, setHeight);
assert_equals(canvas1.width, setWidth-1);
assert_equals(canvas1.height, setHeight-1);
canvas1.width = null;
canvas1.height = null;
assert_equals(canvas1.width, 0);
assert_equals(canvas1.height, 0);
assert_throws_js(TypeError, function() { new OffscreenCanvas(-1, -1); });
var canvas2 = new OffscreenCanvas(null, null);
assert_equals(canvas2.width, 0);
assert_equals(canvas2.height, 0);
canvas2.width = setWidth;
canvas2.height = setHeight;
assert_equals(canvas2.width, setWidth-1);
assert_equals(canvas2.height, setHeight-1);
assert_throws_js(TypeError, function() { canvas2.width = -1; });
assert_throws_js(TypeError, function() { canvas2.height = -1; });
assert_throws_js(TypeError, function() { canvas2.width = obj; });
assert_throws_js(TypeError, function() { canvas2.height = obj; });
assert_throws_js(TypeError, function() { new OffscreenCanvas(obj, obj); });
});
</script>