// fixtures/engines/wait-keys.mjs — during a wait for a font, the keys a // person was editing with stay on the page, in Chromium and in WebKit // (Docs' review 8, adopted). The editor is inert while it waits, so focus // is on the page itself, where Backspace is the browser's: WebKit went // back in history and the waiting change was lost. Space and the arrows // scrolled. // // Run by internal/slidestest/fonts_engines_browser_test.go with the same // SLIDES_ENGINES_CONFIG as first-reveal.mjs. // // Each engine: the deck list, then an editor (so there is a page to go // back to and a page to scroll), with the code face two seconds away: // // 1. Add a code block; during the wait press Backspace, Space, Page // Down, the arrows, Home and End. The page stays where it is and the // code block lands. // 2. Add a code block; during the wait leaving the page asks first // (beforeunload). Staying, the code block lands. const { chromium, webkit } = await import('playwright') const config = JSON.parse(process.env.SLIDES_ENGINES_CONFIG) const pause = (ms) => new Promise((r) => setTimeout(r, ms)) const addCode = () => { document.querySelector('[slides-menu="insert"]').open = true document.querySelector('[slides-menu="insert"] [data-insert-block="code"]').click() } const state = () => ({ path: location.pathname, y: Math.round(scrollY), waiting: document.querySelector('[slides-fonts-status]').getAttribute('data-state') === 'loading', codes: document.querySelectorAll('[slides-stage] [data-block="code"]').length, }) const failures = [] for (const [engineName, engine] of Object.entries({ chromium, webkit }).filter(([n]) => !process.env.SLIDES_ENGINES_ENGINE || n === process.env.SLIDES_ENGINES_ENGINE)) { // 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 leave of [false, true]) { const label = `${engineName}, ${leave ? 'leaving the page' : 'keys'} during a wait` const context = await browser.newContext({ viewport: { width: 1280, height: 700 }, deviceScaleFactor: 1 }) await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))) await context.route('**/*', async (route) => { if (/LiberationMono-/.test(route.request().url())) { const response = await route.fetch() await pause(2500) try { await route.fulfill({ response }) } catch {} return } return route.continue() }) const page = await context.newPage() const deck = config.decks.plain.shift() await page.goto(config.origin + '/') await page.goto(config.origin + '/d/' + deck + '/edit') await page.waitForSelector('[slides-stage] [contenteditable="true"]', { timeout: 15000 }) await page.waitForFunction(() => document.documentElement.getAttribute('data-slides-fonts') === 'shown') await pause(300) const path = await page.evaluate(() => location.pathname) await page.evaluate(addCode) let dialog = null if (leave) { page.once('dialog', (d) => { dialog = d.type(); d.dismiss().catch(() => {}) }) await page.close({ runBeforeUnload: true }) await pause(500) if (page.isClosed()) failures.push(`${label}: the page closed during the wait without asking`) else if (dialog !== 'beforeunload') failures.push(`${label}: leaving during the wait did not ask first (${dialog})`) } else { for (const key of ['Backspace', 'Space', 'PageDown', 'ArrowDown', 'ArrowRight', 'End', 'Home', 'Backspace']) { await page.keyboard.press(key) await pause(60) } const during = await page.evaluate(state) if (!during.waiting) failures.push(`${label}: the wait was over before the keys were pressed, so this proves nothing`) if (during.path !== path) failures.push(`${label}: a key left the page for ${during.path}`) if (during.y !== 0) failures.push(`${label}: a key scrolled the page to ${during.y}`) } if (!page.isClosed()) { await page.waitForFunction(() => document.querySelectorAll('[slides-stage] [data-block="code"]').length > 0, null, { timeout: 10000 }).catch(() => {}) const after = await page.evaluate(state).catch(() => null) if (!after || after.path !== path || after.codes !== 1) failures.push(`${label}: after the wait the page is ${JSON.stringify(after)}; want the editor with one code block`) console.log(JSON.stringify({ engine: engineName, scenario: label, after, dialog })) } await context.close() } await browser.close() } if (failures.length) { console.error(failures.join('\n')) process.exit(1) }