Norcleeh (Discord #general, after v0.1.1788): in magpie's web GUI the interface-font and code-font rows "flash once and disappear" on refresh. Cause, reproduced on a real nogui `magpie web` on mote in Chromium and WebKit, at 127.0.0.1, localhost and the LAN address: a nogui build (Docker, magpie-cli) has fonts.Available false, so boot.js carried no `fonts` flag and app.js never showed the font rows at all. What flashed was the Text size row: index.html shows it, and renderSettings hid it for a browser tab 40-120ms later (`#textSizeRow.hidden = web`). Fix: - A browser tab always gets the font rows. Its /api/fonts answers the server's families plus a common list (Arial, Menlo, Consolas, PingFang SC, Microsoft YaHei, Noto Sans CJK SC, JetBrains Mono, ...) and never errors for a tab; fonts.js keeps only what this browser can draw, and "System default" is always offered, so with nothing kept the rows still show with it. - The app-only rows (Text size, tray, login, tray usage) carry .app-only, which `body.web .app-only` hides before first paint, so none of them paints in a tab. - The boot `fonts` flag is gone. app.js and core both got smaller; no budget changed. - docs/subsystems/gui-shell.md "Desktop fonts" says so. Run (mote-run, at this head rebased on98e23350f): - go build ./... and -tags nogui; gofmt -l clean; GOOS=linux go vet -tags nogui ./internal/gui and GOOS=windows go vet ./internal/gui ./internal/fonts ok (at the pre-rebase head). - go test -tags nogui -run 'Font|Budget|Boot' ./internal/gui ./internal/fonts ok (and with cgo before the rebase); the new TestBrowserTabFontsWithoutInstalledFonts covers nogui, a failed read and a merge with the server's own families. - fonts, i18n-keys, settings-general, text-size, web-page: 76/76. - Before the rebase, 20 files (fonts, font-cascade, win-fonts, login-allow, omarchy, settings-general/-search/-sections/-groups/ -lines-wrap/-tabs-stick, text-size, tray-usages, web-page, web-app-standalone, gui-de, gui-ja, gui-zh-tw, i18n-keys) 259 tests, all ok but i18n-keys' "Runs as" (#3897, green now on main). - Whole GUI suite before the rebase, --test-concurrency=4 beside other sessions' load: 13,626 tests, 160 red in 31 files. Those 31 files run alone at head and at base0a7633136: 166 vs 157 red, the same tests at other widths/languages (routing-*, segs-press-redraw's webkit 900/440px, usage-*); mobile-web's "matches origin/main" needs .git, which a mote-run copy lacks; old-webkit's :has() is on base. segs-press-redraw alone: 7 red at head, 8 at base. - New GUI test, both engines, en and zh: "a browser tab's font rows show on a nogui magpie and nothing flashes" records every rAF frame. Red on the old assets (uiFontRow never shows). Broken by hand: without the .app-only CSS rule it goes red with textSizeRow painting ~20 frames then going away (the reported flash); with `row.hidden = web && fontList?.length === 0` it goes red. - Real servers on mote, both engines, 3 origins: nogui shows the rows (19 families in Chromium, 21 in WebKit), Text size never shown; a cgo desktop server 204/181 families. Not tried: a Windows server with the fix (old code showed the rows), WebKit over a LAN tunnel, Brave/Safari fingerprinting modes, the full Go suite.
414 lines
24 KiB
JavaScript
414 lines
24 KiB
JavaScript
// Installed desktop fonts: real assets with an isolated API, in both engines.
|
|
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 { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
|
|
const assets = process.env.MAGPIE_FONT_ASSETS || path.resolve(__dirname, "../assets");
|
|
const face = (family, name = "Regular", weight = 400, style = "normal", stretch = 100) => ({ family, name, weight, style, stretch });
|
|
const harmony = [face("HarmonyOS Sans SC"), face("HarmonyOS Sans SC", "Medium", 500), face("HarmonyOS Sans SC", "Bold", 700)];
|
|
const mono = [face("Consolas"), face("Consolas", "Italic", 400, "italic")];
|
|
const odd = face('Reader\'s "中文" \\ family');
|
|
const catalogue = [
|
|
{ name: harmony[0].family, styles: harmony }, { name: mono[0].family, styles: mono }, { name: odd.family, styles: [odd] },
|
|
...Array.from({ length: 200 }, (_, i) => ({ name: "Test Family " + i, styles: [face("Test Family " + i)] })),
|
|
];
|
|
|
|
async function open(browser, lang = "en", options = {}) {
|
|
const context = await browser.newContext({ locale: lang === "zh" ? "zh-CN" : "en-US", viewport: options.viewport || { width: 1000, height: 820 } });
|
|
const api = { posts: [], reads: 0, fonts: structuredClone(options.list || catalogue), fontError: false, saveError: false, delay: 0,
|
|
cur: { lang, theme: "light", textSize: 100, currency: "usd", tray: "panel", version: "0.1.0", visionModels: [], imageGenModels: [], ...options.settings } };
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", e => { errors.push(e.message); console.error(e.message); });
|
|
await page.route("**/*", async route => {
|
|
const req = route.request(), url = new URL(req.url());
|
|
const json = data => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs=${JSON.stringify({ ...api.cur, web: !!options.web, ...(options.omarchy ? { omarchy: { mode: "dark", stamp: "one", name: "Test theme", vars: { "--font": '"Theme Font", sans-serif', "--code": '"Theme Mono", monospace' } } } : {}) })};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/fonts") {
|
|
api.reads++;
|
|
return api.fontError ? route.fulfill({ status: 503, body: "could not read installed fonts" }) : json(api.fonts);
|
|
}
|
|
if (url.pathname === "/api/settings") {
|
|
if (options.settingsDelay) await new Promise(r => setTimeout(r, options.settingsDelay));
|
|
if (req.method() === "POST") {
|
|
const body = req.postDataJSON();
|
|
api.posts.push(body);
|
|
if (api.delay) await new Promise(r => setTimeout(r, api.delay));
|
|
if (api.saveError) return route.fulfill({ status: 400, body: "test save failed" });
|
|
api.cur = { ...api.cur, ...body };
|
|
}
|
|
return json(api.cur);
|
|
}
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: api.cur });
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
|
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
|
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)];
|
|
try { return await route.fulfill({ body: await fs.readFile(file), contentType }); }
|
|
catch { return route.fulfill({ status: 404, body: "not found" }); }
|
|
});
|
|
// every frame's rows, from the first paint (Norcleeh: a row flashed and went)
|
|
if (options.frames) await page.addInitScript(() => {
|
|
window.__frames = [];
|
|
const ids = ["uiFontRow", "codeFontRow", "textSizeRow", "loginRow", "trayUsageRow"];
|
|
const look = () => {
|
|
const tray = document.getElementById("traySegs")?.parentElement;
|
|
if (document.getElementById("uiFontRow")) window.__frames.push(Object.fromEntries([...ids.map(id => [id, !!document.getElementById(id)?.getClientRects().length]), ["tray", !!tray?.getClientRects().length]]));
|
|
requestAnimationFrame(look);
|
|
};
|
|
requestAnimationFrame(look);
|
|
});
|
|
await watchSettingsReads(page);
|
|
await page.goto("http://magpie.test/?view=settings&tab=general");
|
|
await settingsDrawn(page); // rows found are the ones that stay (#1659)
|
|
await page.locator("#themeSegs .opt").first().waitFor({ state: "attached" });
|
|
// A real assertion, also usable against the original assets, rather than
|
|
// a timeout or a compile error as the negative-control result.
|
|
assert.equal(await page.locator("#uiFontRow").count(), 1, "Settings must offer an interface font picker");
|
|
// (a row left hidden, as before 10-28 in a nogui magpie's tab, fails at its assertion, not here)
|
|
await page.waitForFunction(() => fontList !== null || fontListError || document.getElementById("uiFontRow").hidden);
|
|
await page.evaluate(async () => {
|
|
await document.fonts.ready;
|
|
await Promise.all(document.getAnimations().map(a => a.finished.catch(() => {})));
|
|
});
|
|
return { page, api, errors, close: () => context.close() };
|
|
}
|
|
|
|
async function family(page, row, name) {
|
|
await page.locator(`#${row} .font-family`).click();
|
|
await page.locator(".font-menu .sc-q").fill(name);
|
|
await page.locator(".font-menu .pm-item").filter({ has: page.locator(".pm-name", { hasText: name }) }).first().click();
|
|
}
|
|
async function style(page, row, name) {
|
|
await page.locator(`#${row} .font-style`).click();
|
|
await page.locator(".font-menu .pm-item").filter({ has: page.locator(".pm-name", { hasText: name }) }).click();
|
|
}
|
|
async function reset(page, row) {
|
|
await page.locator(`#${row} .font-family`).click();
|
|
await page.locator(".font-menu .pm-item").first().click();
|
|
}
|
|
const settled = page => page.waitForFunction(() => prefsBusy === 0 && Object.keys(fontDrafts).length === 0);
|
|
const css = (page, selector) => page.locator(selector).evaluate(e => {
|
|
const s = getComputedStyle(e);
|
|
return { family: s.fontFamily, weight: s.fontWeight, style: s.fontStyle, stretch: s.fontStretch };
|
|
});
|
|
const engines = [["chromium", chromium], ["webkit", webkit]].filter(([name]) => !process.env.BROWSER || process.env.BROWSER === name);
|
|
|
|
for (const [engine, runtime] of engines) {
|
|
for (const lang of ["en", "zh"]) test(`${engine} ${lang}: independent installed fonts, real styles, persistence and reset`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, api, errors } = await open(browser, lang);
|
|
const before = await css(page, "#codeFontRow .font-preview");
|
|
assert.equal(await page.locator("select").count(), 0);
|
|
await family(page, "uiFontRow", "HarmonyOS Sans SC");
|
|
await style(page, "uiFontRow", "Medium");
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont.weight, 500);
|
|
assert.match((await css(page, "body")).family, /^"?HarmonyOS Sans SC/);
|
|
assert.equal((await css(page, "body")).weight, "500");
|
|
assert.deepEqual(await css(page, "#codeFontRow .font-preview"), before);
|
|
await family(page, "codeFontRow", "Consolas");
|
|
await style(page, "codeFontRow", "Italic");
|
|
await settled(page);
|
|
assert.equal((await css(page, "#codeFontRow .font-preview")).style, "italic");
|
|
assert.equal((await css(page, "body")).style, "normal");
|
|
// Other saved preferences must carry both choices through the queue.
|
|
await page.locator("#themeSegs .opt").nth(2).click();
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont.weight, 500);
|
|
assert.equal(api.cur.codeFont.style, "italic");
|
|
await page.reload();
|
|
await page.locator("#uiFontRow .font-family").waitFor();
|
|
await page.waitForFunction(() => fontList !== null && !fontFlight);
|
|
await page.evaluate(async () => { await document.fonts.ready; await Promise.all(document.getAnimations().map(a => a.finished.catch(() => {}))); });
|
|
assert.equal((await css(page, "body")).weight, "500");
|
|
assert.equal((await css(page, "#codeFontRow .font-preview")).style, "italic");
|
|
await family(page, "uiFontRow", "Consolas");
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont.name, "Regular", "a family without Medium chooses a regular face");
|
|
await reset(page, "uiFontRow");
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont, null);
|
|
assert.equal(api.cur.codeFont.style, "italic");
|
|
await reset(page, "codeFontRow");
|
|
await settled(page);
|
|
assert.deepEqual(await css(page, "#codeFontRow .font-preview"), before);
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
test(`${engine}: queued choices and failed writes restore the saved face`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, api, errors } = await open(browser);
|
|
api.delay = 250;
|
|
await family(page, "uiFontRow", "HarmonyOS Sans SC");
|
|
await style(page, "uiFontRow", "Medium");
|
|
await family(page, "codeFontRow", "Consolas");
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont.name, "Medium");
|
|
assert.equal(api.cur.codeFont.family, "Consolas");
|
|
api.saveError = true;
|
|
await style(page, "uiFontRow", "Bold");
|
|
await settled(page);
|
|
assert.equal((await css(page, "body")).weight, "500");
|
|
assert.equal(await page.locator("#uiFontRow .font-style span").textContent(), "Medium");
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
test(`${engine}: refresh errors, missing faces, empty lists and literal names`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, api, errors } = await open(browser, "en", { settings: { uiFont: harmony[1] } });
|
|
api.fontError = true;
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
await page.getByRole("menuitemradio", { name: "Refresh fonts" }).click();
|
|
await page.waitForFunction(() => fontListError);
|
|
assert.equal((await css(page, "body")).weight, "500", "failed discovery must not erase the last collection");
|
|
api.fontError = false;
|
|
api.fonts = [{ name: "Consolas", styles: mono }, { name: odd.family, styles: [odd] }];
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
await page.getByRole("menuitemradio", { name: /Refresh fonts/ }).click();
|
|
await page.waitForFunction(() => !fontFlight && !fontListError);
|
|
assert.match(await page.locator("#uiFontRow .font-note").textContent(), /unavailable/);
|
|
assert.doesNotMatch((await css(page, "body")).family, /HarmonyOS/);
|
|
assert.equal(api.cur.uiFont.family, harmony[0].family, "missing font choice stays saved");
|
|
await family(page, "uiFontRow", odd.family);
|
|
await settled(page);
|
|
assert.equal(await page.locator("#uiFontRow .font-family span").textContent(), odd.family);
|
|
assert.match((await css(page, "body")).family, /Reader/);
|
|
api.fonts = [];
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
await page.getByRole("menuitemradio", { name: "Refresh fonts" }).click();
|
|
await page.waitForFunction(() => !fontFlight && fontList.length === 0);
|
|
await reset(page, "uiFontRow");
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont, null);
|
|
assert.match(await page.locator("#uiFontRow .font-note").textContent(), /No installed fonts/);
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
// #2439: the pointer resting on the menu while a search narrows it got a
|
|
// mouseenter from the redraw, which took the focus out of the field, so
|
|
// Enter chose "Refresh fonts" (the item now under the pointer).
|
|
test(`${engine}: a search narrowing the menu under a still pointer keeps the typing in its field`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, api, errors } = await open(browser, "zh", { viewport: { width: 560, height: 620 } });
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
const second = await page.locator(".font-menu .pm-item").nth(1).boundingBox();
|
|
await page.mouse.move(second.x + second.width / 2, second.y + second.height / 2);
|
|
await page.locator(".font-menu .sc-q").fill("HarmonyOS");
|
|
// the item now under the pointer is Refresh fonts. The redraw's
|
|
// mouseenter comes on the engine's own hover timer (WebKit's is
|
|
// later than a frame), and what is checked is that nothing came, so
|
|
// there is no state to wait for: 300ms is past both engines' timers.
|
|
await page.waitForTimeout(300);
|
|
assert.equal(await page.evaluate(() => document.activeElement.className), "sc-q", "the search field keeps the focus");
|
|
const reads = api.reads;
|
|
await page.keyboard.press("Enter");
|
|
await settled(page);
|
|
assert.equal(await page.locator("#uiFontRow .font-family span").textContent(), "HarmonyOS Sans SC");
|
|
assert.equal(api.reads, reads, "Enter didn't refresh the font list");
|
|
// a pointer that moves still takes an item's focus
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
const item = page.locator(".font-menu .pm-item").nth(2);
|
|
const box = await item.boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2 + 1);
|
|
assert.equal(await item.evaluate(e => e === document.activeElement), true, "a moved pointer focuses the item it's on");
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
test(`${engine}: font menu search and keys fit narrow windows without scrolling the page`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, errors } = await open(browser, "zh", { viewport: { width: 560, height: 620 } });
|
|
const top = await page.locator("#view-settings").evaluate(e => e.scrollTop);
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
const menu = page.locator(".font-menu");
|
|
const box = await menu.boundingBox();
|
|
assert(box.x >= 0 && box.x + box.width <= 560 && box.y >= 0 && box.y + box.height <= 620);
|
|
await menu.hover();
|
|
await page.mouse.wheel(0, 240);
|
|
await page.waitForFunction(() => document.querySelector(".font-menu").scrollTop > 0);
|
|
assert.equal(await page.locator("#view-settings").evaluate(e => e.scrollTop), top);
|
|
await page.locator(".font-menu .sc-q").fill("HarmonyOS");
|
|
await page.keyboard.press("Enter");
|
|
await settled(page);
|
|
assert.equal(await page.locator("#uiFontRow .font-family span").textContent(), "HarmonyOS Sans SC");
|
|
assert.equal(await page.locator("#view-settings").evaluate(e => e.scrollTop), top);
|
|
await page.locator("#uiFontRow .font-style").click();
|
|
await page.keyboard.press("ArrowDown");
|
|
await page.keyboard.press("Enter");
|
|
await settled(page);
|
|
assert.equal(await page.locator("#uiFontRow .font-style span").textContent(), "Medium");
|
|
await page.locator("#uiFontRow .font-style").click();
|
|
await page.keyboard.press("Escape");
|
|
assert.equal(await page.locator(".font-menu").count(), 0);
|
|
for (const width of [440, 560, 1000]) {
|
|
await page.setViewportSize({ width, height: 820 });
|
|
assert(await page.locator("#view-settings").evaluate(e => e.scrollWidth <= e.clientWidth));
|
|
for (const row of ["uiFontRow", "codeFontRow"]) {
|
|
const bounds = await page.locator(`#${row} .font-controls`).boundingBox();
|
|
assert(bounds.x >= 0 && bounds.x + bounds.width <= width, `${row} at ${width}`);
|
|
}
|
|
}
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await style(page, "uiFontRow", "Medium");
|
|
await family(page, "codeFontRow", "Consolas");
|
|
await settled(page);
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `fonts-${engine}-zh.png`) });
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
test(`${engine}: explicit fonts override Omarchy and browser mode keeps its defaults`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, errors } = await open(browser, "en", { omarchy: true, settings: { uiFont: harmony[1], codeFont: mono[0] } });
|
|
assert.match((await css(page, "body")).family, /HarmonyOS/);
|
|
await reset(page, "uiFontRow");
|
|
await settled(page);
|
|
assert.match((await css(page, "body")).family, /Theme Font/);
|
|
assert.match((await css(page, "#codeFontRow .font-preview")).family, /Consolas/);
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
// Norcleeh on Discord: a browser tab had no font rows. It has them now,
|
|
// with the families this browser draws, and its choice is its own.
|
|
for (const lang of ["en", "zh"]) test(`${engine} ${lang}: a browser tab picks its own font from the ones it draws`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const real = ["Georgia", "Courier New", "DejaVu Serif", "Liberation Serif"];
|
|
const list = [{ name: "No Such Family Here", styles: [face("No Such Family Here")] }, ...real.map(n => ({ name: n, styles: [face(n), face(n, "Bold", 700)] }))];
|
|
const { page, api, errors } = await open(browser, lang, { web: true, settings: { uiFont: harmony[1] } });
|
|
api.fonts = list;
|
|
assert.equal(await page.locator("#uiFontRow").isVisible(), true, "a browser tab offers the interface font");
|
|
assert.equal(await page.locator("#codeFontRow").isVisible(), true, "and the code font");
|
|
assert.doesNotMatch((await css(page, "body")).family, /HarmonyOS/, "the app's own choice stays the app's");
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
await page.locator(".font-menu .pm-item").last().click(); // Refresh fonts
|
|
await page.waitForFunction(() => !fontFlight);
|
|
const shown = await page.evaluate(() => fontList.map(f => f.name));
|
|
assert(!shown.includes("No Such Family Here"), "a family this browser doesn't draw isn't offered: " + shown);
|
|
const pick = shown[0];
|
|
assert(real.includes(pick), "an installed family is offered: " + shown);
|
|
await family(page, "uiFontRow", pick);
|
|
await style(page, "uiFontRow", "Bold");
|
|
assert.match((await css(page, "body")).family, new RegExp("^\"?" + pick));
|
|
assert.equal((await css(page, "body")).weight, "700");
|
|
await family(page, "codeFontRow", pick);
|
|
assert.match((await css(page, "#codeFontRow .font-preview")).family, new RegExp("^\"?" + pick));
|
|
assert.equal(api.posts.filter(p => "uiFont" in p || "codeFont" in p).length, 0, "the browser's choice isn't sent as the app's");
|
|
assert.equal(api.cur.uiFont.family, harmony[1].family);
|
|
await page.reload();
|
|
await page.locator("#uiFontRow .font-family").waitFor();
|
|
await page.waitForFunction(() => fontList !== null && !fontFlight);
|
|
assert.match((await css(page, "body")).family, new RegExp("^\"?" + pick), "kept across a reload");
|
|
assert.equal((await css(page, "body")).weight, "700");
|
|
assert.equal(await page.locator("#uiFontRow .font-family span").textContent(), pick);
|
|
await reset(page, "uiFontRow");
|
|
assert.doesNotMatch((await css(page, "body")).family, new RegExp(pick));
|
|
assert.match((await css(page, "#codeFontRow .font-preview")).family, new RegExp("^\"?" + pick));
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
// Norcleeh again, after v0.1.1788: on a refresh a row "flashed and went".
|
|
// A nogui magpie (Docker, magpie-cli) has no boot `fonts`, so the font
|
|
// rows never showed, and Text size painted until the settings hid it.
|
|
// The tab's rows show whatever the server can read, with System default
|
|
// when the browser draws none of its families, and stay through every
|
|
// later settings read; the app's own rows never paint at all.
|
|
for (const lang of ["en", "zh"]) test(`${engine} ${lang}: a browser tab's font rows show on a nogui magpie and nothing flashes`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
for (const fonts of [[{ name: "Georgia", styles: [face("Georgia"), face("Georgia", "Bold", 700)] }, { name: "No Such Family Here", styles: [face("No Such Family Here")] }], []]) {
|
|
const { page, errors, close } = await open(browser, lang, { web: true, frames: true, settingsDelay: 300, list: fonts, settings: { uiFont: harmony[1] } });
|
|
// what a later refresh of the settings or the state redraws
|
|
await page.evaluate(() => loadSettings());
|
|
await page.evaluate(() => new Promise(r => setTimeout(r, 500)));
|
|
const frames = await page.evaluate(() => window.__frames);
|
|
assert(frames.length > 5, "frames were watched: " + frames.length);
|
|
for (const row of ["uiFontRow", "codeFontRow"]) {
|
|
assert.equal(await page.locator("#" + row).isVisible(), true, row + " shows in a browser tab");
|
|
const first = frames.findIndex(f => f[row]);
|
|
assert(first >= 0, row + " never painted");
|
|
assert(frames.slice(first).every(f => f[row]), row + " painted and then went: " + frames.map(f => +f[row]).join(""));
|
|
}
|
|
for (const row of ["textSizeRow", "loginRow", "trayUsageRow", "tray"]) {
|
|
assert(!frames.some(f => f[row]), row + " is the app's and painted in a browser tab: " + frames.map(f => +f[row]).join(""));
|
|
}
|
|
const shown = await page.evaluate(() => fontList.map(f => f.name));
|
|
assert(!shown.includes("No Such Family Here"), "a family this browser doesn't draw isn't offered: " + shown);
|
|
await page.locator("#codeFontRow .font-family").click();
|
|
const names = await page.locator(".font-menu .pm-item .pm-name").allTextContents();
|
|
assert.equal(names[0], lang === "zh" ? "系统默认" : "System default", "System default is offered: " + names);
|
|
if (!fonts.length) assert.deepEqual(shown, [], "no family this browser draws");
|
|
await page.keyboard.press("Escape");
|
|
assert.deepEqual(errors, []);
|
|
await close();
|
|
}
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
test(`${engine}: native notifications update the other webview without another save`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, api, errors } = await open(browser);
|
|
api.cur.uiFont = harmony[1];
|
|
api.cur.codeFont = mono[1];
|
|
await page.evaluate(s => window.receiveFonts(s), api.cur);
|
|
assert.equal((await css(page, "body")).weight, "500");
|
|
assert.equal((await css(page, "#codeFontRow .font-preview")).style, "italic");
|
|
assert.equal(await page.locator("#uiFontRow .font-style span").textContent(), "Medium");
|
|
assert.equal(api.posts.length, 0, "a notification must not echo another save");
|
|
api.cur.uiFont = null;
|
|
await page.evaluate(s => window.receiveFonts(s), api.cur);
|
|
assert.doesNotMatch((await css(page, "body")).family, /HarmonyOS/);
|
|
assert.equal((await css(page, "#codeFontRow .font-preview")).style, "italic");
|
|
// A local queued choice wins over an older notice sent before its reply.
|
|
api.delay = 150;
|
|
await family(page, "uiFontRow", "HarmonyOS Sans SC");
|
|
await page.evaluate(s => window.receiveFonts(s), { uiFont: mono[0], codeFont: null });
|
|
await settled(page);
|
|
assert.match((await css(page, "body")).family, /HarmonyOS/);
|
|
assert.equal((await css(page, "#codeFontRow .font-preview")).style, "italic");
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
|
|
test(`${engine}: named variable traits retain fractional weight and custom width`, async () => {
|
|
const browser = await runtime.launch();
|
|
try {
|
|
const { page, api, errors } = await open(browser);
|
|
const book = face("Variable Sans", "Book", 425.5, "normal", 25);
|
|
api.fonts.push({ name: book.family, styles: [book] });
|
|
await page.locator("#uiFontRow .font-family").click();
|
|
await page.getByRole("menuitemradio", { name: "Refresh fonts" }).click();
|
|
await page.waitForFunction(() => !fontFlight && fontList.some(f => f.name === "Variable Sans"));
|
|
await family(page, "uiFontRow", book.family);
|
|
await settled(page);
|
|
assert.equal(api.cur.uiFont.weight, 425.5);
|
|
assert.equal(api.cur.uiFont.stretch, 25);
|
|
assert.equal((await css(page, "body")).weight, "425.5");
|
|
assert.equal((await css(page, "body")).stretch, "25%");
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|
|
});
|
|
}
|