layout/reftests/canvas/ctm-singular-sanity.html

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <script type="text/javascript">
michael@0 4
michael@0 5 function assert(cond, msg) { if (!cond) { throw msg; } }
michael@0 6
michael@0 7 function isSameTM(m1, m2) {
michael@0 8 // XXX this is probably the ugliest possible way to write this function,
michael@0 9 // but it's intended to be lowest-common-denominator
michael@0 10 if (!(m1.length === 6 && m1.length === m2.length)) {
michael@0 11 return false;
michael@0 12 }
michael@0 13 for (var i = 0; i < m1.length; ++i) {
michael@0 14 if (m1[i] !== m2[i]) {
michael@0 15 return false;
michael@0 16 }
michael@0 17 }
michael@0 18 return true;
michael@0 19 }
michael@0 20
michael@0 21 window.onload = function() {
michael@0 22 var IM = [ 1, 0, 0, 1, 0, 0 ];
michael@0 23
michael@0 24 try {
michael@0 25 var ctx = document.getElementById("c1").getContext("2d");
michael@0 26
michael@0 27 var singular = [ 0, 0, 0, 0, 0, 0 ];
michael@0 28 ctx.mozCurrentTransform = singular;
michael@0 29 assert(isSameTM(singular, ctx.mozCurrentTransform),
michael@0 30 "Expected setting CTM to a singular matrix to work");
michael@0 31 var inv = ctx.mozCurrentTransformInverse;
michael@0 32 assert(!isSameTM(inv, inv),
michael@0 33 "Expected to get back matrix of NaN's from currentTransformInverse");
michael@0 34 ctx.mozCurrentTransform = IM;
michael@0 35
michael@0 36 var m = [ 1, 2, 3, 4, 5, 6 ];
michael@0 37 ctx.mozCurrentTransform = m;
michael@0 38 ctx.mozCurrentTransformInverse = singular;
michael@0 39 assert(isSameTM(m, ctx.mozCurrentTransform),
michael@0 40 "Setting currentTransformInverse to a singular matrix is a no-op");
michael@0 41 ctx.mozCurrentTransform = IM;
michael@0 42 } catch (e) {
michael@0 43 document.body.innerHTML = "FAIL: "+ e.toString();
michael@0 44 return;
michael@0 45 }
michael@0 46 document.body.innerHTML = "Pass";
michael@0 47 }
michael@0 48 </script>
michael@0 49 </head>
michael@0 50 <body>
michael@0 51 <div><canvas id="c1" width="300" height="300"></canvas></div>
michael@0 52 </body>
michael@0 53 </html>

mercurial