dom/workers/test/test_json.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!--
     2   Any copyright is dedicated to the Public Domain.
     3   http://creativecommons.org/publicdomain/zero/1.0/
     4 -->
     5 <!DOCTYPE HTML>
     6 <html>
     7 <!--
     8 Tests of DOM Worker JSON messages
     9 -->
    10 <head>
    11   <title>Test for DOM Worker Navigator</title>
    12   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    13   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    14 </head>
    15 <body>
    16 <p id="display"></p>
    17 <div id="content" style="display: none">
    19 </div>
    20 <pre id="test">
    21 <script src="json_worker.js" language="javascript"></script>
    22 <script class="testbody" language="javascript">
    24   ok(messages.length, "No messages to test!");
    26   var worker = new Worker("json_worker.js");
    28   var index = 0;
    29   worker.onmessage = function(event) {
    30     var key = messages[index++];
    32     // Loop for the ones we shouldn't receive.
    33     while (key.exception) {
    34       key = messages[index++];
    35     }
    37     is(typeof event.data, key.type, "Bad type! " + messages.indexOf(key));
    39     if (key.array) {
    40       is(event.data instanceof Array, key.array,
    41          "Array mismatch! " + messages.indexOf(key));
    42     }
    44     if (key.isNaN) {
    45       ok(isNaN(event.data), "Should be NaN!" + messages.indexOf(key));
    46     }
    48     if (key.isInfinity) {
    49       is(event.data, Infinity, "Should be Infinity!" + messages.indexOf(key));
    50     }
    52     if (key.isNegativeInfinity) {
    53       is(event.data, -Infinity, "Should be -Infinity!" + messages.indexOf(key));
    54     }
    56     if (key.shouldCompare || key.shouldEqual) {
    57       ok(event.data == key.compareValue,
    58          "Values don't compare! "  + messages.indexOf(key));
    59     }
    61     if (key.shouldEqual) {
    62       ok(event.data === key.compareValue,
    63          "Values don't equal! " + messages.indexOf(key));
    64     }
    66     if (key.jsonValue) {
    67       is(JSON.stringify(event.data), key.jsonValue,
    68          "Object stringification inconsistent!" + messages.indexOf(key));
    69     }
    71     if (event.data == "testFinished") {
    72       is(index, messages.length, "Didn't see the right number of messages!");
    73       SimpleTest.finish();
    74     }
    75   };
    77   worker.onerror = function(event) {
    78     ok(false, "Worker had an error: " + event.message);
    79     SimpleTest.finish();
    80   }
    82   worker.postMessage("start");
    84   SimpleTest.waitForExplicitFinish();
    86 </script>
    87 </pre>
    88 </body>
    89 </html>

mercurial