|
1 <?xml version="1.0"?> |
|
2 <!-- |
|
3 Any copyright is dedicated to the Public Domain. |
|
4 http://creativecommons.org/publicdomain/zero/1.0/ |
|
5 --> |
|
6 <window title="Testing OS.File on a chrome worker thread" |
|
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
8 onload="test();"> |
|
9 |
|
10 <script type="application/javascript" |
|
11 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
12 <script type="application/javascript" |
|
13 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> |
|
14 <script type="application/javascript"> |
|
15 <![CDATA[ |
|
16 |
|
17 "use strict"; |
|
18 |
|
19 let worker; |
|
20 |
|
21 let test = function test() { |
|
22 SimpleTest.info("test_osfile_comms.xul: Starting test"); |
|
23 Components.utils.import("resource://gre/modules/ctypes.jsm"); |
|
24 Components.utils.import("resource://gre/modules/osfile.jsm"); |
|
25 worker = new ChromeWorker("worker_test_osfile_comms.js"); |
|
26 SimpleTest.waitForExplicitFinish(); |
|
27 try { |
|
28 worker.onerror = function onerror(error) { |
|
29 SimpleTest.ok(false, "received error "+error); |
|
30 } |
|
31 worker.onmessage = function onmessage(msg) { |
|
32 Components.utils.forceShrinkingGC(); |
|
33 switch (msg.data.kind) { |
|
34 case "is": |
|
35 SimpleTest.ok(msg.data.outcome, msg.data.description + |
|
36 " ("+ msg.data.a + " ==? " + msg.data.b + ")" ); |
|
37 return; |
|
38 case "isnot": |
|
39 SimpleTest.ok(msg.data.outcome, msg.data.description + |
|
40 " ("+ msg.data.a + " !=? " + msg.data.b + ")" ); |
|
41 return; |
|
42 case "ok": |
|
43 SimpleTest.ok(msg.data.condition, msg.data.description); |
|
44 return; |
|
45 case "info": |
|
46 SimpleTest.info(msg.data.description); |
|
47 return; |
|
48 case "finish": |
|
49 SimpleTest.finish(); |
|
50 return; |
|
51 case "value": |
|
52 SimpleTest.ok(true, "test_osfile_comms.xul: Received value " + JSON.stringify(msg.data.value)); |
|
53 let type = eval(msg.data.typename); |
|
54 let check = eval(msg.data.check); |
|
55 let value = msg.data.value; |
|
56 let deserialized = type.fromMsg(value); |
|
57 check(deserialized, "Main thread test: "); |
|
58 return; |
|
59 default: |
|
60 SimpleTest.ok(false, "test_osfile_comms.xul: wrong message "+JSON.stringify(msg.data)); |
|
61 return; |
|
62 } |
|
63 }; |
|
64 worker.postMessage(0) |
|
65 ok(true, "Worker launched"); |
|
66 } catch(x) { |
|
67 // As we have set |waitForExplicitFinish|, we add this fallback |
|
68 // in case of uncaught error, to ensure that the test does not |
|
69 // just freeze. |
|
70 ok(false, "Caught exception " + x + " at " + x.stack); |
|
71 SimpleTest.finish(); |
|
72 } |
|
73 }; |
|
74 |
|
75 ]]> |
|
76 </script> |
|
77 |
|
78 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
79 <p id="display"></p> |
|
80 <div id="content" style="display:none;"></div> |
|
81 <pre id="test"></pre> |
|
82 </body> |
|
83 <label id="test-result"/> |
|
84 </window> |