browser_fullscreen-bug-1798219.js (4241B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Import helpers 7 /* import-globals-from fullscreen_helpers.js */ 8 Services.scriptloader.loadSubScript( 9 "chrome://mochitests/content/browser/dom/base/test/fullscreen/fullscreen_helpers.js", 10 this 11 ); 12 13 add_setup(async function () { 14 await pushPrefs( 15 ["test.wait300msAfterTabSwitch", true], 16 ["full-screen-api.transition-duration.enter", "0 0"], 17 ["full-screen-api.transition-duration.leave", "0 0"], 18 ["full-screen-api.allow-trusted-requests-only", false] 19 ); 20 }); 21 22 async function waitAndCheckFullscreenState(aWindow) { 23 // Wait fullscreen exit event if browser is still in fullscreen mode. 24 if ( 25 aWindow.fullScreen || 26 aWindow.document.documentElement.hasAttribute("inFullscreen") 27 ) { 28 info("The widget is still in fullscreen, wait again"); 29 await waitWidgetFullscreenEvent(aWindow, false, true); 30 } 31 if (aWindow.document.documentElement.hasAttribute("inDOMFullscreen")) { 32 info("The chrome document is still in fullscreen, wait again"); 33 await waitForFullScreenObserver(aWindow, false, true); 34 } 35 36 // Ensure the browser exits fullscreen state. 37 ok(!aWindow.fullScreen, "The widget should not be in fullscreen"); 38 ok( 39 !aWindow.document.documentElement.hasAttribute("inFullscreen"), 40 "The chrome window should not be in fullscreen" 41 ); 42 ok( 43 !aWindow.document.documentElement.hasAttribute("inDOMFullscreen"), 44 "The chrome document should not be in fullscreen" 45 ); 46 } 47 48 add_task(async () => { 49 const URL = 50 "https://example.com/browser/dom/base/test/fullscreen/file_fullscreen-bug-1798219.html"; 51 // We need this dummy tab which load the same URL as test tab to keep the 52 // original content process alive after test page navigates away. 53 let dummyTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL); 54 55 await BrowserTestUtils.withNewTab( 56 { 57 gBrowser, 58 url: URL, 59 }, 60 async function (browser) { 61 await SpecialPowers.spawn(browser, [], function () { 62 content.document.querySelector("button").click(); 63 }); 64 65 // Test requests fullscreen and performs navigation simultaneously, 66 // the fullscreen request might be rejected directly if navigation happens 67 // first, so there might be no reliable state that we can wait. So give 68 // some time for possible fullscreen transition instead and ensure window 69 // should end up exiting fullscreen. 70 await new Promise(aResolve => { 71 SimpleTest.executeSoon(() => { 72 SimpleTest.executeSoon(aResolve); 73 }); 74 }); 75 await waitAndCheckFullscreenState(window); 76 } 77 ); 78 79 let dummyTabClosed = BrowserTestUtils.waitForTabClosing(dummyTab); 80 BrowserTestUtils.removeTab(dummyTab); 81 await dummyTabClosed; 82 }); 83 84 add_task(async () => { 85 await BrowserTestUtils.withNewTab( 86 { 87 gBrowser, 88 url: "https://example.com/browser/dom/base/test/fullscreen/file_fullscreen-bug-1798219-2.html", 89 }, 90 async function (browser) { 91 // Open a new window to run the tests, the original window will keep the 92 // original content process alive after the test window navigates away. 93 let promiseWin = BrowserTestUtils.waitForNewWindow(); 94 await SpecialPowers.spawn(browser, [], function () { 95 content.document.querySelector("button").click(); 96 }); 97 let newWindow = await promiseWin; 98 99 await SpecialPowers.spawn( 100 newWindow.gBrowser.selectedTab.linkedBrowser, 101 [], 102 function () { 103 content.document.querySelector("button").click(); 104 } 105 ); 106 107 // Test requests fullscreen and performs navigation simultaneously, 108 // the fullscreen request might be rejected directly if navigation happens 109 // first, so there might be no reliable state that we can wait. So give 110 // some time for possible fullscreen transition instead and ensure window 111 // should end up exiting fullscreen. 112 await new Promise(aResolve => { 113 SimpleTest.executeSoon(() => { 114 SimpleTest.executeSoon(aResolve); 115 }); 116 }); 117 await waitAndCheckFullscreenState(newWindow); 118 119 newWindow.close(); 120 } 121 ); 122 });