Skip to content

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

TypeScript

test(interaction-harness): the frame-evidence trace judges one layout per frame the page drew (#9456)

Christopher Chedeaud0171bfc4404
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index 5d22524caf..a692ebc7c3 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -1258,7 +1258,9 @@ test.describe('frame evidence', () => {
);
await fixture(page);
const box = page.locator('#box');
- // Count the animation's steady middle: starting and ending it may lay out once each.
+ // Count the animation's steady middle: starting and ending it may lay out
+ // once each. The page also records when it drew each frame (its rAF
+ // times), so the frames are counted in the same window.
const animate = async (property: 'transform' | 'top') => {
let started = 0;
const trace = await traceRendering(page, async () => {
@@ -1270,19 +1272,38 @@ test.describe('frame evidence', () => {
{transform: 'translateY(200px)'},
]
: [{top: '360px'}, {top: '560px'}];
- el.animate(keyframes, {duration: 600});
+ const animation = el.animate(keyframes, {duration: 600});
+ const drawn: number[] = [];
+ (window as unknown as {drawn: number[]}).drawn = drawn;
+ const frame = (time: number) => {
+ drawn.push(performance.timeOrigin + time);
+ if (animation.playState === 'running') {
+ requestAnimationFrame(frame);
+ }
+ };
+ requestAnimationFrame(frame);
return performance.timeOrigin + performance.now();
}, property);
await page.waitForTimeout(700);
});
- return countBetween(trace, started + 100, started + 500);
+ const drawn = await page.evaluate(
+ () => (window as unknown as {drawn: number[]}).drawn,
+ );
+ return {
+ counts: countBetween(trace, started + 100, started + 500),
+ frames: drawn.filter(t => t >= started + 100 && t <= started + 500)
+ .length,
+ };
};
const transform = await animate('transform');
const top = await animate('top');
- expect(transform.Layout ?? 0).toBe(0);
- expect(transform.Paint ?? 0).toBe(0);
- // ~24 frames in 400 ms: one layout per frame.
- expect(top.Layout ?? 0).toBeGreaterThan(18);
+ expect(transform.counts.Layout ?? 0).toBe(0);
+ expect(transform.counts.Paint ?? 0).toBe(0);
+ // One layout per frame the page drew: 24 in 400 ms at 60 Hz, fewer on a
+ // loaded runner, which draws fewer frames; at least 4 to judge. The
+ // window's end can fall between a frame's start and its layout.
+ expect(top.frames).toBeGreaterThanOrEqual(4);
+ expect(top.counts.Layout ?? 0).toBeGreaterThanOrEqual(top.frames - 1);
});
test('the compositor record refuses another open page, whose frames it could not tell apart', async ({