dom/system/tests/test_constants.xul
author Rafael Ávila de Espíndola <respindola@mozilla.com>
Tue, 21 Aug 2012 12:43:33 -0400
changeset 102945 27b3a3e33f9246961a38378d078290c6d1fb928a
parent 98484 bf5a2135b072d34f28e5725b5bde3ca4ee44628a
child 119376 68f8f4b74f63d074b042af1ff4052e4fb1513dda
permissions -rw-r--r--
Bug 784381 - Build bustage for comm-central - SHA1.h - Cannot open include file: 'stdint.h. r=ms2ger.

<?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;

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");
}

function test() {
  ok(true, "test_constants.xul: Starting test");

  // 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();

  // Test 2: Load libxul from chrome thread
  worker = new ChromeWorker("worker_constants.js");
  SimpleTest.waitForExplicitFinish();
  ok(true, "test_constants.xul: 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.xul: wrong message " + JSON.stringify(msg.data));
      return;
    }
  };
  worker.postMessage(0);
  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>