Files
sousa-gecko/dom/performance/tests/test_performance_interactionid_pointerdown.html
T
Nazım Can Altınova b177392d20 Bug 1969825 - Add a mochitest for pointerdown without an pointerup/pointercancel/contextmenu r=sefeng
I initially tried to write a WPT test for this. But I failed to do so
because the test driver for WPT doesn't accept a pointerdown without any
matching pointer events. So either it just doesn't fire a pointerdown or
it fires pointerup with it. So that's why I chose to write one in
mochitest instead.

The test first fires a pointerdown with no up, and then fires another
pointerdown with an up instead. So the second pointerdown should clear
the old one and set its interactionId to zero. So first one should have
interactionId of zero and the second should have a non-zero
interactionId.

Differential Revision: https://phabricator.services.mozilla.com/D252110
2025-06-02 20:58:35 +00:00

61 lines
2.1 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<title>Test PerformanceEventTiming interactionId for pointerdown without a pointerup</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
<div id="target">Click me</div>
<script>
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async function() {
const target = document.getElementById("target");
let observedEntries = [];
const events = ['pointerdown'];
const observerPromise = new Promise(resolve => {
new PerformanceObserver((entryList) => {
observedEntries = observedEntries.concat(
entryList.getEntries().filter(entry => events.includes(entry.name))
);
if (observedEntries.length >= 2) {
resolve();
}
}).observe({ type: "event", buffered: true });
});
// Block for ~110ms during pointerdown, the threshold is 104ms for event timing entries.
document.getElementById("target").addEventListener("pointerdown", () => {
const start = performance.now();
while (performance.now() - start < 110) {
// Busy loop to block rendering
}
});
// First: pointerdown with no pointerup.
await synthesizeMouseAtCenter(target, { type: "mousedown", button: 0 });
// Second: pointerdown with pointerup.
await synthesizeMouseAtCenter(target, { type: "mousedown", button: 0 });
await synthesizeMouseAtCenter(target, { type: "mouseup", button: 0 });
// Wait for entries to flush.
await observerPromise;
ok(observedEntries.length >= 2, `Expected at least 2 entries, got ${observedEntries.length}`);
const first = observedEntries[0];
const second = observedEntries[1];
ok(first.name === "pointerdown", "First should be pointerdown");
ok(second.name === "pointerdown", "Second should be pointerdown");
is(first.interactionId, 0, "First pointerdown should have interactionId 0");
ok(second.interactionId > 0, "Second pointerdown should have non-zero interactionId");
SimpleTest.finish();
});
</script>