issennknight on Discord (macOS 13.7.8, v0.1.1902), afterf92db4cdd: "路由 用量 页面 刚点开并滚动页面时会抖动复位". Two causes, both in the window's own scroll guard, which every page takes: 1. A load landing under the wheel (show()'s back on the page's first reads, loadProvidersNow's put-back after render) called backToReader with the place last heard of. The page hears of a scroll a frame or more late (WebKit scrolls off the main thread; a loaded Mac), so each load took the reader's last steps back and stopped their coast. backAfterLoad now keeps a view that has gone on the way the reader's own scrolls go (readerWay, set from each of theirs) as theirs, and puts back only a move against it (a redraw's clamp). 2. On macOS 13's WebKit (16.6) the page never hears the wheel. Every gesture's first scrolls were put back until three the same way made a run (puttingBack): a shake at the start of each gesture, a page just opened included. The first run given back is now remembered (localStorage magpie.unheardWheels, for the next start too); from then on a scroll at rest waits 120ms before it is put back (waitsBack), and a second the same way within 80ms, the page's height unchanged between them, is the reader's at once (code's two scrolls in a row, 100ms apart in view-wheel-unheard, are both put back). A lone scroll (a redraw's, code's) is still put back, 120ms later; one under a click's hold at once, as before. What the wait puts back is recorded as an at-once put-back is, so a wheel heard later than the wait (a loaded machine) still gives it back (givesBack). Not changed: the browser's scroll anchoring. It lowers scrollTop as data comes in above with what's on the screen still; the test tells that from a put-back (view up and what was under the pointer going down with it). Nothing between v0.1.1902 and425a61322touched this guard (68 commits; none in backToReader, readerScrolls, readerLeaves, puttingBack or overflow-anchor), and no view has smooth scrolling. Size budgets: app.js 1,313,704, the core 1,532,830 (main's plus 1,969), both the guard's own, with no room added. Tests: - New view-open-wheel.test.cjs: Usage and Routing, opened and opened again, the first data held until the wheel is going; the page told of each scroll 80ms late (late) or never (unheard, a capture listener stopping the wheel, learned on the Agents page first); every frame's place and every write moving a view up are recorded. en, zh, zh-TW, ja, de; 420 and 1000 wide; Chromium and WebKit. 162/162 on this tree (mote). - Broken by hand: on the base's assets (425a61322) 117/162 red: late Routing 31, late Usage 4 (210 to 180 under the wheel), unheard all 80 ("nothing put the view back up": 30, 30, 30 put back each gesture). With backAfterLoad but no waitsBack, the unheard half was 80/80 red the same way; with waitsBack but readerAt unset taken as no move, red too (found by logging each write's stack), fixed to 0 as backToReader reads it. - click-scroll.test.cjs: new subtest, a wheel heard 250ms late with the unheard wheels learned still scrolls the view. Red in both engines (Windows, 2 of 2 runs) with the wait's put-back not recorded, 24/24 green with it (3 of 3). Found from the whole suite's first run: under WSL's load, click-scroll's late-heard wheel subtest went red in webkit, which learned the unheard wheels from a run put back. - Also tried and dropped: .view { overflow-anchor: none }. It only silenced a scrollTop-only check; anchoring moves nothing on screen. - TestCoreScriptBudget ok (mote); gofmt -l clean. - After the rebase onto2f5548371: TestCoreScriptBudget and the app.js budget ok (mote); view-open-wheel, view-wheel-unheard, click-scroll on mote under another session's suite (load 16 to 35): 192/192 once, and 1 of 80 unheard subtests red once (#4132: under load the driver's second wheel comes after waitsBack's 120ms). - Rebased ontoc3462d5fe(main's GUI changes: context.js, i18n.js, the Codex auto-reset title; none in the scroll guard). app.js budget ok (mote). TestCoreScriptBudget is red by 670 bytes atc3462d5feitself (1,531,531 > 1,530,861, #4133, taken by another session); this commit adds its own 1,969 to both, so the core stays 670 over, not more. The four scroll files on WSL: chromium all green; Linux WebKit red in click-scroll, view-wheel-unheard and view-wheel-after-click as at2f5548371, and 7 of 80 view-open-wheel unheard subtests (a first gesture's put-backs before the run is learned, the #4132 class). On mote at load 81 (another session's full GUI suite) 14 of 113 red, mostly 5s click timeouts; not counted as a run. - Whole GUI suite at this tree, WSL magpie-desktop (mote had another session's suite): 14,519 tests, 14,263 pass, 256 red. Every red file is named on #4120 / #4121 (Linux reds at main) or was run alone at2f5548371and is red there the same: routing-rule-models, recent-calls-more, searcher-pick, usage-ledger-chart, list-sort (#4131), click-scroll's late-heard wheel, inner-scroll-contain, view-wheel-after-click and view-wheel-unheard in WebKit on Linux (base 9 to 10 red, this tree 4 to 9). Recorded on #4120. - Tried and dropped: a check in waitsBack's timer for a view gone on further untold. It took a code scroll whose event was still pending under load as the reader's (view-wheel-unheard webkit red on mote). Not tried: a real macOS 13 WebKit 16.6 (none here). The unheard case is an emulation (wheels stopped before the page), the same one view-wheel-unheard and view-wheel-after-redraw use. The first gesture of a fresh install on macOS 13 still shakes once, until the run is seen.
358 lines
20 KiB
JavaScript
358 lines
20 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A click never moves the page: what was clicked stays where it is on the
|
|
// screen, and code scrolls a view only with the reader's click in hand.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const now = new Date();
|
|
const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
|
|
const at = (i) => new Date(now.getTime() - (i + 1) * 60e3).toISOString();
|
|
const who = { id: "fixture-key", provider: "fixture", name: "Fixture", who: "key-1", kind: "key", model: "model-a", routing: "", used: 0 };
|
|
const routes = Array.from({ length: 12 }, (_, i) => ({
|
|
id: 100 - i, seq: 100 - i, time: at(i), agent: "fixture", model: "model-a", provider: "fixture",
|
|
order: [who], tries: [{ id: who.id, model: "model-a", start: at(i), done: true, status: 200, ms: 1200 }],
|
|
done: true, status: 200, ms: 1200, tokens: 3000,
|
|
}));
|
|
const state = { agents: [{ id: "fixture", name: "Fixture", path: "/test/config.toml", fields: [] }], profiles: [], settings: { lang: "en", theme: "light" } };
|
|
|
|
async function serve(route) {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: 'window.bootPrefs = {lang:"en",theme:"light",web:true};' });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
// live keeps none: the gateway started a moment ago; the day has them
|
|
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
|
|
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") {
|
|
const d = url.searchParams.get("day");
|
|
return json({ cut: false, days: [{ day, requests: routes.length }], routes: d ? routes : [] });
|
|
}
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
await route.fulfill({ body: await fs.readFile(file), contentType });
|
|
}
|
|
|
|
const view = "#view-routing";
|
|
const top = (page, sel) => page.locator(sel).evaluate((e) => e.getBoundingClientRect().top);
|
|
const settle = (page) => page.waitForTimeout(900);
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(engine + ": a click never moves the page", async (t) => {
|
|
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 640 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
// The request/session grouping buttons also use rt-day. Wait for and
|
|
// click only the date bar, including while its history is loading.
|
|
const dayButtons = page.locator(".rt-days .rt-day");
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve);
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, engine + "-click.png") });
|
|
}
|
|
await browser.close();
|
|
});
|
|
// wide: the accounts sit beside the requests (a Routing area of 1150px
|
|
// or more, 5d871723), so the view ends with the date bar still in sight
|
|
// and Live, with none, leaves the page shorter; narrower, the accounts
|
|
// go below and the bar scrolls away first
|
|
async function reset(width = 1100) {
|
|
await page.setViewportSize({ width, height: 640 });
|
|
await page.goto("http://magpie.test/?view=routing");
|
|
await dayButtons.nth(1).waitFor();
|
|
}
|
|
// the reader scrolls the view till sel is y under its top, or less
|
|
async function scrollTo(sel, y = 300) {
|
|
const box = await page.locator(view).boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 40);
|
|
for (let i = 0; i < 150 && (await top(page, sel)) - box.y > y; i++) {
|
|
// An unchanged frame need not mean the end: WebKit can still be
|
|
// applying the previous wheel event. Check the scroll boundary.
|
|
if (await page.locator(view).evaluate((v) => v.scrollTop + v.clientHeight >= v.scrollHeight - 1)) break;
|
|
await page.mouse.wheel(0, 20);
|
|
await page.waitForTimeout(20);
|
|
}
|
|
await page.waitForTimeout(300);
|
|
assert((await top(page, sel)) > box.y, "what's clicked must be in sight, or the click itself scrolls to it");
|
|
assert(await page.locator(view).evaluate((v) => v.scrollTop > 0), "the view must have scrolled");
|
|
}
|
|
|
|
await t.test("date controls stay separate from request grouping controls", async () => {
|
|
await reset();
|
|
assert.equal(await page.locator(".rt-group-by .rt-day").count(), 2, "the grouping controls share the date-button class");
|
|
assert.equal(await dayButtons.count(), 2, "only Live and the fixture's history day should be selected");
|
|
assert.match(await dayButtons.first().innerText(), /Live/);
|
|
await dayButtons.nth(1).click();
|
|
await page.locator(".rt-req").first().waitFor();
|
|
assert.equal(await dayButtons.nth(1).getAttribute("aria-pressed"), "true");
|
|
assert.equal(await page.locator(".rt-group-by .rt-day").first().getAttribute("aria-pressed"), "true", "picking a day preserves By request");
|
|
});
|
|
|
|
await t.test("Live and a day, picked in turn, stay under the pointer", async () => {
|
|
await reset(1440);
|
|
await dayButtons.nth(1).click(); // the day's requests, the list full
|
|
await settle(page);
|
|
// down to the list's end: Live, with none, leaves the page shorter
|
|
await scrollTo(".rt-days", 0);
|
|
assert(await page.locator(view).evaluate((v) => v.scrollTop + v.clientHeight >= v.scrollHeight - 2), "the view must be at its end");
|
|
for (const i of [0, 1, 0, 1]) {
|
|
const chip = dayButtons.nth(i), was = await top(page, ".rt-days");
|
|
await chip.click();
|
|
await settle(page);
|
|
assert.equal(await dayButtons.nth(i).getAttribute("aria-pressed"), "true");
|
|
const is = await top(page, ".rt-days");
|
|
assert(Math.abs(is - was) <= 1, `picking ${i ? "the day" : "Live"} moved the page ${Math.round(is - was)}px`);
|
|
}
|
|
});
|
|
|
|
await t.test("a request picked in the list, and Replay them all, stay under the pointer", async () => {
|
|
await reset();
|
|
await dayButtons.nth(1).click();
|
|
await settle(page);
|
|
for (const i of [3, 7, 5]) {
|
|
const row = () => page.locator(".rt-req").nth(i);
|
|
await scrollTo(`.rt-req >> nth=${i}`);
|
|
// the list scrolls on its own: the reader brings the row into it
|
|
// (the click would, before it is measured)
|
|
const list = await page.locator(".rt-reqs").boundingBox();
|
|
await page.mouse.move(list.x + list.width / 2, list.y + 20);
|
|
for (let k = 0; k < 40; k++) {
|
|
const b = await row().boundingBox();
|
|
if (b.y + b.height <= list.y + list.height && b.y >= list.y) break;
|
|
await page.mouse.wheel(0, b.y < list.y ? -20 : 20);
|
|
await page.waitForTimeout(20);
|
|
}
|
|
await page.waitForTimeout(300);
|
|
const was = await row().evaluate((e) => e.getBoundingClientRect().top);
|
|
await row().click();
|
|
await settle(page);
|
|
assert.equal(await row().getAttribute("aria-pressed"), "true");
|
|
const is = await row().evaluate((e) => e.getBoundingClientRect().top);
|
|
assert(Math.abs(is - was) <= 1, `picking request ${i} moved the page ${Math.round(is - was)}px`);
|
|
}
|
|
const reqs = ".rt-req >> nth=0";
|
|
const was = await top(page, reqs);
|
|
await page.getByRole("button", { name: "Replay them all" }).click();
|
|
await settle(page);
|
|
const is = await top(page, reqs);
|
|
assert(Math.abs(is - was) <= 1, `Replay them all moved the list ${Math.round(is - was)}px`);
|
|
});
|
|
|
|
await t.test("code can't take the page from a click", async () => {
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => {
|
|
const s = document.createElement("div");
|
|
s.style.cssText = "flex:none;height:1600px";
|
|
const mk = (id, fn) => { const b = document.createElement("button"); b.id = id; b.textContent = id; b.style.flex = "none"; b.onclick = fn; return b; };
|
|
const above = document.createElement("div");
|
|
above.style.flex = "none";
|
|
v.prepend(above);
|
|
v.append(s,
|
|
// sets scrollTop outright
|
|
mk("jump", () => { v.scrollTop = 0; }),
|
|
// the page above it grows when a load comes in
|
|
mk("grow", () => setTimeout(() => { above.style.height = "400px"; }, 300)),
|
|
// redraws itself, and everything after it
|
|
mk("redraw", (e) => { const b = e.currentTarget, c = b.cloneNode(true); c.onclick = b.onclick; above.style.height = "120px"; b.replaceWith(c); }),
|
|
// says it's on purpose, but with no click in hand
|
|
mk("sneak", () => setTimeout(() => { scrollOnPurpose(); v.scrollTop = 0; }, 50)),
|
|
// scrollIntoView from a helper a click only shares
|
|
mk("helper", () => setTimeout(() => document.querySelector("#rt").scrollIntoView(), 50)),
|
|
document.createElement("div"));
|
|
v.lastChild.style.cssText = "flex:none;height:600px";
|
|
});
|
|
for (const id of ["jump", "grow", "redraw", "sneak", "helper"]) {
|
|
await scrollTo("#" + id);
|
|
const was = await top(page, "#" + id);
|
|
await page.locator("#" + id).click();
|
|
await settle(page);
|
|
const is = await top(page, "#" + id);
|
|
assert(Math.abs(is - was) <= 1, `${id} moved the page ${Math.round(is - was)}px`);
|
|
}
|
|
});
|
|
|
|
// The browser tells of a scroll at the next frame. A scroll by code made
|
|
// just before a click, and heard of only after it, was kept as where the
|
|
// reader was (#1554: Playwright's click scrolled the skill picker's chip
|
|
// into view while the view slid in, and the view stayed 5px down).
|
|
await t.test("a scroll the page hears of after the click is still put back", async () => {
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => {
|
|
const s = document.createElement("div");
|
|
s.style.cssText = "flex:none;height:1600px";
|
|
const b = document.createElement("button");
|
|
b.id = "late"; b.textContent = "late"; b.style.flex = "none";
|
|
v.append(s, b, Object.assign(document.createElement("div"), { style: "flex:none;height:600px" }));
|
|
});
|
|
await scrollTo("#late");
|
|
const was = await page.locator(view).evaluate((v) => v.scrollTop);
|
|
// the scroll and the click in one task: no frame between them
|
|
await page.locator(view).evaluate((v) => { v.scrollTop += 40; document.querySelector("#late").click(); });
|
|
await settle(page);
|
|
assert.equal(await page.locator(view).evaluate((v) => v.scrollTop), was, "the scroll before the click must be put back");
|
|
});
|
|
|
|
await t.test("a control under what it unrolls goes down with it", async () => {
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => {
|
|
const s = document.createElement("div");
|
|
s.style.cssText = "flex:none;height:1600px";
|
|
const part = document.createElement("div");
|
|
part.id = "part"; part.style.flex = "none";
|
|
const head = document.createElement("div");
|
|
head.id = "head"; head.textContent = "head";
|
|
const fold = document.createElement("div");
|
|
const b = document.createElement("button");
|
|
b.id = "more"; b.textContent = "more"; b.dataset.unrolls = "";
|
|
b.onclick = () => { fold.style.height = "300px"; };
|
|
part.append(head, fold, b);
|
|
v.append(s, part, Object.assign(document.createElement("div"), { style: "flex:none;height:600px" }));
|
|
});
|
|
await scrollTo("#more");
|
|
const head = await top(page, "#head"), more = await top(page, "#more");
|
|
await page.locator("#more").click();
|
|
await settle(page);
|
|
assert(Math.abs((await top(page, "#head")) - head) <= 1, "what's above the fold must stay put");
|
|
assert(Math.abs((await top(page, "#more")) - more - 300) <= 1, "the control must go down with the rows");
|
|
});
|
|
|
|
await t.test("a click that asks to go somewhere does", async () => {
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => {
|
|
const s = document.createElement("div");
|
|
s.style.cssText = "flex:none;height:1600px";
|
|
const b = document.createElement("button");
|
|
b.id = "go"; b.textContent = "go"; b.style.flex = "none";
|
|
b.onclick = (e) => { if (scrollOnPurpose(e)) v.scrollTop = 0; };
|
|
v.append(s, b);
|
|
});
|
|
await scrollTo("#go");
|
|
await page.locator("#go").click();
|
|
await settle(page);
|
|
assert.equal(await page.locator(view).evaluate((v) => v.scrollTop), 0);
|
|
});
|
|
|
|
await t.test("the room kept for a click goes as the reader scrolls back", async () => {
|
|
await reset(1440);
|
|
await dayButtons.nth(1).click();
|
|
await settle(page);
|
|
await scrollTo(".rt-days", 0);
|
|
await dayButtons.nth(0).click(); // Live: none, the page shorter
|
|
await settle(page);
|
|
assert(await page.locator(view).evaluate((v) => !!v.querySelector(":scope > .view-room")), "room must be kept");
|
|
const box = await page.locator(view).boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
|
for (let i = 0; i < 30; i++) { await page.mouse.wheel(0, -40); await page.waitForTimeout(20); }
|
|
await page.waitForTimeout(300);
|
|
assert.equal(await page.locator(view).evaluate((v) => v.querySelector(":scope > .view-room")), null, "the room must go");
|
|
});
|
|
|
|
await t.test("the reader's wheel still scrolls after a click", async () => {
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => { const s = document.createElement("div"); s.style.cssText = "flex:none;height:1600px"; v.append(s); });
|
|
await dayButtons.nth(1).click();
|
|
const was = await page.locator(view).evaluate((v) => v.scrollTop);
|
|
const box = await page.locator(view).boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
|
await page.mouse.wheel(0, 300);
|
|
await page.waitForTimeout(400);
|
|
assert((await page.locator(view).evaluate((v) => v.scrollTop)) > was + 100, "the wheel must scroll the view");
|
|
});
|
|
|
|
// A busy Mac scrolls the view off the main thread and tells the page of
|
|
// the wheel only after the scroll (WebKit under load, panel-arrange's
|
|
// wheel to the foot put back to 0). The app's own wheel listener is told
|
|
// late here, with the browser's own trusted event, as it is then.
|
|
//
|
|
// Each check waits for the page to hear the wheel and for the reader's
|
|
// moment that opens (readerScrolls) to end, not for a fixed time: on a
|
|
// busy machine the 60ms timer ran late, the code's scroll then fell
|
|
// inside that moment and stood as the reader's, and later still the
|
|
// wheel was unheard when the view was looked at (#1660).
|
|
await t.test("a wheel the page hears of after its scroll is still the reader's", async () => {
|
|
await context.addInitScript(() => {
|
|
const add = EventTarget.prototype.addEventListener;
|
|
window.__wheelsHeard = 0;
|
|
const heard = (fn, e) => { try { fn(e); } finally { window.__wheelsHeard++; } };
|
|
window.addEventListener = function (type, fn, o) {
|
|
if (type !== "wheel") return add.call(this, type, fn, o);
|
|
return add.call(this, type, (e) => (window.__lateWheel ? setTimeout(() => heard(fn, e), window.__lateBy || 60) : heard(fn, e)), o);
|
|
};
|
|
});
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => { const s = document.createElement("div"); s.style.cssText = "flex:none;height:1600px"; v.append(s); });
|
|
await page.evaluate(() => { window.__lateWheel = true; });
|
|
const box = await page.locator(view).boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
|
const scrollTop = () => page.locator(view).evaluate((v) => v.scrollTop);
|
|
// the wheel, looked at once the page has heard it and the reader's
|
|
// moment it opened is over: what the view shows then stays
|
|
const wheel = async (dy) => {
|
|
const n = await page.evaluate(() => window.__wheelsHeard);
|
|
await page.mouse.wheel(0, dy);
|
|
await page.waitForFunction((n) => window.__wheelsHeard > n, n);
|
|
await page.waitForFunction(() => performance.now() >= purposeUntil);
|
|
};
|
|
// a scroll by code is put back at the frame it is told of
|
|
const frames = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => requestAnimationFrame(r)))));
|
|
for (const click of [false, true]) {
|
|
// with nothing clicked, and with a click held
|
|
if (click) await dayButtons.nth(1).click();
|
|
const was = await scrollTop();
|
|
await wheel(300);
|
|
assert((await scrollTop()) > was + 100, `the late-heard wheel must scroll the view${click ? " after a click" : ""}`);
|
|
}
|
|
// a scroll by code is still put back, the wheel that follows it not
|
|
// giving it to the reader
|
|
const was = await scrollTop();
|
|
await page.locator(view).evaluate((v) => { v.scrollTop -= 200; });
|
|
await frames();
|
|
assert.equal(await scrollTop(), was, "code's scroll is put back");
|
|
// the wheel made well after it: what was put back from 50ms before a
|
|
// wheel is taken as that wheel's own (givesBack); a busy machine only
|
|
// widens this gap
|
|
await page.waitForTimeout(100);
|
|
await wheel(-40);
|
|
assert(Math.abs((await scrollTop()) - (was - 40)) <= 1, "the wheel moves the view by its own step only");
|
|
await page.evaluate(() => { window.__lateWheel = false; });
|
|
});
|
|
|
|
// A window that has learned of wheels it never hears (macOS 13, or a run
|
|
// put back on a loaded machine) waits 120ms before it puts a scroll back
|
|
// (waitsBack). A wheel heard later still than that gives back what was
|
|
// put back, as it does at once.
|
|
await t.test("a wheel heard after the wait for unheard wheels is still the reader's", async () => {
|
|
await reset();
|
|
await page.evaluate(() => localStorage.setItem("magpie.unheardWheels", "1"));
|
|
await reset();
|
|
await page.locator(view).evaluate((v) => { const s = document.createElement("div"); s.style.cssText = "flex:none;height:1600px"; v.append(s); });
|
|
await page.evaluate(() => { window.__lateWheel = true; window.__lateBy = 250; });
|
|
const box = await page.locator(view).boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
|
const scrollTop = () => page.locator(view).evaluate((v) => v.scrollTop);
|
|
const was = await scrollTop(), n = await page.evaluate(() => window.__wheelsHeard);
|
|
await page.mouse.wheel(0, 300);
|
|
await page.waitForFunction((n) => window.__wheelsHeard > n, n);
|
|
await page.waitForFunction(() => performance.now() >= purposeUntil);
|
|
assert((await scrollTop()) > was + 100, "the wheel heard 250ms late must scroll the view");
|
|
await page.evaluate(() => { window.__lateWheel = false; window.__lateBy = 0; localStorage.removeItem("magpie.unheardWheels"); });
|
|
});
|
|
|
|
assert.deepEqual(errors, [], "page runtime errors");
|
|
});
|
|
}
|