Skip to content

Commit

Permalink
Bug 1412778 - Enable ESLint rule no-cpows-in-tests across the whole t…
Browse files Browse the repository at this point in the history
…ree. r=florian

MozReview-Commit-ID: 8pidN7x6MYh
  • Loading branch information
Standard8 committed Oct 30, 2017
1 parent dd9eb07 commit 98b92db
Show file tree
Hide file tree
Showing 73 changed files with 120 additions and 12 deletions.
2 changes: 2 additions & 0 deletions browser/base/content/test/general/browser_bug423833.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function test2Setup() {
}

function testOpenFrameInTab() {
/* eslint-disable mozilla/no-cpows-in-tests */
if (gBrowser.contentDocument.location.href == "about:blank")
// Wait another cycle
return;
Expand All @@ -92,6 +93,7 @@ function testOpenFrameInTab() {

// We should now have the error page in a new, active tab.
is(gBrowser.contentDocument.location.href, invalidPage, "New tab should have page url, not about:neterror");
/* eslint-enable mozilla/no-cpows-in-tests */

// Clear up the new tab, and punt to test 3
gBrowser.removeCurrentTab();
Expand Down
2 changes: 2 additions & 0 deletions browser/base/content/test/general/browser_bug561636.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ add_task(async function() {
Services.obs.addObserver(gObserver, "invalidformsubmit");

executeSoon(function() {
// eslint-disable-next-line mozilla/no-cpows-in-tests
browser.contentDocument.getElementById("s").click();
});
});
Expand Down Expand Up @@ -330,6 +331,7 @@ add_task(async function() {
checkPopupShow();
await checkChildFocus(browser, gInvalidFormPopup.firstChild.textContent);

// eslint-disable-next-line mozilla/no-cpows-in-tests
let inputPromise = promiseWaitForEvent(gBrowser.contentDocument.getElementById("i"), "input");
EventUtils.synthesizeKey("f", {});
await inputPromise;
Expand Down
1 change: 1 addition & 0 deletions browser/base/content/test/general/browser_bug575561.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function testLink(aLinkIndexOrFunction, pinTab, expectNewTab, testSubFrame
let href;
if (typeof aLinkIndexOrFunction === "function") {
ok(!browser.isRemoteBrowser, "don't pass a function for a remote browser");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let link = aLinkIndexOrFunction(browser.contentDocument);
info("Clicking " + link.textContent);
link.click();
Expand Down
1 change: 1 addition & 0 deletions browser/base/content/test/general/browser_bug678392.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function test() {

function load(aTab, aUrl, aCallback) {
aTab.linkedBrowser.addEventListener("load", function(aEvent) {
// eslint-disable-next-line mozilla/no-cpows-in-tests
waitForFocus(aCallback, content);
}, {capture: true, once: true});
aTab.linkedBrowser.loadURI(aUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function openNewTab(aWindow, aCallback) {
aWindow.BrowserOpenTab();

let browser = aWindow.gBrowser.selectedBrowser;
// eslint-disable-next-line mozilla/no-cpows-in-tests
if (browser.contentDocument.readyState === "complete") {
executeSoon(aCallback);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_task(async function test_principal_click() {
await kAboutPagesRegistered;
await BrowserTestUtils.withNewTab("about:test-about-principal-parent", async function(browser) {
let loadPromise = BrowserTestUtils.browserLoaded(browser, false, "about:test-about-principal-child");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let myLink = browser.contentDocument.getElementById("aboutchildprincipal");
myLink.click();
await loadPromise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function test() {
registerCleanupFunction(() => gBrowser.removeCurrentTab());

BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => {
// eslint-disable-next-line mozilla/no-cpows-in-tests
let window = gBrowser.selectedBrowser.contentWindow;

window.addEventListener("message", handleMessageEvents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function doTest() {
info("Running test: " + gCurrTest.name);

waitForLoad(function() {
// eslint-disable-next-line mozilla/no-cpows-in-tests
let loadedText = gBrowser.contentDocument.body.textContent;
ok(loadedText, "search page loaded");
let needle = "searchterms=" + gCurrTest.expectText;
Expand Down
2 changes: 2 additions & 0 deletions browser/base/content/test/general/browser_tabfocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function focusInChild() {
content.document.getElementById(message.data.id)[message.data.type]();
});

/* eslint-disable mozilla/no-cpows-in-tests */
addMessageListener("Browser:GetFocusedElement", function getFocusedElement(message) {
var focusedWindow = {};
var node = contentFM.getFocusedElementForWindow(content, false, focusedWindow);
Expand Down Expand Up @@ -128,6 +129,7 @@ function focusElementInChild(elementid, type) {
browser.contentDocument.getElementById(elementid)[type]();
}
}
/* eslint-enable mozilla/no-cpows-in-tests */

add_task(async function() {
tab1 = BrowserTestUtils.addTab(gBrowser);
Expand Down
5 changes: 2 additions & 3 deletions browser/base/content/test/newtab/browser_newtab_focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function promiseNoMuteNotificationOnFirstSession() {
* Wait for the onboarding tour notification opens
*/
function promiseTourNotificationOpened(browser) {
function isOpened() {
return ContentTask.spawn(browser, {}, function() {
let doc = content && content.document;
let notification = doc.querySelector("#onboarding-notification-bar");
if (notification && notification.classList.contains("onboarding-opened")) {
Expand All @@ -88,6 +88,5 @@ function promiseTourNotificationOpened(browser) {
});
observer.observe(doc.body, { childList: true });
});
}
return ContentTask.spawn(browser, {}, isOpened);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function test() {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);

gBrowser.selectedBrowser.addEventListener("load", function() {
// eslint-disable-next-line mozilla/no-cpows-in-tests
var doc = gBrowser.contentDocument;
var testImg = doc.getElementById("test-image");
var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ var tests = [
if (gMultiProcessBrowser) {
is(Services.focus.focusedElement, browser);
} else {
// eslint-disable-next-line mozilla/no-cpows-in-tests
is(Services.focus.focusedElement, browser.contentDocument.getElementById("test-input"));
}

Expand Down
3 changes: 3 additions & 0 deletions browser/base/content/test/sidebar/browser_bug409481.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ function runTest(event) {
sidebar.contentDocument.removeEventListener("load", delayedRunTest, true);

var browser = sidebar.contentDocument.getElementById("web-panels-browser");
// eslint-disable-next-line mozilla/no-cpows-in-tests
var div = browser && browser.contentDocument.getElementById("test_bug409481");
ok(div && div.textContent == "Content!", "Sidebar content loaded");

// eslint-disable-next-line mozilla/no-cpows-in-tests
var link = browser && browser.contentDocument.getElementById("link");
sidebar.contentDocument.addEventListener("popupshown", contextMenuOpened);

Expand All @@ -60,6 +62,7 @@ function copyLinkCommandExecuted(event) {

var sidebar = document.getElementById("sidebar");
var browser = sidebar.contentDocument.getElementById("web-panels-browser");
// eslint-disable-next-line mozilla/no-cpows-in-tests
var textbox = browser && browser.contentDocument.getElementById("textbox");
textbox.focus();
document.commandDispatcher.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_task(async function test_show_form() {
// Now crash the browser.
await BrowserTestUtils.crashBrowser(browser);

// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;

// Ensure the request is visible. We can safely reach into
Expand Down Expand Up @@ -76,6 +77,7 @@ add_task(async function test_show_form() {
// Now crash the browser.
await BrowserTestUtils.crashBrowser(browser);

// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;

// Ensure the request is NOT visible. We can safely reach into
Expand Down
3 changes: 2 additions & 1 deletion browser/base/content/test/tabcrashed/browser_clearEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ add_task(async function test_clear_email() {
await BrowserTestUtils.crashBrowser(browser,
/* shouldShowTabCrashPage */ true,
/* shouldClearMinidumps */ false);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;

// Since about:tabcrashed will run in the parent process, we can safely
Expand All @@ -48,6 +49,7 @@ add_task(async function test_clear_email() {
Email: "",
});

// eslint-disable-next-line mozilla/no-cpows-in-tests
let restoreTab = browser.contentDocument.getElementById("restoreTab");
restoreTab.click();
await BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
Expand All @@ -63,4 +65,3 @@ add_task(async function test_clear_email() {
prefs.setCharPref("email", originalEmail);
});
});

1 change: 1 addition & 0 deletions browser/base/content/test/tabcrashed/browser_showForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_task(async function test_show_form() {
// Now crash the browser.
await BrowserTestUtils.crashBrowser(browser);

// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;

// Ensure the checkbox is checked. We can safely reach into
Expand Down
3 changes: 2 additions & 1 deletion browser/base/content/test/tabcrashed/browser_shown.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function crashTabTestHelper(fieldValues, expectedExtra) {

let tab = gBrowser.getTabForBrowser(browser);
await BrowserTestUtils.crashBrowser(browser);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;

// Since about:tabcrashed will run in the parent process, we can safely
Expand All @@ -82,6 +83,7 @@ function crashTabTestHelper(fieldValues, expectedExtra) {
}

let crashReport = promiseCrashReport(expectedExtra);
// eslint-disable-next-line mozilla/no-cpows-in-tests
let restoreTab = browser.contentDocument.getElementById("restoreTab");
restoreTab.click();
await BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
Expand Down Expand Up @@ -178,4 +180,3 @@ add_task(async function test_send_all() {
"Email": EMAIL,
});
});

Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ add_task(async function() {
is(gBrowser.currentURI.spec, "about:addons", "Foreground tab is at about:addons");

const VIEW = "addons://list/extension";
// eslint-disable-next-line mozilla/no-cpows-in-tests
let win = gBrowser.selectedBrowser.contentWindow;
ok(!win.gViewController.isLoading, "about:addons view is fully loaded");
is(win.gViewController.currentViewId, VIEW, "about:addons is at extensions list");
Expand Down Expand Up @@ -168,6 +169,7 @@ add_task(async function() {
// Again we should be at the extentions list in about:addons
is(gBrowser.currentURI.spec, "about:addons", "Foreground tab is at about:addons");

// eslint-disable-next-line mozilla/no-cpows-in-tests
win = gBrowser.selectedBrowser.contentWindow;
ok(!win.gViewController.isLoading, "about:addons view is fully loaded");
is(win.gViewController.currentViewId, VIEW, "about:addons is at extensions list");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ add_task(async function test() {
await BrowserTestUtils.browserLoaded(browser);

// get the title
// eslint-disable-next-line mozilla/no-cpows-in-tests
let title = browser.contentDocument.title.trim().split("|");

// check each item in the title and validate it meets expectatations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_task(async function() {
await waitForCondition(() => gBrowser.currentURI &&
gBrowser.currentURI.spec == "about:addons");

// eslint-disable-next-line mozilla/no-cpows-in-tests
let addonsPage = gBrowser.selectedBrowser.contentWindow.document.
getElementById("addons-page");
ok(addonsPage, "Add-ons page was opened");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ add_task(async function setup() {
await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
info("Preferences page opened on the general pane.");

// eslint-disable-next-line mozilla/no-cpows-in-tests
await gBrowser.selectedBrowser.contentWindow.promiseLoadHandlersList;
info("Apps list loaded.");

Expand All @@ -17,6 +18,7 @@ add_task(async function setup() {
});

add_task(async function getFeedItem() {
// eslint-disable-next-line mozilla/no-cpows-in-tests
win = gBrowser.selectedBrowser.contentWindow;

container = win.document.getElementById("handlersView");
Expand Down Expand Up @@ -82,6 +84,7 @@ add_task(async function reselectInternalOptionForFeed() {
});

add_task(async function sortingCheck() {
// eslint-disable-next-line mozilla/no-cpows-in-tests
win = gBrowser.selectedBrowser.contentWindow;

const handlerView = win.document.getElementById("handlersView");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ registerCleanupFunction(function() {

add_task(async function() {
await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
// eslint-disable-next-line mozilla/no-cpows-in-tests
await gBrowser.contentWindow.gMainPane._selectDefaultLanguageGroupPromise;
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = gBrowser.contentDocument;
var langGroup = Services.prefs.getComplexValue("font.language.group", Ci.nsIPrefLocalizedString).data;
is(doc.getElementById("font.language.group").value, langGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ add_task(async function() {
window.resizeTo(window.outerWidth, 300);
let prefs = await openPreferencesViaOpenPreferencesAPI("paneSearch", {leaveOpen: true});
is(prefs.selectedPane, "paneSearch", "Search pane was selected");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let mainContent = gBrowser.contentDocument.querySelector(".main-content");
mainContent.scrollTop = 50;
is(mainContent.scrollTop, 50, "main-content should be scrolled 50 pixels");

// eslint-disable-next-line mozilla/no-cpows-in-tests
gBrowser.contentWindow.gotoPref("paneGeneral");
is(mainContent.scrollTop, 0,
"Switching to a different category should reset the scroll position");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

/* eslint-disable mozilla/no-cpows-in-tests */

Services.prefs.setBoolPref("browser.preferences.instantApply", true);

registerCleanupFunction(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_task(async function() {
const tabURL = getRootDirectory(gTestPath) + "browser_bug1184989_prevent_scrolling_when_preferences_flipped.xul";

await BrowserTestUtils.withNewTab({ gBrowser, url: tabURL }, async function(browser) {
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
let container = doc.getElementById("container");

Expand Down Expand Up @@ -41,6 +42,7 @@ add_task(async function() {
});

await BrowserTestUtils.withNewTab({ gBrowser, url: "about:preferences#search" }, async function(browser) {
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = browser.contentDocument;
let container = doc.getElementsByClassName("main-content")[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ function test() {
getService(Ci.nsIHandlerService);
hserv.store(info);

/* eslint-disable mozilla/no-cpows-in-tests */
openPreferencesViaOpenPreferencesAPI("general", {leaveOpen: true})
.then(() => gBrowser.selectedBrowser.contentWindow.promiseLoadHandlersList)
.then(() => runTest(gBrowser.selectedBrowser.contentWindow));
/* eslint-enable mozilla/no-cpows-in-tests */
}

function runTest(win) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_task(async function() {

let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
is(prefs.selectedPane, "paneGeneral", "General pane was selected");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let win = gBrowser.selectedBrowser.contentWindow;

let container = win.document.getElementById("handlersView");
Expand Down Expand Up @@ -98,4 +99,3 @@ registerCleanupFunction(function() {
let infoToModify = gMimeSvc.getFromTypeAndExtension("text/x-test-handler", null);
gHandlerSvc.remove(infoToModify);
});

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_task(async function() {
let prefs = await openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
is(prefs.selectedPane, "paneGeneral", "General pane was selected");

// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = gBrowser.contentDocument;
let checkbox = doc.querySelector("#checkSpelling");
is(checkbox.checked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ var testRunner = {
});

openPreferencesViaOpenPreferencesAPI("panePrivacy", {leaveOpen: true}).then(function() {
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = gBrowser.contentDocument;
let historyMode = doc.getElementById("historyMode");
historyMode.value = "custom";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
add_task(async function() {
let prefs = await openPreferencesViaOpenPreferencesAPI("search", {leaveOpen: true});
is(prefs.selectedPane, "paneSearch", "Search pane is selected by default");
// eslint-disable-next-line mozilla/no-cpows-in-tests
let doc = gBrowser.contentDocument;

let tree = doc.querySelector("#engineList");
Expand All @@ -23,4 +24,3 @@ add_task(async function() {

await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});

Loading

0 comments on commit 98b92db

Please sign in to comment.