diff --git a/accessible/tests/browser/head.js b/accessible/tests/browser/head.js index 0524b4789c58..6ad237096351 100644 --- a/accessible/tests/browser/head.js +++ b/accessible/tests/browser/head.js @@ -130,8 +130,14 @@ function waitForEvent(eventType, expectedId) { let eventObserver = { observe(subject) { let event = subject.QueryInterface(Ci.nsIAccessibleEvent); + let id; + try { + id = event.accessible.id; + } catch (e) { + // This can throw NS_ERROR_FAILURE. + } if (event.eventType === eventType && - event.accessible.id === expectedId) { + id === expectedId) { Services.obs.removeObserver(this, "accessible-event"); resolve(event); } diff --git a/browser/base/content/test/alerts/browser_notification_do_not_disturb.js b/browser/base/content/test/alerts/browser_notification_do_not_disturb.js index d66e12304bb6..7b23e96262e5 100644 --- a/browser/base/content/test/alerts/browser_notification_do_not_disturb.js +++ b/browser/base/content/test/alerts/browser_notification_do_not_disturb.js @@ -35,12 +35,11 @@ function test() { addNotificationPermission(notificationURL).then(function openTab() { tab = BrowserTestUtils.addTab(gBrowser, notificationURL); gBrowser.selectedTab = tab; - tab.linkedBrowser.addEventListener("load", onLoad, true); + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => onLoad()); }); } function onLoad() { - tab.linkedBrowser.removeEventListener("load", onLoad, true); openNotification(tab.linkedBrowser, "showNotification2").then(onAlertShowing); } diff --git a/browser/base/content/test/alerts/browser_notification_remove_permission.js b/browser/base/content/test/alerts/browser_notification_remove_permission.js index a6fdd5042edb..50e128404c16 100644 --- a/browser/base/content/test/alerts/browser_notification_remove_permission.js +++ b/browser/base/content/test/alerts/browser_notification_remove_permission.js @@ -16,12 +16,11 @@ function test() { addNotificationPermission(notificationURL).then(function openTab() { tab = BrowserTestUtils.addTab(gBrowser, notificationURL); gBrowser.selectedTab = tab; - tab.linkedBrowser.addEventListener("load", onLoad, true); + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => onLoad()); }); } function onLoad() { - tab.linkedBrowser.removeEventListener("load", onLoad, true); openNotification(tab.linkedBrowser, "showNotification2").then(onAlertShowing); } diff --git a/browser/base/content/test/general/browser_blockHPKP.js b/browser/base/content/test/general/browser_blockHPKP.js index 26c97cd56a24..a545fe678c7f 100644 --- a/browser/base/content/test/general/browser_blockHPKP.js +++ b/browser/base/content/test/general/browser_blockHPKP.js @@ -49,9 +49,7 @@ function test() { function loadPinningPage() { BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "https://" + kPinningDomain + kURLPath + "valid").then(function() { - gBrowser.selectedBrowser.addEventListener("load", - successfulPinningPageListener, - true); + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => successfulPinningPageListener.handleEvent()); }); } @@ -59,7 +57,6 @@ function loadPinningPage() { // fail to validate var successfulPinningPageListener = { handleEvent() { - gBrowser.selectedBrowser.removeEventListener("load", this, true); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, "https://" + kBadPinningDomain).then(function() { return BrowserTestUtils.waitForErrorPage(gBrowser.selectedBrowser); }).then(errorPageLoaded); diff --git a/browser/base/content/test/general/browser_bug406216.js b/browser/base/content/test/general/browser_bug406216.js index 96a69c4f6325..d010950df29b 100644 --- a/browser/base/content/test/general/browser_bug406216.js +++ b/browser/base/content/test/general/browser_bug406216.js @@ -24,10 +24,10 @@ function addTab(aURI, aIndex) { if (aIndex == 0) gBrowser.removeTab(gBrowser.tabs[0], {skipPermitUnload: true}); - tab.linkedBrowser.addEventListener("load", function(event) { + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => { if (++count == URIS.length) executeSoon(doTabsTest); - }, {capture: true, once: true}); + }); } function doTabsTest() { diff --git a/browser/base/content/test/general/browser_bug432599.js b/browser/base/content/test/general/browser_bug432599.js index 8853c958070c..ee92798a6ffa 100644 --- a/browser/base/content/test/general/browser_bug432599.js +++ b/browser/base/content/test/general/browser_bug432599.js @@ -45,11 +45,11 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { waitForStarChange(false, initTest); - }, {capture: true, once: true}); + }); - content.location = testURL; + gBrowser.loadURI(testURL); } function initTest() { diff --git a/browser/base/content/test/general/browser_bug479408.js b/browser/base/content/test/general/browser_bug479408.js index 77c607b6499c..1c81f1ecdadc 100644 --- a/browser/base/content/test/general/browser_bug479408.js +++ b/browser/base/content/test/general/browser_bug479408.js @@ -3,7 +3,7 @@ function test() { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "http://mochi.test:8888/browser/browser/base/content/test/general/browser_bug479408_sample.html"); - gBrowser.addEventListener("DOMLinkAdded", function(aEvent) { + BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "DOMLinkAdded", true).then(() => { executeSoon(function() { ok(!tab.linkedBrowser.engines, "the subframe's search engine wasn't detected"); @@ -11,5 +11,5 @@ function test() { gBrowser.removeTab(tab); finish(); }); - }, {capture: true, once: true}); + }); } diff --git a/browser/base/content/test/general/browser_bug567306.js b/browser/base/content/test/general/browser_bug567306.js index 54a1305638cc..16e6c26ba357 100644 --- a/browser/base/content/test/general/browser_bug567306.js +++ b/browser/base/content/test/general/browser_bug567306.js @@ -11,14 +11,12 @@ add_task(async function() { let selectedBrowser = newwindow.gBrowser.selectedBrowser; await new Promise((resolve, reject) => { - selectedBrowser.addEventListener("pageshow", function pageshowListener() { - if (selectedBrowser.currentURI.spec == "about:blank") - return; - - selectedBrowser.removeEventListener("pageshow", pageshowListener, true); - ok(true, "pageshow listener called: " + newwindow.content.location); + BrowserTestUtils.waitForContentEvent(selectedBrowser, "pageshow", true, (event) => { + return content.location.href != "about:blank"; + }).then(function pageshowListener() { + ok(true, "pageshow listener called: " + newwindow.gBrowser.currentURI.spec); resolve(); - }, true); + }); selectedBrowser.loadURI("data:text/html,

Select Me

"); }); diff --git a/browser/base/content/test/general/browser_bug581253.js b/browser/base/content/test/general/browser_bug581253.js index 3708727072f7..8cfbcf7c990b 100644 --- a/browser/base/content/test/general/browser_bug581253.js +++ b/browser/base/content/test/general/browser_bug581253.js @@ -24,8 +24,7 @@ add_task(async function test_remove_bookmark_with_tag_via_edit_bookmark() { Assert.ok(await PlacesUtils.bookmarks.fetch({url: testURL}), "the test url is bookmarked"); - // eslint-disable-next-line mozilla/no-cpows-in-tests - content.location = testURL; + gBrowser.loadURI(testURL); await BrowserTestUtils.waitForCondition( () => BookmarkingUI.status == BookmarkingUI.STATUS_STARRED, diff --git a/browser/base/content/test/general/browser_bug767836_perwindowpb.js b/browser/base/content/test/general/browser_bug767836_perwindowpb.js index 8307277ac2da..923de42f9450 100644 --- a/browser/base/content/test/general/browser_bug767836_perwindowpb.js +++ b/browser/base/content/test/general/browser_bug767836_perwindowpb.js @@ -76,12 +76,13 @@ function openNewTab(aWindow, aCallback) { let browser = aWindow.gBrowser.selectedBrowser; // eslint-disable-next-line mozilla/no-cpows-in-tests - if (browser.contentDocument.readyState === "complete") { + let doc = browser.contentDocumentAsCPOW; + if (doc && doc.readyState === "complete") { executeSoon(aCallback); return; } - browser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(browser).then(() => { executeSoon(aCallback); - }, {capture: true, once: true}); + }); } diff --git a/browser/base/content/test/general/browser_bug817947.js b/browser/base/content/test/general/browser_bug817947.js index 24d118f0cd97..ce28c747b9f6 100644 --- a/browser/base/content/test/general/browser_bug817947.js +++ b/browser/base/content/test/general/browser_bug817947.js @@ -47,8 +47,8 @@ function preparePendingTab(aCallback) { }); } -function whenLoaded(aElement, aCallback) { - aElement.addEventListener("load", function() { +function whenLoaded(aBrowser, aCallback) { + BrowserTestUtils.browserLoaded(aBrowser).then(() => { executeSoon(aCallback); - }, {capture: true, once: true}); + }); } diff --git a/browser/base/content/test/general/browser_favicon_change_not_in_document.js b/browser/base/content/test/general/browser_favicon_change_not_in_document.js index 55c0288fadd4..3ad14277bcd7 100644 --- a/browser/base/content/test/general/browser_favicon_change_not_in_document.js +++ b/browser/base/content/test/general/browser_favicon_change_not_in_document.js @@ -20,8 +20,8 @@ add_task(async function() { let domLinkChangedFired = 0; const linkAddedHandler = event => domLinkAddedFired++; const linkChangedhandler = event => domLinkChangedFired++; - gBrowser.addEventListener("DOMLinkAdded", linkAddedHandler); - gBrowser.addEventListener("DOMLinkChanged", linkChangedhandler); + BrowserTestUtils.addContentEventListener(gBrowser.selectedBrowser, "DOMLinkAdded", linkAddedHandler); + BrowserTestUtils.addContentEventListener(gBrowser.selectedBrowser, "DOMLinkChanged", linkChangedhandler); extraTab.linkedBrowser.loadURI(TEST_URL); let expectedFavicon = "http://example.org/yet-another-icon"; await promiseTabLoaded(extraTab); @@ -39,7 +39,5 @@ add_task(async function() { is(domLinkAddedFired, 2, "Should fire the correct number of DOMLinkAdded event."); is(domLinkChangedFired, 0, "Should not fire any DOMLinkChanged event."); - gBrowser.removeEventListener("DOMLinkAdded", linkAddedHandler); - gBrowser.removeEventListener("DOMLinkChanged", linkChangedhandler); gBrowser.removeTab(extraTab); }); diff --git a/browser/base/content/test/general/browser_gZipOfflineChild.js b/browser/base/content/test/general/browser_gZipOfflineChild.js index 5dcb1cf45f5e..5312e8a9b5a8 100644 --- a/browser/base/content/test/general/browser_gZipOfflineChild.js +++ b/browser/base/content/test/general/browser_gZipOfflineChild.js @@ -13,16 +13,20 @@ registerCleanupFunction(function() { Services.prefs.clearUserPref("offline-apps.allow_by_default"); }); -var cacheCount = 0; -var intervalID = 0; - // // Handle "message" events which are posted from the iframe upon // offline cache events. // -function handleMessageEvents(event) { - cacheCount++; - switch (cacheCount) { +function contentTask() { + let resolve; + let promise = new Promise(r => { resolve = r; }); + + var cacheCount = 0; + var intervalID = 0; + + function handleMessageEvents(event) { + cacheCount++; + switch (cacheCount) { case 1: // This is the initial caching off offline data. is(event.data, "oncache", "Child was successfully cached."); @@ -54,12 +58,16 @@ function handleMessageEvents(event) { case 2: is(event.data, "onupdate", "Child was successfully updated."); clearInterval(intervalID); - finish(); + resolve(); break; default: // how'd we get here? ok(false, "cacheCount not 1 or 2"); + } } + + content.addEventListener("message", handleMessageEvents); + return promise; } function test() { @@ -72,9 +80,6 @@ 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); + ContentTask.spawn(gBrowser.selectedBrowser, null, contentTask).then(finish); }); } diff --git a/browser/base/content/test/general/browser_keywordBookmarklets.js b/browser/base/content/test/general/browser_keywordBookmarklets.js index 4594c9d45706..c995c38eeb3e 100644 --- a/browser/base/content/test/general/browser_keywordBookmarklets.js +++ b/browser/base/content/test/general/browser_keywordBookmarklets.js @@ -45,9 +45,5 @@ add_task(async function test_keyword_bookmarklet() { }); function promisePageShow() { - return new Promise(resolve => { - gBrowser.selectedBrowser.addEventListener("pageshow", function() { - resolve(); - }, {once: true}); - }); + return BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "pageshow"); } diff --git a/browser/base/content/test/general/browser_keywordSearch.js b/browser/base/content/test/general/browser_keywordSearch.js index 65d49374edef..e4a2c0a0ebf2 100644 --- a/browser/base/content/test/general/browser_keywordSearch.js +++ b/browser/base/content/test/general/browser_keywordSearch.js @@ -36,6 +36,45 @@ function test() { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); + // We use a web progress listener in the content process to cancel + // the request. For everything else, we can do the work in the + // parent, since it's easier. + ContentTask.spawn(gBrowser.selectedBrowser, null, function* gen() { + const Ci = Components.interfaces; + + let listener = { + onStateChange: function onLocationChange(webProgress, req, flags, status) { + let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT | + Ci.nsIWebProgressListener.STATE_START; + if (!(flags & docStart)) { + return; + } + + req.cancel(Components.results.NS_ERROR_FAILURE); + }, + + QueryInterface: function QueryInterface(aIID) { + if (aIID.equals(Ci.nsIWebProgressListener) || + aIID.equals(Ci.nsIWebProgressListener2) || + aIID.equals(Ci.nsISupportsWeakReference) || + aIID.equals(Ci.nsISupports)) { + return this; + } + + throw Components.results.NS_ERROR_NO_INTERFACE; + } + }; + + let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebProgress); + webProgress.addProgressListener(listener, + Ci.nsIWebProgress.NOTIFY_STATE_DOCUMENT); + + addEventListener("unload", () => { + webProgress.removeProgressListener(listener); + }); + }); + let listener = { onStateChange: function onLocationChange(webProgress, req, flags, status) { // Only care about document starts @@ -50,11 +89,10 @@ function test() { is(req.originalURI.spec, gCurrTest.searchURL, "search URL was loaded"); info("Actual URI: " + req.URI.spec); - req.cancel(Components.results.NS_ERROR_FAILURE); - executeSoon(nextTest); } }; + gBrowser.addProgressListener(listener); registerCleanupFunction(function() { diff --git a/browser/base/content/test/general/browser_keywordSearch_postData.js b/browser/base/content/test/general/browser_keywordSearch_postData.js index fdf3ff54dbac..13c453ee719e 100644 --- a/browser/base/content/test/general/browser_keywordSearch_postData.js +++ b/browser/base/content/test/general/browser_keywordSearch_postData.js @@ -68,7 +68,7 @@ function doTest() { waitForLoad(function() { // eslint-disable-next-line mozilla/no-cpows-in-tests - let loadedText = gBrowser.contentDocument.body.textContent; + let loadedText = gBrowser.contentDocumentAsCPOW.body.textContent; ok(loadedText, "search page loaded"); let needle = "searchterms=" + gCurrTest.expectText; is(loadedText, needle, "The query POST data should be returned in the response"); @@ -84,12 +84,11 @@ function doTest() { function waitForLoad(cb) { let browser = gBrowser.selectedBrowser; - browser.addEventListener("load", function listener() { - if (browser.currentURI.spec == "about:blank") - return; + function wantLoad(url) { + return url != "about:blank"; + } + BrowserTestUtils.browserLoaded(browser, false, wantLoad).then(() => { info("Page loaded: " + browser.currentURI.spec); - browser.removeEventListener("load", listener, true); - cb(); }, true); } diff --git a/browser/base/content/test/general/browser_star_hsts.js b/browser/base/content/test/general/browser_star_hsts.js index 90ce54a6df8f..42999ef777ea 100644 --- a/browser/base/content/test/general/browser_star_hsts.js +++ b/browser/base/content/test/general/browser_star_hsts.js @@ -66,19 +66,8 @@ function promiseStarState(aValue) { function promiseTabLoadEvent(aTab, aURL, aFinalURL) { if (!aFinalURL) aFinalURL = aURL; - return new Promise(resolve => { - info("Wait for load tab event"); - aTab.linkedBrowser.addEventListener("load", function load(event) { - if (event.originalTarget != aTab.linkedBrowser.contentDocument || - event.target.location.href == "about:blank" || - event.target.location.href != aFinalURL) { - info("skipping spurious load event"); - return; - } - aTab.linkedBrowser.removeEventListener("load", load, true); - info("Tab load event received"); - resolve(); - }, true, true); - aTab.linkedBrowser.loadURI(aURL); - }); + + info("Wait for load tab event"); + aTab.linkedBrowser.loadURI(aURL); + return BrowserTestUtils.browserLoaded(aTab.linkedBrowser, false, aFinalURL); } diff --git a/browser/base/content/test/general/browser_tab_dragdrop2.js b/browser/base/content/test/general/browser_tab_dragdrop2.js index e6fb8dcdeef0..5ddc76d62ce9 100644 --- a/browser/base/content/test/general/browser_tab_dragdrop2.js +++ b/browser/base/content/test/general/browser_tab_dragdrop2.js @@ -39,7 +39,7 @@ add_task(async function() { // Run tests once again. let promise = promiseTestsDone(win2); - win2.content.test_panels(); + win2.gBrowser.contentWindowAsCPOW.test_panels(); await promise; ok(true, "tests succeeded a second time"); diff --git a/browser/base/content/test/general/browser_tabfocus.js b/browser/base/content/test/general/browser_tabfocus.js index d5b942bcbb26..6b48c543e2aa 100644 --- a/browser/base/content/test/general/browser_tabfocus.js +++ b/browser/base/content/test/general/browser_tabfocus.js @@ -329,9 +329,7 @@ add_task(async function() { gURLBar.focus(); await new Promise((resolve, reject) => { - window.addEventListener("pageshow", function(event) { - resolve(); - }, {capture: true, once: true}); + BrowserTestUtils.waitForContentEvent(window.gBrowser.selectedBrowser, "pageshow", true).then(() => resolve()); document.getElementById("Browser:Back").doCommand(); }); diff --git a/browser/base/content/test/general/head.js b/browser/base/content/test/general/head.js index ab957f6d6121..32fe182fb091 100644 --- a/browser/base/content/test/general/head.js +++ b/browser/base/content/test/general/head.js @@ -314,7 +314,8 @@ function whenNewTabLoaded(aWindow, aCallback) { aWindow.BrowserOpenTab(); let browser = aWindow.gBrowser.selectedBrowser; - if (browser.contentDocument.readyState === "complete") { + let doc = browser.contentDocumentAsCPOW; + if (doc && doc.readyState === "complete") { aCallback(); return; } @@ -433,11 +434,11 @@ var FullZoomHelper = { let didPs = false; let didZoom = false; - gBrowser.addEventListener("pageshow", function(event) { + BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "pageshow", true).then(() => { didPs = true; if (didZoom) resolve(); - }, {capture: true, once: true}); + }); if (direction == this.BACK) gBrowser.goBack(); diff --git a/browser/base/content/test/newtab/head.js b/browser/base/content/test/newtab/head.js index 359bdc4402c7..a5f1628c850b 100644 --- a/browser/base/content/test/newtab/head.js +++ b/browser/base/content/test/newtab/head.js @@ -40,50 +40,59 @@ requiredSize.innerWidth = (3 * (290 + 20)) + // 3 cols * (tile width + side margins) 100; // breathing room -var oldSize = {}; -Object.keys(requiredSize).forEach(prop => { - info([prop, gBrowser.contentWindow[prop], requiredSize[prop]]); - if (gBrowser.contentWindow[prop] < requiredSize[prop]) { - oldSize[prop] = gBrowser.contentWindow[prop]; - info("Changing browser " + prop + " from " + oldSize[prop] + " to " + - requiredSize[prop]); - gBrowser.contentWindow[prop] = requiredSize[prop]; - } -}); - -var screenHeight = {}; -var screenWidth = {}; -Cc["@mozilla.org/gfx/screenmanager;1"]. - getService(Ci.nsIScreenManager). - primaryScreen. - GetAvailRectDisplayPix({}, {}, screenWidth, screenHeight); -screenHeight = screenHeight.value; -screenWidth = screenWidth.value; - -if (screenHeight < gBrowser.contentWindow.outerHeight) { - info("Warning: Browser outer height is now " + - gBrowser.contentWindow.outerHeight + ", which is larger than the " + - "available screen height, " + screenHeight + - ". That may cause problems."); -} - -if (screenWidth < gBrowser.contentWindow.outerWidth) { - info("Warning: Browser outer width is now " + - gBrowser.contentWindow.outerWidth + ", which is larger than the " + - "available screen width, " + screenWidth + - ". That may cause problems."); -} - -registerCleanupFunction(function() { - while (gWindow.gBrowser.tabs.length > 1) - gWindow.gBrowser.removeTab(gWindow.gBrowser.tabs[1]); - - Object.keys(oldSize).forEach(prop => { - if (oldSize[prop]) { - gBrowser.contentWindow[prop] = oldSize[prop]; - } +add_task(async function setupWindowSize() { + let [oldSize, curWidth, curHeight] = await ContentTask.spawn(gBrowser.selectedBrowser, requiredSize, (requiredSizeArg) => { + var oldSizeVar = {}; + Object.keys(requiredSizeArg).forEach(prop => { + info([prop, content[prop], requiredSizeArg[prop]]); + if (content[prop] < requiredSizeArg[prop]) { + oldSizeVar[prop] = content[prop]; + info("Changing browser " + prop + " from " + oldSizeVar[prop] + " to " + + requiredSizeArg[prop]); + content[prop] = requiredSizeArg[prop]; + } + }); + return [oldSizeVar, content.outerWidth, content.outerHeight]; }); + var screenHeight = {}; + var screenWidth = {}; + Cc["@mozilla.org/gfx/screenmanager;1"]. + getService(Ci.nsIScreenManager). + primaryScreen. + GetAvailRectDisplayPix({}, {}, screenWidth, screenHeight); + screenHeight = screenHeight.value; + screenWidth = screenWidth.value; + + if (screenHeight < curHeight) { + info("Warning: Browser outer height is now " + + curHeight + ", which is larger than the " + + "available screen height, " + screenHeight + + ". That may cause problems."); + } + + if (screenWidth < curWidth) { + info("Warning: Browser outer width is now " + + curWidth + ", which is larger than the " + + "available screen width, " + screenWidth + + ". That may cause problems."); + } + + registerCleanupFunction(function() { + while (gWindow.gBrowser.tabs.length > 1) + gWindow.gBrowser.removeTab(gWindow.gBrowser.tabs[1]); + + ContentTask.spawn(gBrowser.selectedBrowser, oldSize, (oldSizeArg) => { + Object.keys(oldSizeArg).forEach(prop => { + if (oldSizeArg[prop]) { + content[prop] = oldSizeArg[prop]; + } + }); + }); + }); +}); + +registerCleanupFunction(function() { Services.prefs.clearUserPref(PREF_NEWTAB_ENABLED); Services.prefs.clearUserPref(PREF_NEWTAB_ACTIVITY_STREAM); Services.prefs.setCharPref(PREF_NEWTAB_DIRECTORYSOURCE, gOrigDirectorySource); diff --git a/browser/base/content/test/pageinfo/browser_pageInfo.js b/browser/base/content/test/pageinfo/browser_pageInfo.js index 765223723fa6..a2ebd43d22b8 100644 --- a/browser/base/content/test/pageinfo/browser_pageInfo.js +++ b/browser/base/content/test/pageinfo/browser_pageInfo.js @@ -4,12 +4,11 @@ function test() { var pageInfo; gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { Services.obs.addObserver(observer, "page-info-dialog-loaded"); pageInfo = BrowserPageInfo(); - }, {capture: true, once: true}); - content.location = - "https://example.com/browser/browser/base/content/test/pageinfo/feed_tab.html"; + }); + gBrowser.selectedBrowser.loadURI("https://example.com/browser/browser/base/content/test/pageinfo/feed_tab.html"); function observer(win, topic, data) { Services.obs.removeObserver(observer, "page-info-dialog-loaded"); diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js b/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js index 7da1799e72cf..99f3f256d4e0 100644 --- a/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js +++ b/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js @@ -72,8 +72,8 @@ async function test() { }); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - content.location = "https://example.com/browser/browser/base/content/test/pageinfo/image.html"; - await waitForEvent(gBrowser.selectedBrowser, "load"); + gBrowser.selectedBrowser.loadURI("https://example.com/browser/browser/base/content/test/pageinfo/image.html"); + await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); let spec = gBrowser.selectedBrowser.currentURI.spec; diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js b/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js index d9ad8f68e920..6e1ceffa35ea 100644 --- a/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js +++ b/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js @@ -13,9 +13,9 @@ function test() { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function() { // eslint-disable-next-line mozilla/no-cpows-in-tests - var doc = gBrowser.contentDocument; + var doc = gBrowser.contentDocumentAsCPOW; var testImg = doc.getElementById("test-image"); var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec, "mediaTab", getImageInfo(testImg)); @@ -35,14 +35,14 @@ function test() { }); }); }, {capture: true, once: true}); - }, {capture: true, once: true}); + }); - content.location = + gBrowser.loadURI( "data:text/html," + "" + "2" + "2" + "" + "1" + - "2"; + "2"); } diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_images.js b/browser/base/content/test/pageinfo/browser_pageinfo_images.js index 053c3f85e9ff..78ce46265ee9 100644 --- a/browser/base/content/test/pageinfo/browser_pageinfo_images.js +++ b/browser/base/content/test/pageinfo/browser_pageinfo_images.js @@ -5,7 +5,7 @@ function test() { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec, "mediaTab"); @@ -26,9 +26,9 @@ function test() { }); }); }, {capture: true, once: true}); - }, {capture: true, once: true}); + }); - content.location = + gBrowser.selectedBrowser.loadURI( "data:text/html," + "" + " " + @@ -44,5 +44,5 @@ function test() { " test link" + // Cursor " " + // Object " " + - ""; + ""); } diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js b/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js index 2552a873d924..a2129459d141 100644 --- a/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js +++ b/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js @@ -3,7 +3,7 @@ function test() { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { var pageInfo = BrowserPageInfo(gBrowser.selectedBrowser.currentURI.spec, "mediaTab"); @@ -30,8 +30,8 @@ function test() { }); }); }, {capture: true, once: true}); - }, {capture: true, once: true}); + }); - content.location = - "https://example.com/browser/browser/base/content/test/pageinfo/svg_image.html"; + gBrowser.selectedBrowser.loadURI( + "https://example.com/browser/browser/base/content/test/pageinfo/svg_image.html"); } diff --git a/browser/base/content/test/plugins/browser_CTP_context_menu.js b/browser/base/content/test/plugins/browser_CTP_context_menu.js index c928ff560dda..c510a13a07a9 100644 --- a/browser/base/content/test/plugins/browser_CTP_context_menu.js +++ b/browser/base/content/test/plugins/browser_CTP_context_menu.js @@ -21,7 +21,7 @@ add_task(async function() { Services.prefs.setBoolPref("plugins.click_to_play", true); setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Test Plug-in"); - let bindingPromise = waitForEvent(gBrowser.selectedBrowser, "PluginBindingAttached", null, true, true); + let bindingPromise = BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "PluginBindingAttached", true, null, true); await promiseTabLoadEvent(gBrowser.selectedTab, gTestRoot + "plugin_test.html"); await promiseUpdatePluginBindings(gBrowser.selectedBrowser); await bindingPromise; diff --git a/browser/base/content/test/plugins/browser_CTP_drag_drop.js b/browser/base/content/test/plugins/browser_CTP_drag_drop.js index 61ddfcd0618e..27d188b40988 100644 --- a/browser/base/content/test/plugins/browser_CTP_drag_drop.js +++ b/browser/base/content/test/plugins/browser_CTP_drag_drop.js @@ -34,7 +34,7 @@ add_task(async function() { gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); // XXX technically can't load fire before we get this call??? - await waitForEvent(gNewWindow, "load", null, true); + await BrowserTestUtils.waitForEvent(gNewWindow, "load", true); await promisePopupNotification("click-to-play-plugins", gNewWindow.gBrowser.selectedBrowser); diff --git a/browser/base/content/test/plugins/browser_CTP_nonplugins.js b/browser/base/content/test/plugins/browser_CTP_nonplugins.js index 9c843daed30f..cfad122759e1 100644 --- a/browser/base/content/test/plugins/browser_CTP_nonplugins.js +++ b/browser/base/content/test/plugins/browser_CTP_nonplugins.js @@ -31,7 +31,7 @@ add_task(async function() { let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser); ok(popupNotification, "Test 1, Should have a click-to-play notification"); - let pluginRemovedPromise = waitForEvent(gBrowser.selectedBrowser, "PluginRemoved", null, true, true); + let pluginRemovedPromise = BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "PluginRemoved", true, null, true); await ContentTask.spawn(gBrowser.selectedBrowser, {}, async function() { let plugin = content.document.getElementById("secondtestA"); plugin.remove(); diff --git a/browser/base/content/test/plugins/browser_blocking.js b/browser/base/content/test/plugins/browser_blocking.js index 6d4b096d076d..fc2070ffb9a6 100644 --- a/browser/base/content/test/plugins/browser_blocking.js +++ b/browser/base/content/test/plugins/browser_blocking.js @@ -70,7 +70,7 @@ add_task(async function() { "Test 18a, Plugin should have an update link"); }); - let promise = waitForEvent(gBrowser.tabContainer, "TabOpen", null, true); + let promise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen", true); await ContentTask.spawn(gTestBrowser, {}, async function() { let doc = content.document; @@ -86,7 +86,7 @@ add_task(async function() { }); await promise; - promise = waitForEvent(gBrowser.tabContainer, "TabClose", null, true); + promise = BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabClose", true); gBrowser.removeCurrentTab(); await promise; }); diff --git a/browser/base/content/test/plugins/browser_bug744745.js b/browser/base/content/test/plugins/browser_bug744745.js index 81656c5d58fe..25eac6532f40 100644 --- a/browser/base/content/test/plugins/browser_bug744745.js +++ b/browser/base/content/test/plugins/browser_bug744745.js @@ -30,7 +30,7 @@ add_task(async function() { setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Test Plug-in"); - gTestBrowser.addEventListener("PluginBindingAttached", pluginBindingAttached, true, true); + BrowserTestUtils.addContentEventListener(gTestBrowser, "PluginBindingAttached", pluginBindingAttached, true, null, true); let testRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); await promiseTabLoadEvent(gBrowser.selectedTab, testRoot + "plugin_bug744745.html"); diff --git a/browser/base/content/test/plugins/browser_bug820497.js b/browser/base/content/test/plugins/browser_bug820497.js index 1c27b92ab477..d039ed423695 100644 --- a/browser/base/content/test/plugins/browser_bug820497.js +++ b/browser/base/content/test/plugins/browser_bug820497.js @@ -23,7 +23,7 @@ add_task(async function() { setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Test Plug-in"); setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in"); - gTestBrowser.addEventListener("PluginBindingAttached", function() { gNumPluginBindingsAttached++; }, true, true); + BrowserTestUtils.addContentEventListener(gTestBrowser, "PluginBindingAttached", function() { gNumPluginBindingsAttached++; }, true, null, true); await promiseTabLoadEvent(gBrowser.selectedTab, gTestRoot + "plugin_bug820497.html"); diff --git a/browser/base/content/test/plugins/browser_pageInfo_plugins.js b/browser/base/content/test/plugins/browser_pageInfo_plugins.js index 5a4df02ddfaf..6d9f367ef652 100644 --- a/browser/base/content/test/plugins/browser_pageInfo_plugins.js +++ b/browser/base/content/test/plugins/browser_pageInfo_plugins.js @@ -9,12 +9,11 @@ var gSecondTestPermissionString = gPluginHost.getPermissionStringForType("applic function doOnPageLoad(url, continuation) { gNextTest = continuation; - gTestBrowser.addEventListener("load", pageLoad, true); - gTestBrowser.contentWindow.location = url; + BrowserTestUtils.browserLoaded(gTestBrowser).then(pageLoad); + gTestBrowser.loadURI(url); } function pageLoad() { - gTestBrowser.removeEventListener("load", pageLoad); // The plugin events are async dispatched and can come after the load event // This just allows the events to fire before we then go on to test the states executeSoon(gNextTest); @@ -63,10 +62,10 @@ function test() { // The first test plugin is CtP and the second test plugin is enabled. function testPart1a() { - let testElement = gTestBrowser.contentDocument.getElementById("test"); + let testElement = gTestBrowser.contentDocumentAsCPOW.getElementById("test"); let objLoadingContent = testElement.QueryInterface(Ci.nsIObjectLoadingContent); ok(!objLoadingContent.activated, "part 1a: Test plugin should not be activated"); - let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"); + let secondtest = gTestBrowser.contentDocumentAsCPOW.getElementById("secondtestA"); objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent); ok(objLoadingContent.activated, "part 1a: Second Test plugin should be activated"); @@ -94,11 +93,11 @@ function testPart1b() { // Now, the Test plugin should be allowed, and the Test2 plugin should be CtP function testPart2() { - let testElement = gTestBrowser.contentDocument.getElementById("test"). + let testElement = gTestBrowser.contentDocumentAsCPOW.getElementById("test"). QueryInterface(Ci.nsIObjectLoadingContent); ok(testElement.activated, "part 2: Test plugin should be activated"); - let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). + let secondtest = gTestBrowser.contentDocumentAsCPOW.getElementById("secondtestA"). QueryInterface(Ci.nsIObjectLoadingContent); ok(!secondtest.activated, "part 2: Second Test plugin should not be activated"); is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, @@ -123,13 +122,13 @@ function testPart2() { // Now, all the things should be blocked function testPart3() { - let testElement = gTestBrowser.contentDocument.getElementById("test"). + let testElement = gTestBrowser.contentDocumentAsCPOW.getElementById("test"). QueryInterface(Ci.nsIObjectLoadingContent); ok(!testElement.activated, "part 3: Test plugin should not be activated"); is(testElement.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, "part 3: Test plugin should be marked as PLUGIN_DISABLED"); - let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). + let secondtest = gTestBrowser.contentDocumentAsCPOW.getElementById("secondtestA"). QueryInterface(Ci.nsIObjectLoadingContent); ok(!secondtest.activated, "part 3: Second Test plugin should not be activated"); diff --git a/browser/base/content/test/plugins/head.js b/browser/base/content/test/plugins/head.js index 4c3c522a6c29..a7db23e992cf 100644 --- a/browser/base/content/test/plugins/head.js +++ b/browser/base/content/test/plugins/head.js @@ -44,28 +44,6 @@ function waitForMs(aMs) { }); } -function waitForEvent(subject, eventName, checkFn, useCapture, useUntrusted) { - return new Promise((resolve, reject) => { - subject.addEventListener(eventName, function listener(event) { - try { - if (checkFn && !checkFn(event)) { - return; - } - subject.removeEventListener(eventName, listener, useCapture); - resolve(event); - } catch (ex) { - try { - subject.removeEventListener(eventName, listener, useCapture); - } catch (ex2) { - // Maybe the provided object does not support removeEventListener. - } - reject(ex); - } - }, useCapture, useUntrusted); - }); -} - - /** * Waits for a load (or custom) event to finish in a given tab. If provided * load an uri into the tab. diff --git a/browser/base/content/test/siteIdentity/browser_bug906190.js b/browser/base/content/test/siteIdentity/browser_bug906190.js index 28bdfc1dfecb..e73e006b19a1 100644 --- a/browser/base/content/test/siteIdentity/browser_bug906190.js +++ b/browser/base/content/test/siteIdentity/browser_bug906190.js @@ -34,16 +34,19 @@ async function doTest(parentTabSpec, childTabSpec, testTaskFn, waitForMetaRefres await promiseReloaded; // Wait for the script in the page to update the contents of the test div. - let testDiv = content.document.getElementById("mctestdiv"); + // eslint-disable-next-line mozilla/no-cpows-in-tests + let testDiv = gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv"); await BrowserTestUtils.waitForCondition( () => testDiv.innerHTML == "Mixed Content Blocker disabled"); // Add the link for the child tab to the page. - let mainDiv = content.document.createElement("div"); + // eslint-disable-next-line mozilla/no-cpows-in-tests + let mainDiv = gBrowser.contentDocumentAsCPOW.createElement("div"); // eslint-disable-next-line no-unsanitized/property mainDiv.innerHTML = '

Link

'; - content.document.body.appendChild(mainDiv); + // eslint-disable-next-line mozilla/no-cpows-in-tests + gBrowser.contentDocumentAsCPOW.body.appendChild(mainDiv); // Execute the test in the child tabs with the two methods to open it. for (let openFn of [simulateCtrlClick, simulateContextMenuOpenInTab]) { @@ -85,14 +88,9 @@ function simulateContextMenuOpenInTab(browser) { // from s without a tab assigned. That are most likely browsers // that preload the new tab page. function waitForSomeTabToLoad() { - return new Promise(resolve => { - gBrowser.addEventListener("load", function onLoad(event) { - let tab = gBrowser._getTabForContentWindow(event.target.defaultView.top); - if (tab) { - gBrowser.removeEventListener("load", onLoad, true); - resolve(); - } - }, true); + return BrowserTestUtils.firstBrowserLoaded(window, true, (browser) => { + let tab = gBrowser.getTabForBrowser(browser); + return !!tab; }); } @@ -121,7 +119,8 @@ add_task(async function test_same_origin() { activeLoaded: true, activeBlocked: false, passiveLoaded: false, }); - is(content.document.getElementById("mctestdiv").innerHTML, + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv").innerHTML, "Mixed Content Blocker disabled", "OK: Executed mixed script"); }); }); @@ -142,7 +141,8 @@ add_task(async function test_different_origin() { activeLoaded: false, activeBlocked: true, passiveLoaded: false, }); - is(content.document.getElementById("mctestdiv").innerHTML, + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv").innerHTML, "Mixed Content Blocker enabled", "OK: Blocked mixed script"); }); }); @@ -163,7 +163,8 @@ add_task(async function test_same_origin_metarefresh_same_origin() { activeLoaded: true, activeBlocked: false, passiveLoaded: false, }); - is(content.document.getElementById("mctestdiv").innerHTML, + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv").innerHTML, "Mixed Content Blocker disabled", "OK: Executed mixed script"); }, true); }); @@ -183,7 +184,8 @@ add_task(async function test_same_origin_metarefresh_different_origin() { activeLoaded: false, activeBlocked: true, passiveLoaded: false, }); - is(content.document.getElementById("mctestdiv").innerHTML, + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv").innerHTML, "Mixed Content Blocker enabled", "OK: Blocked mixed script"); }, true); }); @@ -203,7 +205,8 @@ add_task(async function test_same_origin_302redirect_same_origin() { ok(!gIdentityHandler._identityBox.classList.contains("mixedActiveBlocked"), "OK: Mixed Content is NOT being blocked"); - is(content.document.getElementById("mctestdiv").innerHTML, + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv").innerHTML, "Mixed Content Blocker disabled", "OK: Executed mixed script"); }); }); @@ -223,7 +226,8 @@ add_task(async function test_same_origin_302redirect_different_origin() { activeLoaded: false, activeBlocked: true, passiveLoaded: false, }); - is(content.document.getElementById("mctestdiv").innerHTML, + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.getElementById("mctestdiv").innerHTML, "Mixed Content Blocker enabled", "OK: Blocked mixed script"); }); }); diff --git a/browser/base/content/test/siteIdentity/browser_identity_UI.js b/browser/base/content/test/siteIdentity/browser_identity_UI.js index c733e314e564..5d884e9b9a7c 100644 --- a/browser/base/content/test/siteIdentity/browser_identity_UI.js +++ b/browser/base/content/test/siteIdentity/browser_identity_UI.js @@ -7,7 +7,7 @@ function test() { ok(gIdentityHandler, "gIdentityHandler should exist"); BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank", true).then(() => { - gBrowser.selectedBrowser.addEventListener("load", checkResult, true); + BrowserTestUtils.addContentEventListener(gBrowser.selectedBrowser, "load", checkResult, true); nextTest(); }); } @@ -79,7 +79,6 @@ function nextTest() { } if (gCurrentTestIndex == -1) { - gBrowser.selectedBrowser.removeEventListener("load", checkResult, true); gBrowser.removeCurrentTab(); finish(); return; @@ -123,8 +122,8 @@ function nextTest() { } } -function checkResult(event) { - if (event.target.URL == "about:blank") +function checkResult() { + if (gBrowser.selectedBrowser.currentURI.spec == "about:blank") return; // Sanity check other values, and the value of gIdentityHandler.getEffectiveHost() diff --git a/browser/base/content/test/urlbar/browser_urlbarHashChangeProxyState.js b/browser/base/content/test/urlbar/browser_urlbarHashChangeProxyState.js index 21a0f52f3085..d43b12856624 100644 --- a/browser/base/content/test/urlbar/browser_urlbarHashChangeProxyState.js +++ b/browser/base/content/test/urlbar/browser_urlbarHashChangeProxyState.js @@ -92,7 +92,7 @@ add_task(async function() { let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:newtab", false); // NB: CPOW usage because new tab pages can be preloaded, in which case no // load events fire. - await BrowserTestUtils.waitForCondition(() => !tab.linkedBrowser.contentDocument.hidden); + await BrowserTestUtils.waitForCondition(() => !tab.linkedBrowser.contentDocumentAsCPOW.hidden); let url = "https://example.org/browser/browser/base/content/test/urlbar/dummy_page.html#foo"; gURLBar.value = url; gURLBar.select(); diff --git a/browser/base/content/test/urlbar/browser_urlbarKeepStateAcrossTabSwitches.js b/browser/base/content/test/urlbar/browser_urlbarKeepStateAcrossTabSwitches.js index 86d092e8acdd..6527d7753efa 100644 --- a/browser/base/content/test/urlbar/browser_urlbarKeepStateAcrossTabSwitches.js +++ b/browser/base/content/test/urlbar/browser_urlbarKeepStateAcrossTabSwitches.js @@ -7,9 +7,11 @@ add_task(async function() { let input = "i-definitely-dont-exist.example.com"; let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank", false); + let browser = tab.linkedBrowser; // NB: CPOW usage because new tab pages can be preloaded, in which case no // load events fire. - await BrowserTestUtils.waitForCondition(() => !tab.linkedBrowser.contentDocument.hidden); + // eslint-disable-next-line mozilla/no-cpows-in-tests + await BrowserTestUtils.waitForCondition(() => browser.contentDocumentAsCPOW && !browser.contentDocumentAsCPOW.hidden); let errorPageLoaded = BrowserTestUtils.waitForErrorPage(tab.linkedBrowser); gURLBar.value = input; gURLBar.select(); @@ -30,9 +32,11 @@ add_task(async function() { let input = "To be or not to be-that is the question"; await SpecialPowers.pushPrefEnv({set: [["keyword.enabled", false]]}); let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:blank", false); + let browser = tab.linkedBrowser; // NB: CPOW usage because new tab pages can be preloaded, in which case no // load events fire. - await BrowserTestUtils.waitForCondition(() => !tab.linkedBrowser.contentDocument.hidden); + // eslint-disable-next-line mozilla/no-cpows-in-tests + await BrowserTestUtils.waitForCondition(() => browser.contentDocumentAsCPOW && !browser.contentDocumentAsCPOW.hidden); let errorPageLoaded = BrowserTestUtils.waitForErrorPage(tab.linkedBrowser); gURLBar.value = input; gURLBar.select(); diff --git a/browser/components/contextualidentity/test/browser/browser_usercontext.js b/browser/components/contextualidentity/test/browser/browser_usercontext.js index 27fb560369a2..d7787a82fc8c 100644 --- a/browser/components/contextualidentity/test/browser/browser_usercontext.js +++ b/browser/components/contextualidentity/test/browser/browser_usercontext.js @@ -70,7 +70,7 @@ add_task(async function test() { // get the title // eslint-disable-next-line mozilla/no-cpows-in-tests - let title = browser.contentDocument.title.trim().split("|"); + let title = browser.contentDocumentAsCPOW.title.trim().split("|"); // check each item in the title and validate it meets expectatations for (let part of title) { diff --git a/browser/components/customizableui/test/browser_synced_tabs_menu.js b/browser/components/customizableui/test/browser_synced_tabs_menu.js index 132e14381f63..be902989e4d2 100644 --- a/browser/components/customizableui/test/browser_synced_tabs_menu.js +++ b/browser/components/customizableui/test/browser_synced_tabs_menu.js @@ -169,9 +169,7 @@ add_task(async function() { is(gBrowser.tabs.length, 2, "there's a new tab"); await new Promise(resolve => { if (gBrowser.selectedBrowser.currentURI.spec == "about:blank") { - gBrowser.selectedBrowser.addEventListener("load", function(e) { - resolve(); - }, {capture: true, once: true}); + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(resolve); return; } // the new tab has already transitioned away from about:blank so we diff --git a/browser/components/customizableui/test/head.js b/browser/components/customizableui/test/head.js index e2d7a9323ef7..10e13be5e436 100644 --- a/browser/components/customizableui/test/head.js +++ b/browser/components/customizableui/test/head.js @@ -401,7 +401,7 @@ function promiseTabHistoryNavigation(aDirection = -1, aConditionFn) { } gBrowser.addEventListener("pageshow", listener, true); - content.history.go(aDirection); + gBrowser.contentWindowAsCPOW.history.go(aDirection); }); } diff --git a/browser/components/extensions/test/browser/head.js b/browser/components/extensions/test/browser/head.js index 6647ce662e0a..cd71bcd06857 100644 --- a/browser/components/extensions/test/browser/head.js +++ b/browser/components/extensions/test/browser/head.js @@ -289,7 +289,7 @@ async function openContextMenuInSidebar(selector = "body") { async function openContextMenuInFrame(frameId) { let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown"); - let doc = gBrowser.selectedBrowser.contentDocument; + let doc = gBrowser.selectedBrowser.contentDocumentAsCPOW; let frame = doc.getElementById(frameId); EventUtils.synthesizeMouseAtCenter(frame.contentDocument.body, {type: "contextmenu"}, frame.contentWindow); await popupShownPromise; diff --git a/browser/components/preferences/in-content/tests/browser_siteData.js b/browser/components/preferences/in-content/tests/browser_siteData.js index 8419af4a188e..f8cec1f243b4 100644 --- a/browser/components/preferences/in-content/tests/browser_siteData.js +++ b/browser/components/preferences/in-content/tests/browser_siteData.js @@ -140,7 +140,7 @@ add_task(async function() { // Open a test site which would save into quota manager await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_QUOTA_USAGE_URL); // eslint-disable-next-line mozilla/no-cpows-in-tests - await waitForEvent(gBrowser.selectedBrowser.contentWindow, "test-indexedDB-done"); + await waitForEvent(gBrowser.selectedBrowser.contentWindowAsCPOW, "test-indexedDB-done"); await BrowserTestUtils.removeTab(gBrowser.selectedTab); let updatedPromise = promiseSiteDataManagerSitesUpdated(); @@ -224,7 +224,7 @@ add_task(async function() { await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_QUOTA_USAGE_URL); // eslint-disable-next-line mozilla/no-cpows-in-tests - await waitForEvent(gBrowser.selectedBrowser.contentWindow, "test-indexedDB-done"); + await waitForEvent(gBrowser.selectedBrowser.contentWindowAsCPOW, "test-indexedDB-done"); await BrowserTestUtils.removeTab(gBrowser.selectedTab); await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true }); diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js index 9c77d2baeac0..b85b4b7f027a 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js @@ -103,7 +103,7 @@ function get_cache_for_private_window() { win.gBrowser.selectedTab = tab; let newTabBrowser = win.gBrowser.getBrowserForTab(tab); - newTabBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(newTabBrowser).then(function() { executeSoon(function() { getStorageEntryCount("private", function(nrEntriesP) { @@ -119,7 +119,7 @@ function get_cache_for_private_window() { }); }); }); - }, {capture: true, once: true}); + }); }); }); } diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js index c721e2fa9a27..1c0e5fef0bbe 100644 --- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_ui.js @@ -14,7 +14,7 @@ function test() { let cmd; function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser).then(function() { ok(aWindow.gPrivateBrowsingUI, "The gPrivateBrowsingUI object exists"); pbMenuItem = aWindow.document.getElementById("menu_newPrivateWindow"); @@ -30,7 +30,7 @@ function test() { aIsPrivateMode + ")"); aCallback(); - }, {capture: true, once: true}); + }); aWindow.gBrowser.selectedBrowser.loadURI(testURI); } diff --git a/browser/components/search/test/browser_aboutSearchReset.js b/browser/components/search/test/browser_aboutSearchReset.js index f748c22111ca..60ff62fcf480 100644 --- a/browser/components/search/test/browser_aboutSearchReset.js +++ b/browser/components/search/test/browser_aboutSearchReset.js @@ -65,7 +65,7 @@ var gTests = [ let loadPromise = promiseStoppedLoad(expectedURL); // eslint-disable-next-line mozilla/no-cpows-in-tests - gBrowser.contentDocument.getElementById("searchResetKeepCurrent").click(); + gBrowser.contentDocumentAsCPOW.getElementById("searchResetKeepCurrent").click(); await loadPromise; is(engine, Services.search.currentEngine, @@ -84,7 +84,7 @@ var gTests = [ let currentEngine = Services.search.currentEngine; let originalEngine = Services.search.originalDefaultEngine; // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = gBrowser.contentDocument; + let doc = gBrowser.contentDocumentAsCPOW; let defaultEngineSpan = doc.getElementById("defaultEngine"); is(defaultEngineSpan.textContent, originalEngine.name, "the name of the original default engine is displayed"); @@ -117,7 +117,7 @@ var gTests = [ false, "about:preferences#search"); // eslint-disable-next-line mozilla/no-cpows-in-tests - gBrowser.contentDocument.getElementById("linkSettingsPage").click(); + gBrowser.contentDocumentAsCPOW.getElementById("linkSettingsPage").click(); await loadPromise; checkTelemetryRecords(TELEMETRY_RESULT_ENUM.OPENED_SETTINGS); diff --git a/browser/components/sessionstore/test/browser_739531.js b/browser/components/sessionstore/test/browser_739531.js index fe60cde4f159..14c81a985ec2 100644 --- a/browser/components/sessionstore/test/browser_739531.js +++ b/browser/components/sessionstore/test/browser_739531.js @@ -13,11 +13,13 @@ function test() { let loadCount = 0; let tab = BrowserTestUtils.addTab(gBrowser, testURL); - tab.linkedBrowser.addEventListener("load", function onLoad(aEvent) { + + let removeFunc; + removeFunc = BrowserTestUtils.addContentEventListener(tab.linkedBrowser, "load", function onLoad(aEvent) { // make sure both the page and the frame are loaded if (++loadCount < 2) return; - tab.linkedBrowser.removeEventListener("load", onLoad, true); + removeFunc(); // executeSoon to allow the JS to execute on the page executeSoon(function() { diff --git a/browser/components/shell/test/browser_1119088.js b/browser/components/shell/test/browser_1119088.js index ed70cdb5b7a9..ffe159f295c8 100644 --- a/browser/components/shell/test/browser_1119088.js +++ b/browser/components/shell/test/browser_1119088.js @@ -4,8 +4,6 @@ let NS_MAC_USER_LIB_DIR = "ULibDir"; function onPageLoad() { - gBrowser.selectedBrowser.removeEventListener("load", onPageLoad, true); - let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. getService(Ci.nsIDirectoryServiceProvider); @@ -34,7 +32,8 @@ function onPageLoad() { let shell = Cc["@mozilla.org/browser/shell-service;1"]. getService(Ci.nsIShellService); - let image = content.document.images[0]; + // eslint-disable-next-line mozilla/no-cpows-in-tests + let image = gBrowser.contentDocumentAsCPOW.images[0]; shell.setDesktopBackground(image, 0, "logo.png"); setTimeout(function() { @@ -59,8 +58,8 @@ function onPageLoad() { function test() { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", onPageLoad, true); - content.location = "about:logo"; + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onPageLoad, false, "about:logo"); + gBrowser.loadURI("about:logo"); waitForExplicitFinish(); } diff --git a/browser/components/translation/test/browser_translation_bing.js b/browser/components/translation/test/browser_translation_bing.js index 0c0ddb776a76..77b79049756f 100644 --- a/browser/components/translation/test/browser_translation_bing.js +++ b/browser/components/translation/test/browser_translation_bing.js @@ -121,12 +121,9 @@ function promiseTestPageLoad(url) { return new Promise(resolve => { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url); let browser = gBrowser.selectedBrowser; - browser.addEventListener("load", function listener() { - if (browser.currentURI.spec == "about:blank") - return; + BrowserTestUtils.browserLoaded(browser, false, (loadurl) => loadurl != "about:blank").then(() => { info("Page loaded: " + browser.currentURI.spec); - browser.removeEventListener("load", listener, true); resolve(tab); - }, true); + }); }); } diff --git a/browser/components/translation/test/browser_translation_exceptions.js b/browser/components/translation/test/browser_translation_exceptions.js index dbda0e51ed9b..89abd8fa93bd 100644 --- a/browser/components/translation/test/browser_translation_exceptions.js +++ b/browser/components/translation/test/browser_translation_exceptions.js @@ -21,7 +21,7 @@ function test() { gBrowser.removeTab(tab); Services.prefs.clearUserPref(kShowUIPref); }); - tab.linkedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => { (async function() { for (let testCase of gTests) { info(testCase.desc); @@ -31,9 +31,9 @@ function test() { ok(false, "Unexpected Exception: " + ex); finish(); }); - }, {capture: true, once: true}); + }); - content.location = "http://example.com/"; + gBrowser.selectedBrowser.loadURI("http://example.com/"); } function getLanguageExceptions() { diff --git a/browser/components/translation/test/browser_translation_infobar.js b/browser/components/translation/test/browser_translation_infobar.js index 3efa7b0dca86..4fd03a9fa0f4 100644 --- a/browser/components/translation/test/browser_translation_infobar.js +++ b/browser/components/translation/test/browser_translation_infobar.js @@ -77,7 +77,7 @@ function test() { Services.prefs.setBoolPref(kShowUIPref, true); let tab = BrowserTestUtils.addTab(gBrowser); gBrowser.selectedTab = tab; - tab.linkedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => { TranslationStub.browser = gBrowser.selectedBrowser; registerCleanupFunction(function() { gBrowser.removeTab(tab); @@ -86,9 +86,9 @@ function test() { run_tests(() => { finish(); }); - }, {capture: true, once: true}); + }); - content.location = "data:text/plain,test page"; + gBrowser.selectedBrowser.loadURI("data:text/plain,test page"); } function checkURLBarIcon(aExpectTranslated = false) { diff --git a/browser/components/translation/test/browser_translation_yandex.js b/browser/components/translation/test/browser_translation_yandex.js index 5f4b591f3331..7e68397768a8 100644 --- a/browser/components/translation/test/browser_translation_yandex.js +++ b/browser/components/translation/test/browser_translation_yandex.js @@ -116,13 +116,10 @@ function promiseTestPageLoad(url) { return new Promise(resolve => { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url); let browser = gBrowser.selectedBrowser; - browser.addEventListener("load", function listener() { - if (browser.currentURI.spec == "about:blank") - return; + BrowserTestUtils.browserLoaded(browser, false, (loadurl) => loadurl != "about:blank").then(() => { info("Page loaded: " + browser.currentURI.spec); - browser.removeEventListener("load", listener, true); resolve(tab); - }, true); + }); }); } diff --git a/browser/components/uitour/test/head.js b/browser/components/uitour/test/head.js index 622fb6bef44c..7252658c8420 100644 --- a/browser/components/uitour/test/head.js +++ b/browser/components/uitour/test/head.js @@ -263,7 +263,7 @@ function loadUITourTestPage(callback, host = "https://example.org/") { gTestTab = BrowserTestUtils.addTab(gBrowser, url); gBrowser.selectedTab = gTestTab; - gTestTab.linkedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(gTestTab.linkedBrowser).then(() => { if (gMultiProcessBrowser) { // When e10s is enabled, make gContentAPI and gContentWindow proxies which has every property // return a function which calls the method of the same name on @@ -352,7 +352,7 @@ function loadUITourTestPage(callback, host = "https://example.org/") { } waitForFocus(callback, gTestTab.linkedBrowser); - }, {capture: true, once: true}); + }); } // Wrapper for UITourTest to be used by add_task tests. diff --git a/browser/extensions/onboarding/test/browser/browser_onboarding_skip_tour.js b/browser/extensions/onboarding/test/browser/browser_onboarding_skip_tour.js index 7b2f1ec798e7..0388dc4056ca 100644 --- a/browser/extensions/onboarding/test/browser/browser_onboarding_skip_tour.js +++ b/browser/extensions/onboarding/test/browser/browser_onboarding_skip_tour.js @@ -37,7 +37,7 @@ add_task(async function test_hide_skip_button_via_perf() { await promiseOnboardingOverlayOpened(tab.linkedBrowser); // eslint-disable-next-line mozilla/no-cpows-in-tests - ok(!content.document.querySelector("#onboarding-skip-tour-button"), "should not render the skip button"); + ok(!gBrowser.contentDocumentAsCPOW.querySelector("#onboarding-skip-tour-button"), "should not render the skip button"); await BrowserTestUtils.removeTab(tab); }); diff --git a/browser/extensions/onboarding/test/browser/browser_onboarding_tourset.js b/browser/extensions/onboarding/test/browser/browser_onboarding_tourset.js index 28ed8db582df..0ab96b321dd2 100644 --- a/browser/extensions/onboarding/test/browser/browser_onboarding_tourset.js +++ b/browser/extensions/onboarding/test/browser/browser_onboarding_tourset.js @@ -14,7 +14,7 @@ add_task(async function test_onboarding_default_new_tourset() { await promiseOnboardingOverlayOpened(tab.linkedBrowser); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = content && content.document; + let doc = gBrowser.contentDocumentAsCPOW; let doms = doc.querySelectorAll(".onboarding-tour-item"); is(doms.length, TOUR_IDs.length, "has exact tour numbers"); doms.forEach((dom, idx) => { @@ -45,7 +45,7 @@ add_task(async function test_onboarding_custom_new_tourset() { await promiseOnboardingOverlayOpened(tab.linkedBrowser); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = content && content.document; + let doc = gBrowser.contentDocumentAsCPOW; let doms = doc.querySelectorAll(".onboarding-tour-item"); is(doms.length, CUSTOM_NEW_TOURs.length, "has exact tour numbers"); doms.forEach((dom, idx) => { @@ -75,7 +75,7 @@ add_task(async function test_onboarding_custom_update_tourset() { await promiseOnboardingOverlayOpened(tab.linkedBrowser); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = content && content.document; + let doc = gBrowser.contentDocumentAsCPOW; let doms = doc.querySelectorAll(".onboarding-tour-item"); is(doms.length, CUSTOM_UPDATE_TOURs.length, "has exact tour numbers"); doms.forEach((dom, idx) => { diff --git a/browser/extensions/shield-recipe-client/test/browser/browser_about_studies.js b/browser/extensions/shield-recipe-client/test/browser/browser_about_studies.js index a70b7595fcf3..699d51574fa3 100644 --- a/browser/extensions/shield-recipe-client/test/browser/browser_about_studies.js +++ b/browser/extensions/shield-recipe-client/test/browser/browser_about_studies.js @@ -15,7 +15,7 @@ decorate_task( withAboutStudies, async function testAboutStudiesWorks(browser) { // eslint-disable-next-line mozilla/no-cpows-in-tests - ok(browser.contentDocument.getElementById("app"), "App element was found"); + ok(browser.contentDocumentAsCPOW.getElementById("app"), "App element was found"); } ); @@ -43,6 +43,8 @@ decorate_task( decorate_task( withAboutStudies, async function testUpdatePreferencesNewOrganization(browser) { + let loadPromise = BrowserTestUtils.firstBrowserLoaded(window); + // We have to use gBrowser instead of browser in most spots since we're // dealing with a new tab outside of the about:studies tab. const tab = await BrowserTestUtils.switchTab(gBrowser, () => { @@ -51,13 +53,9 @@ decorate_task( }); }); - /* eslint-disable mozilla/no-cpows-in-tests */ - if (gBrowser.contentDocument.readyState !== "complete") { - await BrowserTestUtils.waitForEvent(gBrowser.contentWindow, "load"); - } + await loadPromise; - const location = gBrowser.contentWindow.location.href; - /* eslint-enable mozilla/no-cpows-in-tests */ + const location = gBrowser.currentURI.spec; is( location, "about:preferences#privacy", diff --git a/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js b/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js index 339f9021fd5e..3d271514b742 100644 --- a/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js +++ b/browser/modules/test/browser/browser_UsageTelemetry_content_aboutHome.js @@ -53,12 +53,7 @@ add_task(async function test_abouthome_simpleQuery() { let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); info("Setup waiting for AboutHomeLoadSnippetsCompleted."); - let promiseAboutHomeLoaded = new Promise(resolve => { - tab.linkedBrowser.addEventListener("AboutHomeLoadSnippetsCompleted", function loadListener(event) { - tab.linkedBrowser.removeEventListener("AboutHomeLoadSnippetsCompleted", loadListener, true); - resolve(); - }, true, true); - }); + let promiseAboutHomeLoaded = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "AboutHomeLoadSnippetsCompleted", true, null, true); info("Load about:home."); tab.linkedBrowser.loadURI("about:home"); @@ -105,12 +100,7 @@ add_task(async function test_abouthome_activitystream_simpleQuery() { let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); info("Setup waiting for search input to initialise."); - let promiseAboutHomeSearchLoaded = new Promise(resolve => { - tab.linkedBrowser.addEventListener("ContentSearchClient", function loadListener(event) { - tab.linkedBrowser.removeEventListener("ContentSearchClient", loadListener, true); - executeSoon(resolve); - }, true, true); - }); + let promiseAboutHomeSearchLoaded = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "ContentSearchClient", true, null, true).then(() => false); info("Load about:home."); tab.linkedBrowser.loadURI("about:home"); diff --git a/devtools/client/commandline/test/helpers.js b/devtools/client/commandline/test/helpers.js index 83ee5c946d1d..911e78500f9c 100644 --- a/devtools/client/commandline/test/helpers.js +++ b/devtools/client/commandline/test/helpers.js @@ -132,7 +132,7 @@ var { helpers, assert } = (function () { options.browser = tabbrowser.getBrowserForTab(options.tab); options.target = TargetFactory.forTab(options.tab); - var loaded = helpers.listenOnce(options.browser, "load", true).then(function (ev) { + var loaded = BrowserTestUtils.browserLoaded(options.browser).then(function () { var reply = callback.call(null, options); return Promise.resolve(reply).catch(function (error) { @@ -149,7 +149,7 @@ var { helpers, assert } = (function () { }); }); - options.browser.contentWindow.location = url; + options.browser.loadURI(url); return loaded; }; diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_WorkerActor.attach.js b/devtools/client/debugger/test/mochitest/browser_dbg_WorkerActor.attach.js index 654a8f809a0c..61453bfbc2e2 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_WorkerActor.attach.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_WorkerActor.attach.js @@ -45,7 +45,7 @@ function test() { is(workerClient2.isClosed, false, "worker in tab 2 should not be closed"); executeSoon(() => { - tab.linkedBrowser.contentWindow.history.back(); + tab.linkedBrowser.goBack(); }); yield waitForWorkerClose(workerClient2); is(workerClient2.isClosed, true, "worker in tab 2 should be closed"); diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-01.js b/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-01.js index f876cda93322..e75ebea23da9 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-01.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-01.js @@ -90,7 +90,7 @@ function testEventListeners(aThreadClient) { ok(node, "There is a node property."); ok(node.object, "There is a node object property."); ok(node.selector == "window" || - content.document.querySelectorAll(node.selector).length == 1, + gBrowser.contentDocumentAsCPOW.querySelectorAll(node.selector).length == 1, "The node property is a unique CSS selector."); let func = l.function; diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-02.js b/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-02.js index 5569306e639b..50dd240f1e04 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-02.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_event-listeners-02.js @@ -89,7 +89,7 @@ function testEventListeners(aThreadClient) { ok(node, "There is a node property."); ok(node.object, "There is a node object property."); ok(node.selector == "window" || - content.document.querySelectorAll(node.selector).length == 1, + gBrowser.contentDocumentAsCPOW.querySelectorAll(node.selector).length == 1, "The node property is a unique CSS selector."); let func = l.function; diff --git a/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js b/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js index 41320141a196..8845c29be817 100644 --- a/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js +++ b/devtools/client/debugger/test/mochitest/browser_dbg_sources-contextmenu-02.js @@ -43,10 +43,10 @@ function test() { gBrowser.tabContainer.addEventListener("TabOpen", function (e) { ok(true, "A new tab loaded"); - gBrowser.addEventListener("DOMContentLoaded", function (e) { + BrowserTestUtils.waitForContentEvent(e.target.linkedBrowser, "DOMContentLoaded").then(function () { // Pass along the new tab's URI. resolve(gBrowser.currentURI.spec); - }, {once: true}); + }); }, {once: true}); }); } diff --git a/devtools/client/debugger/test/mochitest/head.js b/devtools/client/debugger/test/mochitest/head.js index 903aa6a24d7f..26a863715a6d 100644 --- a/devtools/client/debugger/test/mochitest/head.js +++ b/devtools/client/debugger/test/mochitest/head.js @@ -567,7 +567,7 @@ let initDebugger = Task.async(function*(urlOrTab, options) { } info("Debugee tab added successfully: " + urlOrTab); - let debuggee = tab.linkedBrowser.contentWindow.wrappedJSObject; + let debuggee = tab.linkedBrowser.contentWindowAsCPOW.wrappedJSObject; let target = TargetFactory.forTab(tab); let toolbox = yield gDevTools.showToolbox(target, "jsdebugger"); diff --git a/devtools/client/framework/test/browser_keybindings_01.js b/devtools/client/framework/test/browser_keybindings_01.js index 6cb4ab650218..a28613968d27 100644 --- a/devtools/client/framework/test/browser_keybindings_01.js +++ b/devtools/client/framework/test/browser_keybindings_01.js @@ -28,7 +28,7 @@ function test() let keysetMap = { }; addTab(TEST_URL).then(function () { - doc = content.document; + doc = gBrowser.contentDocumentAsCPOW; node = doc.querySelector("h1"); waitForFocus(setupKeyBindingsTest); }); diff --git a/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing.js b/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing.js index 3273f439514e..5d9b0e2cb010 100644 --- a/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing.js +++ b/devtools/client/framework/test/browser_toolbox_options_enable_serviceworkers_testing.js @@ -83,15 +83,10 @@ function toggleServiceWorkersTestingCheckbox() { } function reload() { - let deferred = defer(); - - gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { - gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); - deferred.resolve(); - }, true); + let promise = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); executeInContent("devtools:test:reload", {}, {}, false); - return deferred.promise; + return promise; } function testRegisterSuccesses(data) { diff --git a/devtools/client/framework/test/shared-head.js b/devtools/client/framework/test/shared-head.js index c9cb21d2f1bc..cf85b36b8c03 100644 --- a/devtools/client/framework/test/shared-head.js +++ b/devtools/client/framework/test/shared-head.js @@ -88,7 +88,7 @@ const ConsoleObserver = { observe: function (subject, topic, data) { let message = subject.wrappedJSObject.arguments[0]; - if (/Failed propType/.test(message)) { + if (message && /Failed propType/.test(message.toString())) { ok(false, message); } } diff --git a/devtools/client/inspector/markup/test/browser_markup_load_01.js b/devtools/client/inspector/markup/test/browser_markup_load_01.js index c0fe2be0c019..ad5cf8313816 100644 --- a/devtools/client/inspector/markup/test/browser_markup_load_01.js +++ b/devtools/client/inspector/markup/test/browser_markup_load_01.js @@ -74,9 +74,5 @@ function* chooseWithInspectElementContextMenu(selector, tab) { } function waitForLinkedBrowserEvent(tab, event) { - return new Promise(resolve => { - tab.linkedBrowser.addEventListener(event, function () { - resolve(); - }, {capture: true, once: true}); - }); + return BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, event, true); } diff --git a/devtools/client/inspector/test/browser_inspector_highlighter-05.js b/devtools/client/inspector/test/browser_inspector_highlighter-05.js index 479e596c8a09..59caa789152b 100644 --- a/devtools/client/inspector/test/browser_inspector_highlighter-05.js +++ b/devtools/client/inspector/test/browser_inspector_highlighter-05.js @@ -50,7 +50,7 @@ add_task(function* () { info("Open the inspector to a blank page."); let { inspector, tab, testActor } = yield openInspectorForURL("about:blank"); - let pageLoaded = waitForPageLoad(tab); + let pageLoaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser); info("Navigate to the test url and waiting for the page to be loaded."); yield navigateTo(inspector, TEST_URL); @@ -64,7 +64,3 @@ add_task(function* () { is(yield testActor.isHighlighting(), true, "Box Model highlighter is working as expected."); }); - -const waitForPageLoad = (tab) => new Promise(resolve => { - tab.linkedBrowser.addEventListener("load", resolve, {capture: true, once: true}); -}); diff --git a/devtools/client/inspector/test/browser_inspector_startup.js b/devtools/client/inspector/test/browser_inspector_startup.js index 74f7006914a1..edd144f9501e 100644 --- a/devtools/client/inspector/test/browser_inspector_startup.js +++ b/devtools/client/inspector/test/browser_inspector_startup.js @@ -69,11 +69,7 @@ add_task(function* () { }); function waitForLinkedBrowserEvent(tab, event) { - return new Promise(resolve => { - tab.linkedBrowser.addEventListener(event, function () { - resolve(); - }, {capture: true, once: true}); - }); + return BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, event, true); } function contentReadyState(tab) { diff --git a/devtools/client/responsive.html/test/browser/browser_window_close.js b/devtools/client/responsive.html/test/browser/browser_window_close.js index 29d9d1e344df..4d127f227ede 100644 --- a/devtools/client/responsive.html/test/browser/browser_window_close.js +++ b/devtools/client/responsive.html/test/browser/browser_window_close.js @@ -9,7 +9,7 @@ add_task(function* () { let newWindow = yield newWindowPromise; newWindow.focus(); - yield once(newWindow.gBrowser, "load", true); + yield BrowserTestUtils.browserLoaded(newWindow.gBrowser.selectedBrowser); let tab = newWindow.gBrowser.selectedTab; yield openRDM(tab); diff --git a/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js b/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js index 811a07054972..1736db477238 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_browser_last_window_closing.js @@ -14,11 +14,11 @@ function test() CloseObserver.init(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,

test browser last window closing

"; + gBrowser.loadURI("data:text/html;charset=utf8,

test browser last window closing

"); } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js b/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js index 7d22814b4036..c58739a6313d 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_chrome_context_pref.js @@ -12,11 +12,11 @@ function test() Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,Scratchpad test for bug 646070 - chrome context preference"; + gBrowser.loadURI("data:text/html,Scratchpad test for bug 646070 - chrome context preference"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js index e41b82500be8..738ece698a0b 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js @@ -7,11 +7,11 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,test context switch in Scratchpad"; + gBrowser.loadURI("data:text/html,test context switch in Scratchpad"); } function runTests() { @@ -49,7 +49,7 @@ function runTests() { ok(!pageResult, "no content.foobarBug636725"); }, then: function* () { - is(content.wrappedJSObject.foobarBug636725, "aloha", + is(gBrowser.contentWindowAsCPOW.wrappedJSObject.foobarBug636725, "aloha", "content.foobarBug636725 has been set"); } }, { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js b/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js index 7f136a8b77c4..e6957446a900 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_display_non_error_exceptions.js @@ -8,12 +8,12 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests, {"state":{"text":""}}); - }, {capture: true, once: true}); + }); - content.location = "data:text/html, test that exceptions are output as " + - "comments correctly in Scratchpad"; + gBrowser.loadURI("data:text/html, test that exceptions are output as " + + "comments correctly in Scratchpad"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js b/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js index 66616dd2f3a8..a96a3b6119e3 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_display_outputs_errors.js @@ -8,12 +8,12 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests, {"state":{"text":""}}); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test that exceptions are output as " + - "comments for 'display' and not sent to the console in Scratchpad"; + gBrowser.loadURI("data:text/html,

test that exceptions are output as " + + "comments for 'display' and not sent to the console in Scratchpad"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js b/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js index b67d63f0708e..35519817d63e 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_edit_ui_updates.js @@ -13,11 +13,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,test Edit menu updates Scratchpad - bug 699130"; + gBrowser.loadURI("data:text/html,test Edit menu updates Scratchpad - bug 699130"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js b/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js index 7cb1de460ac7..5b7d80c80e34 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_eval_func.js @@ -7,11 +7,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,test Scratchpad eval function."; + gBrowser.loadURI("data:text/html;charset=utf8,test Scratchpad eval function."); } function reportErrorAndQuit(error) { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js b/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js index 950bb5fbb0a3..804cea16f234 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_execute_print.js @@ -7,11 +7,11 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test run() and display() in Scratchpad"; + gBrowser.loadURI("data:text/html,

test run() and display() in Scratchpad"); } function runTests() { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_falsy.js b/devtools/client/scratchpad/test/browser_scratchpad_falsy.js index ad5b593a808b..8dc560fc2e6a 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_falsy.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_falsy.js @@ -8,11 +8,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(testFalsy); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test falsy display() values in Scratchpad"; + gBrowser.loadURI("data:text/html,

test falsy display() values in Scratchpad"); } function testFalsy() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_files.js b/devtools/client/scratchpad/test/browser_scratchpad_files.js index 1dba4cdf3325..d39f7a6b4d97 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_files.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_files.js @@ -16,11 +16,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test file open and save in Scratchpad"; + gBrowser.loadURI("data:text/html,

test file open and save in Scratchpad"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js b/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js index 6350ecdab185..b29ba6b476d2 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_goto_line_ui.js @@ -8,11 +8,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test the 'Jump to line' feature in Scratchpad"; + gBrowser.loadURI("data:text/html,

test the 'Jump to line' feature in Scratchpad"); } function runTests(aWindow, aScratchpad) diff --git a/devtools/client/scratchpad/test/browser_scratchpad_help_key.js b/devtools/client/scratchpad/test/browser_scratchpad_help_key.js index 26116dace001..7688d4c5ce29 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_help_key.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_help_key.js @@ -8,10 +8,10 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - content.location = "data:text/html,Test keybindings for opening Scratchpad MDN Documentation, bug 650760"; - gBrowser.selectedBrowser.addEventListener("load", function () { + gBrowser.loadURI("data:text/html,Test keybindings for opening Scratchpad MDN Documentation, bug 650760"); + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTest); - }, {capture: true, once: true}); + }); } function runTest() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_initialization.js b/devtools/client/scratchpad/test/browser_scratchpad_initialization.js index 3f94970d0c52..94239005e2d0 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_initialization.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_initialization.js @@ -10,11 +10,11 @@ function test() Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,initialization test for Scratchpad"; + gBrowser.loadURI("data:text/html,initialization test for Scratchpad"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_inspect.js b/devtools/client/scratchpad/test/browser_scratchpad_inspect.js index 51657c3bd70b..69ed201bc52f 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_inspect.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_inspect.js @@ -7,11 +7,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,

test inspect() in Scratchpad

"; + gBrowser.loadURI("data:text/html;charset=utf8,

test inspect() in Scratchpad

"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_long_string.js b/devtools/client/scratchpad/test/browser_scratchpad_long_string.js index 1012543a3980..797484f52d93 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_long_string.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_long_string.js @@ -7,11 +7,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,

test long string in Scratchpad

"; + gBrowser.loadURI("data:text/html;charset=utf8,

test long string in Scratchpad

"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_modeline.js b/devtools/client/scratchpad/test/browser_scratchpad_modeline.js index c384979bd352..dc7ff23c7f54 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_modeline.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_modeline.js @@ -15,11 +15,11 @@ function test() { Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, false); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test file open and save in Scratchpad"; + gBrowser.loadURI("data:text/html,

test file open and save in Scratchpad"); } function runTests() { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js b/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js index 298091039e92..379a5c1ece3a 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_open_error_console.js @@ -9,12 +9,12 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,test Scratchpad." + - "openErrorConsole()"; + gBrowser.loadURI("data:text/html;charset=utf8,test Scratchpad." + + "openErrorConsole()"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js b/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js index 996f5711d032..92f50d72387e 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_pprint-02.js @@ -7,11 +7,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,test Scratchpad pretty print."; + gBrowser.loadURI("data:text/html;charset=utf8,test Scratchpad pretty print."); } var gTabsize; diff --git a/devtools/client/scratchpad/test/browser_scratchpad_pprint.js b/devtools/client/scratchpad/test/browser_scratchpad_pprint.js index 28ff0cd6b0a5..222e76b1cafb 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_pprint.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_pprint.js @@ -7,11 +7,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,test Scratchpad pretty print."; + gBrowser.loadURI("data:text/html;charset=utf8,test Scratchpad pretty print."); } function runTests(sw) diff --git a/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js b/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js index 006771133fc1..3b7e74c3ce28 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_pprint_error_goto_line.js @@ -10,12 +10,12 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8," - + "test Scratchpad pretty print error goto line."; + gBrowser.loadURI("data:text/html;charset=utf8," + + "test Scratchpad pretty print error goto line."); } function testJumpToPrettyPrintError(sp, error, remark) { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js b/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js index a7d99029ef97..185ca7abe792 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_recent_files.js @@ -336,11 +336,11 @@ function test() PreferenceObserver.init(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(startTest); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test recent files in Scratchpad"; + gBrowser.loadURI("data:text/html,

test recent files in Scratchpad"); } function finishTest() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js b/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js index 39bbaa2570a0..3a538925ddf4 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_reload_and_run.js @@ -17,11 +17,11 @@ function test() Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,Scratchpad test for bug 740948"; + gBrowser.loadURI("data:text/html,Scratchpad test for bug 740948"); } function runTests() @@ -54,8 +54,8 @@ function runTests() let browser = gBrowser.selectedBrowser; let deferred = defer(); - browser.addEventListener("DOMWindowCreated", function () { - browser.contentWindow.addEventListener("foo", function () { + browser.contentWindowAsCPOW.addEventListener("DOMWindowCreated", function () { + browser.contentWindowAsCPOW.addEventListener("foo", function () { is(browser.contentWindow.document.body.innerHTML, "Modified text", "After reloading, HTML is different."); @@ -64,7 +64,7 @@ function runTests() }, {capture: true, once: true}); }, {capture: true, once: true}); - ok(browser.contentWindow.document.body.innerHTML !== "Modified text", + ok(browser.contentWindowAsCPOW.document.body.innerHTML !== "Modified text", "Before reloading, HTML is intact."); sp.reloadAndRun().then(deferred.promise).then(finish); } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js b/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js index b8db9106fcb3..ec56ef79c330 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_remember_view_options.js @@ -13,12 +13,12 @@ function test() // preference value with the expected value. gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,Bug 1140839" + - "

test Scratchpad should remember View options"; + gBrowser.loadURI("data:text/html,Bug 1140839" + + "

test Scratchpad should remember View options"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js b/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js index 1e922a2e4e21..de773d8f2d91 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_reset_undo.js @@ -25,11 +25,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test that undo get's reset after file load in Scratchpad"; + gBrowser.loadURI("data:text/html,

test that undo get's reset after file load in Scratchpad"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js b/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js index 4cb1a2b0e12c..21480e175145 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_revert_to_saved.js @@ -124,10 +124,10 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(startTest); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,

test reverting to last saved state of" + - " a file

"; + gBrowser.loadURI("data:text/html,

test reverting to last saved state of" + + " a file

"); } diff --git a/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js b/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js index 4e176b45717b..33059172a40b 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_run_error_goto_line.js @@ -10,11 +10,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,test Scratchpad pretty print."; + gBrowser.loadURI("data:text/html;charset=utf8,test Scratchpad pretty print."); } function runTests(sw) diff --git a/devtools/client/scratchpad/test/browser_scratchpad_tab.js b/devtools/client/scratchpad/test/browser_scratchpad_tab.js index c48f1b4cf60b..96684d2e50b7 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_tab.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_tab.js @@ -9,13 +9,13 @@ function test() { waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { Services.prefs.setIntPref("devtools.editor.tabsize", 5); openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,Scratchpad test for the Tab key, bug 660560"; + gBrowser.loadURI("data:text/html,Scratchpad test for the Tab key, bug 660560"); } function runTests() { diff --git a/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js b/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js index 1a55fca95061..5eaaeab772a4 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_tab_switch.js @@ -12,16 +12,16 @@ function test() tab1 = BrowserTestUtils.addTab(gBrowser); gBrowser.selectedTab = tab1; - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { tab2 = BrowserTestUtils.addTab(gBrowser); gBrowser.selectedTab = tab2; - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); - content.location = "data:text/html,test context switch in Scratchpad tab 2"; - }, {capture: true, once: true}); + }); + gBrowser.loadURI("data:text/html,test context switch in Scratchpad tab 2"); + }); - content.location = "data:text/html,test context switch in Scratchpad tab 1"; + gBrowser.loadURI("data:text/html,test context switch in Scratchpad tab 1"); } function runTests() @@ -52,11 +52,11 @@ function runTests() sp.setText("window.foosbug653108 = 'aloha';"); - ok(!content.wrappedJSObject.foosbug653108, + ok(!gBrowser.contentWindowAsCPOW.wrappedJSObject.foosbug653108, "no content.foosbug653108"); sp.run().then(function () { - is(content.wrappedJSObject.foosbug653108, "aloha", + is(gBrowser.contentWindowAsCPOW.wrappedJSObject.foosbug653108, "aloha", "content.foosbug653108 has been set"); gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true); @@ -75,17 +75,16 @@ function runTests2() { sp.setText("window.foosbug653108 = 'ahoyhoy';"); sp.run().then(function () { - is(content.wrappedJSObject.foosbug653108, "ahoyhoy", + is(gBrowser.contentWindowAsCPOW.wrappedJSObject.foosbug653108, "ahoyhoy", "content.foosbug653108 has been set 2"); - gBrowser.selectedBrowser.addEventListener("load", runTests3, true); - content.location = "data:text/html,test context switch in Scratchpad location 2"; + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(runTests3); + gBrowser.loadURI("data:text/html,test context switch in Scratchpad location 2"); }); }); } function runTests3() { - gBrowser.selectedBrowser.removeEventListener("load", runTests3, true); // Check that the sandbox is not cached. sp.setText("typeof foosbug653108;"); diff --git a/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js b/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js index 2e7970754c1f..9bf3b20cc67b 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_throw_output.js @@ -8,11 +8,11 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(testThrowOutput); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,

Test throw outputs in Scratchpad

"; + gBrowser.loadURI("data:text/html;charset=utf8,

Test throw outputs in Scratchpad

"); } function testThrowOutput() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_ui.js b/devtools/client/scratchpad/test/browser_scratchpad_ui.js index 5fda567a5554..d5cb5c1e1da4 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_ui.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_ui.js @@ -7,12 +7,12 @@ function test() waitForExplicitFinish(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(runTests); - }, {capture: true, once: true}); + }); - content.location = "data:text/html,foobarBug636725" + - "

test inspect() in Scratchpad"; + gBrowser.loadURI("data:text/html,foobarBug636725" + + "

test inspect() in Scratchpad"); } function runTests() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js b/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js index 9d2ebdf2c39e..713d673dca4e 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_unsaved.js @@ -24,7 +24,7 @@ function test() testRestoreFromFileUnsaved(); gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - content.location = "data:text/html,

test star* UI for unsaved file changes"; + gBrowser.loadURI("data:text/html,

test star* UI for unsaved file changes"); } function testListeners() diff --git a/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js b/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js index 0b3429edf290..670644aef16c 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_wrong_window_focus.js @@ -26,7 +26,7 @@ function test() // is currently active (it should be the older one). gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(function () { openScratchpad(function () { let sw = gScratchpadWindow; let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {}); @@ -41,9 +41,9 @@ function test() }); }); }); - }, {capture: true, once: true}); + }); - content.location = "data:text/html;charset=utf8,

test window focus for Scratchpad."; + gBrowser.loadURI("data:text/html;charset=utf8,

test window focus for Scratchpad."); } function testFocus(sw, hud) { diff --git a/devtools/client/scratchpad/test/head.js b/devtools/client/scratchpad/test/head.js index da55825624b2..27994f03c2b2 100644 --- a/devtools/client/scratchpad/test/head.js +++ b/devtools/client/scratchpad/test/head.js @@ -93,10 +93,10 @@ function openTabAndScratchpad(aOptions = {}) return new promise(resolve => { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); let {selectedBrowser} = gBrowser; - selectedBrowser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(selectedBrowser).then(function () { openScratchpad((win, sp) => resolve([win, sp]), aOptions); - }, {capture: true, once: true}); - content.location = "data:text/html;charset=utf8," + (aOptions.tabContent || ""); + }); + gBrowser.loadURI("data:text/html;charset=utf8," + (aOptions.tabContent || "")); }); } diff --git a/devtools/client/sourceeditor/test/browser_css_autocompletion.js b/devtools/client/sourceeditor/test/browser_css_autocompletion.js index ddd13cb7553d..b5815de0a224 100644 --- a/devtools/client/sourceeditor/test/browser_css_autocompletion.js +++ b/devtools/client/sourceeditor/test/browser_css_autocompletion.js @@ -81,7 +81,7 @@ function test() { waitForExplicitFinish(); addTab(TEST_URI).then(function () { /* eslint-disable mozilla/no-cpows-in-tests */ - doc = content.document; + doc = gBrowser.contentDocumentAsCPOW; /* eslint-enable mozilla/no-cpows-in-tests */ runTests(); }); diff --git a/devtools/client/sourceeditor/test/browser_css_getInfo.js b/devtools/client/sourceeditor/test/browser_css_getInfo.js index 9028d8fea189..aeaf7966c4ac 100644 --- a/devtools/client/sourceeditor/test/browser_css_getInfo.js +++ b/devtools/client/sourceeditor/test/browser_css_getInfo.js @@ -129,7 +129,7 @@ function test() { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { /* eslint-disable mozilla/no-cpows-in-tests */ - doc = content.document; + doc = gBrowser.contentDocumentAsCPOW; /* eslint-enable mozilla/no-cpows-in-tests */ runTests(); }); diff --git a/devtools/client/sourceeditor/test/browser_css_statemachine.js b/devtools/client/sourceeditor/test/browser_css_statemachine.js index a992380f6a4c..d50b3336c895 100644 --- a/devtools/client/sourceeditor/test/browser_css_statemachine.js +++ b/devtools/client/sourceeditor/test/browser_css_statemachine.js @@ -60,7 +60,7 @@ function test() { gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_URI); BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { /* eslint-disable mozilla/no-cpows-in-tests */ - doc = content.document; + doc = gBrowser.contentDocumentAsCPOW; /* eslint-enable mozilla/no-cpows-in-tests */ runTests(); }); diff --git a/devtools/client/storage/test/head.js b/devtools/client/storage/test/head.js index 6ae580be814b..9b774bf6b4f4 100644 --- a/devtools/client/storage/test/head.js +++ b/devtools/client/storage/test/head.js @@ -57,7 +57,7 @@ registerCleanupFunction(() => { */ function* openTab(url, options = {}) { let tab = yield addTab(url, options); - let content = tab.linkedBrowser.contentWindow; + let content = tab.linkedBrowser.contentWindowAsCPOW; gWindow = content.wrappedJSObject; diff --git a/devtools/client/styleeditor/test/head.js b/devtools/client/styleeditor/test/head.js index 8d5492a72d53..ca5eafee4f33 100644 --- a/devtools/client/styleeditor/test/head.js +++ b/devtools/client/styleeditor/test/head.js @@ -46,13 +46,8 @@ var navigateTo = function (url) { info(`Navigating to ${url}`); let browser = gBrowser.selectedBrowser; - return new Promise(resolve => { - browser.addEventListener("load", function () { - resolve(); - }, {capture: true, once: true}); - - browser.loadURI(url); - }); + browser.loadURI(url); + return BrowserTestUtils.browserLoaded(browser); }; var navigateToAndWaitForStyleSheets = Task.async(function* (url, ui) { diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js index 5cdb179a5adc..d205d3ca046d 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_context_menu_open_url.js @@ -70,9 +70,7 @@ function listenToTabLoad() { return new Promise((resolve) => { gBrowser.tabContainer.addEventListener("TabOpen", function (evt) { let newTab = evt.target; - newTab.linkedBrowser.addEventListener("load", function () { - resolve(newTab); - }, {capture: true, once: true}); + BrowserTestUtils.browserLoaded(newTab.linkedBrowser).then(() => resolve(newTab)); }, {capture: true, once: true}); }); } diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_multiple_windows_and_tabs.js b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_multiple_windows_and_tabs.js index a35ba9d5df99..55129fef11ec 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_multiple_windows_and_tabs.js +++ b/devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_multiple_windows_and_tabs.js @@ -35,7 +35,7 @@ add_task(async function () { for (let tab of tabs) { // Open the console in tab${i}. let hud = await openConsole(tab); - let tabWindow = hud.target.tab.linkedBrowser.contentWindow; + let tabWindow = hud.target.tab.linkedBrowser.contentWindowAsCPOW; let message = "message for tab " + tabs.indexOf(tab); // Log a message in the newly opened console. diff --git a/devtools/client/webconsole/new-console-output/test/mochitest/head.js b/devtools/client/webconsole/new-console-output/test/mochitest/head.js index d9fa31e68f72..29261254984a 100644 --- a/devtools/client/webconsole/new-console-output/test/mochitest/head.js +++ b/devtools/client/webconsole/new-console-output/test/mochitest/head.js @@ -211,10 +211,8 @@ function hideContextMenu(hud) { } function loadDocument(url, browser = gBrowser.selectedBrowser) { - return new Promise(resolve => { - browser.addEventListener("load", resolve, {capture: true, once: true}); - BrowserTestUtils.loadURI(browser, url); - }); + BrowserTestUtils.loadURI(browser, url); + return BrowserTestUtils.browserLoaded(browser); } /** diff --git a/devtools/client/webconsole/test/browser_bug_638949_copy_link_location.js b/devtools/client/webconsole/test/browser_bug_638949_copy_link_location.js index dba119056dea..c89ee886bddd 100644 --- a/devtools/client/webconsole/test/browser_bug_638949_copy_link_location.js +++ b/devtools/client/webconsole/test/browser_bug_638949_copy_link_location.js @@ -26,7 +26,7 @@ add_task(function* () { let menu = hud.iframeWindow.document.getElementById("output-contextmenu"); hud.jsterm.clearOutput(); - content.console.log("bug 638949"); + gBrowser.contentWindowAsCPOW.console.log("bug 638949"); // Test that the "Copy Link Location" command is disabled for non-network // messages. @@ -54,7 +54,7 @@ add_task(function* () { hud.jsterm.clearOutput(); // Reloading will produce network logging - content.location.reload(); + gBrowser.reload(); // Test that the "Copy Link Location" command is enabled and works // as expected for any network-related message. diff --git a/devtools/client/webconsole/test/browser_console.js b/devtools/client/webconsole/test/browser_console.js index 5bcddbcba6d7..a0d0afcf9fbd 100644 --- a/devtools/client/webconsole/test/browser_console.js +++ b/devtools/client/webconsole/test/browser_console.js @@ -62,7 +62,7 @@ function testMessages(hud) { Cu.nukeSandbox(sandbox); // Add a message from a content window. - content.console.log("bug587757b"); + gBrowser.contentWindowAsCPOW.console.log("bug587757b"); // Test eval. hud.jsterm.execute("document.location.href"); diff --git a/devtools/client/webconsole/test/browser_console_certificate_imminent_distrust.js b/devtools/client/webconsole/test/browser_console_certificate_imminent_distrust.js index e777395ad12b..084010d76e20 100644 --- a/devtools/client/webconsole/test/browser_console_certificate_imminent_distrust.js +++ b/devtools/client/webconsole/test/browser_console_certificate_imminent_distrust.js @@ -93,7 +93,7 @@ function runTestLoop(theHud) { gHud = theHud; } gHud.jsterm.clearOutput(); - gContentBrowser.addEventListener("load", onLoad, true); + BrowserTestUtils.browserLoaded(gContentBrowser).then(onLoad); if (gCurrentTest.pref) { SpecialPowers.pushPrefEnv({"set": gCurrentTest.pref}, function () { @@ -105,8 +105,6 @@ function runTestLoop(theHud) { } function onLoad() { - gContentBrowser.removeEventListener("load", onLoad, true); - waitForSuccess({ name: gCurrentTest.name, validator: function () { diff --git a/devtools/client/webconsole/test/browser_console_copy_command.js b/devtools/client/webconsole/test/browser_console_copy_command.js index 4f434127df31..0c4bdd55127f 100644 --- a/devtools/client/webconsole/test/browser_console_copy_command.js +++ b/devtools/client/webconsole/test/browser_console_copy_command.js @@ -46,7 +46,7 @@ add_task(function* testCopy() { [obj.toSource(), JSON.stringify(obj, null, " ")], [ "$('#" + ID + "')", - content.document.getElementById(ID).outerHTML + gBrowser.contentDocumentAsCPOW.getElementById(ID).outerHTML ] ]; for (let [source, reference] of samples) { diff --git a/devtools/client/webconsole/test/browser_console_variables_view.js b/devtools/client/webconsole/test/browser_console_variables_view.js index 811e7de5ff67..b66bdb4e79c4 100644 --- a/devtools/client/webconsole/test/browser_console_variables_view.js +++ b/devtools/client/webconsole/test/browser_console_variables_view.js @@ -126,7 +126,7 @@ function onTestPropFound(aResults) { function onFooObjFetchAfterUpdate(aVar) { info("onFooObjFetchAfterUpdate"); - let expectedValue = content.document.title + content.location + + let expectedValue = gBrowser.contentTitle + gBrowser.currentURI.spec + "[object HTMLParagraphElement]"; return findVariableViewProperties(aVar, [ @@ -138,7 +138,7 @@ function onUpdatedTestPropFound(aResults) { let prop = aResults[0].matchedProp; ok(prop, "matched the updated |testProp| property value"); - is(content.wrappedJSObject.fooObj.testProp, aResults[0].value, + is(gBrowser.contentWindowAsCPOW.wrappedJSObject.fooObj.testProp, aResults[0].value, "|fooObj.testProp| value has been updated"); // Check that property name updates work. @@ -168,9 +168,9 @@ function onRenamedTestPropFound(aResults) { let prop = aResults[0].matchedProp; ok(prop, "matched the renamed |testProp| property"); - ok(!content.wrappedJSObject.fooObj.testProp, + ok(!gBrowser.contentWindowAsCPOW.wrappedJSObject.fooObj.testProp, "|fooObj.testProp| has been deleted"); - is(content.wrappedJSObject.fooObj.testUpdatedProp, aResults[0].value, + is(gBrowser.contentWindowAsCPOW.wrappedJSObject.fooObj.testUpdatedProp, aResults[0].value, "|fooObj.testUpdatedProp| is correct"); // Check that property value updates that cause exceptions are reported in @@ -223,6 +223,6 @@ function testPropDelete(aProp) { return waitForSuccess({ name: "property deleted", timeout: 60000, - validator: () => !("testUpdatedProp" in content.wrappedJSObject.fooObj) + validator: () => !("testUpdatedProp" in gBrowser.contentWindowAsCPOW.wrappedJSObject.fooObj) }); } diff --git a/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js b/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js index c54bbc02b3cb..13d5a5c4d1e7 100644 --- a/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js +++ b/devtools/client/webconsole/test/browser_netmonitor_shows_reqs_in_webconsole.js @@ -55,9 +55,9 @@ add_task(function* () { function loadDocument(browser) { let deferred = defer(); - browser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(browser).then(function () { deferred.resolve(); - }, {capture: true, once: true}); + }); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_PATH); return deferred.promise; diff --git a/devtools/client/webconsole/test/browser_output_breaks_after_console_dir_uninspectable.js b/devtools/client/webconsole/test/browser_output_breaks_after_console_dir_uninspectable.js index 38a5b54198ec..092661a6e7a9 100644 --- a/devtools/client/webconsole/test/browser_output_breaks_after_console_dir_uninspectable.js +++ b/devtools/client/webconsole/test/browser_output_breaks_after_console_dir_uninspectable.js @@ -34,7 +34,7 @@ add_task(function* () { }], }); - content.console.log("fooBug773466b"); + gBrowser.contentWindowAsCPOW.console.log("fooBug773466b"); yield waitForMessages({ webconsole: hud, diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_580030_errors_after_page_reload.js b/devtools/client/webconsole/test/browser_webconsole_bug_580030_errors_after_page_reload.js index af00bf913a38..6a45e0282257 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_580030_errors_after_page_reload.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_580030_errors_after_page_reload.js @@ -21,13 +21,13 @@ function test() { executeSoon(() => { hud.jsterm.clearOutput(); info("wait for reload"); - content.location.reload(); + gBrowser.reload(); }); yield hud.target.once("navigate"); info("target navigated"); - let button = content.document.querySelector("button"); + let button = gBrowser.contentDocumentAsCPOW.querySelector("button"); ok(button, "button found"); // On e10s, the exception is triggered in child process @@ -36,7 +36,7 @@ function test() { expectUncaughtException(); } - EventUtils.sendMouseEvent({type: "click"}, button, content); + EventUtils.sendMouseEvent({type: "click"}, button, gBrowser.contentWindowAsCPOW); yield waitForMessages({ webconsole: hud, diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_597103_deactivateHUDForContext_unfocused_window.js b/devtools/client/webconsole/test/browser_webconsole_bug_597103_deactivateHUDForContext_unfocused_window.js index e14c3a069d41..32ac8b7eebff 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_597103_deactivateHUDForContext_unfocused_window.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_597103_deactivateHUDForContext_unfocused_window.js @@ -19,12 +19,10 @@ function tab1Loaded() { function win2Loaded() { tab2 = win2.gBrowser.addTab(TEST_URI); win2.gBrowser.selectedTab = tab2; - tab2.linkedBrowser.addEventListener("load", tab2Loaded, true); + BrowserTestUtils.browserLoaded(tab2.linkedBrowser).then(tab2Loaded); } function tab2Loaded(aEvent) { - tab2.linkedBrowser.removeEventListener(aEvent.type, tab2Loaded, true); - let consolesOpened = 0; function onWebConsoleOpen() { consolesOpened++; diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_597460_filter_scroll.js b/devtools/client/webconsole/test/browser_webconsole_bug_597460_filter_scroll.js index 8b1fd88159f4..28390bac04fc 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_597460_filter_scroll.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_597460_filter_scroll.js @@ -26,7 +26,7 @@ function consoleOpened(hud) { let deferred = defer(); for (let i = 0; i < 200; i++) { - content.console.log("test message " + i); + gBrowser.contentWindowAsCPOW.console.log("test message " + i); } hud.setFilterState("network", false); @@ -53,7 +53,7 @@ function consoleOpened(hud) { }], }).then(deferred.resolve); - content.location.reload(); + gBrowser.reload(); }); return deferred.promise; diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js b/devtools/client/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js index 45d1f7102d61..78b288dd8386 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_632275_getters_document_width.js @@ -17,7 +17,7 @@ function test() { } function consoleOpened(hud) { - let doc = content.wrappedJSObject.document; + let doc = gBrowser.contentWindowAsCPOW.wrappedJSObject.document; getterValue = doc.foobar._val; hud.jsterm.execute("console.dir(document)"); @@ -26,7 +26,7 @@ function consoleOpened(hud) { } function onViewOpened(hud, event, view) { - let doc = content.wrappedJSObject.document; + let doc = gBrowser.contentWindowAsCPOW.wrappedJSObject.document; findVariableViewProperties(view, [ { name: /^(width|height)$/, dontMatch: 1 }, diff --git a/devtools/client/webconsole/test/browser_webconsole_bug_644419_log_limits.js b/devtools/client/webconsole/test/browser_webconsole_bug_644419_log_limits.js index 93063e4364f6..4a52a316980e 100644 --- a/devtools/client/webconsole/test/browser_webconsole_bug_644419_log_limits.js +++ b/devtools/client/webconsole/test/browser_webconsole_bug_644419_log_limits.js @@ -66,7 +66,7 @@ function testWebDevLimits() { function testWebDevLimits2() { // Fill the log with Web Developer errors. for (let i = 0; i < 11; i++) { - content.console.log("test message " + i); + gBrowser.contentWindowAsCPOW.console.log("test message " + i); } return waitForMessages({ @@ -91,7 +91,7 @@ function testJsLimits() { Services.prefs.setIntPref("devtools.hud.loglimit.exception", 10); hud.jsterm.clearOutput(); - content.console.log("testing JS limits"); + gBrowser.contentWindowAsCPOW.console.log("testing JS limits"); // Find the sentinel entry. return waitForMessages({ @@ -106,9 +106,9 @@ function testJsLimits() { function testJsLimits2() { // Fill the log with JS errors. - let head = content.document.getElementsByTagName("head")[0]; + let head = gBrowser.contentDocumentAsCPOW.getElementsByTagName("head")[0]; for (let i = 0; i < 11; i++) { - let script = content.document.createElement("script"); + let script = gBrowser.contentDocumentAsCPOW.createElement("script"); script.text = "fubar" + i + ".bogus(6);"; if (!Services.appinfo.browserTabsRemoteAutostart) { @@ -141,7 +141,7 @@ function testNetLimits() { Services.prefs.setIntPref("devtools.hud.loglimit.network", 10); hud.jsterm.clearOutput(); - content.console.log("testing Net limits"); + gBrowser.contentWindowAsCPOW.console.log("testing Net limits"); // Find the sentinel entry. return waitForMessages({ @@ -159,9 +159,9 @@ function testNetLimits() { function loadImage() { if (gCounter < 11) { - let body = content.document.getElementsByTagName("body")[0]; + let body = gBrowser.contentDocumentAsCPOW.getElementsByTagName("body")[0]; gImage && gImage.removeEventListener("load", loadImage, true); - gImage = content.document.createElement("img"); + gImage = gBrowser.contentDocumentAsCPOW.createElement("img"); gImage.src = "test-image.png?_fubar=" + gCounter; body.insertBefore(gImage, body.firstChild); gImage.addEventListener("load", loadImage, true); @@ -194,7 +194,7 @@ function testCssLimits() { Services.prefs.setIntPref("devtools.hud.loglimit.cssparser", 10); hud.jsterm.clearOutput(); - content.console.log("testing CSS limits"); + gBrowser.contentWindowAsCPOW.console.log("testing CSS limits"); // Find the sentinel entry. return waitForMessages({ @@ -209,9 +209,9 @@ function testCssLimits() { function testCssLimits2() { // Fill the log with CSS errors. - let body = content.document.getElementsByTagName("body")[0]; + let body = gBrowser.contentDocumentAsCPOW.getElementsByTagName("body")[0]; for (let i = 0; i < 11; i++) { - let div = content.document.createElement("div"); + let div = gBrowser.contentDocumentAsCPOW.createElement("div"); div.setAttribute("style", "-moz-foobar" + i + ": 42;"); body.insertBefore(div, body.firstChild); } diff --git a/devtools/client/webconsole/test/browser_webconsole_console_extras.js b/devtools/client/webconsole/test/browser_webconsole_console_extras.js index 078e33119644..eeffc4754c5f 100644 --- a/devtools/client/webconsole/test/browser_webconsole_console_extras.js +++ b/devtools/client/webconsole/test/browser_webconsole_console_extras.js @@ -37,7 +37,7 @@ function consoleOpened(hud) { finishTest(); }); - let button = content.document.querySelector("button"); + let button = gBrowser.contentDocumentAsCPOW.querySelector("button"); ok(button, "we have the button"); - EventUtils.sendMouseEvent({ type: "click" }, button, content); + EventUtils.sendMouseEvent({ type: "click" }, button, gBrowser.contentWindowAsCPOW); } diff --git a/devtools/client/webconsole/test/browser_webconsole_console_logging_api.js b/devtools/client/webconsole/test/browser_webconsole_console_logging_api.js index 317337543cd2..3e7a4e10810c 100644 --- a/devtools/client/webconsole/test/browser_webconsole_console_logging_api.js +++ b/devtools/client/webconsole/test/browser_webconsole_console_logging_api.js @@ -24,7 +24,7 @@ add_task(function* () { }); function* testMethod(method, hud, outputNode) { - let console = content.console; + let console = gBrowser.contentWindowAsCPOW.console; hud.jsterm.clearOutput(); diff --git a/devtools/client/webconsole/test/browser_webconsole_log_file_filter.js b/devtools/client/webconsole/test/browser_webconsole_log_file_filter.js index 7e722a054b36..4b8ca43d2316 100644 --- a/devtools/client/webconsole/test/browser_webconsole_log_file_filter.js +++ b/devtools/client/webconsole/test/browser_webconsole_log_file_filter.js @@ -25,7 +25,7 @@ add_task(function* () { }); function consoleOpened() { - let console = content.console; + let console = gBrowser.contentWindowAsCPOW.console; console.log("sentinel log"); return waitForMessages({ webconsole: hud, @@ -63,7 +63,7 @@ function countMessageNodes() { let outputNode = hud.outputNode; let messageNodes = outputNode.querySelectorAll(".message"); - content.console.log(messageNodes.length); + gBrowser.contentWindowAsCPOW.console.log(messageNodes.length); let displayedMessageNodes = 0; let view = hud.iframeWindow; for (let i = 0; i < messageNodes.length; i++) { diff --git a/devtools/client/webconsole/test/browser_webconsole_notifications.js b/devtools/client/webconsole/test/browser_webconsole_notifications.js index 1cac2dcdcae2..3fb6fbc1dbfd 100644 --- a/devtools/client/webconsole/test/browser_webconsole_notifications.js +++ b/devtools/client/webconsole/test/browser_webconsole_notifications.js @@ -26,7 +26,7 @@ function waitForEvents(onConsoleOpened) { function webConsoleCreated(id) { Services.obs.removeObserver(observer, "web-console-created"); ok(HUDService.getHudReferenceById(id), "We have a hud reference"); - content.wrappedJSObject.console.log("adding a log message"); + gBrowser.contentWindowAsCPOW.wrappedJSObject.console.log("adding a log message"); } function webConsoleDestroyed(id) { diff --git a/devtools/client/webconsole/test/browser_webconsole_output_copy_newlines.js b/devtools/client/webconsole/test/browser_webconsole_output_copy_newlines.js index 991b765f7322..d2321cec82ab 100644 --- a/devtools/client/webconsole/test/browser_webconsole_output_copy_newlines.js +++ b/devtools/client/webconsole/test/browser_webconsole_output_copy_newlines.js @@ -19,8 +19,8 @@ add_task(function* () { .getControllerForCommand("cmd_copy"); is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled"); - content.console.log("Hello world! bug916997a"); - content.console.log("Hello world 2! bug916997b"); + gBrowser.contentWindowAsCPOW.console.log("Hello world! bug916997a"); + gBrowser.contentWindowAsCPOW.console.log("Hello world 2! bug916997b"); yield waitForMessages({ webconsole: hud, diff --git a/devtools/client/webconsole/test/browser_webconsole_reflow.js b/devtools/client/webconsole/test/browser_webconsole_reflow.js index 86caa10e050f..bdb270ad0a43 100644 --- a/devtools/client/webconsole/test/browser_webconsole_reflow.js +++ b/devtools/client/webconsole/test/browser_webconsole_reflow.js @@ -14,8 +14,8 @@ add_task(function* () { let hud = yield openConsole(); function onReflowListenersReady() { - browser.contentDocument.body.style.display = "none"; - browser.contentDocument.body.clientTop; + browser.contentDocumentAsCPOW.body.style.display = "none"; + browser.contentDocumentAsCPOW.body.clientTop; } Services.prefs.setBoolPref("devtools.webconsole.filter.csslog", true); diff --git a/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js b/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js index 740dfd39445d..9d21ccda835a 100644 --- a/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js +++ b/devtools/client/webconsole/test/browser_webconsole_shows_reqs_in_netmonitor.js @@ -52,9 +52,9 @@ add_task(function* () { function loadDocument(browser) { let deferred = defer(); - browser.addEventListener("load", function () { + BrowserTestUtils.browserLoaded(browser).then(function () { deferred.resolve(); - }, {capture: true, once: true}); + }); BrowserTestUtils.loadURI(gBrowser.selectedBrowser, TEST_PATH); return deferred.promise; diff --git a/devtools/client/webconsole/test/head.js b/devtools/client/webconsole/test/head.js index ab1fa4acc24d..b23c80557b8d 100644 --- a/devtools/client/webconsole/test/head.js +++ b/devtools/client/webconsole/test/head.js @@ -227,7 +227,7 @@ var waitForTab = Task.async(function* () { yield once(gBrowser.tabContainer, "TabOpen"); let tab = gBrowser.selectedTab; let browser = tab.linkedBrowser; - yield once(browser, "load", true); + yield BrowserTestUtils.browserLoaded(browser); info("The tab load completed"); return tab; }); diff --git a/devtools/server/tests/browser/browser_markers-docloading-01.js b/devtools/server/tests/browser/browser_markers-docloading-01.js index efb86c23aef6..fa33852bf4a9 100644 --- a/devtools/server/tests/browser/browser_markers-docloading-01.js +++ b/devtools/server/tests/browser/browser_markers-docloading-01.js @@ -12,7 +12,7 @@ const MARKER_NAMES = ["document::DOMContentLoaded", "document::Load"]; add_task(function* () { let browser = yield addTab(MAIN_DOMAIN + "doc_innerHTML.html"); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = browser.contentDocument; + let doc = browser.contentDocumentAsCPOW; initDebuggerServer(); let client = new DebuggerClient(DebuggerServer.connectPipe()); diff --git a/devtools/server/tests/browser/browser_markers-docloading-02.js b/devtools/server/tests/browser/browser_markers-docloading-02.js index 14c60fc1e21d..11b6e01d1762 100644 --- a/devtools/server/tests/browser/browser_markers-docloading-02.js +++ b/devtools/server/tests/browser/browser_markers-docloading-02.js @@ -12,7 +12,7 @@ const MARKER_NAMES = ["document::DOMContentLoaded", "document::Load"]; add_task(function* () { let browser = yield addTab(MAIN_DOMAIN + "doc_innerHTML.html"); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = browser.contentDocument; + let doc = browser.contentDocumentAsCPOW; initDebuggerServer(); let client = new DebuggerClient(DebuggerServer.connectPipe()); diff --git a/devtools/server/tests/browser/browser_markers-docloading-03.js b/devtools/server/tests/browser/browser_markers-docloading-03.js index 2f31bcc99343..d73e25cc2436 100644 --- a/devtools/server/tests/browser/browser_markers-docloading-03.js +++ b/devtools/server/tests/browser/browser_markers-docloading-03.js @@ -12,7 +12,7 @@ const MARKER_NAMES = ["document::DOMContentLoaded", "document::Load"]; add_task(function* () { let browser = yield addTab(MAIN_DOMAIN + "doc_innerHTML.html"); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = browser.contentDocument; + let doc = browser.contentDocumentAsCPOW; initDebuggerServer(); let client = new DebuggerClient(DebuggerServer.connectPipe()); diff --git a/devtools/server/tests/browser/browser_storage_dynamic_windows.js b/devtools/server/tests/browser/browser_storage_dynamic_windows.js index 71ab2adb7697..690f1febe614 100644 --- a/devtools/server/tests/browser/browser_storage_dynamic_windows.js +++ b/devtools/server/tests/browser/browser_storage_dynamic_windows.js @@ -164,10 +164,10 @@ function testAddIframe(front) { front.on("stores-update", onStoresUpdate); // eslint-disable-next-line mozilla/no-cpows-in-tests - let iframe = content.document.createElement("iframe"); + let iframe = gBrowser.contentDocumentAsCPOW.createElement("iframe"); iframe.src = ALT_DOMAIN_SECURED + "storage-secured-iframe.html"; // eslint-disable-next-line mozilla/no-cpows-in-tests - content.document.querySelector("body").appendChild(iframe); + gBrowser.contentDocumentAsCPOW.querySelector("body").appendChild(iframe); }); } diff --git a/devtools/server/tests/browser/browser_storage_updates.js b/devtools/server/tests/browser/browser_storage_updates.js index 8e6cc9587d3e..c160b8e7bfe5 100644 --- a/devtools/server/tests/browser/browser_storage_updates.js +++ b/devtools/server/tests/browser/browser_storage_updates.js @@ -299,7 +299,7 @@ function* finishTests(client) { add_task(function* () { let browser = yield addTab(MAIN_DOMAIN + "storage-updates.html"); // eslint-disable-next-line mozilla/no-cpows-in-tests - let doc = browser.contentDocument; + let doc = browser.contentDocumentAsCPOW; initDebuggerServer(); diff --git a/docshell/test/browser/browser_bug420605.js b/docshell/test/browser/browser_bug420605.js index 7dcbcc2531ea..16c39b2eeba1 100644 --- a/docshell/test/browser/browser_bug420605.js +++ b/docshell/test/browser/browser_bug420605.js @@ -103,8 +103,6 @@ function test() { historyService.addObserver(historyObserver); function onPageLoad() { - gBrowser.selectedBrowser - .removeEventListener("DOMContentLoaded", arguments.callee, true); clickLinkIfReady(); } @@ -116,7 +114,6 @@ function test() { // Now open the test page in a new tab. gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser); - gBrowser.selectedBrowser.addEventListener( - "DOMContentLoaded", onPageLoad, true); - content.location = pageurl; + BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "DOMContentLoaded", true).then(onPageLoad); + gBrowser.selectedBrowser.loadURI(pageurl); } diff --git a/docshell/test/browser/browser_bug673467.js b/docshell/test/browser/browser_bug673467.js index 6f746c896b28..a7ffd68fdf3e 100644 --- a/docshell/test/browser/browser_bug673467.js +++ b/docshell/test/browser/browser_bug673467.js @@ -19,32 +19,35 @@ var doc = "data:text/html," + function test() { waitForExplicitFinish(); - let tab = BrowserTestUtils.addTab(gBrowser, doc); - let tabBrowser = tab.linkedBrowser; + let taskFinished; - BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => { - return ContentTask.spawn(tab.linkedBrowser, null, () => { + let tab = BrowserTestUtils.addTab(gBrowser, doc, {}, (tab) => { + taskFinished = ContentTask.spawn(tab.linkedBrowser, null, () => { return new Promise(resolve => { - // The main page has loaded. Now wait for the iframe to load. - let iframe = content.document.getElementById('iframe'); - iframe.addEventListener('load', function listener(aEvent) { + addEventListener("load", function() { + // The main page has loaded. Now wait for the iframe to load. + let iframe = content.document.getElementById('iframe'); + iframe.addEventListener('load', function listener(aEvent) { - // Wait for the iframe to load the new document, not about:blank. - if (!iframe.src) - return; + // Wait for the iframe to load the new document, not about:blank. + if (!iframe.src) + return; - iframe.removeEventListener('load', listener, true); - let shistory = content - .QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .sessionHistory; + iframe.removeEventListener('load', listener, true); + let shistory = content + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .sessionHistory; - Assert.equal(shistory.count, 1, "shistory count should be 1."); - resolve(); + Assert.equal(shistory.count, 1, "shistory count should be 1."); + resolve(); + }, true); }, true); }); }); - }).then(() => { + }); + + taskFinished.then(() => { gBrowser.removeTab(tab); finish(); }); diff --git a/docshell/test/browser/browser_history_triggeringprincipal_viewsource.js b/docshell/test/browser/browser_history_triggeringprincipal_viewsource.js index 453c696ad7bc..39f9557a48ae 100644 --- a/docshell/test/browser/browser_history_triggeringprincipal_viewsource.js +++ b/docshell/test/browser/browser_history_triggeringprincipal_viewsource.js @@ -37,7 +37,7 @@ add_task(async function() { popupPromise = BrowserTestUtils.waitForEvent(backCtxtMenu, "popupshown"); BrowserTestUtils.synthesizeMouseAtCenter("body", { type: "contextmenu", button: 2 }, aBrowser); await popupPromise; - loadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, VIEW_SRC_URI); + loadPromise = BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "pageshow"); let backItem = backCtxtMenu.getElementsByAttribute("id", "context-back")[0]; backItem.click(); backCtxtMenu.hidePopup(); diff --git a/docshell/test/browser/browser_loadDisallowInherit.js b/docshell/test/browser/browser_loadDisallowInherit.js index 8fd0a9776129..69188dbc79e7 100644 --- a/docshell/test/browser/browser_loadDisallowInherit.js +++ b/docshell/test/browser/browser_loadDisallowInherit.js @@ -19,12 +19,9 @@ function startTest() { let browser = gBrowser.getBrowserForTab(tab); function loadURL(url, flags, func) { - browser.addEventListener("load", function loadListener(e) { - if (browser.currentURI.spec != url) - return; - browser.removeEventListener(e.type, loadListener, true); + BrowserTestUtils.browserLoaded(browser, false, url).then(() => { func(); - }, true); + }); browser.loadURIWithFlags(url, flags, null, null, null); } diff --git a/docshell/test/browser/head.js b/docshell/test/browser/head.js index c9d21277f95b..ac3e59c34c34 100644 --- a/docshell/test/browser/head.js +++ b/docshell/test/browser/head.js @@ -51,9 +51,7 @@ function timelineTestOpenUrl(url) { let tab = window.gBrowser.selectedTab = window.gBrowser.addTab(url); let linkedBrowser = tab.linkedBrowser; - linkedBrowser.addEventListener("load", function() { - resolve(tab); - }, {capture: true, once: true}); + BrowserTestUtils.browserLoaded(linkedBrowser).then(() => resolve(tab)); }); return Promise.all([tabSwitchPromise, loadPromise]).then(([_, tab]) => tab); diff --git a/docshell/test/navigation/browser_bug343515.js b/docshell/test/navigation/browser_bug343515.js index 4fb0779e79d5..cf4b1d7a7ff7 100644 --- a/docshell/test/navigation/browser_bug343515.js +++ b/docshell/test/navigation/browser_bug343515.js @@ -9,11 +9,12 @@ var ctx = {}; // how many load events should happen on that page (one for the toplevel doc // and one for each subframe) and wait until we receive the expected number // of events. -function nShotsListener(aElem, aType, aCallback, aCount) { +function nShotsListener(aBrowser, aType, aCallback, aCount) { let count = aCount; - aElem.addEventListener(aType, function listenerCallback() { + let removeFunc; + removeFunc = BrowserTestUtils.addContentEventListener(aBrowser, aType, function listenerCallback() { if (--count == 0) { - aElem.removeEventListener(aType, listenerCallback, true); + removeFunc(); // aCallback is executed asynchronously, which is handy because load // events fire before mIsDocumentLoaded is actually set to true. :( @@ -22,8 +23,8 @@ function nShotsListener(aElem, aType, aCallback, aCount) { }, true); } -function oneShotListener(aElem, aType, aCallback) { - nShotsListener(aElem, aType, aCallback, 1); +function oneShotListener(aBrowser, aType, aCallback) { + nShotsListener(aBrowser, aType, aCallback, 1); } function waitForPageshow(aBrowser, callback) { diff --git a/dom/base/test/browser_aboutnewtab_process_selection.js b/dom/base/test/browser_aboutnewtab_process_selection.js index 2872f9746e5f..43dc14c22da0 100644 --- a/dom/base/test/browser_aboutnewtab_process_selection.js +++ b/dom/base/test/browser_aboutnewtab_process_selection.js @@ -17,7 +17,8 @@ async function ensurePreloaded(gBrowser) { // We cannot use the regular BrowserTestUtils helper for waiting here, since that // would try to insert the preloaded browser, which would only break things. await BrowserTestUtils.waitForCondition( () => { - return gBrowser._preloadedBrowser.contentDocument.readyState == "complete"; + let doc = gBrowser._preloadedBrowser.contentDocumentAsCPOW; + return doc && doc.readyState == "complete"; }); } diff --git a/dom/base/test/browser_bug1058164.js b/dom/base/test/browser_bug1058164.js index 472b4ac3f1ce..8ddc7e227efb 100644 --- a/dom/base/test/browser_bug1058164.js +++ b/dom/base/test/browser_bug1058164.js @@ -25,13 +25,15 @@ function prepareForVisibilityEvents(browser, expectedOrder) { return new Promise((resolve) => { let order = []; + let rmvHide, rmvShow; + let checkSatisfied = () => { if (order.length < expectedOrder.length) { // We're still waiting... return; } else { - browser.removeEventListener("pagehide", eventListener); - browser.removeEventListener("pageshow", eventListener); + rmvHide(); + rmvShow(); for (let i = 0; i < expectedOrder.length; ++i) { is(order[i], expectedOrder[i], "Got expected event"); @@ -40,15 +42,19 @@ function prepareForVisibilityEvents(browser, expectedOrder) { } }; - let eventListener = (e) => { - if (e.persisted) { - order.push(e.type); - checkSatisfied(); - } + let eventListener = (type) => { + order.push(type); + checkSatisfied(); }; - browser.addEventListener("pagehide", eventListener); - browser.addEventListener("pageshow", eventListener); + let checkFn = (e) => e.persisted; + + rmvHide = BrowserTestUtils.addContentEventListener(browser, "pagehide", + () => eventListener("pagehide"), + false, checkFn, false, false); + rmvShow = BrowserTestUtils.addContentEventListener(browser, "pageshow", + () => eventListener("pageshow"), + false, checkFn, false, false); }); } diff --git a/dom/html/test/browser_bug592641.js b/dom/html/test/browser_bug592641.js index e83987777d27..f29e79bab91c 100644 --- a/dom/html/test/browser_bug592641.js +++ b/dom/html/test/browser_bug592641.js @@ -11,7 +11,7 @@ function test() { ctx.tab1 = BrowserTestUtils.addTab(gBrowser, testPath + "bug592641_img.jpg"); ctx.tab1Browser = gBrowser.getBrowserForTab(ctx.tab1); - ctx.tab1Browser.addEventListener("load", load1Soon, true); + BrowserTestUtils.browserLoaded(ctx.tab1Browser).then(load1Soon); } function checkTitle(title) { @@ -22,7 +22,6 @@ function checkTitle(title) { } function load1Soon() { - ctx.tab1Browser.removeEventListener("load", load1Soon, true); // onload is fired in OnStopDecode, so let's use executeSoon() to make sure // that any other OnStopDecode event handlers get the chance to fire first. executeSoon(load1Done); @@ -37,11 +36,10 @@ function load1Done() { // the cached case. ctx.tab2 = BrowserTestUtils.addTab(gBrowser, testPath + "bug592641_img.jpg"); ctx.tab2Browser = gBrowser.getBrowserForTab(ctx.tab2); - ctx.tab2Browser.addEventListener("load", load2Soon, true); + BrowserTestUtils.browserLoaded(ctx.tab2Browser).then(load2Soon); } function load2Soon() { - ctx.tab2Browser.removeEventListener("load", load2Soon, true); // onload is fired in OnStopDecode, so let's use executeSoon() to make sure // that any other OnStopDecode event handlers get the chance to fire first. executeSoon(load2Done); diff --git a/dom/security/test/csp/browser_test_web_manifest.js b/dom/security/test/csp/browser_test_web_manifest.js index da650c4470b4..364614cba5d7 100644 --- a/dom/security/test/csp/browser_test_web_manifest.js +++ b/dom/security/test/csp/browser_test_web_manifest.js @@ -191,7 +191,7 @@ add_task(async function() { }); async function testObtainingManifest(aBrowser, aTest) { - const waitForObserver = waitForNetObserver(aTest); + const waitForObserver = waitForNetObserver(aBrowser, aTest); // Expect an exception (from promise rejection) if there a content policy // that is violated. try { @@ -206,19 +206,19 @@ async function testObtainingManifest(aBrowser, aTest) { } // Helper object used to observe policy violations when blocking is expected. -function waitForNetObserver(aTest) { - return new Promise((resolve) => { - // We don't need to wait for violation, so just resolve - if (!aTest.expected.includes("block")){ - return resolve(); - } - const observer = { - observe(subject, topic) { - SpecialPowers.removeObserver(observer, "csp-on-violate-policy"); - aTest.run(topic); +function waitForNetObserver(aBrowser, aTest) { + // We don't need to wait for violation, so just resolve + if (!aTest.expected.includes("block")){ + return Promise.resolve(); + } + + return ContentTask.spawn(aBrowser, null, () => { + return new Promise(resolve => { + function observe(subject, topic) { + Services.obs.removeObserver(observe, "csp-on-violate-policy"); resolve(); - }, - }; - SpecialPowers.addObserver(observer, "csp-on-violate-policy"); - }); + }; + Services.obs.addObserver(observe, "csp-on-violate-policy"); + }); + }).then(() => aTest.run("csp-on-violate-policy")); } diff --git a/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js b/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js index e3874e66d965..a9ed18b8116c 100644 --- a/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js +++ b/dom/tests/browser/browser_ConsoleStoragePBTest_perwindowpb.js @@ -29,7 +29,7 @@ function test() { } function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser).then(() => { consoleObserver = { observe: function(aSubject, aTopic, aData) { if (aTopic == "console-api-log-event") { @@ -48,7 +48,7 @@ function test() { aWindow.Services.obs.addObserver( consoleObserver, "console-api-log-event"); aWindow.nativeConsole.log("foo bar baz (private: " + aIsPrivateMode + ")"); - }, {capture: true, once: true}); + }); // We expect that console API messages are always stored. storageShouldOccur = true; diff --git a/dom/url/tests/browser_download_after_revoke.js b/dom/url/tests/browser_download_after_revoke.js index a1aeb4cea3f5..0cf0c7a85e68 100644 --- a/dom/url/tests/browser_download_after_revoke.js +++ b/dom/url/tests/browser_download_after_revoke.js @@ -4,7 +4,6 @@ function test () { function onLoad() { info("Page loaded."); - gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); var listener = { onOpenWindow: function(aXULWindow) { @@ -46,8 +45,8 @@ function test () { }); } - gBrowser.selectedBrowser.addEventListener("load", onLoad, true); + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(onLoad); info("Loading download page..."); - content.location = "http://example.com/browser/dom/url/tests/empty.html"; + gBrowser.loadURI("http://example.com/browser/dom/url/tests/empty.html"); } diff --git a/dom/workers/test/head.js b/dom/workers/test/head.js index c598f55cbf63..a3b7c203da92 100644 --- a/dom/workers/test/head.js +++ b/dom/workers/test/head.js @@ -15,11 +15,7 @@ function addTab(url) { gBrowser.selectedTab = tab; let linkedBrowser = tab.linkedBrowser; linkedBrowser.messageManager.loadFrameScript(FRAME_SCRIPT_URL, false); - return new Promise(function (resolve) { - linkedBrowser.addEventListener("load", function() { - resolve(tab); - }, {capture: true, once: true}); - }); + return BrowserTestUtils.browserLoaded(linkedBrowser).then(() => tab); } /** diff --git a/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js b/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js index 35923e1da2b7..c1beac572cda 100644 --- a/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js +++ b/security/manager/ssl/tests/mochitest/browser/browser_bug627234_perwindowpb.js @@ -49,7 +49,7 @@ function test() { } function doTest(aIsPrivateMode, aWindow, aCallback) { - aWindow.gBrowser.selectedBrowser.addEventListener("load", function() { + BrowserTestUtils.browserLoaded(aWindow.gBrowser.selectedBrowser).then(() => { let sslStatus = new FakeSSLStatus(); uri = aWindow.Services.io.newURI("https://localhost/img.png"); gSSService.processHeader(Ci.nsISiteSecurityService.HEADER_HSTS, uri, @@ -60,7 +60,7 @@ function test() { "checking sts host"); aCallback(); - }, {capture: true, once: true}); + }); aWindow.gBrowser.selectedBrowser.loadURI(testURI); } diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index 3a8f3760193c..b0d9e335736d 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -1581,11 +1581,27 @@ this.BrowserTestUtils = { * Opens a tab with a given uri and params object. If the params object is not set * or the params parameter does not include a triggeringPricnipal then this function * provides a params object using the systemPrincipal as the default triggeringPrincipal. + * + * @param {xul:tabbrowser} tabbrowser + * The gBrowser object to open the tab with. + * @param {string} uri + * The URI to open in the new tab. + * @param {object} params [optional] + * Parameters object for gBrowser.addTab. + * @param {function} beforeLoadFunc [optional] + * A function to run after that xul:browser has been created but before the URL is + * loaded. Can spawn a content task in the tab, for example. */ - addTab(browser, uri, params = {}) { + addTab(tabbrowser, uri, params = {}, beforeLoadFunc = null) { if (!params.triggeringPrincipal) { params.triggeringPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); } - return browser.addTab(uri, params); + if (beforeLoadFunc) { + let window = tabbrowser.ownerGlobal; + window.addEventListener("TabOpen", function(e) { + beforeLoadFunc(e.target); + }, {once: true}); + } + return tabbrowser.addTab(uri, params); } }; diff --git a/testing/mochitest/tests/browser/browser_waitForFocus.js b/testing/mochitest/tests/browser/browser_waitForFocus.js index 81852ec4a3a5..2665da74e34e 100644 --- a/testing/mochitest/tests/browser/browser_waitForFocus.js +++ b/testing/mochitest/tests/browser/browser_waitForFocus.js @@ -3,22 +3,11 @@ const gBaseURL = "https://example.com/browser/testing/mochitest/tests/browser/"; function promiseTabLoadEvent(tab, url) { - return new Promise(function (resolve, reject) { - function handleLoadEvent(event) { - if (event.originalTarget != tab.linkedBrowser.contentDocument || - event.target.location.href == "about:blank" || - (url && event.target.location.href != url)) { - return; - } - - tab.linkedBrowser.removeEventListener("load", handleLoadEvent, true); - resolve(event); - } - - tab.linkedBrowser.addEventListener("load", handleLoadEvent, true, true); - if (url) - tab.linkedBrowser.loadURI(url); - }); + let promise = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, url); + if (url) { + tab.linkedBrowser.loadURI(url); + } + return promise; } // Load a new blank tab diff --git a/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js b/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js index c9814c46ee33..5ad2f2fc0a60 100644 --- a/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js +++ b/toolkit/components/passwordmgr/test/browser/browser_passwordmgr_switchtab.js @@ -35,9 +35,7 @@ add_task(async function test() { gBrowser.removeTab(tab); }); - tab.linkedBrowser.addEventListener("load", () => { - finish(); - }, true); + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => finish()); tab.linkedBrowser.loadURI("http://example.com/browser/toolkit/components/passwordmgr/test/browser/authenticate.sjs"); }); diff --git a/toolkit/components/payments/test/browser/browser_request_summary.js b/toolkit/components/payments/test/browser/browser_request_summary.js index 71232e09220a..9cdbfffbf4aa 100644 --- a/toolkit/components/payments/test/browser/browser_request_summary.js +++ b/toolkit/components/payments/test/browser/browser_request_summary.js @@ -6,6 +6,6 @@ add_task(async function test_summary() { url: "resource://payments/paymentRequest.xhtml", }, async browser => { // eslint-disable-next-line mozilla/no-cpows-in-tests - ok(browser.contentDocument.getElementById("cancel"), "Cancel button exists"); + ok(browser.contentDocumentAsCPOW.getElementById("cancel"), "Cancel button exists"); }); }); diff --git a/toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js b/toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js index 0c1aefc98778..392087b1ceea 100644 --- a/toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js +++ b/toolkit/components/places/tests/browser/browser_favicon_privatebrowsing_perwindowpb.js @@ -23,9 +23,7 @@ function test() { } function waitForTabLoad(aWin, aCallback) { - aWin.gBrowser.selectedBrowser.addEventListener("load", function() { - aCallback(); - }, {capture: true, once: true}); + BrowserTestUtils.browserLoaded(aWin.gBrowser.selectedBrowser).then(aCallback); aWin.gBrowser.selectedBrowser.loadURI(pageURI); } diff --git a/toolkit/components/reader/test/browser_readerMode_with_anchor.js b/toolkit/components/reader/test/browser_readerMode_with_anchor.js index 80afff8eea99..b5c466b1b7b9 100644 --- a/toolkit/components/reader/test/browser_readerMode_with_anchor.js +++ b/toolkit/components/reader/test/browser_readerMode_with_anchor.js @@ -29,7 +29,8 @@ add_task(async function() { let readerButton = document.getElementById("reader-mode-button"); readerButton.click(); await pageShownPromise; - is(content.document.documentElement.scrollTop, 0, "scrollTop should be 0"); + // eslint-disable-next-line mozilla/no-cpows-in-tests + is(gBrowser.contentDocumentAsCPOW.documentElement.scrollTop, 0, "scrollTop should be 0"); await BrowserTestUtils.synthesizeMouseAtCenter("#foo-anchor", {}, browser); await ContentTask.spawn(browser, null, async function() { let foo = content.document.getElementById("foo"); diff --git a/toolkit/components/thumbnails/test/browser_thumbnails_bug726727.js b/toolkit/components/thumbnails/test/browser_thumbnails_bug726727.js index cbff8dce8c3c..292aa0ec27ee 100644 --- a/toolkit/components/thumbnails/test/browser_thumbnails_bug726727.js +++ b/toolkit/components/thumbnails/test/browser_thumbnails_bug726727.js @@ -9,10 +9,12 @@ function* runTests() { // Create a tab that shows an error page. let tab = BrowserTestUtils.addTab(gBrowser, "http://127.0.0.1:1/"); let browser = tab.linkedBrowser; - yield browser.addEventListener("DOMContentLoaded", function() { + yield BrowserTestUtils.waitForContentEvent(browser, "DOMContentLoaded"); + + yield new Promise(resolve => { PageThumbs.shouldStoreThumbnail(browser, (aResult) => { ok(!aResult, "we're not going to capture an error page"); - executeSoon(next); + resolve(); }); - }, {once: true}); + }); } diff --git a/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js b/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js index 00a3c168fcca..26973321882a 100644 --- a/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js +++ b/toolkit/components/thumbnails/test/browser_thumbnails_privacy.js @@ -62,7 +62,7 @@ function testCombination(combi, url, aCombinations, aResult) { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url); let browser = gBrowser.selectedBrowser; - whenLoaded(browser, () => { + BrowserTestUtils.browserLoaded(browser).then(() => { let msg = JSON.stringify(combi) + " == " + aResult; PageThumbs.shouldStoreThumbnail(browser, (aIsSafeSite) => { is(aIsSafeSite, aResult, msg); diff --git a/toolkit/components/thumbnails/test/head.js b/toolkit/components/thumbnails/test/head.js index bf6c5667b46b..c704625c709f 100644 --- a/toolkit/components/thumbnails/test/head.js +++ b/toolkit/components/thumbnails/test/head.js @@ -96,7 +96,8 @@ function next(aValue) { */ function addTab(aURI, aCallback) { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, aURI); - whenLoaded(tab.linkedBrowser, aCallback); + let callback = aCallback ? aCallback : next; + BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(callback); } /** @@ -105,7 +106,7 @@ function addTab(aURI, aCallback) { */ function navigateTo(aURI) { let browser = gBrowser.selectedBrowser; - whenLoaded(browser); + BrowserTestUtils.browserLoaded(browser).then(next); browser.loadURI(aURI); } diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js b/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js index addff873b2a5..a70aae827c30 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js +++ b/toolkit/content/tests/browser/browser_autoplay_policy_play_twice.js @@ -14,7 +14,7 @@ async function allow_play_for_played_video() { let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "about:blank"); info("- create video -"); - let document = tab.linkedBrowser.contentDocument; + let document = tab.linkedBrowser.contentDocumentAsCPOW; let video = document.createElement("video"); video.src = FILE; video.controls = true; diff --git a/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js b/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js index 0bd68458c0e9..333ae07c1b97 100644 --- a/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js +++ b/toolkit/content/tests/browser/browser_autoplay_policy_user_gestures.js @@ -20,7 +20,8 @@ function setup_test_preference() { } function simulateUserGesture(gesture, targetBrowser) { - let targetElement = targetBrowser.contentDocument.documentElement; + // eslint-disable-next-line mozilla/no-cpows-in-tests + let targetElement = targetBrowser.contentDocumentAsCPOW.documentElement; info(`- simulate ${gesture.type} event -`); switch (gesture.type) { case UserGestures.MOUSE_CLICK: @@ -42,7 +43,8 @@ async function test_play_without_user_gesture() { let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "about:blank"); info("- create autoplay video -"); - let document = tab.linkedBrowser.contentDocument; + // eslint-disable-next-line mozilla/no-cpows-in-tests + let document = tab.linkedBrowser.contentDocumentAsCPOW; let video = document.createElement("video"); video.src = FILE; video.autoplay = true; @@ -67,7 +69,8 @@ async function test_play_with_user_gesture(gesture) { let tab = await BrowserTestUtils.openNewForegroundTab(window.gBrowser, "about:blank"); info("- create autoplay video -"); - let document = tab.linkedBrowser.contentDocument; + // eslint-disable-next-line mozilla/no-cpows-in-tests + let document = tab.linkedBrowser.contentDocumentAsCPOW; let video = document.createElement("video"); video.src = FILE; document.body.appendChild(video); diff --git a/toolkit/content/tests/browser/browser_contentTitle.js b/toolkit/content/tests/browser/browser_contentTitle.js index c9c56dafa167..118cfc395a48 100644 --- a/toolkit/content/tests/browser/browser_contentTitle.js +++ b/toolkit/content/tests/browser/browser_contentTitle.js @@ -2,12 +2,7 @@ var url = "https://example.com/browser/toolkit/content/tests/browser/file_conten add_task(async function() { let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url); - await new Promise((resolve) => { - addEventListener("TestLocationChange", function listener() { - removeEventListener("TestLocationChange", listener); - resolve(); - }, true, true); - }); + await BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, "TestLocationChange", true, null, true); is(gBrowser.contentTitle, "Test Page", "Should have the right title."); diff --git a/toolkit/content/tests/browser/browser_datetime_datepicker.js b/toolkit/content/tests/browser/browser_datetime_datepicker.js index df6e5a87b8ec..1104e3902f66 100644 --- a/toolkit/content/tests/browser/browser_datetime_datepicker.js +++ b/toolkit/content/tests/browser/browser_datetime_datepicker.js @@ -168,7 +168,7 @@ add_task(async function test_datepicker_clicked() { }); // eslint-disable-next-line mozilla/no-cpows-in-tests - Assert.equal(content.document.querySelector("input").value, firstDayOnCalendar); + Assert.equal(gBrowser.contentDocumentAsCPOW.querySelector("input").value, firstDayOnCalendar); await helper.tearDown(); }); diff --git a/toolkit/content/tests/browser/browser_saveImageURL.js b/toolkit/content/tests/browser/browser_saveImageURL.js index 6b16e91d384e..970aaea43ca9 100644 --- a/toolkit/content/tests/browser/browser_saveImageURL.js +++ b/toolkit/content/tests/browser/browser_saveImageURL.js @@ -37,7 +37,8 @@ add_task(async function preferred_API() { }); saveImageURL(url, "image.jpg", null, true, false, null, null, null, null, false); - let channel = content.document.docShell.currentDocumentChannel; + // eslint-disable-next-line mozilla/no-cpows-in-tests + let channel = gBrowser.contentDocumentAsCPOW.docShell.currentDocumentChannel; if (channel) { ok(true, channel.QueryInterface(Ci.nsIHttpChannelInternal) .channelIsForDownload); @@ -73,7 +74,8 @@ add_task(async function deprecated_API() { // pass the XUL document instead to test this interface. let doc = document; - let channel = content.document.docShell.currentDocumentChannel; + // eslint-disable-next-line mozilla/no-cpows-in-tests + let channel = gBrowser.contentDocumentAsCPOW.docShell.currentDocumentChannel; if (channel) { ok(true, channel.QueryInterface(Ci.nsIHttpChannelInternal) .channelIsForDownload); diff --git a/toolkit/modules/tests/browser/browser_RemotePageManager.js b/toolkit/modules/tests/browser/browser_RemotePageManager.js index 3e004acb7a26..51d0060d26c0 100644 --- a/toolkit/modules/tests/browser/browser_RemotePageManager.js +++ b/toolkit/modules/tests/browser/browser_RemotePageManager.js @@ -80,14 +80,8 @@ add_task(async function init_navigate() { let port = await waitForPort(TEST_URL); is(port.browser, gBrowser.selectedBrowser, "Port is for the correct browser"); - let loaded = new Promise(resolve => { - function listener() { - gBrowser.selectedBrowser.removeEventListener("load", listener, true); - resolve(); - } - gBrowser.selectedBrowser.addEventListener("load", listener, true); - gBrowser.loadURI("about:blank"); - }); + let loaded = BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser); + gBrowser.loadURI("about:blank"); await waitForMessage(port, "RemotePage:Unload"); diff --git a/toolkit/modules/tests/browser/browser_WebRequest_cookies.js b/toolkit/modules/tests/browser/browser_WebRequest_cookies.js index b1aaa6507d8a..ad0b8daa735d 100644 --- a/toolkit/modules/tests/browser/browser_WebRequest_cookies.js +++ b/toolkit/modules/tests/browser/browser_WebRequest_cookies.js @@ -78,9 +78,5 @@ add_task(async function filter_urls() { }); function waitForLoad(browser = gBrowser.selectedBrowser) { - return new Promise(resolve => { - browser.addEventListener("load", function() { - resolve(); - }, {capture: true, once: true}); - }); + return BrowserTestUtils.browserLoaded(browser); } diff --git a/toolkit/modules/tests/browser/browser_WebRequest_filtering.js b/toolkit/modules/tests/browser/browser_WebRequest_filtering.js index 7d9f34c1d90f..f6dc344283b5 100644 --- a/toolkit/modules/tests/browser/browser_WebRequest_filtering.js +++ b/toolkit/modules/tests/browser/browser_WebRequest_filtering.js @@ -108,9 +108,5 @@ add_task(async function filter_types() { }); function waitForLoad(browser = gBrowser.selectedBrowser) { - return new Promise(resolve => { - browser.addEventListener("load", function() { - resolve(); - }, {capture: true, once: true}); - }); + return BrowserTestUtils.browserLoaded(browser); } diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug562797.js b/toolkit/mozapps/extensions/test/browser/browser_bug562797.js index baff77792699..2002c587e2d9 100644 --- a/toolkit/mozapps/extensions/test/browser/browser_bug562797.js +++ b/toolkit/mozapps/extensions/test/browser/browser_bug562797.js @@ -388,6 +388,20 @@ add_test(function() { }); }); +function wait_for_page_show(browser) { + let promise = new Promise(resolve => { + let removeFunc; + let listener = () => { + removeFunc(); + resolve(); + }; + removeFunc = BrowserTestUtils.addContentEventListener(browser, "pageshow", listener, false, + (event) => event.target.location == "http://example.com/", + false, false); + }); + return promise; +} + // Tests than navigating to a website and then going back returns to the // previous view add_test(function() { @@ -397,10 +411,7 @@ add_test(function() { is_in_list(aManager, "addons://list/plugin", false, false); gBrowser.loadURI("http://example.com/"); - gBrowser.addEventListener("pageshow", function listener(event) { - if (event.target.location != "http://example.com/") - return; - gBrowser.removeEventListener("pageshow", listener); + wait_for_page_show(gBrowser.selectedBrowser).then(() => { info("Part 2"); executeSoon(function() { @@ -419,10 +430,7 @@ add_test(function() { is_in_list(aManager, "addons://list/plugin", false, true); executeSoon(() => go_forward()); - gBrowser.addEventListener("pageshow", function listener(event) { - if (event.target.location != "http://example.com/") - return; - gBrowser.removeEventListener("pageshow", listener); + wait_for_page_show(gBrowser.selectedBrowser).then(() => { info("Part 4"); executeSoon(function() { @@ -540,11 +548,7 @@ add_test(function() { is_in_detail(aManager, "addons://search/", true, false); gBrowser.loadURI("http://example.com/"); - gBrowser.addEventListener("pageshow", function listener(event) { - if (event.target.location != "http://example.com/") - return; - gBrowser.removeEventListener("pageshow", listener); - + wait_for_page_show(gBrowser.selectedBrowser).then(() => { info("Part 4"); executeSoon(function() { ok(gBrowser.canGoBack, "Should be able to go back");