diff --git a/tools/test-harness/xpcshell-simple/README b/tools/test-harness/xpcshell-simple/README index 87129cf408e..a359b3c8d58 100644 --- a/tools/test-harness/xpcshell-simple/README +++ b/tools/test-harness/xpcshell-simple/README @@ -2,5 +2,6 @@ Simple xpcshell-based test harness converted from netwerk/test/unit -current project page at http://wiki.mozilla.org/SoftwareTesting:Tools:Simple_xpcshell_test_harness +Some documentation at http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests +See also http://wiki.mozilla.org/SoftwareTesting:Tools:Simple_xpcshell_test_harness diff --git a/tools/test-harness/xpcshell-simple/example/Makefile.in b/tools/test-harness/xpcshell-simple/example/Makefile.in index 58f756dde62..e77fa45e061 100644 --- a/tools/test-harness/xpcshell-simple/example/Makefile.in +++ b/tools/test-harness/xpcshell-simple/example/Makefile.in @@ -36,7 +36,7 @@ # # ***** END LICENSE BLOCK ***** -DEPTH = ../.. +DEPTH = ../../../.. topsrcdir = @top_srcdir@ srcdir = @srcdir@ VPATH = @srcdir@ diff --git a/tools/test-harness/xpcshell-simple/head.js b/tools/test-harness/xpcshell-simple/head.js index a1e297c1a05..a47988981b4 100644 --- a/tools/test-harness/xpcshell-simple/head.js +++ b/tools/test-harness/xpcshell-simple/head.js @@ -37,7 +37,10 @@ * * ***** END LICENSE BLOCK ***** */ -// This file contains common code that is loaded with each test file. +/* This file contains common code that is loaded with each test file. + * See http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests + * for more informaton + */ var _quit = false; var _fail = false; @@ -59,13 +62,7 @@ _TimerCallback.prototype = { } }; -function do_timeout(delay, expr) { - var timer = Components.classes["@mozilla.org/timer;1"] - .createInstance(Components.interfaces.nsITimer); - timer.initWithCallback(new _TimerCallback(expr), delay, timer.TYPE_ONE_SHOT); -} - -function do_main() { +function _do_main() { if (_quit) return; @@ -80,15 +77,23 @@ function do_main() { thr.processNextEvent(true); } -function do_quit() { +function _do_quit() { dump("*** exiting\n"); _quit = true; } +/************** Functions to be used from the tests **************/ + +function do_timeout(delay, expr) { + var timer = Components.classes["@mozilla.org/timer;1"] + .createInstance(Components.interfaces.nsITimer); + timer.initWithCallback(new _TimerCallback(expr), delay, timer.TYPE_ONE_SHOT); +} + function do_throw(text) { _fail = true; - do_quit(); + _do_quit(); dump("*** CHECK FAILED: " + text + "\n"); var frame = Components.stack; while (frame != null) { @@ -98,18 +103,18 @@ function do_throw(text) { throw Components.results.NS_ERROR_ABORT; } -function do_check_neq(_left, _right) { - if (_left == _right) - do_throw(_left + " != " + _right); +function do_check_neq(left, right) { + if (left == right) + do_throw(left + " != " + right); } -function do_check_eq(_left, _right) { - if (_left != _right) - do_throw(_left + " == " + _right); +function do_check_eq(left, right) { + if (left != right) + do_throw(left + " == " + right); } -function do_check_true(_condition) { - do_check_eq(_condition, true); +function do_check_true(condition) { + do_check_eq(condition, true); } function do_test_pending() { @@ -120,5 +125,5 @@ function do_test_pending() { function do_test_finished() { dump("*** test finished\n"); if (--_tests_pending == 0) - do_quit(); + _do_quit(); } diff --git a/tools/test-harness/xpcshell-simple/tail.js b/tools/test-harness/xpcshell-simple/tail.js index 8a2410f7387..c8046429532 100644 --- a/tools/test-harness/xpcshell-simple/tail.js +++ b/tools/test-harness/xpcshell-simple/tail.js @@ -40,7 +40,7 @@ try { do_test_pending(); run_test(); do_test_finished(); - do_main(); + _do_main(); } catch (e) { _fail = true; dump(e + "\n");