|
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"> |
|
18 |
|
19 </div> |
|
20 <pre id="test"> |
|
21 <script src="json_worker.js" language="javascript"></script> |
|
22 <script class="testbody" language="javascript"> |
|
23 |
|
24 ok(messages.length, "No messages to test!"); |
|
25 |
|
26 var worker = new Worker("json_worker.js"); |
|
27 |
|
28 var index = 0; |
|
29 worker.onmessage = function(event) { |
|
30 var key = messages[index++]; |
|
31 |
|
32 // Loop for the ones we shouldn't receive. |
|
33 while (key.exception) { |
|
34 key = messages[index++]; |
|
35 } |
|
36 |
|
37 is(typeof event.data, key.type, "Bad type! " + messages.indexOf(key)); |
|
38 |
|
39 if (key.array) { |
|
40 is(event.data instanceof Array, key.array, |
|
41 "Array mismatch! " + messages.indexOf(key)); |
|
42 } |
|
43 |
|
44 if (key.isNaN) { |
|
45 ok(isNaN(event.data), "Should be NaN!" + messages.indexOf(key)); |
|
46 } |
|
47 |
|
48 if (key.isInfinity) { |
|
49 is(event.data, Infinity, "Should be Infinity!" + messages.indexOf(key)); |
|
50 } |
|
51 |
|
52 if (key.isNegativeInfinity) { |
|
53 is(event.data, -Infinity, "Should be -Infinity!" + messages.indexOf(key)); |
|
54 } |
|
55 |
|
56 if (key.shouldCompare || key.shouldEqual) { |
|
57 ok(event.data == key.compareValue, |
|
58 "Values don't compare! " + messages.indexOf(key)); |
|
59 } |
|
60 |
|
61 if (key.shouldEqual) { |
|
62 ok(event.data === key.compareValue, |
|
63 "Values don't equal! " + messages.indexOf(key)); |
|
64 } |
|
65 |
|
66 if (key.jsonValue) { |
|
67 is(JSON.stringify(event.data), key.jsonValue, |
|
68 "Object stringification inconsistent!" + messages.indexOf(key)); |
|
69 } |
|
70 |
|
71 if (event.data == "testFinished") { |
|
72 is(index, messages.length, "Didn't see the right number of messages!"); |
|
73 SimpleTest.finish(); |
|
74 } |
|
75 }; |
|
76 |
|
77 worker.onerror = function(event) { |
|
78 ok(false, "Worker had an error: " + event.message); |
|
79 SimpleTest.finish(); |
|
80 } |
|
81 |
|
82 worker.postMessage("start"); |
|
83 |
|
84 SimpleTest.waitForExplicitFinish(); |
|
85 |
|
86 </script> |
|
87 </pre> |
|
88 </body> |
|
89 </html> |