fune/browser/base/content/test/popups/browser_popup_frames.js
Gijs Kruitbosch 9d274b2d2f Bug 1337794 - remove obsolete pagehide handling hacks from browser.js r=mconley
The pagehide handler has been as dead as a doornail for a while now,
but the side-effect of forcing the creation of an about:blank document
in non-remote windows was implicitly relied upon by some tests.

This removes the dead code and fixes up some tests.

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

--HG--
extra : moz-landing-system : lando
2018-09-04 17:55:05 +00:00

77 lines
3.1 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const baseURL = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
add_task(async function test_opening_blocked_popups() {
// Enable the popup blocker.
await SpecialPowers.pushPrefEnv({set: [["dom.disable_open_during_load", true]]});
// Open the test page.
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "data:text/html,Hello");
await ContentTask.spawn(tab.linkedBrowser, baseURL + "popup_blocker.html", uri => {
let iframe = content.document.createElement("iframe");
iframe.id = "popupframe";
iframe.src = uri;
content.document.body.appendChild(iframe);
});
// Wait for the popup-blocked notification.
let notification;
await BrowserTestUtils.waitForCondition(() =>
notification = gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
ok(notification, "Should have notification.");
await ContentTask.spawn(tab.linkedBrowser, baseURL, async function(uri) {
let iframe = content.document.createElement("iframe");
let pageHideHappened = ContentTaskUtils.waitForEvent(this, "pagehide", true);
content.document.body.appendChild(iframe);
iframe.src = uri;
await pageHideHappened;
});
notification = gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked");
ok(notification, "Should still have notification");
// Now navigate the subframe.
await ContentTask.spawn(tab.linkedBrowser, null, async function() {
let pageHideHappened = ContentTaskUtils.waitForEvent(this, "pagehide", true);
content.document.getElementById("popupframe").contentDocument.location.href = "about:blank";
await pageHideHappened;
});
await BrowserTestUtils.waitForCondition(() =>
!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
ok(!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"),
"Should no longer have notification");
// Remove the frame and add another one:
await ContentTask.spawn(tab.linkedBrowser, baseURL + "popup_blocker.html", uri => {
content.document.getElementById("popupframe").remove();
let iframe = content.document.createElement("iframe");
iframe.id = "popupframe";
iframe.src = uri;
content.document.body.appendChild(iframe);
});
// Wait for the popup-blocked notification.
await BrowserTestUtils.waitForCondition(() =>
notification = gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
ok(notification, "Should have notification.");
await ContentTask.spawn(tab.linkedBrowser, null, () => {
content.document.getElementById("popupframe").remove();
});
await BrowserTestUtils.waitForCondition(() =>
!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"));
ok(!gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"),
"Should no longer have notification");
BrowserTestUtils.removeTab(tab);
});