| <!DOCTYPE html> |
| <title>createImageBitmap() rejects an SVG with no natural dimensions, whatever the element's box or width and height attributes</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <img id="hidden" style="display: none" |
| src='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 3"><rect width="100%" height="100%" fill="green"/></svg>'> |
| <script> |
| const ratioOnly = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 3"><rect width="100%" height="100%" fill="green"/></svg>'; |
| const sized = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="10"><rect width="100%" height="100%" fill="green"/></svg>'; |
| |
| function load(image, url) |
| { |
| return new Promise((resolve, reject) => { |
| image.onload = () => resolve(image); |
| image.onerror = () => reject(new Error("could not load " + url)); |
| image.src = url; |
| }); |
| } |
| |
| function loaded(image) |
| { |
| return image.complete ? Promise.resolve(image) : new Promise(resolve => image.onload = () => resolve(image)); |
| } |
| |
| promise_test(async () => { |
| const bitmap = await createImageBitmap(await load(new Image, sized)); |
| assert_equals(bitmap.width, 20); |
| assert_equals(bitmap.height, 10); |
| }, "Dimensions of its own need no box"); |
| |
| promise_test(async t => { |
| await promise_rejects_dom(t, "InvalidStateError", createImageBitmap(await load(new Image, ratioOnly))); |
| }, "A viewBox and nothing else, never inserted, is rejected"); |
| |
| promise_test(async t => { |
| await promise_rejects_dom(t, "InvalidStateError", createImageBitmap(await loaded(document.getElementById("hidden")))); |
| }, "The same in a 'display: none' element is rejected"); |
| |
| promise_test(async t => { |
| await promise_rejects_dom(t, "InvalidStateError", createImageBitmap(await load(new Image(200, 200), ratioOnly))); |
| }, "The same with width and height attributes is rejected"); |
| </script> |