browser_fullscreen-form-validation.js (4430B)
1 "use strict"; 2 3 const kPage = 4 "https://example.org/browser/dom/base/test/fullscreen/dummy_page.html"; 5 const kInterval = 3000; 6 7 add_task(async function () { 8 await pushPrefs( 9 ["test.wait300msAfterTabSwitch", true], 10 ["full-screen-api.transition-duration.enter", "0 0"], 11 ["full-screen-api.transition-duration.leave", "0 0"], 12 ["dom.fullscreen.force_exit_on_multiple_escape_interval", kInterval] 13 ); 14 15 let tab = await BrowserTestUtils.openNewForegroundTab({ 16 gBrowser, 17 opening: kPage, 18 waitForStateStop: true, 19 }); 20 let browser = tab.linkedBrowser; 21 22 // As requestFullscreen checks the active state of the docshell, 23 // wait for the document to be activated, just to be sure that 24 // the fullscreen request won't be denied. 25 await SpecialPowers.spawn(browser, [], () => { 26 // Setup for form validate. 27 let div = content.document.createElement("div"); 28 div.innerHTML = ` 29 <form> 30 <input required> 31 <button type="submit">Submit</button> 32 </form> 33 `; 34 content.document.body.appendChild(div); 35 36 return ContentTaskUtils.waitForCondition( 37 () => content.browsingContext.isActive && content.document.hasFocus() 38 ); 39 }); 40 41 let state; 42 info("Enter DOM fullscreen"); 43 let fullScreenChangedPromise = BrowserTestUtils.waitForContentEvent( 44 browser, 45 "fullscreenchange" 46 ); 47 await SpecialPowers.spawn(browser, [], () => { 48 content.document.body.requestFullscreen(); 49 }); 50 51 await fullScreenChangedPromise; 52 state = await SpecialPowers.spawn(browser, [], () => { 53 return !!content.document.fullscreenElement; 54 }); 55 ok(state, "The content should have entered fullscreen"); 56 ok(document.fullscreenElement, "The chrome should also be in fullscreen"); 57 58 info("Open form validation popup (1)"); 59 let popupShownPromise = promiseWaitForEvent(window, "popupshown"); 60 await SpecialPowers.spawn(browser, [], () => { 61 content.document.querySelector("button").click(); 62 }); 63 await popupShownPromise; 64 let invalidFormPopup = document.getElementById("invalid-form-popup"); 65 is(invalidFormPopup.state, "open", "Should have form validation popup"); 66 ok(document.fullscreenElement, "The chrome should still be in fullscreen"); 67 68 info("Synthesize Esc key (1)"); 69 let popupHidePromise = promiseWaitForEvent(window, "popuphidden"); 70 EventUtils.synthesizeKey("KEY_Escape"); 71 await popupHidePromise; 72 is( 73 invalidFormPopup.state, 74 "closed", 75 "Should have closed form validation popup" 76 ); 77 ok(document.fullscreenElement, "The chrome should still be in fullscreen"); 78 79 info("Wait for multiple-escape-handling interval to expire"); 80 await new Promise(resolve => { 81 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 82 setTimeout(resolve, kInterval + 100); 83 }); 84 85 info("Open form validation popup (2)"); 86 popupShownPromise = promiseWaitForEvent(window, "popupshown"); 87 await SpecialPowers.spawn(browser, [], () => { 88 content.document.querySelector("button").click(); 89 }); 90 await popupShownPromise; 91 is(invalidFormPopup.state, "open", "Should have form validation popup"); 92 ok(document.fullscreenElement, "The chrome should still be in fullscreen"); 93 94 info("Synthesize Esc key (2)"); 95 popupHidePromise = promiseWaitForEvent(window, "popuphidden"); 96 EventUtils.synthesizeKey("KEY_Escape"); 97 await popupHidePromise; 98 is( 99 invalidFormPopup.state, 100 "closed", 101 "Should have closed form validation popup" 102 ); 103 ok(document.fullscreenElement, "The chrome should still be in fullscreen"); 104 105 info("Open form validation popup (3)"); 106 popupShownPromise = promiseWaitForEvent(window, "popupshown"); 107 await SpecialPowers.spawn(browser, [], () => { 108 content.document.querySelector("button").click(); 109 }); 110 await popupShownPromise; 111 is(invalidFormPopup.state, "open", "Should have form validation popup"); 112 ok(document.fullscreenElement, "The chrome should still be in fullscreen"); 113 114 info("Synthesize Esc key (3)"); 115 let fullscreenExitPromise = BrowserTestUtils.waitForContentEvent( 116 browser, 117 "fullscreenchange" 118 ); 119 popupHidePromise = promiseWaitForEvent(window, "popuphidden"); 120 EventUtils.synthesizeKey("KEY_Escape"); 121 await popupHidePromise; 122 is( 123 invalidFormPopup.state, 124 "closed", 125 "Should have closed form validation popup" 126 ); 127 await fullscreenExitPromise; 128 ok(!document.fullscreenElement, "The chrome should have exited fullscreen"); 129 130 gBrowser.removeTab(tab); 131 });