Source code

Revision control

Copy as Markdown

Other Tools

<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1672330</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/paint_listener.js"></script>
<script src="/tests/gfx/layers/apz/test/mochitest/apz_test_utils.js"></script>
<script src="pointerlock_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
#target {
width: 100px;
height: 100px;
background-color: green;
}
iframe {
width: 400px;
height: 300px;
border: 1px solid blue;
}
</style>
</head>
<body>
<div id="target"></div>
<pre id="test">
<script type="text/javascript">
/**
* Test for Bug 1672330
*/
SimpleTest.waitForExplicitFinish();
async function requestPointerLock(aElement, aExpectError = false) {
let doc = aElement.ownerDocument;
let waitForPointerLockEvent = function() {
return new Promise((aResolve) => {
let eventHandler = function(aEvent) {
is(aEvent.type, aExpectError ? 'pointerlockerror' : 'pointerlockchange',
`got ${aEvent.type}`);
doc.removeEventListener('pointerlockchange', eventHandler);
doc.removeEventListener('pointerlockerror', eventHandler);
aResolve();
};
doc.addEventListener('pointerlockchange', eventHandler);
doc.addEventListener('pointerlockerror', eventHandler);
});
};
aElement.requestPointerLock();
await waitForPointerLockEvent();
is(doc.pointerLockElement, aExpectError ? null : aElement, "target pointer locked");
}
async function start() {
await waitUntilApzStable();
let target = document.getElementById("target");
SpecialPowers.wrap(document).clearUserGestureActivation();
// Pointer lock request should be rejected due to the lack of user gesture.
await requestPointerLock(target, true);
// Test mouse event should not be dispatched to document.
document.addEventListener("mousemove", function(e) {
ok(false, "Got unexpected mousemove");
});
info("test sending mouse event to iframe");
let iframe = document.querySelector("iframe");
synthesizeMouse(iframe, 10, 10, { type: "mousemove" });
await new Promise(resolve => { SimpleTest.executeSoon(resolve); });
info("test sending mouse event to another window");
await new Promise((aResolve) => {
let win = window.open("iframe_differentDOM.html");
win.addEventListener("load", async function() {
info("win onload");
await waitUntilApzStable();
synthesizeMouse(win.document.body, 10, 10, { type: "mousemove" }, win);
win.close();
aResolve();
});
});
await new Promise(resolve => { SimpleTest.executeSoon(resolve); });
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>