Source code
Revision control
Copy as Markdown
Other Tools
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<script src="/tests/SimpleTest/SimpleTest.js">
</script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="pointerlock_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style type="text/css">
#child {
width: 100px;
height: 100px;
background-color:Green;
}
</style>
</head>
<body>
<div id="parent">
<div id="child"></div>
</div>
<script type="application/javascript">
/*
* Test will check to make sure that the following mouse events are no
* longer executed in pointer lock.
* - mouseover, mouseout, mouseenter, mouseleave
*/
SimpleTest.waitForExplicitFinish();
function PointerEventStats() {
this.mouseEnter = false;
this.mouseLeave = false;
this.mouseOver = false;
this.mouseOut = false;
}
var parent
, child
, parentStats = new PointerEventStats()
, childStats = new PointerEventStats()
, isPointerLocked = false;
function runTests () {
ok(isPointerLocked, "expected mouse to be locked, but wasn't.");
is(childStats.mouseEnter, false,
"child's mouseenter should not be firing in Full Screen and Pointer Lock.");
is(childStats.mouseOver, false,
"child's mouseover should not be firing in Full Screen and Pointer Lock.");
is(childStats.mouseLeave, false,
"child's mouseleave should not be firing in Full Screen and Pointer Lock.");
is(childStats.mouseOut, false,
"child's mouseout should not be firing in Full Screen and Pointer Lock.");
is(parentStats.mouseEnter, false,
"parent's mouseenter should not be firing in Full Screen and Pointer Lock.");
is(parentStats.mouseOver, false,
"parent's mouseover should not be firing in Full Screen and Pointer Lock.");
is(parentStats.mouseLeave, false,
"parent's mouseleave should not be firing in Full Screen and Pointer Lock.");
is(parentStats.mouseOut, false,
"parent's mouseout should not be firing in Full Screen and Pointer Lock.");
}
var parentMoveListener = function () {
isPointerLocked = !!document.pointerLockElement;
removeEventListeners();
document.exitPointerLock();
};
var parentOutListener = function (e) {
parentStats.mouseOut = true;
};
var parentLeaveListener = function (e) {
parentStats.mouseLeave = true;
};
var parentOverListener = function (e) {
parentStats.mouseOver = true;
};
var parentEnterListener = function (e) {
parentStats.mouseEnter = true;
};
var childOutListener = function (e) {
childStats.mouseOut = true;
};
var childLeaveListener = function (e) {
childStats.mouseLeave = true;
};
var childOverListener = function (e) {
childStats.mouseOver = true;
};
var childEnterListener = function (e) {
childStats.mouseEnter = true;
};
function addEventListeners() {
parent.addEventListener("mousemove", parentMoveListener);
parent.addEventListener("mouseout", parentOutListener);
parent.addEventListener("mouseleave", parentLeaveListener);
parent.addEventListener("mouseover", parentOverListener);
parent.addEventListener("mouseenter", parentEnterListener);
child.addEventListener("mouseout", childOutListener);
child.addEventListener("mouseleave", childLeaveListener);
child.addEventListener("mouseover", childOverListener);
child.addEventListener("mouseenter", childEnterListener);
}
function removeEventListeners() {
parent.removeEventListener("mousemove", parentMoveListener);
parent.removeEventListener("mouseout", parentOutListener);
parent.removeEventListener("mouseleave", parentLeaveListener);
parent.removeEventListener("mouseover", parentOverListener);
parent.removeEventListener("mouseenter", parentEnterListener);
child.removeEventListener("mouseout", childOutListener);
child.removeEventListener("mouseleave", childLeaveListener);
child.removeEventListener("mouseover" , childOverListener);
child.removeEventListener("mouseenter", childEnterListener);
}
document.addEventListener("pointerlockchange", function (e) {
if (document.pointerLockElement === parent) {
addEventListeners();
synthesizeMouseAtCenter(child, { type: "mousemove" }, window);
}
else {
addFullscreenChangeContinuation("exit", function() {
runTests();
SimpleTest.finish();
});
document.exitFullscreen();
}
});
function start() {
parent = document.getElementById("parent");
child = document.getElementById("child");
addFullscreenChangeContinuation("enter", function() {
parent.requestPointerLock();
});
parent.requestFullscreen();
}
</script>
</body>
</html>