diff options
author | Moonchild <moonchild@palemoon.org> | 2023-09-26 15:15:45 +0200 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-09-26 15:15:45 +0200 |
commit | bfda40bce9d8aeed5bea22ceb4d9ddae3a51a57c (patch) | |
tree | c50dc42e698be69c7f009d598bff4e0158b3178a /layout | |
parent | 8b4aae99b42f6258e1c05a235981522a484532d4 (diff) | |
download | uxp-bfda40bce9d8aeed5bea22ceb4d9ddae3a51a57c.tar.gz |
Issue #2316 - Part 2: Add reftests
Diffstat (limited to 'layout')
8 files changed, 209 insertions, 0 deletions
diff --git a/layout/reftests/svg/sizing/canvas-drawImage-height-with-no-width-ref.html b/layout/reftests/svg/sizing/canvas-drawImage-height-with-no-width-ref.html new file mode 100644 index 0000000000..f68abfeecf --- /dev/null +++ b/layout/reftests/svg/sizing/canvas-drawImage-height-with-no-width-ref.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML> +<html class="reftest-wait"> +<script src="svg-image-util.js"></script> +<style> + canvas { + background: blue; + } +</style> +<body> + <script> + let viewBoxes = [null, "0 0 50 50", "0 0 50 20"]; + let promises = []; + for (viewBox of viewBoxes) { + // Without a given width or height the svg should be sized as if a width + // of 300px and height of 150px were given. + promises.push(generateCanvasDrawImageSVG("350", "200", "300px", "200px", viewBox)); + } + Promise.all(promises).then(() => { document.documentElement.className = "" }); + </script> + <!-- Body gets populated by script --> +</body> +</html> diff --git a/layout/reftests/svg/sizing/canvas-drawImage-height-with-no-width.html b/layout/reftests/svg/sizing/canvas-drawImage-height-with-no-width.html new file mode 100644 index 0000000000..da4f20a2f9 --- /dev/null +++ b/layout/reftests/svg/sizing/canvas-drawImage-height-with-no-width.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML> +<html class="reftest-wait"> +<script src="svg-image-util.js"></script> +<style> + canvas { + background: blue; + } +</style> +<body> + <script> + let viewBoxes = [null, "0 0 50 50", "0 0 50 20"]; + let promises = []; + for (viewBox of viewBoxes) { + // Without a given width or height the svg should be sized as if a width + // of 300px and height of 150px were given. + promises.push(generateCanvasDrawImageSVG("350", "200", null, "200px", viewBox)); + } + Promise.all(promises).then(() => { document.documentElement.className = "" }); + </script> + <!-- Body gets populated by script --> +</body> +</html> diff --git a/layout/reftests/svg/sizing/canvas-drawImage-no-width-or-height-ref.html b/layout/reftests/svg/sizing/canvas-drawImage-no-width-or-height-ref.html new file mode 100644 index 0000000000..045d626743 --- /dev/null +++ b/layout/reftests/svg/sizing/canvas-drawImage-no-width-or-height-ref.html @@ -0,0 +1,20 @@ +<!DOCTYPE HTML> +<html class="reftest-wait"> +<script src="svg-image-util.js"></script> +<style> + canvas { + background: blue; + } +</style> +<body> + <script> + let viewBoxes = [null, "0 0 50 50", "0 0 50 20"]; + let promises = []; + for (viewBox of viewBoxes) { + promises.push(generateCanvasDrawImageSVG("350", "200", "300px", "150px", viewBox)); + } + Promise.all(promises).then(() => { document.documentElement.className = "" }); + </script> + <!-- Body gets populated by script --> +</body> +</html> diff --git a/layout/reftests/svg/sizing/canvas-drawImage-no-width-or-height.html b/layout/reftests/svg/sizing/canvas-drawImage-no-width-or-height.html new file mode 100644 index 0000000000..e5bc8c16ca --- /dev/null +++ b/layout/reftests/svg/sizing/canvas-drawImage-no-width-or-height.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML> +<html class="reftest-wait"> +<script src="svg-image-util.js"></script> +<style> + canvas { + background: blue; + } +</style> +<body> + <script> + let viewBoxes = [null, "0 0 50 50", "0 0 50 20"]; + let promises = []; + for (viewBox of viewBoxes) { + // Without a given width or height the svg should be sized as if a width + // of 300px and height of 150px were given. + promises.push(generateCanvasDrawImageSVG("350", "200", null, null, viewBox)); + } + Promise.all(promises).then(() => { document.documentElement.className = "" }); + </script> + <!-- Body gets populated by script --> +</body> +</html> diff --git a/layout/reftests/svg/sizing/canvas-drawImage-width-with-no-height-ref.html b/layout/reftests/svg/sizing/canvas-drawImage-width-with-no-height-ref.html new file mode 100644 index 0000000000..24d91d32c4 --- /dev/null +++ b/layout/reftests/svg/sizing/canvas-drawImage-width-with-no-height-ref.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML> +<html class="reftest-wait"> +<script src="svg-image-util.js"></script> +<style> + canvas { + background: blue; + } +</style> +<body> + <script> + let viewBoxes = [null, "0 0 50 50", "0 0 50 20"]; + let promises = []; + for (viewBox of viewBoxes) { + // Without a given width or height the svg should be sized as if a width + // of 300px and height of 150px were given. + promises.push(generateCanvasDrawImageSVG("350", "200", "200px", "150px", viewBox)); + } + Promise.all(promises).then(() => { document.documentElement.className = "" }); + </script> + <!-- Body gets populated by script --> +</body> +</html> diff --git a/layout/reftests/svg/sizing/canvas-drawImage-width-with-no-height.html b/layout/reftests/svg/sizing/canvas-drawImage-width-with-no-height.html new file mode 100644 index 0000000000..7a4452face --- /dev/null +++ b/layout/reftests/svg/sizing/canvas-drawImage-width-with-no-height.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML> +<html class="reftest-wait"> +<script src="svg-image-util.js"></script> +<style> + canvas { + background: blue; + } +</style> +<body> + <script> + let viewBoxes = [null, "0 0 50 50", "0 0 50 20"]; + let promises = []; + for (viewBox of viewBoxes) { + // Without a given width or height the svg should be sized as if a width + // of 300px and height of 150px were given. + promises.push(generateCanvasDrawImageSVG("350", "200", "200px", null, viewBox)); + } + Promise.all(promises).then(() => { document.documentElement.className = "" }); + </script> + <!-- Body gets populated by script --> +</body> +</html> diff --git a/layout/reftests/svg/sizing/reftest.list b/layout/reftests/svg/sizing/reftest.list index 960b59d8d9..3e269c5a31 100644 --- a/layout/reftests/svg/sizing/reftest.list +++ b/layout/reftests/svg/sizing/reftest.list @@ -310,3 +310,8 @@ skip == dynamic--inline-resize-window-width.xhtml pass.svg # Fails way too mu fails random-if(Android) == dynamic--object-svg-unloaded.xhtml pass.svg # == dynamic--object--auto-auto--pct-px.html +# Note: Other web rendering engines do no not pass the following tests due +# due to differences in surface calculations. +== canvas-drawImage-no-width-or-height.html canvas-drawImage-no-width-or-height-ref.html +== canvas-drawImage-width-with-no-height.html canvas-drawImage-width-with-no-height-ref.html +== canvas-drawImage-height-with-no-width.html canvas-drawImage-height-with-no-width-ref.html diff --git a/layout/reftests/svg/sizing/svg-image-util.js b/layout/reftests/svg/sizing/svg-image-util.js new file mode 100644 index 0000000000..d58e622ec7 --- /dev/null +++ b/layout/reftests/svg/sizing/svg-image-util.js @@ -0,0 +1,74 @@ +/** + * Reusable SVG data uri prefix for generated SVGs. + */ +const SVG_DATA_URI_PREFIX = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"'; +/** + * Reusable SVG data uri suffix for generated SVGs. + */ +const SVG_DATA_URI_SUFFIX = '><rect fill="brown" x="-2000" y="-2000" width="4000" height="4000"></rect><rect fill="green" height="50" width="50"></rect><rect fill="yellow" x="10" y="10" height="30" width="30"></rect></svg>'; + +/** + * Generates full data URI for an SVG document, with the given parameters + * on the SVG element. + * + * @param aWidth The width attribute, or null for no width. + * @param aHeight The height attribute, or null for no height. + * @param aViewbox The viewBox attribute, or null for no viewBox. + */ +function generateSVGDataURI(aWidth, aHeight, aViewBox) { + let datauri = SVG_DATA_URI_PREFIX; + + if (aWidth) { + datauri += " width=\"" + aWidth + "\"" + } + + if (aHeight) { + datauri += " height=\"" + aHeight + "\""; + } + + if (aViewBox) { + datauri += " viewBox=\"" + aViewBox + "\""; + } + + datauri += SVG_DATA_URI_SUFFIX; + + return datauri; +} + +/** + * Generates a canvas, with the given width and height parameters, and uses + * CanvasRenderingContext2D.drawImage() to draw a SVG image with the given + * width and height attributes. + * + * @param aCanvasWidth The width attribute of the canvas. + * @param aCanvasHeight The height attribute of the canvas. + * @param aSVGWidth The width attribute of the svg, or null for no width. + * @param aSVGHeight The height attribute of the svg, or null for no height. + * @param aSVGViewBox The viewBox attribute sf the svg, or null for no viewBox. + * + * @returns A promise that resolves when the SVG image has been drawn to the + * created canvas + */ +async function generateCanvasDrawImageSVG(aCanvasWidth, aCanvasHeight, aSVGWidth, + aSVGHeight, aSVGViewBox) { + let canvas = document.createElement("canvas"); + let ctx = canvas.getContext("2d"); + document.body.appendChild(canvas); + + canvas.setAttribute("width", aCanvasWidth); + canvas.setAttribute("height", aCanvasHeight); + + let img = document.createElement("img"); + + let promise = new Promise(resolve => { + img.onload = () => { + ctx.drawImage(img, 0, 0); + resolve(); + }; + }); + + let uri = generateSVGDataURI(aSVGWidth, aSVGHeight, aSVGViewBox); + img.src = uri; + + return promise; +} |