browser_fullscreen-document-mutation-navigation.js (4169B)
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 async function startTests(testFun, name) { 24 TEST_URLS.forEach(url => { 25 add_task(async () => { 26 info(`Test ${name}, url: ${url}`); 27 await BrowserTestUtils.withNewTab( 28 { 29 gBrowser, 30 url, 31 }, 32 async function (browser) { 33 let promiseFsState = waitForFullscreenState(document, true); 34 // Trigger click event in inner most iframe 35 SpecialPowers.spawn( 36 browser.browsingContext.children[0].children[0], 37 [], 38 function () { 39 content.setTimeout(() => { 40 content.document.getElementById("div").click(); 41 }, 0); 42 } 43 ); 44 await promiseFsState; 45 46 // This should exit fullscreen 47 promiseFsState = waitForFullscreenState(document, false, true); 48 await testFun(browser); 49 await promiseFsState; 50 51 // This test triggers a fullscreen request during the fullscreen exit 52 // process, so it could be possible that the widget or the chrome 53 // document goes into fullscreen mode again, but they should end up 54 // leaving fullscreen mode again. 55 if ( 56 window.fullScreen || 57 document.documentElement.hasAttribute("inFullscreen") 58 ) { 59 info("widget is still in fullscreen, wait again"); 60 await waitWidgetFullscreenEvent(window, false, true); 61 } 62 if (document.documentElement.hasAttribute("inDOMFullscreen")) { 63 info("chrome document is still in fullscreen, wait again"); 64 await waitForFullScreenObserver(document, false, true); 65 } 66 67 // Ensure the browser exits fullscreen state. 68 ok(!window.fullScreen, "The widget should not be in fullscreen"); 69 ok( 70 !document.documentElement.hasAttribute("inFullscreen"), 71 "The chrome window should not be in fullscreen" 72 ); 73 ok( 74 !document.documentElement.hasAttribute("inDOMFullscreen"), 75 "The chrome document should not be in fullscreen" 76 ); 77 } 78 ); 79 }); 80 }); 81 } 82 83 function MutateAndNavigateFromRemoteDocument( 84 aBrowsingContext, 85 aElementId, 86 aURL 87 ) { 88 return SpecialPowers.spawn( 89 aBrowsingContext, 90 [aElementId, aURL], 91 async function (id, url) { 92 let element = content.document.getElementById(id); 93 element.requestFullscreen(); 94 content.document.body.appendChild(element); 95 content.location.href = url; 96 } 97 ); 98 } 99 100 startTests(async browser => { 101 // toplevel 102 await MutateAndNavigateFromRemoteDocument( 103 browser.browsingContext, 104 "div", 105 "about:blank" 106 ); 107 }, "document_mutation_navigation_toplevel"); 108 109 startTests(async browser => { 110 let promiseRemoteFsState = waitRemoteFullscreenExitEvents([ 111 // browsingContext, name 112 [browser.browsingContext, "toplevel"], 113 ]); 114 // middle iframe 115 await MutateAndNavigateFromRemoteDocument( 116 browser.browsingContext.children[0], 117 "div", 118 "about:blank" 119 ); 120 await promiseRemoteFsState; 121 }, "document_mutation_navigation_middle_frame"); 122 123 startTests(async browser => { 124 let promiseRemoteFsState = waitRemoteFullscreenExitEvents([ 125 // browsingContext, name 126 [browser.browsingContext, "toplevel"], 127 [browser.browsingContext.children[0], "middle"], 128 ]); 129 // innermost iframe 130 await MutateAndNavigateFromRemoteDocument( 131 browser.browsingContext.children[0].children[0], 132 "div", 133 "about:blank" 134 ); 135 await promiseRemoteFsState; 136 }, "document_mutation_navigation_inner_frame");