From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../content/test/popups/browser_popup_frames.js | 128 +++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 browser/base/content/test/popups/browser_popup_frames.js (limited to 'browser/base/content/test/popups/browser_popup_frames.js') 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/"); +}); -- cgit v1.2.3