An open source design system that's fully customizable and agent ready
TypeScript
test(interaction-harness): a lift stall comes before a pacing error (#10530)
Christopher Chedeau7a1c0d6488d0
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.mdindex 345bd8fa32..f2176327e7 100644--- a/internal/interaction-harness/README.md+++ b/internal/interaction-harness/README.md@@ -553,9 +553,10 @@ arrives. So a lift that reaches the page past the 40 ms stillness intervalafter its finger's last move reads as a resting finger. The page releases itat 0. Every WebKit play reads its release from the page's own stamps, howeverit is paced, and fails by name when the page's release is not the script's.-The error is `TouchLiftStallError` when `onEvent` ran for the lift gap's-excess. Record what the page did in a listener of its own, or let the script-rest before the lift. A runner too loaded to dispatch in time stretches a+The error is `TouchLiftStallError` when `onEvent` alone carries the scripted+gap past the stillness interval, however much a loaded runner stretched it.+Record what the page did in a listener of its own, or let the script rest+before the lift. A runner too loaded to dispatch in time stretches agesture the same way, and the play fails with `TouchPacingError`. A play whoseproof reads no release from the lift, such as a pinch's end, passes`releaseUnread`.diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.tsindex 53006e8136..14e84f65e6 100644--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts@@ -86,6 +86,7 @@ import {holdInputUntil,installInputLog,type InputRecord,+ type PlayOptions,installLongTaskLog,installPageFreeze,installTimerGate,@@ -399,12 +400,16 @@ test.describe('touch input', () => {);});- /** A flick up a page that takes every touch, its lift right after its last move. */+ /**+ * 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.+ */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 ["touchmove","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","touchend"])addEventListener(type,e=>touches.push([type,e.timeStamp]),{passive:true})</script>',}),);await page.goto('http://lift-stall.test/');@@ -461,6 +466,55 @@ test.describe('touch input', () => {await driver.play(script, {onEvent: slowRead, releaseUnread: true});});+ test("a lift stall is named before the page's stall that stretched the lift gap further; with a quick onEvent the page's stall is named", async ({+ page,+ browserName,+ }) => {+ test.skip(+ browserName !== 'webkit',+ 'only WebKit stamps a touch when it arrives; Chromium carries the scripted times',+ );+ const {driver, script} = await liftStallPage(page);+ const moves = toTouchEvents(script).filter(+ step => step.type === 'touchMove',+ ).length;+ const lastMove = toTouchEvents(script).length - 2;+ // The page's own listener holds the last move 100 ms, so WebKit hands+ // the page the lift only after that.+ await page.evaluate(count => {+ let seen = 0;+ addEventListener(+ 'touchmove',+ () => {+ seen += 1;+ if (seen % count === 0) {+ const end = performance.now() + 100;+ while (performance.now() < end) {+ // the page is busy+ }+ }+ },+ {passive: true},+ );+ }, moves);+ // onEvent waits 60 ms on the runner's own timer at the last move: alone,+ // it carries the lift past the stillness interval.+ const runnerWait = async (_: unknown, index: number) => {+ if (index === lastMove) {+ await new Promise(resolve => setTimeout(resolve, 60));+ }+ };+ const outcome = (onEvent: PlayOptions['onEvent']) =>+ driver.play(script, {onEvent}).then(+ () => 'resolved',+ (error: unknown) => error,+ );+ const stalled = await outcome(runnerWait);+ expect(stalled, String(stalled)).toBeInstanceOf(TouchLiftStallError);+ const held = await outcome(() => {});+ expect(held, String(held)).toBeInstanceOf(TouchPageStallError);+ });+test('a default-paced play whose page holds its last move fails by name: TouchPageStallError, where the page stamps touches on arrival', async ({page,browserName,diff --git a/internal/interaction-harness/src/touch.pacing.test.ts b/internal/interaction-harness/src/touch.pacing.test.tsindex 30c6a59e92..7583b4d0e1 100644--- a/internal/interaction-harness/src/touch.pacing.test.ts+++ b/internal/interaction-harness/src/touch.pacing.test.ts@@ -32,8 +32,11 @@ import {touchArrivalsFrom,TOUCH_STILLNESS_MS,touchPacingFault,+ touchPlayError,+ TouchLiftStallError,TouchPacingError,TouchPageStallError,+ liftStallError,type TouchArrival,type TouchPacing,} from './touch';@@ -509,3 +512,72 @@ describe('the pacing errors', () => {expect(error.message).not.toMatch(/not the runner/);});});++describe('liftStallError', () => {+ // The flick's last move is its step 5; its lift, step 6, comes 16 ms later.+ const onEventAt5 = (ms: number) => [0, 0, 0, 0, 0, ms, 0];+ const lateLift = at([0, 16, 32, 48, 64, 80, 200]);++ it('names the lift stall when onEvent alone carries the gap past the stillness interval, however much later a loaded runner made the lift', () => {+ const fault = touchPacingFault(FLICK, lateLift);+ if (fault?.kind !== 'rest') {+ throw new Error('expected the page to read a rest');+ }+ // onEvent ran 70 ms of the 120 ms gap; the runner stretched the rest.+ const error = liftStallError(FLICK, lateLift, fault, onEventAt5(70));+ expect(error).toBeInstanceOf(TouchLiftStallError);+ expect(error?.numbers).toMatchObject({+ scriptedGapMs: 16,+ gapMs: 120,+ onEventMs: 70,+ });+ });++ it('leaves a lift that onEvent cannot carry past the interval to the pacing errors', () => {+ const fault = touchPacingFault(FLICK, lateLift);+ if (fault == null) {+ throw new Error('expected a fault');+ }+ const below = TOUCH_STILLNESS_MS - 16;+ expect(liftStallError(FLICK, lateLift, fault, onEventAt5(5))).toBeNull();+ expect(+ liftStallError(FLICK, lateLift, fault, onEventAt5(below)),+ ).toBeNull();+ expect(+ liftStallError(FLICK, lateLift, fault, onEventAt5(below + 1)),+ ).toBeInstanceOf(TouchLiftStallError);+ });+});++describe('touchPlayError', () => {+ // The lift reaches the page 120 ms after the last move, step 5, where the+ // script spaces 16 ms: the page reads a resting finger.+ const lateLift = at([0, 16, 32, 48, 64, 80, 200]);+ const heldLift = lateLift.map((a, i) =>+ i === 5 ? {...a, handledAt: a.stamp + 110} : a,+ );+ const quick = [0, 0, 0, 0, 0, 0, 0];+ const slowAt5 = [0, 0, 0, 0, 0, 70, 0];+ const errorFor = (arrivals: TouchArrival[], onEventMs: number[]) => {+ const fault = touchPacingFault(FLICK, arrivals);+ if (fault?.kind !== 'rest') {+ throw new Error('expected the page to read a rest');+ }+ return touchPlayError(FLICK, arrivals, fault, onEventMs);+ };++ it("names the runner's dispatch stall when onEvent is quick and the page's listeners did not hold the lift", () => {+ const error = errorFor(lateLift, quick);+ expect(error).toBeInstanceOf(TouchPacingError);+ expect((error as TouchPacingError).fault.heldByPage).toBeNull();+ });++ it("names the page's stall when its listeners held the lift and onEvent is quick", () => {+ expect(errorFor(heldLift, quick)).toBeInstanceOf(TouchPageStallError);+ });++ it('names the lift stall first when onEvent alone carries the gap past the stillness interval', () => {+ expect(errorFor(lateLift, slowAt5)).toBeInstanceOf(TouchLiftStallError);+ expect(errorFor(heldLift, slowAt5)).toBeInstanceOf(TouchLiftStallError);+ });+});diff --git a/internal/interaction-harness/src/touch.ts b/internal/interaction-harness/src/touch.tsindex 3020e918b6..5ffbb7a195 100644--- a/internal/interaction-harness/src/touch.ts+++ b/internal/interaction-harness/src/touch.ts@@ -567,9 +567,11 @@ 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- * for that excess: page work there holds the next event back by a round trip.- * On a page that stamps touches on arrival (WebKit), the page then reads a- * resting finger and releases at 0.+ * 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+ * 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.*/export class TouchLiftStallError extends Error {constructor(@@ -592,10 +594,12 @@ export class TouchLiftStallError extends Error {/*** The `TouchLiftStallError` for a fault the play's own `onEvent` explains. The- * page read a rest, and `onEvent` ran for the lift gap's excess over the- * script. Null for any other fault.+ * page read a rest, and the scripted gap plus `onEvent`'s run passes the+ * stillness interval. A loaded runner that stretched the gap more changes+ * nothing: the lift stall is the more specific cause, so it comes before any+ * pacing error. Null for any other fault.*/-function liftStallError(+export function liftStallError(steps: readonly TouchEventStep[],arrivals: readonly TouchArrival[],fault: TouchPacingFault,@@ -625,11 +629,30 @@ function liftStallError(const ranMs = onEventMs.slice(lastMoved, lift).reduce((sum, ms) => sum + ms, 0);- return ranMs >= gapMs - scriptedGapMs+ return scriptedGapMs + ranMs > TOUCH_STILLNESS_MS? new TouchLiftStallError({scriptedGapMs, gapMs, onEventMs: ranMs}): null;}+/**+ * The error a paced play's fault throws. The lift stall comes first, since+ * it is the more specific cause. Then a gap the page's own listeners held is+ * the page's, and any other gap is the runner's.+ */+export function touchPlayError(+ steps: readonly TouchEventStep[],+ arrivals: readonly TouchArrival[],+ fault: TouchPacingFault,+ onEventMs: readonly number[],+): TouchLiftStallError | TouchPageStallError | TouchPacingError {+ return (+ liftStallError(steps, arrivals, fault, onEventMs) ??+ (fault.heldByPage == null+ ? new TouchPacingError(fault)+ : new TouchPageStallError({...fault, heldByPage: fault.heldByPage}))+ );+}+/** Records what the page saw of a paced play's touches (WebKit). */interface TouchArrivalProbe {arm(): Promise<void>;@@ -695,12 +718,7 @@ async function playSteps(}const fault = touchPacingFault(steps, arrivals, releaseTolerance);if (fault != null) {- throw (- liftStallError(steps, arrivals, fault, onEventMs) ??- (fault.heldByPage == null- ? new TouchPacingError(fault)- : new TouchPageStallError({...fault, heldByPage: fault.heldByPage}))- );+ throw touchPlayError(steps, arrivals, fault, onEventMs);}const reading = readRelease(steps, arrivals);if (reading != null) {