file_fullscreen-denied.html (5259B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=545812 5 6 Test DOM fullscreen API. 7 8 --> 9 <head> 10 <title>Test for Bug 545812</title> 11 <script src="/tests/SimpleTest/SimpleTest.js"></script> 12 <script src="/tests/SimpleTest/EventUtils.js"></script> 13 <script type="application/javascript" src="file_fullscreen-utils.js"></script> 14 <style> 15 body { 16 background-color: black; 17 } 18 </style> 19 </head> 20 <body> 21 22 <script type="application/javascript"> 23 24 /** Test for Bug 545812 */ 25 26 function ok(condition, msg) { 27 opener.ok(condition, "[denied] " + msg); 28 } 29 30 function is(a, b, msg) { 31 opener.is(a, b, "[denied] " + msg); 32 } 33 34 const INNER_FILE = "file_fullscreen-denied-inner.html"; 35 function setupForInnerTest(targetName, callback) { 36 window.testTargetName = targetName; 37 window.continueTest = () => { 38 delete window.testTargetName; 39 delete window.continueTest; 40 callback(); 41 }; 42 } 43 44 function begin() { 45 document.addEventListener("fullscreenchange", () => { 46 ok(false, "Should never receive " + 47 "a fullscreenchange event in the main window."); 48 }); 49 SimpleTest.executeSoon(testIFrameWithoutAllowFullscreen); 50 } 51 52 function testIFrameWithoutAllowFullscreen() { 53 // Create an iframe without an allowfullscreen attribute, whose 54 // contents request fullscreen. The request should be denied, and 55 // we should not receive a fullscreenchange event in this document. 56 var iframe = document.createElement("iframe"); 57 iframe.src = INNER_FILE; 58 // The iframe is same-origin so when we use feature policy otherwise we'd hit 59 // the "allowed" code-path (as intended). It is a bug that this test passes 60 // without the allow attribute. 61 iframe.allow = "fullscreen 'none'"; 62 setupForInnerTest("an iframe without allowfullscreen", () => { 63 document.body.removeChild(iframe); 64 SimpleTest.executeSoon(testFrameElement); 65 }); 66 document.body.appendChild(iframe); 67 } 68 69 function testFrameElement() { 70 var frameset = document.createElement("frameset"); 71 var frame = document.createElement("frame"); 72 frame.src = INNER_FILE; 73 frameset.appendChild(frame); 74 setupForInnerTest("a frame element", () => { 75 document.documentElement.removeChild(frameset); 76 SimpleTest.executeSoon(testObjectElement); 77 }); 78 document.documentElement.appendChild(frameset); 79 } 80 81 function testObjectElement() { 82 var objectElem = document.createElement("object"); 83 objectElem.data = INNER_FILE; 84 setupForInnerTest("an object element", () => { 85 document.body.removeChild(objectElem); 86 // In the following tests we want to test trust context requirement 87 // of fullscreen request, so temporary re-enable this pref. 88 SpecialPowers.pushPrefEnv({ 89 "set":[["full-screen-api.allow-trusted-requests-only", true]] 90 }, testNonTrustContext); 91 }); 92 document.body.appendChild(objectElem); 93 } 94 95 function testNonTrustContext() { 96 addFullscreenErrorContinuation(() => { 97 ok(!document.fullscreenElement, 98 "Should not grant request in non-trust context."); 99 SimpleTest.executeSoon(testLongRunningEventHandler); 100 }); 101 document.documentElement.requestFullscreen(); 102 } 103 104 function testLongRunningEventHandler() { 105 let timeout = SpecialPowers.getIntPref("dom.user_activation.transient.timeout") + 1000; 106 107 function longRunningHandler() { 108 window.removeEventListener("keypress", longRunningHandler); 109 // Busy loop until transient useractivation is timed out, so our request for 110 // fullscreen should be rejected. 111 var end = (new Date()).getTime() + timeout; 112 while ((new Date()).getTime() < end) { 113 ; // Wait... 114 } 115 document.documentElement.requestFullscreen(); 116 } 117 addFullscreenErrorContinuation(() => { 118 ok(!document.fullscreenElement, 119 "Should not grant request in long-running event handler."); 120 SimpleTest.executeSoon(testFullscreenMouseBtn); 121 }); 122 window.addEventListener("keypress", longRunningHandler); 123 sendString("a"); 124 } 125 126 function requestFullscreenMouseBtn(event, button) { 127 let clickEl = document.createElement("p"); 128 clickEl.innerText = "Click Me"; 129 130 function eventHandler(evt) { 131 document.body.requestFullscreen(); 132 evt.target.removeEventListener(evt, this); 133 } 134 135 clickEl.addEventListener(event, eventHandler); 136 document.body.appendChild(clickEl); 137 synthesizeMouseAtCenter(clickEl, { button }); 138 } 139 140 async function testFullscreenMouseBtn() { 141 await SpecialPowers.pushPrefEnv({ 142 "set": [["full-screen-api.mouse-event-allow-left-button-only", true]] 143 }); 144 let fsRequestEvents = ["mousedown", "mouseup", "pointerdown", "pointerup"]; 145 let mouseButtons = [1, 2]; 146 147 for (let i = 0; i < fsRequestEvents.length; i++) { 148 let evt = fsRequestEvents[i]; 149 for (let j = 0; j < mouseButtons.length; j++) { 150 let mouseButton = mouseButtons[j]; 151 await new Promise(resolve => { 152 addFullscreenErrorContinuation(resolve); 153 requestFullscreenMouseBtn(evt, mouseButton); 154 }); 155 ok(!document.fullscreenElement, `Should not grant request on '${evt}' triggered by mouse button ${mouseButton}`); 156 } 157 } 158 // Restore the pref environment we changed before 159 // entering testNonTrustContext. 160 await SpecialPowers.popPrefEnv(); 161 await SpecialPowers.popPrefEnv(); 162 finish(); 163 } 164 165 function finish() { 166 opener.nextTest(); 167 } 168 169 </script> 170 </body> 171 </html>