Bug 763848 - Companion test suite. r=khuey

This commit is contained in:
David Rajchenbach-Teller 2012-06-28 21:56:53 -04:00
Родитель d10793c683
Коммит 880883830e
4 изменённых файлов: 134 добавлений и 0 удалений

Просмотреть файл

@ -68,6 +68,10 @@ EXPORTS_mozilla = \
# We fire the nsDOMDeviceAcceleration
LOCAL_INCLUDES += -I$(topsrcdir)/content/events/src
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/config.mk
# we don't want the shared lib, but we want to force the creation of a static lib.

Просмотреть файл

@ -0,0 +1,16 @@
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = dom/system/tests
MODULE = test_domsystem
_CHROME_TEST_FILES = \
test_constants.xul \
worker_constants.js \
$(NULL)
include $(topsrcdir)/config/rules.mk
libs:: $(_CHROME_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)

Просмотреть файл

@ -0,0 +1,56 @@
<?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() {
ok(true, "test_constants.xul: Starting test");
worker = new ChromeWorker("worker_constants.js");
SimpleTest.waitForExplicitFinish();
ok(true, "test_constants.xul: Chrome worker created");
worker.onerror = function(error) {
error.preventDefault();
ok(false, "error "+error);
}
worker.onmessage = function(msg) {
switch (msg.data.kind) {
case "is":
return SimpleTest.is(msg.data.a, msg.data.b, msg.data.description);
case "isnot":
return SimpleTest.isnot(msg.data.a, msg.data.b, msg.data.description);
case "ok":
return SimpleTest.ok(msg.data.condition, msg.data.description);
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>

Просмотреть файл

@ -0,0 +1,58 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function log(text) {
dump("WORKER "+text+"\n");
}
function send(message) {
self.postMessage(message);
}
self.onmessage = function(msg) {
self.onmessage = function(msg) {
log("ignored message "+JSON.stringify(msg.data));
};
try {
test_xul();
} catch (x) {
log("Catching error: " + x);
log("Stack: " + x.stack);
log("Source: " + x.toSource());
ok(false, x.toString() + "\n" + x.stack);
}
finish();
};
function finish() {
send({kind: "finish"});
}
function ok(condition, description) {
send({kind: "ok", condition: condition, description:description});
}
function is(a, b, description) {
send({kind: "is", a: a, b:b, description:description});
}
function isnot(a, b, description) {
send({kind: "isnot", a: a, b:b, description:description});
}
// Test that OS.Constants.Sys.libxulpath lets us open libxul
function test_xul() {
let success;
let lib;
isnot(null, OS.Constants.Sys.libxulpath, "libxulpath is defined");
try {
lib = ctypes.open(OS.Constants.Sys.libxulpath);
lib.declare("DumpJSStack", ctypes.default_abi, ctypes.void_t);
success = true;
} catch (x) {
success = false;
log("Could not open libxul " + x);
}
if (lib) {
lib.close();
}
ok(success, "test_xul: opened libxul successfully");
}