Bug 1596056 - Enable ESLint on reftest harness files (automatic fixes). r=tnikkel

Depends on D189057

Differential Revision: https://phabricator.services.mozilla.com/D189058
This commit is contained in:
Mark Banner 2023-09-24 10:38:55 +00:00
parent b8dcda2dd2
commit a0c258004e
4 changed files with 101 additions and 47 deletions

View file

@ -27,7 +27,7 @@ class ReftestFissionChild extends JSWindowActorChild {
// |this| can be destroyed here and unable to send messages, which is // |this| can be destroyed here and unable to send messages, which is
// not a problem, the reftest harness probably torn down the page and // not a problem, the reftest harness probably torn down the page and
// moved on to the next test. // moved on to the next test.
Cu.reportError(e); console.error(e);
} }
} }
} }
@ -334,7 +334,7 @@ class ReftestFissionChild extends JSWindowActorChild {
flushWindow(win.frames[i]); flushWindow(win.frames[i]);
} }
} catch (e) { } catch (e) {
Cu.reportError(e); console.error(e);
} }
} }
} }

View file

@ -46,7 +46,9 @@ const RE_PREF_ITEM = /^(|test-|ref-)pref\((.+?),(.*)\)$/;
function ReadTopManifest(aFileURL, aFilter, aManifestID) { function ReadTopManifest(aFileURL, aFilter, aManifestID) {
var url = g.ioService.newURI(aFileURL); var url = g.ioService.newURI(aFileURL);
if (!url) throw "Expected a file or http URL for the manifest."; if (!url) {
throw "Expected a file or http URL for the manifest.";
}
g.manifestsLoaded = {}; g.manifestsLoaded = {};
ReadManifest(url, aFilter, aManifestID); ReadManifest(url, aFilter, aManifestID);
@ -59,8 +61,10 @@ function ReadManifest(aURL, aFilter, aManifestID) {
// are included with filters will be read via their include before they are // are included with filters will be read via their include before they are
// read directly in the case of a duplicate // read directly in the case of a duplicate
if (g.manifestsLoaded.hasOwnProperty(aURL.spec)) { if (g.manifestsLoaded.hasOwnProperty(aURL.spec)) {
if (g.manifestsLoaded[aURL.spec] === null) return; if (g.manifestsLoaded[aURL.spec] === null) {
else aFilter = [aFilter[0], aFilter[1], true]; return;
}
aFilter = [aFilter[0], aFilter[1], true];
} }
g.manifestsLoaded[aURL.spec] = aFilter[1]; g.manifestsLoaded[aURL.spec] = aFilter[1];
@ -110,22 +114,29 @@ function ReadManifest(aURL, aFilter, aManifestID) {
} }
for (var str of lines) { for (var str of lines) {
++lineNo; ++lineNo;
if (str.charAt(0) == "#") continue; // entire line was a comment if (str.charAt(0) == "#") {
continue;
} // entire line was a comment
var i = str.search(/\s+#/); var i = str.search(/\s+#/);
if (i >= 0) str = str.substring(0, i); if (i >= 0) {
str = str.substring(0, i);
}
// strip leading and trailing whitespace // strip leading and trailing whitespace
str = str.replace(/^\s*/, "").replace(/\s*$/, ""); str = str.replace(/^\s*/, "").replace(/\s*$/, "");
if (!str || str == "") continue; if (!str || str == "") {
continue;
}
var items = str.split(/\s+/); // split on whitespace var items = str.split(/\s+/); // split on whitespace
if (items[0] == "url-prefix") { if (items[0] == "url-prefix") {
if (items.length != 2) if (items.length != 2) {
throw ( throw (
"url-prefix requires one url in manifest file " + "url-prefix requires one url in manifest file " +
aURL.spec + aURL.spec +
" line " + " line " +
lineNo lineNo
); );
}
urlprefix = items[1]; urlprefix = items[1];
continue; continue;
} }
@ -219,8 +230,9 @@ function ReadManifest(aURL, aFilter, aManifestID) {
} }
} else if ((m = item.match(/^slow-if\((.*?)\)$/))) { } else if ((m = item.match(/^slow-if\((.*?)\)$/))) {
cond = false; cond = false;
if (Cu.evalInSandbox("(" + m[1] + ")", GetOrCreateSandbox())) if (Cu.evalInSandbox("(" + m[1] + ")", GetOrCreateSandbox())) {
slow = true; slow = true;
}
} else if (item == "silentfail") { } else if (item == "silentfail") {
cond = false; cond = false;
allow_silent_fail = true; allow_silent_fail = true;
@ -344,7 +356,7 @@ function ReadManifest(aURL, aFilter, aManifestID) {
var principal = secMan.createContentPrincipal(aURL, {}); var principal = secMan.createContentPrincipal(aURL, {});
if (items[0] == "include") { if (items[0] == "include") {
if (items.length != 2) if (items.length != 2) {
throw ( throw (
"Error in manifest file " + "Error in manifest file " +
aURL.spec + aURL.spec +
@ -352,7 +364,8 @@ function ReadManifest(aURL, aFilter, aManifestID) {
lineNo + lineNo +
": incorrect number of arguments to include" ": incorrect number of arguments to include"
); );
if (runHttp) }
if (runHttp) {
throw ( throw (
"Error in manifest file " + "Error in manifest file " +
aURL.spec + aURL.spec +
@ -360,6 +373,7 @@ function ReadManifest(aURL, aFilter, aManifestID) {
lineNo + lineNo +
": use of include with http" ": use of include with http"
); );
}
// If the expected_status is EXPECTED_PASS (the default) then allow // If the expected_status is EXPECTED_PASS (the default) then allow
// the include. If 'skip' is true, that means there was a skip // the include. If 'skip' is true, that means there was a skip
@ -439,7 +453,7 @@ function ReadManifest(aURL, aFilter, aManifestID) {
} }
} else if (items[0] == TYPE_LOAD || items[0] == TYPE_SCRIPT) { } else if (items[0] == TYPE_LOAD || items[0] == TYPE_SCRIPT) {
var type = items[0]; var type = items[0];
if (items.length != 2) if (items.length != 2) {
throw ( throw (
"Error in manifest file " + "Error in manifest file " +
aURL.spec + aURL.spec +
@ -448,7 +462,8 @@ function ReadManifest(aURL, aFilter, aManifestID) {
": incorrect number of arguments to " + ": incorrect number of arguments to " +
type type
); );
if (type == TYPE_LOAD && expected_status != EXPECTED_PASS) }
if (type == TYPE_LOAD && expected_status != EXPECTED_PASS) {
throw ( throw (
"Error in manifest file " + "Error in manifest file " +
aURL.spec + aURL.spec +
@ -456,6 +471,7 @@ function ReadManifest(aURL, aFilter, aManifestID) {
lineNo + lineNo +
": incorrect known failure type for load test" ": incorrect known failure type for load test"
); );
}
AddTestItem( AddTestItem(
{ {
type: type, type: type,
@ -490,7 +506,7 @@ function ReadManifest(aURL, aFilter, aManifestID) {
items[0] == TYPE_REFTEST_NOTEQUAL || items[0] == TYPE_REFTEST_NOTEQUAL ||
items[0] == TYPE_PRINT items[0] == TYPE_PRINT
) { ) {
if (items.length != 3) if (items.length != 3) {
throw ( throw (
"Error in manifest file " + "Error in manifest file " +
aURL.spec + aURL.spec +
@ -499,6 +515,7 @@ function ReadManifest(aURL, aFilter, aManifestID) {
": incorrect number of arguments to " + ": incorrect number of arguments to " +
items[0] items[0]
); );
}
if ( if (
items[0] == TYPE_REFTEST_NOTEQUAL && items[0] == TYPE_REFTEST_NOTEQUAL &&
@ -742,8 +759,7 @@ function BuildConditionSandbox(aURL) {
httpProps.forEach(x => (sandbox.http[x] = hh[x])); httpProps.forEach(x => (sandbox.http[x] = hh[x]));
// set to specific Android13 version (Pixel 5 in CI) // set to specific Android13 version (Pixel 5 in CI)
sandbox.Android13 = sandbox.Android13 = sandbox.Android && sandbox.http.platform == "Android 13";
sandbox.Android && sandbox.http["platform"] == "Android 13";
// Set OSX to be the Mac OS X version, as an integer, or undefined // Set OSX to be the Mac OS X version, as an integer, or undefined
// for other platforms. The integer is formed by 100 times the // for other platforms. The integer is formed by 100 times the
@ -931,7 +947,9 @@ function CreateUrls(test) {
); );
function FileToURI(file) { function FileToURI(file) {
if (file === null) return file; if (file === null) {
return file;
}
var testURI = g.ioService.newURI(file, null, testbase); var testURI = g.ioService.newURI(file, null, testbase);
let isChromeOrViewSource = let isChromeOrViewSource =
@ -967,7 +985,9 @@ function TestIdentifier(aUrl, aManifestID) {
} }
function AddTestItem(aTest, aFilter, aManifestID) { function AddTestItem(aTest, aFilter, aManifestID) {
if (!aFilter) aFilter = [null, [], false]; if (!aFilter) {
aFilter = [null, [], false];
}
var identifier = TestIdentifier(aTest.url1, aManifestID); var identifier = TestIdentifier(aTest.url1, aManifestID);
if (aTest.url2 !== null) { if (aTest.url2 !== null) {
@ -984,21 +1004,33 @@ function AddTestItem(aTest, aFilter, aManifestID) {
var manifestFilter = aFilter[1]; var manifestFilter = aFilter[1];
var invertManifest = aFilter[2]; var invertManifest = aFilter[2];
if (globalFilter && !globalFilter.test(url1.spec)) { if (globalFilter && !globalFilter.test(url1.spec)) {
if (url2 === null) return; if (url2 === null) {
if (globalFilter && !globalFilter.test(url2.spec)) return; return;
}
if (globalFilter && !globalFilter.test(url2.spec)) {
return;
}
} }
if (manifestFilter && !(invertManifest ^ manifestFilter.test(url1.spec))) { if (manifestFilter && !(invertManifest ^ manifestFilter.test(url1.spec))) {
if (url2 === null) return; if (url2 === null) {
if (manifestFilter && !(invertManifest ^ manifestFilter.test(url2.spec)))
return; return;
} }
if (g.focusFilterMode == FOCUS_FILTER_NEEDS_FOCUS_TESTS && !aTest.needsFocus) if (manifestFilter && !(invertManifest ^ manifestFilter.test(url2.spec))) {
return; return;
}
}
if (
g.focusFilterMode == FOCUS_FILTER_NEEDS_FOCUS_TESTS &&
!aTest.needsFocus
) {
return;
}
if ( if (
g.focusFilterMode == FOCUS_FILTER_NON_NEEDS_FOCUS_TESTS && g.focusFilterMode == FOCUS_FILTER_NON_NEEDS_FOCUS_TESTS &&
aTest.needsFocus aTest.needsFocus
) ) {
return; return;
}
aTest.identifier = identifier; aTest.identifier = identifier;
g.urls.push(aTest); g.urls.push(aTest);
@ -1006,6 +1038,7 @@ function AddTestItem(aTest, aFilter, aManifestID) {
// No-output timeouts during manifest parsing have been a problem for // No-output timeouts during manifest parsing have been a problem for
// jsreftests on Android/debug. Any logging resets the no-output timer, // jsreftests on Android/debug. Any logging resets the no-output timer,
// even debug logging which is normally not displayed. // even debug logging which is normally not displayed.
if (g.urls.length % 5000 == 0) if (g.urls.length % 5000 == 0) {
g.logger.debug(g.urls.length + " tests found..."); g.logger.debug(g.urls.length + " tests found...");
}
} }

View file

@ -170,15 +170,17 @@ function setupTextZoom(contentRootElement) {
if ( if (
!contentRootElement || !contentRootElement ||
!contentRootElement.hasAttribute("reftest-text-zoom") !contentRootElement.hasAttribute("reftest-text-zoom")
) ) {
return; return;
}
docShell.browsingContext.textZoom = docShell.browsingContext.textZoom =
contentRootElement.getAttribute("reftest-text-zoom"); contentRootElement.getAttribute("reftest-text-zoom");
} }
function setupFullZoom(contentRootElement) { function setupFullZoom(contentRootElement) {
if (!contentRootElement || !contentRootElement.hasAttribute("reftest-zoom")) if (!contentRootElement || !contentRootElement.hasAttribute("reftest-zoom")) {
return; return;
}
docShell.browsingContext.fullZoom = docShell.browsingContext.fullZoom =
contentRootElement.getAttribute("reftest-zoom"); contentRootElement.getAttribute("reftest-zoom");
} }
@ -343,8 +345,9 @@ function setupAsyncZoom(options) {
if ( if (
!contentRootElement || !contentRootElement ||
!contentRootElement.hasAttribute("reftest-async-zoom") !contentRootElement.hasAttribute("reftest-async-zoom")
) ) {
return false; return false;
}
var zoom = attrOrDefault(contentRootElement, "reftest-async-zoom", 1); var zoom = attrOrDefault(contentRootElement, "reftest-async-zoom", 1);
if (zoom != 1) { if (zoom != 1) {
@ -888,7 +891,9 @@ function WaitForTestEnd(
Ci.nsIObserverService Ci.nsIObserverService
); );
var flushWaiter = function (aSubject, aTopic, aData) { var flushWaiter = function (aSubject, aTopic, aData) {
if (aTopic) LogInfo("MakeProgress: apz-repaints-flushed fired"); if (aTopic) {
LogInfo("MakeProgress: apz-repaints-flushed fired");
}
os.removeObserver(flushWaiter, "apz-repaints-flushed"); os.removeObserver(flushWaiter, "apz-repaints-flushed");
state = STATE_WAITING_TO_FINISH; state = STATE_WAITING_TO_FINISH;
if (operationInProgress) { if (operationInProgress) {
@ -1189,7 +1194,9 @@ async function RecordResult(forURL) {
var error = ""; var error = "";
var testwindow = content; var testwindow = content;
if (testwindow.wrappedJSObject) testwindow = testwindow.wrappedJSObject; if (testwindow.wrappedJSObject) {
testwindow = testwindow.wrappedJSObject;
}
var testcases; var testcases;
if ( if (

View file

@ -319,8 +319,9 @@ function InitAndStartRefTests() {
} }
g.windowUtils = g.containingWindow.windowUtils; g.windowUtils = g.containingWindow.windowUtils;
if (!g.windowUtils || !g.windowUtils.compareCanvases) if (!g.windowUtils || !g.windowUtils.compareCanvases) {
throw "nsIDOMWindowUtils inteface missing"; throw "nsIDOMWindowUtils inteface missing";
}
g.ioService = Cc[IO_SERVICE_CONTRACTID].getService(Ci.nsIIOService); g.ioService = Cc[IO_SERVICE_CONTRACTID].getService(Ci.nsIIOService);
g.debug = Cc[DEBUG_CONTRACTID].getService(Ci.nsIDebug2); g.debug = Cc[DEBUG_CONTRACTID].getService(Ci.nsIDebug2);
@ -333,7 +334,9 @@ function InitAndStartRefTests() {
g.server = new HttpServer(); g.server = new HttpServer();
} }
try { try {
if (g.server) StartHTTPServer(); if (g.server) {
StartHTTPServer();
}
} catch (ex) { } catch (ex) {
//g.browser.loadURI('data:text/plain,' + ex); //g.browser.loadURI('data:text/plain,' + ex);
++g.testResults.Exception; ++g.testResults.Exception;
@ -449,7 +452,7 @@ function ReadTests() {
// Parse reftest manifests // Parse reftest manifests
logger.debug("Reading " + manifests.length + " manifests"); logger.debug("Reading " + manifests.length + " manifests");
manifests = JSON.parse(manifests); manifests = JSON.parse(manifests);
g.urlsFilterRegex = manifests[null]; g.urlsFilterRegex = manifests.null;
var globalFilter = null; var globalFilter = null;
if (manifests.hasOwnProperty("")) { if (manifests.hasOwnProperty("")) {
@ -560,11 +563,17 @@ function StartTests() {
// tURLs is a temporary array containing all active tests // tURLs is a temporary array containing all active tests
var tURLs = new Array(); var tURLs = new Array();
for (var i = 0; i < g.urls.length; ++i) { for (var i = 0; i < g.urls.length; ++i) {
if (g.urls[i].skip) continue; if (g.urls[i].skip) {
continue;
}
if (g.urls[i].needsFocus && !Focus()) continue; if (g.urls[i].needsFocus && !Focus()) {
continue;
}
if (g.urls[i].slow && !g.runSlowTests) continue; if (g.urls[i].slow && !g.runSlowTests) {
continue;
}
tURLs.push(g.urls[i]); tURLs.push(g.urls[i]);
} }
@ -624,7 +633,9 @@ function StartTests() {
} }
g.totalTests = g.urls.length; g.totalTests = g.urls.length;
if (!g.totalTests && !g.verify && !g.repeat) throw "No tests to run"; if (!g.totalTests && !g.verify && !g.repeat) {
throw "No tests to run";
}
g.uriCanvases = {}; g.uriCanvases = {};
@ -645,7 +656,9 @@ function StartTests() {
function OnRefTestUnload() {} function OnRefTestUnload() {}
function AddURIUseCount(uri) { function AddURIUseCount(uri) {
if (uri == null) return; if (uri == null) {
return;
}
var spec = uri.spec; var spec = uri.spec;
if (spec in g.uriUseCounts) { if (spec in g.uriUseCounts) {
@ -907,9 +920,8 @@ async function StartCurrentURI(aURLTargetType) {
g.urls.shift(); g.urls.shift();
await StartCurrentTest(); await StartCurrentTest();
return; return;
} else {
throw e;
} }
throw e;
} }
} }
@ -1211,7 +1223,7 @@ function RecordResult(testRunTime, errorMsg, typeSpecificResults) {
// (If it's empty, we'll spuriously succeed, regardless of // (If it's empty, we'll spuriously succeed, regardless of
// our expectations) // our expectations)
if (error) { if (error) {
output = outputs[expected][false]; output = outputs[expected].false;
extra = { status_msg: output.n }; extra = { status_msg: output.n };
++g.testResults[output.n]; ++g.testResults[output.n];
logger.testEnd( logger.testEnd(
@ -1269,13 +1281,15 @@ function RecordResult(testRunTime, errorMsg, typeSpecificResults) {
// This failure may be due to a JavaScript Engine bug causing // This failure may be due to a JavaScript Engine bug causing
// early termination of the test. If we do not allow silent // early termination of the test. If we do not allow silent
// failure, report an error. // failure, report an error.
if (!g.urls[0].allowSilentFail) if (!g.urls[0].allowSilentFail) {
errorMsg = "No test results reported. (SCRIPT)\n"; errorMsg = "No test results reported. (SCRIPT)\n";
else logger.info("An expected silent failure occurred"); } else {
logger.info("An expected silent failure occurred");
}
} }
if (errorMsg) { if (errorMsg) {
output = outputs[expected][false]; output = outputs[expected].false;
extra = { status_msg: output.n }; extra = { status_msg: output.n };
++g.testResults[output.n]; ++g.testResults[output.n];
logger.testStatus( logger.testStatus(
@ -1301,8 +1315,8 @@ function RecordResult(testRunTime, errorMsg, typeSpecificResults) {
// (since we can't tell whether they were really intended to be // (since we can't tell whether they were really intended to be
// marked failing or not). // marked failing or not).
outputPair = { outputPair = {
true: outputs[EXPECTED_RANDOM][true], true: outputs[EXPECTED_RANDOM].true,
false: outputs[expected][false], false: outputs[expected].false,
}; };
} else { } else {
outputPair = outputs[expected]; outputPair = outputs[expected];