1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/system/tests/test_constants.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,141 @@ 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 constants 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 +let worker; 1.21 + 1.22 +function test_xul() { 1.23 + let lib; 1.24 + isnot(null, OS.Constants.Path.libxul, "libxulpath is defined"); 1.25 + try { 1.26 + lib = ctypes.open(OS.Constants.Path.libxul); 1.27 + lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t); 1.28 + } catch (x) { 1.29 + success = false; 1.30 + ok(false, "Could not open libxul " + x); 1.31 + } 1.32 + if (lib) { 1.33 + lib.close(); 1.34 + } 1.35 + ok(true, "test_xul: opened libxul successfully"); 1.36 +} 1.37 + 1.38 +// Test that OS.Constants.libc is defined 1.39 +function test_libc() { 1.40 + isnot(null, OS.Constants.libc, "OS.Constants.libc is defined"); 1.41 + is(0001, OS.Constants.libc.S_IXOTH, "OS.Constants.libc.S_IXOTH is defined"); 1.42 + is(0002, OS.Constants.libc.S_IWOTH, "OS.Constants.libc.S_IWOTH is defined"); 1.43 + is(0007, OS.Constants.libc.S_IRWXO, "OS.Constants.libc.S_IRWXO is defined"); 1.44 + is(0010, OS.Constants.libc.S_IXGRP, "OS.Constants.libc.S_IXGRP is defined"); 1.45 + is(0020, OS.Constants.libc.S_IWGRP, "OS.Constants.libc.S_IWGRP is defined"); 1.46 + is(0040, OS.Constants.libc.S_IRGRP, "OS.Constants.libc.S_IRGRP is defined"); 1.47 + is(0070, OS.Constants.libc.S_IRWXG, "OS.Constants.libc.S_IRWXG is defined"); 1.48 + is(0100, OS.Constants.libc.S_IXUSR, "OS.Constants.libc.S_IXUSR is defined"); 1.49 + is(0200, OS.Constants.libc.S_IWUSR, "OS.Constants.libc.S_IWUSR is defined"); 1.50 + is(0400, OS.Constants.libc.S_IRUSR, "OS.Constants.libc.S_IRUSR is defined"); 1.51 + is(0700, OS.Constants.libc.S_IRWXU, "OS.Constants.libc.S_IRWXU is defined"); 1.52 +} 1.53 + 1.54 +// Test that OS.Constants.Win is defined 1.55 +function test_Win() { 1.56 + var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"] 1.57 + .getService(Components.interfaces.nsIXULRuntime); 1.58 + if(xulRuntime.OS == "Windows") { 1.59 + ok("Win" in OS.Constants, "OS.Constants.Win is defined"); 1.60 + is(OS.Constants.Win.INVALID_HANDLE_VALUE, -1, 1.61 + "OS.Constants.Win.INVALID_HANDLE_VALUE is defined and correct"); 1.62 + } 1.63 +} 1.64 + 1.65 +// Test that OS.Constants.Sys.DEBUG is set properly on main thread 1.66 +function test_debugBuildMainThread(isDebugBuild) { 1.67 + is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on main thread"); 1.68 +} 1.69 + 1.70 +// Test that OS.Constants.Sys.umask is set properly on main thread 1.71 +function test_umaskMainThread(umask) { 1.72 + is(umask, OS.Constants.Sys.umask, 1.73 + "OS.Constants.Sys.umask is set properly on main thread: " + 1.74 + ("0000"+umask.toString(8)).slice(-4)); 1.75 +} 1.76 + 1.77 + 1.78 +function test() { 1.79 + ok(true, "test_constants.xul: Starting test"); 1.80 + 1.81 + // Test 1: Load libxul from main thread 1.82 + Components.classes["@mozilla.org/net/osfileconstantsservice;1"]. 1.83 + getService(Components.interfaces.nsIOSFileConstantsService). 1.84 + init(); 1.85 + Components.utils.import("resource://gre/modules/ctypes.jsm"); 1.86 + test_xul(); 1.87 + test_libc(); 1.88 + test_Win(); 1.89 + 1.90 + let isDebugBuild = Components.classes["@mozilla.org/xpcom/debug;1"] 1.91 + .getService(Components.interfaces.nsIDebug2).isDebugBuild; 1.92 + test_debugBuildMainThread(isDebugBuild); 1.93 + 1.94 + let umask = Components.classes["@mozilla.org/system-info;1"]. 1.95 + getService(Components.interfaces.nsIPropertyBag2). 1.96 + getProperty("umask"); 1.97 + test_umaskMainThread(umask); 1.98 + 1.99 + // Test 2: Load libxul from chrome thread 1.100 + worker = new ChromeWorker("worker_constants.js"); 1.101 + SimpleTest.waitForExplicitFinish(); 1.102 + ok(true, "test_constants.xul: Chrome worker created"); 1.103 + worker.onerror = function onerror(error) { 1.104 + error.preventDefault(); 1.105 + ok(false, "error " + error); 1.106 + } 1.107 + worker.onmessage = function onmessage(msg) { 1.108 + switch (msg.data.kind) { 1.109 + case "is": 1.110 + SimpleTest.is(msg.data.a, msg.data.b, msg.data.description); 1.111 + return; 1.112 + case "isnot": 1.113 + SimpleTest.isnot(msg.data.a, msg.data.b, msg.data.description); 1.114 + return; 1.115 + case "ok": 1.116 + SimpleTest.ok(msg.data.condition, msg.data.description); 1.117 + return; 1.118 + case "finish": 1.119 + SimpleTest.finish(); 1.120 + return; 1.121 + default: 1.122 + SimpleTest.ok(false, "test_constants.xul: wrong message " + JSON.stringify(msg.data)); 1.123 + return; 1.124 + } 1.125 + }; 1.126 + 1.127 + // pass expected values that are unavailable off-main-thread 1.128 + // to the worker 1.129 + worker.postMessage({ 1.130 + isDebugBuild: isDebugBuild, 1.131 + umask: umask 1.132 + }); 1.133 + ok(true, "test_constants.xul: Test in progress"); 1.134 +}; 1.135 +]]> 1.136 + </script> 1.137 + 1.138 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.139 + <p id="display"></p> 1.140 + <div id="content" style="display:none;"></div> 1.141 + <pre id="test"></pre> 1.142 + </body> 1.143 + <label id="test-result"/> 1.144 +</window>