mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-30 09:08:55 +00:00
88 lines
2.6 KiB
HTML
88 lines
2.6 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../testing.js"></script>
|
|
|
|
<script id=OffscreenCanvas>
|
|
{
|
|
const canvas = new OffscreenCanvas(256, 256);
|
|
testing.expectEqual(true, canvas instanceof OffscreenCanvas);
|
|
testing.expectEqual(canvas.width, 256);
|
|
testing.expectEqual(canvas.height, 256);
|
|
}
|
|
</script>
|
|
|
|
<script id=OffscreenCanvas#width>
|
|
{
|
|
const canvas = new OffscreenCanvas(100, 200);
|
|
testing.expectEqual(canvas.width, 100);
|
|
canvas.width = 300;
|
|
testing.expectEqual(canvas.width, 300);
|
|
}
|
|
</script>
|
|
|
|
<script id=OffscreenCanvas#height>
|
|
{
|
|
const canvas = new OffscreenCanvas(100, 200);
|
|
testing.expectEqual(canvas.height, 200);
|
|
canvas.height = 400;
|
|
testing.expectEqual(canvas.height, 400);
|
|
}
|
|
</script>
|
|
|
|
<script id=OffscreenCanvas#getContext>
|
|
{
|
|
const canvas = new OffscreenCanvas(64, 64);
|
|
const ctx = canvas.getContext("2d");
|
|
testing.expectEqual(true, ctx instanceof OffscreenCanvasRenderingContext2D);
|
|
// We can't really test rendering but let's try to call it at least.
|
|
ctx.fillRect(0, 0, 10, 10);
|
|
}
|
|
</script>
|
|
|
|
<script id=OffscreenCanvas#convertToBlob>
|
|
{
|
|
const canvas = new OffscreenCanvas(64, 64);
|
|
const promise = canvas.convertToBlob();
|
|
testing.expectEqual(true, promise instanceof Promise);
|
|
// The promise should resolve to a Blob (even if empty)
|
|
promise.then(blob => {
|
|
testing.expectEqual(true, blob instanceof Blob);
|
|
testing.expectEqual(blob.size, 0); // Empty since no rendering
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<script id=HTMLCanvasElement#transferControlToOffscreen>
|
|
{
|
|
const htmlCanvas = document.createElement("canvas");
|
|
htmlCanvas.width = 128;
|
|
htmlCanvas.height = 96;
|
|
const offscreen = htmlCanvas.transferControlToOffscreen();
|
|
testing.expectEqual(true, offscreen instanceof OffscreenCanvas);
|
|
testing.expectEqual(offscreen.width, 128);
|
|
testing.expectEqual(offscreen.height, 96);
|
|
}
|
|
</script>
|
|
|
|
<script id=OffscreenCanvasRenderingContext2D#getImageData>
|
|
{
|
|
const canvas = new OffscreenCanvas(100, 50);
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
const imageData = ctx.getImageData(0, 0, 10, 20);
|
|
testing.expectEqual(true, imageData instanceof ImageData);
|
|
testing.expectEqual(imageData.width, 10);
|
|
testing.expectEqual(imageData.height, 20);
|
|
testing.expectEqual(imageData.data.length, 10 * 20 * 4);
|
|
|
|
// Undrawn canvas should return transparent black pixels.
|
|
testing.expectEqual(imageData.data[0], 0);
|
|
testing.expectEqual(imageData.data[1], 0);
|
|
testing.expectEqual(imageData.data[2], 0);
|
|
testing.expectEqual(imageData.data[3], 0);
|
|
|
|
// Zero or negative dimensions should throw.
|
|
testing.expectError('Index or size', () => ctx.getImageData(0, 0, 0, 10));
|
|
testing.expectError('Index or size', () => ctx.getImageData(0, 0, 10, -5));
|
|
}
|
|
</script>
|