Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {expect, test, type Page} from '@playwright/test';
import {build} from 'esbuild';
import type {Animator, MotionHandle} from '../animator';
import type * as MotionBundle from './motionBundle';
import {controlClock} from './controlClock';
import {CYCLE, controlClock} from './controlClock';

let script = '';

Expand Down Expand Up @@ -133,6 +133,13 @@ async function blockedRun(
// Before the animation, so it is on the compositor first; in the top
// strip, clear of the box (top 40 px) and its marker.
await startBusyControl(page);
// The control's start, epoch ms: its position then gives each frame's
// time without the frame's stamp.
const controlStart = await page.evaluate(() => {
const [animation] =
document.querySelector('[data-harness-control]')?.getAnimations() ?? [];
return performance.timeOrigin + Number(animation?.startTime ?? Number.NaN);
});
const cast = await startScreencast(page);
// The curve starts when the browser commits it (handle.started).
const start = await page.evaluate(
Expand All @@ -152,14 +159,17 @@ async function blockedRun(
const frames = await cast.stop();
const tracked = await trackMarker(page, frames);
const control = await trackMarker(page, frames, {rgb: CONTROL_RGB});
return {start, busy, tracked, control};
return {start, busy, tracked, control, controlStart};
}

test('a spring keeps advancing every frame through a 1 s main-thread block, on its curve', async ({
page,
browserName,
}) => {
const {start, busy, tracked, control} = await blockedRun(page, SLOW);
const {start, busy, tracked, control, controlStart} = await blockedRun(
page,
SLOW,
);
// Judged against what the compositor presented in the same window, not a
// display-rate bound: a loaded runner's compositor skips frames for every
// animation alike, and the harness reads a slow tail inside the block at
Expand All @@ -186,8 +196,8 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
// screencast's timestamps say (a loaded runner stamps some frames late).
// Placing the box's position on the analytic curve (inverting it), the
// spring must have advanced the same time over each such run of frames.
// Chromium also stamps frames on the page's clock, so there the median
// offset from the curve is near zero too.
// In Chromium the spring must also sit on its curve from its start
// (`fromStart` below).
const inside = tracked.filter(
f => f.box != null && f.t > busy.from + 20 && f.t < busy.to - 20,
);
Expand Down Expand Up @@ -240,6 +250,19 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
const offsets = inside.map((f, i) => f.t - start - curve[i]);
const sorted = [...offsets].sort((x, y) => x - y);
const median = sorted[Math.floor(sorted.length / 2)];
// The same offset at each frame's time as the control gives it: its time
// since its start, in the cycle the frame's stamp falls in. A loaded
// runner stamps frames late, which moves the stamped median (recorded) and
// not this one. Only Chromium stamps frames on the page's clock, so only
// there does a stamp tell the cycle.
Comment on lines +256 to +257

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, non-blocking: this reason may be stronger than needed. frames.ts rebases WebKit's monotonic stamps onto the wall clock "so both engines share the page's timeline", and the cycle choice here only needs a stamp within 400 ms of the page clock. In local WebKit runs of this test, fromStart read about -4 to -5 ms. If that holds on the WebKit CI job, the comment could say that the old 20 ms stamped check needed Chromium, not the cycle choice. A follow-up could also extend the bound to WebKit.

const fromControl = clock
.map(({i, ms}) => {
const sinceStart = inside[i].t - controlStart;
const controlMs = ms + CYCLE * Math.round((sinceStart - ms) / CYCLE);
return controlStart + controlMs - start - curve[i];
})
.sort((x, y) => x - y);
const fromStart = fromControl[Math.floor(fromControl.length / 2)];
// The offsets' spread reads the screencast's timestamps, which a loaded
// runner stamps late on some frames: recorded, judged by the drift instead.
const spread =
Expand All @@ -249,6 +272,7 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
frames: clock.length,
drift: drift(curve),
faster: drift(faster),
fromStart,
median,
spread,
};
Expand All @@ -262,7 +286,7 @@ test('a spring keeps advancing every frame through a 1 s main-thread block, on i
expect(read.drift, JSON.stringify(read)).toBeLessThan(12);
expect(read.faster, JSON.stringify(read)).toBeGreaterThan(24);
if (browserName === 'chromium') {
expect(Math.abs(median)).toBeLessThan(20);
expect(Math.abs(read.fromStart), JSON.stringify(read)).toBeLessThan(20);
}
});

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/motion/__tests__/controlClock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
* @file controlClock.ts
* @input Screencast frames: each one's timestamp and the harness's control
* box's x on it (240 px out in 400 ms, back in 400 ms, repeating)
* @output Exports controlClock: the control's own time at each usable frame
* @output Exports controlClock: the control's own time at each usable frame;
* and CYCLE, one out-and-back, ms
* @position Test support for animator.interaction.browser.spec.ts, whose
* busy-window proof reads the spring against the control's clock
*/

/** The control's speed, px per ms: 240 px in 400 ms. */
const SPEED = 0.6;
/** One out-and-back, ms. */
const CYCLE = 800;
export const CYCLE = 800;
/**
* Frames this near a turn are left out: there the two times a position
* gives are under 80 ms apart.
Expand Down