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.

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

mercurial