dom/tests/mochitest/bugs/test_toJSON.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=760851
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Test for Bug 760851</title>
     9   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    11   <script type="application/javascript">
    13   /** Test for Bug 760851 **/
    14   SimpleTest.waitForExplicitFinish();
    16   // We need to skip all the interface constants.
    17   var keysToSkip = ["TYPE_NAVIGATE", "TYPE_RELOAD", "TYPE_RESERVED",
    18                     "TYPE_BACK_FORWARD"];
    20   // Testing window.performance is sufficient, because checkAttributesMatch is
    21   // recursive, so window.performance.navigation and window.performance.timing
    22   // get tested as well.
    23   var toTest = [window.performance];
    25   function checkAttributesMatch(obj, jsonObj) {
    26     if (typeof(obj) !== "object") {
    27       throw "Expected obj to be of type \"object\". Test failed.";
    28     }
    29     if (typeof(jsonObj) !== "object") {
    30       is(false, "Expected object " + jsonObj + " to be of type object, but gotten otherwise");
    31     }
    32     for (key in obj) {
    33       if (typeof(obj[key]) === "function" || keysToSkip.indexOf(key) > -1)
    34         continue;
    35       if (typeof(obj[key]) === "object") {
    36         checkAttributesMatch(obj[key], jsonObj[key]);
    37         continue;
    38       }
    39       is(jsonObj[key], obj[key], "values for " + obj + " key " + key + " should match");
    40     }
    41   }
    43   function runTest() {
    44     toTest.forEach(function(testObj) {
    45       var jsonCopy = JSON.parse(JSON.stringify(testObj));
    46       checkAttributesMatch(testObj, jsonCopy);
    47     });
    48     SimpleTest.finish();
    49   }
    51   </script>
    52 </head>
    53 <body onload="runTest();">
    54 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760851">Mozilla Bug 760851</a>
    55 <p id="display"></p>
    56 <div id="content" style="display: none">
    57   <p></p>
    58   <p></p>
    59   <p></p>
    60 </div>
    61 <pre id="test">
    62 </pre>
    63 </body>
    64 </html>

mercurial