gecko/dom/html/test/file_fullscreen-denied.html

96 lines
2.8 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=545812
Test DOM full-screen API.
-->
<head>
<title>Test for Bug 545812</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="file_fullscreen-utils.js"></script>
<style>
body {
background-color: black;
}
</style>
</head>
<body>
<script type="application/javascript">
/** Test for Bug 545812 **/
function ok(condition, msg) {
opener.ok(condition, "[denied] " + msg);
}
function is(a, b, msg) {
opener.is(a, b, "[denied] " + msg);
}
var gotFullScreenChange = false;
function begin() {
document.addEventListener("mozfullscreenchange",
function() {
ok(false, "Should never receive a mozfullscreenchange event in the main window.");
gotFullScreenChange = true;
},
false);
// Request full-screen from a non trusted context (this script isn't a user
// generated event!).
SpecialPowers.pushPrefEnv({"set":[["full-screen-api.allow-trusted-requests-only", true]]}, startTest);
function startTest() {
addFullscreenErrorContinuation(
function() {
ok(!document.mozFullScreen, "Should not grant request in non-trusted context");
// Test requesting full-screen mode in a long-running user-generated event handler.
// The request in the key handler should not be granted.
window.addEventListener("keypress", keyHandler, false);
synthesizeKey("VK_A", {});
});
document.body.mozRequestFullScreen();
}
}
function keyHandler(event) {
window.removeEventListener("keypress", keyHandler, false);
// Busy loop until 2s has passed. We should then be past the 1 second threshold, and so
// our request for full-screen mode should be rejected.
var end = (new Date()).getTime() + 2000;
while ((new Date()).getTime() < end) {
; // Wait...
}
addFullscreenErrorContinuation(
function() {
ok(!document.mozFullScreen, "Should not grant request in long-running event handler.");
// Disable the requirement for trusted contexts only, so the tests are easier
// to write.
SpecialPowers.pushPrefEnv({"set":[["full-screen-api.allow-trusted-requests-only", false]]}, function() {
// Create an iframe without a allowfullscreen attribute, whose contents requests
// full-screen. The request should be denied, and we should not receive a fullscreenchange
// event in this document.
var iframe = document.createElement("iframe");
iframe.src = "file_fullscreen-denied-inner.html";
document.body.appendChild(iframe);
});
});
document.body.mozRequestFullScreen();
}
function finish() {
ok(!gotFullScreenChange, "Should not ever grant a fullscreen request in this doc.");
opener.nextTest();
}
</script>
</pre>
<div id="full-screen-element"></div>
</body>
</html>