fune/browser/base/content/test/popups/browser_popup_frames.js
Prathiksha 49ac66dc70 Bug 1331931 - Move the blocked popup icon into the identity block and add a blocked popup indicator item to the identity popup. r=johannh
MozReview-Commit-ID: HxsG2Uz2PuZ

--HG--
extra : rebase_source : 447af5fb2897d45a920244a39aefe7ee2e16b470
2017-09-17 18:35:10 +05:30

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");
iframe.src = uri;
let pageHideHappened = ContentTaskUtils.waitForEvent(this, "pagehide", true);
content.document.body.appendChild(iframe);
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");
await BrowserTestUtils.removeTab(tab);
});