summaryrefslogtreecommitdiffstats
path: root/dom/system/tests/test_constants.xhtml
diff options
context:
space:
mode:
Diffstat (limited to 'dom/system/tests/test_constants.xhtml')
-rw-r--r--dom/system/tests/test_constants.xhtml115
1 files changed, 115 insertions, 0 deletions
diff --git a/dom/system/tests/test_constants.xhtml b/dom/system/tests/test_constants.xhtml
new file mode 100644
index 0000000000..f7450e0a6c
--- /dev/null
+++ b/dom/system/tests/test_constants.xhtml
@@ -0,0 +1,115 @@
+<?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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+ <script type="application/javascript">
+ <![CDATA[
+
+/* global OS */
+
+let worker;
+
+// Test that OS.Constants.libc is defined
+function test_libc() {
+ isnot(null, OS.Constants.libc, "OS.Constants.libc is defined");
+ is(0o001, OS.Constants.libc.S_IXOTH, "OS.Constants.libc.S_IXOTH is defined");
+ is(0o002, OS.Constants.libc.S_IWOTH, "OS.Constants.libc.S_IWOTH is defined");
+ is(0o007, OS.Constants.libc.S_IRWXO, "OS.Constants.libc.S_IRWXO is defined");
+ is(0o010, OS.Constants.libc.S_IXGRP, "OS.Constants.libc.S_IXGRP is defined");
+ is(0o020, OS.Constants.libc.S_IWGRP, "OS.Constants.libc.S_IWGRP is defined");
+ is(0o040, OS.Constants.libc.S_IRGRP, "OS.Constants.libc.S_IRGRP is defined");
+ is(0o070, OS.Constants.libc.S_IRWXG, "OS.Constants.libc.S_IRWXG is defined");
+ is(0o100, OS.Constants.libc.S_IXUSR, "OS.Constants.libc.S_IXUSR is defined");
+ is(0o200, OS.Constants.libc.S_IWUSR, "OS.Constants.libc.S_IWUSR is defined");
+ is(0o400, OS.Constants.libc.S_IRUSR, "OS.Constants.libc.S_IRUSR is defined");
+ is(0o700, OS.Constants.libc.S_IRWXU, "OS.Constants.libc.S_IRWXU is defined");
+}
+
+// Test that OS.Constants.Win is defined
+function test_Win() {
+ var xulRuntime = Cc["@mozilla.org/xre/app-info;1"]
+ .getService(Ci.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");
+ }
+}
+
+// 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));
+}
+
+var ctypes;
+function test() {
+ ok(true, "test_constants.xhtml: Starting test");
+
+ // Test 1: Load libxul from main thread
+ Cc["@mozilla.org/net/osfileconstantsservice;1"].
+ getService(Ci.nsIOSFileConstantsService).
+ init();
+ ({ctypes} = ChromeUtils.import("resource://gre/modules/ctypes.jsm"));
+ test_libc();
+ test_Win();
+
+
+ let umask = Cc["@mozilla.org/system-info;1"].
+ getService(Ci.nsIPropertyBag2).
+ getProperty("umask");
+ test_umaskMainThread(umask);
+
+ // Test 2: Load libxul from chrome thread
+ worker = new ChromeWorker("worker_constants.js");
+ SimpleTest.waitForExplicitFinish();
+ ok(true, "test_constants.xhtml: Chrome worker created");
+ worker.onerror = function onerror(error) {
+ error.preventDefault();
+ ok(false, "error " + error);
+ }
+ worker.onmessage = function onmessage(msg) {
+ switch (msg.data.kind) {
+ case "is":
+ SimpleTest.is(msg.data.a, msg.data.b, msg.data.description);
+ return;
+ case "isnot":
+ SimpleTest.isnot(msg.data.a, msg.data.b, msg.data.description);
+ return;
+ case "ok":
+ SimpleTest.ok(msg.data.condition, msg.data.description);
+ return;
+ case "finish":
+ SimpleTest.finish();
+ return;
+ default:
+ SimpleTest.ok(false, "test_constants.xhtml: wrong message " + JSON.stringify(msg.data));
+ return;
+ }
+ };
+
+ // pass expected values that are unavailable off-main-thread
+ // to the worker
+ worker.postMessage({
+ umask: umask
+ });
+ ok(true, "test_constants.xhtml: 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>