head.js (3772B)
1 const TEST_URL = 2 "https://example.com/browser/browser/base/content/test/fullscreen/open_and_focus_helper.html"; 3 4 const { DOMFullscreenTestUtils } = ChromeUtils.importESModule( 5 "resource://testing-common/DOMFullscreenTestUtils.sys.mjs" 6 ); 7 DOMFullscreenTestUtils.init(this, window); 8 9 async function testExpectFullScreenExit( 10 browser, 11 leaveFS, 12 action, 13 actionAfterFSEvent 14 ) { 15 let fsPromise = DOMFullscreenTestUtils.waitForFullScreenState( 16 browser, 17 false, 18 actionAfterFSEvent 19 ); 20 if (leaveFS) { 21 if (action) { 22 await action(); 23 } 24 await fsPromise; 25 ok(true, "Should leave full-screen"); 26 } else { 27 if (action) { 28 await action(); 29 } 30 let result = await Promise.race([ 31 fsPromise, 32 new Promise(resolve => { 33 SimpleTest.requestFlakyTimeout("Wait for failure condition"); 34 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 35 setTimeout(() => resolve(true), 2500); 36 }), 37 ]); 38 ok(result, "Should not leave full-screen"); 39 } 40 } 41 42 function jsWindowFocus(browser, iframeId) { 43 return ContentTask.spawn(browser, { iframeId }, async args => { 44 let destWin = content; 45 if (args.iframeId) { 46 let iframe = content.document.getElementById(args.iframeId); 47 if (!iframe) { 48 throw new Error("iframe not set"); 49 } 50 destWin = iframe.contentWindow; 51 } 52 await content.wrappedJSObject.sendMessage(destWin, "focus"); 53 }); 54 } 55 56 function jsElementFocus(browser, iframeId) { 57 return ContentTask.spawn(browser, { iframeId }, async args => { 58 let destWin = content; 59 if (args.iframeId) { 60 let iframe = content.document.getElementById(args.iframeId); 61 if (!iframe) { 62 throw new Error("iframe not set"); 63 } 64 destWin = iframe.contentWindow; 65 } 66 await content.wrappedJSObject.sendMessage(destWin, "elementfocus"); 67 }); 68 } 69 70 async function jsWindowOpen(browser, isPopup, iframeId) { 71 //let windowOpened = BrowserTestUtils.waitForNewWindow(); 72 let windowOpened = isPopup 73 ? BrowserTestUtils.waitForNewWindow({ url: TEST_URL }) 74 : BrowserTestUtils.waitForNewTab(gBrowser, TEST_URL, true); 75 ContentTask.spawn(browser, { isPopup, iframeId }, async args => { 76 let destWin = content; 77 if (args.iframeId) { 78 // Create a cross origin iframe 79 destWin = ( 80 await content.wrappedJSObject.createIframe(args.iframeId, true) 81 ).contentWindow; 82 } 83 // Send message to either the iframe or the current page to open a popup 84 await content.wrappedJSObject.sendMessage( 85 destWin, 86 args.isPopup ? "openpopup" : "open" 87 ); 88 }); 89 return windowOpened; 90 } 91 92 async function jsClickLink(browser, isPopup, iframeId) { 93 //let windowOpened = BrowserTestUtils.waitForNewWindow(); 94 let windowOpened = isPopup 95 ? BrowserTestUtils.waitForNewWindow({ url: TEST_URL }) 96 : BrowserTestUtils.waitForNewTab(gBrowser, TEST_URL, true); 97 ContentTask.spawn(browser, { isPopup, iframeId }, async args => { 98 let destWin = content; 99 if (args.iframeId) { 100 // Create a cross origin iframe 101 destWin = ( 102 await content.wrappedJSObject.createIframe(args.iframeId, true) 103 ).contentWindow; 104 } 105 // Send message to either the iframe or the current page to click a link 106 await content.wrappedJSObject.sendMessage(destWin, "clicklink"); 107 }); 108 return windowOpened; 109 } 110 111 function waitForFocus(...args) { 112 return new Promise(resolve => SimpleTest.waitForFocus(resolve, ...args)); 113 } 114 115 function waitForBrowserWindowActive(win) { 116 return new Promise(resolve => { 117 if (Services.focus.activeWindow == win) { 118 resolve(); 119 } else { 120 win.addEventListener( 121 "activate", 122 () => { 123 resolve(); 124 }, 125 { once: true } 126 ); 127 } 128 }); 129 }