Bug 387455: adjust browser chrome test harness output (provide summary, don't fail if there are no tests), r=robcee
--- a/testing/mochitest/browser-harness.xul
+++ b/testing/mochitest/browser-harness.xul
@@ -97,24 +97,28 @@
getService(Ci.nsIFileProtocolHandler);
var chromeDir = fileHandler.getFileFromURLSpec(resolvedURI.spec);
return chromeDir.parent.QueryInterface(Ci.nsILocalFile);
}
function browserTestFile(aTestFile) {
this.path = aTestFile;
- this.exception = null;
- this.timedOut = false;
this.tests = [];
this.scope = null;
}
browserTestFile.prototype = {
- get allPassed() {
- return !this.tests.some(function (t) !t.pass);
+ get passCount() {
+ return this.tests.filter(function (t) !t.todo && t.pass).length;
+ },
+ get todoCount() {
+ return this.tests.filter(function (t) t.todo && t.pass).length;
+ },
+ get failCount() {
+ return this.tests.filter(function (t) !t.pass).length;
},
get log() {
return this.tests.map(function (t) t.msg).join("\n");
}
};
// Returns an array of chrome:// URLs to all the test files
function listTests() {
@@ -149,26 +153,33 @@
setStatus("Running...");
testWin.focus();
var Tester = new testWin.Tester(listTests(), testsFinished);
Tester.start();
}
function getLogFromTests(aTests) {
- return aTests.map(function (f) {
- var output = f.path + "\n";
- if (f.log)
- output += f.log + "\n";
- if (f.exception)
- output += "\tFAIL - Exception thrown: " + f.exception + "\n";
- if (f.timedOut)
- output += "\tFAIL - Timed out\n";
- return output;
- }).join("");
+ if (!aTests.length)
+ return "PASS - No tests to run";
+
+ var log = aTests.map(function (f) {
+ var output = f.path + "\n";
+ if (f.log)
+ output += f.log + "\n";
+ return output;
+ }).join("");
+ log += "\nBrowser Chrome Test Summary\n";
+ function sum(a, b){ return a + b; }
+ var passCount = aTests.map(function (f) f.passCount).reduce(sum);
+ var failCount = aTests.map(function (f) f.failCount).reduce(sum);
+ var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
+ log += "\tPass: " + passCount + "\n\tFail: " + failCount + "\n\tTodo: " + todoCount + "\n";
+
+ return log;
}
function testsFinished(aTests) {
// Focus our window, to display the results
window.focus();
var start = "*** Start BrowserChrome Test Results ***\n";
var end = "\n*** End BrowserChrome Test Results ***\n";
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -65,39 +65,42 @@ Tester.prototype = {
getService(Ci.mozIJSSubScriptLoader);
scriptLoader.loadSubScript(this.currentTest.path, this.currentTest.scope);
// Run the test
var exception = null;
try {
this.currentTest.scope.test();
} catch (ex) {
- this.currentTest.exception = ex;
+ this.currentTest.tests.push(new testResult(false, "Exception thrown", ex, false));
}
- // If the test ran synchronously, set the result and move to the next test,
+ // If the test ran synchronously, move to the next test,
// otherwise start a poller to monitor it's progress.
if (this.currentTest.scope.done) {
- this.currentTest.result = this.currentTest.scope.result;
this.execTest();
} else {
var self = this;
this.checker = new resultPoller(this.currentTest, function () { self.execTest(); });
this.checker.start();
}
}
};
function testResult(aCondition, aName, aDiag, aIsTodo) {
aName = aName || "";
this.pass = !!aCondition;
- if (this.pass)
- this.msg = "\tPASS - " + aName;
- else {
+ this.todo = aIsTodo;
+ if (this.pass) {
+ if (aIsTodo)
+ this.msg = "\tTODO PASS - " + aName;
+ else
+ this.msg = "\tPASS - " + aName;
+ } else {
this.msg = "\tFAIL - ";
if (aIsTodo)
this.msg += "TODO Worked? - ";
this.msg += aName;
if (aDiag)
this.msg += " - " + aDiag;
}
}
@@ -153,24 +156,21 @@ resultPoller.prototype = {
interval: 0,
start: function resultPoller_start() {
var self = this;
function checkDone() {
self.loopCount++;
if (self.loopCount > MAX_LOOP_COUNT) {
- self.test.timedOut = true;
+ self.test.tests.push(new testResult(false, "Timed out", "", false));
self.test.scope.done = true;
}
if (self.test.scope.done) {
- // Set the result
- self.test.result = self.test.scope.result;
-
clearInterval(self.interval);
// Notify the callback
self.callback();
self.callback = null;
self.test = null;
}
}