// fixtures/engines/first-reveal.mjs — once a slide's text is on screen, // nothing about it changes, in Chromium and in WebKit, on every path: // a script missing, the editor late, a family late, a change waiting for // its family, nothing wrong (Paul, 2026-10-26: "No flashing, ever!"). // Docs' fixtures/engines/first-reveal.mjs, adopted to Slides' surfaces. // // Run by internal/slidestest/fonts_engines_browser_test.go, which serves // Slides through its production serving stack and passes the origin, a // signed-in cookie, the decks and the DOM probe in SLIDES_ENGINES_CONFIG. // // Each scenario captures the slide about every 50 ms for several // seconds, without Playwright's wait for document.fonts.ready, so the // interval before a slow font is observed too. The verdict: every // capture is either "nothing painted yet" (the slide hidden: no ink on // it) before the first capture with text, or exactly the final picture. // A capture that changes, disappears or blanks after text has appeared // fails. A change made during the run (an action) may show the picture // before it or the final picture, never a third. // // Two controls must fail the same verdicts in each engine, or this whole // check fails as blind: a page that hides the slide for a second after // it is shown, and a run put on the slide in a face that has not loaded // (which the DOM probe, not the pixels, must see). process.env.PW_TEST_SCREENSHOT_NO_FONTS_READY = '1' const { chromium, webkit } = await import('playwright') const { PNG } = await import('pngjs') const { createHash } = await import('node:crypto') const { writeFileSync } = await import('node:fs') const config = JSON.parse(process.env.SLIDES_ENGINES_CONFIG) const pause = (ms) => new Promise((r) => setTimeout(r, ms)) const scenarios = [ { name: 'viewer, nothing missing', deck: 'paper', path: (s) => '/d/' + s + '?slide=1' }, { name: 'viewer, the serif late', deck: 'paper', path: (s) => '/d/' + s + '?slide=1', slowFont: /LiberationSerif-/, fontDelay: 8000, length: 10000 }, { name: 'viewer, no gate', deck: 'paper', path: (s) => '/d/' + s + '?slide=1', block: /\/static\/fontsgate\./, length: 7500 }, { name: 'viewer, no hold', deck: 'paper', path: (s) => '/d/' + s + '?slide=1', block: /\/static\/fontshold\./ }, { name: 'projector, nothing missing', deck: 'projector', path: (s) => s }, { name: 'projector, the code late', deck: 'projector', path: (s) => s, slowFont: /LiberationMono-/, fontDelay: 8000, length: 10000 }, { name: 'editor, nothing missing', deck: 'paper', path: (s) => '/d/' + s + '/edit', editor: true }, { name: 'editor later than the layout deadline', deck: 'edges', path: (s) => '/d/' + s + '/edit', editor: true, editorDelay: 5000, length: 8000 }, // Every shape of text the renderer and the editor could draw // differently — no paragraphs, one empty, empties before, between and // after words — in every type the editor binds and in table cells, on // generated decks, with the editor late (Astra's finding 3 on #27). ...[1, 2, 3, 4, 5, 6].map((n) => ({ name: `editor later than the layout deadline, generated deck ${n}`, deck: 'generated', path: (s) => '/d/' + s + '/edit', editor: true, editorDelay: 5000, length: 7000 })), // A change that needs a family nobody has loaded, its files two // seconds away (inside the four seconds a change waits): the picture // before it, then the final one, and the wait said at once. { name: 'add a code block, its font late', deck: 'plain', path: (s) => '/d/' + s + '/edit', editor: true, slowFont: /LiberationMono-/, fontDelay: 2000, length: 5000, action: 'add-code', busy: true }, { name: 'the theme\'s serif heading, its font late', deck: 'systemHeading', path: (s) => '/d/' + s + '/edit', editor: true, slowFont: /LiberationSerif-/, fontDelay: 2000, length: 5000, action: 'theme-heading', busy: true }, // The prefetch has brought the family in: no wait at all. { name: 'add a code block once the prefetch is done', deck: 'plain', path: (s) => '/d/' + s + '/edit', editor: true, length: 3000, action: 'add-code', prefetched: true, busy: false }, // The probe's control: a run in a face that is loading, on purpose. { name: 'control: text in a face that has not loaded', deck: 'plain', path: (s) => '/d/' + s + '?slide=1', length: 2500, probeControl: true }, // The control: shown, then hidden for a second. Must be caught. { name: 'control: hidden for a second after it is shown', deck: 'paper', path: (s) => '/d/' + s + '?slide=1', control: true }, ] const only = process.env.SLIDES_ENGINES_ONLY const chosen = only ? scenarios.filter((s) => s.control || s.probeControl || s.name.includes(only)) : scenarios // unloadedOnce puts a run on the slide, once it is shown, in a face // added to the page that is still loading. const unloadedOnce = `(() => { const tick = () => { const s = document.querySelector('[slides-slide]') if (s && document.documentElement.getAttribute('data-slides-fonts') === 'shown') { const face = new FontFace('Liberation Mono', 'url("/static/fonts/LiberationMono-Regular.woff2?probe-control")', { weight: '400', style: 'normal' }) document.fonts.add(face) face.load().catch(() => {}) const p = document.createElement('p'); p.style.fontFamily = '"Liberation Mono"'; p.textContent = 'Not loaded yet' s.querySelector('[slides-block]').append(p) return } requestAnimationFrame(tick) } requestAnimationFrame(tick) })()` // flashOnce is the control's deliberate flash. const flashOnce = `(() => { const tick = () => { const s = document.querySelector('[slides-slide]') if (s && getComputedStyle(s).visibility === 'visible' && s.textContent.trim()) { setTimeout(() => { s.style.setProperty('visibility', 'hidden', 'important') setTimeout(() => s.style.removeProperty('visibility'), 1000) }, 600) return } requestAnimationFrame(tick) } requestAnimationFrame(tick) })()` const ACTIONS = { 'add-code': () => { document.querySelector('[slides-menu="insert"]').open = true document.querySelector('[slides-menu="insert"] [data-insert-block="code"]').click() }, 'theme-heading': () => { const s = document.querySelector('#rst-deck-font-heading') s.value = '' s.dispatchEvent(new Event('change', { bubbles: true })) }, } // The slide's box, once it is laid out: what every capture is clipped to. const slideBox = () => { const s = document.querySelector('[slides-stage] [slides-slide]') || document.querySelector('[slides-slide]') if (!s) return null const r = s.getBoundingClientRect() // Laid out by slides.css (a 16:9 box), not the unstyled document a // capture can catch before the stylesheets are in. if (r.width < 50 || r.height < 50 || Math.abs(r.width / r.height - 16 / 9) > 0.05) return null return { x: Math.max(0, Math.floor(r.left)), y: Math.max(0, Math.floor(r.top)), width: Math.floor(r.width), height: Math.floor(r.height) } } function verdict(frames) { const text = frames.findIndex((f) => !f.blank) if (text < 0) return 'the slide was never seen with text on it' const last = frames[frames.length - 1] if (last.blank) return `the slide was blank at the end (${last.ms}ms)` for (const f of frames.slice(text)) { if (f.blank) return `text was on screen at ${frames[text].ms}ms, then gone at ${f.ms}ms` if (f.hash !== last.hash) return `at ${f.ms}ms the slide was ${f.hash.slice(0, 8)}; finally ${last.hash.slice(0, 8)}` } return null } function actionVerdict(frames, before, busy) { const after = frames.filter((f) => f.afterAction) const last = after[after.length - 1] if (!last) return 'nothing was captured after the action' if (last.ink === before.ink) return 'the action never took effect' if (busy && !after[0].busy) return 'the wait for the font was not said at once' if (!busy && after.some((f) => f.busy)) return 'the action waited for a font the prefetch had brought in' for (const f of after) { if (f.blank) return `the slide was blank at ${f.ms}ms` if (f.ink !== before.ink && f.ink !== last.ink) return `at ${f.ms}ms text that was neither the text before the action nor the final text` } return null } const failures = [] const engines = Object.entries({ chromium, webkit }).filter(([n]) => !process.env.SLIDES_ENGINES_ENGINE || n === process.env.SLIDES_ENGINES_ENGINE) for (const [engineName, engine] of engines) { // Chromium is the full browser in its new headless mode (channel // 'chromium'), not Playwright's default headless shell: the shell // re-rasterises a few glyph edges differently when a late editor // replaces a text's DOM with an identical one, which no browser a // person uses does, and these checks compare pixels exactly. const browser = await engine.launch(engineName === 'chromium' ? { headless: true, channel: 'chromium' } : { headless: true }) for (const s of chosen) { const context = await browser.newContext({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 1 }) await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))) if (s.control) await context.addInitScript(flashOnce) if (s.probeControl) await context.addInitScript(unloadedOnce) await context.addInitScript(config.probe) await context.route('**/*', async (route) => { const url = route.request().url() if (s.block && s.block.test(url)) return route.abort() if (url.includes('probe-control')) { await pause(8000) return route.continue().catch(() => {}) } const editorJS = /\/static\/editor\.[0-9a-f.]+\.js/.test(url) const wait = s.editorDelay && editorJS ? s.editorDelay : s.slowFont && s.slowFont.test(url) ? s.fontDelay : 0 if (wait) { const response = await route.fetch() await pause(wait) try { await route.fulfill({ response }) } catch {} return } return route.continue() }) const page = await context.newPage() const target = config.decks[s.deck].shift() if (!target) throw new Error(`no fresh ${s.deck} deck left for ${engineName}, ${s.name}`) await page.goto(config.origin + s.path(target), { waitUntil: 'commit' }) const label = `${engineName}, ${s.name}` const frames = [] const skipped = { clip: 0, state: 0, shot: 0 } let before = null if (s.action) { await page.waitForSelector('[slides-stage] [contenteditable="true"]', { timeout: 15000 }) await page.waitForFunction(() => document.documentElement.getAttribute('data-slides-fonts') === 'shown', null, { timeout: 15000 }) if (s.prefetched) await page.waitForFunction(() => document.documentElement.getAttribute('data-slides-fonts-prefetch') === 'done', null, { timeout: 60000 }) await pause(800) } let clip = null const start = Date.now() let acted = false while (Date.now() - start < (s.length || (s.editorDelay || 0) + 3500)) { if (s.action && !acted && before) { await page.evaluate(ACTIONS[s.action]) acted = true } const ms = Date.now() - start if (!clip) clip = await page.evaluate(slideBox).catch(() => null) if (!clip) { skipped.clip++; await pause(20); continue } const state = await page.evaluate(() => { const sl = document.querySelector('[slides-stage] [slides-slide]') || document.querySelector('[slides-slide]') const st = document.querySelector('[slides-fonts-status]') return sl ? { visible: getComputedStyle(sl).visibility === 'visible', busy: !!st && ['loading', 'refused'].includes(st.getAttribute('data-state')) } : null }).catch(() => null) if (!state) { skipped.state++; continue } // Nothing is added to the page for the capture: a stylesheet // inserted per screenshot makes WebKit rebuild its font set (Docs' // review 7). const raw = await page.screenshot({ clip, caret: 'hide', timeout: 2000 }).catch(() => null) if (!raw) { skipped.shot++; continue } const shot = PNG.sync.read(raw) // The background is the commonest colour in a sparse sample; ink // is every pixel well away from it. The ink mask is compared for // an action, so a selection or focus ring that the editor draws a // frame later is not the text changing. const counts = new Map() for (let i = 0; i < shot.data.length; i += 4 * 17) { const k = (shot.data[i] >> 3) << 10 | (shot.data[i + 1] >> 3) << 5 | (shot.data[i + 2] >> 3) counts.set(k, (counts.get(k) || 0) + 1) } let bg = 0 let most = -1 for (const [k, n] of counts) if (n > most) { most = n; bg = k } const [br, bgc, bb] = [((bg >> 10) & 31) << 3, ((bg >> 5) & 31) << 3, (bg & 31) << 3] const mask = Buffer.alloc(shot.data.length / 4) let ink = 0 for (let i = 0; i < shot.data.length; i += 4) { const d = Math.abs(shot.data[i] - br) + Math.abs(shot.data[i + 1] - bgc) + Math.abs(shot.data[i + 2] - bb) if (d > 160) { mask[i / 4] = 1; ink++ } } const blank = !state.visible || ink < 20 if (process.env.SLIDES_ENGINES_SHOTS && !blank) writeFileSync(`${process.env.SLIDES_ENGINES_SHOTS}/${engineName}-${s.name.replace(/\W+/g, '_')}-${frames.length}.png`, raw) const frame = { ms, blank, hash: createHash('sha256').update(shot.data).digest('hex'), ink: createHash('sha256').update(mask).digest('hex'), busy: state.busy, afterAction: acted } if (s.action && !acted && !blank) before = frame frames.push(frame) } let v = s.action ? actionVerdict(frames, before || frames[0], s.busy) : verdict(frames) const violations = await page.evaluate(() => (window.__fontProbe ? window.__fontProbe.violations : null)).catch(() => null) if (!v && violations && violations.length) v = `text visible in a face that had not loaded: ${violations[0]}` const transitions = frames.filter((f, i) => !i || f.hash !== frames[i - 1].hash || f.blank !== frames[i - 1].blank).map((f) => `${f.ms}${f.afterAction ? '*' : ''}:${f.blank ? 'blank' : f.hash.slice(0, 6)}`) console.log(JSON.stringify({ engine: engineName, scenario: s.name, frames: frames.length, skipped, verdict: v, transitions: transitions.slice(0, 12) })) if (s.probeControl) { if (!violations || !violations.length) failures.push(`${label}: the font probe did not see text in a face that had not loaded; it is blind`) } else if (s.control && !v) failures.push(`${label}: the check did not see the control's flash; it is blind`) else if (!s.control && v) failures.push(`${label}: ${v}`) await context.close() } await browser.close() } if (failures.length) { console.error(failures.join('\n')) process.exit(1) }