diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/popups/browser_popup_frames.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/popups/browser_popup_frames.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/browser/base/content/test/popups/browser_popup_frames.js b/browser/base/content/test/popups/browser_popup_frames.js new file mode 100644 index 0000000000..838eb5c045 --- /dev/null +++ b/browser/base/content/test/popups/browser_popup_frames.js @@ -0,0 +1,128 @@ +/* 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", + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + "http://example.com" +); + +async function test_opening_blocked_popups(testURL) { + // Enable the popup blocker. + await SpecialPowers.pushPrefEnv({ + set: [["dom.disable_open_during_load", true]], + }); + + // Open the test page. + let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, testURL); + + let popupframeBC = await SpecialPowers.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); + return iframe.browsingContext; + } + ); + + // Wait for the popup-blocked notification. + let notification; + await TestUtils.waitForCondition( + () => + (notification = gBrowser + .getNotificationBox() + .getNotificationWithValue("popup-blocked")), + "Waiting for the popup-blocked notification." + ); + + ok(notification, "Should have notification."); + + let pageHideHappened = BrowserTestUtils.waitForContentEvent( + tab.linkedBrowser, + "pagehide", + true + ); + await SpecialPowers.spawn(tab.linkedBrowser, [baseURL], async function (uri) { + let iframe = content.document.createElement("iframe"); + content.document.body.appendChild(iframe); + iframe.src = uri; + }); + + await pageHideHappened; + notification = gBrowser + .getNotificationBox() + .getNotificationWithValue("popup-blocked"); + ok(notification, "Should still have notification"); + + pageHideHappened = BrowserTestUtils.waitForContentEvent( + tab.linkedBrowser, + "pagehide", + true + ); + // Now navigate the subframe. + await SpecialPowers.spawn(popupframeBC, [], async function () { + content.document.location.href = "about:blank"; + }); + await pageHideHappened; + await TestUtils.waitForCondition( + () => + !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), + "Notification should go away" + ); + ok( + !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), + "Should no longer have notification" + ); + + // Remove the frame and add another one: + await SpecialPowers.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 TestUtils.waitForCondition( + () => + (notification = gBrowser + .getNotificationBox() + .getNotificationWithValue("popup-blocked")) + ); + + ok(notification, "Should have notification."); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("popupframe").remove(); + }); + + await TestUtils.waitForCondition( + () => + !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked") + ); + ok( + !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), + "Should no longer have notification" + ); + + BrowserTestUtils.removeTab(tab); +} + +add_task(async function () { + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await test_opening_blocked_popups("http://example.com/"); +}); + +add_task(async function () { + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + await test_opening_blocked_popups("http://w3c-test.org/"); +}); |