2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* TestRunner: A test runner for SimpleTest
|
|
|
|
* TODO:
|
2008-07-27 13:31:22 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* * Avoid moving iframes: That causes reloads on mozilla and opera.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
var TestRunner = {};
|
|
|
|
TestRunner.logEnabled = false;
|
|
|
|
TestRunner._currentTest = 0;
|
2007-09-04 06:02:34 -07:00
|
|
|
TestRunner.currentTestURL = "";
|
2007-03-22 10:30:00 -07:00
|
|
|
TestRunner._urls = [];
|
|
|
|
|
2009-05-14 07:17:48 -07:00
|
|
|
TestRunner.timeout = 5 * 60 * 1000; // 5 minutes.
|
2008-01-15 14:23:44 -08:00
|
|
|
TestRunner.maxTimeouts = 4; // halt testing after too many timeouts
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2008-01-15 14:23:44 -08:00
|
|
|
* Make sure the tests don't hang indefinitely.
|
2007-03-22 10:30:00 -07:00
|
|
|
**/
|
2008-01-15 14:23:44 -08:00
|
|
|
TestRunner._numTimeouts = 0;
|
2008-01-21 19:54:20 -08:00
|
|
|
TestRunner._currentTestStartTime = new Date().valueOf();
|
2009-11-19 09:35:09 -08:00
|
|
|
TestRunner._timeoutFactor = 1;
|
2008-01-15 14:23:44 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
TestRunner._checkForHangs = function() {
|
|
|
|
if (TestRunner._currentTest < TestRunner._urls.length) {
|
2009-05-14 07:17:48 -07:00
|
|
|
var runtime = new Date().valueOf() - TestRunner._currentTestStartTime;
|
2009-11-19 09:35:09 -08:00
|
|
|
if (runtime >= TestRunner.timeout * TestRunner._timeoutFactor) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var frameWindow = $('testframe').contentWindow.wrappedJSObject ||
|
2009-05-14 07:17:48 -07:00
|
|
|
$('testframe').contentWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
frameWindow.SimpleTest.ok(false, "Test timed out.");
|
2008-01-15 14:23:44 -08:00
|
|
|
|
|
|
|
// If we have too many timeouts, give up. We don't want to wait hours
|
|
|
|
// for results if some bug causes lots of tests to time out.
|
|
|
|
if (++TestRunner._numTimeouts >= TestRunner.maxTimeouts) {
|
|
|
|
TestRunner._haltTests = true;
|
2009-05-14 07:17:48 -07:00
|
|
|
|
|
|
|
TestRunner.currentTestURL = "(SimpleTest/TestRunner.js)";
|
|
|
|
frameWindow.SimpleTest.ok(false, TestRunner.maxTimeouts + " test timeouts, giving up.");
|
|
|
|
var skippedTests = TestRunner._urls.length - TestRunner._currentTest;
|
|
|
|
frameWindow.SimpleTest.ok(false, "Skipping " + skippedTests + " remaining tests.");
|
2008-01-15 14:23:44 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
frameWindow.SimpleTest.finish();
|
2009-05-14 07:17:48 -07:00
|
|
|
|
|
|
|
if (TestRunner._haltTests)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-05-14 07:17:48 -07:00
|
|
|
|
2008-07-27 13:31:22 -07:00
|
|
|
TestRunner.deferred = callLater(30, TestRunner._checkForHangs);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-19 09:35:09 -08:00
|
|
|
TestRunner.requestLongerTimeout = function(factor) {
|
|
|
|
TestRunner._timeoutFactor = factor;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* This function is called after generating the summary.
|
|
|
|
**/
|
|
|
|
TestRunner.onComplete = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If logEnabled is true, this is the logger that will be used.
|
|
|
|
**/
|
|
|
|
TestRunner.logger = MochiKit.Logging.logger;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle element visibility
|
|
|
|
**/
|
|
|
|
TestRunner._toggle = function(el) {
|
|
|
|
if (el.className == "noshow") {
|
|
|
|
el.className = "";
|
|
|
|
el.style.cssText = "";
|
|
|
|
} else {
|
|
|
|
el.className = "noshow";
|
|
|
|
el.style.cssText = "width:0px; height:0px; border:0px;";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the iframe that contains a test
|
|
|
|
**/
|
2008-07-27 13:28:26 -07:00
|
|
|
TestRunner._makeIframe = function (url, retry) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var iframe = $('testframe');
|
2008-12-23 13:33:58 -08:00
|
|
|
if (url != "about:blank" &&
|
|
|
|
(("hasFocus" in document && !document.hasFocus()) ||
|
|
|
|
("activeElement" in document && document.activeElement != iframe))) {
|
2008-05-07 14:45:13 -07:00
|
|
|
// typically calling ourselves from setTimeout is sufficient
|
|
|
|
// but we'll try focus() just in case that's needed
|
|
|
|
window.focus();
|
|
|
|
iframe.focus();
|
|
|
|
if (retry < 3) {
|
2008-07-27 13:28:26 -07:00
|
|
|
window.setTimeout('TestRunner._makeIframe("'+url+'", '+(retry+1)+')', 1000);
|
2008-05-07 14:45:13 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-27 13:28:26 -07:00
|
|
|
if (TestRunner.logEnabled) {
|
2008-07-27 13:31:22 -07:00
|
|
|
TestRunner.logger.log("Error: Unable to restore focus, expect failures and timeouts.");
|
2008-07-27 13:28:26 -07:00
|
|
|
}
|
2008-05-07 14:45:13 -07:00
|
|
|
}
|
2009-11-18 11:13:29 -08:00
|
|
|
window.scrollTo(0, $('indicator').offsetTop);
|
2007-03-22 10:30:00 -07:00
|
|
|
iframe.src = url;
|
2008-07-27 13:31:22 -07:00
|
|
|
iframe.name = url;
|
2007-03-22 10:30:00 -07:00
|
|
|
iframe.width = "500";
|
|
|
|
return iframe;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TestRunner entry point.
|
|
|
|
*
|
|
|
|
* The arguments are the URLs of the test to be ran.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
TestRunner.runTests = function (/*url...*/) {
|
|
|
|
if (TestRunner.logEnabled)
|
|
|
|
TestRunner.logger.log("SimpleTest START");
|
2008-07-27 13:31:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
TestRunner._urls = flattenArguments(arguments);
|
|
|
|
$('testframe').src="";
|
|
|
|
TestRunner._checkForHangs();
|
2008-05-07 14:45:13 -07:00
|
|
|
window.focus();
|
|
|
|
$('testframe').focus();
|
2007-03-22 10:30:00 -07:00
|
|
|
TestRunner.runNextTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2009-05-14 07:17:48 -07:00
|
|
|
* Run the next test. If no test remains, calls onComplete().
|
|
|
|
**/
|
2008-01-15 14:23:44 -08:00
|
|
|
TestRunner._haltTests = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
TestRunner.runNextTest = function() {
|
2008-01-15 14:23:44 -08:00
|
|
|
if (TestRunner._currentTest < TestRunner._urls.length &&
|
2009-05-14 07:17:48 -07:00
|
|
|
!TestRunner._haltTests)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
var url = TestRunner._urls[TestRunner._currentTest];
|
2007-09-04 06:02:34 -07:00
|
|
|
TestRunner.currentTestURL = url;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
$("current-test-path").innerHTML = url;
|
2008-07-27 13:31:22 -07:00
|
|
|
|
2008-01-21 19:54:20 -08:00
|
|
|
TestRunner._currentTestStartTime = new Date().valueOf();
|
2009-11-19 09:35:09 -08:00
|
|
|
TestRunner._timeoutFactor = 1;
|
2008-01-15 14:23:44 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (TestRunner.logEnabled)
|
|
|
|
TestRunner.logger.log("Running " + url + "...");
|
2008-07-27 13:31:22 -07:00
|
|
|
|
2008-07-27 13:28:26 -07:00
|
|
|
TestRunner._makeIframe(url, 0);
|
2009-05-14 07:17:48 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
$("current-test").innerHTML = "<b>Finished</b>";
|
2008-07-27 13:28:26 -07:00
|
|
|
TestRunner._makeIframe("about:blank", 0);
|
2009-05-14 07:17:48 -07:00
|
|
|
|
|
|
|
if (parseInt($("pass-count").innerHTML) == 0 &&
|
|
|
|
parseInt($("fail-count").innerHTML) == 0 &&
|
|
|
|
parseInt($("todo-count").innerHTML) == 0)
|
|
|
|
{
|
|
|
|
// No |$('testframe').contentWindow|, so manually update: ...
|
|
|
|
// ... the log,
|
|
|
|
if (TestRunner.logEnabled)
|
|
|
|
TestRunner.logger.error("TEST-UNEXPECTED-FAIL | (SimpleTest/TestRunner.js) | No checks actually run.");
|
|
|
|
// ... the count,
|
|
|
|
$("fail-count").innerHTML = 1;
|
|
|
|
// ... the indicator.
|
|
|
|
var indicator = $("indicator");
|
|
|
|
indicator.innerHTML = "Status: Fail (No checks actually run)";
|
|
|
|
indicator.style.backgroundColor = "red";
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (TestRunner.logEnabled) {
|
2008-01-21 19:54:20 -08:00
|
|
|
TestRunner.logger.log("Passed: " + $("pass-count").innerHTML);
|
|
|
|
TestRunner.logger.log("Failed: " + $("fail-count").innerHTML);
|
|
|
|
TestRunner.logger.log("Todo: " + $("todo-count").innerHTML);
|
2008-02-06 23:18:45 -08:00
|
|
|
TestRunner.logger.log("SimpleTest FINISHED");
|
2008-01-21 19:54:20 -08:00
|
|
|
}
|
2009-05-14 07:17:48 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (TestRunner.onComplete)
|
|
|
|
TestRunner.onComplete();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This stub is called by SimpleTest when a test is finished.
|
|
|
|
**/
|
|
|
|
TestRunner.testFinished = function(doc) {
|
|
|
|
if (TestRunner.logEnabled)
|
2009-05-14 07:17:48 -07:00
|
|
|
TestRunner.logger.debug("SimpleTest finished " +
|
|
|
|
TestRunner._urls[TestRunner._currentTest]);
|
2008-07-27 13:31:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
TestRunner.updateUI();
|
|
|
|
TestRunner._currentTest++;
|
|
|
|
TestRunner.runNextTest();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the results.
|
|
|
|
*/
|
|
|
|
TestRunner.countResults = function(doc) {
|
|
|
|
var nOK = withDocument(doc,
|
|
|
|
partial(getElementsByTagAndClassName, 'div', 'test_ok')
|
|
|
|
).length;
|
|
|
|
var nNotOK = withDocument(doc,
|
|
|
|
partial(getElementsByTagAndClassName, 'div', 'test_not_ok')
|
|
|
|
).length;
|
|
|
|
var nTodo = withDocument(doc,
|
|
|
|
partial(getElementsByTagAndClassName, 'div', 'test_todo')
|
|
|
|
).length;
|
|
|
|
return {"OK": nOK, "notOK": nNotOK, "todo": nTodo};
|
|
|
|
}
|
|
|
|
|
|
|
|
TestRunner.updateUI = function() {
|
2009-09-15 17:54:56 -07:00
|
|
|
var testFrame = $('testframe');
|
|
|
|
var results = TestRunner.countResults(testFrame.contentDocument ||
|
|
|
|
testFrame.contentWindow.document);
|
2007-03-22 10:30:00 -07:00
|
|
|
var passCount = parseInt($("pass-count").innerHTML) + results.OK;
|
|
|
|
var failCount = parseInt($("fail-count").innerHTML) + results.notOK;
|
|
|
|
var todoCount = parseInt($("todo-count").innerHTML) + results.todo;
|
|
|
|
$("pass-count").innerHTML = passCount;
|
|
|
|
$("fail-count").innerHTML = failCount;
|
|
|
|
$("todo-count").innerHTML = todoCount;
|
2008-07-27 13:31:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Set the top Green/Red bar
|
|
|
|
var indicator = $("indicator");
|
|
|
|
if (failCount > 0) {
|
|
|
|
indicator.innerHTML = "Status: Fail";
|
|
|
|
indicator.style.backgroundColor = "red";
|
|
|
|
} else if (passCount > 0) {
|
|
|
|
indicator.innerHTML = "Status: Pass";
|
2009-05-14 07:17:48 -07:00
|
|
|
indicator.style.backgroundColor = "#0d0";
|
|
|
|
} else {
|
|
|
|
indicator.innerHTML = "Status: ToDo";
|
|
|
|
indicator.style.backgroundColor = "orange";
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-07-27 13:31:22 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Set the table values
|
|
|
|
var trID = "tr-" + $('current-test-path').innerHTML;
|
|
|
|
var row = $(trID);
|
2009-04-21 04:25:22 -07:00
|
|
|
var tds = row.getElementsByTagName("td");
|
2009-05-14 07:17:48 -07:00
|
|
|
tds[0].style.backgroundColor = "#0d0";
|
2009-09-15 17:54:56 -07:00
|
|
|
tds[0].innerHTML = results.OK;
|
2009-05-14 07:17:48 -07:00
|
|
|
tds[1].style.backgroundColor = results.notOK > 0 ? "red" : "#0d0";
|
2009-09-15 17:54:56 -07:00
|
|
|
tds[1].innerHTML = results.notOK;
|
2009-04-21 04:25:22 -07:00
|
|
|
tds[2].style.backgroundColor = results.todo > 0 ? "orange" : "#0d0";
|
2009-09-15 17:54:56 -07:00
|
|
|
tds[2].innerHTML = results.todo;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|