Automatic update from web-platform-tests Add WPT tests to increase PointerLock coverage New tests in wpt/pointerlock/: - pointerlock_all_mouse_events_to_locktarget: verifies that mouse events are routed to the lock target element and not the element under the cursor (spec §2.1). - pointerlock_suppress_mouse_boundary_events_when_locked.html: verifies that mouse boundary events (out, leave, etc) do not fire while the pointer is locked (spec §2.1). - pointerlock_target_change: verifies that calling requestPointerLock() on a different element while already locked changes the lock target, fires pointerlockchange, and that subsequent pointermove events are dispatched to the new lock target (spec §3 step 6.2, plus Pointer Events routing during lock). - pointerlock_api_behavior: verifies miscellaneous behaviours of calling pointerlock functions. Has two tests: (a) exitPointerLock() is a no-op when not locked, and (b) the pointerlockchange event fired by the UA matches spec (does not bubble, is not cancelable, targets the document) (spec §2.3, §3, §4). Replaced/strengthened test in wpt/pointerlock/: - pointerlock_remove_target: replaces the previous manual-style test with an automated version that verifies pointer lock exits when the locked element is removed from the DOM (spec §8). The pointerlock spec is defined in https://w3c.github.io/pointerlock/ Bug: 521748207 Change-Id: I0ec1359afb99bab94aa8d4bf9fb10a40075b58bd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7682773 Commit-Queue: Gaston Rodriguez <gastonr@microsoft.com> Reviewed-by: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/main@{#1648623} -- wpt-commits: f013fa8e4862dca55e7ed285374fe2bdee842506 wpt-pr: 60707
58 lines
1.9 KiB
JavaScript
58 lines
1.9 KiB
JavaScript
/* Requests a pointer lock on `element` and waits for the resulting
|
|
* 'pointerlockchange' event.
|
|
* @param {Element} element - The element to lock the pointer to.
|
|
* @param {boolean} provideTransientActivation - If true, a synthetic click is
|
|
* performed on `element` first to satisfy the user activation requirement.
|
|
* @returns {Event} The pointerlockchange Event object.
|
|
*/
|
|
async function lockPointerAndWaitForEvent(element, provideTransientActivation) {
|
|
assert_not_equals(element, null, "element can't be null");
|
|
if (provideTransientActivation) {
|
|
// Make a gesture to provide transient activation so that the UA
|
|
// will allow us to acquire the pointer lock.
|
|
await new test_driver.Actions()
|
|
.pointerMove(0, 0, {
|
|
origin: element
|
|
})
|
|
.pointerDown()
|
|
.pointerUp()
|
|
.send();
|
|
}
|
|
var lockEvent = null;
|
|
var lockPromise = new Promise(resolve => {
|
|
document.addEventListener('pointerlockchange', function(e) {
|
|
lockEvent = e;
|
|
resolve();
|
|
}, {
|
|
once: true
|
|
});
|
|
});
|
|
await element.requestPointerLock();
|
|
await lockPromise;
|
|
assert_equals(document.pointerLockElement, element,
|
|
`document.pointerLockElement should be ${element}.`);
|
|
return lockEvent;
|
|
}
|
|
|
|
/* Calls document.exitPointerLock() and waits for the resulting
|
|
* 'pointerlockchange' event. Asserts that document.pointerLockElement is
|
|
* null afterwards.
|
|
* @returns {Event} The pointerlockchange Event object.
|
|
*/
|
|
async function unlockPointerAndWaitForEvent() {
|
|
var unlockEvent = null;
|
|
var unlockPromise = new Promise(resolve => {
|
|
document.addEventListener('pointerlockchange', function(e) {
|
|
unlockEvent = e;
|
|
resolve();
|
|
}, {
|
|
once: true
|
|
});
|
|
});
|
|
document.exitPointerLock();
|
|
await unlockPromise;
|
|
assert_equals(document.pointerLockElement, null,
|
|
"document.pointerLockElement should be null.");
|
|
return unlockEvent;
|
|
}
|