Bug 1508985 - Enable ESLint for dom/tests/browser (manual changes) r=Standard8,qdot

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Vincent W 2019-01-22 21:26:02 +00:00
parent 3b243b7e27
commit a3846471d6
23 changed files with 56 additions and 123 deletions

View File

@ -208,7 +208,7 @@ dom/security/test/sri/**
dom/serviceworkers/**
dom/smil/**
dom/svg/**
dom/tests/browser/**
dom/tests/html/**
dom/tests/mochitest/**
dom/u2f/**

View File

@ -101,6 +101,8 @@ async function consoleAPISanityTest(browser) {
});
}
// These globals are all defined in spawnWithObserver in a sub-process.
/* global gWindow, gArgs:true, gLevel:true, gStyle:true, expect, resolve */
function testConsoleData(aMessageObject) {
let messageWindow = Services.wm.getOuterWindowWithId(aMessageObject.ID);
is(messageWindow, gWindow, "found correct window by window ID");

View File

@ -5,7 +5,7 @@
const TEST_URI = "http://example.com/browser/dom/tests/browser/test_largeAllocation.html";
function expectProcessCreated() {
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
let os = Services.obs;
return new Promise(resolve => {
let topic = "ipc:content-created";
function observer() {

View File

@ -41,6 +41,7 @@ SpecialPowers.pushPrefEnv(
* Test navigation from a content page to a chrome page. Also check that only
* one beforeunload event is fired.
*/
/* global messageManager */
add_task(async function() {
let beforeUnloadCount = 0;
messageManager.addMessageListener("Test:OnBeforeUnloadReceived", function() {

View File

@ -273,6 +273,7 @@ async function newTabTest(location) {
async function(browser) {
await ContentTask.spawn(browser, { location, testInDocument_: testInDocument.toSource() },
async function({ location, testInDocument_ }) {
// eslint-disable-next-line no-eval
let testInDocument = eval(`(() => (${testInDocument_}))()`);
testInDocument(content.document, location);
});

View File

@ -50,6 +50,7 @@ add_task(async function() {
function f() {
let e = content.document.activeElement;
if (e.tagName != test.tagName) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(f, 10);
} else {
is(Services.focus.focusedElement, e,
@ -68,6 +69,7 @@ add_task(async function() {
function f() {
let e = content.document.activeElement;
if (e.tagName != test.tagName) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(f, 10);
} else {
isnot(Services.focus.focusedElement, e,
@ -110,6 +112,7 @@ add_task(async function() {
function f() {
let e = content.document.activeElement;
if (e.tagName != test.tagName) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(f, 10);
} else {
isnot(Services.focus.focusedElement, e,
@ -128,6 +131,7 @@ add_task(async function() {
function f() {
let e = content.document.activeElement;
if (e.tagName != test.tagName) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(f, 10);
} else {
isnot(Services.focus.focusedElement, e,

View File

@ -13,8 +13,7 @@ add_task(async function test() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, kTestURI);
let fm = Cc["@mozilla.org/focus-manager;1"].
getService(Ci.nsIFocusManager);
let fm = Services.focus;
for (var button = 0; button < 3; button++) {
// Set focus to a chrome element before synthesizing a mouse down event.
@ -31,8 +30,7 @@ add_task(async function test() {
"Failed to move focus away from search bar: button=" + button);
await ContentTask.spawn(tab.linkedBrowser, button, async function(button) {
let fm = Cc["@mozilla.org/focus-manager;1"].
getService(Ci.nsIFocusManager);
let fm = Services.focus;
let attempts = 10;
await new Promise(resolve => {

View File

@ -8,23 +8,21 @@ var PaintListener = {};
Services.scriptloader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
const { ContentTaskUtils } = ChromeUtils.import("resource://testing-common/ContentTaskUtils.jsm", {});
function getRecordedKeypressCount()
{
function getRecordedKeypressCount() {
let snapshot = Services.telemetry.getSnapshotForHistograms("main", false);
var totalCount = 0;
for (var prop in snapshot) {
if (snapshot[prop]["KEYPRESS_PRESENT_LATENCY"]) {
if (snapshot[prop].KEYPRESS_PRESENT_LATENCY) {
dump("found snapshot");
totalCount += Object.values(snapshot[prop]["KEYPRESS_PRESENT_LATENCY"].values).reduce((a, b) => a + b, 0);
totalCount += Object.values(snapshot[prop].KEYPRESS_PRESENT_LATENCY.values).reduce((a, b) => a + b, 0);
}
}
return totalCount;
}
add_task(async function()
{
add_task(async function() {
await SpecialPowers.pushPrefEnv({set: [["toolkit.telemetry.ipcBatchTimeout", 10]]});
let histogram = Services.telemetry.getHistogramById("KEYPRESS_PRESENT_LATENCY");
histogram.clear();
@ -33,17 +31,17 @@ add_task(async function()
gURLBar.focus();
await SimpleTest.promiseFocus(window);
EventUtils.sendChar('x');
EventUtils.sendChar("x");
await ContentTaskUtils.waitForCondition(() => { return getRecordedKeypressCount() > 0; }, "waiting for telemetry", 200, 600)
await ContentTaskUtils.waitForCondition(() => { return getRecordedKeypressCount() > 0; }, "waiting for telemetry", 200, 600);
let result = getRecordedKeypressCount();
ok(result == 1, "One keypress recorded");
gURLBar.focus();
await SimpleTest.promiseFocus(window);
EventUtils.sendChar('x');
EventUtils.sendChar("x");
await ContentTaskUtils.waitForCondition(() => { return getRecordedKeypressCount() > 1; }, "waiting for telemetry", 200, 600)
await ContentTaskUtils.waitForCondition(() => { return getRecordedKeypressCount() > 1; }, "waiting for telemetry", 200, 600);
result = getRecordedKeypressCount();
ok(result == 2, "Two keypresses recorded");
});

View File

@ -1,4 +1,5 @@
let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
/* import-globals-from helper_largeAllocation.js */
Services.scriptloader.loadSubScript(testDir + "/helper_largeAllocation.js", this);
// Force-enabling the Large-Allocation header

View File

@ -12,7 +12,7 @@ add_task(async function() {
["dom.ipc.processCount.webLargeAllocation", 20],
],
});
/* global largeAllocSuccessTests */
await largeAllocSuccessTests();
});

View File

@ -5,74 +5,6 @@ const HELPER_PAGE_ORIGIN = "http://example.com/";
let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
Services.scriptloader.loadSubScript(testDir + "/helper_localStorage_e10s.js",
this);
// Simple tab wrapper abstracting our messaging mechanism;
class KnownTab {
constructor(name, tab) {
this.name = name;
this.tab = tab;
}
cleanup() {
this.tab = null;
}
}
// Simple data structure class to help us track opened tabs and their pids.
class KnownTabs {
constructor() {
this.byPid = new Map();
this.byName = new Map();
}
cleanup() {
this.byPid = null;
this.byName = null;
}
}
/**
* Open our helper page in a tab in its own content process, asserting that it
* really is in its own process. We initially load and wait for about:blank to
* load, and only then loadURI to our actual page. This is to ensure that
* LocalStorageManager has had an opportunity to be created and populate
* mOriginsHavingData.
*
* (nsGlobalWindow will reliably create LocalStorageManager as a side-effect of
* the unconditional call to nsGlobalWindow::PreloadLocalStorage. This will
* reliably create the StorageDBChild instance, and its corresponding
* StorageDBParent will send the set of origins when it is constructed.)
*/
async function openTestTabInOwnProcess(name, knownTabs) {
let realUrl = HELPER_PAGE_URL + "?" + encodeURIComponent(name);
// Load and wait for about:blank.
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser, opening: "about:blank", forceNewProcess: true,
});
let pid = tab.linkedBrowser.frameLoader.tabParent.osPid;
ok(!knownTabs.byName.has(name), "tab needs its own name: " + name);
ok(!knownTabs.byPid.has(pid), "tab needs to be in its own process: " + pid);
let knownTab = new KnownTab(name, tab);
knownTabs.byPid.set(pid, knownTab);
knownTabs.byName.set(name, knownTab);
// Now trigger the actual load of our page.
BrowserTestUtils.loadURI(tab.linkedBrowser, realUrl);
await BrowserTestUtils.browserLoaded(tab.linkedBrowser);
is(tab.linkedBrowser.frameLoader.tabParent.osPid, pid, "still same pid");
return knownTab;
}
/**
* Close all the tabs we opened.
*/
async function cleanupTabs(knownTabs) {
for (let knownTab of knownTabs.byName.values()) {
BrowserTestUtils.removeTab(knownTab.tab);
knownTab.cleanup();
}
knownTabs.cleanup();
}
/**
* Wait for a LocalStorage flush to occur. This notification can occur as a
@ -81,6 +13,9 @@ async function cleanupTabs(knownTabs) {
* - InsertDBOp seeing a preload op for an origin with outstanding changes.
* - Us generating a "domstorage-test-flush-force" observer notification.
*/
/* import-globals-from helper_localStorage_e10s.js */
function waitForLocalStorageFlush() {
if (Services.lsm.nextGenLocalStorageEnabled) {
return new Promise(resolve => executeSoon(resolve));

View File

@ -2,6 +2,8 @@ const HELPER_PAGE_URL =
"http://example.com/browser/dom/tests/browser/page_localstorage_snapshotting_e10s.html";
const HELPER_PAGE_ORIGIN = "http://example.com/";
/* import-globals-from helper_localStorage_e10s.js */
let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
Services.scriptloader.loadSubScript(testDir + "/helper_localStorage_e10s.js",
this);
@ -94,7 +96,7 @@ add_task(async function() {
// Enable LocalStorage's testing API so we can explicitly create
// snapshots when needed.
["dom.storage.testing", true],
]
],
});
// Ensure that there is no localstorage data by forcing the origin to be
@ -120,7 +122,7 @@ add_task(async function() {
["key5", "initial5"],
["key6", "initial6"],
["key7", "initial7"],
["key8", "initial8"]
["key8", "initial8"],
];
const initialState = {
@ -130,11 +132,10 @@ add_task(async function() {
key5: "initial5",
key6: "initial6",
key7: "initial7",
key8: "initial8"
key8: "initial8",
};
function getPartialPrefill()
{
function getPartialPrefill() {
let size = 0;
let entries = Object.entries(initialState);
for (let i = 0; i < entries.length / 2; i++) {
@ -147,7 +148,7 @@ add_task(async function() {
const prefillValues = [
0, // no prefill
getPartialPrefill(), // partial prefill
-1 // full prefill
-1, // full prefill
];
for (let prefillValue of prefillValues) {
@ -155,8 +156,8 @@ add_task(async function() {
await SpecialPowers.pushPrefEnv({
set: [
["dom.storage.snapshot_prefill", prefillValue]
]
["dom.storage.snapshot_prefill", prefillValue],
],
});
info("Stage 1");
@ -171,7 +172,7 @@ add_task(async function() {
["key6", "setRemove16"],
["key7", "setRemove17"],
["key8", null],
["key9", "setRemove19"]
["key9", "setRemove19"],
];
const setRemoveState1 = {
@ -182,7 +183,7 @@ add_task(async function() {
key5: "setRemove15",
key6: "setRemove16",
key7: "setRemove17",
key9: "setRemove19"
key9: "setRemove19",
};
const setRemoveMutations2 = [
@ -195,7 +196,7 @@ add_task(async function() {
["key6", "setRemove26"],
["key7", null],
["key8", "setRemove28"],
["key9", "setRemove29"]
["key9", "setRemove29"],
];
const setRemoveState2 = {
@ -206,7 +207,7 @@ add_task(async function() {
key5: "setRemove25",
key6: "setRemove26",
key8: "setRemove28",
key9: "setRemove29"
key9: "setRemove29",
};
// Apply initial mutations using an explicit snapshot. The explicit
@ -259,7 +260,7 @@ add_task(async function() {
const setRemoveClearMutations1 = [
["key0", "setRemoveClear10"],
["key1", null],
[null, null]
[null, null],
];
const setRemoveClearState1 = {
@ -268,7 +269,7 @@ add_task(async function() {
const setRemoveClearMutations2 = [
["key8", null],
["key9", "setRemoveClear29"],
[null, null]
[null, null],
];
const setRemoveClearState2 = {
@ -318,7 +319,7 @@ add_task(async function() {
["key5", "initial5"],
["key3", "initial3"],
["key2", "initial2"],
["key1", "initial1"]
["key1", "initial1"],
];
// Apply initial mutations using an explicit snapshot. The explicit

View File

@ -12,7 +12,7 @@ function awaitAndClosePrompt() {
Services.obs.addObserver(onDialogShown, "tabmodal-dialog-loaded");
});
}
/* global messageManager */
let lastMessageReceived = "";
function waitForMessage(message) {
return new Promise((resolve, reject) => {

View File

@ -115,7 +115,6 @@ function prepareForResult(aBrowser, aExpectation) {
await BrowserTestUtils.loadURI(aBrowser, kContentDoc);
await BrowserTestUtils.browserLoaded(aBrowser);
})();
break;
case kNewWin:
return (async function() {
let newWin = await BrowserTestUtils.waitForNewWindow({url: expectedSpec});
@ -123,7 +122,6 @@ function prepareForResult(aBrowser, aExpectation) {
is(newBrowser.currentURI.spec, expectedSpec, "Should be at dummy.html");
await BrowserTestUtils.closeWindow(newWin);
})();
break;
case kNewTab:
return (async function() {
let newTab = await BrowserTestUtils.waitForNewTab(gBrowser);
@ -131,13 +129,10 @@ function prepareForResult(aBrowser, aExpectation) {
"Should be at dummy.html");
BrowserTestUtils.removeTab(newTab);
})();
break;
default:
ok(false, "prepareForResult can't handle an expectation of " + aExpectation);
return;
return Promise.resolve();
}
return deferred.promise;
}
/**

View File

@ -11,7 +11,7 @@ add_task(async function testNotActivated() {
// we call requestPerformanceMetrics()
let failed = false;
try {
let promise = await ChromeUtils.requestPerformanceMetrics();
await ChromeUtils.requestPerformanceMetrics();
} catch (e) {
failed = true;
}

View File

@ -23,8 +23,7 @@ var sandboxCode = (function() {
function test() {
waitForExplicitFinish();
let appShell = Cc["@mozilla.org/appshell/appShellService;1"]
.getService(Ci.nsIAppShellService);
let appShell = Services.appShell;
let doc = appShell.hiddenDOMWindow.document;
let frame = doc.createElement("iframe");
frame.setAttribute("type", "content");

View File

@ -6,7 +6,7 @@ const TEST_URI = "http://example.com/browser/dom/tests/browser/test_largeAllocat
const TEST_URI_2 = "http://example.com/browser/dom/tests/browser/test_largeAllocation2.html";
function expectProcessCreated() {
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
let os = Services.obs;
let kill; // A kill function which will disable the promise.
let promise = new Promise((resolve, reject) => {
let topic = "ipc:content-created";
@ -27,7 +27,7 @@ function expectProcessCreated() {
}
function expectNoProcess() {
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
let os = Services.obs;
let topic = "ipc:content-created";
function observer() {
ok(false, "A process was created!");
@ -40,9 +40,7 @@ function expectNoProcess() {
function getPID(aBrowser) {
return ContentTask.spawn(aBrowser, null, () => {
const appinfo = Cc["@mozilla.org/xre/app-info;1"]
.getService(Ci.nsIXULRuntime);
return appinfo.processID;
return Services.appinfo.processID;
});
}
@ -103,6 +101,7 @@ async function largeAllocSuccessTests() {
let stopExpectNoProcess = expectNoProcess();
await ContentTask.spawn(aBrowser, TEST_URI, TEST_URI => {
// eslint-disable-next-line no-unsanitized/property
content.document.body.innerHTML = `<iframe src='${TEST_URI}'></iframe>`;
return new Promise(resolve => {
@ -182,7 +181,6 @@ async function largeAllocSuccessTests() {
await BrowserTestUtils.browserLoaded(aBrowser);
let pid3 = await getPID(aBrowser);
// We should have been kicked out of the large-allocation process by the
// load, meaning we're back in a non-fresh process

View File

@ -40,10 +40,10 @@ class KnownTabs {
* StorageDBParent will send the set of origins when it is constructed.)
*/
async function openTestTabInOwnProcess(helperPageUrl, name, knownTabs) {
let realUrl = helperPageUrl + '?' + encodeURIComponent(name);
let realUrl = helperPageUrl + "?" + encodeURIComponent(name);
// Load and wait for about:blank.
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser, opening: 'about:blank', forceNewProcess: true
gBrowser, opening: "about:blank", forceNewProcess: true,
});
let pid = tab.linkedBrowser.frameLoader.tabParent.osPid;
ok(!knownTabs.byName.has(name), "tab needs its own name: " + name);

View File

@ -70,7 +70,6 @@ add_task(async function test() {
let isTopLevel = false;
let aboutMemoryFound = false;
let parentProcessEvent = false;
let workerEvent = false;
let subFrameIds = [];
let topLevelIds = [];
let sharedWorker = false;
@ -108,7 +107,6 @@ add_task(async function test() {
parentProcessEvent = true;
}
if (entry.isWorker) {
workerEvent = true;
workerDuration += entry.duration;
} else {
duration += entry.duration;

View File

@ -5,10 +5,12 @@
var result = null;
function handlePosition(position) {
// eslint-disable-next-line no-unsanitized/property
result.innerHTML = position.coords.latitude + " " + position.coords.longitude;
}
function handleError(error) {
// eslint-disable-next-line no-unsanitized/property
result.innerHTML = error.message;
}

View File

@ -12,6 +12,7 @@
aEvent.preventDefault();
return false;
}
return true;
}, {once: true});
let form = document.getElementById("form");

View File

@ -1,9 +1,7 @@
onconnect = function(e) {
let onconnect = function(e) {
var port = e.ports[0];
port.onmessage = function(e) {
var workerResult = "Result: " + (e.data[0] * e.data[1]);
port.postMessage(e.data[0]);
};
};

View File

@ -7,6 +7,7 @@
return a + "c";
};
/* global foobar585956c */
function foobar585956b(a) {
return foobar585956c(a + "b");
}