//go:build browser package slidestest // A reader open on a deck learns a font the deck takes on after it was // opened (final review, I6): the viewer's in-place paging, the follow // view (static/present.js) and the slide window (talk-store.mjs) each // carry the incoming page's or talk version's uploaded fonts, learn them // and make them ready before the slide goes up. Before, the incoming // slide was shown in the stack's next family for the rest of the visit. import ( "strings" "testing" "time" "github.com/chromedp/cdproto/cdp" "github.com/chromedp/cdproto/network" "github.com/chromedp/chromedp" ) func TestAnUploadedFontReachesAnOpenReader(t *testing.T) { for _, c := range []struct { name string watcher bool path func(sqid, session, token string) string next, prev string }{ {"viewer", false, func(sqid, _, _ string) string { return "/d/" + sqid + "?slide=1" }, `[slides-pager] a[rel="next"]`, `[slides-pager] a[rel="prev"]`}, {"follow view", true, func(_, session, _ string) string { return "/p/" + session }, `[slides-bar] a[rel="next"]`, `[slides-bar] a[rel="prev"]`}, {"slide window", false, func(_, session, token string) string { return "/p/" + session + "?t=" + token }, `[slides-bar] form input[value="next"]`, `[slides-bar] form input[value="prev"]`}, } { t.Run(c.name, func(t *testing.T) { fr := newFontRigWith(t, dirStore(t)) css, _ := uploadFamily(t, fr, "LiberationMono-Regular.ttf", "Oddity Sans 2") sqid := fr.deck(t, "Readers", paperDeck) fam := recordFamily(t, fr, sqid, css) session, token := startPresenting(t, fr.app, "/d/"+sqid, fr.cookies) fr.probeAlso(css) if c.watcher { fr.rig.Run(cdpStep(network.ClearBrowserCookies, cdp.Empty{})) } fr.goTo(t, c.path(sqid, session, token)) fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) fr.eval(t, markPageJS, nil) // The deck takes the font on while the reader is open. fr.ops(t, sqid, `[{"op":"set_meta","fontFiles":[`+fam+`],"fonts":{"heading":"'`+css+`', Liberation Serif, Georgia, serif","body":""}}]`) fr.rig.Run(chromedp.Sleep(time.Second)) press := func(sel, want string) { t.Helper() if strings.Contains(sel, "form") { fr.eval(t, `(() => { document.querySelector(`+jsString(sel)+`).form.requestSubmit(); return true })()`, nil) } else { fr.eval(t, clickJS(sel), nil) } fr.until(t, `document.querySelector('[slides-slide]').textContent.includes(`+jsString(want)+`)`) fr.rig.Run(chromedp.Sleep(700 * time.Millisecond)) } press(c.next, "Second") press(c.prev, "A heading in serif") press(c.next, "Second") var same bool fr.eval(t, `!!window.__samePage`, &same) if !same { t.Fatal("paging reloaded the page, so this shows nothing about the reader learning") } p := fr.cleanAcross(t) web := false for run, faces := range p.Seen { for f := range faces { if strings.Contains(f, "oddity sans 2:") && !strings.Contains(f, "oddity sans 2:web") { t.Errorf("%q was shown in %s: the reader never learned the deck's font", run, f) } web = web || strings.Contains(f, "oddity sans 2:web") } } if !web { t.Errorf("no heading was seen in the deck's uploaded font: %v", p.Seen) } }) } }