Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Suites: glass and motion frame by frame, and frame times in the real WebKitGTK

Yashwanth Kamireddi1f39a18a4e89
diff --git a/.uiverify/glass-frames.mjs b/.uiverify/glass-frames.mjs
new file mode 100644
index 0000000..c306e19
--- /dev/null
+++ b/.uiverify/glass-frames.mjs
@@ -0,0 +1,209 @@
+// What the window's chrome costs, frame by frame: the time between frames, as the engine gives
+// them, while a person does the things that make glass and motion work hardest — scrolling the
+// long lists under the toolbars (Photos, Notes, Drive), opening menus over them, sliding a
+// segmented control and switching apps. Prints one line per action (p50, p95, longest, how
+// many frames ran late) so a change to the material or the motion can be compared before and
+// after, in each engine; and checks the rules the chrome keeps everywhere:
+//
+// - no more than a few live blurs on screen at once, none inside anything that scrolls and
+// none on top of another (glass on glass), and none at all in WebKitGTK, which blurs what
+// is behind again on every frame of a scroll (tokens.css "Liquid Glass");
+// - nothing freezes: no frame held past the bound below.
+//
+// ENGINE=webkit node .uiverify/glass-frames.mjs
+// ENGINE=gtk node .uiverify/glass-frames.mjs (on a headless display only)
+// JSON=1 … prints the numbers as JSON too, for a table
+// GLASS=live … the blurred tier in WebKit too, to measure what it would cost there
+import http from "node:http";
+import { engine, engineName } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+
+const BASE = process.env.BASE ?? "http://localhost:4173";
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${m}`); if (!p) failures++; };
+
+// Photo-like pictures from the engine's own canvas, served from here (as photos-scroll does).
+const maker = await b.newPage();
+const pics = await maker.evaluate(() => Array.from({ length: 12 }, (_, i) => {
+ const c = document.createElement("canvas"); c.width = 384; c.height = 288;
+ const g = c.getContext("2d");
+ const grad = g.createLinearGradient(0, 0, 384, 288);
+ grad.addColorStop(0, `hsl(${i * 30} 70% 60%)`); grad.addColorStop(1, `hsl(${i * 30 + 120} 60% 35%)`);
+ g.fillStyle = grad; g.fillRect(0, 0, 384, 288);
+ for (let k = 0; k < 60; k++) { g.fillStyle = `hsla(${(i * 30 + k * 13) % 360} 80% 60% / 0.35)`; g.beginPath(); g.arc((k * 97) % 384, (k * 53) % 288, 10 + (k % 7) * 6, 0, 7); g.fill(); }
+ return c.toDataURL("image/jpeg", 0.8).split(",")[1];
+}));
+await maker.close();
+const bufs = pics.map((p) => Buffer.from(p, "base64"));
+const server = http.createServer((q, r) => {
+ const n = Number(decodeURIComponent(q.url).match(/q(\d+)/)?.[1] ?? 0);
+ r.writeHead(200, { "content-type": "image/jpeg", "cache-control": "max-age=3600", "access-control-allow-origin": "*" });
+ r.end(bufs[n % bufs.length]);
+}).listen(0);
+const picBase = `http://127.0.0.1:${server.address().port}`;
+
+const ctx = await b.newContext({ viewport: { width: 1280, height: 800 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null,
+ notesFixture: true, calendarFixture: true, contactsFixture: true, driveFixture: true, remindersFixture: true });
+await ctx.addInitScript((base) => {
+ window.__picBase = base;
+ const P = (i, t) => ({ id: `q${i}`, master: `mq${i}`, takenAt: t, addedAt: t, kind: "image", width: 4032, height: 3024,
+ duration: null, filename: `IMG_${i}.JPG`, size: 2400000, uti: "public.jpeg", favorite: i % 9 === 0, hidden: false,
+ deleted: false, deletedAt: null, subtype: 0, changeTag: null });
+ window.__photos = Array.from({ length: 2000 }, (_, i) => P(i, 1792600000 - i * 20000));
+ // Long lists: 400 notes and 400 files, invented.
+ const words = ["Garden plan", "Trip to the coast", "Recipes", "Book list", "Meeting with Sam", "Gift ideas", "Running log", "Maya's birthday"];
+ window.__notesExtra = Array.from({ length: 400 }, (_, i) => ({ guid: `x${i}`, folderGuid: "f1", title: `${words[i % words.length]} ${i}`,
+ snippet: "A few lines about it, to read in the list.", body: `${words[i % words.length]} ${i}\nA few lines about it, to read in the list.`,
+ locked: false, editable: true, pinned: false, createdAt: null, modifiedAt: 1788400000 - i * 600, etag: null }));
+ window.__driveExtra = Array.from({ length: 400 }, (_, i) => ({ drivewsid: `FILE::x${i}`, parentId: null, name: `${words[i % words.length]} ${i}`,
+ extension: ["pdf", "pages", "png", "txt"][i % 4], kind: "FILE", size: 20000 + i * 911, childCount: null, createdAt: 1787000000,
+ modifiedAt: 1788000000 - i * 600, etag: null }));
+}, picBase);
+// GLASS=live: the blurred tier even in WebKit — to measure what it would cost there.
+if (process.env.GLASS === "live") await ctx.addInitScript(() => {
+ new MutationObserver(() => { if (document.documentElement?.dataset.engine) delete document.documentElement.dataset.engine; })
+ .observe(document, { subtree: true, attributes: true, attributeFilter: ["data-engine"] });
+});
+const page = await ctx.newPage();
+page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); failures++; });
+await page.goto(BASE, { waitUntil: "networkidle" });
+await page.locator(".nav-item").first().waitFor();
+await page.waitForFunction(() => ["NotesView", "DriveView", "PhotosView"]
+ .every((n) => performance.getEntriesByType("resource").some((r) => r.name.includes(`/${n}-`))), null, { timeout: 20000 });
+
+const stats = (gaps) => {
+ const s = [...gaps].sort((x, y) => x - y);
+ const q = (p) => s[Math.min(s.length - 1, Math.floor(p * s.length))];
+ return { frames: s.length, p50: q(0.5), p95: q(0.95), max: s[s.length - 1], late: gaps.filter((g) => g > 25).length };
+};
+const results = {};
+// Headless WebKit paints in software, every frame on the CPU; its bound is looser. A freeze is
+// what fails here — a slower frame is for the numbers, compared before and after a change.
+const BOUND = engineName === "chromium" ? 250 : 900;
+const report = (what, gaps) => {
+ const st = stats(gaps);
+ results[what] = st;
+ console.log(` ${what}: ${st.frames} frames, p50 ${st.p50.toFixed(1)} ms, p95 ${st.p95.toFixed(1)} ms, max ${st.max.toFixed(1)} ms, ${st.late} late (>25 ms)`);
+ ok(st.max < BOUND, `${engineName} ${what}: never freezes (longest frame ${Math.round(st.max)} ms, bound ${BOUND})`);
+};
+
+/** Scroll `sel` at `speed` px/s for `ms`, one step a frame; the gaps between frames. */
+const scroll = (sel, speed, ms) => page.evaluate(([sel, speed, ms]) => new Promise((done) => {
+ const el = document.querySelector(sel);
+ el.scrollTop = 0;
+ const gaps = [];
+ requestAnimationFrame((t0) => {
+ let last = t0;
+ const step = (now) => {
+ gaps.push(now - last);
+ el.scrollTop += (speed * (now - last)) / 1000;
+ last = now;
+ if (now - t0 < ms && el.scrollTop + el.clientHeight < el.scrollHeight - 2) requestAnimationFrame(step);
+ else done(gaps.slice(2));
+ };
+ requestAnimationFrame(step);
+ });
+}), [sel, speed, ms]);
+
+/** Run `act` in the page and gather the gaps of the `n` frames after it. */
+const framesAfter = (act, n = 10) => page.evaluate(async ([act, n]) => {
+ await new Promise((r) => requestAnimationFrame(r));
+ let last = performance.now();
+ (0, eval)(act);
+ const gaps = [];
+ for (let i = 0; i < n; i++) {
+ const now = await new Promise((r) => requestAnimationFrame(r));
+ gaps.push(now - last);
+ last = now;
+ }
+ return gaps;
+}, [act, n]);
+
+/** The live blurs on screen: how many, and whether any sits in a scroller or on another. */
+const blurs = () => page.evaluate(() => {
+ const live = [...document.querySelectorAll("body *")].filter((el) => {
+ const cs = getComputedStyle(el);
+ const f = cs.backdropFilter || cs.webkitBackdropFilter || "none";
+ if (f === "none") return false;
+ const r = el.getBoundingClientRect();
+ return r.width > 0 && r.height > 0 && cs.visibility !== "hidden";
+ });
+ const scrolls = (el) => { for (let p = el.parentElement; p; p = p.parentElement) {
+ const o = getComputedStyle(p).overflowY; if ((o === "auto" || o === "scroll") && p.scrollHeight > p.clientHeight) return true; } return false; };
+ return {
+ count: live.length,
+ area: Math.round(live.reduce((a, el) => { const r = el.getBoundingClientRect(); return a + r.width * r.height; }, 0) / (innerWidth * innerHeight) * 100),
+ inScroller: live.filter(scrolls).map((el) => el.className).slice(0, 3),
+ nested: live.filter((el) => live.some((o) => o !== el && o.contains(el))).map((el) => el.className).slice(0, 3),
+ };
+});
+const gtkLike = await page.evaluate(() => document.documentElement.dataset.engine === "gtk");
+const checkBlurs = async (where) => {
+ const bl = await blurs();
+ ok(bl.count <= 4 && bl.area <= 25, `${where}: ${bl.count} live blur(s), ${bl.area}% of the window (at most 4, 25%)`);
+ ok(bl.inScroller.length === 0, `${where}: no blur inside a scroller ${bl.inScroller.join(", ")}`);
+ ok(bl.nested.length === 0, `${where}: no blur on a blur ${bl.nested.join(", ")}`);
+ if (gtkLike) ok(bl.count === 0, `${where}: WebKitGTK draws no live blur`);
+};
+
+// ---- switching apps -----------------------------------------------------------------------
+const order = ["Notes", "Calendar", "Contacts", "Drive", "Reminders", "Photos", "Notes", "Drive"];
+for (const name of order.slice(0, 6)) { await openScreen(page, name); await page.waitForTimeout(300); }
+const switchGaps = [];
+for (const name of order) {
+ switchGaps.push(...await framesAfter(`[...document.querySelectorAll(".nav-item")].find((b) => b.textContent.includes(${JSON.stringify(name)})).click()`, 12));
+ await page.waitForTimeout(250);
+}
+report("switching apps", switchGaps);
+
+// ---- Photos ----------------------------------------------------------------------------------
+await openScreen(page, "Photos");
+await page.locator(".px-tile").first().waitFor();
+await page.waitForTimeout(800);
+await checkBlurs("Photos");
+report("scrolling Photos", await scroll(".px-scroll", 3000, 3000));
+
+// ---- Notes ----------------------------------------------------------------------------------
+await openScreen(page, "Notes");
+await page.locator(".note-row").nth(40).waitFor({ state: "attached" });
+await page.waitForTimeout(400);
+await checkBlurs("Notes");
+report("scrolling Notes' list", await scroll(".note-rows", 2000, 2500));
+
+// ---- Drive ----------------------------------------------------------------------------------
+await openScreen(page, "Drive");
+await page.locator(".drive-row").nth(40).waitFor({ state: "attached" });
+await page.waitForTimeout(400);
+await checkBlurs("Drive");
+report("scrolling Drive's list", await scroll(".drive-rows", 2000, 2500));
+await page.evaluate(() => { document.querySelector(".drive-rows").scrollTop = 0; });
+await page.waitForTimeout(200);
+const menuGaps = [];
+for (let i = 0; i < 8; i++) {
+ menuGaps.push(...await framesAfter(`(() => { const r = document.querySelectorAll(".drive-row")[${4 + i}]; const b = r.getBoundingClientRect();
+ r.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: b.left + 60, clientY: b.top + b.height / 2, button: 2 })); })()`, 10));
+ ok(await page.locator(".row-menu").isVisible(), `${engineName} the row's menu opens (${i + 1})`);
+ if (i === 0) await checkBlurs("Drive, a menu open");
+ await page.keyboard.press("Escape");
+ await page.locator(".row-menu").waitFor({ state: "detached" });
+ await page.waitForTimeout(120);
+}
+report("opening a menu", menuGaps);
+
+// ---- Calendar's view switch: the segmented control's thumb ---------------------------------
+await openScreen(page, "Calendar");
+await page.locator(".cx").first().waitFor();
+await page.waitForTimeout(400);
+const thumbGaps = [];
+for (let i = 0; i < 8; i++) {
+ thumbGaps.push(...await framesAfter(`document.querySelectorAll('.segmented[aria-label="View"] .segment')[${i % 2 ? 1 : 2}].click()`, 14));
+ await page.waitForTimeout(200);
+}
+report("sliding a segmented control", thumbGaps);
+
+if (process.env.JSON) console.log(JSON.stringify({ engine: engineName, results }));
+await b.close();
+server.close();
+process.exitCode = failures ? 1 : (process.exitCode ?? 0);
diff --git a/.uiverify/glass-motion.mjs b/.uiverify/glass-motion.mjs
new file mode 100644
index 0000000..63b2140
--- /dev/null
+++ b/.uiverify/glass-motion.mjs
@@ -0,0 +1,155 @@
+// The glass and the motion that answers a person, frame by frame:
+//
+// - the engine is marked, and what appears for a moment (a menu) takes the live blur only
+// where it is cheap (Chromium, the engine WebView2 is); in WebKit, WebKitGTK's sibling,
+// it is frosted without one; chrome that stays up over a scroll (toolbars, the sidebar)
+// is frosted in every engine; content never takes any of it;
+// - a segmented control's thumb slides from the old segment to the new one, from the first
+// painted frame, with a cap under the segments on every frame, and is gone once settled;
+// - a popover grows out of what opened it: drawn small and clear on its first frame, whole
+// and without any style of its own once settled; a menu is simply there;
+// - under Reduce Motion, none of it moves.
+import { engine, engineName } from "./engine.mjs";
+import { SERVICES, installStub, openScreen } from "./stub.mjs";
+
+const b = await engine.launch();
+let failures = 0;
+const ok = (p, m) => { console.log(`${p ? "PASS" : "FAIL"} ${engineName} ${m}`); if (!p) failures++; };
+
+async function open(reducedMotion) {
+ const ctx = await b.newContext({ viewport: { width: 1280, height: 820 }, reducedMotion });
+ await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null,
+ notesFixture: true, calendarFixture: true, driveFixture: true });
+ const page = await ctx.newPage();
+ page.on("pageerror", (e) => { console.log(`FAIL page error: ${e.message}`); failures++; });
+ await page.goto(process.env.URL ?? "http://localhost:4173", { waitUntil: "networkidle" });
+ await page.locator(".nav-item").first().waitFor();
+ return { ctx, page };
+}
+
+/** Click `selector` in the page and record `look` (a function body run in the page) on that
+ task and on each of the next `n` frames. */
+const frames = (page, click, look, n = 14) => page.evaluate(async ([click, look, n]) => {
+ const read = new Function(look);
+ const out = [];
+ (0, eval)(click);
+ out.push(read());
+ for (let i = 0; i < n; i++) {
+ await new Promise((r) => requestAnimationFrame(r));
+ out.push(read());
+ }
+ return out;
+}, [click, look, n]);
+
+// ---- the material ------------------------------------------------------------------------
+{
+ const { ctx, page } = await open("no-preference");
+ const marked = await page.evaluate(() => document.documentElement.dataset.engine ?? null);
+ ok(marked === (engineName === "chromium" || engineName === "msedge" ? null : "gtk"), `the window says which engine draws it (${marked})`);
+ await openScreen(page, "Drive");
+ await page.locator(".drive-row").first().waitFor();
+ const filters = await page.evaluate(() => {
+ const f = (el) => { if (!el) return null; const cs = getComputedStyle(el); return cs.backdropFilter || cs.webkitBackdropFilter || "none"; };
+ return { tool: f(document.querySelector(".toolbar-group")), list: f(document.querySelector(".drive-rows")),
+ sidebar: f(document.querySelector(".sidebar")), row: f(document.querySelector(".drive-row")) };
+ });
+ // Toolbars stay up while lists scroll under them: frosted in every engine, never blurred.
+ ok(filters.tool === "none", `a toolbar's capsule is frosted, not blurred (${filters.tool})`);
+ ok(filters.list === "none" && filters.row === "none", "the list it sits over is content: no glass");
+ ok(filters.sidebar === "none", "the sidebar, which nothing moves under, takes no blur");
+
+ // A menu: there on its first frame, whole; regular glass.
+ const r = await page.locator(".drive-row").nth(1).boundingBox();
+ const menu = await frames(page, `(() => { const row = document.querySelectorAll(".drive-row")[1];
+ row.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: ${r.x + 60}, clientY: ${r.y + r.height / 2}, button: 2 })); })()`,
+ `const m = document.querySelector(".row-menu"); if (!m) return null; const cs = getComputedStyle(m);
+ return { opacity: Number(cs.opacity), scale: cs.scale, filter: cs.backdropFilter || cs.webkitBackdropFilter || "none" };`, 3);
+ const first = menu.slice(1).find(Boolean);
+ ok(first && first.opacity === 1 && (first.scale === "none" || first.scale === "1"), `a menu is simply there on its first frame, whole (${JSON.stringify(first)})`);
+ ok(first && (marked ? first.filter === "none" : /blur/.test(first.filter)), `a menu is regular glass (${first?.filter})`);
+ await page.keyboard.press("Escape");
+
+ // ---- a segmented control's thumb ----
+ await openScreen(page, "Calendar");
+ await page.locator(".cx").first().waitFor();
+ await page.waitForTimeout(300);
+ const look = `const g = document.querySelector('.segmented[aria-label="View"]');
+ const on = g.querySelector('.segment[aria-pressed="true"]');
+ const before = getComputedStyle(g, "::before");
+ const sliding = g.classList.contains("is-sliding");
+ const gx = g.getBoundingClientRect().left;
+ return { sliding, x: sliding ? parseFloat(g.style.getPropertyValue("--thumb-x")) : null,
+ onX: on.getBoundingClientRect().left - gx, label: on.textContent,
+ capOwn: getComputedStyle(on).backgroundColor, ghost: sliding ? before.backgroundColor : null };`;
+ const segs = await page.locator('.segmented[aria-label="View"] .segment').allTextContents();
+ const pressed = await page.locator('.segmented[aria-label="View"] .segment[aria-pressed="true"]').textContent();
+ const target = segs.indexOf(pressed) === 0 ? segs.length - 1 : 0;
+ const slide = await frames(page, `document.querySelectorAll('.segmented[aria-label="View"] .segment')[${target}].click()`, look, 20);
+ const painted = slide.slice(1);
+ ok(painted[0].sliding, "the thumb is on its way from the first painted frame");
+ const xs = painted.filter((f) => f.sliding).map((f) => f.x);
+ const toward = Math.sign(painted.at(-1).onX - xs[0]);
+ ok(xs.length >= 3 && xs.every((x, i) => i === 0 || Math.sign(x - xs[i - 1]) !== -toward), `it moves one way only, toward the new segment (${xs.map((x) => x.toFixed(0)).join(" ")})`);
+ ok(painted.filter((f) => f.sliding).every((f) => f.ghost && f.ghost !== "rgba(0, 0, 0, 0)"), "a cap is drawn on every frame of the way");
+ const last = painted.at(-1);
+ ok(!last.sliding && last.label === segs[target], `and it settles on ${segs[target]}, the thumb gone, the segment's own cap back`);
+ const settledAt = painted.findIndex((f) => !f.sliding);
+ ok(settledAt > 0 && settledAt <= 16, `settled in ${settledAt} frames (160ms; at most 16)`);
+
+ // ---- a popover grows out of what opened it ----
+ await page.keyboard.press("Control+2");
+ await page.waitForTimeout(400);
+ const block = page.locator(".cx-block", { hasText: "Dentist" }).first();
+ ok(await block.count() > 0, "the week shows the sample event");
+ {
+ const bb = await block.boundingBox();
+ // Each frame's popover from before the click on, the click made as a person makes it (a
+ // block opens its popover on the press and release, with the engine's own events).
+ await page.evaluate(() => {
+ window.__pop = [];
+ const t0 = performance.now();
+ const rec = () => {
+ const p = document.querySelector(".cx-popover");
+ if (p) { const cs = getComputedStyle(p); window.__pop.push({ opacity: Number(cs.opacity), scale: p.style.scale || null, origin: p.style.transformOrigin || null }); }
+ if (performance.now() - t0 < 3000 && window.__pop.length < 24) requestAnimationFrame(rec);
+ };
+ requestAnimationFrame(rec);
+ });
+ await page.mouse.click(bb.x + bb.width / 2, bb.y + bb.height / 2);
+ await page.waitForFunction(() => window.__pop.length >= 24 || (window.__pop.length > 0 && window.__pop.at(-1).opacity === 1 && !window.__pop.at(-1).scale), null, { timeout: 5000 }).catch(() => {});
+ await page.waitForTimeout(300);
+ const pop = [null, ...await page.evaluate(() => window.__pop)];
+ const shown = pop.slice(1).filter(Boolean);
+ if (shown.length) {
+ ok(shown[0].opacity < 1 && Number(shown[0].scale) < 1, `a popover's first frame is small and clear (${JSON.stringify(shown[0])})`);
+ ok(shown.every((f, i) => i === 0 || f.opacity >= shown[i - 1].opacity), "it only ever grows clearer");
+ const end = shown.at(-1);
+ ok(end.opacity === 1 && end.scale === null && end.origin === null, "and settles whole, with no style of its own left");
+ } else ok(false, "the event's popover opens");
+ await page.keyboard.press("Escape");
+ }
+ await ctx.close();
+}
+
+// ---- Reduce Motion: nothing moves ---------------------------------------------------------
+{
+ const { ctx, page } = await open("reduce");
+ await openScreen(page, "Calendar");
+ await page.locator(".cx").first().waitFor();
+ await page.waitForTimeout(300);
+ const seen = await frames(page, `document.querySelectorAll('.segmented[aria-label="View"] .segment')[1].click()`,
+ `return document.querySelector('.segmented[aria-label="View"]').classList.contains("is-sliding");`, 4);
+ ok(seen.every((s) => !s), "under Reduce Motion the thumb is simply on the new segment");
+ await page.keyboard.press("Control+2");
+ await page.waitForTimeout(400);
+ const block = page.locator(".cx-block", { hasText: "Dentist" }).first();
+ if (await block.count()) {
+ await block.click();
+ const p = await page.evaluate(() => { const el = document.querySelector(".cx-popover"); return el ? { opacity: getComputedStyle(el).opacity, scale: el.style.scale } : null; });
+ ok(p && p.opacity === "1" && !p.scale, "and a popover is simply there, whole");
+ }
+ await ctx.close();
+}
+
+await b.close();
+process.exitCode = failures ? 1 : 0;
diff --git a/.uiverify/gtk-frames.py b/.uiverify/gtk-frames.py
new file mode 100644
index 0000000..9c5acb9
--- /dev/null
+++ b/.uiverify/gtk-frames.py
@@ -0,0 +1,238 @@
+#!/usr/bin/env python3
+"""
+Frame times in the real WebKitGTK — the system's own, the one Skykeep's window is on Linux —
+for what glass-frames.mjs measures in Playwright's engines: switching apps, scrolling Photos,
+Notes' list and Drive's list, opening a row's menu, sliding a segmented control's thumb.
+
+This drives WebKitGTK directly through its GObject bindings, in a window on a headless Wayland
+display — never the desktop's. The display needs weston's kiosk shell: under its desktop shell
+a headless window is never given a frame to draw, and requestAnimationFrame never fires.
+
+ weston --backend=headless --renderer=gl --shell=kiosk --socket=<name> --width=1280 --height=800 &
+ WAYLAND_DISPLAY=<name> GDK_BACKEND=wayland python3 .uiverify/gtk-frames.py http://localhost:4173 [label]
+
+The page gets the same stub the browser suites use (stub.mjs installStub, read through node),
+with 2,000 photos served from here as real JPEGs, 400 notes and 400 files. Prints one line per
+action and, last, the numbers as JSON. Exits non-zero when a frame is held past the bound.
+"""
+import io
+import json
+import os
+import subprocess
+import sys
+import threading
+from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
+
+import gi
+
+gi.require_version("Gtk", "3.0")
+gi.require_version("WebKit2", "4.1")
+from gi.repository import GLib, Gtk, WebKit2 # noqa: E402
+
+URL = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:4173"
+LABEL = sys.argv[2] if len(sys.argv) > 2 else ""
+HERE = os.path.dirname(os.path.abspath(__file__))
+BOUND = 900 # ms: a frozen frame, not a slow one
+
+
+def pictures():
+ """Twelve photo-like JPEGs, as glass-frames.mjs draws them."""
+ from PIL import Image, ImageDraw
+
+ out = []
+ for i in range(12):
+ img = Image.new("RGB", (384, 288))
+ d = ImageDraw.Draw(img)
+ for y in range(288):
+ h = (i * 30 + y // 3) % 360
+ d.line([(0, y), (384, y)], fill=f"hsl({h},65%,{60 - y // 12}%)")
+ for k in range(60):
+ x, yy, r = (k * 97) % 384, (k * 53) % 288, 10 + (k % 7) * 6
+ d.ellipse([x - r, yy - r, x + r, yy + r], fill=f"hsl({(i * 30 + k * 13) % 360},80%,60%)")
+ b = io.BytesIO()
+ img.save(b, "JPEG", quality=80)
+ out.append(b.getvalue())
+ return out
+
+
+PICS = pictures()
+
+
+class Pics(BaseHTTPRequestHandler):
+ def do_GET(self):
+ import re
+ from urllib.parse import unquote
+
+ m = re.search(r"q(\d+)", unquote(self.path))
+ body = PICS[int(m.group(1)) % len(PICS) if m else 0]
+ self.send_response(200)
+ self.send_header("content-type", "image/jpeg")
+ self.send_header("cache-control", "max-age=3600")
+ self.send_header("access-control-allow-origin", "*")
+ self.end_headers()
+ self.wfile.write(body)
+
+ def log_message(self, *a):
+ pass
+
+
+server = ThreadingHTTPServer(("127.0.0.1", 0), Pics)
+threading.Thread(target=server.serve_forever, daemon=True).start()
+pic_base = f"http://127.0.0.1:{server.server_address[1]}"
+
+# The stub, as a script run before the page's own: installStub's source, called with its options.
+stub = subprocess.run(
+ ["node", "--input-type=module", "-e",
+ "import { installStub, SERVICES } from './stub.mjs';"
+ "const opts = { screen: 'library', services: SERVICES, twoFactor: null, notesFixture: true, calendarFixture: true,"
+ " contactsFixture: true, driveFixture: true, remindersFixture: true };"
+ "process.stdout.write(`(${installStub.toString()})(${JSON.stringify(opts)});`);"],
+ cwd=HERE, capture_output=True, text=True, check=True).stdout
+
+LIBRARY = """
+window.__picBase = %s;
+const P = (i, t) => ({ id: `q${i}`, master: `mq${i}`, takenAt: t, addedAt: t, kind: "image", width: 4032, height: 3024,
+ duration: null, filename: `IMG_${i}.JPG`, size: 2400000, uti: "public.jpeg", favorite: i %% 9 === 0, hidden: false,
+ deleted: false, deletedAt: null, subtype: 0, changeTag: null });
+window.__photos = Array.from({ length: 2000 }, (_, i) => P(i, 1792600000 - i * 20000));
+const words = ["Garden plan", "Trip to the coast", "Recipes", "Book list", "Meeting with Sam", "Gift ideas", "Running log", "Maya's birthday"];
+window.__notesExtra = Array.from({ length: 400 }, (_, i) => ({ guid: `x${i}`, folderGuid: "f1", title: `${words[i %% words.length]} ${i}`,
+ snippet: "A few lines about it, to read in the list.", body: `${words[i %% words.length]} ${i}\\nA few lines about it, to read in the list.`,
+ locked: false, editable: true, pinned: false, createdAt: null, modifiedAt: 1788400000 - i * 600, etag: null }));
+window.__driveExtra = Array.from({ length: 400 }, (_, i) => ({ drivewsid: `FILE::x${i}`, parentId: null, name: `${words[i %% words.length]} ${i}`,
+ extension: ["pdf", "pages", "png", "txt"][i %% 4], kind: "FILE", size: 20000 + i * 911, childCount: null, createdAt: 1787000000,
+ modifiedAt: 1788000000 - i * 600, etag: null }));
+""" % json.dumps(pic_base)
+
+RUN = r"""
+const raf = () => new Promise((r) => requestAnimationFrame(r));
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+const until = async (sel, n = 1, ms = 15000) => {
+ const t = performance.now();
+ while (document.querySelectorAll(sel).length < n) { if (performance.now() - t > ms) throw new Error("never drawn: " + sel); await sleep(50); }
+};
+const nav = (name) => [...document.querySelectorAll(".nav-item")].find((b) => b.textContent.includes(name));
+const open = async (name, root) => { nav(name).click(); if (root) await until(root); await sleep(400); };
+const after = async (act, n) => {
+ await raf();
+ let last = performance.now();
+ act();
+ const gaps = [];
+ for (let i = 0; i < n; i++) { const now = await raf(); gaps.push(now - last); last = now; }
+ return gaps;
+};
+const scroll = (sel, speed, ms) => new Promise((done) => {
+ const el = document.querySelector(sel);
+ el.scrollTop = 0;
+ const gaps = [];
+ requestAnimationFrame((t0) => {
+ let last = t0;
+ const step = (now) => {
+ gaps.push(now - last);
+ el.scrollTop += (speed * (now - last)) / 1000;
+ last = now;
+ if (now - t0 < ms && el.scrollTop + el.clientHeight < el.scrollHeight - 2) requestAnimationFrame(step);
+ else done(gaps.slice(2));
+ };
+ requestAnimationFrame(step);
+ });
+});
+const res = { engine: document.documentElement.dataset.engine ?? null, size: [innerWidth, innerHeight] };
+await until(".nav-item");
+for (const [n, r] of [["Notes", ".notes"], ["Calendar", ".cx"], ["Contacts", ".contacts"], ["Drive", ".drive"], ["Reminders", ".rx"], ["Photos", ".px"]]) await open(n, r);
+let g = [];
+for (const name of ["Notes", "Calendar", "Contacts", "Drive", "Reminders", "Photos", "Notes", "Drive"]) {
+ g.push(...await after(() => nav(name).click(), 12));
+ await sleep(250);
+}
+res["switching apps"] = g;
+await open("Photos", ".px-tile");
+await sleep(800);
+res["scrolling Photos"] = await scroll(".px-scroll", 3000, 3000);
+await open("Notes", ".note-row");
+await until(".note-row", 40);
+res["scrolling Notes' list"] = await scroll(".note-rows", 2000, 2500);
+await open("Drive", ".drive-row");
+await until(".drive-row", 40);
+res["scrolling Drive's list"] = await scroll(".drive-rows", 2000, 2500);
+document.querySelector(".drive-rows").scrollTop = 0;
+await sleep(200);
+g = [];
+for (let i = 0; i < 8; i++) {
+ g.push(...await after(() => {
+ const row = document.querySelectorAll(".drive-row")[4 + i];
+ const b = row.getBoundingClientRect();
+ row.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true, cancelable: true, clientX: b.left + 60, clientY: b.top + b.height / 2, button: 2 }));
+ }, 10));
+ if (!document.querySelector(".row-menu")) throw new Error("the row's menu did not open");
+ (document.activeElement ?? document).dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
+ for (let k = 0; k < 40 && document.querySelector(".row-menu"); k++) await sleep(25);
+ await sleep(120);
+}
+res["opening a menu"] = g;
+await open("Calendar", ".cx");
+g = [];
+for (let i = 0; i < 8; i++) {
+ const segs = document.querySelectorAll('.segmented[aria-label="View"] .segment');
+ g.push(...await after(() => segs[i % 2 ? 1 : 2].click(), 14));
+ await sleep(200);
+}
+res["sliding a segmented control"] = g;
+return JSON.stringify(res);
+"""
+
+
+def stats(gaps):
+ s = sorted(gaps)
+ q = lambda p: s[min(len(s) - 1, int(p * len(s)))] # noqa: E731
+ return {"frames": len(s), "p50": q(0.5), "p95": q(0.95), "max": s[-1], "late": sum(1 for x in gaps if x > 25)}
+
+
+Gtk.init(None)
+win = Gtk.Window(title="gtk-frames")
+win.set_default_size(1280, 800)
+manager = WebKit2.UserContentManager()
+manager.add_script(WebKit2.UserScript(stub + LIBRARY, WebKit2.UserContentInjectedFrames.TOP_FRAME,
+ WebKit2.UserScriptInjectionTime.START, None, None))
+# GLASS=live: the blurred tier here too, to measure what it would cost in WebKitGTK.
+if os.environ.get("GLASS") == "live":
+ manager.add_script(WebKit2.UserScript(
+ "new MutationObserver(() => { if (document.documentElement?.dataset.engine) delete document.documentElement.dataset.engine; })"
+ ".observe(document, { subtree: true, attributes: true, attributeFilter: ['data-engine'] });",
+ WebKit2.UserContentInjectedFrames.TOP_FRAME, WebKit2.UserScriptInjectionTime.START, None, None))
+view = WebKit2.WebView.new_with_user_content_manager(manager)
+settings = view.get_settings()
+settings.set_hardware_acceleration_policy(WebKit2.HardwareAccelerationPolicy.ALWAYS)
+win.add(view)
+win.show_all()
+code = {"rc": 1}
+
+
+def done(v, result, _):
+ try:
+ out = json.loads(v.call_async_javascript_function_finish(result).to_string())
+ table = {k: stats(g) for k, g in out.items() if isinstance(g, list) and k != "size"}
+ print(f"WebKitGTK {WebKit2.get_major_version()}.{WebKit2.get_minor_version()}.{WebKit2.get_micro_version()}"
+ f" {LABEL} engine={out['engine']} window={out['size']}")
+ frozen = False
+ for k, st in table.items():
+ print(f" {k}: {st['frames']} frames, p50 {st['p50']:.1f} ms, p95 {st['p95']:.1f} ms, max {st['max']:.1f} ms, {st['late']} late (>25 ms)")
+ frozen |= st["max"] >= BOUND
+ print(json.dumps({"engine": "gtk", "label": LABEL, "results": table}))
+ code["rc"] = 1 if frozen else 0
+ except Exception as e: # noqa: BLE001
+ print("FAIL", e)
+ Gtk.main_quit()
+
+
+def loaded(v, event):
+ if event == WebKit2.LoadEvent.FINISHED:
+ GLib.timeout_add(1500, lambda: (v.call_async_javascript_function(RUN, -1, None, None, None, None, done, None), False)[1])
+
+
+view.connect("load-changed", loaded)
+view.load_uri(URL)
+GLib.timeout_add_seconds(300, lambda: (print("FAIL timed out"), Gtk.main_quit()))
+Gtk.main()
+server.shutdown()
+sys.exit(code["rc"])
diff --git a/.uiverify/stub.mjs b/.uiverify/stub.mjs
index befa61b..618658e 100644
--- a/.uiverify/stub.mjs
+++ b/.uiverify/stub.mjs
@@ -1061,7 +1061,8 @@ export function installStub({ screen, services, twoFactor, calendarFixture, note
if (window.__slowDrive) await new Promise((r) => setTimeout(r, window.__slowDrive));
// A folder of a test's own, where it keeps one (__driveIn); every folder holds the fixture otherwise.
if (window.__driveIn?.[args.folderId]) return [...window.__driveIn[args.folderId]];
- return !driveFixture ? [] : driveItems;
+ // A suite's own extra files (`window.__driveExtra`), for a long list.
+ return !driveFixture ? [] : window.__driveExtra ? driveItems.concat(window.__driveExtra) : driveItems;
case "drive_recents": {
if (!driveFixture) return [];
const now = Math.floor(Date.now() / 1000);