LibWeb: Add a test for WindowOrWorkerGlobalScope.createImageBitmap

This commit is contained in:
Lucas CHOLLET 2024-04-06 15:06:10 -04:00 committed by Andreas Kling
parent 94128fe027
commit 7f7119c78d
Notes: sideshowbarker 2024-07-17 05:01:20 +09:00
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,2 @@
RangeError: 0 is an invalid value for sw
Bitmap is correctly loaded

View file

@ -0,0 +1,45 @@
<script src="include.js"></script>
<canvas id="test" width="2" height="2" hidden="hidden"></canvas>
<script>
test(() => {
// The blob is a JXL image for a 2x2 checkerboard
// Made with the following tree on https://jxl-art.lucaversari.it/:
// Width 2
// Height 2
// Bitdepth 8
// if N > 0
// - Set 0
// - Set 255
let file = new Blob([new Uint8Array([255, 10, 8, 16, 0, 9, 8, 6, 1, 0, 40, 0, 75, 56, 73, 152, 108, 128, 253, 145, 96, 0])]);
createImageBitmap(file, 0, 0, 0, 0).catch((err) => println(err));
createImageBitmap(file).then((bitmap) => {
if (bitmap.width !== 2 || bitmap.height !== 2)
println(`Unexpected size for image bitmap: '${bitmap.width}'x'${bitmap.height}'`);
const canvas = document.getElementById("test");
const ctx = canvas.getContext("2d");
ctx.drawImage(bitmap, 0, 0)
function is_pixel_wrong(coord, color) {
let pixel = ctx.getImageData(coord[0], coord[1], 1, 1).data;
if (pixel[3] !== 255)
return true;
if (color === 'white')
return pixel[0] !== 255 || pixel[1] !== 255 || pixel[2] !== 255;
return pixel[0] !== 0 || pixel[1] !== 0 || pixel[2] !== 0;
}
if (is_pixel_wrong([0, 0], 'white') || is_pixel_wrong([0, 1], 'black') ||
is_pixel_wrong([1, 0], 'black') || is_pixel_wrong([1, 1], 'white'))
println(`Invalid value in the bitmap`);
else
println(`Bitmap is correctly loaded`);
})
});
</script>