browser_framebusting_notification.js (6131B)
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 "use strict"; 6 7 const { PermissionTestUtils } = ChromeUtils.importESModule( 8 "resource://testing-common/PermissionTestUtils.sys.mjs" 9 ); 10 11 add_setup(async function () { 12 await SpecialPowers.pushPrefEnv({ 13 set: [ 14 ["dom.disable_open_during_load", true], 15 ["dom.security.framebusting_intervention.enabled", true], 16 ["dom.disable_open_click_delay", 0], 17 ], 18 }); 19 }); 20 21 add_task(async function () { 22 const tab = await BrowserTestUtils.openNewForegroundTab( 23 gBrowser, 24 "about:blank" 25 ); 26 27 await triggerFramebustingIntervention(tab); 28 await openSettingsPopup(); 29 30 info("Checking notification l10n..."); 31 const notification = gBrowser 32 .getNotificationBox() 33 .getNotificationWithValue("popup-blocked"); 34 is( 35 notification.messageL10nId, 36 "redirect-warning-with-popup-message", 37 "Notification message is correct" 38 ); 39 40 // Run actual checks. 41 await checkLocalization(); 42 await checkToolbarAllowSite(tab); 43 await checkToolbarManageSettings(); 44 await checkToolbarDontShow(tab); 45 await checkToolbarRedirect(tab); 46 47 info("Cleaning up..."); 48 await closeSettingsPopup(); 49 BrowserTestUtils.removeTab(tab); 50 }); 51 52 async function openSettingsPopup() { 53 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 54 55 // Close a still open one beforehand. 56 if (blockedPopupOptions.state === "open") { 57 await closeSettingsPopup(); 58 } 59 60 info("Waiting for notification..."); 61 let notification; 62 await TestUtils.waitForCondition( 63 () => 64 (notification = gBrowser 65 .getNotificationBox() 66 .getNotificationWithValue("popup-blocked")) 67 ); 68 69 info("Clicking button..."); 70 const promise = BrowserTestUtils.waitForEvent( 71 window, 72 "popupshown", 73 true, 74 event => event.target == blockedPopupOptions 75 ); 76 notification._buttons[0].click(); 77 78 info("Waiting for toolbar to show..."); 79 await promise; 80 } 81 82 async function closeSettingsPopup() { 83 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 84 85 info("Hiding settings popup..."); 86 const promise = BrowserTestUtils.waitForEvent( 87 blockedPopupOptions, 88 "popuphidden" 89 ); 90 blockedPopupOptions.hidePopup(); 91 92 info("Waiting for popup to hide..."); 93 await promise; 94 } 95 96 async function checkLocalization() { 97 const expectedProperties = [ 98 { 99 idx: 0, 100 dataset: { 101 l10nId: "popups-infobar-allow2", 102 l10nArgs: JSON.stringify({ 103 uriHost: new URL(FRAMEBUSTING_PARENT_URL).host, 104 }), 105 }, 106 }, 107 { idx: 1, dataset: { l10nId: "edit-popup-settings2" } }, 108 { 109 idx: 2, 110 dataset: { l10nId: "popups-infobar-dont-show-message2" }, 111 }, 112 { idx: 3, hidden: false }, 113 { 114 idx: 4, 115 dataset: { 116 l10nId: "popup-trigger-redirect-menuitem", 117 l10nArgs: JSON.stringify({ redirectURI: FRAMEBUSTING_FRAME_URL }), 118 }, 119 }, 120 { idx: 5, hidden: true }, 121 ]; 122 123 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 124 is(blockedPopupOptions.children.length, expectedProperties.length); 125 126 for (const { idx, ...properties } of expectedProperties) { 127 const element = blockedPopupOptions.children[idx]; 128 for (const [key, value] of Object.entries(properties)) { 129 Assert.deepEqual(element[key], value); 130 } 131 } 132 } 133 134 async function checkToolbarAllowSite(tab) { 135 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 136 const allowSiteItem = blockedPopupOptions.children[0]; 137 138 info("Clicking allow site item..."); 139 allowSiteItem.click(); 140 141 info("Waiting to be redirected..."); 142 await BrowserTestUtils.waitForLocationChange( 143 gBrowser, 144 FRAMEBUSTING_FRAME_URL 145 ); 146 147 info("Checking permission..."); 148 is( 149 PermissionTestUtils.testPermission(FRAMEBUSTING_PARENT_URL, "popup"), 150 Services.perms.ALLOW_ACTION, 151 "popup permissions is allow" 152 ); 153 154 info("Triggering framebusting intervention..."); 155 await triggerFramebustingIntervention(tab); 156 157 // uh oh - busted! 158 await BrowserTestUtils.browserLoaded( 159 tab.linkedBrowser, 160 /*includeSubframes=*/ false, 161 FRAMEBUSTING_FRAME_URL 162 ); 163 164 info("Removing permission..."); 165 PermissionTestUtils.remove(FRAMEBUSTING_PARENT_URL, "popup"); 166 167 info("Resetting to initial state..."); 168 await triggerFramebustingIntervention(tab); 169 await openSettingsPopup(); 170 } 171 172 async function checkToolbarManageSettings() { 173 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 174 const manageSettingsItem = blockedPopupOptions.children[1]; 175 176 const promise = BrowserTestUtils.waitForLocationChange( 177 gBrowser, 178 "about:preferences#privacy" 179 ); 180 181 info("Clicking manage settings item..."); 182 manageSettingsItem.click(); 183 184 info("Waiting for navigation..."); 185 await promise; 186 187 info("Closing new tab..."); 188 BrowserTestUtils.removeTab(gBrowser.selectedTab); 189 } 190 191 async function checkToolbarDontShow(tab) { 192 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 193 const dontShowItem = blockedPopupOptions.children[2]; 194 195 info("Clicking don't show item..."); 196 dontShowItem.click(); 197 198 info("Checking prefs..."); 199 is(Services.prefs.getBoolPref("privacy.popups.showBrowserMessage"), false); 200 201 info("Resetting prefs..."); 202 Services.prefs.setBoolPref("privacy.popups.showBrowserMessage", true); 203 204 info("Resetting to initial state..."); 205 await triggerFramebustingIntervention(tab); 206 await openSettingsPopup(); 207 } 208 209 async function checkToolbarRedirect(tab) { 210 const blockedPopupOptions = document.getElementById("blockedPopupOptions"); 211 const redirectItem = blockedPopupOptions.children[4]; 212 213 info("Clicking redirect item..."); 214 redirectItem.click(); 215 216 info("Waiting to be redirected..."); 217 await BrowserTestUtils.browserLoaded( 218 tab.linkedBrowser, 219 /*includeSubFrames=*/ false, 220 FRAMEBUSTING_FRAME_URL 221 ); 222 223 info("Resetting to initial state..."); 224 await triggerFramebustingIntervention(tab); 225 await openSettingsPopup(); 226 }