Bug 481406: Browser chrome harness should report console messages in the test log. r=gavin

This commit is contained in:
Dave Townsend 2009-07-03 08:22:31 +01:00
parent 7de5d30e8d
commit 403d145887
4 changed files with 54 additions and 29 deletions

View File

@ -3,10 +3,6 @@ const Ci = Components.interfaces;
const gCompleteState = Ci.nsIWebProgressListener.STATE_STOP + const gCompleteState = Ci.nsIWebProgressListener.STATE_STOP +
Ci.nsIWebProgressListener.STATE_IS_NETWORK; Ci.nsIWebProgressListener.STATE_IS_NETWORK;
function LOG(str) {
dump(str + "\n");
}
var gFrontProgressListener = { var gFrontProgressListener = {
onProgressChange: function (aWebProgress, aRequest, onProgressChange: function (aWebProgress, aRequest,
aCurSelfProgress, aMaxSelfProgress, aCurSelfProgress, aMaxSelfProgress,
@ -15,7 +11,7 @@ var gFrontProgressListener = {
onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) { onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) {
var state = "onStateChange"; var state = "onStateChange";
LOG("FrontProgress: " + state + " 0x" + aStateFlags.toString(16)); info("FrontProgress: " + state + " 0x" + aStateFlags.toString(16));
ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener"); ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener"); is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener");
gFrontNotificationsPos++; gFrontNotificationsPos++;
@ -23,7 +19,7 @@ var gFrontProgressListener = {
onLocationChange: function (aWebProgress, aRequest, aLocationURI) { onLocationChange: function (aWebProgress, aRequest, aLocationURI) {
var state = "onLocationChange"; var state = "onLocationChange";
LOG("FrontProgress: " + state + " " + aLocationURI.spec); info("FrontProgress: " + state + " " + aLocationURI.spec);
ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener"); ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener"); is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener");
gFrontNotificationsPos++; gFrontNotificationsPos++;
@ -34,7 +30,7 @@ var gFrontProgressListener = {
onSecurityChange: function (aWebProgress, aRequest, aState) { onSecurityChange: function (aWebProgress, aRequest, aState) {
var state = "onSecurityChange"; var state = "onSecurityChange";
LOG("FrontProgress: " + state + " 0x" + aState.toString(16)); info("FrontProgress: " + state + " 0x" + aState.toString(16));
ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener"); ok(gFrontNotificationsPos < gFrontNotifications.length, "Got an expected notification for the front notifications listener");
is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener"); is(state, gFrontNotifications[gFrontNotificationsPos], "Got a notification for the front notifications listener");
gFrontNotificationsPos++; gFrontNotificationsPos++;
@ -49,7 +45,7 @@ var gAllProgressListener = {
onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { onStateChange: function (aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) {
var state = "onStateChange"; var state = "onStateChange";
LOG("AllProgress: " + state + " 0x" + aStateFlags.toString(16)); info("AllProgress: " + state + " 0x" + aStateFlags.toString(16));
ok(aBrowser == gTestBrowser, state + " notification came from the correct browser"); ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener"); ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener");
is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener"); is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener");
@ -64,7 +60,7 @@ var gAllProgressListener = {
onLocationChange: function (aBrowser, aWebProgress, aRequest, aLocationURI) { onLocationChange: function (aBrowser, aWebProgress, aRequest, aLocationURI) {
var state = "onLocationChange"; var state = "onLocationChange";
LOG("AllProgress: " + state + " " + aLocationURI.spec); info("AllProgress: " + state + " " + aLocationURI.spec);
ok(aBrowser == gTestBrowser, state + " notification came from the correct browser"); ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener"); ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener");
is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener"); is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener");
@ -78,7 +74,7 @@ var gAllProgressListener = {
onSecurityChange: function (aBrowser, aWebProgress, aRequest, aState) { onSecurityChange: function (aBrowser, aWebProgress, aRequest, aState) {
var state = "onSecurityChange"; var state = "onSecurityChange";
LOG("AllProgress: " + state + " 0x" + aState.toString(16)); info("AllProgress: " + state + " 0x" + aState.toString(16));
ok(aBrowser == gTestBrowser, state + " notification came from the correct browser"); ok(aBrowser == gTestBrowser, state + " notification came from the correct browser");
ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener"); ok(gAllNotificationsPos < gAllNotifications.length, "Got an expected notification for the all notifications listener");
is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener"); is(state, gAllNotifications[gAllNotificationsPos], "Got a notification for the all notifications listener");
@ -92,7 +88,6 @@ var gTestPage = "/browser/browser/base/content/test/alltabslistener.html";
var gNextTest; var gNextTest;
function test() { function test() {
LOG("Running tests from alltabslistener.js");
waitForExplicitFinish(); waitForExplicitFinish();
gBackgroundTab = gBrowser.addTab("about:blank"); gBackgroundTab = gBrowser.addTab("about:blank");
@ -120,7 +115,7 @@ function startTests() {
} }
function startTest1() { function startTest1() {
LOG("\nTest 1"); info("\nTest 1");
gBrowser.addProgressListener(gFrontProgressListener); gBrowser.addProgressListener(gFrontProgressListener);
gBrowser.addTabsProgressListener(gAllProgressListener); gBrowser.addTabsProgressListener(gAllProgressListener);
@ -135,7 +130,7 @@ function startTest1() {
} }
function startTest2() { function startTest2() {
LOG("\nTest 2"); info("\nTest 2");
gAllNotifications = [ gAllNotifications = [
"onStateChange", "onStateChange",
"onLocationChange", "onLocationChange",
@ -148,7 +143,7 @@ function startTest2() {
} }
function startTest3() { function startTest3() {
LOG("\nTest 3"); info("\nTest 3");
gAllNotifications = [ gAllNotifications = [
"onStateChange", "onStateChange",
"onLocationChange", "onLocationChange",
@ -160,7 +155,7 @@ function startTest3() {
} }
function startTest4() { function startTest4() {
LOG("\nTest 4"); info("\nTest 4");
gAllNotifications = [ gAllNotifications = [
"onStateChange", "onStateChange",
"onLocationChange", "onLocationChange",
@ -173,7 +168,7 @@ function startTest4() {
} }
function startTest5() { function startTest5() {
LOG("\nTest 5"); info("\nTest 5");
// Switch the foreground browser // Switch the foreground browser
[gForegroundBrowser, gBackgroundBrowser] = [gBackgroundBrowser, gForegroundBrowser]; [gForegroundBrowser, gBackgroundBrowser] = [gBackgroundBrowser, gForegroundBrowser];
[gForegroundTab, gBackgroundTab] = [gBackgroundTab, gForegroundTab]; [gForegroundTab, gBackgroundTab] = [gBackgroundTab, gForegroundTab];
@ -193,7 +188,7 @@ function startTest5() {
} }
function startTest6() { function startTest6() {
LOG("\nTest 6"); info("\nTest 6");
gAllNotifications = [ gAllNotifications = [
"onStateChange", "onStateChange",
"onLocationChange", "onLocationChange",
@ -205,7 +200,6 @@ function startTest6() {
} }
function finishTest() { function finishTest() {
LOG("\nFinished tests from alltabslistener.js");
gBrowser.removeProgressListener(gFrontProgressListener); gBrowser.removeProgressListener(gFrontProgressListener);
gBrowser.removeTabsProgressListener(gAllProgressListener); gBrowser.removeTabsProgressListener(gAllProgressListener);
gBrowser.removeTab(gBackgroundTab); gBrowser.removeTab(gBackgroundTab);

View File

@ -70,6 +70,10 @@
background-color: orange; background-color: orange;
} }
.info {
color: grey;
}
.failed { .failed {
color: red; color: red;
font-weight: bold; font-weight: bold;
@ -184,13 +188,13 @@
} }
browserTest.prototype = { browserTest.prototype = {
get passCount() { get passCount() {
return this.results.filter(function (t) !t.todo && t.pass).length; return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
}, },
get todoCount() { get todoCount() {
return this.results.filter(function (t) t.todo && t.pass).length; return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
}, },
get failCount() { get failCount() {
return this.results.filter(function (t) !t.pass).length; return this.results.filter(function (t) !t.info && !t.pass).length;
}, },
addResult: function addResult(result) { addResult: function addResult(result) {
@ -207,12 +211,10 @@
} }
var path = _entityEncode(this.path); var path = _entityEncode(this.path);
return this.results.map(function (t) { return this.results.map(function (t) {
var result = "<p class=\"result "; var class = t.info ? "info" : "result " + (t.pass ? "passed" : "failed");
result += t.pass ? "passed" : "failed"; return "<p class=\"" + class + "\">" + t.result + " | " + path +
result += "\">" + t.result + " | " + path + " | " + _entityEncode(t.msg) + "</p>";
" | " + _entityEncode( t.msg ) + "</p>"; }).join("\n");
return result;
}).join("\n");
} }
}; };

View File

@ -31,6 +31,8 @@ function Tester(aTests, aDumper, aCallback) {
this.dumper = aDumper; this.dumper = aDumper;
this.tests = aTests; this.tests = aTests;
this.callback = aCallback; this.callback = aCallback;
this._cs = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
} }
Tester.prototype = { Tester.prototype = {
checker: null, checker: null,
@ -47,6 +49,7 @@ Tester.prototype = {
start: function Tester_start() { start: function Tester_start() {
this.dumper.dump("*** Start BrowserChrome Test Results ***\n"); this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
this._cs.registerListener(this);
if (this.tests.length) if (this.tests.length)
this.execTest(); this.execTest();
@ -55,6 +58,8 @@ Tester.prototype = {
}, },
finish: function Tester_finish(aSkipSummary) { finish: function Tester_finish(aSkipSummary) {
this._cs.unregisterListener(this);
if (this.tests.length) { if (this.tests.length) {
this.dumper.dump("\nBrowser Chrome Test Summary\n"); this.dumper.dump("\nBrowser Chrome Test Summary\n");
@ -79,6 +84,11 @@ Tester.prototype = {
this.tests = null; this.tests = null;
}, },
observe: function Tester_observe(aConsoleMessage) {
var msg = "Console message: " + aConsoleMessage.message;
this.currentTest.addResult(new testMessage(msg));
},
execTest: function Tester_execTest() { execTest: function Tester_execTest() {
if (this.done) { if (this.done) {
this.finish(); this.finish();
@ -118,15 +128,24 @@ Tester.prototype = {
self.execTest(); self.execTest();
}, TIMEOUT_SECONDS * 1000); }, TIMEOUT_SECONDS * 1000);
} }
},
QueryInterface: function(aIID) {
if (aIID.equals(Ci.nsIConsoleListener) ||
aIID.equals(Ci.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
} }
}; };
function testResult(aCondition, aName, aDiag, aIsTodo) { function testResult(aCondition, aName, aDiag, aIsTodo) {
aName = aName || ""; this.msg = aName || "";
this.info = false;
this.pass = !!aCondition; this.pass = !!aCondition;
this.todo = aIsTodo; this.todo = aIsTodo;
this.msg = aName;
if (this.pass) { if (this.pass) {
if (aIsTodo) if (aIsTodo)
this.result = "TEST-KNOWN-FAIL"; this.result = "TEST-KNOWN-FAIL";
@ -142,6 +161,12 @@ function testResult(aCondition, aName, aDiag, aIsTodo) {
} }
} }
function testMessage(aName) {
this.msg = aName || "";
this.info = true;
this.result = "TEST-INFO";
}
// Need to be careful adding properties to this object, since its properties // Need to be careful adding properties to this object, since its properties
// cannot conflict with global variables used in tests. // cannot conflict with global variables used in tests.
function testScope(aTester, aTest) { function testScope(aTester, aTest) {
@ -171,6 +196,9 @@ function testScope(aTester, aTest) {
this.todo_isnot = function test_todo_isnot(a, b, name) { this.todo_isnot = function test_todo_isnot(a, b, name) {
self.todo(a != b, name, "Didn't expect " + a + ", but got it"); self.todo(a != b, name, "Didn't expect " + a + ", but got it");
}; };
this.info = function test_info(name) {
self.__browserTest.addResult(new testMessage(name));
};
this.executeSoon = function test_executeSoon(func) { this.executeSoon = function test_executeSoon(func) {
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager); let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);

View File

@ -5,6 +5,7 @@ function test() {
todo(false, "pass todo"); todo(false, "pass todo");
todo_is(false, true, "pass todo_is"); todo_is(false, true, "pass todo_is");
todo_isnot(true, true, "pass todo_isnot"); todo_isnot(true, true, "pass todo_isnot");
info("info message");
var func = is; var func = is;
func(true, true, "pass indirect is"); func(true, true, "pass indirect is");