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 --- .../test/popups/browser_popup_blocker_frames.js | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 browser/base/content/test/popups/browser_popup_blocker_frames.js (limited to 'browser/base/content/test/popups/browser_popup_blocker_frames.js') diff --git a/browser/base/content/test/popups/browser_popup_blocker_frames.js b/browser/base/content/test/popups/browser_popup_blocker_frames.js new file mode 100644 index 0000000000..163fa4a0bb --- /dev/null +++ b/browser/base/content/test/popups/browser_popup_blocker_frames.js @@ -0,0 +1,100 @@ +/* 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); + + 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); + } + ); + + // Wait for the popup-blocked notification. + await TestUtils.waitForCondition( + () => + gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), + "Waiting for the popup-blocked notification." + ); + + let popupTabs = []; + function onTabOpen(event) { + popupTabs.push(event.target); + } + gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen); + + await SpecialPowers.pushPermissions([ + { type: "popup", allow: true, context: testURL }, + ]); + + 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); + } + ); + + await TestUtils.waitForCondition( + () => + popupTabs.length == 2 && + popupTabs.every( + aTab => aTab.linkedBrowser.currentURI.spec != "about:blank" + ), + "Waiting for two tabs to be opened." + ); + + ok( + popupTabs[0].linkedBrowser.currentURI.spec.endsWith("popup_blocker_a.html"), + "Popup a" + ); + ok( + popupTabs[1].linkedBrowser.currentURI.spec.endsWith("popup_blocker_b.html"), + "Popup b" + ); + + await SpecialPowers.popPermissions(); + + gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen); + + await SpecialPowers.spawn(tab.linkedBrowser, [], () => { + content.document.getElementById("popupframe").remove(); + }); + + BrowserTestUtils.removeTab(tab); + for (let popup of popupTabs) { + gBrowser.removeTab(popup); + } +} + +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