Skip to content

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

TypeScript

test(interaction-harness): a busy proof reads a held frame's run pace under any settle bound (#10044)

Christopher Chedeau828bc9b9af88
diff --git a/internal/interaction-harness/src/busy.lateblock.fixture.ts b/internal/interaction-harness/src/busy.lateblock.fixture.ts
new file mode 100644
index 0000000000..9b849a2c52
--- /dev/null
+++ b/internal/interaction-harness/src/busy.lateblock.fixture.ts
@@ -0,0 +1,223 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file busy.lateblock.fixture.ts
+ * @input One recorded busy-main-thread run of a slow spring through a 1 s
+ * block that started 200 ms into its curve, in Playwright's WebKit, in the
+ * CI WebKit lane's container (4 CPUs, one worker), with a compositor
+ * control box
+ * @output `step`, the cast's position step; `tracked` and `control`: the
+ * screencast frames each was tracked in, as [ms after the block started, x
+ * in CSS px, or null where it was not found]; `block`: the block's span on
+ * the same clock. Late in the block the spring moves about 1.3 px a frame
+ * in 1 px changes. The screencast stamps its frames unevenly. Against
+ * their stamps, its four frames before +925 ms read 2.4 px a frame. The
+ * run from +925 ms reads 1.0. Its frame at +942 ms holds the position
+ * before while the control moves 6 px, against 10 on the frames around
+ * it. The next frame catches up 2 px.
+ * @position Fixture for busy.test.ts
+ */
+
+/**
+ * The cast's position step, CSS px: its frames are JPEGs at the viewport's
+ * size whose 4:2:0 chroma holds color in 2 by 2 pixel blocks.
+ */
+export const step = {x: 2, y: 2};
+
+export const block = {from: 0, to: 1000};
+
+export const tracked: ReadonlyArray<readonly [number, number | null]> = [
+ [-207.1, 9],
+ [-193.2, 9],
+ [-176.5, 9],
+ [-163.4, 10],
+ [-140.7, 11],
+ [-123.1, 14],
+ [-107.1, 17],
+ [-96.2, 20],
+ [-80.4, 22],
+ [-68.7, 26],
+ [-53.9, 29],
+ [-41.6, 33],
+ [-26.9, 36],
+ [-15.0, 41],
+ [-0.2, 44],
+ [11.8, 49],
+ [26.6, 53],
+ [39.1, 58],
+ [53.9, 62],
+ [72.6, 67],
+ [89.5, 73],
+ [99.2, 79],
+ [116.9, 82],
+ [126.8, 88],
+ [143.7, 92],
+ [166.2, 98],
+ [183.7, 105],
+ [193.3, 111],
+ [211.0, 115],
+ [220.7, 121],
+ [237.5, 124],
+ [259.2, 129],
+ [276.8, 136],
+ [292.6, 142],
+ [303.3, 147],
+ [319.2, 150],
+ [330.3, 155],
+ [346.0, 158],
+ [363.5, 163],
+ [380.3, 168],
+ [397.1, 173],
+ [406.8, 177],
+ [423.6, 180],
+ [433.5, 184],
+ [457.0, 187],
+ [474.2, 193],
+ [491.0, 197],
+ [501.1, 201],
+ [518.8, 203],
+ [528.7, 207],
+ [545.4, 209],
+ [565.1, 213],
+ [582.7, 217],
+ [592.6, 221],
+ [610.3, 223],
+ [620.6, 226],
+ [637.5, 228],
+ [659.7, 231],
+ [676.5, 235],
+ [693.4, 238],
+ [703.2, 240],
+ [719.9, 242],
+ [730.0, 244],
+ [746.9, 246],
+ [760.1, 248],
+ [777.7, 250],
+ [793.6, 253],
+ [804.9, 255],
+ [820.7, 256],
+ [831.5, 258],
+ [847.2, 259],
+ [872.0, 261],
+ [888.9, 264],
+ [898.7, 266],
+ [915.4, 267],
+ [925.1, 269],
+ [941.9, 269],
+ [957.5, 271],
+ [975.1, 273],
+ [991.0, 274],
+ [1001.6, 275],
+ [1017.4, 276],
+ [1028.0, 278],
+ [1043.8, 278],
+ [1055.1, 280],
+ [1070.8, 280],
+ [1082.1, 281],
+ [1097.8, 282],
+ [1108.9, 283],
+ [1124.6, 284],
+ [1135.6, 285],
+ [1151.3, 286],
+ [1162.5, 287],
+ [1178.2, 287],
+ [1189.4, 288],
+];
+
+export const control: ReadonlyArray<readonly [number, number | null]> = [
+ [-207.1, null],
+ [-193.2, 22],
+ [-176.5, 30],
+ [-163.4, 41],
+ [-140.7, 49],
+ [-123.1, 62],
+ [-107.1, 73],
+ [-96.2, 82],
+ [-80.4, 89],
+ [-68.7, 98],
+ [-53.9, 105],
+ [-41.6, 114],
+ [-26.9, 122],
+ [-15.0, 130],
+ [-0.2, 138],
+ [11.8, 146],
+ [26.6, 154],
+ [39.1, 162],
+ [53.9, 170],
+ [72.6, 178],
+ [89.5, 190],
+ [99.2, 200],
+ [116.9, 206],
+ [126.8, 217],
+ [143.7, 222],
+ [166.2, 233],
+ [183.7, 236],
+ [193.3, 225],
+ [211.0, 219],
+ [220.7, 209],
+ [237.5, 203],
+ [259.2, 193],
+ [276.8, 180],
+ [292.6, 169],
+ [303.3, 160],
+ [319.2, 153],
+ [330.3, 144],
+ [346.0, 137],
+ [363.5, 128],
+ [380.3, 117],
+ [397.1, 107],
+ [406.8, 97],
+ [423.6, 91],
+ [433.5, 81],
+ [457.0, 75],
+ [474.2, 61],
+ [491.0, 50],
+ [501.1, 41],
+ [518.8, 34],
+ [528.7, 24],
+ [545.4, 18],
+ [565.1, 8],
+ [582.7, 6],
+ [592.6, 16],
+ [610.3, 22],
+ [620.6, 33],
+ [637.5, 39],
+ [659.7, 49],
+ [676.5, 62],
+ [693.4, 73],
+ [703.2, 82],
+ [719.9, 89],
+ [730.0, 98],
+ [746.9, 105],
+ [760.1, 114],
+ [777.7, 123],
+ [793.6, 133],
+ [804.9, 142],
+ [820.7, 150],
+ [831.5, 158],
+ [847.2, 166],
+ [872.0, 174],
+ [888.9, 190],
+ [898.7, 200],
+ [915.4, 206],
+ [925.1, 216],
+ [941.9, 222],
+ [957.5, 232],
+ [975.1, 241],
+ [991.0, 230],
+ [1001.6, 221],
+ [1017.4, 214],
+ [1028.0, 205],
+ [1043.8, 199],
+ [1055.1, 189],
+ [1070.8, 182],
+ [1082.1, 173],
+ [1097.8, 166],
+ [1108.9, 157],
+ [1124.6, 150],
+ [1135.6, 141],
+ [1151.3, 134],
+ [1162.5, 125],
+ [1178.2, 118],
+ [1189.4, 108],
+];
diff --git a/internal/interaction-harness/src/busy.test.ts b/internal/interaction-harness/src/busy.test.ts
index a979656518..6b4810957e 100644
--- a/internal/interaction-harness/src/busy.test.ts
+++ b/internal/interaction-harness/src/busy.test.ts
@@ -9,7 +9,10 @@
* presentation order; a settle bound in cast steps reads the step from the
* run (2 px in WebKit's cast, 1 px in Chromium's), stops a WebKit coast at
* its tail's plateaus where a 2 px bound reads them as a stall, and still
- * fails a 40 ms freeze more than two steps from rest in either cast.
+ * fails a 40 ms freeze more than two steps from rest in either cast. The
+ * proof reads a held frame at its run's own pace, whatever the settle
+ * bound. A slow spring late in a WebKit block passes, and its holds and a
+ * freeze still fail.
* @position Unit test of ./busy and ./frames' ordering; the browser proof
* with a real compositor animation and a rAF control is in
* harness.interaction.browser.spec.ts.
@@ -17,6 +20,7 @@
import {describe, expect, it} from 'vitest';
import {busyWindowProof, BusyWindowTooLateError, castStep} from './busy';
+import * as lateBlock from './busy.lateblock.fixture';
import * as skip from './busy.skip.fixture';
import * as slowTail from './busy.slowtail.fixture';
import * as webkitDecel from './busy.webkitdecel.fixture';
@@ -707,6 +711,80 @@ describe('busyWindowProof in a slow tail', () => {
});
});
+describe('busyWindowProof in a slow tail late in a WebKit block', () => {
+ const control = slowTailFrames(lateBlock.control);
+ /**
+ * The spring's frames, each frame from `from` through `to` ms holding the
+ * position before.
+ */
+ const held = (from: number, to: number): TrackedFrame[] => {
+ const frames = slowTailFrames(lateBlock.tracked);
+ const hold = [...frames].reverse().find(f => f.t < from)!.box!;
+ return frames.map(f =>
+ f.t >= from && f.t <= to ? ({...f, box: {...hold}} as TrackedFrame) : f,
+ );
+ };
+ const judge = (tracked: readonly TrackedFrame[]) =>
+ busyWindowProof(tracked, lateBlock.block, {
+ axis: 'x',
+ settledWithin: 2,
+ control,
+ });
+
+ it("reads a held frame at its run's own pace where uneven stamps put the frames before it over two steps a frame", () => {
+ // The frame at +942 ms holds the position before while the control
+ // moves, and the next catches up 2 px. The run moves 1.0 px a frame.
+ const proof = judge(slowTailFrames(lateBlock.tracked));
+ expect(proof.verdict.failures).toEqual([]);
+ });
+
+ it('still fails a one-frame hold there where the spring moves two steps a frame or more', () => {
+ // Held at 168 px at +397 ms, where the spring moves about 5 px a frame:
+ // the next frame catches up 9 px.
+ const proof = judge(held(390, 400));
+ expect(proof.verdict.failures.join('\n')).toMatch(
+ /moved on \d+ of the \d+ frames the control moved/,
+ );
+ });
+
+ it('still fails a two-frame hold in its slow tail', () => {
+ // Held at 258 px at +847 and +872 ms, then 264 px: about 1.6 px a frame
+ // across the run, two frames held.
+ const proof = judge(held(840, 880));
+ expect(proof.verdict.failures.join('\n')).toMatch(
+ /moved on \d+ of the \d+ frames the control moved/,
+ );
+ });
+
+ it('still fails the spring frozen through the block', () => {
+ const proof = judge(held(100, 1000));
+ expect(proof.verdict.pass, proof.summary).toBe(false);
+ });
+
+ it('reads a held frame across a sparse stretch at the pace before it', () => {
+ // 1 px a frame, then three frames 36.7 ms apart read 230, 230 and 232.
+ // The pace before the run explains the held frame, as with frames on
+ // time. The run's own reading, over the time it spans, is slower.
+ const frames: (readonly [number, number])[] = [];
+ for (let i = 0; i <= 30; i += 1) {
+ frames.push([-200 + i * 16.7, 200 + i]);
+ }
+ const sparse = frames[frames.length - 1][0];
+ frames.push([sparse + 36.7, 230], [sparse + 73.4, 232]);
+ for (let j = 1; sparse + 73.4 + j * 16.7 <= 1100; j += 1) {
+ frames.push([sparse + 73.4 + j * 16.7, 232 + j]);
+ }
+ const proof = busyWindowProof(slowTailFrames(frames), lateBlock.block, {
+ axis: 'x',
+ settledWithin: 2,
+ control: slowTailFrames(
+ frames.map(([t]) => [t, Math.round(0.18 * (t + 200))] as const),
+ ),
+ });
+ expect(proof.verdict.failures).toEqual([]);
+ });
+});
+
describe('busyWindowProof settledWithinSteps', () => {
/** Holds the position the frame at or before `fromT` shows for `ms`. */
const freeze = (
@@ -978,9 +1056,9 @@ describe('busyWindowProof settledWithinSteps', () => {
expect(proof.verdict.failures).toEqual([]);
});
- it("reads the run's own pace only for a step-counted bound: with settledWithin, that held frame fails as before", () => {
- // The same coast with a pixel bound: the pace before the hold alone
- // judges the held frame, as for every proof that does not opt in.
+ it("reads that held frame at the run's own pace under a pixel bound too", () => {
+ // The same coast with a pixel bound: the settle bound does not change how
+ // a held frame is read.
const proof = busyWindowProof(
webkit(webkitDecel.tracked),
webkitDecel.block,
@@ -990,9 +1068,7 @@ describe('busyWindowProof settledWithinSteps', () => {
control: webkit(webkitDecel.control),
},
);
- expect(proof.verdict.failures.join('\n')).toMatch(
- /moved on 7 of the 8 frames the control moved/,
- );
+ expect(proof.verdict.failures).toEqual([]);
});
it('reads a three-frame plateau that ends in a two-step change at about 1.3 px a frame as slow motion', () => {
diff --git a/internal/interaction-harness/src/busy.ts b/internal/interaction-harness/src/busy.ts
index 269e3c7b4d..2add207346 100644
--- a/internal/interaction-harness/src/busy.ts
+++ b/internal/interaction-harness/src/busy.ts
@@ -1261,32 +1261,33 @@ export function busyWindowProof(
}
const unchanged = k - 1 - start;
// Under one step a frame the change that ends the run is a single step.
- // Under two, a frame delivered early can also show no step, and the
- // change then carries the motion of every frame the run held, at the
- // pace of the frames before it, to the nearest step. An early frame
- // hides one frame's motion: at one step a frame or more the run is one
- // frame long, and under one step a frame it adds at most one step to
- // the catch-up.
+ // Under two, a frame delivered early can also show no step. The change
+ // then carries the motion of every frame the run held, to the nearest
+ // step, at the pace before the run or across it. An early frame hides
+ // one frame's motion. At one step a frame or more, the run is one frame
+ // long. Under one step a frame, it adds at most one step to the
+ // catch-up.
const catchUp = Math.abs(series[k].value - series[i].value);
- // The pace at the run: the component's motion over the frames before
- // it. A proof that bounds its settle in the cast's own steps also reads
- // the pace across the run itself, its catch-up over the frames from the
- // run's start to the change, where the curve slows faster than the
- // frames before it show. A freeze still fails: its run is longer than
- // one frame at a step a frame or more, and at a steady pace of two steps
- // a frame its catch-up carries two frames of that pace.
+ // Two readings give the pace at the run, and either can explain the
+ // run. One is the component's motion over the frames before the run.
+ // The other is its catch-up across the run itself, from the run's start
+ // to the change. The run's own reading counts where the curve slows
+ // faster than the frames before it show. It also counts where a loaded
+ // runner stamps those frames unevenly, whatever the settle bound. A
+ // freeze still fails. Its run is longer than one frame at a step a frame
+ // or more. At a steady pace of two steps a frame, its catch-up carries
+ // two frames of that pace.
const paceBefore = pxPerFrameBefore(start);
const runFrames = (series[k].t - series[start].t) / cadence;
- const pace =
- paceBefore == null || settledWithinSteps == null || runFrames <= 0
- ? paceBefore
- : Math.min(paceBefore, catchUp / runFrames);
+ const explains = (pace: number | null): boolean =>
+ pace != null &&
+ pace < 2 * stepPx &&
+ (pace < stepPx ? catchUp < 2.5 * stepPx : unchanged <= 1) &&
+ catchUp <= (unchanged + 1) * pace + stepPx;
const shown =
catchUp < 1.5 * stepPx ||
- (pace != null &&
- pace < 2 * stepPx &&
- (pace < stepPx ? catchUp < 2.5 * stepPx : unchanged <= 1) &&
- catchUp <= (unchanged + 1) * pace + stepPx);
+ explains(paceBefore) ||
+ (paceBefore != null && runFrames > 0 && explains(catchUp / runFrames));
if (!shown) {
return false;
}