dom/workers/test/test_json.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/test_json.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +<!--
     1.5 +  Any copyright is dedicated to the Public Domain.
     1.6 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.7 +-->
     1.8 +<!DOCTYPE HTML>
     1.9 +<html>
    1.10 +<!--
    1.11 +Tests of DOM Worker JSON messages
    1.12 +-->
    1.13 +<head>
    1.14 +  <title>Test for DOM Worker Navigator</title>
    1.15 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.16 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.17 +</head>
    1.18 +<body>
    1.19 +<p id="display"></p>
    1.20 +<div id="content" style="display: none">
    1.21 +
    1.22 +</div>
    1.23 +<pre id="test">
    1.24 +<script src="json_worker.js" language="javascript"></script>
    1.25 +<script class="testbody" language="javascript">
    1.26 +
    1.27 +  ok(messages.length, "No messages to test!");
    1.28 +
    1.29 +  var worker = new Worker("json_worker.js");
    1.30 +
    1.31 +  var index = 0;
    1.32 +  worker.onmessage = function(event) {
    1.33 +    var key = messages[index++];
    1.34 +
    1.35 +    // Loop for the ones we shouldn't receive.
    1.36 +    while (key.exception) {
    1.37 +      key = messages[index++];
    1.38 +    }
    1.39 +
    1.40 +    is(typeof event.data, key.type, "Bad type! " + messages.indexOf(key));
    1.41 +
    1.42 +    if (key.array) {
    1.43 +      is(event.data instanceof Array, key.array,
    1.44 +         "Array mismatch! " + messages.indexOf(key));
    1.45 +    }
    1.46 +
    1.47 +    if (key.isNaN) {
    1.48 +      ok(isNaN(event.data), "Should be NaN!" + messages.indexOf(key));
    1.49 +    }
    1.50 +
    1.51 +    if (key.isInfinity) {
    1.52 +      is(event.data, Infinity, "Should be Infinity!" + messages.indexOf(key));
    1.53 +    }
    1.54 +
    1.55 +    if (key.isNegativeInfinity) {
    1.56 +      is(event.data, -Infinity, "Should be -Infinity!" + messages.indexOf(key));
    1.57 +    }
    1.58 +
    1.59 +    if (key.shouldCompare || key.shouldEqual) {
    1.60 +      ok(event.data == key.compareValue,
    1.61 +         "Values don't compare! "  + messages.indexOf(key));
    1.62 +    }
    1.63 +
    1.64 +    if (key.shouldEqual) {
    1.65 +      ok(event.data === key.compareValue,
    1.66 +         "Values don't equal! " + messages.indexOf(key));
    1.67 +    }
    1.68 +
    1.69 +    if (key.jsonValue) {
    1.70 +      is(JSON.stringify(event.data), key.jsonValue,
    1.71 +         "Object stringification inconsistent!" + messages.indexOf(key));
    1.72 +    }
    1.73 +
    1.74 +    if (event.data == "testFinished") {
    1.75 +      is(index, messages.length, "Didn't see the right number of messages!");
    1.76 +      SimpleTest.finish();
    1.77 +    }
    1.78 +  };
    1.79 +
    1.80 +  worker.onerror = function(event) {
    1.81 +    ok(false, "Worker had an error: " + event.message);
    1.82 +    SimpleTest.finish();
    1.83 +  }
    1.84 +
    1.85 +  worker.postMessage("start");
    1.86 +
    1.87 +  SimpleTest.waitForExplicitFinish();
    1.88 +
    1.89 +</script>
    1.90 +</pre>
    1.91 +</body>
    1.92 +</html>

mercurial