Skip to content

Commit 453dcde

Browse files
committed
test(interaction-harness): the animator spec reads its control on the harness clock, and core's copy goes
The harness controlClock duplicated core's motion/__tests__/controlClock.ts, and the two already disagreed: core's left out only 24 px at a turn, and it read a repeated frame at its stale position. The animator's busy-window proof now reads `controlClock(control)` from the harness, over the whole screencast, and core's copy and its test go. Their two edge cases move into busy.clock.test.ts: a turn between the first two usable frames, and a first frame stamped 50 ms late. The README now says that a control mounted `within` a dialog moves with it, so trackMarker tracks it; trackControl searches only the top strip.
1 parent 46ee9c5 commit 453dcde

5 files changed

Lines changed: 38 additions & 163 deletions

File tree

‎internal/interaction-harness/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ entry: in WebKit, with the popover above BottomSheet's open modal dialog, the
218218
sheet's dim held for 155 to 225 ms into a block while the control moved, and
219219
inside the dialog it moves in step with the sheet. `waitForAnimation` and
220220
`blockMainThread`'s `during` never count the control's own animation, so on
221-
a dialog they still wait for the backdrop's. Track it from the
222-
same screencast with `trackControl(page, frames)` (`trackMarker` with
223-
`CONTROL_RGB`, searching only the strip it crosses) and pass it as `control`: the component passes when it moved on every frame the control
221+
a dialog they still wait for the backdrop's. Track a top-layer control from
222+
the same screencast with `trackControl(page, frames)` (`trackMarker` with
223+
`CONTROL_RGB`, searching only the top strip it crosses). A control mounted
224+
`within` a dialog moves with it, so track that one with `trackMarker(page,
225+
frames, {rgb: CONTROL_RGB})`. Pass either as `control`: the component passes when it moved on every frame the control
224226
moved and its longest stall is no longer than the control's. Both are read from
225227
the same screencast frames, so a compositor animation misses none. A window in
226228
which the control moved on fewer than four frames fails, since the machine

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* @output The control's clock. Its readings follow the control's animation
77
* time across turns and gaps, whatever the stamps say, also for frames
88
* stamped late and put out of order. A frame near a turn, or one that
9-
* repeats the position before it, gets no reading.
9+
* repeats the position before it, gets no reading. Includes the cases of
10+
* the animator spec's former clock.
1011
* @position Unit test of ./busy's controlClock
1112
*/
1213

@@ -125,6 +126,28 @@ describe('controlClock', () => {
125126
expect(read.length).toBeGreaterThan(frames.length / 2);
126127
});
127128

129+
it('reads the first usable frame and the next one right when a turn lies between them', () => {
130+
// At 338.3 ms the box is at 203 px on its way out, just inside the band.
131+
// The frames after it sit within 36 px of the end until 466.3 ms. There
132+
// the next usable frame is at 200.2 px, on its way back.
133+
const times = Array.from({length: 60}, (_, i) => 338 + 1 / 3 + i * 16);
134+
const frames = control(times);
135+
const clock = controlClock(frames);
136+
expect(clock.has(frames[0].t)).toBe(true);
137+
expect(frames.slice(1, 8).some(frame => clock.has(frame.t))).toBe(false);
138+
expect(clock.has(frames[8].t)).toBe(true);
139+
expectAnimationTimes(clock, timesByStamp(times, frames));
140+
});
141+
142+
it('reads every frame at its own time when the first frame is stamped 50 ms late', () => {
143+
// The late first frame does not set the origin, so it moves no reading.
144+
const times = Array.from({length: 60}, (_, i) => 100 + i * 16);
145+
const frames = control(times, i => (i === 0 ? 50 : 0));
146+
const clock = controlClock(frames);
147+
expect(clock.has(frames[0].t)).toBe(true);
148+
expectAnimationTimes(clock, timesByStamp(times, frames));
149+
});
150+
128151
it('gives no reading to a frame that repeats the position before it', () => {
129152
// The second frame shows the first frame's position, stamped a frame later.
130153
const frames = control([100, 100, 150], i => (i === 1 ? FRAME : 0));

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
type BlockedWindow,
2828
busyWindowProof,
2929
CONTROL_RGB,
30+
controlClock,
3031
countBetween,
3132
markElement,
3233
startBusyControl,
@@ -38,7 +39,6 @@ import {expect, test, type Page} from '@playwright/test';
3839
import {build} from 'esbuild';
3940
import type {Animator, MotionHandle} from '../animator';
4041
import type * as MotionBundle from './motionBundle';
41-
import {controlClock} from './controlClock';
4242

4343
let script = '';
4444

@@ -221,18 +221,17 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
221221
},
222222
);
223223
const [curve, faster] = curveMs;
224-
const controlAt = new Map(
225-
control.flatMap(f => (f.box == null ? [] : [[f.t, f.box.x] as const])),
226-
);
227224
// The control's own time at each frame (controlClock): 240 px out in
228225
// 400 ms, back in 400 ms, read from its position on the origin most frames
229226
// agree with, so no one frame's stamp or direction sets it.
230-
const clock = controlClock(
231-
inside.map(f => ({t: f.t, x: controlAt.get(f.t) ?? null})),
232-
);
227+
const clock = controlClock(control);
228+
const timed = inside.flatMap((f, i) => {
229+
const ms = clock.get(f.t);
230+
return ms == null ? [] : [{i, ms}];
231+
});
233232
/** How far the box's curve time drifts from the control's, ms. */
234233
const drift = (times: number[]) => {
235-
const gaps = clock.map(({i, ms}) => times[i] - ms).sort((x, y) => x - y);
234+
const gaps = timed.map(({i, ms}) => times[i] - ms).sort((x, y) => x - y);
236235
return (
237236
gaps[Math.floor(gaps.length * 0.9)] - gaps[Math.floor(gaps.length * 0.1)]
238237
);
@@ -246,7 +245,7 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
246245
sorted[Math.floor(sorted.length * 0.9)] -
247246
sorted[Math.floor(sorted.length * 0.1)];
248247
const read = {
249-
frames: clock.length,
248+
frames: timed.length,
250249
drift: drift(curve),
251250
faster: drift(faster),
252251
median,
@@ -258,7 +257,7 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
258257
});
259258
// Placed on its curve and on the control's, every frame is the same time
260259
// apart, to within the 1 px steps of both; a spring 10% off drifts.
261-
expect(clock.length, JSON.stringify(read)).toBeGreaterThan(20);
260+
expect(timed.length, JSON.stringify(read)).toBeGreaterThan(20);
262261
expect(read.drift, JSON.stringify(read)).toBeLessThan(12);
263262
expect(read.faster, JSON.stringify(read)).toBeGreaterThan(24);
264263
if (browserName === 'chromium') {

‎packages/core/src/motion/__tests__/controlClock.test.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎packages/core/src/motion/__tests__/controlClock.ts‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)