Files
leaguerecorder/app/vendor/rune/scripts/web-clock-smoke.mjs
T
vhaudiquet 5bf262b82b app: cherry-pick rune's pause and sound fixes onto the checkout
Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch
ported, carrying the four commits of upstream issues 1320 (a pause while
a clip is layered holds the layer's picture and time) and 1325 (a video's
sound is read ahead of the clock and leads it). Both were written against
eb9f1104 and ported across the refactors since. The faults are the first
two and the third in docs/rune-upstream.md; the app's workarounds in
review.rs stay until the fixes arrive upstream.
2026-11-22 22:16:30 +01:00

44 lines
2.2 KiB
JavaScript

// A page's fake clock drives Rune's frames, even one installed after the app started
// (Playwright's `clock.install`): with the clock paused, a touch fling's momentum waits for
// `runFor` instead of finishing in real time. Chromium only (touch comes from CDP).
import assert from 'node:assert/strict';
export async function clockSmoke(browser, url) {
// Its own context: Playwright's clock belongs to a context, and would pause the other pages.
const context = await browser.newContext({ viewport: { width: 390, height: 760 }, deviceScaleFactor: 3, hasTouch: true, isMobile: true });
const page = await context.newPage();
try {
await page.addInitScript(() => {
window.__submits = 0;
const submit = GPUQueue.prototype.submit;
GPUQueue.prototype.submit = function (...args) { window.__submits++; return submit.apply(this, args); };
});
await page.goto(url);
await page.waitForFunction(() => window.__submits > 0, { timeout: 30000 });
await page.waitForTimeout(1000);
await page.clock.install();
await page.clock.pauseAt(await page.evaluate(() => Date.now() + 1000));
const cdp = await context.newCDPSession(page);
const touch = (type, y) => cdp.send('Input.dispatchTouchEvent', { type, touchPoints: type === 'touchEnd' ? [] : [{ x: 180, y }] });
await touch('touchStart', 180);
for (let i = 1; i <= 10; i++) {
await touch('touchMove', 180 + 30 * i);
await page.clock.runFor(16);
}
await touch('touchEnd', 480);
await page.clock.runFor(16);
// Two seconds of real time with the page clock paused: the fling must not move on.
await page.waitForTimeout(2000);
await page.clock.runFor(16);
const a = await page.screenshot();
await page.clock.runFor(32);
assert.ok(!a.equals(await page.screenshot()), 'momentum follows the paused page clock, not real time');
await page.clock.runFor(5000);
const settled = await page.screenshot();
await page.clock.runFor(100);
assert.ok(settled.equals(await page.screenshot()), 'momentum settles as the page clock runs');
} finally {
await context.close();
}
}