servo/tests/wpt/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-drawImage.html

49 lines
1.8 KiB
HTML

<!DOCTYPE html>
<html>
<title>createImageBitmap + drawImage test</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/canvas-tests.js"></script>
<script src="/common/media.js"></script>
<script src="common.js"></script>
<link rel="stylesheet" href="/common/canvas-tests.css">
<body>
<script>
function testCanvasDisplayingPattern(canvas)
{
var tolerance = 5; // for creating ImageBitmap from a video, the tolerance needs to be high
_assertPixelApprox(canvas, 5,5, 255,0,0,255, "5,5", "255,0,0,255", tolerance);
_assertPixelApprox(canvas, 15,5, 0,255,0,255, "15,5", "0,255,0,255", tolerance);
_assertPixelApprox(canvas, 5,15, 0,0,255,255, "5,15", "0,0,255,255", tolerance);
_assertPixelApprox(canvas, 15,15, 0,0,0,255, "15,15", "0,0,0,255", tolerance);
}
function testDrawImageBitmap(source, args = [])
{
var canvas = document.createElement("canvas");
canvas.width = 20;
canvas.height = 20;
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
return createImageBitmap(source, ...args).then(imageBitmap => {
ctx.drawImage(imageBitmap, 0, 0);
testCanvasDisplayingPattern(canvas);
});
}
for (let { name, factory } of imageSourceTypes) {
promise_test(function() {
return factory().then(function(img) {
return testDrawImageBitmap(img);
});
}, `createImageBitmap from ${name}, and drawImage on the created ImageBitmap`);
promise_test(function() {
return factory().then(function(img) {
return testDrawImageBitmap(img, [20, 20, -20, -20]);
});
}, `createImageBitmap from ${name} with negative sw/sh, and drawImage on the created ImageBitmap`);
}
</script>
</body>
</html>