browser_fullscreen_warning.js (8458B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 function checkWarningState(aWarningElement, aExpectedState, aMsg) { 7 ["hidden", "ontop", "onscreen"].forEach(state => { 8 is( 9 aWarningElement.hasAttribute(state), 10 state == aExpectedState, 11 `${aMsg} - check ${state} attribute.` 12 ); 13 }); 14 } 15 16 async function waitForWarningState(aWarningElement, aExpectedState) { 17 await BrowserTestUtils.waitForAttribute(aExpectedState, aWarningElement, ""); 18 checkWarningState( 19 aWarningElement, 20 aExpectedState, 21 `Wait for ${aExpectedState} state` 22 ); 23 } 24 25 add_setup(async function init() { 26 await SpecialPowers.pushPrefEnv({ 27 set: [ 28 ["test.wait300msAfterTabSwitch", true], 29 ["full-screen-api.enabled", true], 30 ["full-screen-api.allow-trusted-requests-only", false], 31 ], 32 }); 33 }); 34 35 add_task(async function test_fullscreen_display_none() { 36 await BrowserTestUtils.withNewTab( 37 { 38 gBrowser, 39 url: `data:text/html, 40 <html> 41 <head> 42 <meta charset="utf-8"/> 43 <title>Fullscreen Test</title> 44 </head> 45 <body id="body"> 46 <iframe 47 src="https://example.org/browser/browser/base/content/test/fullscreen/fullscreen.html" 48 hidden 49 allowfullscreen></iframe> 50 </body> 51 </html>`, 52 }, 53 async function (browser) { 54 let warning = document.getElementById("fullscreen-warning"); 55 checkWarningState( 56 warning, 57 "hidden", 58 "Should not show full screen warning initially" 59 ); 60 61 let warningShownPromise = waitForWarningState(warning, "onscreen"); 62 // Enter fullscreen 63 await SpecialPowers.spawn(browser, [], async () => { 64 let frame = content.document.querySelector("iframe"); 65 frame.focus(); 66 await SpecialPowers.spawn(frame, [], () => { 67 content.document.getElementById("request").click(); 68 }); 69 }); 70 await warningShownPromise; 71 ok(true, "Fullscreen warning shown"); 72 // Exit fullscreen 73 let warningHiddenPromise = waitForWarningState(warning, "hidden"); 74 let exitFullscreenPromise = BrowserTestUtils.waitForEvent( 75 document, 76 "fullscreenchange", 77 false, 78 () => !document.fullscreenElement 79 ); 80 document.getElementById("fullscreen-exit-button").click(); 81 await Promise.all([exitFullscreenPromise, warningHiddenPromise]); 82 } 83 ); 84 }); 85 86 add_task(async function test_fullscreen_pointerlock_conflict() { 87 await BrowserTestUtils.withNewTab("https://example.com", async browser => { 88 let fsWarning = document.getElementById("fullscreen-warning"); 89 let plWarning = document.getElementById("pointerlock-warning"); 90 91 checkWarningState( 92 fsWarning, 93 "hidden", 94 "Should not show full screen warning initially" 95 ); 96 checkWarningState( 97 plWarning, 98 "hidden", 99 "Should not show pointer lock warning initially" 100 ); 101 102 let fsWarningShownPromise = waitForWarningState(fsWarning, "onscreen"); 103 info("Entering full screen and pointer lock."); 104 await SpecialPowers.spawn(browser, [], async () => { 105 await content.document.body.requestFullscreen(); 106 await content.document.body.requestPointerLock(); 107 }); 108 109 await fsWarningShownPromise; 110 checkWarningState( 111 plWarning, 112 "hidden", 113 "Should not show pointer lock warning" 114 ); 115 116 info("Exiting pointerlock"); 117 await SpecialPowers.spawn(browser, [], async () => { 118 await content.document.exitPointerLock(); 119 }); 120 121 checkWarningState( 122 fsWarning, 123 "onscreen", 124 "Should still show full screen warning" 125 ); 126 checkWarningState( 127 plWarning, 128 "hidden", 129 "Should not show pointer lock warning" 130 ); 131 132 // Cleanup 133 info("Exiting fullscreen"); 134 await document.exitFullscreen(); 135 }); 136 }); 137 138 // https://bugzilla.mozilla.org/show_bug.cgi?id=1821884 139 add_task(async function test_reshow_fullscreen_notification() { 140 await BrowserTestUtils.withNewTab("https://example.com", async browser => { 141 let newWin = await BrowserTestUtils.openNewBrowserWindow(); 142 let fsWarning = document.getElementById("fullscreen-warning"); 143 144 info("Entering full screen and wait for the fullscreen warning to appear."); 145 await SimpleTest.promiseFocus(window); 146 await Promise.all([ 147 waitForWarningState(fsWarning, "onscreen"), 148 BrowserTestUtils.waitForEvent(fsWarning, "transitionend"), 149 SpecialPowers.spawn(browser, [], async () => { 150 content.document.body.requestFullscreen(); 151 }), 152 ]); 153 154 info( 155 "Switch focus away from the fullscreen window, the fullscreen warning should still hide automatically." 156 ); 157 await Promise.all([ 158 waitForWarningState(fsWarning, "hidden"), 159 SimpleTest.promiseFocus(newWin), 160 ]); 161 162 info( 163 "Switch focus back to the fullscreen window, the fullscreen warning should show again." 164 ); 165 await Promise.all([ 166 waitForWarningState(fsWarning, "onscreen"), 167 SimpleTest.promiseFocus(window), 168 ]); 169 170 info("Wait for fullscreen warning timed out."); 171 await waitForWarningState(fsWarning, "hidden"); 172 173 info("The fullscreen warning should not show again."); 174 await SimpleTest.promiseFocus(newWin); 175 await SimpleTest.promiseFocus(window); 176 await new Promise(resolve => { 177 requestAnimationFrame(() => { 178 requestAnimationFrame(resolve); 179 }); 180 }); 181 checkWarningState( 182 fsWarning, 183 "hidden", 184 "The fullscreen warning should not show." 185 ); 186 187 info("Close new browser window."); 188 await BrowserTestUtils.closeWindow(newWin); 189 190 info("Exit fullscreen."); 191 await document.exitFullscreen(); 192 }); 193 }); 194 195 add_task(async function test_fullscreen_reappear() { 196 await BrowserTestUtils.withNewTab("https://example.com", async browser => { 197 let fsWarning = document.getElementById("fullscreen-warning"); 198 199 info("Entering full screen and wait for the fullscreen warning to appear."); 200 await Promise.all([ 201 waitForWarningState(fsWarning, "onscreen"), 202 SpecialPowers.spawn(browser, [], async () => { 203 content.document.body.requestFullscreen(); 204 }), 205 ]); 206 207 info("Wait for fullscreen warning timed out."); 208 await waitForWarningState(fsWarning, "hidden"); 209 210 info("Move mouse to the top of screen."); 211 await Promise.all([ 212 waitForWarningState(fsWarning, "ontop"), 213 EventUtils.synthesizeMouse(document.documentElement, 100, 0, { 214 type: "mousemove", 215 }), 216 ]); 217 218 info("Wait for fullscreen warning timed out again."); 219 await waitForWarningState(fsWarning, "hidden"); 220 221 info("Exit fullscreen."); 222 await document.exitFullscreen(); 223 }); 224 }); 225 226 // https://bugzilla.mozilla.org/show_bug.cgi?id=1847901 227 add_task(async function test_fullscreen_warning_disabled() { 228 // Disable fullscreen warning 229 await SpecialPowers.pushPrefEnv({ 230 set: [["full-screen-api.warning.timeout", 0]], 231 }); 232 233 await BrowserTestUtils.withNewTab("https://example.com", async browser => { 234 let newWin = await BrowserTestUtils.openNewBrowserWindow(); 235 let fsWarning = document.getElementById("fullscreen-warning"); 236 let mut = new MutationObserver(mutations => { 237 ok(false, `${mutations[0].attributeName} attribute should not change`); 238 }); 239 mut.observe(fsWarning, { 240 attributeFilter: ["hidden", "onscreen", "ontop"], 241 }); 242 243 info("Entering full screen."); 244 await SimpleTest.promiseFocus(window); 245 await SpecialPowers.spawn(browser, [], async () => { 246 return content.document.body.requestFullscreen(); 247 }); 248 // Wait a bit to ensure no state change. 249 await new Promise(resolve => { 250 requestAnimationFrame(() => { 251 requestAnimationFrame(resolve); 252 }); 253 }); 254 255 info("The fullscreen warning should still not show after switching focus."); 256 await SimpleTest.promiseFocus(newWin); 257 await SimpleTest.promiseFocus(window); 258 // Wait a bit to ensure no state change. 259 await new Promise(resolve => { 260 requestAnimationFrame(() => { 261 requestAnimationFrame(resolve); 262 }); 263 }); 264 265 mut.disconnect(); 266 267 info("Close new browser window."); 268 await BrowserTestUtils.closeWindow(newWin); 269 270 info("Exit fullscreen."); 271 await document.exitFullscreen(); 272 }); 273 274 // Revert the setting to avoid affecting subsequent tests. 275 await SpecialPowers.popPrefEnv(); 276 });