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

View File

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

View File

@ -31,6 +31,8 @@ function Tester(aTests, aDumper, aCallback) {
this.dumper = aDumper;
this.tests = aTests;
this.callback = aCallback;
this._cs = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
}
Tester.prototype = {
checker: null,
@ -47,6 +49,7 @@ Tester.prototype = {
start: function Tester_start() {
this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
this._cs.registerListener(this);
if (this.tests.length)
this.execTest();
@ -55,6 +58,8 @@ Tester.prototype = {
},
finish: function Tester_finish(aSkipSummary) {
this._cs.unregisterListener(this);
if (this.tests.length) {
this.dumper.dump("\nBrowser Chrome Test Summary\n");
@ -79,6 +84,11 @@ Tester.prototype = {
this.tests = null;
},
observe: function Tester_observe(aConsoleMessage) {
var msg = "Console message: " + aConsoleMessage.message;
this.currentTest.addResult(new testMessage(msg));
},
execTest: function Tester_execTest() {
if (this.done) {
this.finish();
@ -118,15 +128,24 @@ Tester.prototype = {
self.execTest();
}, 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) {
aName = aName || "";
this.msg = aName || "";
this.info = false;
this.pass = !!aCondition;
this.todo = aIsTodo;
this.msg = aName;
if (this.pass) {
if (aIsTodo)
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
// cannot conflict with global variables used in tests.
function testScope(aTester, aTest) {
@ -171,6 +196,9 @@ function testScope(aTester, aTest) {
this.todo_isnot = function test_todo_isnot(a, b, name) {
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) {
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);

View File

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