Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(interaction-harness): read a WebKit lift at its touchend (#10508)

Christopher Chedeau8e997b5daa45
diff --git a/internal/interaction-harness/src/touch.pacing.test.ts b/internal/interaction-harness/src/touch.pacing.test.ts
index 5d74e6692f..30c6a59e92 100644
--- a/internal/interaction-harness/src/touch.pacing.test.ts
+++ b/internal/interaction-harness/src/touch.pacing.test.ts
@@ -357,20 +357,68 @@ describe("the release a paced play's page reads, as Core's velocity tracker read
});
describe('touchArrivalsFrom', () => {
- it('gives each step one arrival: the earliest stamp of its pointer and touch events, and the latest handling', () => {
+ it('gives each step one arrival: a move at its pointer event, a touch-down and a lift at their touch events, and the latest handling', () => {
expect(
touchArrivalsFrom({
- eventTypes: ['pointerdown', 'touchstart', 'pointermove', 'touchmove'],
- pointerTypes: ['touch', '', 'touch', ''],
- stamps: [23, 24, 39, 100],
- handledAt: [23, 24, 100, 100],
+ eventTypes: [
+ 'pointerdown',
+ 'touchstart',
+ 'pointermove',
+ 'touchmove',
+ 'pointerup',
+ 'touchend',
+ ],
+ pointerTypes: ['touch', '', 'touch', '', 'touch', ''],
+ stamps: [23, 24, 39, 100, 116, 140],
+ handledAt: [23, 24, 100, 100, 140, 140],
}),
).toEqual([
- {stamp: 23, handledAt: 24},
- {stamp: 39, handledAt: 100},
+ {stamp: 24, firstStamp: 23, handledAt: 24},
+ {stamp: 39, firstStamp: 39, handledAt: 100},
+ {stamp: 140, firstStamp: 116, handledAt: 140},
]);
});
+ it("reads a lift at its touchend, which the page's pointerup listener held: the page's rest", () => {
+ // How WebKit recorded a Carousel flick on a loaded runner. The pointerup
+ // came 4 ms after the last move. Its listeners finished 49 ms later, when
+ // WebKit stamped the touchend, and the gesture host reads the lift there.
+ const record = {
+ eventTypes: [
+ 'pointerdown',
+ 'touchstart',
+ ...[0, 1, 2, 3, 4].flatMap(() => ['pointermove', 'touchmove']),
+ 'pointerup',
+ 'touchend',
+ ],
+ pointerTypes: [
+ 'touch',
+ '',
+ ...[0, 1, 2, 3, 4].flatMap(() => ['touch', '']),
+ 'touch',
+ '',
+ ],
+ stamps: [
+ 3097, 3099, 3116, 3121, 3146, 3149, 3180, 3185, 3246, 3255, 3294, 3295,
+ 3298, 3347,
+ ],
+ handledAt: [
+ 3099, 3102, 3121, 3121, 3149, 3150, 3185, 3185, 3255, 3255, 3295, 3295,
+ 3347, 3355,
+ ],
+ };
+ const arrivals = touchArrivalsFrom(record);
+ expect(arrivals.at(-1)).toEqual({
+ stamp: 3347,
+ firstStamp: 3298,
+ handledAt: 3355,
+ });
+ const fault = touchPacingFault(FLICK, arrivals);
+ expect(fault?.kind).toBe('rest');
+ // The lift's own pointerup listener held its touchend 49 ms.
+ expect(fault?.heldByPage).toEqual({gapMs: 53, handlingMs: 49});
+ });
+
it("leaves a mouse's pointer event out of a touch step", () => {
expect(
touchArrivalsFrom({
@@ -379,7 +427,7 @@ describe('touchArrivalsFrom', () => {
stamps: [5, 39, 39],
handledAt: [90, 40, 40],
}),
- ).toEqual([{stamp: 39, handledAt: 40}]);
+ ).toEqual([{stamp: 39, firstStamp: 39, handledAt: 40}]);
});
it("reads a page whose pointer listener held each move as the page's rest, which the touch events alone hide", () => {
diff --git a/internal/interaction-harness/src/touch.ts b/internal/interaction-harness/src/touch.ts
index c9febc3381..3020e918b6 100644
--- a/internal/interaction-harness/src/touch.ts
+++ b/internal/interaction-harness/src/touch.ts
@@ -238,8 +238,18 @@ export function pacedDeadline(
/** What the page saw of one touch event of a paced play. */
export interface TouchArrival {
- /** The event's own `timeStamp`: when it reached the page, in WebKit. */
+ /**
+ * When the page's gesture host read the step, in WebKit. A move reads at
+ * its pointer event's `timeStamp`, a touch-down or a lift at its touch
+ * event's.
+ */
readonly stamp: number;
+ /**
+ * The step's earliest `timeStamp`, its pointer event's; `stamp` when the
+ * step had none. A touch-down or a lift reads later than this when the
+ * page's own pointer listeners held its touch event.
+ */
+ readonly firstStamp?: number;
/**
* When the page's own touch and pointer listeners had finished with it;
* NaN unseen.
@@ -474,13 +484,19 @@ export function touchPacingFault(
const scriptedGapsMs = span.map(i => steps[i].t - steps[i - 1].t);
let heldByPage: TouchPacingFault['heldByPage'] = null;
span.forEach((i, k) => {
- const handlingMs = arrivals[i - 1].handledAt - arrivals[i - 1].stamp;
- const held =
- Number.isFinite(handlingMs) &&
- handlingMs > scriptedGapsMs[k] &&
- handlingMs + HELD_BACK_MS >= gapsMs[k] - scriptedGapsMs[k];
- if (held && (heldByPage == null || handlingMs > heldByPage.handlingMs)) {
- heldByPage = {gapMs: gapsMs[k], handlingMs};
+ // The event before held this one back, or this step's own pointer
+ // listeners held its touch event (a lift read at its touchend).
+ const before = arrivals[i - 1].handledAt - arrivals[i - 1].stamp;
+ const own =
+ arrivals[i].stamp - (arrivals[i].firstStamp ?? arrivals[i].stamp);
+ for (const handlingMs of [before, own]) {
+ const held =
+ Number.isFinite(handlingMs) &&
+ handlingMs > scriptedGapsMs[k] &&
+ handlingMs + HELD_BACK_MS >= gapsMs[k] - scriptedGapsMs[k];
+ if (held && (heldByPage == null || handlingMs > heldByPage.handlingMs)) {
+ heldByPage = {gapMs: gapsMs[k], handlingMs};
+ }
}
});
return {
@@ -793,8 +809,10 @@ const TOUCH_TYPES = [
* One arrival for each touch event a probe recorded, in dispatch order. WebKit
* dispatches each step's pointer events just before its touch event, and
* stamps the touch event only once the page's pointer listeners are done.
- * So an arrival takes the earliest stamp of its step's events, when a
- * gesture host samples the finger, and the latest handling mark of them.
+ * Core's gesture host reads a finger's moves from its pointer events, and its
+ * touch-down and lift from its touch events. So a move arrives at the
+ * earliest stamp of its step, and a touch-down or a lift at its touch
+ * event's own stamp. Each takes the latest handling mark of its step.
*/
export function touchArrivalsFrom(record: {
readonly eventTypes: readonly string[];
@@ -816,7 +834,11 @@ export function touchArrivalsFrom(record: {
handledAt = Number.isNaN(handledAt) ? mark : Math.max(handledAt, mark);
}
if (type.startsWith('touch')) {
- arrivals.push({stamp, handledAt});
+ arrivals.push({
+ stamp: type === 'touchmove' ? stamp : record.stamps[i],
+ firstStamp: stamp,
+ handledAt,
+ });
stamp = Number.POSITIVE_INFINITY;
handledAt = Number.NaN;
}