dom/system/tests/worker_constants.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function log(text) {
     5   dump("WORKER "+text+"\n");
     6 }
     8 function send(message) {
     9   self.postMessage(message);
    10 }
    12 self.onmessage = function(msg) {
    13   self.onmessage = function(msg) {
    14     log("ignored message "+JSON.stringify(msg.data));
    15   };
    16   let { isDebugBuild, umask } = msg.data;
    17   try {
    18     test_name();
    19     test_xul();
    20     test_debugBuildWorkerThread(isDebugBuild);
    21     test_umaskWorkerThread(umask);
    22   } catch (x) {
    23     log("Catching error: " + x);
    24     log("Stack: " + x.stack);
    25     log("Source: " + x.toSource());
    26     ok(false, x.toString() + "\n" + x.stack);
    27   }
    28   finish();
    29 };
    31 function finish() {
    32   send({kind: "finish"});
    33 }
    35 function ok(condition, description) {
    36   send({kind: "ok", condition: condition, description:description});
    37 }
    38 function is(a, b, description) {
    39   send({kind: "is", a: a, b:b, description:description});
    40 }
    41 function isnot(a, b, description) {
    42   send({kind: "isnot", a: a, b:b, description:description});
    43 }
    45 // Test that OS.Constants.Sys.Name is defined
    46 function test_name() {
    47   isnot(null, OS.Constants.Sys.Name, "OS.Constants.Sys.Name is defined");
    48 }
    50 // Test that OS.Constants.Sys.DEBUG is set properly in ChromeWorker thread
    51 function test_debugBuildWorkerThread(isDebugBuild) {
    52   is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on worker thread");
    53 }
    55 // Test that OS.Constants.Sys.umask is set properly in ChromeWorker thread
    56 function test_umaskWorkerThread(umask) {
    57   is(umask, OS.Constants.Sys.umask,
    58      "OS.Constants.Sys.umask is set properly on worker thread: " +
    59      ("0000"+umask.toString(8)).slice(-4));
    60 }
    62 // Test that OS.Constants.Path.libxul lets us open libxul
    63 function test_xul() {
    64   let lib;
    65   isnot(null, OS.Constants.Path.libxul, "libxul is defined");
    66   try {
    67     lib = ctypes.open(OS.Constants.Path.libxul);
    68     lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
    69   } catch (x) {
    70     ok(false, "test_xul: Could not open libxul: " + x);
    71   }
    72   if (lib) {
    73     lib.close();
    74   }
    75   ok(true, "test_xul: opened libxul successfully");
    76 }

mercurial