browser_bug1620341.js (3568B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const tab1URL = `data:text/html, 7 <html xmlns="http://www.w3.org/1999/xhtml"> 8 <head> 9 <meta charset="utf-8"/> 10 <title>First tab to be loaded</title> 11 </head> 12 <body> 13 <button>JUST A BUTTON</button> 14 </body> 15 </html>`; 16 17 const ORIGIN = 18 "https://example.com/browser/browser/base/content/test/fullscreen/fullscreen_frame.html"; 19 20 add_setup(async function () { 21 await SpecialPowers.pushPrefEnv({ 22 set: [["test.wait300msAfterTabSwitch", true]], 23 }); 24 }); 25 26 add_task(async function test_fullscreen_cross_origin() { 27 async function requestFullscreenThenCloseTab() { 28 await BrowserTestUtils.withNewTab(ORIGIN, async function (browser) { 29 info("Start fullscreen on iframe frameAllowed"); 30 31 // Make sure there is no attribute "inDOMFullscreen" before requesting fullscreen. 32 await TestUtils.waitForCondition( 33 () => !document.documentElement.hasAttribute("inDOMFullscreen") 34 ); 35 36 ok( 37 !gBrowser.tabContainer.hasAttribute("closebuttons"), 38 "Close buttons should be visible on every tab" 39 ); 40 41 // Request fullscreen from iframe 42 await SpecialPowers.spawn(browser, [], async function () { 43 let frame = content.document.getElementById("frameAllowed"); 44 frame.focus(); 45 await SpecialPowers.spawn(frame, [], async () => { 46 let frameDoc = content.document; 47 const waitForFullscreen = new Promise(resolve => { 48 const message = "fullscreenchange"; 49 function handler(evt) { 50 frameDoc.removeEventListener(message, handler); 51 Assert.equal(evt.type, message, `Request should be allowed`); 52 resolve(); 53 } 54 frameDoc.addEventListener(message, handler); 55 }); 56 57 frameDoc.getElementById("request").click(); 58 await waitForFullscreen; 59 }); 60 }); 61 62 // Make sure there is attribute "inDOMFullscreen" after requesting fullscreen. 63 await TestUtils.waitForCondition(() => 64 document.documentElement.hasAttribute("inDOMFullscreen") 65 ); 66 }); 67 } 68 69 await SpecialPowers.pushPrefEnv({ 70 set: [ 71 ["full-screen-api.enabled", true], 72 ["full-screen-api.allow-trusted-requests-only", false], 73 ["full-screen-api.transition-duration.enter", "0 0"], 74 ["full-screen-api.transition-duration.leave", "0 0"], 75 ["dom.security.featurePolicy.header.enabled", true], 76 ["dom.security.featurePolicy.webidl.enabled", true], 77 ], 78 }); 79 80 // Open a tab with tab1URL. 81 let tab1 = await BrowserTestUtils.openNewForegroundTab( 82 gBrowser, 83 tab1URL, 84 true 85 ); 86 87 // 1. Open another tab and load a page with two iframes. 88 // 2. Request fullscreen from an iframe which is in a different origin. 89 // 3. Close the tab after receiving "fullscreenchange" message. 90 // Note that we don't do "doc.exitFullscreen()" before closing the tab 91 // on purpose. 92 await requestFullscreenThenCloseTab(); 93 94 // Wait until attribute "inDOMFullscreen" is removed. 95 await TestUtils.waitForCondition( 96 () => !document.documentElement.hasAttribute("inDOMFullscreen") 97 ); 98 99 await TestUtils.waitForCondition( 100 () => !gBrowser.tabContainer.hasAttribute("closebuttons"), 101 "Close buttons should come back to every tab" 102 ); 103 104 // Remove the remaining tab and leave the test. 105 let tabClosed = BrowserTestUtils.waitForTabClosing(tab1); 106 BrowserTestUtils.removeTab(tab1); 107 await tabClosed; 108 });