Bug 1701777: Fix timeout handling for xorigin mochitests. r=mccr8

This copies some of the basic diagnostic reporting logic from SimpleTest to
TestRunner so that it can report timeout errors without an unnecessary
async roundtrip, and moves timeout handling to use a "message" event which
works in both in-process and out-of-process modes.

Differential Revision: https://phabricator.services.mozilla.com/D110326
This commit is contained in:
Kris Maglione 2021-03-31 02:02:36 +00:00
Родитель 168b2347b3
Коммит 0cb6c22523
2 изменённых файлов: 54 добавлений и 9 удалений

Просмотреть файл

@ -2289,3 +2289,10 @@ var add_task = (function() {
if (usesFailurePatterns()) {
SimpleTest.requestCompleteLog();
}
addEventListener("message", async event => {
if (event.data == "SimpleTest:timeout") {
await SimpleTest.timeout();
SimpleTest.finish();
}
});

Просмотреть файл

@ -138,21 +138,58 @@ TestRunner._timeoutFactor = 1;
TestRunner.jscovDirPrefix = "";
var coverageCollector = {};
function record(succeeded, expectedFail, msg) {
let successInfo;
let failureInfo;
if (expectedFail) {
successInfo = {
status: "PASS",
expected: "FAIL",
message: "TEST-UNEXPECTED-PASS",
};
failureInfo = {
status: "FAIL",
expected: "FAIL",
message: "TEST-KNOWN-FAIL",
};
} else {
successInfo = {
status: "PASS",
expected: "PASS",
message: "TEST-PASS",
};
failureInfo = {
status: "FAIL",
expected: "PASS",
message: "TEST-UNEXPECTED-FAIL",
};
}
let result = succeeded ? successInfo : failureInfo;
TestRunner.structuredLogger.testStatus(
TestRunner.currentTestURL,
msg,
result.status,
result.expected,
"",
""
);
}
TestRunner._checkForHangs = function() {
function reportError(win, msg) {
if ("SimpleTest" in win) {
if (TestRunner.timeoutAsPass) {
win.SimpleTest.record(false, msg, "", "", false);
} else {
win.SimpleTest.ok(false, msg);
}
if (testInXOriginFrame() || "SimpleTest" in win) {
record(false, TestRunner.timeoutAsPass, msg);
} else if ("W3CTest" in win) {
win.W3CTest.logFailure(msg);
}
}
async function killTest(win) {
if ("SimpleTest" in win) {
if (testInXOriginFrame()) {
win.postMessage("SimpleTest:timeout", "*");
} else if ("SimpleTest" in win) {
await win.SimpleTest.timeout();
win.SimpleTest.finish();
} else if ("W3CTest" in win) {
@ -163,9 +200,10 @@ TestRunner._checkForHangs = function() {
if (TestRunner._currentTest < TestRunner._urls.length) {
var runtime = new Date().valueOf() - TestRunner._currentTestStartTime;
if (runtime >= TestRunner.timeout * TestRunner._timeoutFactor) {
let testIframe = $("testframe");
var frameWindow =
$("testframe").contentWindow.wrappedJSObject ||
$("testframe").contentWindow;
(!testInXOriginFrame() && testIframe.contentWindow.wrappedJSObject) ||
testIframe.contentWindow;
// TODO : Do this in a way that reports that the test ended with a status "TIMEOUT"
reportError(frameWindow, "Test timed out.");