From 9df123ff943484f9694c6808a94e944d0134541f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Fri, 9 Oct 2026 01:05:26 -0400 Subject: [PATCH] Site: alpha-aware contrast check; test the open steps (R2.1) --- site/e2e/night.spec.ts | 18 +++++++++++++----- site/e2e/text.spec.ts | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/site/e2e/night.spec.ts b/site/e2e/night.spec.ts index 8082d94..091f4f4 100644 --- a/site/e2e/night.spec.ts +++ b/site/e2e/night.spec.ts @@ -66,19 +66,27 @@ for (const scheme of ["light", "dark"] as const) { await page.emulateMedia({ colorScheme: scheme }); await open(page); const worst = await page.evaluate(() => { - const parse = (c: string) => c.match(/[\d.]+/g)!.slice(0, 3).map(Number); - const lum = (c: string) => { - const [r, g, b] = parse(c).map((v) => { + const parse = (c: string) => { + const [r, g, b, a = 1] = c.match(/[\d.]+/g)!.map(Number); + return { rgb: [r, g, b], a }; + }; + const lum = (rgb: number[]) => { + const [r, g, b] = rgb.map((v) => { const s = v / 255; return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4; }); return 0.2126 * r + 0.7152 * g + 0.0722 * b; }; - const page = lum(getComputedStyle(document.documentElement).backgroundColor); + const ground = parse(getComputedStyle(document.documentElement).backgroundColor).rgb; + const page = lum(ground); + const shown = (c: string) => { + const { rgb, a } = parse(c); + return rgb.map((v, i) => v * a + ground[i] * (1 - a)); + }; const ratios = [...document.querySelectorAll("h1, h2, h3, p, a, li, button")] .filter((el) => el.textContent?.trim() && getComputedStyle(el).color !== "rgba(0, 0, 0, 0)") .map((el) => { - const text = lum(getComputedStyle(el).color); + const text = lum(shown(getComputedStyle(el).color)); return { ratio: (Math.max(text, page) + 0.05) / (Math.min(text, page) + 0.05), text: el.textContent }; }); return ratios.sort((a, b) => a.ratio - b.ratio)[0]; diff --git a/site/e2e/text.spec.ts b/site/e2e/text.spec.ts index 240cc9c..33f90af 100644 --- a/site/e2e/text.spec.ts +++ b/site/e2e/text.spec.ts @@ -126,3 +126,20 @@ test.describe("English locale", () => { } }); }); + +test("the download area tells how to open an unnotarized app", async ({ browser }) => { + for (const [locale, words] of [ + ["en-US", ["System Settings", "Privacy & Security", "Open Anyway"]], + ["zh-CN", ["系统设置", "隐私与安全性", "仍要打开"]], + ] as const) { + const page = await browser.newPage({ locale, reducedMotion: "reduce" }); + await page.goto("/"); + const steps = page.locator("#download [data-t=unsigned]"); + await expect(steps).toBeVisible(); + for (const word of words) await expect(steps).toContainText(word); + await page.locator(".lang").click(); + await expect(steps).toBeVisible(); + await expect(steps).not.toContainText(words[0]); + await page.close(); + } +});