diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/svg/test/test_transformParsing.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/svg/test/test_transformParsing.html')
-rw-r--r-- | dom/svg/test/test_transformParsing.html | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/dom/svg/test/test_transformParsing.html b/dom/svg/test/test_transformParsing.html new file mode 100644 index 0000000000..bd6bb61f42 --- /dev/null +++ b/dom/svg/test/test_transformParsing.html @@ -0,0 +1,103 @@ +<!doctype html> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=946529 +--> +<head> + <meta charset="utf-8"> + <title>Test transform parsing</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=946529">Mozilla Bug 946529</a> +<p id="display"></p> +<div id="content" style="display: none"> + <svg width="100%" height="1" id="svg"> + <g id="g"/> + </svg> +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +// Test cases +checkParseOk("", [ ]); +checkParseOk("matrix(-.7235 .6903 .6903 .7235 -2050 1.14e4)", + [ { type: "matrix", a: -0.7235, b: 0.6903, c: 0.6903, + d: 0.7235, e: -2050, f: 11400 } ]); +checkParseOk("matrix(0e0 1e0 1e1 1e-1 1E+2 -.1e1)", + [ { type: "matrix", a: 0, b: 1, c: 10, + d: 0.1, e: 100, f: -1 } ]); +checkParseOk("matrix(-0e-0 1e+0 0e-5 1e-10 12.3e+4 .12e2)", + [ { type: "matrix", a: 0, b: 1, c: 0, + d: 0.0000000001, e: 123000, f: 12 } ]); + +// Fail cases +checkParseFail("matrix(1e+ 0 0 0 0 0)"); +checkParseFail("matrix(e2 0 0 0 0 0)"); +checkParseFail("matrix(1 e2 0 0 0 0 0)"); +checkParseFail("matrix(1e 2 0 0 0 0 0)"); +checkParseFail("matrix(1e+-2 0 0 0 0 0)"); +checkParseFail("matrix(1e 0 0 0 0 0)"); +checkParseFail("matrix(1e1.1 0 0 0 0 0)"); +checkParseFail("scale(2) matrix(1e1.1 0 0 0 0 0)"); + +function checkParseOk(spec, expected) { + var g = document.getElementById("g"); + + // Clear previous value + g.removeAttribute("transform"); + + g.setAttribute("transform", spec); + + // Check length + var transformList = g.transform.baseVal; + is(transformList.numberOfItems, expected.length, spec + " - length"); + if (transformList.numberOfItems != expected.length) + return; + + // Check each item + for (var i = 0; i < transformList.numberOfItems; i++) { + checkTransform(transformList.getItem(i), expected[i], spec, i); + } +} + +function checkTransform(transform, expected, spec, index) { + var typeMapping = { + "unknown": SVGTransform.SVG_TRANSFORM_UNKNOWN, + "matrix": SVGTransform.SVG_TRANSFORM_MATRIX, + "translate": SVGTransform.SVG_TRANSFORM_TRANSLATE, + "scale": SVGTransform.SVG_TRANSFORM_SCALE, + "rotate": SVGTransform.SVG_TRANSFORM_ROTATE, + "skewx": SVGTransform.SVG_TRANSFORM_SKEWX, + "skewy": SVGTransform.SVG_TRANSFORM_SKEWY, + }; + var name = "Item " + index + " of '" + spec + "'"; + + // Compare type + if (typeof expected.type != "undefined") { + is(transform.type, typeMapping[expected.type], name + " - transform type"); + } + + // Compare angle + if (typeof expected.angle != "undefined") { + is(transform.angle, expected.angle, name + " - angle"); + } + + // Compare matrix values (roughly) + ["a", "b", "c", "d", "e", "f"].forEach(function(item) { + var actual = transform.matrix[item]; + var msg = name + " - matrix:" + item; + const tolerance = 1 / 65535; + ok(Math.abs(actual - expected[item]) < tolerance, + msg + " - got " + actual + ", expected " + expected[item]); + }); +} + +function checkParseFail(spec) { + checkParseOk(spec, []); +} +</script> +</pre> +</body> +</html> |