browser_fullscreen_window_focus.js (4008B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 async function pause() { 7 /* eslint-disable mozilla/no-arbitrary-setTimeout */ 8 return new Promise(resolve => setTimeout(resolve, 500)); 9 } 10 11 const IFRAME_ID = "testIframe"; 12 13 async function testWindowFocus(isPopup, iframeID) { 14 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); 15 16 info("Calling window.open()"); 17 let openedWindow = await jsWindowOpen(tab.linkedBrowser, isPopup, iframeID); 18 info("Letting OOP focus to stabilize"); 19 await pause(); // Bug 1719659 for proper fix 20 info("re-focusing main window"); 21 await waitForFocus(tab.linkedBrowser); 22 23 info("Entering full-screen"); 24 await DOMFullscreenTestUtils.changeFullscreen(tab.linkedBrowser, true); 25 26 await testExpectFullScreenExit( 27 tab.linkedBrowser, 28 true, 29 async () => { 30 info("Calling window.focus()"); 31 await jsWindowFocus(tab.linkedBrowser, iframeID); 32 }, 33 () => { 34 // Async fullscreen transitions will swallow the repaint of the tab, 35 // preventing us from detecting that we've successfully changed 36 // fullscreen. Supply an action to switch back to the tab after the 37 // fullscreen event has been received, which will ensure that the 38 // tab is repainted when the DOMFullscreenChild is listening for it. 39 info("Calling switchTab()"); 40 BrowserTestUtils.switchTab(gBrowser, tab); 41 } 42 ); 43 44 // Cleanup 45 if (isPopup) { 46 openedWindow.close(); 47 } else { 48 BrowserTestUtils.removeTab(openedWindow); 49 } 50 BrowserTestUtils.removeTab(tab); 51 } 52 53 async function testWindowElementFocus(isPopup) { 54 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL); 55 56 info("Calling window.open()"); 57 let openedWindow = await jsWindowOpen(tab.linkedBrowser, isPopup); 58 info("Letting OOP focus to stabilize"); 59 await pause(); // Bug 1719659 for proper fix 60 info("re-focusing main window"); 61 await waitForFocus(tab.linkedBrowser); 62 63 info("Entering full-screen"); 64 await DOMFullscreenTestUtils.changeFullscreen(tab.linkedBrowser, true); 65 66 await testExpectFullScreenExit( 67 tab.linkedBrowser, 68 false, 69 async () => { 70 info("Calling element.focus() on popup"); 71 await ContentTask.spawn(tab.linkedBrowser, {}, async () => { 72 await content.wrappedJSObject.sendMessage( 73 content.wrappedJSObject.openedWindow, 74 "elementfocus" 75 ); 76 }); 77 }, 78 () => { 79 // Async fullscreen transitions will swallow the repaint of the tab, 80 // preventing us from detecting that we've successfully changed 81 // fullscreen. Supply an action to switch back to the tab after the 82 // fullscreen event has been received, which will ensure that the 83 // tab is repainted when the DOMFullscreenChild is listening for it. 84 info("Calling switchTab()"); 85 BrowserTestUtils.switchTab(gBrowser, tab); 86 } 87 ); 88 89 // Cleanup 90 await DOMFullscreenTestUtils.changeFullscreen(tab.linkedBrowser, false); 91 if (isPopup) { 92 openedWindow.close(); 93 } else { 94 BrowserTestUtils.removeTab(openedWindow); 95 } 96 BrowserTestUtils.removeTab(tab); 97 } 98 99 add_setup(async function () { 100 await SpecialPowers.pushPrefEnv({ 101 set: [ 102 ["dom.disable_open_during_load", false], // Allow window.focus calls without user interaction 103 ["browser.link.open_newwindow.disabled_in_fullscreen", false], 104 ], 105 }); 106 }); 107 108 add_task(function test_popupWindowFocus() { 109 return testWindowFocus(true); 110 }); 111 112 add_task(function test_iframePopupWindowFocus() { 113 return testWindowFocus(true, IFRAME_ID); 114 }); 115 116 add_task(function test_popupWindowElementFocus() { 117 return testWindowElementFocus(true); 118 }); 119 120 add_task(function test_backgroundTabFocus() { 121 return testWindowFocus(false); 122 }); 123 124 add_task(function test_iframebackgroundTabFocus() { 125 return testWindowFocus(false, IFRAME_ID); 126 }); 127 128 add_task(function test_backgroundTabElementFocus() { 129 return testWindowElementFocus(false); 130 });