diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /layout/reftests/canvas/ctm-sanity.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/reftests/canvas/ctm-sanity.html')
-rw-r--r-- | layout/reftests/canvas/ctm-sanity.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/layout/reftests/canvas/ctm-sanity.html b/layout/reftests/canvas/ctm-sanity.html new file mode 100644 index 0000000000..c0ff466a33 --- /dev/null +++ b/layout/reftests/canvas/ctm-sanity.html @@ -0,0 +1,85 @@ +<html> +<head> + <script type="text/javascript"> +function assert(cond, msg) { + if (!cond) { + throw msg; + } +} + +assert.equal = function(m1, m2, msg) { + assert( + m1.is2D && + m2.is2D && + m1.a === m2.a && + m1.b === m2.b && + m1.c === m2.c && + m1.d === m2.d && + m1.e === m2.e && + m1.f === m2.f, + msg + ); +}; + +window.onload = function() { + var IM = new DOMMatrix([1, 0, 0, 1, 0, 0]); + + try { + var ctx = document.getElementById("c1").getContext("2d"); + + assert.equal(ctx.getTransform(), IM, "Transform is identity by default"); + assert.equal( + ctx.getTransform().invertSelf(), + IM, + "Inverse transform is identity by default" + ); + + var m = new DOMMatrix([1, 2, 3, 4, 5, 6]); + ctx.setTransform(m); + assert.equal(ctx.getTransform(), m, "Transform successfully set"); + + var badVals = [ + ["string"], + [-1], + ["string", 1, 2, 3, 4, 5], + [{ obj: true }, 1, 2, 3, 4, 5], + ]; + for (var i = 0; i < badVals.length; ++i) { + try { + ctx.setTransform(...badVals[i]); + } catch {} + assert.equal( + ctx.getTransform(), + m, + "Expected |setTransform(" + badVals[i] + ")| to not change transform" + ); + } + + ctx.setTransform(IM); + var noopVals = [ + [Number.NaN, 1, 2, 3, 4, 5], + [Infinity, 1, 2, 3, 4, 5], + ]; + for (var i = 0; i < noopVals.length; ++i) { + ctx.setTransform(...noopVals[i]); + assert.equal( + ctx.getTransform(), + IM, + "Illegal float values result in a no-op" + ); + } + + ctx.setTransform(m.a, m.b, m.c, m.d, m.e, m.f); + assert.equal(ctx.getTransform(), m, "setTransform() updates transform"); + } catch (e) { + document.body.innerHTML = "FAIL: " + e.toString(); + return; + } + document.body.innerHTML = "Pass"; +}; + </script> +</head> +<body> + <div><canvas id="c1" width="300" height="300"></canvas></div> +</body> +</html> |