Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PointerEvent.deviceProperties #45420

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<!--
Tentative; contingent on merge of:
https://github.com/w3c/pointerevents/pull/495
-->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<style>
div {
user-select: none; // Prevents text selection on drag.
}
</style>
<div id="logger" draggable="false"></div>
<div id="console"></div>
<!-- This test verifies that if the PointerEventDeviceId flag is enabled,
pointerEvent.deviceProperties.uniqueId is -1. If not, it is undefined. -->
<script>
function CheckDeviceId(event) {
eventFired++;
assert_equals(event.deviceProperties.uniqueId, -1, "deviceId is -1");
}

window.addEventListener("pointerdown", CheckDeviceId, false);
window.addEventListener("pointermove", CheckDeviceId, false);

promise_test(async () => {
if (!window.internals)
return;
eventFired = 0;
let actions = new test_driver.Actions()
.addPointer("TestPointer", "pen")
.pointerDown()
.pointerMove(100, 100)
.pointerUp();

await actions.send();

assert_true(eventFired == 2);
}, 'PointerEvent.deviceProperties.uniqueId');
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<!--
Tentative; contingent on merge of:
https://github.com/w3c/pointerevents/pull/495
-->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="console"></div>

<!-- This test verifies that if the kPointerEventDeviceId flag is enabled,
pointerEvent.deviceProperties.uniqueId can be set via PointerEventInit. If not, it is
undefined. -->
<script>
const UNIQUE_ID = 1001;
const INVALID_UNIQUE_ID = -1;

function CheckDeviceId(event, uniqueId) {
assert_equals(event.deviceProperties.uniqueId, uniqueId, "uniqueId is populated");
}

promise_test(async () => {
if (!window.internals)
return;
var deviceProps = new DeviceProperties({
uniqueId: 1001
});
var downEvent = new PointerEvent("pointerdown",
{pointerId: 1,
bubbles: true,
cancelable: true,
pointerType: "pen",
width: 100,
height: 100,
isPrimary: true,
deviceProperties: deviceProps
});
CheckDeviceId(downEvent, UNIQUE_ID);
var moveEvent = new PointerEvent("pointermove",
{pointerId: 1,
bubbles: true,
cancelable: true,
pointerType: "pen",
width: 100,
height: 100,
isPrimary: true,
deviceProperties: deviceProps
});
CheckDeviceId(moveEvent, UNIQUE_ID);
var upEvent = new PointerEvent("pointerup",
{pointerId: 1,
bubbles: true,
cancelable: true,
pointerType: "pen",
width: 100,
height: 100,
isPrimary: true,
deviceProperties: deviceProps
});
CheckDeviceId(upEvent, UNIQUE_ID);
}, 'PointerEvent.deviceProperties via DevicePropertiesInit');

promise_test(async () => {
if (!window.internals)
return;
var emptyDeviceProps = new DeviceProperties({});
var downEventEmptyProps = new PointerEvent("pointerdown",
{pointerId: 1,
bubbles: true,
cancelable: true,
pointerType: "pen",
width: 100,
height: 100,
isPrimary: true,
deviceProperties: emptyDeviceProps
});
CheckDeviceId(downEventEmptyProps, INVALID_UNIQUE_ID);
}, 'PointerEvent.deviceProperties via empty DevicePropertiesInit');

promise_test(async () => {
if (!window.internals)
return;
var downEventEmptyProps = new PointerEvent("pointerdown",
{pointerId: 1,
bubbles: true,
cancelable: true,
pointerType: "pen",
width: 100,
height: 100,
isPrimary: true,
});
CheckDeviceId(downEventEmptyProps, INVALID_UNIQUE_ID);
}, 'No deviceProperties in PointerEventInit');
</script>