2012-06-29 05:56:53 +04:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<window title="Testing constants on a chrome worker thread"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="test();">
|
|
|
|
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
|
|
|
<script type="application/javascript">
|
|
|
|
<![CDATA[
|
|
|
|
|
|
|
|
let worker;
|
|
|
|
|
2012-07-04 16:30:58 +04:00
|
|
|
function test_xul() {
|
|
|
|
let lib;
|
|
|
|
isnot(null, OS.Constants.Path.libxul, "libxulpath is defined");
|
|
|
|
try {
|
|
|
|
lib = ctypes.open(OS.Constants.Path.libxul);
|
|
|
|
lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
|
|
|
|
} catch (x) {
|
|
|
|
success = false;
|
|
|
|
ok(false, "Could not open libxul " + x);
|
|
|
|
}
|
|
|
|
if (lib) {
|
|
|
|
lib.close();
|
|
|
|
}
|
|
|
|
ok(true, "test_xul: opened libxul successfully");
|
|
|
|
}
|
|
|
|
|
2013-01-20 03:49:42 +04:00
|
|
|
// Test that OS.Constants.libc is defined
|
|
|
|
function test_libc() {
|
|
|
|
isnot(null, OS.Constants.libc, "OS.Constants.libc is defined");
|
|
|
|
is(0001, OS.Constants.libc.S_IXOTH, "OS.Constants.libc.S_IXOTH is defined");
|
|
|
|
is(0002, OS.Constants.libc.S_IWOTH, "OS.Constants.libc.S_IWOTH is defined");
|
|
|
|
is(0007, OS.Constants.libc.S_IRWXO, "OS.Constants.libc.S_IRWXO is defined");
|
|
|
|
is(0010, OS.Constants.libc.S_IXGRP, "OS.Constants.libc.S_IXGRP is defined");
|
|
|
|
is(0020, OS.Constants.libc.S_IWGRP, "OS.Constants.libc.S_IWGRP is defined");
|
|
|
|
is(0040, OS.Constants.libc.S_IRGRP, "OS.Constants.libc.S_IRGRP is defined");
|
|
|
|
is(0070, OS.Constants.libc.S_IRWXG, "OS.Constants.libc.S_IRWXG is defined");
|
|
|
|
is(0100, OS.Constants.libc.S_IXUSR, "OS.Constants.libc.S_IXUSR is defined");
|
|
|
|
is(0200, OS.Constants.libc.S_IWUSR, "OS.Constants.libc.S_IWUSR is defined");
|
|
|
|
is(0400, OS.Constants.libc.S_IRUSR, "OS.Constants.libc.S_IRUSR is defined");
|
|
|
|
is(0700, OS.Constants.libc.S_IRWXU, "OS.Constants.libc.S_IRWXU is defined");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that OS.Constants.Win is defined
|
|
|
|
function test_Win() {
|
|
|
|
var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Components.interfaces.nsIXULRuntime);
|
|
|
|
if(xulRuntime.OS == "Windows") {
|
|
|
|
ok("Win" in OS.Constants, "OS.Constants.Win is defined");
|
|
|
|
is(OS.Constants.Win.INVALID_HANDLE_VALUE, -1,
|
|
|
|
"OS.Constants.Win.INVALID_HANDLE_VALUE is defined and correct");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 16:36:10 +04:00
|
|
|
// Test that OS.Constants.Sys.DEBUG is set properly on main thread
|
|
|
|
function test_debugBuildMainThread(isDebugBuild) {
|
|
|
|
is(isDebugBuild, !!OS.Constants.Sys.DEBUG, "OS.Constants.Sys.DEBUG is set properly on main thread");
|
|
|
|
}
|
|
|
|
|
2014-04-26 18:56:58 +04:00
|
|
|
// Test that OS.Constants.Sys.umask is set properly on main thread
|
|
|
|
function test_umaskMainThread(umask) {
|
|
|
|
is(umask, OS.Constants.Sys.umask,
|
|
|
|
"OS.Constants.Sys.umask is set properly on main thread: " +
|
|
|
|
("0000"+umask.toString(8)).slice(-4));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-29 05:56:53 +04:00
|
|
|
function test() {
|
|
|
|
ok(true, "test_constants.xul: Starting test");
|
2012-07-04 16:30:58 +04:00
|
|
|
|
|
|
|
// Test 1: Load libxul from main thread
|
|
|
|
Components.classes["@mozilla.org/net/osfileconstantsservice;1"].
|
|
|
|
getService(Components.interfaces.nsIOSFileConstantsService).
|
|
|
|
init();
|
|
|
|
Components.utils.import("resource://gre/modules/ctypes.jsm");
|
|
|
|
test_xul();
|
2013-01-20 03:49:42 +04:00
|
|
|
test_libc();
|
|
|
|
test_Win();
|
2012-07-04 16:30:58 +04:00
|
|
|
|
2013-04-24 16:36:10 +04:00
|
|
|
let isDebugBuild = Components.classes["@mozilla.org/xpcom/debug;1"]
|
|
|
|
.getService(Components.interfaces.nsIDebug2).isDebugBuild;
|
|
|
|
test_debugBuildMainThread(isDebugBuild);
|
|
|
|
|
2014-04-26 18:56:58 +04:00
|
|
|
let umask = Components.classes["@mozilla.org/system-info;1"].
|
|
|
|
getService(Components.interfaces.nsIPropertyBag2).
|
|
|
|
getProperty("umask");
|
|
|
|
test_umaskMainThread(umask);
|
|
|
|
|
2012-07-04 16:30:58 +04:00
|
|
|
// Test 2: Load libxul from chrome thread
|
2012-06-29 05:56:53 +04:00
|
|
|
worker = new ChromeWorker("worker_constants.js");
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
ok(true, "test_constants.xul: Chrome worker created");
|
2012-07-06 05:08:02 +04:00
|
|
|
worker.onerror = function onerror(error) {
|
2012-06-29 05:56:53 +04:00
|
|
|
error.preventDefault();
|
2012-07-06 05:08:02 +04:00
|
|
|
ok(false, "error " + error);
|
2012-06-29 05:56:53 +04:00
|
|
|
}
|
2012-07-06 05:08:02 +04:00
|
|
|
worker.onmessage = function onmessage(msg) {
|
2012-06-29 05:56:53 +04:00
|
|
|
switch (msg.data.kind) {
|
|
|
|
case "is":
|
2012-07-06 05:08:02 +04:00
|
|
|
SimpleTest.is(msg.data.a, msg.data.b, msg.data.description);
|
|
|
|
return;
|
2012-06-29 05:56:53 +04:00
|
|
|
case "isnot":
|
2012-07-06 05:08:02 +04:00
|
|
|
SimpleTest.isnot(msg.data.a, msg.data.b, msg.data.description);
|
|
|
|
return;
|
2012-06-29 05:56:53 +04:00
|
|
|
case "ok":
|
2012-07-06 05:08:02 +04:00
|
|
|
SimpleTest.ok(msg.data.condition, msg.data.description);
|
|
|
|
return;
|
2012-06-29 05:56:53 +04:00
|
|
|
case "finish":
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
default:
|
2012-07-06 05:08:02 +04:00
|
|
|
SimpleTest.ok(false, "test_constants.xul: wrong message " + JSON.stringify(msg.data));
|
2012-06-29 05:56:53 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2013-04-24 16:36:10 +04:00
|
|
|
|
2014-04-26 18:56:58 +04:00
|
|
|
// pass expected values that are unavailable off-main-thread
|
|
|
|
// to the worker
|
|
|
|
worker.postMessage({
|
|
|
|
isDebugBuild: isDebugBuild,
|
|
|
|
umask: umask
|
|
|
|
});
|
2012-06-29 05:56:53 +04:00
|
|
|
ok(true, "test_constants.xul: Test in progress");
|
|
|
|
};
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display:none;"></div>
|
|
|
|
<pre id="test"></pre>
|
|
|
|
</body>
|
|
|
|
<label id="test-result"/>
|
|
|
|
</window>
|