Skip to content

Commit

Permalink
Bug 1780071 - Manual fixes/disabling of no-comparison-or-assignment-i…
Browse files Browse the repository at this point in the history
…nside-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
  • Loading branch information
gijsk committed Feb 19, 2024
1 parent 02ba212 commit ff17e7f
Show file tree
Hide file tree
Showing 68 changed files with 162 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion devtools/client/application/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions devtools/client/debugger/test/mochitest/shared-head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion devtools/client/netmonitor/test/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
3 changes: 3 additions & 0 deletions devtools/client/shared/test/browser_tableWidget_basic.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
1 change: 1 addition & 0 deletions devtools/shared/heapsnapshot/tests/xpcshell/Census.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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|.
Expand Down
4 changes: 2 additions & 2 deletions docshell/test/browser/browser_browsingContext-02.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions docshell/test/browser/browser_csp_sandbox_no_script_js_uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions dom/base/test/chrome/bug418986-1.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 2 additions & 0 deletions dom/base/test/common_postMessages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

function getType(a) {
if (a === null || a === undefined) {
return "null";
Expand Down
2 changes: 2 additions & 0 deletions dom/base/test/file_bug1008126_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions dom/base/test/file_bug945152_worker.js
Original file line number Diff line number Diff line change
@@ -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 = ".";
Expand Down
1 change: 1 addition & 0 deletions dom/base/test/meta_viewport/viewport_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions dom/events/test/pointerevents/mochitest_support_external.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// to tests on auto MochiTest system with minimum changes.
// Author: Maksim Lebedev <[email protected]>

/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

// Function allows to prepare our tests after load document
addEventListener(
"load",
Expand Down
2 changes: 2 additions & 0 deletions dom/events/test/test_bug336682.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions dom/file/tests/common_blob.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

const RANGE_1 = 1;
const RANGE_2 = 2;

Expand Down
2 changes: 2 additions & 0 deletions dom/file/tests/worker_blob_reading.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

importScripts("common_blob_reading.js");

function info(message) {
Expand Down
2 changes: 2 additions & 0 deletions dom/file/tests/worker_fileReader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

importScripts("common_fileReader.js");

function ok(a, msg) {
Expand Down
2 changes: 2 additions & 0 deletions dom/html/test/formData_test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

function testHas() {
var f = new FormData();
f.append("foo", "bar");
Expand Down
2 changes: 2 additions & 0 deletions dom/indexedDB/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 2 additions & 0 deletions dom/localstorage/test/unit/databaseShadowing-shared.js
Original file line number Diff line number Diff line change
@@ -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: {} },

Expand Down
8 changes: 5 additions & 3 deletions dom/reporting/tests/common_deprecated.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions dom/reporting/tests/worker_deprecated.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions dom/serviceworkers/test/close_test.js
Original file line number Diff line number Diff line change
@@ -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 });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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/";

Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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/";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

self.importScripts("eventsource_worker_helper.js");

self.addEventListener("fetch", function (event) {
Expand Down
2 changes: 2 additions & 0 deletions dom/serviceworkers/test/test_serviceworker_interfaces.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions dom/url/tests/protocol_worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

function ok(a, msg) {
postMessage({ type: "status", status: !!a, msg });
}
Expand Down
Loading

0 comments on commit ff17e7f

Please sign in to comment.