gecko/dom/tests/mochitest/pointerlock/file_approval.html

67 lines
2.4 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--https://bugzilla.mozilla.org/show_bug.cgi?id=746885-->
<head>
<title>Bug 746885</title>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="pointerlock_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=746885">
Mozilla Bug 746885
</a>
<div id="div"></div>
<pre id="test">
<script type="text/javascript">
/*
* Test for Bug 746885
* When requesting pointer lock on a domain that doesn't have fullscreen
* permission, the pointer lock request should be delayed until approval
* has been granted.
*/
SimpleTest.waitForExplicitFinish();
// Ensure fullscreen won't be automatically granted for this document's domain.
SpecialPowers.removeFullscreenAllowed(document);
var div = document.getElementById("div");
var isApproved = false;
document.addEventListener("mozpointerlockchange",
function (e) {
is(isApproved, true, "Should only receive mozpointerlockchange when we've been approved for fullscreen.");
document.mozCancelFullScreen();
}, false);
function approveFullscreen() {
isApproved = true;
SpecialPowers.setFullscreenAllowed(document);
}
document.addEventListener("mozfullscreenchange", function(e) {
if (document.mozFullScreenElement === div) {
// First entered fullscreen. Request pointer lock...
div.mozRequestPointerLock();
// ... But only approve fullscreen after a delay, giving the pointer
// lock request time to run if it were going to. Note we need two timeouts
// here to because if we were to fail and the pointer lock request were to
// succeed without approval, we'd need to give it time to run, and time for
// its asynchronously dispatched mozpointerlockchange to run.
setTimeout(function(){ setTimeout(approveFullscreen, 0); }, 0);
} else {
SimpleTest.finish();
}
}, false);
function start() {
div.mozRequestFullScreen();
}
</script>
</pre>
</body>
</html>