dom/system/tests/worker_constants.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/system/tests/worker_constants.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function log(text) {
     1.8 +  dump("WORKER "+text+"\n");
     1.9 +}
    1.10 +
    1.11 +function send(message) {
    1.12 +  self.postMessage(message);
    1.13 +}
    1.14 +
    1.15 +self.onmessage = function(msg) {
    1.16 +  self.onmessage = function(msg) {
    1.17 +    log("ignored message "+JSON.stringify(msg.data));
    1.18 +  };
    1.19 +  let { isDebugBuild, umask } = msg.data;
    1.20 +  try {
    1.21 +    test_name();
    1.22 +    test_xul();
    1.23 +    test_debugBuildWorkerThread(isDebugBuild);
    1.24 +    test_umaskWorkerThread(umask);
    1.25 +  } catch (x) {
    1.26 +    log("Catching error: " + x);
    1.27 +    log("Stack: " + x.stack);
    1.28 +    log("Source: " + x.toSource());
    1.29 +    ok(false, x.toString() + "\n" + x.stack);
    1.30 +  }
    1.31 +  finish();
    1.32 +};
    1.33 +
    1.34 +function finish() {
    1.35 +  send({kind: "finish"});
    1.36 +}
    1.37 +
    1.38 +function ok(condition, description) {
    1.39 +  send({kind: "ok", condition: condition, description:description});
    1.40 +}
    1.41 +function is(a, b, description) {
    1.42 +  send({kind: "is", a: a, b:b, description:description});
    1.43 +}
    1.44 +function isnot(a, b, description) {
    1.45 +  send({kind: "isnot", a: a, b:b, description:description});
    1.46 +}
    1.47 +
    1.48 +// Test that OS.Constants.Sys.Name is defined
    1.49 +function test_name() {
    1.50 +  isnot(null, OS.Constants.Sys.Name, "OS.Constants.Sys.Name is defined");
    1.51 +}
    1.52 +
    1.53 +// Test that OS.Constants.Sys.DEBUG is set properly in ChromeWorker thread
    1.54 +function test_debugBuildWorkerThread(isDebugBuild) {
    1.55 +  is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on worker thread");
    1.56 +}
    1.57 +
    1.58 +// Test that OS.Constants.Sys.umask is set properly in ChromeWorker thread
    1.59 +function test_umaskWorkerThread(umask) {
    1.60 +  is(umask, OS.Constants.Sys.umask,
    1.61 +     "OS.Constants.Sys.umask is set properly on worker thread: " +
    1.62 +     ("0000"+umask.toString(8)).slice(-4));
    1.63 +}
    1.64 +
    1.65 +// Test that OS.Constants.Path.libxul lets us open libxul
    1.66 +function test_xul() {
    1.67 +  let lib;
    1.68 +  isnot(null, OS.Constants.Path.libxul, "libxul is defined");
    1.69 +  try {
    1.70 +    lib = ctypes.open(OS.Constants.Path.libxul);
    1.71 +    lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
    1.72 +  } catch (x) {
    1.73 +    ok(false, "test_xul: Could not open libxul: " + x);
    1.74 +  }
    1.75 +  if (lib) {
    1.76 +    lib.close();
    1.77 +  }
    1.78 +  ok(true, "test_xul: opened libxul successfully");
    1.79 +}

mercurial