Bug 1614822 - Enable ESLint for testing/mochitest/tests/Harness_sanity/. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D62512

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Banner 2020-02-12 19:38:40 +00:00
parent 8dc9ea96b7
commit 556504ff93
17 changed files with 55 additions and 40 deletions

View File

@ -175,9 +175,6 @@ services/fxaccounts/FxAccountsPairingChannel.js
# Servo is imported.
servo/
# third party modules
testing/mochitest/tests/Harness_sanity/
# Test files that we don't want to lint (preprocessed, minified etc)
testing/marionette/atom.js
testing/mozbase/mozprofile/tests/files/prefs_with_comments.js

View File

@ -32,6 +32,7 @@ const mochitestTestPaths = [
"**/test/mochitest/",
"**/tests/mochitest/",
"testing/mochitest/tests/SimpleTest/",
"testing/mochitest/tests/Harness_sanity/",
];
const chromeTestPaths = [

View File

@ -1,10 +1,13 @@
/* eslint-env mozilla/frame-script */
/* global assert */
// Just receive 'foo' message and forward it back
// as 'bar' message
addMessageListener("foo", function (message) {
addMessageListener("foo", function(message) {
sendAsyncMessage("bar", message);
});
addMessageListener("valid-assert", function (message) {
addMessageListener("valid-assert", function(message) {
assert.ok(true, "valid assertion");
assert.equal(1, 1, "another valid assertion");
sendAsyncMessage("valid-assert-done");

View File

@ -1,3 +1,5 @@
addMessageListener("ImportTesting:IsModuleLoaded", function (msg) {
/* eslint-env mozilla/frame-script */
addMessageListener("ImportTesting:IsModuleLoaded", function(msg) {
sendAsyncMessage("ImportTesting:IsModuleLoadedReply", Cu.isModuleLoaded(msg));
});

View File

@ -1,13 +1,15 @@
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
/* eslint-env mozilla/frame-script */
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var permChangedObs = {
observe: function(subject, topic, data) {
if (topic == 'perm-changed') {
observe(subject, topic, data) {
if (topic == "perm-changed") {
var permission = subject.QueryInterface(Ci.nsIPermission);
var msg = { op: data, type: permission.type };
sendAsyncMessage('perm-changed', msg);
sendAsyncMessage("perm-changed", msg);
}
}
},
};
Services.obs.addObserver(permChangedObs, 'perm-changed');
Services.obs.addObserver(permChangedObs, "perm-changed");

View File

@ -54,6 +54,7 @@ async function starttest(){
// Test an invalid pref
var retVal = null;
// eslint-disable-next-line mozilla/use-default-preference-values
try {
retVal = SpecialPowers.getBoolPref('extensions.checkCompat0123456789');
} catch (ex) {
@ -71,7 +72,7 @@ async function starttest(){
SpecialPowers.removeChromeEventListener("TestEvent", testEventListener2, true);
dispatchTestEvent();
is(eventCount, 1, "Shouldn't have got an event!");
// Test Complex Pref - TODO: Without chrome access, I don't know how you'd actually
// set this preference since you have to create an XPCOM object.
// Leaving untested for now.
@ -79,7 +80,7 @@ async function starttest(){
// Test a DOMWindowUtils method and property
is(SpecialPowers.DOMWindowUtils.getClassName(window), "Proxy");
is(SpecialPowers.DOMWindowUtils.docCharsetIsForced, false);
// QueryInterface and getPrivilegedProps tests
is(SpecialPowers.can_QI(SpecialPowers), false);
let doc = SpecialPowers.wrap(document);
@ -91,7 +92,7 @@ async function starttest(){
is(SpecialPowers.getPrivilegedProps(doc, "baseURIObject.fileName"),
"test_SpecialPowersExtension.html",
"Should have a fileName property now");
//try to run garbage collection
SpecialPowers.gc();

View File

@ -9,6 +9,9 @@
<pre id="test">
<script class="testbody" type="text/javascript">
/* eslint-env mozilla/frame-script */
/* global assert */
SimpleTest.waitForExplicitFinish();
var url = SimpleTest.getTestFileURL("SpecialPowersLoadChromeScript.js");

View File

@ -9,6 +9,9 @@
<pre id="test">
<script class="testbody" type="text/javascript">
/* eslint-env mozilla/frame-script */
/* global assert */
SimpleTest.waitForExplicitFinish();

View File

@ -12,6 +12,7 @@
SimpleTest.waitForExplicitFinish();
/* eslint-disable mozilla/use-services */
function loadPrivilegedScriptTest() {
function isMainProcess() {
return Cc["@mozilla.org/xre/app-info;1"].
@ -29,7 +30,7 @@ try {
ok(false, "loadPrivilegedScript shoulde not throw");
}
port.onmessage = (e) => {
is(contentProcessType, e.data['isMainProcess'], "content and the script should be in the same process");
is(contentProcessType, e.data.isMainProcess, "content and the script should be in the same process");
SimpleTest.finish();
};
</script>

View File

@ -71,15 +71,15 @@ add_task(async function() {
},
"SpecialPowers.spawn-subframe": () => {
return SpecialPowers.spawn(frame, [subframeSrc], async src => {
let frame = this.content.document.createElement("iframe");
frame.src = src;
this.content.document.body.appendChild(frame);
let subFrame = this.content.document.createElement("iframe");
subFrame.src = src;
this.content.document.body.appendChild(subFrame);
await new Promise(resolve => {
frame.addEventListener("load", resolve, { once: true });
subFrame.addEventListener("load", resolve, { once: true });
});
await SpecialPowers.spawn(frame, [], () => {
await SpecialPowers.spawn(subFrame, [], () => {
Assert.equal(1, 2, "Thing");
Assert.equal(1, 1, "Hmm");
Assert.ok(true, "Yay.");

View File

@ -30,6 +30,7 @@
is(result, "Hello there.", "Got correct element text from frame");
/* eslint-disable no-shadow */
result = await SpecialPowers.spawn(frame, ["#hello"], selector => {
return SpecialPowers.spawn(content.parent, [selector], selector => {
let elem = content.document.querySelector(selector);
@ -54,7 +55,7 @@
is(result, "Hello there.", "Got correct element text from browsing context");
let line = 58; // Keep this in sync with the line number where the callback function starts.
let line = 59; // Keep this in sync with the line number where the callback function starts.
let callback = () => {
let e = new Error("Hello.");
return { filename: e.fileName, lineNumber: e.lineNumber };

View File

@ -50,7 +50,7 @@ function starttest() {
$("testMouseEvent").addEventListener("click", doCheck, {once: true});
sendMouseEvent({type:'click'}, "testMouseEvent");
is(check, true, 'sendMouseEvent should dispatch click event');
check = false;
$("testKeyEvent").addEventListener("keypress", doCheck, {once: true});
$("testKeyEvent").focus();
@ -58,12 +58,12 @@ function starttest() {
is($("testKeyEvent").value, "x", "sendChar should work");
is(check, true, "sendChar should dispatch keyPress");
$("testKeyEvent").value = "";
$("testStrEvent").focus();
sendString("string");
is($("testStrEvent").value, "string", "sendString should work");
$("testStrEvent").value = "";
var keydown = false;
var keypress = false;
$("testKeyEvent").focus();
@ -76,7 +76,7 @@ function starttest() {
} else {
ok(keypress, "sendKey should dispatch keyPress even for non-printable key");
}
/* test synthesizeMouse* */
//focus trick enables us to run this in iframes
$("radioTarget1").addEventListener('focus', function (aEvent) {
@ -97,22 +97,22 @@ function starttest() {
$("textBoxA").addEventListener("click", function() { check = true; });
synthesizeMouseAtCenter($("textBoxA"), {});
is(check, true, 'synthesizeMouse should dispatch mouse event');
check = false;
synthesizeMouseExpectEvent($("textBoxA"), 1, 1, {}, $("textBoxA"), "click", "synthesizeMouseExpectEvent should fire click event");
is(check, true, 'synthesizeMouse should dispatch mouse event');
}, {once: true});
$("textBoxA").focus();
/**
* TODO: testing synthesizeWheel requires a setTimeout
* TODO: testing synthesizeWheel requires a setTimeout
* since there is delay between the scroll event and a check, so for now just test
* that we can successfully call it to avoid having setTimeout vary the runtime metric.
* Testing of this method is currently done here:
* toolkit/content/tests/chrome/test_mousescroll.xul
*/
synthesizeWheel($("scrollB"), 5, 5, {'deltaY': 10.0, deltaMode: WheelEvent.DOM_DELTA_LINE});
/* test synthesizeKey* */
check = false;
$("testKeyEvent").addEventListener("keypress", doCheck, {once:true});
@ -150,18 +150,18 @@ function starttest() {
{ arg: "~", code: "Backquote", keyCode: KeyboardEvent.DOM_VK_BACK_QUOTE },
{ arg: "<", code: "Comma", keyCode: KeyboardEvent.DOM_VK_COMMA },
{ arg: ".", code: "Period", keyCode: KeyboardEvent.DOM_VK_PERIOD }]) {
let keydown, keyup;
let testKeydown, keyup;
$("testKeyEvent").focus();
$("testKeyEvent").addEventListener("keydown", (e) => { keydown = e; }, {once: true});
$("testKeyEvent").addEventListener("keydown", (e) => { testKeydown = e; }, {once: true});
$("testKeyEvent").addEventListener("keyup", (e) => { keyup = e; }, {once: true});
synthesizeKey(test.arg);
is(keydown.code, test.code, `Synthesizing "${test.arg}" should set code value of "keydown" to "${test.code}"`);
is(keydown.keyCode, test.keyCode, `Synthesizing "${test.arg}" should set keyCode value of "keydown" to "${test.keyCode}"`);
is(testKeydown.code, test.code, `Synthesizing "${test.arg}" should set code value of "keydown" to "${test.code}"`);
is(testKeydown.keyCode, test.keyCode, `Synthesizing "${test.arg}" should set keyCode value of "keydown" to "${test.keyCode}"`);
is(keyup.code, test.code, `Synthesizing "${test.arg}" key should set code value of "keyup" to "${test.code}"`);
is(keyup.keyCode, test.keyCode, `Synthesizing "${test.arg}" key should set keyCode value of "keyup" to "${test.keyCode}"`);
$("testKeyEvent").value = "";
}
/* test synthesizeComposition */
var description = "";
var keydownEvent = null;
@ -272,7 +272,7 @@ function starttest() {
is(querySelectedText.text, "",
"query selected text event returns wrong selected text");
$("textBoxB").value = "";
querySelectedText = synthesizeQuerySelectedText();
ok(querySelectedText, "query selected text event result is null");
ok(querySelectedText.succeeded, "query selected text event failed");

View File

@ -9,6 +9,7 @@
<script>
ok(true, "a call to ok");
SimpleTest.expectUncaughtException();
// eslint-disable-next-line no-throw-literal
throw "an uncaught exception";
</script>
</body>

View File

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

View File

@ -84,6 +84,7 @@ function starttest() {
//expect and throw exception here. Otherwise, any code that follows the throw call will never be executed
SimpleTest.expectUncaughtException();
//make sure we catch this error
// eslint-disable-next-line no-throw-literal
throw "i am an uncaught exception"
}
);

View File

@ -9,7 +9,7 @@
</head>
<body>
<script class="testbody" type="text/javascript">
for (pref of [1, 2]) {
for (const pref of [1, 2]) {
try {
SpecialPowers.getBoolPref("simpletest.cleanup." + pref);
ok(false, "Cleanup function should have unset pref");

View File

@ -14,13 +14,11 @@ var capturedFailures = [];
window.ok = function (cond, name) {
if (!captureFailure) {
SimpleTest.ok(cond, name);
} else {
if (cond) {
} else if (cond) {
SimpleTest.ok(false, `Expect a failure with "${name}"`);
} else {
capturedFailures.push(name);
}
}
};
SimpleTest.waitForExplicitFinish();