browser_popup_frames.js (3815B)
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 let popupframeBC = 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 return iframe.browsingContext; 29 } 30 ); 31 32 // Wait for the popup-blocked notification. 33 let notification; 34 await TestUtils.waitForCondition( 35 () => 36 (notification = gBrowser 37 .getNotificationBox() 38 .getNotificationWithValue("popup-blocked")), 39 "Waiting for the popup-blocked notification." 40 ); 41 42 ok(notification, "Should have notification."); 43 44 let pageHideHappened = BrowserTestUtils.waitForContentEvent( 45 tab.linkedBrowser, 46 "pagehide", 47 true 48 ); 49 await SpecialPowers.spawn(tab.linkedBrowser, [baseURL], async function (uri) { 50 let iframe = content.document.createElement("iframe"); 51 content.document.body.appendChild(iframe); 52 iframe.src = uri; 53 }); 54 55 await pageHideHappened; 56 notification = gBrowser 57 .getNotificationBox() 58 .getNotificationWithValue("popup-blocked"); 59 ok(notification, "Should still have notification"); 60 61 pageHideHappened = BrowserTestUtils.waitForContentEvent( 62 tab.linkedBrowser, 63 "pagehide", 64 true 65 ); 66 // Now navigate the subframe. 67 await SpecialPowers.spawn(popupframeBC, [], async function () { 68 content.document.location.href = "about:blank"; 69 }); 70 await pageHideHappened; 71 await TestUtils.waitForCondition( 72 () => 73 !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), 74 "Notification should go away" 75 ); 76 ok( 77 !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), 78 "Should no longer have notification" 79 ); 80 81 // Remove the frame and add another one: 82 await SpecialPowers.spawn( 83 tab.linkedBrowser, 84 [baseURL + "popup_blocker.html"], 85 uri => { 86 content.document.getElementById("popupframe").remove(); 87 let iframe = content.document.createElement("iframe"); 88 iframe.id = "popupframe"; 89 iframe.src = uri; 90 content.document.body.appendChild(iframe); 91 } 92 ); 93 94 // Wait for the popup-blocked notification. 95 await TestUtils.waitForCondition( 96 () => 97 (notification = gBrowser 98 .getNotificationBox() 99 .getNotificationWithValue("popup-blocked")) 100 ); 101 102 ok(notification, "Should have notification."); 103 104 await SpecialPowers.spawn(tab.linkedBrowser, [], () => { 105 content.document.getElementById("popupframe").remove(); 106 }); 107 108 await TestUtils.waitForCondition( 109 () => 110 !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked") 111 ); 112 ok( 113 !gBrowser.getNotificationBox().getNotificationWithValue("popup-blocked"), 114 "Should no longer have notification" 115 ); 116 117 BrowserTestUtils.removeTab(tab); 118 } 119 120 add_task(async function () { 121 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 122 await test_opening_blocked_popups("http://example.com/"); 123 }); 124 125 add_task(async function () { 126 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 127 await test_opening_blocked_popups("http://w3c-test.org/"); 128 });