Skip to content

Commit 172ea76

Browse files
committed
NOT FOR LANDING: the busy proof on every frame and on the read frames
Both decodes on the same frames, with the proofs compared.
1 parent 904df99 commit 172ea76

1 file changed

Lines changed: 82 additions & 59 deletions

File tree

‎packages/core/src/motion/__tests__/animatedLayoutBusy.interaction.browser.spec.ts‎

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,28 @@ import {
2727
markElement,
2828
startBusyControl,
2929
startScreencast,
30+
trackMarker,
3031
trackMarkers,
3132
writeEvidence,
32-
} from '@astryxdesign/interaction-harness';
33+
} from "@astryxdesign/interaction-harness";
3334
import {
3435
expect,
3536
test,
3637
type Locator,
3738
type Page,
38-
} from '@astryxdesign/a11y-spec/playwright';
39+
} from "@astryxdesign/a11y-spec/playwright";
3940
import {
4041
DEFAULT_STORYBOOK_DIR,
4142
serveStorybook,
4243
type StaticServer,
43-
} from '@astryxdesign/a11y-spec/storybook';
44+
} from "@astryxdesign/a11y-spec/storybook";
4445

4546
// Linux WebKit hands the glide to its compositor late. Nothing moves for the
4647
// first 30 to 100 ms of the block, so too little of the curve is left to judge.
4748
// Apple's WebKit (the iOS 26.2 Simulator) moves on every frame from the start.
4849
test.skip(
49-
({browserName}) => browserName === 'webkit',
50-
'Linux WebKit starts the glide on its compositor 30\u2013100 ms late; Apple\u2019s WebKit does not',
50+
({ browserName }) => browserName === "webkit",
51+
"Linux WebKit starts the glide on its compositor 30\u2013100 ms late; Apple\u2019s WebKit does not",
5152
);
5253

5354
let storybook: StaticServer | undefined;
@@ -92,18 +93,18 @@ interface GlideRead {
9293
/** Loads a story and waits for its first render, its fonts and two frames. */
9394
async function openStory(page: Page, story: string): Promise<void> {
9495
await page.goto(
95-
`${storybook?.origin ?? ''}/iframe.html?id=${story}&viewMode=story`,
96+
`${storybook?.origin ?? ""}/iframe.html?id=${story}&viewMode=story`,
9697
);
9798
await page
98-
.locator('#storybook-root > *')
99+
.locator("#storybook-root > *")
99100
.first()
100-
.waitFor({state: 'attached'});
101+
.waitFor({ state: "attached" });
101102
await page.addStyleTag({
102103
content: `* { --duration-medium-min: ${GLIDE_MS}ms !important; --duration-medium: ${GLIDE_MS}ms !important; }`,
103104
});
104105
await page.evaluate(async () => {
105106
await document.fonts.ready;
106-
await new Promise<void>(resolve => {
107+
await new Promise<void>((resolve) => {
107108
requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
108109
});
109110
});
@@ -121,22 +122,22 @@ async function clickThenBlock(
121122
page: Page,
122123
trigger: Locator,
123124
follower: Locator,
124-
axis: 'x' | 'y',
125-
): Promise<{busy: BlockedWindow; glides: GlideRead[]}> {
125+
axis: "x" | "y",
126+
): Promise<{ busy: BlockedWindow; glides: GlideRead[] }> {
126127
const handle = await follower.elementHandle();
127128
await trigger.evaluate(
128-
(element, {duration, carried, along}) => {
129+
(element, { duration, carried, along }) => {
129130
const offsetOf = (value: unknown) => {
130131
const match = /^(-?[\d.e+-]+)px(?:\s+(-?[\d.e+-]+)px)?/.exec(
131132
String(value),
132133
);
133134
if (match == null) {
134135
return 0;
135136
}
136-
return along === 'x' ? Number(match[1]) : Number(match[2] ?? 0);
137+
return along === "x" ? Number(match[1]) : Number(match[2] ?? 0);
137138
};
138139
element.addEventListener(
139-
'click',
140+
"click",
140141
() => {
141142
requestAnimationFrame(() => {
142143
const glides: GlideRead[] = [];
@@ -149,7 +150,7 @@ async function clickThenBlock(
149150
const effect = animation.effect as KeyframeEffect;
150151
const frames = effect
151152
.getKeyframes()
152-
.filter(frame => typeof frame.translate === 'string');
153+
.filter((frame) => typeof frame.translate === "string");
153154
if (frames.length < 2) {
154155
continue;
155156
}
@@ -171,7 +172,7 @@ async function clickThenBlock(
171172
while (now - from < duration) {
172173
now = performance.now();
173174
}
174-
(window as unknown as {busy: unknown}).busy = {
175+
(window as unknown as { busy: unknown }).busy = {
175176
busy: {
176177
from: performance.timeOrigin + from,
177178
to: performance.timeOrigin + now,
@@ -182,18 +183,21 @@ async function clickThenBlock(
182183
}, 0);
183184
});
184185
},
185-
{capture: true, once: true},
186+
{ capture: true, once: true },
186187
);
187188
},
188-
{duration: BLOCK_MS, carried: handle, along: axis},
189+
{ duration: BLOCK_MS, carried: handle, along: axis },
189190
);
190191
await trigger.click();
191192
const signal = await page.waitForFunction(
192193
() =>
193-
(window as unknown as {busy?: {busy: BlockedWindow; glides: GlideRead[]}})
194-
.busy,
194+
(
195+
window as unknown as {
196+
busy?: { busy: BlockedWindow; glides: GlideRead[] };
197+
}
198+
).busy,
195199
undefined,
196-
{polling: 50, timeout: 0},
200+
{ polling: 50, timeout: 0 },
197201
);
198202
return (await signal.jsonValue()) as {
199203
busy: BlockedWindow;
@@ -236,14 +240,14 @@ async function busyGlide(
236240
{
237241
trigger,
238242
follower,
239-
axis = 'y',
240-
}: {trigger: Locator; follower: Locator; axis?: 'x' | 'y'},
243+
axis = "y",
244+
}: { trigger: Locator; follower: Locator; axis?: "x" | "y" },
241245
) {
242246
await markElement(follower);
243247
// Before the glide, so the control is on the compositor first.
244248
await startBusyControl(page);
245249
const cast = await startScreencast(page);
246-
const {busy, glides} = await clickThenBlock(page, trigger, follower, axis);
250+
const { busy, glides } = await clickThenBlock(page, trigger, follower, axis);
247251
// Until every animation but the control's has ended.
248252
await expect
249253
.poll(async () =>
@@ -252,10 +256,10 @@ async function busyGlide(
252256
document
253257
.getAnimations()
254258
.filter(
255-
a =>
259+
(a) =>
256260
!(
257261
(a.effect as KeyframeEffect | null)?.target?.closest(
258-
'[data-harness-control]',
262+
"[data-harness-control]",
259263
) ?? false
260264
),
261265
).length,
@@ -265,19 +269,20 @@ async function busyGlide(
265269
// Where the marker rests, read from the page. A glide frozen through the
266270
// block stays far from it, and a frame after the block can still be stale.
267271
const settledAt = await follower.evaluate((el, along) => {
268-
const chip = el.querySelector('[data-harness-marker-chip]');
272+
const chip = el.querySelector("[data-harness-marker-chip]");
269273
if (chip == null) {
270-
throw new Error('the follower lost its marker chip');
274+
throw new Error("the follower lost its marker chip");
271275
}
272276
const box = chip.getBoundingClientRect();
273-
return along === 'x' ? box.x : box.y;
277+
return along === "x" ? box.x : box.y;
274278
}, axis);
275279
const frames = await cast.stop();
280+
const tNew0 = Date.now();
276281
// The cast's step, from one frame in the block.
277282
const [probe] = await trackMarkers(
278283
page,
279-
[frames.find(f => f.t >= busy.from) ?? frames[frames.length - 1]],
280-
{colors: [MARKER_RGB]},
284+
[frames.find((f) => f.t >= busy.from) ?? frames[frames.length - 1]],
285+
{ colors: [MARKER_RGB] },
281286
);
282287
const step = castStep(probe, axis);
283288
// Where the glide's keyframes first move the follower by less than a cast
@@ -293,23 +298,41 @@ async function busyGlide(
293298
readable += 1;
294299
}
295300
// The part of the block the judgment reads ends there.
296-
const judgedWindow = {...busy, to: Math.min(busy.to, readable)};
301+
const judgedWindow = { ...busy, to: Math.min(busy.to, readable) };
297302
// Only the frames the proof reads are decoded, each once for both colors.
298303
// On a loaded machine every decode counts.
299-
const [tracked, control] = await trackMarkers(
300-
page,
301-
frames.filter(f => f.t <= judgedWindow.to + BUSY_PROOF_LOOKAROUND_MS),
302-
{colors: [MARKER_RGB, CONTROL_RGB]},
304+
const near = frames.filter(
305+
(f) => f.t <= judgedWindow.to + BUSY_PROOF_LOOKAROUND_MS,
303306
);
307+
const [tracked, control] = await trackMarkers(page, near, {
308+
colors: [MARKER_RGB, CONTROL_RGB],
309+
});
310+
const tNew = Date.now() - tNew0;
311+
const tOld0 = Date.now();
312+
const trackedAll = await trackMarker(page, frames);
313+
const controlAll = await trackMarker(page, frames, { rgb: CONTROL_RGB });
314+
const tOld = Date.now() - tOld0;
304315
const proof = busyWindowProof(tracked, judgedWindow, {
305316
axis,
306317
settledWithinSteps: 2,
307318
settledAt,
308319
minJudgedFrames: MIN_JUDGED_FRAMES,
309320
control,
310321
});
311-
const at = (box: (typeof tracked)[number]['box']) =>
312-
box == null ? null : axis === 'x' ? box.x : box.y;
322+
const proofAll = busyWindowProof(trackedAll, judgedWindow, {
323+
axis,
324+
settledWithinSteps: 2,
325+
settledAt,
326+
minJudgedFrames: MIN_JUDGED_FRAMES,
327+
control: controlAll,
328+
});
329+
console.log(
330+
`EQUIV ${name} frames=${frames.length} decodedNew=${1 + near.length} decodedOld=${2 * frames.length} msNew=${tNew} msOld=${tOld} same=${JSON.stringify(proof) === JSON.stringify(proofAll)} ok=${proof.ok} okAll=${proofAll.ok}`,
331+
);
332+
expect(proofAll).toEqual(proof);
333+
334+
const at = (box: (typeof tracked)[number]["box"]) =>
335+
box == null ? null : axis === "x" ? box.x : box.y;
313336
await writeEvidence(
314337
`busy-main-thread/animated-layout-${name}`,
315338
{
@@ -336,67 +359,67 @@ async function busyGlide(
336359
const summary = `judged until +${(readable - busy.from).toFixed(0)} ms (${step} px cast step): ${proof.summary}`;
337360
test
338361
.info()
339-
.annotations.push({type: 'busy-main-thread', description: summary});
340-
return {busy, proof, summary, glides, readableMs: readable - busy.from};
362+
.annotations.push({ type: "busy-main-thread", description: summary });
363+
return { busy, proof, summary, glides, readableMs: readable - busy.from };
341364
}
342365

343366
/** Marks the app div whose text starts with `text` for a test to find. */
344367
async function markAppDiv(page: Page, text: string): Promise<Locator> {
345-
await page.evaluate(t => {
346-
const element = [...document.querySelectorAll('div')].find(el =>
368+
await page.evaluate((t) => {
369+
const element = [...document.querySelectorAll("div")].find((el) =>
347370
el.firstChild?.textContent?.trim().startsWith(t),
348371
);
349-
element?.setAttribute('data-test-id', 'follower');
372+
element?.setAttribute("data-test-id", "follower");
350373
}, text);
351374
return page.locator('[data-test-id="follower"]');
352375
}
353376

354377
function expectKeptAdvancing(run: Awaited<ReturnType<typeof busyGlide>>) {
355378
expect(run.busy.spanMs).toBeGreaterThanOrEqual(BLOCK_MS);
356-
expect(run.glides.length, 'a glide carries the follower').toBeGreaterThan(0);
379+
expect(run.glides.length, "a glide carries the follower").toBeGreaterThan(0);
357380
expect(run.proof.verdict.failures, run.summary).toEqual([]);
358381
expect(run.proof.monotonic, run.summary).toBe(true);
359382
}
360383

361-
test.describe('spec:AST-094 FR5: the shared glide keeps advancing through a blocked main thread', () => {
362-
test('the content after a Collapsible keeps moving on the frames the compositor control moves', async ({
384+
test.describe("spec:AST-094 FR5: the shared glide keeps advancing through a blocked main thread", () => {
385+
test("the content after a Collapsible keeps moving on the frames the compositor control moves", async ({
363386
page,
364387
}) => {
365-
await openStory(page, 'core-animated-layout--animated-layout');
366-
const follower = await markAppDiv(page, 'A plain app div');
388+
await openStory(page, "core-animated-layout--animated-layout");
389+
const follower = await markAppDiv(page, "A plain app div");
367390
expectKeptAdvancing(
368-
await busyGlide(page, 'collapsible', {
369-
trigger: page.getByRole('button', {name: 'Shipping details'}),
391+
await busyGlide(page, "collapsible", {
392+
trigger: page.getByRole("button", { name: "Shipping details" }),
370393
follower,
371394
}),
372395
);
373396
});
374397

375-
test('the rows after a TreeList branch keep moving on the frames the compositor control moves', async ({
398+
test("the rows after a TreeList branch keep moving on the frames the compositor control moves", async ({
376399
page,
377400
}) => {
378-
await openStory(page, 'core-animated-layout--animated-layout');
401+
await openStory(page, "core-animated-layout--animated-layout");
379402
expectKeptAdvancing(
380-
await busyGlide(page, 'treelist', {
403+
await busyGlide(page, "treelist", {
381404
trigger: page.locator('[data-tree-id="docs"] [data-tree-toggle]'),
382405
follower: page.locator('[data-tree-id="notes"]'),
383406
}),
384407
);
385408
});
386409

387-
test('the rows after a Table row keep moving on the frames the compositor control moves', async ({
410+
test("the rows after a Table row keep moving on the frames the compositor control moves", async ({
388411
page,
389412
}) => {
390-
await openStory(page, 'core-tablerowexpansion--gliding-rows');
413+
await openStory(page, "core-tablerowexpansion--gliding-rows");
391414
// A row takes no child, so its first cell, which rides its glide, carries
392415
// the marker.
393416
expectKeptAdvancing(
394-
await busyGlide(page, 'table-row', {
395-
trigger: page.locator('[data-expansion-toggle]').first(),
417+
await busyGlide(page, "table-row", {
418+
trigger: page.locator("[data-expansion-toggle]").first(),
396419
follower: page
397-
.locator('tr[data-expansion-key]')
420+
.locator("tr[data-expansion-key]")
398421
.nth(1)
399-
.locator('td')
422+
.locator("td")
400423
.first(),
401424
}),
402425
);

0 commit comments

Comments
 (0)