layout/reftests/canvas/ctm-sanity.html

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <html>
     2 <head>
     3   <script type="text/javascript">
     5 function assert(cond, msg) { if (!cond) { throw msg; } }
     7 function isSameTM(m1, m2) {
     8     // XXX this is probably the ugliest possible way to write this function,
     9     // but it's intended to be lowest-common-denominator
    10     if (!(m1.length === 6 && m1.length === m2.length)) {
    11         return false;
    12     }
    13     for (var i = 0; i < m1.length; ++i) {
    14         if (m1[i] !== m2[i]) {
    15             return false;
    16         }
    17     }
    18     return true;
    19 }
    21 window.onload = function() {
    22     var IM = [ 1, 0, 0, 1, 0, 0 ];
    24     try {
    25         var ctx = document.getElementById("c1").getContext("2d");
    27         assert(isSameTM(IM, ctx.mozCurrentTransform),
    28                "currentTransform is identity by default");
    29         assert(isSameTM(IM, ctx.mozCurrentTransformInverse),
    30                "currentTransformInverse is identity by default");
    32         var m = [ 1, 2, 3, 4, 5, 6 ];
    33         ctx.mozCurrentTransform = m;
    34         assert(isSameTM(m, ctx.mozCurrentTransform),
    35                "currentTransform successfully set");
    36         var badVals = [ -1,
    37                         "string",
    38                         { obj: true },
    39                         [ "array of string" ],
    40                         [ -1 ],
    41                         [ "string", 1, 2, 3, 4, 5 ],
    42                         [ { obj: true }, 1, 2, 3, 4, 5 ],
    43         ];
    44         for (var i = 0; i < badVals.length; ++i) {
    45             var error = false;
    46             try { ctx.mozCurrentTransform = badVals[i]; }
    47             catch(e) { error = true; }
    48             assert(error && isSameTM(m, ctx.mozCurrentTransform),
    49                    "Expected |currentTransform = "+ badVals[i] +"| to throw exception and not change .currentTransform");
    51             error = false;
    52             try { ctx.mozCurrentTransformInverse = badVals[i]; }
    53             catch(e) { error = true; }
    54             assert(error && isSameTM(m, ctx.mozCurrentTransform),
    55                    "Expected |currentTransformInverse = "+ badVals[i] +"| to throw exception and not change .currentTransform");
    56         }
    57         ctx.mozCurrentTransform = IM;
    59         var noopVals = [ [ Number.NaN, 1, 2, 3, 4, 5 ],
    60                          [ Infinity, 1, 2, 3, 4, 5 ],
    61         ];
    62         for (var i = 0; i < noopVals.length; ++i) {
    63             ctx.mozCurrentTransform = noopVals[i];
    64             assert(isSameTM(ctx.mozCurrentTransform, IM),
    65                    "Illegal float values result in no-ops (sigh)");
    66         }
    67         ctx.mozCurrentTransform = IM;
    69         ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
    70         assert(isSameTM(ctx.mozCurrentTransform, m),
    71                "setTransform() updates currentTransform");
    72      } catch (e) {
    73         document.body.innerHTML = "FAIL: "+ e.toString();
    74         return;
    75     }
    76     document.body.innerHTML = "Pass";
    77 }
    78   </script>
    79 </head>
    80 <body>
    81   <div><canvas id="c1" width="300" height="300"></canvas></div>
    82 </body>
    83 </html>

mercurial