diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /browser/base/content/test/popups/browser_popup_blocker_frames.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/popups/browser_popup_blocker_frames.js | 100 |
1 files changed, 100 insertions, 0 deletions
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/"); +}); |