browser_fullscreen-navigation-history-race.js (4546B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 requestLongerTimeout(2); 7 8 // Import helpers 9 Services.scriptloader.loadSubScript( 10 "chrome://mochitests/content/browser/dom/base/test/fullscreen/fullscreen_helpers.js", 11 this 12 ); 13 14 add_setup(async function () { 15 await pushPrefs( 16 ["test.wait300msAfterTabSwitch", true], 17 ["full-screen-api.transition-duration.enter", "0 0"], 18 ["full-screen-api.transition-duration.leave", "0 0"], 19 ["full-screen-api.allow-trusted-requests-only", false] 20 ); 21 }); 22 23 function preventBFCache(aBrowsingContext, aPrevent) { 24 return SpecialPowers.spawn(aBrowsingContext, [aPrevent], prevent => { 25 if (prevent) { 26 // Using a dummy onunload listener to disable the bfcache. 27 content.window.addEventListener("unload", () => {}); 28 } 29 content.window.addEventListener( 30 "pagehide", 31 e => { 32 // XXX checking persisted property causes intermittent failures, so we 33 // dump the value instead, bug 1822263. 34 // is(e.persisted, !prevent, `Check BFCache state`); 35 info(`Check BFCache state: e.persisted is ${e.persisted}`); 36 }, 37 { once: true } 38 ); 39 }); 40 } 41 42 [true, false].forEach(crossOrigin => { 43 [true, false].forEach(initialPagePreventsBFCache => { 44 [true, false].forEach(fullscreenPagePreventsBFCache => { 45 add_task(async function navigation_history() { 46 info( 47 `crossOrigin: ${crossOrigin}, initialPagePreventsBFCache: ${initialPagePreventsBFCache}, fullscreenPagePreventsBFCache: ${fullscreenPagePreventsBFCache}` 48 ); 49 await BrowserTestUtils.withNewTab( 50 { 51 gBrowser, 52 url: "https://example.com/browser/dom/base/test/fullscreen/dummy_page.html", 53 }, 54 async function (browser) { 55 // Maybe prevent BFCache on initial page. 56 await preventBFCache( 57 browser.browsingContext, 58 initialPagePreventsBFCache 59 ); 60 61 // Navigate to fullscreen page. 62 const url = crossOrigin 63 ? "https://example.org/browser/dom/base/test/fullscreen/file_fullscreen-iframe-inner.html" 64 : "https://example.com/browser/dom/base/test/fullscreen/file_fullscreen-iframe-inner.html"; 65 const loaded = BrowserTestUtils.browserLoaded(browser, false, url); 66 BrowserTestUtils.startLoadingURIString(browser, url); 67 await loaded; 68 69 // Maybe prevent BFCache on fullscreen test page. 70 await preventBFCache( 71 browser.browsingContext, 72 fullscreenPagePreventsBFCache 73 ); 74 75 // Trigger click event to enter fullscreen. 76 await SpecialPowers.spawn(browser.browsingContext, [], () => { 77 let target = content.document.getElementById("div"); 78 target.addEventListener( 79 "mousedown", 80 function () { 81 content.window.history.back(); 82 }, 83 { once: true } 84 ); 85 EventUtils.synthesizeMouseAtCenter(target, {}, content.window); 86 }); 87 88 // Give some time for fullscreen transition. 89 await new Promise(aResolve => { 90 SimpleTest.executeSoon(() => { 91 SimpleTest.executeSoon(aResolve); 92 }); 93 }); 94 95 // Wait fullscreen exit event if browser is still in fullscreen mode. 96 if ( 97 window.fullScreen || 98 document.documentElement.hasAttribute("inFullscreen") 99 ) { 100 info("The widget is still in fullscreen, wait again"); 101 await waitWidgetFullscreenEvent(window, false, true); 102 } 103 if (document.documentElement.hasAttribute("inDOMFullscreen")) { 104 info("The chrome document is still in fullscreen, wait again"); 105 await waitForFullScreenObserver(window, false, true); 106 } 107 108 // Ensure the browser exits fullscreen state. 109 ok(!window.fullScreen, "The widget should not be in fullscreen"); 110 ok( 111 !document.documentElement.hasAttribute("inFullscreen"), 112 "The chrome window should not be in fullscreen" 113 ); 114 ok( 115 !document.documentElement.hasAttribute("inDOMFullscreen"), 116 "The chrome document should not be in fullscreen" 117 ); 118 } 119 ); 120 }); 121 }); 122 }); 123 });