Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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 | assert(isSameTM(IM, ctx.mozCurrentTransform), |
michael@0 | 28 | "currentTransform is identity by default"); |
michael@0 | 29 | assert(isSameTM(IM, ctx.mozCurrentTransformInverse), |
michael@0 | 30 | "currentTransformInverse is identity by default"); |
michael@0 | 31 | |
michael@0 | 32 | var m = [ 1, 2, 3, 4, 5, 6 ]; |
michael@0 | 33 | ctx.mozCurrentTransform = m; |
michael@0 | 34 | assert(isSameTM(m, ctx.mozCurrentTransform), |
michael@0 | 35 | "currentTransform successfully set"); |
michael@0 | 36 | var badVals = [ -1, |
michael@0 | 37 | "string", |
michael@0 | 38 | { obj: true }, |
michael@0 | 39 | [ "array of string" ], |
michael@0 | 40 | [ -1 ], |
michael@0 | 41 | [ "string", 1, 2, 3, 4, 5 ], |
michael@0 | 42 | [ { obj: true }, 1, 2, 3, 4, 5 ], |
michael@0 | 43 | ]; |
michael@0 | 44 | for (var i = 0; i < badVals.length; ++i) { |
michael@0 | 45 | var error = false; |
michael@0 | 46 | try { ctx.mozCurrentTransform = badVals[i]; } |
michael@0 | 47 | catch(e) { error = true; } |
michael@0 | 48 | assert(error && isSameTM(m, ctx.mozCurrentTransform), |
michael@0 | 49 | "Expected |currentTransform = "+ badVals[i] +"| to throw exception and not change .currentTransform"); |
michael@0 | 50 | |
michael@0 | 51 | error = false; |
michael@0 | 52 | try { ctx.mozCurrentTransformInverse = badVals[i]; } |
michael@0 | 53 | catch(e) { error = true; } |
michael@0 | 54 | assert(error && isSameTM(m, ctx.mozCurrentTransform), |
michael@0 | 55 | "Expected |currentTransformInverse = "+ badVals[i] +"| to throw exception and not change .currentTransform"); |
michael@0 | 56 | } |
michael@0 | 57 | ctx.mozCurrentTransform = IM; |
michael@0 | 58 | |
michael@0 | 59 | var noopVals = [ [ Number.NaN, 1, 2, 3, 4, 5 ], |
michael@0 | 60 | [ Infinity, 1, 2, 3, 4, 5 ], |
michael@0 | 61 | ]; |
michael@0 | 62 | for (var i = 0; i < noopVals.length; ++i) { |
michael@0 | 63 | ctx.mozCurrentTransform = noopVals[i]; |
michael@0 | 64 | assert(isSameTM(ctx.mozCurrentTransform, IM), |
michael@0 | 65 | "Illegal float values result in no-ops (sigh)"); |
michael@0 | 66 | } |
michael@0 | 67 | ctx.mozCurrentTransform = IM; |
michael@0 | 68 | |
michael@0 | 69 | ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]); |
michael@0 | 70 | assert(isSameTM(ctx.mozCurrentTransform, m), |
michael@0 | 71 | "setTransform() updates currentTransform"); |
michael@0 | 72 | } catch (e) { |
michael@0 | 73 | document.body.innerHTML = "FAIL: "+ e.toString(); |
michael@0 | 74 | return; |
michael@0 | 75 | } |
michael@0 | 76 | document.body.innerHTML = "Pass"; |
michael@0 | 77 | } |
michael@0 | 78 | </script> |
michael@0 | 79 | </head> |
michael@0 | 80 | <body> |
michael@0 | 81 | <div><canvas id="c1" width="300" height="300"></canvas></div> |
michael@0 | 82 | </body> |
michael@0 | 83 | </html> |