Bug 1780071 - Manual fixes/disabling of no-comparison-or-assignment-inside-ok for exceptional cases, r=Standard8,devtools-reviewers,anti-tracking-reviewers,places-reviewers,dom-storage-reviewers,pbz,asuth,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D198979
This commit is contained in:
Gijs Kruitbosch 2024-02-19 23:30:40 +00:00
parent 02ba212707
commit ff17e7fc68
68 changed files with 162 additions and 35 deletions

View file

@ -34,7 +34,11 @@ add_task(async function () {
const events = getTelemetryEvents("jsdebugger");
const openToolboxEvent = events.find(event => event.method == "enter");
ok(openToolboxEvent.session_id > 0, "Event has a valid session id");
Assert.greater(
Number(openToolboxEvent.session_id),
0,
"Event has a valid session id"
);
is(
openToolboxEvent.start_state,
"application",

View file

@ -82,7 +82,11 @@ function checkTelemetryEvent(expectedEvent, objectName = "application") {
// assert we only got 1 event with a valid session ID
is(events.length, 1, "There was only 1 event logged");
const [event] = events;
ok(event.session_id > 0, "There is a valid session_id in the event");
Assert.greater(
Number(event.session_id),
0,
"There is a valid session_id in the event"
);
// assert expected data
Assert.deepEqual(event, { ...expectedEvent, session_id: event.session_id });

View file

@ -56,6 +56,8 @@ add_task(async function testSourceTreeNamesForWebExtensions() {
});
await ToolboxTask.spawn(null, async () => {
// Disable autofixing to `Assert` methods which are not available here.
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
try {
/* global gToolbox */
// Wait for the debugger to finish loading.

View file

@ -2,6 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// This file is loaded in a `spawn` context sometimes which doesn't have,
// `Assert`, so we can't use its comparison functions.
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
/**
* Helper methods to drive with the debugger during mochitests. This file can be safely
* required from other panel test files.

View file

@ -103,6 +103,6 @@ async function checkResults() {
// extras
is(extra.host, expected.extra.host, "host is correct");
ok(extra.width > 0, "width is greater than 0");
Assert.greater(Number(extra.width), 0, "width is greater than 0");
}
}

View file

@ -144,7 +144,7 @@ async function checkResults() {
// extras
is(extra.host, expected.extra.host, "host is correct");
ok(extra.width > 0, "width is greater than 0");
Assert.greater(Number(extra.width), 0, "width is greater than 0");
is(extra.start_state, expected.extra.start_state, "start_state is correct");
is(extra.panel_name, expected.extra.panel_name, "panel_name is correct");
is(extra.cold, expected.extra.cold, "cold is correct");

View file

@ -121,7 +121,7 @@ async function checkResults() {
// extras
is(extra.host, expected.extra.host, "host is correct");
ok(extra.width > 0, "width is greater than 0");
Assert.greater(Number(extra.width), 0, "width is greater than 0");
is(extra.panel_name, expected.extra.panel_name, "panel_name is correct");
is(extra.next_panel, expected.extra.next_panel, "next_panel is correct");
is(extra.reason, expected.extra.reason, "reason is correct");

View file

@ -122,8 +122,8 @@ function checkTelemetryResults() {
const expected = TELEMETRY_DATA[i];
// ignore timestamp
ok(timestamp > 0, "timestamp is greater than 0");
ok(extra.time_open > 0, "time_open is greater than 0");
Assert.greater(timestamp, 0, "timestamp is greater than 0");
Assert.greater(Number(extra.time_open), 0, "time_open is greater than 0");
is(category, expected.category, "category is correct");
is(method, expected.method, "method is correct");
is(object, expected.object, "object is correct");

View file

@ -104,7 +104,7 @@ function checkResults() {
is(method, expected.method, "method is correct");
is(object, expected.object, "object is correct");
is(value, null, "value is correct");
ok(extra.width > 0, "width is greater than 0");
Assert.greater(Number(extra.width), 0, "width is greater than 0");
checkExtra("host", extra, expected);
checkExtra("start_state", extra, expected);

View file

@ -1156,7 +1156,11 @@ function checkTelemetryEvent(expectedEvent, query) {
is(events.length, 1, "There was only 1 event logged");
const [event] = events;
ok(event.session_id > 0, "There is a valid session_id in the logged event");
Assert.greater(
Number(event.session_id),
0,
"There is a valid session_id in the logged event"
);
const f = e => JSON.stringify(e, null, 2);
is(

View file

@ -111,6 +111,6 @@ async function checkResults() {
// extras
is(extra.host, expected.extra.host, "host is correct");
ok(extra.width > 0, "width is greater than 0");
Assert.greater(Number(extra.width), 0, "width is greater than 0");
}
}

View file

@ -1,6 +1,9 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// We test sorting of strings, which Assert.greater/less etc. don't do.
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// Tests that the table widget api works fine
"use strict";

View file

@ -35,6 +35,8 @@ add_task(async function () {
const browserToolboxDoc = gToolbox.getCurrentPanel().panelWindow.document;
const browserToolboxHosts = getDBHostsInTree(browserToolboxDoc);
// In the spawn task, we don't have access to Assert:
// eslint-disable-next-line mozilla/no-comparison-or-assignment-inside-ok
ok(browserToolboxHosts.length > 1, "There are more than 1 indexedDB hosts");
ok(
browserToolboxHosts.includes("about:devtools-toolbox"),

View file

@ -57,7 +57,11 @@ function checkTelemetryEvent(expectedEvent) {
const events = getFiltersChangedEventsExtra();
is(events.length, 1, "There was only 1 event logged");
const [event] = events;
ok(event.session_id > 0, "There is a valid session_id in the logged event");
Assert.greater(
Number(event.session_id),
0,
"There is a valid session_id in the logged event"
);
const f = e => JSON.stringify(e, null, 2);
is(
f(event),

View file

@ -32,7 +32,11 @@ add_task(async function () {
const events = getJumpToDefinitionEventsExtra();
is(events.length, 1, "There was 1 event logged");
const [event] = events;
ok(event.session_id > 0, "There is a valid session_id in the logged event");
Assert.greater(
Number(event.session_id),
0,
"There is a valid session_id in the logged event"
);
});
function getJumpToDefinitionEventsExtra() {

View file

@ -35,7 +35,11 @@ add_task(async function () {
let events = getObjectExpandedEventsExtra();
is(events.length, 1, "There was 1 event logged");
const [event] = events;
ok(event.session_id > 0, "There is a valid session_id in the logged event");
Assert.greater(
Number(event.session_id),
0,
"There is a valid session_id in the logged event"
);
info("Click on the second arrow icon to expand the prototype node");
const secondArrowIcon = message.querySelectorAll(".arrow")[1];

View file

@ -166,6 +166,6 @@ function checkEventTelemetry(expectedData) {
expected.extra.functionality,
"'functionality' is correct"
);
ok(extra.session_id > 0, "'session_id' is correct");
Assert.greater(Number(extra.session_id), 0, "'session_id' is correct");
}
}

View file

@ -148,6 +148,7 @@ function ok(val) {
throw new Error("Census mismatch: expected truthy, got " + val);
}
}
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// Return a walker that checks that the subject census has at least as many
// items of each category as |basis|.

View file

@ -178,7 +178,7 @@ add_task(async function () {
}
let topBrowserId = topBC.browserId;
ok(topBrowserId > 0, "Should have a browser ID.");
Assert.greater(topBrowserId, 0, "Should have a browser ID.");
for (let [name, bc] of Object.entries({
first,
second,
@ -193,7 +193,7 @@ add_task(async function () {
);
}
ok(sixth.browserId > 0, "sixth should have a browserId.");
Assert.greater(sixth.browserId, 0, "sixth should have a browserId.");
isnot(
sixth.browserId,
topBrowserId,

View file

@ -20,8 +20,9 @@ add_task(async function test_csp_sandbox_no_script_js_uri() {
let observerPromise = SpecialPowers.spawn(browser, [], () => {
return new Promise(resolve => {
SpecialPowers.addObserver(function obs(subject) {
ok(
subject == content,
Assert.equal(
subject,
content,
"Should block script spawned via javascript uri"
);
SpecialPowers.removeObserver(

View file

@ -1,4 +1,7 @@
/* globals chromeWindow */
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// The main test function.
var test = function (isContent) {
SimpleTest.waitForExplicitFinish();

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function getType(a) {
if (a === null || a === undefined) {
return "null";

View file

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
var gEntry1 = "data_1.txt";
var gEntry2 = "data_2.txt";
var gEntry3 = "data_big.txt";

View file

@ -1,3 +1,4 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
var gData1 = "TEST_DATA_1:ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var gData2 = "TEST_DATA_2:1234567890";
var gPaddingChar = ".";

View file

@ -40,5 +40,6 @@ function getViewportInfo(aDisplayWidth, aDisplayHeight) {
}
function fuzzeq(a, b, msg) {
// eslint-disable-next-line mozilla/no-comparison-or-assignment-inside-ok
ok(Math.abs(a - b) < 1e-6, msg);
}

View file

@ -2,6 +2,8 @@
// to tests on auto MochiTest system with minimum changes.
// Author: Maksim Lebedev <alessarik@gmail.com>
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// Function allows to prepare our tests after load document
addEventListener(
"load",

View file

@ -4,6 +4,8 @@
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
var gState = 0;
/**
* After all the on/offline handlers run,

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
const RANGE_1 = 1;
const RANGE_2 = 2;

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
importScripts("common_blob_reading.js");
function info(message) {

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
importScripts("common_fileReader.js");
function ok(a, msg) {

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function testHas() {
var f = new FormData();
f.append("foo", "bar");

View file

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// testSteps is expected to be defined by the test using this file.
/* global testSteps:false */

View file

@ -1,5 +1,7 @@
/* import-globals-from head.js */
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
const principalInfos = [
{ url: "http://example.com", attrs: {} },

View file

@ -1,5 +1,7 @@
let testingInterface;
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// eslint-disable-next-line no-unused-vars
function test_deprecatedInterface() {
info("Testing DeprecatedTestingInterface report");
@ -34,7 +36,7 @@ function test_deprecatedInterface() {
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 48, "We have a lineNumber");
is(report.body.lineNumber, 50, "We have a lineNumber");
is(report.body.columnNumber, 24, "We have a columnNumber");
obs.disconnect();
@ -86,7 +88,7 @@ function test_deprecatedMethod() {
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 100, "We have a lineNumber");
is(report.body.lineNumber, 102, "We have a lineNumber");
is(report.body.columnNumber, 22, "We have a columnNumber");
obs.disconnect();
@ -167,7 +169,7 @@ function test_deprecatedAttribute() {
.replace("worker_deprecated.js", "common_deprecated.js"),
"We have a sourceFile"
);
is(report.body.lineNumber, 181, "We have a lineNumber");
is(report.body.lineNumber, 183, "We have a lineNumber");
is(report.body.columnNumber, 8, "We have a columnNumber");
obs.disconnect();

View file

@ -1,4 +1,5 @@
/* eslint-disable no-undef */
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// eslint-disable-next-line no-unused-vars
function ok(a, msg) {

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(v, msg) {
client.postMessage({ status: "ok", result: !!v, message: msg });
}

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// Cross origin request
var prefix = "http://example.com/tests/dom/serviceworkers/test/eventsource/";

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
var prefix = "http://example.com/tests/dom/serviceworkers/test/eventsource/";
self.importScripts("eventsource_worker_helper.js");

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// Cross origin request
var prefix = "http://example.com/tests/dom/serviceworkers/test/eventsource/";

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
self.importScripts("eventsource_worker_helper.js");
self.addEventListener("fetch", function (event) {

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// This is a list of all interfaces that are exposed to workers.
// Please only add things to this list with great care and proper review
// from the associated module peers.

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(a, msg) {
postMessage({ type: "status", status: !!a, msg });
}

View file

@ -1,5 +1,9 @@
/* import-globals-from urlSearchParams_worker.js */
// This file gets included into a worker which doesn't have any
// assertion methods besides `ok` and `is`.
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function testSimpleURLSearchParams() {
var u = new URLSearchParams();
ok(u, "URLSearchParams created");

View file

@ -1,5 +1,7 @@
"use strict";
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(a, msg) {
postMessage(JSON.stringify({ type: "status", what: !!a, msg }));
}

View file

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(a, msg) {
postMessage({ type: "status", status: !!a, msg });
}

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function info(message) {
dump("INFO: " + message + "\n");
}

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(test, message) {
postMessage({ type: "ok", test, message });
}

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(test, message) {
postMessage({ type: "ok", test, message });
}

View file

@ -3,10 +3,7 @@
* http://creativecommons.org/licenses/publicdomain/
*/
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function info(text) {
dump("Test for Bug 925437: worker: " + text + "\n");

View file

@ -3,6 +3,8 @@
* http://creativecommons.org/licenses/publicdomain/
*/
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function info(text) {
dump("Test for Bug 925437: worker: " + text + "\n");
}

View file

@ -1,5 +1,7 @@
"use strict";
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(a, msg) {
dump("OK: " + !!a + " => " + a + " " + msg + "\n");
postMessage({ type: "status", status: !!a, msg: a + ": " + msg });

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
// This is a list of all interfaces that are exposed to workers.
// Please only add things to this list with great care and proper review
// from the associated module peers.

View file

@ -1,4 +1,7 @@
"use strict";
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
SimpleTest.waitForExplicitFinish();
var gen = runTests();

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
/* Notes:
- All times are expressed in milliseconds in this test suite.
- Test harness code is at the end of this file.

View file

@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function ok(what, msg) {
postMessage({ event: msg, test: "ok", a: what });
}

View file

@ -1,4 +1,7 @@
/* eslint-env worker */
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
importScripts("common_temporaryFileBlob.js");
function info(msg) {

View file

@ -87,8 +87,9 @@ add_task(async () => {
const nfrm_match = nfrm_line.exec(copiedText);
if (nfrm_match) {
const nfrm_mb = nfrm_match[1];
ok(
nfrm_mb < MB_EXCLUSIVE_MAX,
Assert.less(
nfrm_mb,
MB_EXCLUSIVE_MAX,
`native-font-resource-mac ${nfrm_mb} MB should be less than ${MB_EXCLUSIVE_MAX} MB.`
);
} else {
@ -102,8 +103,9 @@ add_task(async () => {
const gfx_match = gfx_line.exec(copiedText);
if (gfx_match && gfx_match.index < om_match.index) {
const gfx_mb = gfx_match[1];
ok(
gfx_mb < MB_EXCLUSIVE_MAX,
Assert.less(
gfx_mb,
MB_EXCLUSIVE_MAX,
`Explicit Allocations gfx ${gfx_mb} MB should be less than ${MB_EXCLUSIVE_MAX} MB.`
);
} else {

View file

@ -45,8 +45,9 @@ add_task(async function test_windowlessBrowserTroubleshootCrash() {
);
var data = await Troubleshoot.snapshot();
ok(
data.graphics.windowLayerManagerType !== "None",
Assert.notStrictEqual(
data.graphics.windowLayerManagerType,
"None",
"windowless browser window should not set windowLayerManagerType to 'None'"
);

View file

@ -140,7 +140,7 @@ add_task(async function () {
await new Promise(resolve => requestAnimationFrame(resolve));
frameCount = await SpecialPowers.spawn(iframe, [1000], observeFrameUpdate);
ok(frameCount > 0, "There should be frameUpdate(s)");
Assert.greater(frameCount, 0, "There should be frameUpdate(s)");
await new Promise(resolve => requestAnimationFrame(resolve));

View file

@ -27,7 +27,7 @@ function actOnMozImage(doc, id, func) {
function assertPrefVal(name, val) {
let boolValue = Services.prefs.getBoolPref(name);
ok(boolValue === val, `pref ${name} is set to ${val}`);
Assert.strictEqual(boolValue, val, `pref ${name} is set to ${val}`);
if (boolValue !== val) {
throw Error(`pref ${name} is not set to ${val}`);
}
@ -121,7 +121,7 @@ async function createMozIconInFile(ext, expectSuccess = true) {
await waitLoad;
const icon = content.document.getElementById(`moz-icon-${_ext}-${_kSize}`);
ok(icon !== null, `got a valid ${_ext} moz-icon`);
Assert.notStrictEqual(icon, null, `got a valid ${_ext} moz-icon`);
is(icon.width, _kSize, `${_kSize} px width ${_ext} moz-icon`);
is(icon.height, _kSize, `${_kSize} px height ${_ext} moz-icon`);
};

View file

@ -4,6 +4,8 @@
//
//----------------------------------------------------------------------
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
function advance_clock(milliseconds) {
SpecialPowers.DOMWindowUtils.advanceTimeAndRefresh(milliseconds);
}

View file

@ -1,5 +1,7 @@
// # Bug 418986, part 2.
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
const is_chrome_window = window.location.protocol === "chrome:";
const HTML_NS = "http://www.w3.org/1999/xhtml";

View file

@ -355,6 +355,7 @@ add_task(async function test_get_falls_back_sorts_results() {
order: "-id",
});
// eslint-disable-next-line mozilla/no-comparison-or-assignment-inside-ok
ok(records[0].id > records[records.length - 1].id, "records are sorted");
clientWithDump.db.getLastModified = backup;

View file

@ -32,6 +32,8 @@ AntiTracking._createTask({
allowList: false,
callback: async _ => {
document.cookie = "name=value";
// Assert isn't available in the webpage.
// eslint-disable-next-line mozilla/no-comparison-or-assignment-inside-ok
ok(document.cookie != "", "Nothing is blocked");
// requestStorageAccess should resolve

View file

@ -1,3 +1,6 @@
// We're using custom message passing so don't have access to Assert.foo
// everywhere. Disable the linter:
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
AntiTracking.runTest(
"Test whether we receive any persistent permissions in normal windows",
// Blocking callback

View file

@ -1,3 +1,7 @@
// We're using custom message passing so don't have access to Assert.foo
// everywhere. Disable the linter:
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
AntiTracking.runTest(
"Test whether we receive any persistent permissions in normal windows",
// Blocking callback

View file

@ -57,7 +57,7 @@ const TEST_URI = Services.io.newURI("http://foo.com");
let node = rootNode.getChild(i);
// test that bm1 does not have new title
if (node.bookmarkGuid == bm1.guid)
ok(node.title != "foo",
isnot(node.title, "foo",
"Changing a bookmark's title did not affect the title of other bookmarks with the same URI");
}
rootNode.containerOpen = false;

View file

@ -103,6 +103,10 @@ async function testCopyPaste(isPrivate) {
document.execCommand("paste");
return pastePromise;
});
// Don't use Assert.strictEqual here because the test starts timing out,
// because the logging creates lots of copies of this very huge string.
// eslint-disable-next-line mozilla/no-comparison-or-assignment-inside-ok
ok(readStr === Ipsum, "Read what we pasted");
if (isPrivate) {