browser_fullscreen-popup.js (2710B)
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 add_setup(async function () { 6 await SpecialPowers.pushPrefEnv({ 7 set: [["test.wait300msAfterTabSwitch", true]], 8 }); 9 }); 10 11 async function waitForPopup(aPopup, aOpened, aMsg) { 12 await BrowserTestUtils.waitForPopupEvent( 13 aPopup, 14 aOpened ? "shown" : "hidden" 15 ); 16 Assert.equal( 17 aPopup.popupOpen, 18 aOpened, 19 `Check ${aMsg} popup is ${aOpened ? "opened" : "closed"}` 20 ); 21 } 22 23 async function waitForFullscreen(aWindow, aFullscreen) { 24 let promise = BrowserTestUtils.waitForEvent(aWindow, "fullscreen"); 25 aWindow.fullScreen = aFullscreen; 26 await promise; 27 Assert.equal(aWindow.fullScreen, aFullscreen, `Check fullscreen state`); 28 } 29 30 function testFullscreenPopup(aURL, aPopId, aOpenPopupFun) { 31 add_task(async function test_fullscreen_popup() { 32 info(`Tests for ${aPopId}`); 33 const win = await BrowserTestUtils.openNewBrowserWindow(); 34 const tab = await BrowserTestUtils.openNewForegroundTab(win.gBrowser, aURL); 35 36 const browser = tab.linkedBrowser; 37 const popup = win.document.getElementById(aPopId); 38 39 info("Show popup"); 40 let shownPromise = waitForPopup(popup, true, aPopId); 41 await aOpenPopupFun(browser); 42 await shownPromise; 43 44 info("Popup should be closed after entering fullscreen"); 45 let hiddenPromise = waitForPopup(popup, false, aPopId); 46 await waitForFullscreen(win, true); 47 await hiddenPromise; 48 49 info("Show popup again"); 50 shownPromise = waitForPopup(popup, true, aPopId); 51 await aOpenPopupFun(browser); 52 await shownPromise; 53 54 info("Popup should be closed after exiting fullscreen"); 55 hiddenPromise = waitForPopup(popup, false, aPopId); 56 await waitForFullscreen(win, false); 57 await hiddenPromise; 58 59 // Close opened tab 60 let tabClosed = BrowserTestUtils.waitForTabClosing(tab); 61 await BrowserTestUtils.removeTab(tab); 62 await tabClosed; 63 64 // Close opened window 65 await BrowserTestUtils.closeWindow(win); 66 }); 67 } 68 69 // Test for autocomplete. 70 testFullscreenPopup( 71 `data:text/html, 72 <input id="list-input" list="test-list" type="text"/> 73 <datalist id="test-list"> 74 <option value="item 1"/> 75 <option value="item 2"/> 76 <option value="item 3"/> 77 <option value="item 4"/> 78 </datalist>`, 79 "PopupAutoComplete", 80 async browser => { 81 await SpecialPowers.spawn(browser, [], async function () { 82 const input = content.document.querySelector("input"); 83 input.focus(); 84 }); 85 await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser); 86 } 87 );