Skip to content

Commit

Permalink
Swap PointerEvent.deviceProperties with PointerEvent.persistentDeviceId
Browse files Browse the repository at this point in the history
Bring back a unique id on the base pointer event and remove
deviceProperties. Rather than deviceId, this will be called
persistentDeviceId.
Spec: w3c/pointerevents#495

Change-Id: Ia284adc60bc4030b69dbec89d0e37117fecf3f83
Bug: 330760871
  • Loading branch information
sahirv authored and chromium-wpt-export-bot committed Jun 24, 2024
1 parent d91a229 commit 8c5f788
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
</style>
<div id="logger" draggable="false"></div>
<div id="console"></div>
<!-- This test verifies that pointerEvent.deviceProperties.uniqueId is 0
<!-- This test verifies that pointerEvent.persistentDeviceId is 0
by default for a pointer with an invalid hardware id - in this case
a testdriver generated event, which does not support hardware id. -->
<script>
function CheckDeviceId(event) {
eventFired++;
assert_equals(event.deviceProperties.uniqueId, 0, "deviceId is 0");
assert_equals(event.persistentDeviceId, 0, "deviceId is 0");
}

window.addEventListener("pointerdown", CheckDeviceId, false);
Expand All @@ -41,5 +41,5 @@
await actions.send();

assert_true(eventFired == 2);
}, 'PointerEvent.deviceProperties.uniqueId');
}, 'PointerEvent.persistentDeviceId');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Tentative; contingent on merge of:
https://github.com/w3c/pointerevents/pull/495
This manual test validates the behavior of PointerEvent.deviceProperties.uniqueId.
This manual test validates the behavior of PointerEvent.persistentDeviceId.
Specifically, this test ensures that pointing devices get their own unique id, and
that the unique id is persistent over the session.
In order to run this test, it is necessary to have multiple pointing devices; such as a
pen and a mouse. Please follow the instructions exactly as written in order to ensure
the correct results are obtained.
-->
<title>DeviceProperties.uniqueId is unique for pointer events from different devices</title>
<title>persistentDeviceId is unique for pointer events from different devices</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
Expand Down Expand Up @@ -94,13 +94,10 @@ <h2>Instructions</h2>
setup({explicit_timeout: true, explicit_done: true});

function LogDeviceId(event, list) {
if (event.deviceProperties) {
const uniqueId = event.deviceProperties.uniqueId;
currentuniqueid.innerText = uniqueId ? uniqueId : "Unknown";
if (!uniqueId) {
return;
}
list.push(uniqueId);
if (event.persistentDeviceId) {
const persistentDeviceId = event.persistentDeviceId;
currentuniqueid.innerText = persistentDeviceId ? persistentDeviceId : "Unknown";
list.push(persistentDeviceId);
}
}

Expand All @@ -117,17 +114,17 @@ <h2>Instructions</h2>
let device2UniqueIds = new Set(device2Ids);

test(function () {
assert_greater_than(device1Ids.length, 1, "Events from Device 1 have uniqueIds.");
assert_equals(device1UniqueIds.size, 1, "Device 1 has a consistent uniqueId.");
}, "uniqueId is consistent for device 1");
assert_greater_than(device1Ids.length, 1, "Events from Device 1 have deviceIds.");
assert_equals(device1UniqueIds.size, 1, "Device 1 has a consistent deviceId.");
}, "deviceId is consistent for device 1");
test(function () {
assert_greater_than(device2Ids.length, 1, "Events from Device 2 have uniqueIds.");
assert_equals(device2UniqueIds.size, 1, "Device 2 has a consistent uniqueId.");
}, "uniqueId is consistent for device 2");
assert_greater_than(device2Ids.length, 1, "Events from Device 2 have deviceIds.");
assert_equals(device2UniqueIds.size, 1, "Device 2 has a consistent deviceId.");
}, "deviceId is consistent for device 2");
test(function () {
// Ensure the two sets are different.
assert_equals(device1UniqueIds.intersection(device2UniqueIds).size, 0, "Device 1 and 2 have different uniqueIds.");
}, "uniqueId is unique to device 1 and device 2");
assert_equals(device1UniqueIds.intersection(device2UniqueIds).size, 0, "Device 1 and 2 have different deviceIds.");
}, "deviceId is unique to device 1 and device 2");
done();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
<script src="/resources/testharnessreport.js"></script>
<div id="console"></div>

<!-- This test verifies that pointerEvent.deviceProperties.uniqueId
<!-- This test verifies that pointerEvent.persistentDeviceId
can be set via PointerEventInit. -->
<script>
const UNIQUE_ID = 1001;
const INVALID_UNIQUE_ID = 0;
const PERSISTENT_ID = 1001;
const INVALID_PERSISTENT_ID = 0;

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

promise_test(async () => {
if (!window.internals)
return;
var deviceProps = new DeviceProperties({
uniqueId: 1001
});
var deviceId = PERSISTENT_ID;
var downEvent = new PointerEvent("pointerdown",
{pointerId: 1,
bubbles: true,
Expand All @@ -31,9 +29,9 @@
width: 100,
height: 100,
isPrimary: true,
deviceProperties: deviceProps
persistentDeviceId: deviceId
});
CheckDeviceId(downEvent, UNIQUE_ID);
CheckDeviceId(downEvent, PERSISTENT_ID);
var moveEvent = new PointerEvent("pointermove",
{pointerId: 1,
bubbles: true,
Expand All @@ -42,9 +40,9 @@
width: 100,
height: 100,
isPrimary: true,
deviceProperties: deviceProps
persistentDeviceId: deviceId
});
CheckDeviceId(moveEvent, UNIQUE_ID);
CheckDeviceId(moveEvent, PERSISTENT_ID);
var upEvent = new PointerEvent("pointerup",
{pointerId: 1,
bubbles: true,
Expand All @@ -53,27 +51,10 @@
width: 100,
height: 100,
isPrimary: true,
deviceProperties: deviceProps
persistentDeviceId: deviceId
});
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');
CheckDeviceId(upEvent, PERSISTENT_ID);
}, 'PointerEvent.persistentDeviceId via PointerEventInit');

promise_test(async () => {
if (!window.internals)
Expand All @@ -87,6 +68,6 @@
height: 100,
isPrimary: true,
});
assert_equals(downEventEmptyProps.deviceProperties, null);
}, 'No deviceProperties in PointerEventInit');
assert_equals(downEventEmptyProps.persistentDeviceId, INVALID_PERSISTENT_ID);
}, 'No persistentDeviceId in PointerEventInit');
</script>

0 comments on commit 8c5f788

Please sign in to comment.