Commit 92650052 authored by chongz's avatar chongz Committed by Commit bot

[PointerLock] Add null check before dispatching click event

BUG=706802

Review-Url: https://codereview.chromium.org/2846993002
Cr-Commit-Position: refs/heads/master@{#469510}
parent 74c96e84
<!DOCTYPE html>
<meta charset="utf-8">
<title>Remove PointerLock target on mouseup</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<p>Click anywhere to run the test. If a "PASS" result appears the test passes, otherwise it fails</p>
<div id="target"></div>
<script>
async_test(t => {
const target = document.getElementById('target');
document.addEventListener('mousedown', t.step_func(() => {
target.requestPointerLock();
document.addEventListener('mouseup', t.step_func(() => {
target.remove();
assert_true(document.pointerLockElement === null, 'Pointer lock exited!');
t.done();
}));
}));
})
</script>
// This file contains the commonly used functions in pointerlock tests.
const boundaryOffset = 2;
function scrollPageIfNeeded(targetSelector, targetDocument) {
const target = targetDocument.querySelector(targetSelector);
const targetRect = target.getBoundingClientRect();
if (targetRect.top < 0 || targetRect.left < 0 || targetRect.bottom > window.innerHeight || targetRect.right > window.innerWidth)
window.scrollTo(targetRect.left, targetRect.top);
}
function mouseClickInTarget(targetSelector, targetFrame, button) {
let targetDocument = document;
let frameLeft = 0;
let frameTop = 0;
if (button === undefined) {
button = 'left';
}
if (targetFrame !== undefined) {
targetDocument = targetFrame.contentDocument;
const frameRect = targetFrame.getBoundingClientRect();
frameLeft = frameRect.left;
frameTop = frameRect.top;
}
return new Promise(function(resolve, reject) {
if (window.chrome && chrome.gpuBenchmarking) {
scrollPageIfNeeded(targetSelector, targetDocument);
const target = targetDocument.querySelector(targetSelector);
const targetRect = target.getBoundingClientRect();
const xPosition = frameLeft + targetRect.left + boundaryOffset;
const yPosition = frameTop + targetRect.top + boundaryOffset;
chrome.gpuBenchmarking.pointerActionSequence(
[{
source: 'mouse',
actions: [
{name: 'pointerMove', x: xPosition, y: yPosition},
{name: 'pointerDown', x: xPosition, y: yPosition, button: button},
{name: 'pointerUp', button: button}
]
}],
resolve);
} else {
reject();
}
});
}
{
const pointerlock_automation = async_test("PointerLock Automation");
// Defined in every test and should return a promise that gets resolved when input is finished.
inject_input().then(function() {
pointerlock_automation.done();
});
}
importAutomationScript('/pointerlock/pointerlock_common_input.js');
function inject_input() {
return mouseClickInTarget('#target');
}
......@@ -117,7 +117,8 @@
// Fullscreen tests all use the same automation script.
src = automationPath + '/fullscreen/auto-click.js';
} else if (pathAndBase.startsWith('/pointerevents/')
|| pathAndBase.startsWith('/uievents/')) {
|| pathAndBase.startsWith('/uievents/')
|| pathAndBase.startsWith('/pointerlock/')) {
// Per-test automation scripts.
src = automationPath + pathAndBase + '-automation.js';
} else {
......
......@@ -140,6 +140,10 @@ void PointerLockController::DispatchLockedMouseEvent(
element_->DispatchMouseEvent(event, event_type, event.click_count);
// Event handlers may remove element.
if (!element_)
return;
// Create click events
if (event_type == EventTypeNames::mouseup) {
element_->DispatchMouseEvent(event, EventTypeNames::click,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment