diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/canvas/test/test_invalid_mime_type_blob.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/test/test_invalid_mime_type_blob.html')
-rw-r--r-- | dom/canvas/test/test_invalid_mime_type_blob.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/dom/canvas/test/test_invalid_mime_type_blob.html b/dom/canvas/test/test_invalid_mime_type_blob.html new file mode 100644 index 0000000000..45d3606347 --- /dev/null +++ b/dom/canvas/test/test_invalid_mime_type_blob.html @@ -0,0 +1,85 @@ +<!DOCTYPE HTML> +<title>createImageBitmap from Blob with invalid type</title> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> +<body> +<script> + +function syncBlob() { + info("Let's create a small memory blob..."); + + // A 1x1 PNG image. + // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain) + const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" + + "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="); + + let bytes = new Array(IMAGE.length); + for (let i = 0; i < IMAGE.length; i++) { + bytes[i] = IMAGE.charCodeAt(i); + } + + let blob = new Blob([new Uint8Array(bytes)], { type: "text/html"}); + window.createImageBitmap(blob) + .then(imageBitmap => { + ok(true, "Image created!"); + is(imageBitmap.width, 1, "Image is 1x1"); + is(imageBitmap.height, 1, "Image is 1x1"); + }) + .then(next); +} + +function asyncBlob() { + info("Let's create a big memory blob..."); + + // A 1x1 PNG image. + // Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain) + const IMAGE = atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" + + "ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="); + + let bytes = new Array(IMAGE.length); + for (let i = 0; i < IMAGE.length; i++) { + bytes[i] = IMAGE.charCodeAt(i); + } + + let blob = new Blob([new Uint8Array(bytes)], { type: "text/html"}); + while (blob.size <= 1024*1024) { + blob = new Blob([blob, blob], { type: "text/html"}); + } + + ok(blob.size > 1024 * 1024, "More than 1mb"); + + let bc = new BroadcastChannel('a'); + bc.onmessage = e => { + window.createImageBitmap(e.data) + .then(imageBitmap => { + ok(true, "Image created!"); + is(imageBitmap.width, 1, "Image is 1x1"); + is(imageBitmap.height, 1, "Image is 1x1"); + }) + .then(next); + } + + new BroadcastChannel('a').postMessage(blob); +} + +let tests = [ + syncBlob, + asyncBlob, +]; + +function next() { + if (!tests.length) { + SimpleTest.finish(); + return; + } + + let test = tests.shift(); + test(); +} + +SimpleTest.requestLongerTimeout(3); // slow on Android +SimpleTest.waitForExplicitFinish(); +next(); +</script> +</body> +</html> |