From a0c258004ed7729489c71c950b8e4fbacf0996fb Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Sun, 24 Sep 2023 10:38:55 +0000 Subject: [PATCH] Bug 1596056 - Enable ESLint on reftest harness files (automatic fixes). r=tnikkel Depends on D189057 Differential Revision: https://phabricator.services.mozilla.com/D189058 --- layout/tools/reftest/ReftestFissionChild.jsm | 4 +- layout/tools/reftest/manifest.jsm | 81 ++++++++++++++------ layout/tools/reftest/reftest-content.js | 17 ++-- layout/tools/reftest/reftest.jsm | 46 +++++++---- 4 files changed, 101 insertions(+), 47 deletions(-) diff --git a/layout/tools/reftest/ReftestFissionChild.jsm b/layout/tools/reftest/ReftestFissionChild.jsm index bcf7dfac9c5c..1e2be3906c0c 100644 --- a/layout/tools/reftest/ReftestFissionChild.jsm +++ b/layout/tools/reftest/ReftestFissionChild.jsm @@ -27,7 +27,7 @@ class ReftestFissionChild extends JSWindowActorChild { // |this| can be destroyed here and unable to send messages, which is // not a problem, the reftest harness probably torn down the page and // moved on to the next test. - Cu.reportError(e); + console.error(e); } } } @@ -334,7 +334,7 @@ class ReftestFissionChild extends JSWindowActorChild { flushWindow(win.frames[i]); } } catch (e) { - Cu.reportError(e); + console.error(e); } } } diff --git a/layout/tools/reftest/manifest.jsm b/layout/tools/reftest/manifest.jsm index 9b3fa1292e0c..8ad813c9ea62 100644 --- a/layout/tools/reftest/manifest.jsm +++ b/layout/tools/reftest/manifest.jsm @@ -46,7 +46,9 @@ const RE_PREF_ITEM = /^(|test-|ref-)pref\((.+?),(.*)\)$/; function ReadTopManifest(aFileURL, aFilter, aManifestID) { 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 = {}; 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 // read directly in the case of a duplicate if (g.manifestsLoaded.hasOwnProperty(aURL.spec)) { - if (g.manifestsLoaded[aURL.spec] === null) return; - else aFilter = [aFilter[0], aFilter[1], true]; + if (g.manifestsLoaded[aURL.spec] === null) { + return; + } + aFilter = [aFilter[0], aFilter[1], true]; } g.manifestsLoaded[aURL.spec] = aFilter[1]; @@ -110,22 +114,29 @@ function ReadManifest(aURL, aFilter, aManifestID) { } for (var str of lines) { ++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+#/); - if (i >= 0) str = str.substring(0, i); + if (i >= 0) { + str = str.substring(0, i); + } // strip leading and trailing whitespace str = str.replace(/^\s*/, "").replace(/\s*$/, ""); - if (!str || str == "") continue; + if (!str || str == "") { + continue; + } var items = str.split(/\s+/); // split on whitespace if (items[0] == "url-prefix") { - if (items.length != 2) + if (items.length != 2) { throw ( "url-prefix requires one url in manifest file " + aURL.spec + " line " + lineNo ); + } urlprefix = items[1]; continue; } @@ -219,8 +230,9 @@ function ReadManifest(aURL, aFilter, aManifestID) { } } else if ((m = item.match(/^slow-if\((.*?)\)$/))) { cond = false; - if (Cu.evalInSandbox("(" + m[1] + ")", GetOrCreateSandbox())) + if (Cu.evalInSandbox("(" + m[1] + ")", GetOrCreateSandbox())) { slow = true; + } } else if (item == "silentfail") { cond = false; allow_silent_fail = true; @@ -344,7 +356,7 @@ function ReadManifest(aURL, aFilter, aManifestID) { var principal = secMan.createContentPrincipal(aURL, {}); if (items[0] == "include") { - if (items.length != 2) + if (items.length != 2) { throw ( "Error in manifest file " + aURL.spec + @@ -352,7 +364,8 @@ function ReadManifest(aURL, aFilter, aManifestID) { lineNo + ": incorrect number of arguments to include" ); - if (runHttp) + } + if (runHttp) { throw ( "Error in manifest file " + aURL.spec + @@ -360,6 +373,7 @@ function ReadManifest(aURL, aFilter, aManifestID) { lineNo + ": use of include with http" ); + } // If the expected_status is EXPECTED_PASS (the default) then allow // 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) { var type = items[0]; - if (items.length != 2) + if (items.length != 2) { throw ( "Error in manifest file " + aURL.spec + @@ -448,7 +462,8 @@ function ReadManifest(aURL, aFilter, aManifestID) { ": incorrect number of arguments to " + type ); - if (type == TYPE_LOAD && expected_status != EXPECTED_PASS) + } + if (type == TYPE_LOAD && expected_status != EXPECTED_PASS) { throw ( "Error in manifest file " + aURL.spec + @@ -456,6 +471,7 @@ function ReadManifest(aURL, aFilter, aManifestID) { lineNo + ": incorrect known failure type for load test" ); + } AddTestItem( { type: type, @@ -490,7 +506,7 @@ function ReadManifest(aURL, aFilter, aManifestID) { items[0] == TYPE_REFTEST_NOTEQUAL || items[0] == TYPE_PRINT ) { - if (items.length != 3) + if (items.length != 3) { throw ( "Error in manifest file " + aURL.spec + @@ -499,6 +515,7 @@ function ReadManifest(aURL, aFilter, aManifestID) { ": incorrect number of arguments to " + items[0] ); + } if ( items[0] == TYPE_REFTEST_NOTEQUAL && @@ -742,8 +759,7 @@ function BuildConditionSandbox(aURL) { httpProps.forEach(x => (sandbox.http[x] = hh[x])); // set to specific Android13 version (Pixel 5 in CI) - sandbox.Android13 = - sandbox.Android && sandbox.http["platform"] == "Android 13"; + sandbox.Android13 = sandbox.Android && sandbox.http.platform == "Android 13"; // 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 @@ -931,7 +947,9 @@ function CreateUrls(test) { ); function FileToURI(file) { - if (file === null) return file; + if (file === null) { + return file; + } var testURI = g.ioService.newURI(file, null, testbase); let isChromeOrViewSource = @@ -967,7 +985,9 @@ function TestIdentifier(aUrl, aManifestID) { } function AddTestItem(aTest, aFilter, aManifestID) { - if (!aFilter) aFilter = [null, [], false]; + if (!aFilter) { + aFilter = [null, [], false]; + } var identifier = TestIdentifier(aTest.url1, aManifestID); if (aTest.url2 !== null) { @@ -984,21 +1004,33 @@ function AddTestItem(aTest, aFilter, aManifestID) { var manifestFilter = aFilter[1]; var invertManifest = aFilter[2]; if (globalFilter && !globalFilter.test(url1.spec)) { - if (url2 === null) return; - if (globalFilter && !globalFilter.test(url2.spec)) return; + if (url2 === null) { + return; + } + if (globalFilter && !globalFilter.test(url2.spec)) { + return; + } } if (manifestFilter && !(invertManifest ^ manifestFilter.test(url1.spec))) { - if (url2 === null) return; - if (manifestFilter && !(invertManifest ^ manifestFilter.test(url2.spec))) + if (url2 === null) { return; + } + if (manifestFilter && !(invertManifest ^ manifestFilter.test(url2.spec))) { + return; + } } - if (g.focusFilterMode == FOCUS_FILTER_NEEDS_FOCUS_TESTS && !aTest.needsFocus) + if ( + g.focusFilterMode == FOCUS_FILTER_NEEDS_FOCUS_TESTS && + !aTest.needsFocus + ) { return; + } if ( g.focusFilterMode == FOCUS_FILTER_NON_NEEDS_FOCUS_TESTS && aTest.needsFocus - ) + ) { return; + } aTest.identifier = identifier; g.urls.push(aTest); @@ -1006,6 +1038,7 @@ function AddTestItem(aTest, aFilter, aManifestID) { // No-output timeouts during manifest parsing have been a problem for // jsreftests on Android/debug. Any logging resets the no-output timer, // 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..."); + } } diff --git a/layout/tools/reftest/reftest-content.js b/layout/tools/reftest/reftest-content.js index 9374432742a4..48cd27612baf 100644 --- a/layout/tools/reftest/reftest-content.js +++ b/layout/tools/reftest/reftest-content.js @@ -170,15 +170,17 @@ function setupTextZoom(contentRootElement) { if ( !contentRootElement || !contentRootElement.hasAttribute("reftest-text-zoom") - ) + ) { return; + } docShell.browsingContext.textZoom = contentRootElement.getAttribute("reftest-text-zoom"); } function setupFullZoom(contentRootElement) { - if (!contentRootElement || !contentRootElement.hasAttribute("reftest-zoom")) + if (!contentRootElement || !contentRootElement.hasAttribute("reftest-zoom")) { return; + } docShell.browsingContext.fullZoom = contentRootElement.getAttribute("reftest-zoom"); } @@ -343,8 +345,9 @@ function setupAsyncZoom(options) { if ( !contentRootElement || !contentRootElement.hasAttribute("reftest-async-zoom") - ) + ) { return false; + } var zoom = attrOrDefault(contentRootElement, "reftest-async-zoom", 1); if (zoom != 1) { @@ -888,7 +891,9 @@ function WaitForTestEnd( Ci.nsIObserverService ); 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"); state = STATE_WAITING_TO_FINISH; if (operationInProgress) { @@ -1189,7 +1194,9 @@ async function RecordResult(forURL) { var error = ""; var testwindow = content; - if (testwindow.wrappedJSObject) testwindow = testwindow.wrappedJSObject; + if (testwindow.wrappedJSObject) { + testwindow = testwindow.wrappedJSObject; + } var testcases; if ( diff --git a/layout/tools/reftest/reftest.jsm b/layout/tools/reftest/reftest.jsm index b09722441f4a..f758ad273050 100644 --- a/layout/tools/reftest/reftest.jsm +++ b/layout/tools/reftest/reftest.jsm @@ -319,8 +319,9 @@ function InitAndStartRefTests() { } g.windowUtils = g.containingWindow.windowUtils; - if (!g.windowUtils || !g.windowUtils.compareCanvases) + if (!g.windowUtils || !g.windowUtils.compareCanvases) { throw "nsIDOMWindowUtils inteface missing"; + } g.ioService = Cc[IO_SERVICE_CONTRACTID].getService(Ci.nsIIOService); g.debug = Cc[DEBUG_CONTRACTID].getService(Ci.nsIDebug2); @@ -333,7 +334,9 @@ function InitAndStartRefTests() { g.server = new HttpServer(); } try { - if (g.server) StartHTTPServer(); + if (g.server) { + StartHTTPServer(); + } } catch (ex) { //g.browser.loadURI('data:text/plain,' + ex); ++g.testResults.Exception; @@ -449,7 +452,7 @@ function ReadTests() { // Parse reftest manifests logger.debug("Reading " + manifests.length + " manifests"); manifests = JSON.parse(manifests); - g.urlsFilterRegex = manifests[null]; + g.urlsFilterRegex = manifests.null; var globalFilter = null; if (manifests.hasOwnProperty("")) { @@ -560,11 +563,17 @@ function StartTests() { // tURLs is a temporary array containing all active tests var tURLs = new Array(); 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]); } @@ -624,7 +633,9 @@ function StartTests() { } 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 = {}; @@ -645,7 +656,9 @@ function StartTests() { function OnRefTestUnload() {} function AddURIUseCount(uri) { - if (uri == null) return; + if (uri == null) { + return; + } var spec = uri.spec; if (spec in g.uriUseCounts) { @@ -907,9 +920,8 @@ async function StartCurrentURI(aURLTargetType) { g.urls.shift(); await StartCurrentTest(); 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 // our expectations) if (error) { - output = outputs[expected][false]; + output = outputs[expected].false; extra = { status_msg: output.n }; ++g.testResults[output.n]; logger.testEnd( @@ -1269,13 +1281,15 @@ function RecordResult(testRunTime, errorMsg, typeSpecificResults) { // This failure may be due to a JavaScript Engine bug causing // early termination of the test. If we do not allow silent // failure, report an error. - if (!g.urls[0].allowSilentFail) + if (!g.urls[0].allowSilentFail) { 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) { - output = outputs[expected][false]; + output = outputs[expected].false; extra = { status_msg: output.n }; ++g.testResults[output.n]; logger.testStatus( @@ -1301,8 +1315,8 @@ function RecordResult(testRunTime, errorMsg, typeSpecificResults) { // (since we can't tell whether they were really intended to be // marked failing or not). outputPair = { - true: outputs[EXPECTED_RANDOM][true], - false: outputs[expected][false], + true: outputs[EXPECTED_RANDOM].true, + false: outputs[expected].false, }; } else { outputPair = outputs[expected];