Bug 1259651 - Add the ability to register callback functions to be notified when a mochitest times out to SimpleTest. r=ted.

MozReview-Commit-ID: 2p7qqFMxHpW
This commit is contained in:
JW Wang 2016-04-01 07:42:43 +08:00
Родитель 61b8bad2ea
Коммит 3191a9a1a8
2 изменённых файлов: 15 добавлений и 0 удалений

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

@ -217,6 +217,7 @@ if (typeof(computedStyle) == 'undefined') {
SimpleTest._tests = [];
SimpleTest._stopOnLoad = true;
SimpleTest._cleanupFunctions = [];
SimpleTest._timeoutFunctions = [];
SimpleTest.expected = 'pass';
SimpleTest.num_failed = 0;
SimpleTest._inChaosMode = false;
@ -988,6 +989,10 @@ SimpleTest.registerCleanupFunction = function(aFunc) {
SimpleTest._cleanupFunctions.push(aFunc);
};
SimpleTest.registerTimeoutFunction = function(aFunc) {
SimpleTest._timeoutFunctions.push(aFunc);
};
SimpleTest.testInChaosMode = function() {
if (SimpleTest._inChaosMode) {
// It's already enabled for this test, don't enter twice
@ -997,6 +1002,13 @@ SimpleTest.testInChaosMode = function() {
SimpleTest._inChaosMode = true;
};
SimpleTest.timeout = function() {
for (let func of SimpleTest._timeoutFunctions) {
func();
}
SimpleTest._timeoutFunctions = [];
}
/**
* Finishes the tests. This is automatically called, except when
* SimpleTest.waitForExplicitFinish() has been invoked.
@ -1021,6 +1033,8 @@ SimpleTest.finish = function() {
SimpleTest._tests.push(test);
}
SimpleTest._timeoutFunctions = [];
SimpleTest.testsLength = SimpleTest._tests.length;
SimpleTest._alreadyFinished = true;

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

@ -119,6 +119,7 @@ TestRunner._checkForHangs = function() {
function killTest(win) {
if ("SimpleTest" in win) {
win.SimpleTest.timeout();
win.SimpleTest.finish();
} else if ("W3CTest" in win) {
win.W3CTest.timeout();