Skip to content

Commit bb770b3

Browse files
committed
test(core): the WebKit row release video proof judges rest on the exit curve
After #9890 the row's touch release plays the theme's exit tokens, whose curve leaves fastest at its end. The video's 40 ms frames rarely land in the last few milliseconds before Linux WebKit's end-of-animation hand-back, so the "within 1 of rest" check failed most runs. The case now sets a 400 ms exit on the row, reads the clock and curve from the page, and judges rest as the curve's value one recording frame before the end.
1 parent 57aa93c commit bb770b3

1 file changed

Lines changed: 43 additions & 12 deletions

File tree

‎packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts‎

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ async function exitOf(surface: Locator): Promise<Exit> {
8989
const strengthAt = (exit: Exit, t: number) =>
9090
1 - exit.ease(Math.min(1, Math.max(0, t / exit.ms)));
9191

92+
/**
93+
* The spacing of a Playwright video recording's frames (about 25 fps), with
94+
* margin for jitter.
95+
*/
96+
const RECORDING_FRAME_MS = 50;
97+
9298
/** Long enough that the press is believed (scroll.delaysContentTouchesMs). */
9399
const HOLD_MS = 400;
94100

@@ -531,7 +537,13 @@ test('WebKit: the release keeps fading while the main thread is blocked (video)'
531537
recordVideo: {dir: testInfo.outputPath('video'), size},
532538
});
533539
const page = await context.newPage();
534-
const {driver, center, probe} = await openRow(page, LIST_ROW);
540+
const {driver, row, center, probe} = await openRow(page, LIST_ROW);
541+
// A long exit duration on the row, so its release spans many of the
542+
// recording's frames inside the block, whatever the theme's own value is.
543+
await row.evaluate(el =>
544+
(el as HTMLElement).style.setProperty('--duration-exit', '400ms'),
545+
);
546+
const exit = await exitOf(row);
535547
// A beacon the main thread paints: blue while it is about to block, green
536548
// once it has run again. Frames in which the beacon is blue were presented
537549
// while script could not run.
@@ -636,17 +648,31 @@ test('WebKit: the release keeps fading while the main thread is blocked (video)'
636648
},
637649
);
638650
const blocked = samples.filter(s => s.beacon === 'blocked');
639-
const rest = Math.max(
640-
...samples.filter(s => s.beacon === 'before').map(s => s.value),
651+
const before = samples.filter(s => s.beacon === 'before');
652+
const rest = Math.max(...before.map(s => s.value));
653+
// The pressed colour from the hold's own frames, not from the page's
654+
// load, so a dark frame while Storybook starts cannot move it.
655+
const holdStart = blocked.length > 0 ? blocked[0].t - HOLD_MS / 1000 : 0;
656+
const pressed = Math.min(
657+
...before.filter(s => s.t >= holdStart).map(s => s.value),
641658
);
642-
// Judge the release up to the frame it reaches the row's resting color.
659+
// The exit curve leaves fastest at its end, so the last frame the
660+
// recording catches can be up to one frame short of rest. The release
661+
// has reached its end when a frame shows at least the curve's value one
662+
// recording frame (with margin) before the end.
663+
const nearRest =
664+
rest -
665+
(rest - pressed) * strengthAt(exit, exit.ms - RECORDING_FRAME_MS) -
666+
1;
667+
// Judge the release up to the frame it reaches the row's resting color,
668+
// within one recording frame.
643669
// (Measured in the Linux WebKit build: once an accelerated animation has
644670
// finished while script is still blocked, the compositor shows the value
645671
// the main thread last committed until script runs again. That is this
646672
// build's end-of-animation hand-back, after the release; iOS Safari 26.2
647673
// holds the resting color on the simulator. It is recorded below, not
648674
// judged here.)
649-
const restIndex = blocked.findIndex(s => s.value >= rest - 1);
675+
const restIndex = blocked.findIndex(s => s.value >= nearRest);
650676
const fading = restIndex === -1 ? blocked : blocked.slice(0, restIndex + 1);
651677
const distinct = fading
652678
.map(s => Math.round(s.value))
@@ -656,7 +682,7 @@ test('WebKit: the release keeps fading while the main thread is blocked (video)'
656682
'busy-main-thread/list-row-release-webkit',
657683
{
658684
'webkit.json': JSON.stringify(
659-
{rest, blocked, distinct, afterEnd},
685+
{rest, pressed, nearRest, exit, blocked, distinct, afterEnd},
660686
null,
661687
1,
662688
),
@@ -672,16 +698,21 @@ test('WebKit: the release keeps fading while the main thread is blocked (video)'
672698
expect(blocked.length).toBeGreaterThan(0);
673699
// The row kept getting lighter while script could not run, all the way
674700
// to its resting color: from a frame still short of rest, it reached rest
675-
// inside the blocked window. A release on the main thread would hold its
676-
// first frame's value until the block ends, 700 ms on, and could not. (The
677-
// recording's frames are 40 ms apart, so how many land inside the 200 ms
678-
// release depends on its phase: the count is not judged.)
701+
// (within one recording frame) inside the blocked window. A release on
702+
// the main thread would hold its first frame's value until the block
703+
// ends, 700 ms on, and could not. (The recording's frames are about
704+
// 40 ms apart, so how many land inside the release depends on its phase:
705+
// the count is not judged.)
679706
const values = JSON.stringify(blocked.map(s => Math.round(s.value)));
680-
expect(blocked[0].value, values).toBeLessThan(rest - 1);
707+
expect(blocked[0].value, values).toBeLessThan(nearRest);
681708
expect(restIndex, values).toBeGreaterThan(0);
709+
// Lighter frame by frame. The first frames move the row by about one
710+
// level, so a video decode may round one of them a level back: allow
711+
// that one level, never more.
682712
for (let i = 1; i < distinct.length; i++) {
683-
expect(distinct[i], values).toBeGreaterThan(distinct[i - 1]);
713+
expect(distinct[i], values).toBeGreaterThanOrEqual(distinct[i - 1] - 1);
684714
}
715+
expect(distinct.at(-1), values).toBeGreaterThan(distinct[0]);
685716
} finally {
686717
await decoder.close();
687718
}

0 commit comments

Comments
 (0)