oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3package slidestest
4
5// A reader open on a deck learns a font the deck takes on after it was
6// opened (final review, I6): the viewer's in-place paging, the follow
7// view (static/present.js) and the slide window (talk-store.mjs) each
8// carry the incoming page's or talk version's uploaded fonts, learn them
9// and make them ready before the slide goes up. Before, the incoming
10// slide was shown in the stack's next family for the rest of the visit.
11
12import (
13 "strings"
14 "testing"
15 "time"
16
17 "github.com/chromedp/cdproto/cdp"
18 "github.com/chromedp/cdproto/network"
19 "github.com/chromedp/chromedp"
20)
21
22func TestAnUploadedFontReachesAnOpenReader(t *testing.T) {
23 for _, c := range []struct {
24 name string
25 watcher bool
26 path func(sqid, session, token string) string
27 next, prev string
28 }{
29 {"viewer", false, func(sqid, _, _ string) string { return "/d/" + sqid + "?slide=1" },
30 `[slides-pager] a[rel="next"]`, `[slides-pager] a[rel="prev"]`},
31 {"follow view", true, func(_, session, _ string) string { return "/p/" + session },
32 `[slides-bar] a[rel="next"]`, `[slides-bar] a[rel="prev"]`},
33 {"slide window", false, func(_, session, token string) string { return "/p/" + session + "?t=" + token },
34 `[slides-bar] form input[value="next"]`, `[slides-bar] form input[value="prev"]`},
35 } {
36 t.Run(c.name, func(t *testing.T) {
37 fr := newFontRigWith(t, dirStore(t))
38 css, _ := uploadFamily(t, fr, "LiberationMono-Regular.ttf", "Oddity Sans 2")
39 sqid := fr.deck(t, "Readers", paperDeck)
40 fam := recordFamily(t, fr, sqid, css)
41 session, token := startPresenting(t, fr.app, "/d/"+sqid, fr.cookies)
42 fr.probeAlso(css)
43 if c.watcher {
44 fr.rig.Run(cdpStep(network.ClearBrowserCookies, cdp.Empty{}))
45 }
46 fr.goTo(t, c.path(sqid, session, token))
47 fr.rig.Run(chromedp.Sleep(300 * time.Millisecond))
48 fr.eval(t, markPageJS, nil)
49
50 // The deck takes the font on while the reader is open.
51 fr.ops(t, sqid, `[{"op":"set_meta","fontFiles":[`+fam+`],"fonts":{"heading":"'`+css+`', Liberation Serif, Georgia, serif","body":""}}]`)
52 fr.rig.Run(chromedp.Sleep(time.Second))
53 press := func(sel, want string) {
54 t.Helper()
55 if strings.Contains(sel, "form") {
56 fr.eval(t, `(() => { document.querySelector(`+jsString(sel)+`).form.requestSubmit(); return true })()`, nil)
57 } else {
58 fr.eval(t, clickJS(sel), nil)
59 }
60 fr.until(t, `document.querySelector('[slides-slide]').textContent.includes(`+jsString(want)+`)`)
61 fr.rig.Run(chromedp.Sleep(700 * time.Millisecond))
62 }
63 press(c.next, "Second")
64 press(c.prev, "A heading in serif")
65 press(c.next, "Second")
66
67 var same bool
68 fr.eval(t, `!!window.__samePage`, &same)
69 if !same {
70 t.Fatal("paging reloaded the page, so this shows nothing about the reader learning")
71 }
72 p := fr.cleanAcross(t)
73 web := false
74 for run, faces := range p.Seen {
75 for f := range faces {
76 if strings.Contains(f, "oddity sans 2:") && !strings.Contains(f, "oddity sans 2:web") {
77 t.Errorf("%q was shown in %s: the reader never learned the deck's font", run, f)
78 }
79 web = web || strings.Contains(f, "oddity sans 2:web")
80 }
81 }
82 if !web {
83 t.Errorf("no heading was seen in the deck's uploaded font: %v", p.Seen)
84 }
85 })
86 }
87}
88