dom/system/tests/test_constants.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 constants on a chrome worker thread"
     7         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     8         onload="test();">
    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[
    17 let worker;
    19 function test_xul() {
    20   let lib;
    21   isnot(null, OS.Constants.Path.libxul, "libxulpath is defined");
    22   try {
    23     lib = ctypes.open(OS.Constants.Path.libxul);
    24     lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
    25   } catch (x) {
    26     success = false;
    27     ok(false, "Could not open libxul " + x);
    28   }
    29   if (lib) {
    30     lib.close();
    31   }
    32   ok(true, "test_xul: opened libxul successfully");
    33 }
    35 // Test that OS.Constants.libc is defined
    36 function test_libc() {
    37   isnot(null, OS.Constants.libc, "OS.Constants.libc is defined");
    38   is(0001, OS.Constants.libc.S_IXOTH, "OS.Constants.libc.S_IXOTH is defined");
    39   is(0002, OS.Constants.libc.S_IWOTH, "OS.Constants.libc.S_IWOTH is defined");
    40   is(0007, OS.Constants.libc.S_IRWXO, "OS.Constants.libc.S_IRWXO is defined");
    41   is(0010, OS.Constants.libc.S_IXGRP, "OS.Constants.libc.S_IXGRP is defined");
    42   is(0020, OS.Constants.libc.S_IWGRP, "OS.Constants.libc.S_IWGRP is defined");
    43   is(0040, OS.Constants.libc.S_IRGRP, "OS.Constants.libc.S_IRGRP is defined");
    44   is(0070, OS.Constants.libc.S_IRWXG, "OS.Constants.libc.S_IRWXG is defined");
    45   is(0100, OS.Constants.libc.S_IXUSR, "OS.Constants.libc.S_IXUSR is defined");
    46   is(0200, OS.Constants.libc.S_IWUSR, "OS.Constants.libc.S_IWUSR is defined");
    47   is(0400, OS.Constants.libc.S_IRUSR, "OS.Constants.libc.S_IRUSR is defined");
    48   is(0700, OS.Constants.libc.S_IRWXU, "OS.Constants.libc.S_IRWXU is defined");
    49 }
    51 // Test that OS.Constants.Win is defined
    52 function test_Win() {
    53   var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
    54                            .getService(Components.interfaces.nsIXULRuntime);
    55   if(xulRuntime.OS == "Windows") {
    56     ok("Win" in OS.Constants, "OS.Constants.Win is defined");
    57     is(OS.Constants.Win.INVALID_HANDLE_VALUE, -1,
    58       "OS.Constants.Win.INVALID_HANDLE_VALUE is defined and correct");
    59   }
    60 }
    62 // Test that OS.Constants.Sys.DEBUG is set properly on main thread
    63 function test_debugBuildMainThread(isDebugBuild) {
    64   is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on main thread");
    65 }
    67 // Test that OS.Constants.Sys.umask is set properly on main thread
    68 function test_umaskMainThread(umask) {
    69   is(umask, OS.Constants.Sys.umask,
    70      "OS.Constants.Sys.umask is set properly on main thread: " +
    71      ("0000"+umask.toString(8)).slice(-4));
    72 }
    75 function test() {
    76   ok(true, "test_constants.xul: Starting test");
    78   // Test 1: Load libxul from main thread
    79   Components.classes["@mozilla.org/net/osfileconstantsservice;1"].
    80     getService(Components.interfaces.nsIOSFileConstantsService).
    81     init();
    82   Components.utils.import("resource://gre/modules/ctypes.jsm");
    83   test_xul();
    84   test_libc();
    85   test_Win();
    87   let isDebugBuild = Components.classes["@mozilla.org/xpcom/debug;1"]
    88                             .getService(Components.interfaces.nsIDebug2).isDebugBuild;
    89   test_debugBuildMainThread(isDebugBuild);
    91   let umask = Components.classes["@mozilla.org/system-info;1"].
    92     getService(Components.interfaces.nsIPropertyBag2).
    93     getProperty("umask");
    94   test_umaskMainThread(umask);
    96   // Test 2: Load libxul from chrome thread
    97   worker = new ChromeWorker("worker_constants.js");
    98   SimpleTest.waitForExplicitFinish();
    99   ok(true, "test_constants.xul: Chrome worker created");
   100   worker.onerror = function onerror(error) {
   101     error.preventDefault();
   102     ok(false, "error " + error);
   103   }
   104   worker.onmessage = function onmessage(msg) {
   105     switch (msg.data.kind) {
   106     case "is":
   107       SimpleTest.is(msg.data.a, msg.data.b, msg.data.description);
   108       return;
   109     case "isnot":
   110       SimpleTest.isnot(msg.data.a, msg.data.b, msg.data.description);
   111       return;
   112     case "ok":
   113       SimpleTest.ok(msg.data.condition, msg.data.description);
   114       return;
   115     case "finish":
   116       SimpleTest.finish();
   117       return;
   118     default:
   119       SimpleTest.ok(false, "test_constants.xul: wrong message " + JSON.stringify(msg.data));
   120       return;
   121     }
   122   };
   124   // pass expected values that are unavailable off-main-thread
   125   // to the worker
   126   worker.postMessage({
   127     isDebugBuild: isDebugBuild,
   128     umask: umask
   129   });
   130   ok(true, "test_constants.xul: Test in progress");
   131 };
   132 ]]>
   133   </script>
   135   <body xmlns="http://www.w3.org/1999/xhtml">
   136     <p id="display"></p>
   137     <div id="content" style="display:none;"></div>
   138     <pre id="test"></pre>
   139   </body>
   140   <label id="test-result"/>
   141 </window>

mercurial