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 pointerup (#10585)

Christopher Chedeaubb3a4b2ae639
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index 6aa7c4360a..86eeb995e2 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -365,6 +365,35 @@ test.describe('touch input', () => {
);
});
+ test('a lift whose page pointerup listener holds its touchend reads at the pointerup, as the gesture host does: the paced flick passes', async ({
+ page,
+ browserName,
+ }) => {
+ test.skip(
+ browserName !== 'webkit',
+ 'only WebKit stamps a touch when it arrives; Chromium carries the scripted times',
+ );
+ // The lift's pointerup listener holds the main thread 50 ms, as a busy
+ // app's can. WebKit stamps the touchend after it, but the gesture host
+ // reads the lift at the pointerup, paired with the moves.
+ await page.route('http://pointerup-stalling-page.test/', route =>
+ route.fulfill({
+ contentType: 'text/html',
+ body: '<!doctype html><body style="margin:0;height:3000px;touch-action:none"><script>addEventListener("pointerup",()=>{const end=performance.now()+50;while(performance.now()<end){}});</script>',
+ }),
+ );
+ await page.goto('http://pointerup-stalling-page.test/');
+ const driver = await touchDriver(page);
+ const played = await driver.play(
+ flick(
+ {x: 200, y: 400},
+ {velocity: {x: 0, y: -1500}, durationMs: 80, hz: 120},
+ ),
+ {pacing: 'spacing'},
+ );
+ expect(played.at(-1)?.release).toBeDefined();
+ });
+
test("a page whose touch listener holds its main thread changes a paced flick's release itself: TouchPageStallError, never the runner's", async ({
page,
browserName,
@@ -402,14 +431,14 @@ test.describe('touch input', () => {
/**
* A flick up a page that takes every touch, its lift right after its last
- * move. The page logs each move at its pointer event and the lift at its
- * touch event, where Core's gesture host reads them.
+ * move. The page logs each move and the lift at its pointer event, where
+ * Core's gesture host and the play read them.
*/
async function liftStallPage(page: Page) {
await page.route('http://lift-stall.test/', route =>
route.fulfill({
contentType: 'text/html',
- body: '<!doctype html><body style="margin:0;height:3000px;touch-action:none"><script>window.touches=[];for(const type of ["pointermove","touchend"])addEventListener(type,e=>touches.push([type,e.timeStamp]),{passive:true})</script>',
+ body: '<!doctype html><body style="margin:0;height:3000px;touch-action:none"><script>window.touches=[];for(const type of ["pointermove","pointerup"])addEventListener(type,e=>touches.push([type,e.timeStamp]),{passive:true})</script>',
}),
);
await page.goto('http://lift-stall.test/');
@@ -430,7 +459,7 @@ test.describe('touch input', () => {
const pageLiftGap = () =>
page.evaluate(() => {
const {touches} = window as unknown as {touches: [string, number][]};
- const lift = touches.findIndex(([type]) => type === 'touchend');
+ const lift = touches.findIndex(([type]) => type === 'pointerup');
return touches[lift][1] - touches[lift - 1][1];
});
return {driver: await touchDriver(page), script, slowRead, pageLiftGap};
diff --git a/internal/interaction-harness/src/touch.pacing.test.ts b/internal/interaction-harness/src/touch.pacing.test.ts
index 2c9d111340..15d2b83b2a 100644
--- a/internal/interaction-harness/src/touch.pacing.test.ts
+++ b/internal/interaction-harness/src/touch.pacing.test.ts
@@ -365,7 +365,7 @@ describe("the release a paced play's page reads, as Core's velocity tracker read
});
describe('touchArrivalsFrom', () => {
- 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', () => {
+ it('gives each step one arrival: a move and a lift at their pointer events, a touch-down at its touch event, and the latest handling', () => {
expect(
touchArrivalsFrom({
eventTypes: [
@@ -383,14 +383,26 @@ describe('touchArrivalsFrom', () => {
).toEqual([
{stamp: 24, firstStamp: 23, handledAt: 24},
{stamp: 39, firstStamp: 39, handledAt: 100},
- {stamp: 140, firstStamp: 116, handledAt: 140},
+ {stamp: 116, firstStamp: 116, handledAt: 140},
]);
});
- it("reads a lift at its touchend, which the page's pointerup listener held: the page's rest", () => {
+ it('reads a lift with no pointer event at its touchend', () => {
+ expect(
+ touchArrivalsFrom({
+ eventTypes: ['touchstart', 'touchmove', 'touchend'],
+ pointerTypes: ['', '', ''],
+ stamps: [24, 39, 140],
+ handledAt: [24, 39, 140],
+ }).at(-1),
+ ).toEqual({stamp: 140, firstStamp: 140, handledAt: 140});
+ });
+
+ it("reads a lift at its pointerup, as the gesture host does: a pointerup listener that holds the touchend is not 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.
+ // WebKit stamped the touchend. The gesture host reads the lift at the
+ // pointerup, paired with the moves.
const record = {
eventTypes: [
'pointerdown',
@@ -417,14 +429,11 @@ describe('touchArrivalsFrom', () => {
};
const arrivals = touchArrivalsFrom(record);
expect(arrivals.at(-1)).toEqual({
- stamp: 3347,
+ stamp: 3298,
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});
+ expect(touchPacingFault(FLICK, arrivals)).toBeNull();
});
it("leaves a mouse's pointer event out of a touch step", () => {
diff --git a/internal/interaction-harness/src/touch.ts b/internal/interaction-harness/src/touch.ts
index ee5c57faa7..134b34b9ad 100644
--- a/internal/interaction-harness/src/touch.ts
+++ b/internal/interaction-harness/src/touch.ts
@@ -274,15 +274,15 @@ export function pacedDeadline(
/** What the page saw of one touch event of a paced play. */
export interface TouchArrival {
/**
- * 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.
+ * When the page's gesture host read the step, in WebKit. A move or a lift
+ * reads at its pointer event's `timeStamp`, a touch-down at its touch
+ * event's. A step with no pointer event reads 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.
+ * step had none. A touch-down reads later than this when the page's own
+ * pointer listeners held its touch event.
*/
readonly firstStamp?: number;
/**
@@ -714,9 +714,9 @@ export class TouchPageStallError extends Error {
/**
* A play's lift reached the page more than the stillness interval after its
- * finger's last move, where the script throws. The play's own `onEvent` ran
- * long enough to carry the gap past that interval by itself. Page work there
- * holds the next event back by a round trip. A loaded runner can stretch the
+ * finger's last move, where the script throws. The scripted gap plus the time
+ * the play's own `onEvent` ran passes that interval. Page work there holds the
+ * next event back by a round trip. A loaded runner can stretch the
* gap more, and the error still names `onEvent`. On a page that stamps
* touches on arrival (WebKit), the page then reads a resting finger and
* releases at 0.
@@ -1019,10 +1019,11 @@ 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.
- * 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.
+ * Core's gesture host reads a finger's moves from its pointer events, and
+ * its lift from the pointerup paired with them. It reads the touch-down from
+ * its touch event. So a move or a lift arrives at the earliest stamp of its
+ * step, and a touch-down at its touch event's own stamp. Each takes the
+ * latest handling mark of its step.
*/
export function touchArrivalsFrom(record: {
readonly eventTypes: readonly string[];
@@ -1045,7 +1046,7 @@ export function touchArrivalsFrom(record: {
}
if (type.startsWith('touch')) {
arrivals.push({
- stamp: type === 'touchmove' ? stamp : record.stamps[i],
+ stamp: type === 'touchstart' ? record.stamps[i] : stamp,
firstStamp: stamp,
handledAt,
});
diff --git a/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts b/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts
index e1bb35c5f5..cce3b63aab 100644
--- a/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts
+++ b/packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts
@@ -678,6 +678,31 @@ test('callbacks: the new page once the settle is moving, the settle when the tra
expect(await log(page)).toEqual(['index:2:drag:moving', 'settle:2:1']);
});
+test('a flick pages on when a page pointerup listener holds its touchend: the lift is read where the moves were', async ({
+ page,
+}) => {
+ const {driver} = await open(page);
+ // A busy app's pointerup listener: WebKit stamps the touchend after it.
+ await page.evaluate(() => {
+ addEventListener('pointerup', () => {
+ const end = performance.now() + 50;
+ while (performance.now() < end) {
+ // The listener's own work.
+ }
+ });
+ });
+ await driver.play(
+ flick(
+ {x: 320, y: 200},
+ {velocity: {x: -1500, y: 0}, durationMs: 80, hz: 120},
+ ),
+ {pacing: 'spacing'},
+ );
+ await expect
+ .poll(async () => page.evaluate(() => window.pager.index))
+ .toBe(2);
+});
+
test('a flick pages exactly one page, and the settle starts from the release velocity', async ({
page,
browserName,
diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
index 667a7c728d..b0a3a35d5b 100644
--- a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
@@ -943,10 +943,25 @@ test('a fast swipe that rests before the lift springs back: a still finger never
expect(Math.abs(await translateX(top))).toBeLessThan(0.5);
});
-test('a flick from near the edge finishes the pop', async ({page}) => {
+/**
+ * A flick from near the leading edge. Given `busyLiftMs`, a page pointerup
+ * listener works that long, as a busy app's: WebKit stamps the lift's
+ * touchend after it. The pop must finish.
+ */
+async function flickFromTheEdge(page: Page, busyLiftMs?: number) {
const {driver, left, topTitle} = await openStack(page, 'pushed', {
standalone: true,
});
+ if (busyLiftMs != null) {
+ await page.evaluate(spin => {
+ addEventListener('pointerup', () => {
+ const end = performance.now() + spin;
+ while (performance.now() < end) {
+ // The listener's own work.
+ }
+ });
+ }, busyLiftMs);
+ }
// ~60 px of travel at ~1200 px/s: p + 0.35·v is well past half.
const script = flick({x: left + 6, y: 400}, {velocity: {x: 1200, y: 0}});
const run = await armInputRun(page, TOUCH_INPUT_TYPES);
@@ -981,6 +996,16 @@ test('a flick from near the edge finishes the pop', async ({page}) => {
}
throw error;
}
+}
+
+test('a flick from near the edge finishes the pop', async ({page}) => {
+ await flickFromTheEdge(page);
+});
+
+test('a flick from near the edge finishes the pop when a page pointerup listener holds its lift', async ({
+ page,
+}) => {
+ await flickFromTheEdge(page, 50);
});
test('in a browser tab the leading screen edge stays the browser’s', async ({