dom/workers/test/test_json.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial