layout/reftests/canvas/dash-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">
     4 function assert(cond, msg) { if (!cond) { throw msg; } }
     5 window.onload = function() {
     6     try {
     7         var ctx = document.getElementById("c1").getContext("2d");
     9         assert(null === ctx.mozDash,
    10                "Default dash is null (no dash)");
    11         assert(0 == ctx.mozDashOffset,
    12                "Default dashOffset is 0 (no dash)");
    14         ctx.mozDash = [ 2 ];
    15         assert(1 == ctx.mozDash.length && 2 == ctx.mozDash[0],
    16                "dash = [ 2 ] works");
    17         ctx.mozDash = null;
    18         assert(null === ctx.mozDash,
    19                "dash = null resets to null");
    20         ctx.mozDash = [ 2 ];
    21         ctx.mozDash = undefined;
    22         assert(null === ctx.mozDash,
    23                "dash = undefined resets to null");
    24         ctx.mozDash = [ 2 ];
    25         ctx.mozDash = [ ];
    26         assert(null === ctx.mozDash,
    27                "dash = [] resets to null");
    29         ctx.mozDash = [ 2 ];
    30         assert(0 == ctx.mozDashOffset, "dashOffset is 0");
    31         ctx.mozDashOffset = 1;
    32         assert(1 == ctx.mozDashOffset, "Setting dashOffset succeeded");
    33         ctx.mozDash = null;
    34         assert(0 == ctx.mozDashOffset, "Disabling dash resets dashOffset");
    35         ctx.mozDash = [ 2 ];
    36         assert(0 == ctx.mozDashOffset, "Previous dashOffset isn't remembered");
    37         ctx.mozDash = null;
    39         // NB: might want to add a |.dash = number| special case,
    40         // don't test that it fails here.  Might also want to add a
    41         // |.dash = [0]| special case for resetting, so don't test
    42         // that either.
    43         var badVals = [ -1,
    44                         "string",
    45                         /* According to the WebIDL sequence-ifying
    46                          * (really they mean array-ifying here)
    47                          * algorithm, objects without .length
    48                          * properties convert to a 0-length arrays.
    49                          * This seems ... odd, since by the book we're
    50                          * forced to accept |ctx.dash = Function|,
    51                          * e.g., but there it is.
    52                          */
    53                         // { obj: true },
    54                         [ "array of string" ],
    55                         [ -1 ],
    56                         [ 0, 0, 0 ],
    57                         [ 2, "string" ],
    58         ];
    59         ctx.mozDash = [ 2 ];
    60         for (var i = 0; i < badVals.length; ++i) {
    61             var error = false;
    62             try { ctx.mozDash = badVals[i]; }
    63             catch(e) { error = true; }
    64             assert(error && 1 == ctx.mozDash.length && 2 == ctx.mozDash[0],
    65                    "Expected |dash = "+ badVals[i] +"| to throw exception and not change .dash");
    66         }
    67         ctx.mozDash = null;
    69         ctx.save();
    70         ctx.mozDash = [ 2 ];
    71         ctx.restore();
    72         assert(null === ctx.mozDash,
    73                "dash was saved then restored");
    74     } catch (e) {
    75         document.body.innerHTML = "FAIL: "+ e.toString();
    76         return;
    77     }
    78     document.body.innerHTML = "Pass";
    79 }
    80   </script>
    81 </head>
    82 <body>
    83   <div><canvas id="c1" width="300" height="300"></canvas></div>
    84 </body>
    85 </html>

mercurial