Bug 550481: Exceptions from the do_execute_soon callback should be logged and fail the test. r=ted

This commit is contained in:
Dave Townsend 2010-03-08 10:26:54 -08:00
parent ae934ea79f
commit 8bf7ebf228
2 changed files with 70 additions and 5 deletions

View file

@ -0,0 +1,20 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
* ***** END LICENSE BLOCK ***** */
var complete = false;
function run_test() {
dump("Starting test\n");
do_register_cleanup(function() {
dump("Checking test completed\n");
do_check_true(complete);
});
do_execute_soon(function execute_soon_callback() {
dump("do_execute_soon callback\n");
complete = true;
});
}

View file

@ -119,6 +119,17 @@ function _do_quit() {
_quit = true;
}
function _dump_exception_stack(stack) {
stack.split("\n").forEach(function(frame) {
if (!frame)
return;
// frame is of the form "fname(args)@file:line"
let frame_regexp = new RegExp("(.*)\\(.*\\)@(.*):(\\d*)", "g");
let parts = frame_regexp.exec(frame);
dump("JS frame :: " + parts[2] + " :: " + (parts[1] ? parts[1] : "anonymous") + " :: line " + parts[3] + "\n");
});
}
function _execute_test() {
// Map resource://test/ to the current working directory.
let (ios = Components.classes["@mozilla.org/network/io-service;1"]
@ -142,10 +153,21 @@ function _execute_test() {
_do_main();
} catch (e) {
_passed = false;
// Print exception, but not do_throw() result.
// Hopefully, this won't mask other NS_ERROR_ABORTs.
if (!_quit || e != Components.results.NS_ERROR_ABORT)
dump("TEST-UNEXPECTED-FAIL | (xpcshell/head.js) | " + e + "\n");
// do_check failures are already logged and set _quit to true and throw
// NS_ERROR_ABORT. If both of those are true it is likely this exception
// has already been logged so there is no need to log it again. It's
// possible that this will mask an NS_ERROR_ABORT that happens after a
// do_check failure though.
if (!_quit || e != Components.results.NS_ERROR_ABORT) {
dump("TEST-UNEXPECTED-FAIL | (xpcshell/head.js) | " + e);
if (e.stack) {
dump(" - See following stack:\n");
_dump_exception_stack(e.stack);
}
else {
dump("\n");
}
}
}
// _TAIL_FILES is dynamically defined by <runxpcshelltests.py>.
@ -192,12 +214,35 @@ function do_timeout(delay, func) {
}
function do_execute_soon(callback) {
do_test_pending();
var tm = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager);
tm.mainThread.dispatch({
run: function() {
callback();
try {
callback();
} catch (e) {
// do_check failures are already logged and set _quit to true and throw
// NS_ERROR_ABORT. If both of those are true it is likely this exception
// has already been logged so there is no need to log it again. It's
// possible that this will mask an NS_ERROR_ABORT that happens after a
// do_check failure though.
if (!_quit || e != Components.results.NS_ERROR_ABORT) {
dump("TEST-UNEXPECTED-FAIL | (xpcshell/head.js) | " + e);
if (e.stack) {
dump(" - See following stack:\n");
_dump_exception_stack(e.stack);
}
else {
dump("\n");
}
_do_quit();
}
}
finally {
do_test_finished();
}
}
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
}