browser_popup_blocker_frames.js (2856B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const baseURL = getRootDirectory(gTestPath).replace( 6 "chrome://mochitests/content", 7 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 8 "http://example.com" 9 ); 10 11 async function test_opening_blocked_popups(testURL) { 12 // Enable the popup blocker. 13 await SpecialPowers.pushPrefEnv({ 14 set: [["dom.disable_open_during_load", true]], 15 }); 16 17 // Open the test page. 18 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, testURL); 19 20 await SpecialPowers.spawn( 21 tab.linkedBrowser, 22 [baseURL + "popup_blocker.html"], 23 uri => { 24 let iframe = content.document.createElement("iframe"); 25 iframe.id = "popupframe"; 26 iframe.src = uri; 27 content.document.body.appendChild(iframe); 28 } 29 ); 30 31 // Wait for the popup-blocked notification. 32 await TestUtils.waitForCondition( 33 () => 34 gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), 35 "Waiting for the popup-blocked notification." 36 ); 37 38 let popupTabs = []; 39 function onTabOpen(event) { 40 popupTabs.push(event.target); 41 } 42 gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen); 43 44 await SpecialPowers.pushPermissions([ 45 { type: "popup", allow: true, context: testURL }, 46 ]); 47 48 await SpecialPowers.spawn( 49 tab.linkedBrowser, 50 [baseURL + "popup_blocker.html"], 51 uri => { 52 content.document.getElementById("popupframe").remove(); 53 let iframe = content.document.createElement("iframe"); 54 iframe.id = "popupframe"; 55 iframe.src = uri; 56 content.document.body.appendChild(iframe); 57 } 58 ); 59 60 await TestUtils.waitForCondition( 61 () => 62 popupTabs.length == 2 && 63 popupTabs.every( 64 aTab => aTab.linkedBrowser.currentURI.spec != "about:blank" 65 ), 66 "Waiting for two tabs to be opened." 67 ); 68 69 ok( 70 popupTabs[0].linkedBrowser.currentURI.spec.endsWith("popup_blocker_a.html"), 71 "Popup a" 72 ); 73 ok( 74 popupTabs[1].linkedBrowser.currentURI.spec.endsWith("popup_blocker_b.html"), 75 "Popup b" 76 ); 77 78 await SpecialPowers.popPermissions(); 79 80 gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen); 81 82 await SpecialPowers.spawn(tab.linkedBrowser, [], () => { 83 content.document.getElementById("popupframe").remove(); 84 }); 85 86 BrowserTestUtils.removeTab(tab); 87 for (let popup of popupTabs) { 88 gBrowser.removeTab(popup); 89 } 90 } 91 92 add_task(async function () { 93 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 94 await test_opening_blocked_popups("http://example.com/"); 95 }); 96 97 add_task(async function () { 98 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 99 await test_opening_blocked_popups("http://w3c-test.org/"); 100 });