2011-05-10 11:04:15 -07:00
|
|
|
/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2007-03-22 10:30:00 -07:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-17 07:22:55 -07:00
|
|
|
/*
|
|
|
|
* This file contains common code that is loaded before each test file(s).
|
2007-03-22 10:30:00 -07:00
|
|
|
* See http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests
|
2009-03-17 07:22:55 -07:00
|
|
|
* for more information.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
var _quit = false;
|
2009-06-04 15:05:22 -07:00
|
|
|
var _passed = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
var _tests_pending = 0;
|
2009-06-04 15:05:22 -07:00
|
|
|
var _passedChecks = 0, _falsePassedChecks = 0;
|
2011-02-20 16:54:14 -08:00
|
|
|
var _todoChecks = 0;
|
2009-07-10 16:42:59 -07:00
|
|
|
var _cleanupFunctions = [];
|
2010-08-13 13:28:14 -07:00
|
|
|
var _pendingTimers = [];
|
2012-12-11 15:12:59 -08:00
|
|
|
var _profileInitialized = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
let _log = function (action, params) {
|
|
|
|
if (typeof _XPCSHELL_PROCESS != "undefined") {
|
|
|
|
params.process = _XPCSHELL_PROCESS;
|
|
|
|
}
|
|
|
|
params.action = action;
|
|
|
|
params._time = Date.now();
|
|
|
|
dump("\n" + JSON.stringify(params) + "\n");
|
|
|
|
}
|
|
|
|
|
2009-11-11 23:01:04 -08:00
|
|
|
function _dump(str) {
|
2011-05-10 11:04:15 -07:00
|
|
|
let start = /^TEST-/.test(str) ? "\n" : "";
|
2009-11-11 23:01:04 -08:00
|
|
|
if (typeof _XPCSHELL_PROCESS == "undefined") {
|
2011-05-10 11:04:15 -07:00
|
|
|
dump(start + str);
|
2009-11-11 23:01:04 -08:00
|
|
|
} else {
|
2011-05-10 11:04:15 -07:00
|
|
|
dump(start + _XPCSHELL_PROCESS + ": " + str);
|
2009-11-11 23:01:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-12 21:52:00 -08:00
|
|
|
// Disable automatic network detection, so tests work correctly when
|
|
|
|
// not connected to a network.
|
|
|
|
let (ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService2)) {
|
|
|
|
ios.manageOfflineStatus = false;
|
|
|
|
ios.offline = false;
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:12:02 -08:00
|
|
|
// Determine if we're running on parent or child
|
|
|
|
let runningInParent = true;
|
2010-12-10 17:17:25 -08:00
|
|
|
try {
|
2012-12-07 14:12:02 -08:00
|
|
|
runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
|
|
|
|
getService(Components.interfaces.nsIXULRuntime).processType
|
|
|
|
== Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
2013-06-26 06:56:11 -07:00
|
|
|
// Only if building of places is enabled.
|
|
|
|
if (runningInParent &&
|
|
|
|
"mozIAsyncHistory" in Components.interfaces) {
|
|
|
|
// Ensure places history is enabled for xpcshell-tests as some non-FF
|
|
|
|
// apps disable it.
|
|
|
|
let (prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch)) {
|
|
|
|
prefs.setBoolPref("places.history.enabled", true);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2012-12-07 14:12:02 -08:00
|
|
|
try {
|
|
|
|
if (runningInParent) {
|
|
|
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
// disable necko IPC security checks for xpcshell, as they lack the
|
|
|
|
// docshells needed to pass them
|
|
|
|
prefs.setBoolPref("network.disable.ipc.security", true);
|
|
|
|
|
|
|
|
// Disable IPv6 lookups for 'localhost' on windows.
|
|
|
|
if ("@mozilla.org/windows-registry-key;1" in Components.classes) {
|
|
|
|
prefs.setCharPref("network.dns.ipv4OnlyDomains", "localhost");
|
2010-12-10 17:17:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
2013-08-15 11:48:12 -07:00
|
|
|
// Configure crash reporting, if possible
|
|
|
|
// We rely on the Python harness to set MOZ_CRASHREPORTER,
|
|
|
|
// MOZ_CRASHREPORTER_NO_REPORT, and handle checking for minidumps.
|
2010-08-12 01:55:28 -07:00
|
|
|
// Note that if we're in a child process, we don't want to init the
|
|
|
|
// crashreporter component.
|
2013-08-15 11:48:12 -07:00
|
|
|
try {
|
2012-12-07 14:12:02 -08:00
|
|
|
if (runningInParent &&
|
2010-08-12 01:55:28 -07:00
|
|
|
"@mozilla.org/toolkit/crash-reporter;1" in Components.classes) {
|
|
|
|
let (crashReporter =
|
|
|
|
Components.classes["@mozilla.org/toolkit/crash-reporter;1"]
|
|
|
|
.getService(Components.interfaces.nsICrashReporter)) {
|
2013-07-10 14:10:04 -07:00
|
|
|
crashReporter.minidumpPath = do_get_tempdir();
|
2010-07-01 13:03:42 -07:00
|
|
|
}
|
2009-05-11 12:54:39 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-12 01:55:28 -07:00
|
|
|
catch (e) { }
|
2009-05-11 12:54:39 -07:00
|
|
|
|
2010-08-13 13:28:14 -07:00
|
|
|
/**
|
|
|
|
* Date.now() is not necessarily monotonically increasing (insert sob story
|
|
|
|
* about times not being the right tool to use for measuring intervals of time,
|
|
|
|
* robarnold can tell all), so be wary of error by erring by at least
|
|
|
|
* _timerFuzz ms.
|
|
|
|
*/
|
|
|
|
const _timerFuzz = 15;
|
|
|
|
|
|
|
|
function _Timer(func, delay) {
|
|
|
|
delay = Number(delay);
|
|
|
|
if (delay < 0)
|
|
|
|
do_throw("do_timeout() delay must be nonnegative");
|
2009-06-13 06:11:00 -07:00
|
|
|
|
2009-12-28 09:31:00 -08:00
|
|
|
if (typeof func !== "function")
|
2010-08-13 13:28:14 -07:00
|
|
|
do_throw("string callbacks no longer accepted; use a function!");
|
2009-12-28 09:31:00 -08:00
|
|
|
|
|
|
|
this._func = func;
|
2010-08-13 13:28:14 -07:00
|
|
|
this._start = Date.now();
|
|
|
|
this._delay = delay;
|
|
|
|
|
|
|
|
var timer = Components.classes["@mozilla.org/timer;1"]
|
|
|
|
.createInstance(Components.interfaces.nsITimer);
|
|
|
|
timer.initWithCallback(this, delay + _timerFuzz, timer.TYPE_ONE_SHOT);
|
|
|
|
|
2009-11-03 10:39:40 -08:00
|
|
|
// Keep timer alive until it fires
|
2010-08-13 13:28:14 -07:00
|
|
|
_pendingTimers.push(timer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-13 13:28:14 -07:00
|
|
|
_Timer.prototype = {
|
2007-03-22 10:30:00 -07:00
|
|
|
QueryInterface: function(iid) {
|
2013-07-23 10:31:30 -07:00
|
|
|
if (iid.equals(Components.interfaces.nsITimerCallback) ||
|
|
|
|
iid.equals(Components.interfaces.nsISupports))
|
2007-03-22 10:30:00 -07:00
|
|
|
return this;
|
2009-06-13 06:11:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
2009-06-13 06:11:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
notify: function(timer) {
|
2010-08-13 13:28:14 -07:00
|
|
|
_pendingTimers.splice(_pendingTimers.indexOf(timer), 1);
|
|
|
|
|
|
|
|
// The current nsITimer implementation can undershoot, but even if it
|
|
|
|
// couldn't, paranoia is probably a virtue here given the potential for
|
|
|
|
// random orange on tinderboxen.
|
|
|
|
var end = Date.now();
|
|
|
|
var elapsed = end - this._start;
|
|
|
|
if (elapsed >= this._delay) {
|
|
|
|
try {
|
|
|
|
this._func.call(null);
|
|
|
|
} catch (e) {
|
2010-08-13 23:03:36 -07:00
|
|
|
do_throw("exception thrown from do_timeout callback: " + e);
|
2010-08-13 13:28:14 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Timer undershot, retry with a little overshoot to try to avoid more
|
|
|
|
// undershoots.
|
|
|
|
var newDelay = this._delay - elapsed;
|
|
|
|
do_timeout(newDelay, this._func);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function _do_main() {
|
|
|
|
if (_quit)
|
|
|
|
return;
|
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_info",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | running event loop\n"});
|
2009-06-04 15:05:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var thr = Components.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService().currentThread;
|
|
|
|
|
|
|
|
while (!_quit)
|
|
|
|
thr.processNextEvent(true);
|
|
|
|
|
|
|
|
while (thr.hasPendingEvents())
|
|
|
|
thr.processNextEvent(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _do_quit() {
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_info",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | exiting test\n"});
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
_quit = true;
|
|
|
|
}
|
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
function _format_exception_stack(stack) {
|
2013-09-02 08:58:37 -07:00
|
|
|
// frame is of the form "fname@file:line"
|
|
|
|
let frame_regexp = new RegExp("(.*)@(.*):(\\d*)", "g");
|
2013-07-22 19:44:25 -07:00
|
|
|
return stack.split("\n").reduce(function(stack_msg, frame) {
|
|
|
|
if (frame) {
|
|
|
|
let parts = frame_regexp.exec(frame);
|
|
|
|
if (parts) {
|
2013-09-02 08:58:37 -07:00
|
|
|
let [ _, func, file, line ] = parts;
|
|
|
|
return stack_msg + "JS frame :: " + file + " :: " +
|
|
|
|
(func || "anonymous") + " :: line " + line + "\n";
|
2013-07-22 19:44:25 -07:00
|
|
|
}
|
|
|
|
else { /* Could be a -e (command line string) style location. */
|
|
|
|
return stack_msg + "JS frame :: " + frame + "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stack_msg;
|
|
|
|
}, "");
|
2010-03-08 10:26:54 -08:00
|
|
|
}
|
|
|
|
|
2010-10-19 02:18:40 -07:00
|
|
|
/**
|
|
|
|
* Overrides idleService with a mock. Idle is commonly used for maintenance
|
|
|
|
* tasks, thus if a test uses a service that requires the idle service, it will
|
|
|
|
* start handling them.
|
|
|
|
* This behaviour would cause random failures and slowdown tests execution,
|
|
|
|
* for example by running database vacuum or cleanups for each test.
|
|
|
|
*
|
|
|
|
* @note Idle service is overridden by default. If a test requires it, it will
|
|
|
|
* have to call do_get_idle() function at least once before use.
|
|
|
|
*/
|
2013-07-23 10:31:30 -07:00
|
|
|
var _fakeIdleService = {
|
2010-10-19 02:18:40 -07:00
|
|
|
get registrar() {
|
|
|
|
delete this.registrar;
|
|
|
|
return this.registrar =
|
|
|
|
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
},
|
|
|
|
contractID: "@mozilla.org/widget/idleservice;1",
|
|
|
|
get CID() this.registrar.contractIDToCID(this.contractID),
|
|
|
|
|
|
|
|
activate: function FIS_activate()
|
|
|
|
{
|
|
|
|
if (!this.originalFactory) {
|
|
|
|
// Save original factory.
|
|
|
|
this.originalFactory =
|
|
|
|
Components.manager.getClassObject(Components.classes[this.contractID],
|
|
|
|
Components.interfaces.nsIFactory);
|
|
|
|
// Unregister original factory.
|
|
|
|
this.registrar.unregisterFactory(this.CID, this.originalFactory);
|
|
|
|
// Replace with the mock.
|
|
|
|
this.registrar.registerFactory(this.CID, "Fake Idle Service",
|
|
|
|
this.contractID, this.factory
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate: function FIS_deactivate()
|
|
|
|
{
|
|
|
|
if (this.originalFactory) {
|
|
|
|
// Unregister the mock.
|
|
|
|
this.registrar.unregisterFactory(this.CID, this.factory);
|
|
|
|
// Restore original factory.
|
|
|
|
this.registrar.registerFactory(this.CID, "Idle Service",
|
|
|
|
this.contractID, this.originalFactory);
|
|
|
|
delete this.originalFactory;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
factory: {
|
|
|
|
// nsIFactory
|
|
|
|
createInstance: function (aOuter, aIID)
|
|
|
|
{
|
|
|
|
if (aOuter) {
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
|
|
|
return _fakeIdleService.QueryInterface(aIID);
|
|
|
|
},
|
|
|
|
lockFactory: function (aLock) {
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
if (aIID.equals(Components.interfaces.nsIFactory) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// nsIIdleService
|
|
|
|
get idleTime() 0,
|
|
|
|
addIdleObserver: function () {},
|
|
|
|
removeIdleObserver: function () {},
|
|
|
|
|
|
|
|
QueryInterface: function(aIID) {
|
|
|
|
// Useful for testing purposes, see test_get_idle.js.
|
|
|
|
if (aIID.equals(Components.interfaces.nsIFactory)) {
|
|
|
|
return this.factory;
|
|
|
|
}
|
|
|
|
if (aIID.equals(Components.interfaces.nsIIdleService) ||
|
|
|
|
aIID.equals(Components.interfaces.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores the idle service factory if needed and returns the service's handle.
|
|
|
|
* @return A handle to the idle service.
|
|
|
|
*/
|
|
|
|
function do_get_idle() {
|
|
|
|
_fakeIdleService.deactivate();
|
|
|
|
return Components.classes[_fakeIdleService.contractID]
|
|
|
|
.getService(Components.interfaces.nsIIdleService);
|
|
|
|
}
|
|
|
|
|
2012-05-15 09:53:28 -07:00
|
|
|
// Map resource://test/ to current working directory and
|
|
|
|
// resource://testing-common/ to the shared test modules directory.
|
|
|
|
function _register_protocol_handlers() {
|
2010-02-23 05:11:37 -08:00
|
|
|
let (ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService)) {
|
|
|
|
let protocolHandler =
|
|
|
|
ios.getProtocolHandler("resource")
|
|
|
|
.QueryInterface(Components.interfaces.nsIResProtocolHandler);
|
|
|
|
let curDirURI = ios.newFileURI(do_get_cwd());
|
|
|
|
protocolHandler.setSubstitution("test", curDirURI);
|
2012-05-10 10:10:14 -07:00
|
|
|
|
|
|
|
if (this._TESTING_MODULES_DIR) {
|
|
|
|
let modulesFile = Components.classes["@mozilla.org/file/local;1"].
|
|
|
|
createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
modulesFile.initWithPath(_TESTING_MODULES_DIR);
|
|
|
|
|
2012-06-29 13:27:11 -07:00
|
|
|
if (!modulesFile.exists()) {
|
|
|
|
throw new Error("Specified modules directory does not exist: " +
|
|
|
|
_TESTING_MODULES_DIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!modulesFile.isDirectory()) {
|
|
|
|
throw new Error("Specified modules directory is not a directory: " +
|
|
|
|
_TESTING_MODULES_DIR);
|
|
|
|
}
|
|
|
|
|
2012-05-10 10:10:14 -07:00
|
|
|
let modulesURI = ios.newFileURI(modulesFile);
|
2012-06-29 13:27:11 -07:00
|
|
|
|
2012-05-10 10:19:16 -07:00
|
|
|
protocolHandler.setSubstitution("testing-common", modulesURI);
|
2012-05-10 10:10:14 -07:00
|
|
|
}
|
2010-02-23 05:11:37 -08:00
|
|
|
}
|
2012-05-15 09:53:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function _execute_test() {
|
|
|
|
_register_protocol_handlers();
|
2010-02-23 05:11:37 -08:00
|
|
|
|
2010-10-19 02:18:40 -07:00
|
|
|
// Override idle service by default.
|
|
|
|
// Call do_get_idle() to restore the factory and get the service.
|
|
|
|
_fakeIdleService.activate();
|
|
|
|
|
2009-06-13 06:11:00 -07:00
|
|
|
// _HEAD_FILES is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
_load_files(_HEAD_FILES);
|
|
|
|
// _TEST_FILE is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
_load_files(_TEST_FILE);
|
|
|
|
|
2009-03-17 07:22:55 -07:00
|
|
|
try {
|
2013-05-03 09:08:30 -07:00
|
|
|
do_test_pending("MAIN run_test");
|
2009-03-17 07:22:55 -07:00
|
|
|
run_test();
|
2013-05-03 09:08:30 -07:00
|
|
|
do_test_finished("MAIN run_test");
|
2009-03-17 07:22:55 -07:00
|
|
|
_do_main();
|
|
|
|
} catch (e) {
|
2009-06-04 15:05:22 -07:00
|
|
|
_passed = false;
|
2010-03-08 10:26:54 -08:00
|
|
|
// do_check failures are already logged and set _quit to true and throw
|
|
|
|
// NS_ERROR_ABORT. If both of those are true it is likely this exception
|
|
|
|
// has already been logged so there is no need to log it again. It's
|
|
|
|
// possible that this will mask an NS_ERROR_ABORT that happens after a
|
|
|
|
// do_check failure though.
|
|
|
|
if (!_quit || e != Components.results.NS_ERROR_ABORT) {
|
2013-07-22 19:44:25 -07:00
|
|
|
let msgObject = {};
|
2012-03-03 19:19:04 -08:00
|
|
|
if (e.fileName) {
|
2013-07-22 19:44:25 -07:00
|
|
|
msgObject.source_file = e.fileName;
|
2012-03-03 19:19:04 -08:00
|
|
|
if (e.lineNumber) {
|
2013-07-22 19:44:25 -07:00
|
|
|
msgObject.line_number = e.lineNumber;
|
2011-12-28 08:57:28 -08:00
|
|
|
}
|
|
|
|
} else {
|
2013-07-22 19:44:25 -07:00
|
|
|
msgObject.source_file = "xpcshell/head.js";
|
2011-12-28 08:57:28 -08:00
|
|
|
}
|
2013-07-22 19:44:25 -07:00
|
|
|
msgObject.diagnostic = _exception_message(e);
|
2010-03-08 10:26:54 -08:00
|
|
|
if (e.stack) {
|
2013-07-22 19:44:25 -07:00
|
|
|
msgObject.diagnostic += " - See following stack:\n";
|
|
|
|
msgObject.stack = _format_exception_stack(e.stack);
|
2010-03-08 10:26:54 -08:00
|
|
|
}
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_unexpected_fail", msgObject);
|
2010-03-08 10:26:54 -08:00
|
|
|
}
|
2009-03-17 07:22:55 -07:00
|
|
|
}
|
|
|
|
|
2009-06-13 06:11:00 -07:00
|
|
|
// _TAIL_FILES is dynamically defined by <runxpcshelltests.py>.
|
|
|
|
_load_files(_TAIL_FILES);
|
|
|
|
|
2009-07-10 16:42:59 -07:00
|
|
|
// Execute all of our cleanup functions.
|
|
|
|
var func;
|
|
|
|
while ((func = _cleanupFunctions.pop()))
|
|
|
|
func();
|
|
|
|
|
2010-10-19 02:18:40 -07:00
|
|
|
// Restore idle service to avoid leaks.
|
|
|
|
_fakeIdleService.deactivate();
|
|
|
|
|
2009-06-04 15:05:22 -07:00
|
|
|
if (!_passed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var truePassedChecks = _passedChecks - _falsePassedChecks;
|
2009-11-11 23:01:04 -08:00
|
|
|
if (truePassedChecks > 0) {
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_pass",
|
|
|
|
{_message: "TEST-PASS | (xpcshell/head.js) | " + truePassedChecks + " (+ " +
|
|
|
|
_falsePassedChecks + ") check(s) passed\n",
|
|
|
|
source_file: _TEST_FILE,
|
|
|
|
passed_checks: truePassedChecks});
|
|
|
|
_log("test_info",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | " + _todoChecks +
|
|
|
|
" check(s) todo\n",
|
|
|
|
source_file: _TEST_FILE,
|
|
|
|
todo_checks: _todoChecks});
|
2009-11-11 23:01:04 -08:00
|
|
|
} else {
|
2009-06-04 15:05:22 -07:00
|
|
|
// ToDo: switch to TEST-UNEXPECTED-FAIL when all tests have been updated. (Bug 496443)
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_info",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | No (+ " + _falsePassedChecks +
|
|
|
|
") checks actually run\n",
|
|
|
|
source_file: _TEST_FILE});
|
2009-11-11 23:01:04 -08:00
|
|
|
}
|
2009-03-17 07:22:55 -07:00
|
|
|
}
|
|
|
|
|
2009-06-13 06:11:00 -07:00
|
|
|
/**
|
|
|
|
* Loads files.
|
|
|
|
*
|
|
|
|
* @param aFiles Array of files to load.
|
|
|
|
*/
|
|
|
|
function _load_files(aFiles) {
|
|
|
|
function loadTailFile(element, index, array) {
|
2013-07-22 19:44:25 -07:00
|
|
|
try {
|
|
|
|
load(element);
|
|
|
|
} catch (e if e instanceof SyntaxError) {
|
|
|
|
_log("javascript_error",
|
|
|
|
{_message: "TEST-UNEXPECTED-FAIL | (xpcshell/head.js) | Source file " + element + " contains SyntaxError",
|
|
|
|
diagnostic: _exception_message(e),
|
|
|
|
source_file: element,
|
|
|
|
stack: _format_exception_stack(e.stack)});
|
|
|
|
}
|
2009-06-13 06:11:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
aFiles.forEach(loadTailFile);
|
|
|
|
}
|
|
|
|
|
2013-06-07 09:43:48 -07:00
|
|
|
function _wrap_with_quotes_if_necessary(val) {
|
|
|
|
return typeof val == "string" ? '"' + val + '"' : val;
|
|
|
|
}
|
2009-03-17 07:22:55 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/************** Functions to be used from the tests **************/
|
|
|
|
|
2011-09-06 21:26:20 -07:00
|
|
|
/**
|
|
|
|
* Prints a message to the output log.
|
|
|
|
*/
|
|
|
|
function do_print(msg) {
|
|
|
|
var caller_stack = Components.stack.caller;
|
2013-06-07 09:43:48 -07:00
|
|
|
msg = _wrap_with_quotes_if_necessary(msg);
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_info",
|
|
|
|
{source_file: caller_stack.filename,
|
|
|
|
diagnostic: msg});
|
|
|
|
|
2011-09-06 21:26:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 13:28:14 -07:00
|
|
|
/**
|
|
|
|
* Calls the given function at least the specified number of milliseconds later.
|
|
|
|
* The callback will not undershoot the given time, but it might overshoot --
|
|
|
|
* don't expect precision!
|
|
|
|
*
|
|
|
|
* @param delay : uint
|
|
|
|
* the number of milliseconds to delay
|
|
|
|
* @param callback : function() : void
|
|
|
|
* the function to call
|
|
|
|
*/
|
2009-12-28 09:31:00 -08:00
|
|
|
function do_timeout(delay, func) {
|
2010-08-13 13:28:14 -07:00
|
|
|
new _Timer(func, Number(delay));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:08:30 -07:00
|
|
|
function do_execute_soon(callback, aName) {
|
|
|
|
let funcName = (aName ? aName : callback.name);
|
|
|
|
do_test_pending(funcName);
|
2009-08-06 07:25:16 -07:00
|
|
|
var tm = Components.classes["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIThreadManager);
|
|
|
|
|
|
|
|
tm.mainThread.dispatch({
|
|
|
|
run: function() {
|
2010-03-08 10:26:54 -08:00
|
|
|
try {
|
|
|
|
callback();
|
|
|
|
} catch (e) {
|
|
|
|
// do_check failures are already logged and set _quit to true and throw
|
|
|
|
// NS_ERROR_ABORT. If both of those are true it is likely this exception
|
|
|
|
// has already been logged so there is no need to log it again. It's
|
|
|
|
// possible that this will mask an NS_ERROR_ABORT that happens after a
|
|
|
|
// do_check failure though.
|
|
|
|
if (!_quit || e != Components.results.NS_ERROR_ABORT) {
|
|
|
|
if (e.stack) {
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("javascript_error",
|
|
|
|
{source_file: "xpcshell/head.js",
|
|
|
|
diagnostic: _exception_message(e) + " - See following stack:",
|
|
|
|
stack: _format_exception_stack(e.stack)});
|
|
|
|
} else {
|
|
|
|
_log("javascript_error",
|
|
|
|
{source_file: "xpcshell/head.js",
|
|
|
|
diagnostic: _exception_message(e)});
|
2010-03-08 10:26:54 -08:00
|
|
|
}
|
|
|
|
_do_quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
2013-05-03 09:08:30 -07:00
|
|
|
do_test_finished(funcName);
|
2010-03-08 10:26:54 -08:00
|
|
|
}
|
2009-08-06 07:25:16 -07:00
|
|
|
}
|
|
|
|
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2013-05-07 19:37:49 -07:00
|
|
|
/**
|
|
|
|
* Shows an error message and the current stack and aborts the test.
|
|
|
|
*
|
|
|
|
* @param error A message string or an Error object.
|
|
|
|
* @param stack null or nsIStackFrame object or a string containing
|
|
|
|
* \n separated stack lines (as in Error().stack).
|
|
|
|
*/
|
|
|
|
function do_throw(error, stack) {
|
|
|
|
let filename = "";
|
2013-07-13 09:37:13 -07:00
|
|
|
// If we didn't get passed a stack, maybe the error has one
|
|
|
|
// otherwise get it from our call context
|
|
|
|
stack = stack || error.stack || Components.stack.caller;
|
2009-06-04 15:05:22 -07:00
|
|
|
|
2013-05-07 19:37:49 -07:00
|
|
|
if (stack instanceof Components.interfaces.nsIStackFrame)
|
|
|
|
filename = stack.filename;
|
2013-07-13 09:37:13 -07:00
|
|
|
else if (error.fileName)
|
|
|
|
filename = error.fileName;
|
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
_log_message_with_stack("test_unexpected_fail",
|
|
|
|
error, stack, filename);
|
2013-05-07 19:37:49 -07:00
|
|
|
|
2013-07-13 09:37:13 -07:00
|
|
|
_passed = false;
|
|
|
|
_do_quit();
|
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
|
|
|
}
|
2013-05-07 19:37:49 -07:00
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
function _format_stack(stack) {
|
2013-05-07 19:37:49 -07:00
|
|
|
if (stack instanceof Components.interfaces.nsIStackFrame) {
|
2013-07-22 19:44:25 -07:00
|
|
|
let stack_msg = "";
|
2013-05-07 19:37:49 -07:00
|
|
|
let frame = stack;
|
|
|
|
while (frame != null) {
|
2013-07-22 19:44:25 -07:00
|
|
|
stack_msg += frame + "\n";
|
2013-05-07 19:37:49 -07:00
|
|
|
frame = frame.caller;
|
|
|
|
}
|
2013-07-22 19:44:25 -07:00
|
|
|
return stack_msg;
|
2013-07-13 09:37:13 -07:00
|
|
|
}
|
2013-07-22 19:44:25 -07:00
|
|
|
return "" + stack;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-02-20 16:54:14 -08:00
|
|
|
function do_throw_todo(text, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_passed = false;
|
2013-07-22 19:44:25 -07:00
|
|
|
_log_message_with_stack("test_unexpected_pass",
|
|
|
|
text, stack, stack.filename);
|
2011-02-20 16:54:14 -08:00
|
|
|
_do_quit();
|
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
2013-07-13 09:37:13 -07:00
|
|
|
// Make a nice display string from an object that behaves
|
|
|
|
// like Error
|
|
|
|
function _exception_message(ex) {
|
|
|
|
let message = "";
|
|
|
|
if (ex.name) {
|
|
|
|
message = ex.name + ": ";
|
|
|
|
}
|
|
|
|
if (ex.message) {
|
|
|
|
message += ex.message;
|
|
|
|
}
|
|
|
|
if (ex.fileName) {
|
|
|
|
message += (" at " + ex.fileName);
|
|
|
|
if (ex.lineNumber) {
|
|
|
|
message += (":" + ex.lineNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (message !== "") {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
// Force ex to be stringified
|
|
|
|
return "" + ex;
|
|
|
|
}
|
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
function _log_message_with_stack(action, ex, stack, filename, text) {
|
2013-07-13 09:37:13 -07:00
|
|
|
if (stack) {
|
2013-07-22 19:44:25 -07:00
|
|
|
_log(action,
|
|
|
|
{diagnostic: (text ? text : "") +
|
|
|
|
_exception_message(ex) +
|
|
|
|
" - See following stack:",
|
|
|
|
source_file: filename,
|
|
|
|
stack: _format_stack(stack)});
|
|
|
|
} else {
|
|
|
|
_log(action,
|
|
|
|
{diagnostic: (text ? text : "") +
|
|
|
|
_exception_message(ex),
|
|
|
|
source_file: filename});
|
2013-07-13 09:37:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-05 12:06:00 -08:00
|
|
|
function do_report_unexpected_exception(ex, text) {
|
|
|
|
var caller_stack = Components.stack.caller;
|
|
|
|
text = text ? text + " - " : "";
|
|
|
|
|
|
|
|
_passed = false;
|
2013-07-22 19:44:25 -07:00
|
|
|
_log_message_with_stack("test_unexpected_fail", ex, ex.stack,
|
|
|
|
caller_stack.filename, text + "Unexpected exception ");
|
2009-11-05 12:06:00 -08:00
|
|
|
_do_quit();
|
|
|
|
throw Components.results.NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
function do_note_exception(ex, text) {
|
|
|
|
var caller_stack = Components.stack.caller;
|
|
|
|
text = text ? text + " - " : "";
|
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
_log_message_with_stack("test_info", ex, ex.stack,
|
|
|
|
caller_stack.filename, text + "Swallowed exception ");
|
2009-11-05 12:06:00 -08:00
|
|
|
}
|
|
|
|
|
2011-02-20 16:54:14 -08:00
|
|
|
function _do_check_neq(left, right, stack, todo) {
|
2008-07-15 22:45:42 -07:00
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
2009-06-04 15:05:22 -07:00
|
|
|
|
2013-06-07 09:43:48 -07:00
|
|
|
var text = _wrap_with_quotes_if_necessary(left) + " != " +
|
|
|
|
_wrap_with_quotes_if_necessary(right);
|
2013-06-07 09:44:00 -07:00
|
|
|
do_report_result(left != right, text, stack, todo);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-02-20 16:54:14 -08:00
|
|
|
function do_check_neq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_neq(left, right, stack, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_neq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_neq(left, right, stack, true);
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:15:58 -08:00
|
|
|
function do_report_result(passed, text, stack, todo) {
|
|
|
|
if (passed) {
|
|
|
|
if (todo) {
|
|
|
|
do_throw_todo(text, stack);
|
2011-02-20 16:54:14 -08:00
|
|
|
} else {
|
|
|
|
++_passedChecks;
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_pass",
|
|
|
|
{source_file: stack.filename,
|
|
|
|
test_name: stack.name,
|
|
|
|
line_number: stack.lineNumber,
|
|
|
|
diagnostic: "[" + stack.name + " : " + stack.lineNumber + "] " +
|
|
|
|
text + "\n"});
|
2013-01-14 16:15:58 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (todo) {
|
|
|
|
++_todoChecks;
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_known_fail",
|
|
|
|
{source_file: stack.filename,
|
|
|
|
test_name: stack.name,
|
|
|
|
line_number: stack.lineNumber,
|
|
|
|
diagnostic: "[" + stack.name + " : " + stack.lineNumber + "] " +
|
|
|
|
text + "\n"});
|
2011-02-20 16:54:14 -08:00
|
|
|
} else {
|
2013-01-14 16:15:58 -08:00
|
|
|
do_throw(text, stack);
|
2011-02-20 16:54:14 -08:00
|
|
|
}
|
2009-06-04 15:05:22 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-01-14 16:15:58 -08:00
|
|
|
function _do_check_eq(left, right, stack, todo) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
2013-06-07 09:43:48 -07:00
|
|
|
var text = _wrap_with_quotes_if_necessary(left) + " == " +
|
|
|
|
_wrap_with_quotes_if_necessary(right);
|
2013-01-14 16:15:58 -08:00
|
|
|
do_report_result(left == right, text, stack, todo);
|
|
|
|
}
|
|
|
|
|
2011-02-20 16:54:14 -08:00
|
|
|
function do_check_eq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_eq(left, right, stack, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_eq(left, right, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
_do_check_eq(left, right, stack, true);
|
|
|
|
}
|
|
|
|
|
2008-07-15 22:45:42 -07:00
|
|
|
function do_check_true(condition, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
2009-06-04 15:05:22 -07:00
|
|
|
|
2008-07-15 22:45:42 -07:00
|
|
|
do_check_eq(condition, true, stack);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-02-20 16:54:14 -08:00
|
|
|
function todo_check_true(condition, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
todo_check_eq(condition, true, stack);
|
|
|
|
}
|
|
|
|
|
2008-07-15 22:45:42 -07:00
|
|
|
function do_check_false(condition, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
2009-06-04 15:05:22 -07:00
|
|
|
|
2008-07-15 22:45:42 -07:00
|
|
|
do_check_eq(condition, false, stack);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-02-20 16:54:14 -08:00
|
|
|
function todo_check_false(condition, stack) {
|
|
|
|
if (!stack)
|
|
|
|
stack = Components.stack.caller;
|
|
|
|
|
|
|
|
todo_check_eq(condition, false, stack);
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:23:31 -07:00
|
|
|
function do_check_null(condition, stack=Components.stack.caller) {
|
|
|
|
do_check_eq(condition, null, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_null(condition, stack=Components.stack.caller) {
|
|
|
|
todo_check_eq(condition, null, stack);
|
|
|
|
}
|
|
|
|
|
2013-01-14 16:15:58 -08:00
|
|
|
/**
|
|
|
|
* Check that |value| matches |pattern|.
|
|
|
|
*
|
|
|
|
* A |value| matches a pattern |pattern| if any one of the following is true:
|
|
|
|
*
|
|
|
|
* - |value| and |pattern| are both objects; |pattern|'s enumerable
|
|
|
|
* properties' values are valid patterns; and for each enumerable
|
|
|
|
* property |p| of |pattern|, plus 'length' if present at all, |value|
|
|
|
|
* has a property |p| whose value matches |pattern.p|. Note that if |j|
|
|
|
|
* has other properties not present in |p|, |j| may still match |p|.
|
|
|
|
*
|
|
|
|
* - |value| and |pattern| are equal string, numeric, or boolean literals
|
|
|
|
*
|
|
|
|
* - |pattern| is |undefined| (this is a wildcard pattern)
|
|
|
|
*
|
|
|
|
* - typeof |pattern| == "function", and |pattern(value)| is true.
|
|
|
|
*
|
|
|
|
* For example:
|
|
|
|
*
|
|
|
|
* do_check_matches({x:1}, {x:1}) // pass
|
|
|
|
* do_check_matches({x:1}, {}) // fail: all pattern props required
|
|
|
|
* do_check_matches({x:1}, {x:2}) // fail: values must match
|
|
|
|
* do_check_matches({x:1}, {x:1, y:2}) // pass: extra props tolerated
|
|
|
|
*
|
|
|
|
* // Property order is irrelevant.
|
|
|
|
* do_check_matches({x:"foo", y:"bar"}, {y:"bar", x:"foo"}) // pass
|
|
|
|
*
|
|
|
|
* do_check_matches({x:undefined}, {x:1}) // pass: 'undefined' is wildcard
|
|
|
|
* do_check_matches({x:undefined}, {x:2})
|
|
|
|
* do_check_matches({x:undefined}, {y:2}) // fail: 'x' must still be there
|
|
|
|
*
|
|
|
|
* // Patterns nest.
|
|
|
|
* do_check_matches({a:1, b:{c:2,d:undefined}}, {a:1, b:{c:2,d:3}})
|
|
|
|
*
|
|
|
|
* // 'length' property counts, even if non-enumerable.
|
|
|
|
* do_check_matches([3,4,5], [3,4,5]) // pass
|
|
|
|
* do_check_matches([3,4,5], [3,5,5]) // fail; value doesn't match
|
|
|
|
* do_check_matches([3,4,5], [3,4,5,6]) // fail; length doesn't match
|
|
|
|
*
|
|
|
|
* // functions in patterns get applied.
|
|
|
|
* do_check_matches({foo:function (v) v.length == 2}, {foo:"hi"}) // pass
|
|
|
|
* do_check_matches({foo:function (v) v.length == 2}, {bar:"hi"}) // fail
|
|
|
|
* do_check_matches({foo:function (v) v.length == 2}, {foo:"hello"}) // fail
|
|
|
|
*
|
|
|
|
* // We don't check constructors, prototypes, or classes. However, if
|
|
|
|
* // pattern has a 'length' property, we require values to match that as
|
|
|
|
* // well, even if 'length' is non-enumerable in the pattern. So arrays
|
|
|
|
* // are useful as patterns.
|
|
|
|
* do_check_matches({0:0, 1:1, length:2}, [0,1]) // pass
|
|
|
|
* do_check_matches({0:1}, [1,2]) // pass
|
|
|
|
* do_check_matches([0], {0:0, length:1}) // pass
|
|
|
|
*
|
|
|
|
* Notes:
|
|
|
|
*
|
|
|
|
* The 'length' hack gives us reasonably intuitive handling of arrays.
|
|
|
|
*
|
|
|
|
* This is not a tight pattern-matcher; it's only good for checking data
|
|
|
|
* from well-behaved sources. For example:
|
|
|
|
* - By default, we don't mind values having extra properties.
|
|
|
|
* - We don't check for proxies or getters.
|
|
|
|
* - We don't check the prototype chain.
|
|
|
|
* However, if you know the values are, say, JSON, which is pretty
|
|
|
|
* well-behaved, and if you want to tolerate additional properties
|
|
|
|
* appearing on the JSON for backward-compatibility, then do_check_matches
|
|
|
|
* is ideal. If you do want to be more careful, you can use function
|
|
|
|
* patterns to implement more stringent checks.
|
|
|
|
*/
|
|
|
|
function do_check_matches(pattern, value, stack=Components.stack.caller, todo=false) {
|
|
|
|
var matcher = pattern_matcher(pattern);
|
|
|
|
var text = "VALUE: " + uneval(value) + "\nPATTERN: " + uneval(pattern) + "\n";
|
|
|
|
var diagnosis = []
|
|
|
|
if (matcher(value, diagnosis)) {
|
|
|
|
do_report_result(true, "value matches pattern:\n" + text, stack, todo);
|
|
|
|
} else {
|
|
|
|
text = ("value doesn't match pattern:\n" +
|
|
|
|
text +
|
|
|
|
"DIAGNOSIS: " +
|
|
|
|
format_pattern_match_failure(diagnosis[0]) + "\n");
|
|
|
|
do_report_result(false, text, stack, todo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function todo_check_matches(pattern, value, stack=Components.stack.caller) {
|
|
|
|
do_check_matches(pattern, value, stack, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a pattern-matching function of one argument, |value|, that
|
|
|
|
// returns true if |value| matches |pattern|.
|
|
|
|
//
|
|
|
|
// If the pattern doesn't match, and the pattern-matching function was
|
|
|
|
// passed its optional |diagnosis| argument, the pattern-matching function
|
|
|
|
// sets |diagnosis|'s '0' property to a JSON-ish description of the portion
|
|
|
|
// of the pattern that didn't match, which can be formatted legibly by
|
|
|
|
// format_pattern_match_failure.
|
|
|
|
function pattern_matcher(pattern) {
|
|
|
|
function explain(diagnosis, reason) {
|
|
|
|
if (diagnosis) {
|
|
|
|
diagnosis[0] = reason;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (typeof pattern == "function") {
|
|
|
|
return pattern;
|
|
|
|
} else if (typeof pattern == "object" && pattern) {
|
|
|
|
var matchers = [[p, pattern_matcher(pattern[p])] for (p in pattern)];
|
|
|
|
// Kludge: include 'length', if not enumerable. (If it is enumerable,
|
|
|
|
// we picked it up in the array comprehension, above.
|
|
|
|
ld = Object.getOwnPropertyDescriptor(pattern, 'length');
|
|
|
|
if (ld && !ld.enumerable) {
|
|
|
|
matchers.push(['length', pattern_matcher(pattern.length)])
|
|
|
|
}
|
|
|
|
return function (value, diagnosis) {
|
|
|
|
if (!(value && typeof value == "object")) {
|
|
|
|
return explain(diagnosis, "value not object");
|
|
|
|
}
|
|
|
|
for (let [p, m] of matchers) {
|
|
|
|
var element_diagnosis = [];
|
|
|
|
if (!(p in value && m(value[p], element_diagnosis))) {
|
|
|
|
return explain(diagnosis, { property:p,
|
|
|
|
diagnosis:element_diagnosis[0] });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
} else if (pattern === undefined) {
|
|
|
|
return function(value) { return true; };
|
|
|
|
} else {
|
|
|
|
return function (value, diagnosis) {
|
|
|
|
if (value !== pattern) {
|
|
|
|
return explain(diagnosis, "pattern " + uneval(pattern) + " not === to value " + uneval(value));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format an explanation for a pattern match failure, as stored in the
|
|
|
|
// second argument to a matching function.
|
|
|
|
function format_pattern_match_failure(diagnosis, indent="") {
|
|
|
|
var a;
|
|
|
|
if (!diagnosis) {
|
|
|
|
a = "Matcher did not explain reason for mismatch.";
|
|
|
|
} else if (typeof diagnosis == "string") {
|
|
|
|
a = diagnosis;
|
|
|
|
} else if (diagnosis.property) {
|
|
|
|
a = "Property " + uneval(diagnosis.property) + " of object didn't match:\n";
|
|
|
|
a += format_pattern_match_failure(diagnosis.diagnosis, indent + " ");
|
|
|
|
}
|
|
|
|
return indent + a;
|
|
|
|
}
|
|
|
|
|
2013-09-06 08:06:22 -07:00
|
|
|
// Check that |func| throws an nsIException that has
|
|
|
|
// |Components.results[resultName]| as the value of its 'result' property.
|
|
|
|
function do_check_throws_nsIException(func, resultName,
|
|
|
|
stack=Components.stack.caller, todo=false)
|
|
|
|
{
|
|
|
|
let expected = Components.results[resultName];
|
|
|
|
if (typeof expected !== 'number') {
|
|
|
|
do_throw("do_check_throws_nsIException requires a Components.results" +
|
|
|
|
" property name, not " + uneval(resultName), stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
let msg = ("do_check_throws_nsIException: func should throw" +
|
|
|
|
" an nsIException whose 'result' is Components.results." +
|
|
|
|
resultName);
|
|
|
|
|
|
|
|
try {
|
|
|
|
func();
|
|
|
|
} catch (ex) {
|
|
|
|
if (!(ex instanceof Components.interfaces.nsIException) ||
|
|
|
|
ex.result !== expected) {
|
|
|
|
do_report_result(false, msg + ", threw " + legible_exception(ex) +
|
|
|
|
" instead", stack, todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_report_result(true, msg, stack, todo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call this here, not in the 'try' clause, so do_report_result's own
|
|
|
|
// throw doesn't get caught by our 'catch' clause.
|
|
|
|
do_report_result(false, msg + ", but returned normally", stack, todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Produce a human-readable form of |exception|. This looks up
|
|
|
|
// Components.results values, tries toString methods, and so on.
|
|
|
|
function legible_exception(exception)
|
|
|
|
{
|
|
|
|
switch (typeof exception) {
|
|
|
|
case 'object':
|
|
|
|
if (exception instanceof Components.interfaces.nsIException) {
|
|
|
|
return "nsIException instance: " + uneval(exception.toString());
|
|
|
|
}
|
|
|
|
return exception.toString();
|
|
|
|
|
|
|
|
case 'number':
|
|
|
|
for (let name in Components.results) {
|
|
|
|
if (exception === Components.results[name]) {
|
|
|
|
return "Components.results." + name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall through.
|
|
|
|
default:
|
|
|
|
return uneval(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-03 09:08:30 -07:00
|
|
|
function do_test_pending(aName) {
|
2009-06-04 15:05:22 -07:00
|
|
|
++_tests_pending;
|
|
|
|
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_pending",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | test" +
|
|
|
|
(aName ? " " + aName : "") +
|
|
|
|
" pending (" + _tests_pending + ")\n"});
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-05-03 09:08:30 -07:00
|
|
|
function do_test_finished(aName) {
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_finish",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | test" +
|
|
|
|
(aName ? " " + aName : "") +
|
|
|
|
" finished (" + _tests_pending + ")\n"});
|
2007-03-22 10:30:00 -07:00
|
|
|
if (--_tests_pending == 0)
|
|
|
|
_do_quit();
|
|
|
|
}
|
|
|
|
|
2009-03-21 08:20:00 -07:00
|
|
|
function do_get_file(path, allowNonexistent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
2009-03-21 08:20:00 -07:00
|
|
|
let lf = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties)
|
|
|
|
.get("CurWorkD", Components.interfaces.nsILocalFile);
|
|
|
|
|
|
|
|
let bits = path.split("/");
|
|
|
|
for (let i = 0; i < bits.length; i++) {
|
|
|
|
if (bits[i]) {
|
|
|
|
if (bits[i] == "..")
|
|
|
|
lf = lf.parent;
|
|
|
|
else
|
|
|
|
lf.append(bits[i]);
|
|
|
|
}
|
2008-07-24 08:33:41 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-06-04 15:05:22 -07:00
|
|
|
if (!allowNonexistent && !lf.exists()) {
|
|
|
|
// Not using do_throw(): caller will continue.
|
|
|
|
_passed = false;
|
|
|
|
var stack = Components.stack.caller;
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_unexpected_fail",
|
|
|
|
{source_file: stack.filename,
|
|
|
|
test_name: stack.name,
|
|
|
|
line_number: stack.lineNumber,
|
|
|
|
diagnostic: "[" + stack.name + " : " + stack.lineNumber + "] " +
|
|
|
|
lf.path + " does not exist\n"});
|
2007-06-07 15:34:06 -07:00
|
|
|
}
|
2009-03-21 08:20:00 -07:00
|
|
|
|
|
|
|
return lf;
|
2007-06-07 15:34:06 -07:00
|
|
|
}
|
2009-06-04 15:05:22 -07:00
|
|
|
catch (ex) {
|
2009-03-21 08:20:00 -07:00
|
|
|
do_throw(ex.toString(), Components.stack.caller);
|
|
|
|
}
|
2009-06-04 15:05:22 -07:00
|
|
|
|
2009-03-21 08:20:00 -07:00
|
|
|
return null;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-03-21 08:20:00 -07:00
|
|
|
// do_get_cwd() isn't exactly self-explanatory, so provide a helper
|
|
|
|
function do_get_cwd() {
|
|
|
|
return do_get_file("");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-05-09 03:48:21 -07:00
|
|
|
|
2010-06-25 07:43:25 -07:00
|
|
|
function do_load_manifest(path) {
|
2007-05-09 03:48:21 -07:00
|
|
|
var lf = do_get_file(path);
|
|
|
|
const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
|
|
|
|
do_check_true(Components.manager instanceof nsIComponentRegistrar);
|
2009-06-04 15:05:22 -07:00
|
|
|
// Previous do_check_true() is not a test check.
|
|
|
|
++_falsePassedChecks;
|
2007-05-09 03:48:21 -07:00
|
|
|
Components.manager.autoRegister(lf);
|
|
|
|
}
|
2007-08-03 16:00:39 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a DOM document.
|
|
|
|
*
|
|
|
|
* @param aPath File path to the document.
|
|
|
|
* @param aType Content type to use in DOMParser.
|
|
|
|
*
|
|
|
|
* @return nsIDOMDocument from the file.
|
|
|
|
*/
|
|
|
|
function do_parse_document(aPath, aType) {
|
|
|
|
switch (aType) {
|
|
|
|
case "application/xhtml+xml":
|
|
|
|
case "application/xml":
|
|
|
|
case "text/xml":
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2009-06-04 15:05:22 -07:00
|
|
|
do_throw("type: expected application/xhtml+xml, application/xml or text/xml," +
|
|
|
|
" got '" + aType + "'",
|
|
|
|
Components.stack.caller);
|
2007-08-03 16:00:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var lf = do_get_file(aPath);
|
|
|
|
const C_i = Components.interfaces;
|
|
|
|
const parserClass = "@mozilla.org/xmlextras/domparser;1";
|
|
|
|
const streamClass = "@mozilla.org/network/file-input-stream;1";
|
|
|
|
var stream = Components.classes[streamClass]
|
|
|
|
.createInstance(C_i.nsIFileInputStream);
|
|
|
|
stream.init(lf, -1, -1, C_i.nsIFileInputStream.CLOSE_ON_EOF);
|
|
|
|
var parser = Components.classes[parserClass]
|
|
|
|
.createInstance(C_i.nsIDOMParser);
|
|
|
|
var doc = parser.parseFromStream(stream, null, lf.fileSize, aType);
|
|
|
|
parser = null;
|
|
|
|
stream = null;
|
|
|
|
lf = null;
|
|
|
|
return doc;
|
|
|
|
}
|
2009-07-10 16:42:59 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a function that will run when the test harness is done running all
|
|
|
|
* tests.
|
|
|
|
*
|
|
|
|
* @param aFunction
|
|
|
|
* The function to be called when the test harness has finished running.
|
|
|
|
*/
|
|
|
|
function do_register_cleanup(aFunction)
|
|
|
|
{
|
|
|
|
_cleanupFunctions.push(aFunction);
|
|
|
|
}
|
2009-05-14 04:37:40 -07:00
|
|
|
|
2013-07-16 09:38:35 -07:00
|
|
|
/**
|
|
|
|
* Returns the directory for a temp dir, which is created by the
|
|
|
|
* test harness. Every test gets its own temp dir.
|
|
|
|
*
|
|
|
|
* @return nsILocalFile of the temporary directory
|
|
|
|
*/
|
|
|
|
function do_get_tempdir() {
|
|
|
|
let env = Components.classes["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Components.interfaces.nsIEnvironment);
|
|
|
|
// the python harness sets this in the environment for us
|
|
|
|
let path = env.get("XPCSHELL_TEST_TEMP_DIR");
|
|
|
|
let file = Components.classes["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
file.initWithPath(path);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2009-05-14 04:37:40 -07:00
|
|
|
/**
|
|
|
|
* Registers a directory with the profile service,
|
|
|
|
* and return the directory as an nsILocalFile.
|
|
|
|
*
|
|
|
|
* @return nsILocalFile of the profile directory.
|
|
|
|
*/
|
|
|
|
function do_get_profile() {
|
2013-01-08 07:13:44 -08:00
|
|
|
if (!runningInParent) {
|
2013-07-22 19:44:25 -07:00
|
|
|
_log("test_info",
|
|
|
|
{_message: "TEST-INFO | (xpcshell/head.js) | Ignoring profile creation from child process.\n"});
|
|
|
|
|
2013-01-08 07:13:44 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-12-11 15:12:59 -08:00
|
|
|
if (!_profileInitialized) {
|
|
|
|
// Since we have a profile, we will notify profile shutdown topics at
|
|
|
|
// the end of the current test, to ensure correct cleanup on shutdown.
|
|
|
|
do_register_cleanup(function() {
|
|
|
|
let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Components.interfaces.nsIObserverService);
|
|
|
|
obsSvc.notifyObservers(null, "profile-change-net-teardown", null);
|
|
|
|
obsSvc.notifyObservers(null, "profile-change-teardown", null);
|
|
|
|
obsSvc.notifyObservers(null, "profile-before-change", null);
|
|
|
|
});
|
|
|
|
}
|
2010-04-01 15:42:22 -07:00
|
|
|
|
2009-05-14 04:37:40 -07:00
|
|
|
let env = Components.classes["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Components.interfaces.nsIEnvironment);
|
|
|
|
// the python harness sets this in the environment for us
|
|
|
|
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
|
|
|
|
let file = Components.classes["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Components.interfaces.nsILocalFile);
|
|
|
|
file.initWithPath(profd);
|
|
|
|
|
|
|
|
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties);
|
|
|
|
let provider = {
|
|
|
|
getFile: function(prop, persistent) {
|
|
|
|
persistent.value = true;
|
2010-09-15 15:55:08 -07:00
|
|
|
if (prop == "ProfD" || prop == "ProfLD" || prop == "ProfDS" ||
|
|
|
|
prop == "ProfLDS" || prop == "TmpD") {
|
2009-05-14 04:37:40 -07:00
|
|
|
return file.clone();
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
},
|
|
|
|
QueryInterface: function(iid) {
|
2010-04-01 04:29:13 -07:00
|
|
|
if (iid.equals(Components.interfaces.nsIDirectoryServiceProvider) ||
|
2009-05-14 04:37:40 -07:00
|
|
|
iid.equals(Components.interfaces.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
|
|
|
|
.registerProvider(provider);
|
2012-03-02 09:36:53 -08:00
|
|
|
|
2012-12-11 15:12:59 -08:00
|
|
|
let obsSvc = Components.classes["@mozilla.org/observer-service;1"].
|
|
|
|
getService(Components.interfaces.nsIObserverService);
|
|
|
|
|
|
|
|
if (!_profileInitialized) {
|
|
|
|
obsSvc.notifyObservers(null, "profile-do-change", "xpcshell-do-get-profile");
|
|
|
|
_profileInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The methods of 'provider' will retain this scope so null out everything
|
2012-03-02 09:36:53 -08:00
|
|
|
// to avoid spurious leak reports.
|
|
|
|
env = null;
|
|
|
|
profd = null;
|
|
|
|
dirSvc = null;
|
|
|
|
provider = null;
|
2012-12-11 15:12:59 -08:00
|
|
|
obsSvc = null;
|
2009-05-14 04:37:40 -07:00
|
|
|
return file.clone();
|
|
|
|
}
|
2009-10-17 00:05:27 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function loads head.js (this file) in the child process, so that all
|
|
|
|
* functions defined in this file (do_throw, etc) are available to subsequent
|
|
|
|
* sendCommand calls. It also sets various constants used by these functions.
|
|
|
|
*
|
|
|
|
* (Note that you may use sendCommand without calling this function first; you
|
|
|
|
* simply won't have any of the functions in this file available.)
|
|
|
|
*/
|
|
|
|
function do_load_child_test_harness()
|
|
|
|
{
|
|
|
|
// Make sure this isn't called from child process
|
2012-12-07 14:12:02 -08:00
|
|
|
if (!runningInParent) {
|
2009-10-17 00:05:27 -07:00
|
|
|
do_throw("run_test_in_child cannot be called from child!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow to be called multiple times, but only run once
|
|
|
|
if (typeof do_load_child_test_harness.alreadyRun != "undefined")
|
|
|
|
return;
|
|
|
|
do_load_child_test_harness.alreadyRun = 1;
|
|
|
|
|
2009-11-11 23:01:04 -08:00
|
|
|
_XPCSHELL_PROCESS = "parent";
|
2012-05-10 10:10:14 -07:00
|
|
|
|
|
|
|
let command =
|
2013-04-14 17:49:40 -07:00
|
|
|
"const _HEAD_JS_PATH=" + uneval(_HEAD_JS_PATH) + "; "
|
|
|
|
+ "const _HTTPD_JS_PATH=" + uneval(_HTTPD_JS_PATH) + "; "
|
|
|
|
+ "const _HEAD_FILES=" + uneval(_HEAD_FILES) + "; "
|
|
|
|
+ "const _TAIL_FILES=" + uneval(_TAIL_FILES) + "; "
|
2012-05-10 10:10:14 -07:00
|
|
|
+ "const _XPCSHELL_PROCESS='child';";
|
|
|
|
|
|
|
|
if (this._TESTING_MODULES_DIR) {
|
2013-04-14 17:49:40 -07:00
|
|
|
command += " const _TESTING_MODULES_DIR=" + uneval(_TESTING_MODULES_DIR) + ";";
|
2012-05-10 10:10:14 -07:00
|
|
|
}
|
|
|
|
|
2013-04-14 17:49:40 -07:00
|
|
|
command += " load(_HEAD_JS_PATH);";
|
2012-05-10 10:10:14 -07:00
|
|
|
sendCommand(command);
|
2009-10-17 00:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs an entire xpcshell unit test in a child process (rather than in chrome,
|
|
|
|
* which is the default).
|
|
|
|
*
|
|
|
|
* This function returns immediately, before the test has completed.
|
|
|
|
*
|
|
|
|
* @param testFile
|
|
|
|
* The name of the script to run. Path format same as load().
|
|
|
|
* @param optionalCallback.
|
|
|
|
* Optional function to be called (in parent) when test on child is
|
|
|
|
* complete. If provided, the function must call do_test_finished();
|
|
|
|
*/
|
|
|
|
function run_test_in_child(testFile, optionalCallback)
|
|
|
|
{
|
|
|
|
var callback = (typeof optionalCallback == 'undefined') ?
|
|
|
|
do_test_finished : optionalCallback;
|
|
|
|
|
|
|
|
do_load_child_test_harness();
|
|
|
|
|
|
|
|
var testPath = do_get_file(testFile).path.replace(/\\/g, "/");
|
2013-05-03 09:08:30 -07:00
|
|
|
do_test_pending("run in child");
|
2013-07-22 19:44:25 -07:00
|
|
|
sendCommand("_log('child_test_start', {_message: 'CHILD-TEST-STARTED'}); "
|
2012-03-08 15:00:05 -08:00
|
|
|
+ "const _TEST_FILE=['" + testPath + "']; _execute_test(); "
|
2013-07-22 19:44:25 -07:00
|
|
|
+ "_log('child_test_end', {_message: 'CHILD-TEST-COMPLETED'});",
|
2009-10-17 00:05:27 -07:00
|
|
|
callback);
|
|
|
|
}
|
|
|
|
|
2011-04-18 13:31:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a test function to the list of tests that are to be run asynchronously.
|
|
|
|
*
|
|
|
|
* Each test function must call run_next_test() when it's done. Test files
|
|
|
|
* should call run_next_test() in their run_test function to execute all
|
|
|
|
* async tests.
|
|
|
|
*
|
|
|
|
* @return the test function that was passed in.
|
|
|
|
*/
|
2012-12-11 10:53:43 -08:00
|
|
|
let _gTests = [];
|
2011-04-18 13:31:20 -07:00
|
|
|
function add_test(func) {
|
2012-12-11 10:53:43 -08:00
|
|
|
_gTests.push([false, func]);
|
2011-04-18 13:31:20 -07:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2012-12-11 10:53:43 -08:00
|
|
|
// We lazy import Task.jsm so we don't incur a run-time penalty for all tests.
|
|
|
|
let _Task;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a test function which is a Task function.
|
|
|
|
*
|
|
|
|
* Task functions are functions fed into Task.jsm's Task.spawn(). They are
|
|
|
|
* generators that emit promises.
|
|
|
|
*
|
|
|
|
* If an exception is thrown, a do_check_* comparison fails, or if a rejected
|
|
|
|
* promise is yielded, the test function aborts immediately and the test is
|
|
|
|
* reported as a failure.
|
|
|
|
*
|
|
|
|
* Unlike add_test(), there is no need to call run_next_test(). The next test
|
|
|
|
* will run automatically as soon the task function is exhausted. To trigger
|
|
|
|
* premature (but successful) termination of the function, simply return or
|
|
|
|
* throw a Task.Result instance.
|
|
|
|
*
|
|
|
|
* Example usage:
|
|
|
|
*
|
|
|
|
* add_task(function test() {
|
|
|
|
* let result = yield Promise.resolve(true);
|
|
|
|
*
|
|
|
|
* do_check_true(result);
|
|
|
|
*
|
|
|
|
* let secondary = yield someFunctionThatReturnsAPromise(result);
|
|
|
|
* do_check_eq(secondary, "expected value");
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* add_task(function test_early_return() {
|
|
|
|
* let result = yield somethingThatReturnsAPromise();
|
|
|
|
*
|
|
|
|
* if (!result) {
|
|
|
|
* // Test is ended immediately, with success.
|
|
|
|
* return;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* do_check_eq(result, "foo");
|
|
|
|
* });
|
|
|
|
*/
|
|
|
|
function add_task(func) {
|
|
|
|
if (!_Task) {
|
|
|
|
let ns = {};
|
|
|
|
_Task = Components.utils.import("resource://gre/modules/Task.jsm", ns).Task;
|
|
|
|
}
|
|
|
|
|
|
|
|
_gTests.push([true, func]);
|
|
|
|
}
|
|
|
|
|
2011-04-18 13:31:20 -07:00
|
|
|
/**
|
|
|
|
* Runs the next test function from the list of async tests.
|
|
|
|
*/
|
2012-12-11 10:53:43 -08:00
|
|
|
let _gRunningTest = null;
|
|
|
|
let _gTestIndex = 0; // The index of the currently running test.
|
2011-04-18 13:31:20 -07:00
|
|
|
function run_next_test()
|
|
|
|
{
|
|
|
|
function _run_next_test()
|
|
|
|
{
|
2012-12-11 10:53:43 -08:00
|
|
|
if (_gTestIndex < _gTests.length) {
|
|
|
|
let _isTask;
|
|
|
|
[_isTask, _gRunningTest] = _gTests[_gTestIndex++];
|
|
|
|
print("TEST-INFO | " + _TEST_FILE + " | Starting " + _gRunningTest.name);
|
2013-05-03 09:08:30 -07:00
|
|
|
do_test_pending(_gRunningTest.name);
|
2012-12-11 10:53:43 -08:00
|
|
|
|
|
|
|
if (_isTask) {
|
|
|
|
_Task.spawn(_gRunningTest)
|
|
|
|
.then(run_next_test, do_report_unexpected_exception);
|
|
|
|
} else {
|
|
|
|
// Exceptions do not kill asynchronous tests, so they'll time out.
|
|
|
|
try {
|
|
|
|
_gRunningTest();
|
|
|
|
} catch (e) {
|
|
|
|
do_throw(e);
|
|
|
|
}
|
2011-04-18 13:31:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For sane stacks during failures, we execute this code soon, but not now.
|
|
|
|
// We do this now, before we call do_test_finished(), to ensure the pending
|
|
|
|
// counter (_tests_pending) never reaches 0 while we still have tests to run
|
|
|
|
// (do_execute_soon bumps that counter).
|
2013-05-03 09:08:30 -07:00
|
|
|
do_execute_soon(_run_next_test, "run_next_test " + _gTestIndex);
|
2011-04-18 13:31:20 -07:00
|
|
|
|
2012-12-11 10:53:43 -08:00
|
|
|
if (_gRunningTest !== null) {
|
2011-04-18 13:31:20 -07:00
|
|
|
// Close the previous test do_test_pending call.
|
2013-05-03 09:08:30 -07:00
|
|
|
do_test_finished(_gRunningTest.name);
|
2011-04-18 13:31:20 -07:00
|
|
|
}
|
|
|
|
}
|
2013-07-01 06:43:17 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (runningInParent) {
|
|
|
|
// Always use network provider for geolocation tests
|
|
|
|
// so we bypass the OSX dialog raised by the corelocation provider
|
|
|
|
let prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
|
|
|
|
prefs.setBoolPref("geo.provider.testing", true);
|
|
|
|
}
|
|
|
|
} catch (e) { }
|