Subversion Repositories JSX

Compare Revisions

Last modification

Ignore whitespace Rev 431 → Rev 432

/trunk/test/test.js
412,6 → 412,7
 
var table = document.createElement("table");
table.id = id;
this._table = table;
 
var thead = document.createElement("thead");
var tr = document.createElement("tr");
442,8 → 443,35
var tbody = document.createElement("tbody");
table.appendChild(tbody);
 
var tests = this._tests;
for (var i = 0, len = tests.length; i < len; ++i)
{
var test = tests[i];
var number = i + 1;
var file = this._file;
var feature = this._feature;
var description = "";
 
if (test && typeof test != "function")
{
if (test.file)
{
file = test.file;
}
 
if (test.feature)
{
feature = test.feature;
}
 
description = test.description || test.desc || test.name;
test = test.code;
}
 
this._appendRow(number, file, feature, description);
}
 
document.body.appendChild(table);
this._table = table;
},
 
/**
457,17 → 485,21
 
/**
* @protected
* @param {int} num
* @param {string} file
* @param {string} feature
* @param {string} desc
*/
_appendEntry: function (num, file, feature, desc, result, msgType) {
if (!this._table)
_appendRow: function (num, file, feature, desc) {
var table = this._table;
if (!table)
{
return;
}
 
var tbody = this._table.tBodies[0];
var tbody = table.tBodies[0];
 
var tr = document.createElement("tr");
tr.className = msgType;
 
var th = document.createElement("th");
th.appendChild(document.createTextNode(num));
499,11 → 531,9
tr.appendChild(td);
 
td = document.createElement("td");
td.id = table.id + "-" + num;
td.innerHTML = "testing…";
 
/* FIXME: Use standards-compliant methods instead */
td.innerHTML = this._htmlEscape(result).replace(/\r?\n|\r/g, "<br>");
 
td.className = msgType;
tr.appendChild(td);
 
tbody.appendChild(tr);
510,8 → 540,28
},
 
/**
* Updates a result cell
*
* @protected
* @param {int} rowNum
* Row number
* @param {string} result
* @param {string} msgType
*/
_updateResult: function (rowNum, result, msgType) {
var td = document.getElementById(this._table.id + "-" + rowNum);
if (td)
{
/* FIXME: Use standards-compliant methods instead */
td.innerHTML = this._htmlEscape(result).replace(/\r?\n|\r/g, "<br>");
 
td.className = msgType;
}
},
 
/**
* @protected
*/
_appendSummary: function (text) {
if (this._table)
{
564,7 → 614,7
* @param msgType
*/
_printResult: function (num, file, feature, desc, result, msgType) {
this._appendEntry(num, file, feature, desc, result, msgType);
this._updateResult(num, result, msgType);
this._printMsg("Test " + num
+ (file || feature ? ", " : "")
+ file
715,85 → 765,101
}
}
 
if (this._tests.length == 0)
var tests = this._tests;
if (tests.length == 0)
{
return this._printMsg("No tests defined.", "info");
}
 
var result = {
this._appendTable();
 
tests.result = {
failed: 0,
passed: 0
};
 
this._appendTable();
 
for (var i = 0, len = this._tests.length; i < len; ++i)
var hasSetTimeout = jsx.object.isMethod(jsx.global, "window", "setTimeout");
var hasClearTimeout = jsx.object.isMethod(jsx.global, "window", "clearTimeout");
var me = this;
for (var i = 0, len = tests.length; i < len; ++i)
{
var test = this._tests[i];
var number = i + 1;
var file = this._file;
var feature = this._feature;
var description = "";
 
if (test && typeof test != "function")
if (hasSetTimeout)
{
if (test.file)
{
file = test.file;
}
/* Asynchronous testing allows GUI thread to paint table */
(function (i) {
var timeout = window.setTimeout(function () {
me._runTest(i, hasSetUp, hasTearDown);
 
if (test.feature)
{
feature = test.feature;
}
 
description = test.description || test.desc || test.name;
test = test.code;
if (hasClearTimeout)
{
window.clearTimeout(timeout);
}
}, 50);
}(i));
}
 
if (hasSetUp)
else
{
this._setUp(i, test);
this._runTest(i, hasSetUp, hasTearDown);
}
}
},
 
try
/**
* @protected
*/
_runTest: function (i, hasSetUp, hasTearDown) {
var tests = this._tests;
var test = tests[i];
var number = i + 1;
var file = this._file;
var feature = this._feature;
var description = "";
 
if (test && typeof test != "function")
{
if (test.file)
{
test(i);
++result.passed;
this._printResult(number, file, feature, description,
"passed", "info");
file = test.file;
}
catch (e)
 
if (test.feature)
{
++result.failed;
this._printResult(number, file, feature, description,
"threw " + e + (e.stack ? "\n\n" + e.stack : ""),
"error");
feature = test.feature;
}
 
if (hasTearDown)
{
this._tearDown(i, test);
}
description = test.description || test.desc || test.name;
test = test.code;
}
 
this._printSummary(result);
},
if (hasSetUp)
{
this._setUp(i, test);
}
 
runAsync: function () {
var args = arguments;
var _run = this.run;
var jsx_dom_timeout = jsx.object.getFeature(jsx, "dom", "timeout");
if (jsx_dom_timeout)
try
{
var me = this;
return jsx_dom_timeout.runAsync(
function () {
_run.apply(me, args);
});
test(i);
++tests.result.passed;
this._printResult(number, file, feature, description,
"passed", "info");
}
catch (e)
{
++tests.result.failed;
this._printResult(number, file, feature, description,
"threw " + e + (e.stack ? "\n\n" + e.stack : ""),
"error");
}
 
return _run.apply(this, args);
if (hasTearDown)
{
this._tearDown(i, test);
}
 
if (i == tests.length - 1)
{
this._printSummary(tests.result);
}
},
 
setFile: function (file) {