Skip to content

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

TypeScript

test(interaction-harness): the frame-evidence proof fits the compositor (#10451)

Christopher Chedeaufa40f714868e
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index b3c017dcfc..4ac20c8f76 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -561,35 +561,65 @@ test.describe('frame evidence', () => {
// counts: the component is judged against what the compositor presented
// in the same window, and the bound's own verdict is recorded beside it.
const control = await startBusyControl(page);
+ // The cast and the page measure the box from different edges. Both read
+ // it once at rest, so the frozen check below compares displacements.
+ // The control's motion keeps the cast sending frames meanwhile.
+ const restCast = await startScreencast(page);
+ await frames(page, 3);
+ // WebKit's first cast frame can lag several frames on a busy page.
+ await expect.poll(() => restCast.frameCount()).toBeGreaterThan(0);
+ const [atRest] = await trackMarker(page, (await restCast.stop()).slice(-1));
+ expect(atRest?.box, 'the cast shows the box at rest').toBeTruthy();
+ const rest = {
+ cast: atRest?.box?.y ?? Number.NaN,
+ page: await box.evaluate(el => el.getBoundingClientRect().y),
+ };
// The README's order: the cast, then the animation, then the block once
// it runs (on the compositor, for the compositor's run).
+ // 560 px in 1100 ms is two cast steps or more a frame up to 120 Hz.
+ // WebKit's headless compositor presents above 60 Hz.
const run = async (
driver: 'compositor' | 'raf',
everyNthFrame = 1,
blockMs = 700,
+ durationMs = 1100,
) => {
const cast = await startScreencast(page, {everyNthFrame});
- await box.evaluate((el, how) => {
- el.getAnimations().forEach(a => a.cancel());
- el.style.transform = 'none';
- if (how === 'compositor') {
- el.animate(
- [{transform: 'translateY(0px)'}, {transform: 'translateY(560px)'}],
- {duration: 1600, easing: 'linear'},
- );
- } else {
- const start = performance.now();
- const step = (now: number) => {
- const p = Math.min(1, (now - start) / 1600);
- el.style.transform = `translateY(${560 * p}px)`;
- if (p < 1) {
- requestAnimationFrame(step);
- }
- };
- requestAnimationFrame(step);
- }
- }, driver);
+ await box.evaluate(
+ (el, {how, duration}) => {
+ el.getAnimations().forEach(a => a.cancel());
+ el.style.transform = 'none';
+ if (how === 'compositor') {
+ el.animate(
+ [
+ {transform: 'translateY(0px)'},
+ {transform: 'translateY(560px)'},
+ ],
+ {duration, easing: 'linear'},
+ );
+ } else {
+ // Where each frame left the box, on the page's clock.
+ const written: Array<{at: number; y: number}> = [];
+ (globalThis as unknown as {written: typeof written}).written =
+ written;
+ const start = performance.now();
+ const step = (now: number) => {
+ const p = Math.min(1, (now - start) / duration);
+ el.style.transform = `translateY(${560 * p}px)`;
+ written.push({
+ at: performance.timeOrigin + performance.now(),
+ y: el.getBoundingClientRect().y,
+ });
+ if (p < 1) {
+ requestAnimationFrame(step);
+ }
+ };
+ requestAnimationFrame(step);
+ }
+ },
+ {how: driver, duration: durationMs},
+ );
// A rendering update first: until one commits the cancel, the
// compositor keeps playing the previous run's animation into the block.
await page.evaluate(
@@ -608,12 +638,21 @@ test.describe('frame evidence', () => {
const tracked = await trackMarker(page, frames);
const controlFrames = await trackMarker(page, frames, {rgb: CONTROL_RGB});
const alone = busyWindowProof(tracked, window, {axis: 'y'});
+ // The last place a frame left the box before the block.
+ const written = await page.evaluate(
+ () =>
+ (globalThis as unknown as {written?: Array<{at: number; y: number}>})
+ .written ?? [],
+ );
+ const leftAt = written.filter(w => w.at < window.from).at(-1)?.y;
return {
proof: busyWindowProof(tracked, window, {
axis: 'y',
control: controlFrames,
}),
alone,
+ tracked,
+ leftAt,
};
};
@@ -627,7 +666,12 @@ test.describe('frame evidence', () => {
// Resolvable on the cast's grid: two position steps or more per frame.
expect(compositor.pxPerFrame).toBeGreaterThanOrEqual(2 * compositor.stepPx);
- const {proof: raf, alone: rafAlone} = await run('raf');
+ const {
+ proof: raf,
+ alone: rafAlone,
+ tracked: rafTracked,
+ leftAt,
+ } = await run('raf');
testInfo.annotations.push({
type: 'busy-main-thread rAF control',
description: raf.summary,
@@ -636,7 +680,19 @@ test.describe('frame evidence', () => {
// screen changes, so at most the frame presented as the block starts
// moved, and the bound's verdict fails it as the control's does.
expect(raf.changed).toBeLessThanOrEqual(1);
- expect(raf.longestStallMs).toBeGreaterThan(600);
+ // Still where the last frame before the block left it, within a cast
+ // step. A starved compositor can present that frame late in the block.
+ const last = rafTracked
+ .filter(
+ f => f.box != null && f.t > raf.judged.from && f.t < raf.judged.to,
+ )
+ .at(-1);
+ expect(leftAt, 'a frame moved the box before the block').toBeDefined();
+ const shown = (last?.box?.y ?? Number.NaN) - rest.cast;
+ const left = (leftAt ?? Number.NaN) - rest.page;
+ expect(Math.abs(shown - left), raf.summary).toBeLessThanOrEqual(
+ compositor.stepPx,
+ );
expect(raf.verdict.failures.join('\n')).toMatch(
/moved on [01] of the \d+ frames the control moved/,
);
@@ -650,10 +706,10 @@ test.describe('frame evidence', () => {
// at one frame in six (a loaded machine's ~100 ms), the compositor
// animation still passes and the rAF one still fails. A 1.4 s block keeps
// the control's four frames on a runner that presents half the rate.
- const {proof: slow} = await run('compositor', 6, 1400);
+ const {proof: slow} = await run('compositor', 6, 1400, 1600);
expect(slow.cadenceMs, slow.summary).toBeGreaterThan(60);
expect(slow.verdict.failures, slow.summary).toEqual([]);
- const {proof: slowRaf} = await run('raf', 6, 1400);
+ const {proof: slowRaf} = await run('raf', 6, 1400, 1600);
expect(slowRaf.verdict.pass, slowRaf.summary).toBe(false);
expect(slowRaf.verdict.failures.join('\n')).toMatch(/longest stall/);
await control.remove();