Bug 1791282 - Enable all ESLint rules on testing/mochitest files. r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D157586
This commit is contained in:
Mark Banner 2022-09-21 14:53:18 +00:00
parent 58f9ba8b8d
commit d8d50459f8
6 changed files with 29 additions and 60 deletions

View file

@ -378,36 +378,6 @@ module.exports = {
"no-with": "off",
},
},
{
files: [
"testing/mochitest/browser-harness.xhtml",
"testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
"testing/mochitest/chrome/test_sanityEventUtils.xhtml",
"testing/mochitest/chrome/test_sanityException.xhtml",
"testing/mochitest/chrome/test_sanityException2.xhtml",
"testing/mochitest/harness.xhtml",
],
rules: {
"dot-notation": "off",
"object-shorthand": "off",
"mozilla/use-services": "off",
"mozilla/no-compare-against-boolean-literals": "off",
"mozilla/no-useless-parameters": "off",
"mozilla/no-useless-removeEventListener": "off",
"mozilla/use-cc-etc": "off",
"consistent-return": "off",
"no-fallthrough": "off",
"no-nested-ternary": "off",
"no-redeclare": "off",
"no-sequences": "off",
"no-shadow": "off",
"no-throw-literal": "off",
"no-undef": "off",
"no-unsanitized/property": "off",
"no-unused-vars": "off",
"no-useless-call": "off",
},
},
{
files: [
"dom/base/test/chrome/file_bug1139964.xhtml",

View file

@ -80,14 +80,14 @@
return this.fileLogger = logger;
},
structuredLogger: TestRunner.structuredLogger,
dump: function (str) {
dump(str) {
this.structuredLogger.info(str);
if (this.fileLogger)
this.fileLogger.log(str);
},
done: function () {
done() {
if (this.fileLogger)
this.fileLogger.close();
}
@ -108,10 +108,10 @@
var gErrorCount = 0;
function browserTest(aTestFile) {
this.path = aTestFile['url'];
this.expected = aTestFile['expected'];
this.https_first_disabled = aTestFile['https_first_disabled'] || false,
this.allow_xul_xbl = aTestFile['allow_xul_xbl'] || false,
this.path = aTestFile.url;
this.expected = aTestFile.expected;
this.https_first_disabled = aTestFile.https_first_disabled || false;
this.allow_xul_xbl = aTestFile.allow_xul_xbl || false;
this.dumper = gDumper;
this.results = [];
this.scope = null;
@ -223,11 +223,11 @@
}
// load server.js in so we can share template functions
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
var srvScope = {};
scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
srvScope);
Services.scriptloader.loadSubScript(
'chrome://mochikit/content/server.js',
srvScope
);
var fileNames = [];
var fileNameRegexp = /browser_.+\.js$/;
@ -245,8 +245,6 @@
}
function createTester(links) {
var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
getService(Ci.nsIWindowMediator);
var winType = null;
if (gConfig.testRoot == "browser") {
const IS_THUNDERBIRD = Services.appinfo.ID == "{3550f703-e582-4d05-9a08-453d09bdfdc6}";
@ -255,7 +253,7 @@
if (!winType) {
throw new Error("Unrecognized gConfig.testRoot: " + gConfig.testRoot);
}
var testWin = windowMediator.getMostRecentWindow(winType);
var testWin = Services.wm.getMostRecentWindow(winType);
setStatus("Running...");
@ -274,23 +272,20 @@
}
function executeSoon(callback) {
let tm = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
tm.dispatchToMainThread(callback);
Services.tm.dispatchToMainThread(callback);
}
function waitForFocus(callback, win) {
// If "win" is already focused, just call the callback.
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
if (fm.focusedWindow == win) {
if (Services.focus.focusedWindow == win) {
executeSoon(callback);
return;
}
// Otherwise focus it, and wait for the focus event.
win.addEventListener("focus", function listener() {
win.removeEventListener("focus", listener, true);
executeSoon(callback);
}, true);
}, { capture: true, once: true});
win.focus();
}
@ -309,8 +304,11 @@
var failCount = aTests.map(f => f.failCount).reduce(sum);
var todoCount = aTests.map(f => f.todoCount).reduce(sum);
log += "<div id=\"summary\" class=\"";
log += failCount != 0 ? "failure" :
passCount == 0 ? "todo" : "success";
if (failCount != 0) {
log += "failure";
} else {
log += passCount == 0 ? "todo" : "success";
}
log += "\">\n<p>Passed: " + passCount + "</p>\n" +
"<p>Failed: " + failCount;
if (failCount > 0)
@ -355,6 +353,7 @@
window.focus();
// UI
// eslint-disable-next-line no-unsanitized/property
document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
setStatus("Done.");
}

View file

@ -17,9 +17,7 @@
<script type="application/javascript">
<![CDATA[
info("\nProfile::EventUtilsLoadTime: " + (loadTime - start) + "\n");
var testFile = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("CurWorkD", Ci.nsIFile);
var testFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
var regularDtForDrag1 = null;
var gSetDropEffect = true;
var gData;
@ -61,7 +59,7 @@
var dragfile = [[
{ type : "application/x-moz-file",
data : testFile,
eqTest : function(actualData, expectedData) {return expectedData.equals(actualData);} },
eqTest(actualData, expectedData) {return expectedData.equals(actualData);} },
{ type : "Files",
data : null }
]];
@ -77,6 +75,7 @@
switch (aEvent.currentTarget.id) {
case "drag2" :
dt.setData("text/plain", "this is text/plain");
// fallthrough
case "drag1" :
regularDtForDrag1 = dt;
dt.setData("text/uri-list", "http://www.mozilla.org/");

View file

@ -15,6 +15,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=670817
SimpleTest.expectUncaughtException();
ok(true, "a call to ok");
// eslint-disable-next-line no-throw-literal
throw "this is a deliberately thrown exception";
]]></script>

View file

@ -17,6 +17,7 @@ SimpleTest.waitForExplicitFinish();
ok(true, "a call to ok");
SimpleTest.executeSoon(function() {
SimpleTest.expectUncaughtException();
// eslint-disable-next-line no-throw-literal
throw "this is a deliberately thrown exception";
});
SimpleTest.executeSoon(function() {

View file

@ -20,16 +20,14 @@
function loadTests()
{
window.removeEventListener("load", loadTests, false);
window.removeEventListener("load", loadTests);
getTestList({}, linkAndHookup);
}
function linkAndHookup(links) {
// load server.js in so we can share template functions
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
var srvScope = {};
scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
Services.scriptloader.loadSubScript('chrome://mochikit/content/server.js',
srvScope);
// generate our test list
@ -37,6 +35,7 @@ function linkAndHookup(links) {
var tableContent = srvScope.linksToTableRows(links, 0);
function populate() {
// eslint-disable-next-line no-unsanitized/property
document.getElementById("test-table").innerHTML += tableContent;
}
gTestList = JSON.parse(srvScope.jsonArrayOfTestFiles(links));
@ -45,7 +44,7 @@ function linkAndHookup(links) {
hookup();
}
window.addEventListener("load", loadTests, false);
window.addEventListener("load", loadTests);
]]>
</script>