diff --git a/dom/imptests/testharnessreport.js b/dom/imptests/testharnessreport.js index db269d78f87..82da2e13832 100644 --- a/dom/imptests/testharnessreport.js +++ b/dom/imptests/testharnessreport.js @@ -101,27 +101,51 @@ var W3CTest = { this.expectedFailures[url] === "error" }); this.runner.testFinished(this.tests); + }, + + /** + * Log an unexpected failure. Intended to be used from harness code, not + * from tests. + */ + "logFailure": function(message) { + this.report({ + "message": message, + "result": false, + "todo": false + }); + }, + + /** + * Timeout the current test. Intended to be used from harness code, not + * from tests. + */ + "timeout": function() { + timeout(); } }; (function() { - if (!W3CTest.runner) { - return; - } - // Get expected fails. If there aren't any, there will be a 404, which is - // fine. Anything else is unexpected. - var request = new XMLHttpRequest(); - request.open("GET", "/tests/dom/imptests/failures/" + W3CTest.getURL() + ".json", false); - request.send(); - if (request.status === 200) { - W3CTest.expectedFailures = JSON.parse(request.responseText); - } else if (request.status !== 404) { - is(request.status, 404, "Request status neither 200 nor 404"); - } + try { + if (!W3CTest.runner) { + return; + } + // Get expected fails. If there aren't any, there will be a 404, which is + // fine. Anything else is unexpected. + var request = new XMLHttpRequest(); + request.open("GET", "/tests/dom/imptests/failures/" + W3CTest.getURL() + ".json", false); + request.send(); + if (request.status === 200) { + W3CTest.expectedFailures = JSON.parse(request.responseText); + } else if (request.status !== 404) { + W3CTest.logFailure("Request status was " + request.status); + } - add_result_callback(W3CTest.result.bind(W3CTest)); - add_completion_callback(W3CTest.finish.bind(W3CTest)); - setup({ - "output": false, - "timeout": 1000000, - }); + add_result_callback(W3CTest.result.bind(W3CTest)); + add_completion_callback(W3CTest.finish.bind(W3CTest)); + setup({ + "output": false, + "timeout": 1000000 + }); + } catch (e) { + W3CTest.logFailure("Unexpected exception: " + e); + } })(); diff --git a/testing/mochitest/tests/SimpleTest/TestRunner.js b/testing/mochitest/tests/SimpleTest/TestRunner.js index 3724710bdd9..ca7dd19f9c8 100644 --- a/testing/mochitest/tests/SimpleTest/TestRunner.js +++ b/testing/mochitest/tests/SimpleTest/TestRunner.js @@ -93,11 +93,7 @@ TestRunner._checkForHangs = function() { if ("SimpleTest" in win) { win.SimpleTest.ok(false, msg); } else if ("W3CTest" in win) { - win.W3CTest.report({ - "message": msg, - "result": false, - "todo": false - }); + win.W3CTest.logFailure(msg); } } @@ -105,7 +101,7 @@ TestRunner._checkForHangs = function() { if ("SimpleTest" in win) { win.SimpleTest.finish(); } else if ("W3CTest" in win) { - win.W3CTest.kill(); + win.W3CTest.timeout(); } }