Bug 664884: Test mozCurrentTransform/mozCurrentTransformInverse. r=joe,roc
authorChris Jones <jones.chris.g@gmail.com>
Wed, 29 Jun 2011 14:34:58 -0700
changeset 72006 5166d82391eef3b501d1e0a32fdfaad5b0cfe676
parent 72005 0949d3090bba60344eb90f5b6f507b75e0dd0dba
child 72007 7a0d3239bf2b531d2c5090d31e4fbc28b2ef6013
push id317
push usercjones@mozilla.com
push dateWed, 29 Jun 2011 21:35:14 +0000
treeherdermozilla-inbound@1382428eb6ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe, roc
bugs664884
milestone7.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 664884: Test mozCurrentTransform/mozCurrentTransformInverse. r=joe,roc
layout/reftests/canvas/ctm-1-ref.html
layout/reftests/canvas/ctm-1.html
layout/reftests/canvas/ctm-sanity.html
layout/reftests/canvas/ctm-singular-sanity.html
layout/reftests/canvas/reftest.list
new file mode 100644
--- /dev/null
+++ b/layout/reftests/canvas/ctm-1-ref.html
@@ -0,0 +1,18 @@
+<html>
+<head>
+  <script type="text/javascript">
+window.onload = function() {
+    var ctx = document.getElementById("c1").getContext("2d");
+    
+    ctx.setTransform(10, 0, 0, 1, 0, 0);
+    ctx.fillRect(1, 1, 10, 10);
+
+    ctx.setTransform(1, 0, 0, 10, 0, 0);
+    ctx.fillRect(150, 1, 10, 10);
+}
+  </script>
+</head>
+<body style="padding: 0px; margin: 0px;">
+  <div><canvas id="c1" width="300" height="300"></canvas></div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/canvas/ctm-1.html
@@ -0,0 +1,18 @@
+<html>
+<head>
+  <script type="text/javascript">
+window.onload = function() {
+    var ctx = document.getElementById("c1").getContext("2d");
+    
+    ctx.mozCurrentTransform = [ 10, 0, 0, 1, 0, 0 ];
+    ctx.fillRect(1, 1, 10, 10);
+
+    ctx.mozCurrentTransformInverse = [ 1, 0, 0, .1, 0, 0 ];
+    ctx.fillRect(150, 1, 10, 10);
+}
+  </script>
+</head>
+<body style="padding: 0px; margin: 0px;">
+  <div><canvas id="c1" width="300" height="300"></canvas></div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/canvas/ctm-sanity.html
@@ -0,0 +1,83 @@
+<html>
+<head>
+  <script type="text/javascript">
+
+function assert(cond, msg) { if (!cond) { throw msg; } }
+
+function isSameTM(m1, m2) {
+    // XXX this is probably the ugliest possible way to write this function,
+    // but it's intended to be lowest-common-denominator
+    if (!(m1.length === 6 && m1.length === m2.length)) {
+        return false;
+    }
+    for (var i = 0; i < m1.length; ++i) {
+        if (m1[i] !== m2[i]) {
+            return false;
+        }
+    }
+    return true;
+}
+
+window.onload = function() {
+    var IM = [ 1, 0, 0, 1, 0, 0 ];
+
+    try {
+        var ctx = document.getElementById("c1").getContext("2d");
+
+        assert(isSameTM(IM, ctx.mozCurrentTransform),
+               "currentTransform is identity by default");
+        assert(isSameTM(IM, ctx.mozCurrentTransformInverse),
+               "currentTransformInverse is identity by default");
+
+        var m = [ 1, 2, 3, 4, 5, 6 ];
+        ctx.mozCurrentTransform = m;
+        assert(isSameTM(m, ctx.mozCurrentTransform),
+               "currentTransform sucessfully set");
+        var badVals = [ -1,
+                        "string",
+                        { obj: true },
+                        [ "array of string" ],
+                        [ -1 ],
+                        [ "string", 1, 2, 3, 4, 5 ],
+                        [ { obj: true }, 1, 2, 3, 4, 5 ],
+        ];
+        for (var i = 0; i < badVals.length; ++i) {
+            var error = false;
+            try { ctx.mozCurrentTransform = badVals[i]; }
+            catch(e) { error = true; }
+            assert(error && isSameTM(m, ctx.mozCurrentTransform),
+                   "Expected |currentTransform = "+ badVals[i] +"| to throw exception and not change .currentTransform");
+
+            error = false;
+            try { ctx.mozCurrentTransformInverse = badVals[i]; }
+            catch(e) { error = true; }
+            assert(error && isSameTM(m, ctx.mozCurrentTransform),
+                   "Expected |currentTransformInverse = "+ badVals[i] +"| to throw exception and not change .currentTransform");
+        }
+        ctx.mozCurrentTransform = 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.mozCurrentTransform = noopVals[i];
+            assert(isSameTM(ctx.mozCurrentTransform, IM),
+                   "Illegal float values result in no-ops (sigh)");
+        }
+        ctx.mozCurrentTransform = IM;
+
+        ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
+        assert(isSameTM(ctx.mozCurrentTransform, m),
+               "setTransform() updates currentTransform");
+     } 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>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/canvas/ctm-singular-sanity.html
@@ -0,0 +1,53 @@
+<html>
+<head>
+  <script type="text/javascript">
+
+function assert(cond, msg) { if (!cond) { throw msg; } }
+
+function isSameTM(m1, m2) {
+    // XXX this is probably the ugliest possible way to write this function,
+    // but it's intended to be lowest-common-denominator
+    if (!(m1.length === 6 && m1.length === m2.length)) {
+        return false;
+    }
+    for (var i = 0; i < m1.length; ++i) {
+        if (m1[i] !== m2[i]) {
+            return false;
+        }
+    }
+    return true;
+}
+
+window.onload = function() {
+    var IM = [ 1, 0, 0, 1, 0, 0 ];
+
+    try {
+        var ctx = document.getElementById("c1").getContext("2d");
+
+        var singular = [ 0, 0, 0, 0, 0, 0 ];
+        ctx.mozCurrentTransform = singular;
+        assert(isSameTM(singular, ctx.mozCurrentTransform),
+               "Expected setting CTM to a singular matrix to work");
+        var inv = ctx.mozCurrentTransformInverse;
+        assert(!isSameTM(inv, inv),
+               "Expected to get back matrix of NaN's from currentTransformInverse");
+        ctx.mozCurrentTransform = IM;
+
+        var m = [ 1, 2, 3, 4, 5, 6 ];
+        ctx.mozCurrentTransform = m;
+        ctx.mozCurrentTransformInverse = singular;
+        assert(isSameTM(m, ctx.mozCurrentTransform,
+                        "Setting currentTransformInverse to a singular matrix is a no-op");
+        ctx.mozCurrentTransform = IM;
+    } 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>
--- a/layout/reftests/canvas/reftest.list
+++ b/layout/reftests/canvas/reftest.list
@@ -51,8 +51,12 @@ fails-if(cocoaWidget) == linear-gradient
 
 == zero-dimensions.html zero-dimensions-ref.html
 
 == evenodd-fill-sanity.html data:text/html,<body>Pass
 != evenodd-fill-1.html nonzero-fill-1.html
 == evenodd-fill-1.html evenodd-fill-ref.html
 == evenodd-fill-2.html evenodd-fill-ref.html
 == evenodd-fill-3.html nonzero-fill-2.html
+
+== ctm-sanity.html data:text/html,<body>Pass
+fails == ctm-singular-sanity.html data:text/html,<body>Pass  # Bug 612033
+== ctm-1.html ctm-1-ref.html