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