toolkit/components/osfile/tests/mochi/test_osfile_comms.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/osfile/tests/mochi/test_osfile_comms.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!--
     1.6 +  Any copyright is dedicated to the Public Domain.
     1.7 +  http://creativecommons.org/publicdomain/zero/1.0/
     1.8 +-->
     1.9 +<window title="Testing OS.File on a chrome worker thread"
    1.10 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.11 +        onload="test();">
    1.12 +
    1.13 +  <script type="application/javascript"
    1.14 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.15 +  <script type="application/javascript"
    1.16 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.17 +  <script type="application/javascript">
    1.18 +  <![CDATA[
    1.19 +
    1.20 +"use strict";
    1.21 +
    1.22 +let worker;
    1.23 +
    1.24 +let test = function test() {
    1.25 +  SimpleTest.info("test_osfile_comms.xul: Starting test");
    1.26 +  Components.utils.import("resource://gre/modules/ctypes.jsm");
    1.27 +  Components.utils.import("resource://gre/modules/osfile.jsm");
    1.28 +  worker = new ChromeWorker("worker_test_osfile_comms.js");
    1.29 +  SimpleTest.waitForExplicitFinish();
    1.30 +  try {
    1.31 +    worker.onerror = function onerror(error) {
    1.32 +      SimpleTest.ok(false, "received error "+error);
    1.33 +    }
    1.34 +   worker.onmessage = function onmessage(msg) {
    1.35 +    Components.utils.forceShrinkingGC();
    1.36 +    switch (msg.data.kind) {
    1.37 +      case "is":
    1.38 +        SimpleTest.ok(msg.data.outcome, msg.data.description +
    1.39 +        " ("+ msg.data.a + " ==? " + msg.data.b + ")" );
    1.40 +        return;
    1.41 +      case "isnot":
    1.42 +        SimpleTest.ok(msg.data.outcome, msg.data.description +
    1.43 +        " ("+ msg.data.a + " !=? " + msg.data.b + ")" );
    1.44 +        return;
    1.45 +      case "ok":
    1.46 +        SimpleTest.ok(msg.data.condition, msg.data.description);
    1.47 +        return;
    1.48 +      case "info":
    1.49 +        SimpleTest.info(msg.data.description);
    1.50 +        return;
    1.51 +      case "finish":
    1.52 +        SimpleTest.finish();
    1.53 +        return;
    1.54 +      case "value":
    1.55 +        SimpleTest.ok(true, "test_osfile_comms.xul: Received value " + JSON.stringify(msg.data.value));
    1.56 +        let type = eval(msg.data.typename);
    1.57 +        let check = eval(msg.data.check);
    1.58 +        let value = msg.data.value;
    1.59 +        let deserialized = type.fromMsg(value);
    1.60 +        check(deserialized, "Main thread test: ");
    1.61 +       return;
    1.62 +      default:
    1.63 +        SimpleTest.ok(false, "test_osfile_comms.xul: wrong message "+JSON.stringify(msg.data));
    1.64 +        return;
    1.65 +      }
    1.66 +    };
    1.67 +    worker.postMessage(0)
    1.68 +    ok(true, "Worker launched");
    1.69 +  } catch(x) {
    1.70 +    // As we have set |waitForExplicitFinish|, we add this fallback
    1.71 +    // in case of uncaught error, to ensure that the test does not
    1.72 +    // just freeze.
    1.73 +    ok(false, "Caught exception " + x + " at " + x.stack);
    1.74 +    SimpleTest.finish();
    1.75 +  }
    1.76 +};
    1.77 +
    1.78 +]]>
    1.79 +  </script>
    1.80 +
    1.81 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.82 +    <p id="display"></p>
    1.83 +    <div id="content" style="display:none;"></div>
    1.84 +    <pre id="test"></pre>
    1.85 +  </body>
    1.86 +  <label id="test-result"/>
    1.87 +</window>

mercurial