//go:build browser package slidestest import ( "context" "encoding/json" "fmt" "net/http" "net/url" "strings" "testing" "time" "amadan.net/rastrillo/fiesta/check/rhythm" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" ) // rhythmCanvas is what the audit reads around on every screen: the // slide itself and the pictures of it. A slide is the deck's geometry, // sized in cqw against its own 16:9 frame (slides.css), not the page's, // so its insides are not on the page's scale and are not meant to be. // The editor's stage and its phone preview, the viewer's slide, the // presenter's slides and the strip's pictures are all that. Nothing // else is skipped: the editor's chrome around the stage (the bar, the // strip, the stage bar, the inspector card, the notes) is read. var rhythmCanvas = []string{ "[slides-slide]", "[slides-thumb]", "[slides-film-thumb]", "[presenter-frame]", } // rhythmScreen is one state of one screen: where it is, what only that // screen draws (ready), the least number of blocks it must draw for the // audit to have read anything, whether page scripts run, and an // optional step in the page (submit a form) with what to wait for after. type rhythmScreen struct { name, path, ready string blocks int noScript bool act, then string // at is where the browser must be when the audit reads, when it is // not path (a form's POST answers at the form's action). at string } // rhythmDrawn is how many blocks main draws outside the skipped // regions: an element with a box, not inline, not inside a region the // audit reads around. A page that drew nothing would pass the audit by // having nothing to measure. const rhythmDrawn = `((skip) => { const main = document.querySelector('main'); if (!main) return 0; let n = 0; for (const el of main.querySelectorAll('*')) { if (skip.some((s) => el.closest(s))) continue; const cs = getComputedStyle(el); if (cs.display === 'none' || cs.display === 'contents' || cs.display.startsWith('inline')) continue; const r = el.getBoundingClientRect(); if (r.width > 0 && r.height > 0) n++; } return n; })` // stackHygiene is what the audit cannot see in a stack under main: a // child taken out of the flow (position: absolute or fixed, such as a // visually hidden live region) that the stack's sibling rule still gave // a margin, which moves it; and the first child in the flow carrying a // margin, which a stack's first block never has. That one comes from // the stack's rule seeing an out-of-flow or visually hidden sibling // before it: the audit measures nothing above a stack's first block. const stackHygiene = `(() => { const out = []; const name = (el) => el.tagName.toLowerCase() + [...el.attributes].filter((a) => a.name !== 'class' && a.name !== 'id' && !a.name.startsWith('aria-')).slice(0, 2).map((a) => '[' + a.name + ']').join(''); for (const stack of document.querySelectorAll('main [rst-stack], main[rst-stack]')) { let first = true; for (const el of stack.children) { const cs = getComputedStyle(el); if (cs.display === 'none' || el.matches('[type="hidden"], template, script')) continue; const margin = parseFloat(cs.marginBlockStart) + parseFloat(cs.marginBlockEnd); if (cs.position === 'absolute' || cs.position === 'fixed') { if (margin !== 0) out.push(name(el) + ' is out of the flow of ' + name(stack) + ' with a ' + margin + 'px margin'); continue; } if (first && parseFloat(cs.marginBlockStart) !== 0) out.push(name(el) + ' opens ' + name(stack) + ' with a ' + cs.marginBlockStart + ' margin'); first = false; } } return out; })()` // scriptsAreOn reads the parser's scripting flag the way the page sees // it: with scripting off, a