Skip to content

Commit 3e35bda

Browse files
committed
fix(interaction-harness): the first busy self-test lets a rendering update land before its rAF block, and the gates never count the busy control's own animation
astracat found two gaps on 1ca51a4. 1. The rAF run blocked right after cancelling the compositor run's still-running animation. With no rendering update between the cancel and the block, the compositor kept playing the cancelled animation into the block, so the rAF mutant read 6 to 8 changed frames. The run now waits two animation frames before blocking. A probe that cancels and then blocks at once kept moving in 1 of 8 Chromium runs here (27 changed frames); with two frames first, 0 of 8. 2. Inside a dialog (`within`), the control's endless animation answered `waitForAnimation(dialog)` and `blockMainThread`'s `during: dialog`, so a backdrop proof could block before its dim ran. Both gates now skip any animation inside `[data-harness-control]`. Red first: on a dialog that animates nothing else, both gates resolved at once. Now both keep waiting until the dialog's own animation runs, 6 of 6 in Chromium and in WebKit.
1 parent 4259a40 commit 3e35bda

4 files changed

Lines changed: 64 additions & 4 deletions

File tree

‎internal/interaction-harness/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ dialog's backdrop mounts the control inside the dialog with
175175
`startBusyControl(page, {within: dialog})`, a plain fixed box with no top-layer
176176
entry: in WebKit, with the popover above BottomSheet's open modal dialog, the
177177
sheet's dim held for 155 to 225 ms into a block while the control moved, and
178-
inside the dialog it moves in step with the sheet. Track it from the
178+
inside the dialog it moves in step with the sheet. `waitForAnimation` and
179+
`blockMainThread`'s `during` never count the control's own animation, so on
180+
a dialog they still wait for the backdrop's. Track it from the
179181
same screencast (`trackMarker(page, frames, {rgb: CONTROL_RGB})`) and pass it
180182
as `control`: the component passes when it moved on every frame the control
181183
moved and its longest stall is no longer than the control's. Both are read from

‎internal/interaction-harness/src/busy.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ const CONTROL_TRAVEL = 240;
4343
* open modal dialog), as a plain fixed box with no top-layer entry, for a
4444
* proof of the dialog's `::backdrop`: in WebKit, with the popover above
4545
* BottomSheet's open modal dialog, the sheet's dim held for 155 to 225 ms
46-
* into a block while the control moved. Start it before the block: it
46+
* into a block while the control moved. `waitForAnimation` and
47+
* `blockMainThread`'s `during` never count the control's own animation, so
48+
* they still wait for the dialog's. Start it before the block: it
4749
* resolves once the animation is running and past its first frame (on the
4850
* compositor; see `blockMainThread`). Keep the component's marker out of the
4951
* strip it crosses (the top `CONTROL_SIDE` px, `CONTROL_SIDE +
@@ -176,8 +178,9 @@ export interface BusyWindow {
176178
* holds that hand-off, and even a compositor animation freezes. To catch a
177179
* settle near its start, call it before the release that starts the settle and
178180
* await it after: the page is already waiting when the animation begins. Any
179-
* animation inside `during` counts, so pick an element that runs nothing
180-
* else meanwhile.
181+
* animation inside `during` counts but the busy-window control's own
182+
* (`startBusyControl`, mounted inside a dialog with `within`), so pick an
183+
* element that runs nothing else meanwhile.
181184
*
182185
* An animation counts once it is no longer pending and has run at least one
183186
* frame (`minProgressMs` below 16 ms is raised to 16). One created in the
@@ -227,11 +230,21 @@ export async function blockMainThread(
227230
const frame = gate?.frame ?? window.requestAnimationFrame.bind(window);
228231
const later = gate?.timeout ?? window.setTimeout.bind(window);
229232
const deadline = performance.now() + wait;
233+
// The busy-window control animates on its own, inside a dialog with
234+
// `within`: it never stands for the animation under test.
235+
const isControl = (a: Animation) => {
236+
const target = (a.effect as KeyframeEffect | null)?.target ?? null;
237+
return (
238+
target instanceof Element &&
239+
target.closest('[data-harness-control]') != null
240+
);
241+
};
230242
const tick = () => {
231243
const running = element
232244
.getAnimations({subtree: true})
233245
.some(
234246
a =>
247+
!isControl(a) &&
235248
a.playState === 'running' &&
236249
!a.pending &&
237250
Number(a.currentTime ?? 0) >= minProgress,

‎internal/interaction-harness/src/curves.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,12 +981,23 @@ export async function waitForAnimation(
981981
(target === element || element.contains(target))
982982
);
983983
};
984+
// The busy-window control (busy.ts) animates on its own, inside a
985+
// dialog with `within`: it never answers for the component.
986+
const isControl = (a: Animation) => {
987+
const target =
988+
(a.effect as KeyframeEffect | null)?.target ?? null;
989+
return (
990+
target instanceof Element &&
991+
target.closest('[data-harness-control]') != null
992+
);
993+
};
984994
const after = watchedFrom ?? recorder.armedAt();
985995
// Document-timeline animations only, as for holdAnimations: a scroll-
986996
// or view-timeline one that reached its end is not a finished curve.
987997
const recorded = recorder.log.filter(
988998
e =>
989999
e.seenAt >= after &&
1000+
!isControl(e.animation) &&
9901001
(inside(e.animation) || e.ancestors.includes(element)) &&
9911002
e.animation.timeline instanceof DocumentTimeline,
9921003
);
@@ -1004,6 +1015,7 @@ export async function waitForAnimation(
10041015
.map(e => e.animation)
10051016
).filter(
10061017
a =>
1018+
!isControl(a) &&
10071019
a.playState === 'running' &&
10081020
a.timeline instanceof DocumentTimeline,
10091021
);

‎internal/interaction-harness/src/harness.interaction.browser.spec.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,14 @@ test.describe('frame evidence', () => {
387387
requestAnimationFrame(step);
388388
}
389389
}, driver);
390+
// A rendering update first: until one commits the cancel, the
391+
// compositor keeps playing the previous run's animation into the block.
392+
await page.evaluate(
393+
() =>
394+
new Promise<void>(resolve =>
395+
requestAnimationFrame(() => requestAnimationFrame(() => resolve())),
396+
),
397+
);
390398
const window = await blockMainThread(
391399
page,
392400
blockMs,
@@ -690,6 +698,31 @@ test.describe('frame evidence', () => {
690698
expect(proof.verdict.failures, proof.summary).toEqual([]);
691699
});
692700

701+
test("waitForAnimation and blockMainThread's during never count the control's own animation inside a dialog", async ({
702+
page,
703+
}) => {
704+
await page.setContent(
705+
'<dialog id="d" style="width:200px;height:200px">still</dialog>',
706+
);
707+
await page.evaluate(() =>
708+
(document.getElementById('d') as HTMLDialogElement).showModal(),
709+
);
710+
const dialog = page.locator('#d');
711+
const control = await startBusyControl(page, {within: dialog});
712+
// The dialog animates nothing of its own: both gates keep waiting.
713+
await expect(
714+
blockMainThread(page, 100, {during: dialog, timeout: 600}),
715+
).rejects.toThrow(/no animation started/);
716+
await expect(waitForAnimation(dialog, {timeout: 600})).rejects.toThrow();
717+
// Its own animation answers both.
718+
await dialog.evaluate(el =>
719+
el.animate([{opacity: 1}, {opacity: 0.5}], {duration: 2000}),
720+
);
721+
await waitForAnimation(dialog);
722+
await blockMainThread(page, 100, {during: dialog});
723+
await control.remove();
724+
});
725+
693726
test('a hold that starts before the block is judged from its first presented change inside it; a single change and then a freeze still fails', async ({
694727
page,
695728
}) => {

0 commit comments

Comments
 (0)