| 1 | //go:build browser |
| 2 | |
| 3 | package slidestest |
| 4 | |
| 5 | import ( |
| 6 | "encoding/json" |
| 7 | "net/http" |
| 8 | "strconv" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | "time" |
| 12 | |
| 13 | "github.com/chromedp/cdproto/cdp" |
| 14 | "github.com/chromedp/cdproto/network" |
| 15 | "github.com/chromedp/cdproto/page" |
| 16 | "github.com/chromedp/chromedp" |
| 17 | ) |
| 18 | |
| 19 | // Astra's second review of #27: the interleavings the first round's fixes |
| 20 | // did not cover. Each was a probe of Astra's that failed at c1d2f4d. |
| 21 | |
| 22 | // A resync never discards a change that was waiting for its font. The |
| 23 | // accent's save is refused (413), which sends the editor into a resync; |
| 24 | // meanwhile text with code in it is pasted, its font three seconds away. |
| 25 | // The paste runs once its font is in, on the document it was made in, and |
| 26 | // survives the rebuild: it is on the slide afterwards, in the code face, |
| 27 | // and on the server, once. And it never leaves the slide on the way: once |
| 28 | // its words are there, no frame and no DOM change is without them, in the |
| 29 | // desktop view or the both view, whose phone stage loads over the network |
| 30 | // in the middle of the rebuild (Claude Fable on #27: the server's HTML |
| 31 | // was installed, and painted, before the paste was put back). |
| 32 | func TestFontAResyncNeverDiscardsAWaitingPaste(t *testing.T) { |
| 33 | for _, view := range []string{"desktop", "both"} { |
| 34 | t.Run(view, func(t *testing.T) { |
| 35 | fr := newFontRig(t) |
| 36 | sqid := fr.deck(t, "resync pending paste", inkDeck) |
| 37 | fr.match.Store("LiberationMono-") |
| 38 | fr.slow.Store(int64(3 * time.Second)) |
| 39 | fr.rig.Run(fr.navigate("/d/" + sqid + "/edit")) |
| 40 | fr.editable(t) |
| 41 | if view != "desktop" { |
| 42 | fr.eval(t, clickJS(`[slides-switcher] input[value="`+view+`"]`), nil) |
| 43 | fr.rig.Run(chromedp.Sleep(800 * time.Millisecond)) |
| 44 | fr.editable(t) |
| 45 | } |
| 46 | fr.eval(t, `(() => { const f = window.fetch; let first = true; |
| 47 | window.fetch = async function (u, o) { |
| 48 | if (first && String(u).endsWith('/updates') && o && o.method === 'POST') { first = false; await new Promise((r) => setTimeout(r, 150)); return new Response('', { status: 413 }) } |
| 49 | return f.call(this, u, o) }; |
| 50 | window.__log = []; const stage = document.querySelector('[slides-stage]'); |
| 51 | const rec = () => { const has = stage.textContent.includes('REVIEW_RESYNC_PASTE'); const last = window.__log[window.__log.length - 1]; |
| 52 | if (!last || last.has !== has) window.__log.push({ ms: Math.round(performance.now()), has }) }; |
| 53 | new MutationObserver(rec).observe(stage, { subtree: true, childList: true, characterData: true }); |
| 54 | const frame = () => { rec(); requestAnimationFrame(frame) }; requestAnimationFrame(frame); |
| 55 | return true })()`, nil) |
| 56 | fr.eval(t, changeJS("#rst-deck-accent", "#ff0000"), nil) |
| 57 | fr.eval(t, pasteJS(`<p>REVIEW_RESYNC_PASTE <code>codeword</code></p>`), nil) |
| 58 | fr.rig.Run(chromedp.Sleep(6 * time.Second)) |
| 59 | text := fr.stageText(t) |
| 60 | if strings.Count(text, "REVIEW_RESYNC_PASTE") != 1 { |
| 61 | t.Errorf("after the resync the paste is on the slide %d times: %q", strings.Count(text, "REVIEW_RESYNC_PASTE"), text) |
| 62 | } |
| 63 | if got := fr.faceOf(t, `[slides-stage] [data-block="text"] code`); !strings.HasPrefix(got, "liberation mono:web") { |
| 64 | t.Errorf("the pasted code is in %s", got) |
| 65 | } |
| 66 | var log []struct { |
| 67 | Ms int `json:"ms"` |
| 68 | Has bool `json:"has"` |
| 69 | } |
| 70 | fr.eval(t, `window.__log`, &log) |
| 71 | seen := 0 |
| 72 | for _, e := range log { |
| 73 | if e.Has { |
| 74 | seen++ |
| 75 | } |
| 76 | } |
| 77 | if seen != 1 { |
| 78 | t.Errorf("the pasted words appeared %d times on the stage, want once and to stay: %+v", seen, log) |
| 79 | } |
| 80 | view := apiJSON(t, fr.app, http.MethodGet, "/api/v1/decks/"+sqid, fr.token, "", http.StatusOK) |
| 81 | b, _ := json.Marshal(view) |
| 82 | if n := strings.Count(string(b), "REVIEW_RESYNC_PASTE"); n != 1 { |
| 83 | t.Errorf("the server holds the paste %d times, want once: %s", n, b) |
| 84 | } |
| 85 | }) |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | // refuseFirstSaveJS answers the editor's first save 413 and marks the |
| 90 | // moment (window.refused); every later save is counted (window.later) and |
| 91 | // its bytes kept as a string (window.laterBodies: the words an update |
| 92 | // inserts are in it as they are). |
| 93 | // holdResync holds the rebuild's fetch of the whole log: for ms, or |
| 94 | // forever when ms is 0. |
| 95 | func refuseFirstSaveJS(holdResyncMs int) string { |
| 96 | hold := `await new Promise(() => {})` |
| 97 | if holdResyncMs > 0 { |
| 98 | hold = `await new Promise((r) => setTimeout(r, ` + strconv.Itoa(holdResyncMs) + `))` |
| 99 | } |
| 100 | return `(() => { const f = window.fetch; window.later = []; window.laterBodies = []; |
| 101 | window.fetch = async function (u, o) { |
| 102 | const post = String(u).endsWith('/updates') && o && o.method === 'POST'; |
| 103 | if (post && !window.refused) { await new Promise((r) => setTimeout(r, 150)); window.refused = true; return new Response('', { status: 413 }) } |
| 104 | if (window.refused && String(u).includes('since=0')) { ` + hold + ` } |
| 105 | const r = await f.call(this, u, o); |
| 106 | if (post) { window.later.push(r.status); window.laterBodies.push(Array.from(o.body, (c) => String.fromCharCode(c)).join('')) } |
| 107 | return r }; |
| 108 | return true })()` |
| 109 | } |
| 110 | |
| 111 | // Changes written on top of text the server refused are kept without it |
| 112 | // (feat/replay-while-diverged). Two pastes after the refused words and a |
| 113 | // Backspace over them, none of which waited for a font: their own Yjs |
| 114 | // updates are anchored to the refused words and cannot be carried, so |
| 115 | // they are replayed from their ProseMirror transactions. The pastes land |
| 116 | // where the refused words were, once, on the page and on the server; the |
| 117 | // Backspace had nothing left to delete; the refused words are on neither. |
| 118 | // (On fix/carry-replay they were held back and lost; before it they were |
| 119 | // posted and sat pending in the server's log, Claude Fable on #27/#88.) |
| 120 | func TestChangesOnRefusedTextAreKeptWithoutIt(t *testing.T) { |
| 121 | fr := newFontRig(t) |
| 122 | sqid := fr.deck(t, "uncarriable", inkDeck) |
| 123 | fr.rig.Run(fr.navigate("/d/" + sqid + "/edit")) |
| 124 | fr.editable(t) |
| 125 | fr.eval(t, refuseFirstSaveJS(2500), nil) |
| 126 | fr.eval(t, pasteJS(`REFUSEDWORDS`), nil) |
| 127 | fr.until(t, `window.refused === true`) |
| 128 | fr.rig.Run(chromedp.Sleep(50 * time.Millisecond)) |
| 129 | fr.eval(t, pasteJS(`ONTOPOFIT`), nil) |
| 130 | fr.rig.Run(chromedp.Sleep(50 * time.Millisecond)) |
| 131 | fr.eval(t, pasteJS(`ANDAGAIN`), nil) |
| 132 | fr.rig.Run(chromedp.Sleep(50 * time.Millisecond)) |
| 133 | // Select the refused words and press Backspace. |
| 134 | fr.eval(t, `(() => { const el = document.querySelector('[slides-stage] [data-block="text"]'); el.focus(); |
| 135 | const w = document.createTreeWalker(el, NodeFilter.SHOW_TEXT); let n; |
| 136 | while ((n = w.nextNode())) { const i = n.data.indexOf('REFUSEDWORDS'); if (i >= 0) { const r = document.createRange(); r.setStart(n, i); r.setEnd(n, i + 12); |
| 137 | getSelection().removeAllRanges(); getSelection().addRange(r); return true } } |
| 138 | return false })()`, nil) |
| 139 | fr.rig.Run(chromedp.Sleep(50*time.Millisecond), chromedp.KeyEvent("\b")) |
| 140 | fr.rig.Run(chromedp.Sleep(4 * time.Second)) |
| 141 | text := fr.stageText(t) |
| 142 | view := apiJSON(t, fr.app, http.MethodGet, "/api/v1/decks/"+sqid, fr.token, "", http.StatusOK) |
| 143 | b, _ := json.Marshal(view) |
| 144 | for _, c := range []struct { |
| 145 | words string |
| 146 | n int |
| 147 | }{{"REFUSEDWORDS", 0}, {"ONTOPOFIT", 1}, {"ANDAGAIN", 1}} { |
| 148 | if got := strings.Count(text, c.words); got != c.n { |
| 149 | t.Errorf("the page holds %s %d times, want %d: %q", c.words, got, c.n, text) |
| 150 | } |
| 151 | if got := strings.Count(string(b), c.words); got != c.n { |
| 152 | t.Errorf("the server holds %s %d times, want %d", c.words, got, c.n) |
| 153 | } |
| 154 | } |
| 155 | samePageAndServer(t, fr, sqid) |
| 156 | } |
| 157 | |
| 158 | // Closing the tab while it is diverged sends what was written meanwhile |
| 159 | // (Claude Fable on #27: the beacon read only the old queue, and the words |
| 160 | // typed after the refusal were in neither). |
| 161 | func TestLeavingWhileDivergedSendsWhatWasWritten(t *testing.T) { |
| 162 | fr := newFontRig(t) |
| 163 | sqid := fr.deck(t, "beacon diverged", inkDeck) |
| 164 | fr.rig.Run(fr.navigate("/d/" + sqid + "/edit")) |
| 165 | fr.editable(t) |
| 166 | fr.eval(t, refuseFirstSaveJS(0), nil) |
| 167 | fr.eval(t, changeJS("#rst-deck-accent", "#ff0000"), nil) |
| 168 | fr.until(t, `window.refused === true`) |
| 169 | fr.rig.Run(chromedp.Sleep(50 * time.Millisecond)) |
| 170 | fr.eval(t, pasteJS(`BEACONEDWORDS`), nil) |
| 171 | fr.rig.Run(chromedp.Sleep(100 * time.Millisecond)) |
| 172 | fr.rig.Run(chromedp.Navigate("about:blank")) |
| 173 | deadline := time.Now().Add(5 * time.Second) |
| 174 | for { |
| 175 | view := apiJSON(t, fr.app, http.MethodGet, "/api/v1/decks/"+sqid, fr.token, "", http.StatusOK) |
| 176 | b, _ := json.Marshal(view) |
| 177 | if strings.Count(string(b), "BEACONEDWORDS") == 1 { |
| 178 | return |
| 179 | } |
| 180 | if time.Now().After(deadline) { |
| 181 | t.Fatalf("the words written while diverged never reached the server: %s", b) |
| 182 | } |
| 183 | time.Sleep(100 * time.Millisecond) |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | // A slide made in an empty deck goes up once its save is acknowledged, |
| 188 | // through a retry: the first save answers 500, its retry 204, and the |
| 189 | // stage shows the new slide. |
| 190 | func TestANewSlideGoesUpAfterARetriedSave(t *testing.T) { |
| 191 | fr := newFontRig(t) |
| 192 | sqid := fr.deck(t, "first save retry", `[{"op":"set_meta","theme":"paper","title":"Empty"}]`) |
| 193 | fr.rig.Run(fr.navigate("/d/" + sqid + "/edit")) |
| 194 | fr.until(t, `document.documentElement.dataset.slidesFonts === 'shown' && !!document.querySelector('[slides-menu]')`) |
| 195 | fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) |
| 196 | fr.eval(t, `(() => { const f = fetch; let first = true; window.posts = []; |
| 197 | window.fetch = async (...args) => { |
| 198 | if (String(args[0]).endsWith('/updates') && args[1] && args[1].method === 'POST') { |
| 199 | if (first) { first = false; window.posts.push(500); return new Response('', { status: 500 }) } |
| 200 | const r = await f(...args); window.posts.push(r.status); return r } |
| 201 | return f(...args) }; |
| 202 | return true })()`, nil) |
| 203 | fr.eval(t, clickJS(`[slides-menu] [data-command="new-slide"]`), nil) |
| 204 | fr.until(t, `!!document.querySelector('[slides-stage] [data-block="heading"][contenteditable="true"]')`) |
| 205 | var posts []int |
| 206 | fr.eval(t, `window.posts`, &posts) |
| 207 | if len(posts) < 2 || posts[0] != 500 { |
| 208 | t.Errorf("the saves were answered %v; the check meant a 500 then its retry", posts) |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // The projector never goes back to an older slide because an old answer |
| 213 | // arrived late (Astra's finding 2 on #27). Each case holds an answer back, |
| 214 | // lets the session move on through the stream, then releases it: nothing |
| 215 | // changes — not the slide, not the counter, not the blackout. |
| 216 | // |
| 217 | // This is static/present.js's ordering, which a session begun before |
| 218 | // positions keeps (preDeploy). A session with a position moves its slide |
| 219 | // window from memory instead, and its link orders presses and answers |
| 220 | // (fixtures/talk-link.mjs, TestPresenterFastPressesNeverJumpBack). |
| 221 | func TestTheProjectorIgnoresAStaleAnswer(t *testing.T) { |
| 222 | three := strings.TrimSuffix(paperDeck, "]") + `,{"op":"add_slide","id":"slidethree03","layout":"flow","template":"title-body"},{"op":"add_block","slide":"slidethree03","id":"head00000003","type":"heading","region":"heading","props":{"level":1},"markdown":"Third"}]` |
| 223 | // holdJS holds the body of the next response whose URL matches. |
| 224 | holdJS := func(match string) string { |
| 225 | return `(() => { const f = window.fetch; window.fetch = async function (u, o) { const r = await f.call(this, u, o); |
| 226 | if (` + match + `) { const text = r.text.bind(r); r.text = async () => { const html = await text(); window.held = true; await new Promise((res) => (window.release = res)); return html } } |
| 227 | return r }; return true })()` |
| 228 | } |
| 229 | for _, c := range []struct { |
| 230 | name, page, hold, act string |
| 231 | after func(fr *fontRig, session, token string) |
| 232 | want string // the data-slide that must stay |
| 233 | blackout bool |
| 234 | }{ |
| 235 | {name: "the presenter's Next answered after the stream moved on", page: "token", |
| 236 | hold: `String(u).endsWith('/command')`, |
| 237 | act: `document.querySelector('[slides-bar] form input[value="next"]').form.requestSubmit()`, |
| 238 | after: func(fr *fontRig, s, tk string) { |
| 239 | fr.until(t, `window.held && document.querySelector('[slides-surface]').dataset.slide === '2'`) |
| 240 | command(t, fr.app, s, "next", tk, "", nil) |
| 241 | }, want: "3"}, |
| 242 | {name: "a watcher's Next answered after the stream moved on", page: "watcher", |
| 243 | hold: `String(u).includes('slide=2') && !String(u).includes('/updates')`, |
| 244 | act: `document.querySelector('[slides-bar] a[rel="next"]').click()`, |
| 245 | after: func(fr *fontRig, s, tk string) { |
| 246 | fr.until(t, `window.held`) |
| 247 | command(t, fr.app, s, "next", tk, "", nil) |
| 248 | command(t, fr.app, s, "next", tk, "", nil) |
| 249 | }, want: "3"}, |
| 250 | {name: "a watcher's Back answered after the stream moved on", page: "watcher", |
| 251 | hold: `window.armed && String(u) === location.href`, |
| 252 | act: `document.querySelector('[slides-bar] a[rel="next"]').click()`, |
| 253 | after: func(fr *fontRig, s, tk string) { |
| 254 | fr.until(t, `document.querySelector('[slides-surface]').dataset.slide === '2' && location.search.includes('slide=2')`) |
| 255 | fr.eval(t, `window.armed = true; history.back(); true`, nil) |
| 256 | fr.until(t, `window.held`) |
| 257 | command(t, fr.app, s, "next", tk, "", nil) |
| 258 | command(t, fr.app, s, "next", tk, "", nil) |
| 259 | }, want: "3"}, |
| 260 | {name: "an old answer does not lift a blackout", page: "token", |
| 261 | hold: `String(u).endsWith('/command')`, |
| 262 | act: `document.querySelector('[slides-bar] form input[value="next"]').form.requestSubmit()`, |
| 263 | after: func(fr *fontRig, s, tk string) { |
| 264 | fr.until(t, `window.held && document.querySelector('[slides-surface]').dataset.slide === '2'`) |
| 265 | command(t, fr.app, s, "blackout", tk, "", nil) |
| 266 | }, want: "2", blackout: true}, |
| 267 | } { |
| 268 | t.Run(c.name, func(t *testing.T) { |
| 269 | fr := newFontRig(t) |
| 270 | sqid := fr.deck(t, "ordering", three) |
| 271 | session, token := startPresenting(t, fr.app, "/d/"+sqid, fr.cookies) |
| 272 | preDeploy(t, fr.app, session) |
| 273 | path := "/p/" + session |
| 274 | if c.page == "token" { |
| 275 | path += "?t=" + token |
| 276 | } else { |
| 277 | // A watcher is nobody signed in: the presenter's own |
| 278 | // cookie drives even a talk begun before positions. |
| 279 | fr.rig.Run(cdpStep(network.ClearBrowserCookies, cdp.Empty{})) |
| 280 | } |
| 281 | fr.rig.Run(fr.navigate(path)) |
| 282 | fr.shown(t) |
| 283 | fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) |
| 284 | fr.eval(t, holdJS(c.hold), nil) |
| 285 | fr.eval(t, `(() => { `+c.act+`; return true })()`, nil) |
| 286 | c.after(fr, session, token) |
| 287 | want := `document.querySelector('[slides-surface]').dataset.slide === '` + c.want + `'` |
| 288 | if c.blackout { |
| 289 | want += ` && document.querySelector('[slides-surface]').dataset.blackout === 'true'` |
| 290 | } |
| 291 | fr.until(t, want) |
| 292 | fr.eval(t, `window.release(); true`, nil) |
| 293 | fr.rig.Run(chromedp.Sleep(time.Second)) |
| 294 | var state struct { |
| 295 | Slide, Blackout, Counter, Text string |
| 296 | } |
| 297 | fr.eval(t, `(() => { const s = document.querySelector('[slides-surface]'); return { Slide: s.dataset.slide, Blackout: s.dataset.blackout, |
| 298 | Counter: (document.querySelector('[slides-counter]') || {}).textContent || '', Text: document.querySelector('[slides-stage]').textContent } })()`, &state) |
| 299 | if state.Slide != c.want { |
| 300 | t.Errorf("the old answer moved the projector to slide %s, want it to stay on %s (%+v)", state.Slide, c.want, state) |
| 301 | } |
| 302 | if c.blackout && state.Blackout != "true" { |
| 303 | t.Error("the old answer lifted the blackout") |
| 304 | } |
| 305 | if !strings.Contains(state.Counter, c.want+" ") && !strings.Contains(state.Counter, " "+c.want+" ") { |
| 306 | t.Errorf("the counter says %q on slide %s", state.Counter, c.want) |
| 307 | } |
| 308 | }) |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | // A presenter's command whose in-place answer fails is never sent twice |
| 313 | // (Claude Fable on #27: the fallback was form.submit(), a second POST of |
| 314 | // "next"). The server applies the Next and the answer is lost; the page |
| 315 | // falls back to loading itself, and the session is on slide 2, not 3. |
| 316 | // |
| 317 | // static/present.js's fallback, on a session begun before positions |
| 318 | // (preDeploy). A session with a position keeps moving with no answer at |
| 319 | // all and tells the server where it went when it can |
| 320 | // (TestADroppedNetworkKeepsThePressingWindowMoving). |
| 321 | func TestAFailedCommandAnswerIsNotSentAgain(t *testing.T) { |
| 322 | three := strings.TrimSuffix(paperDeck, "]") + `,{"op":"add_slide","id":"slidethree03","layout":"flow","template":"title-body"},{"op":"add_block","slide":"slidethree03","id":"head00000003","type":"heading","region":"heading","props":{"level":1},"markdown":"Third"}]` |
| 323 | fr := newFontRig(t) |
| 324 | sqid := fr.deck(t, "fallback", three) |
| 325 | session, token := startPresenting(t, fr.app, "/d/"+sqid, fr.cookies) |
| 326 | preDeploy(t, fr.app, session) |
| 327 | // The stream is kept quiet, so the failed answer is still the newest |
| 328 | // thing this page has heard: with it, the stream's own event would |
| 329 | // move the page on and the fallback would never run. |
| 330 | fr.rig.Run(cdpStep(page.AddScriptToEvaluateOnNewDocument, page.AddScriptToEvaluateOnNewDocumentParams{ |
| 331 | Source: `try { if (sessionStorage.getItem('quiet-stream')) window.EventSource = class { addEventListener () {} close () {} } } catch (e) {}`, |
| 332 | })) |
| 333 | fr.goTo(t, "/p/"+session+"?t="+token) |
| 334 | fr.eval(t, `sessionStorage.setItem('quiet-stream', '1'); true`, nil) |
| 335 | fr.goTo(t, "/p/"+session+"?t="+token) |
| 336 | fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) |
| 337 | fr.eval(t, `(() => { const f = window.fetch; window.fetch = async function (u, o) { const r = await f.call(this, u, o); |
| 338 | if (String(u).endsWith('/command')) return new Response('', { status: 502 }); |
| 339 | return r }; window.__before = true; return true })()`, nil) |
| 340 | fr.eval(t, `(() => { document.querySelector('[slides-bar] form input[value="next"]').form.requestSubmit(); return true })()`, nil) |
| 341 | fr.until(t, `!window.__before && document.documentElement.dataset.slidesFonts === 'shown' && !!document.querySelector('[slides-surface]')`) |
| 342 | fr.rig.Run(chromedp.Sleep(time.Second)) |
| 343 | var slide string |
| 344 | fr.eval(t, `document.querySelector('[slides-surface]').dataset.slide`, &slide) |
| 345 | if slide != "2" { |
| 346 | t.Errorf("after one Next whose answer failed the session is on slide %s, want 2: the command was sent again", slide) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // After an in-place change of slide, focus is where a keyboard user |
| 351 | // expects it and the change is said (Astra's finding 4 on #27). Pressed |
| 352 | // with the keyboard: Next keeps focus on Next; Previous onto the first |
| 353 | // slide and Next onto the last, where that link is gone, put focus on the |
| 354 | // slide; the projector's Next button keeps it, and a watcher's Next onto |
| 355 | // the last slide puts it on the slide. Each change is said through a |
| 356 | // polite live region that was in the page before it: "Slide 2 of 3: |
| 357 | // Second". |
| 358 | func TestInPlaceSlideChangesKeepFocusAndAreAnnounced(t *testing.T) { |
| 359 | three := strings.TrimSuffix(paperDeck, "]") + `,{"op":"add_slide","id":"slidethree03","layout":"flow","template":"title-body"},{"op":"add_block","slide":"slidethree03","id":"head00000003","type":"heading","region":"heading","props":{"level":1},"markdown":"Third"}]` |
| 360 | fr := newFontRig(t) |
| 361 | sqid := fr.deck(t, "a11y", three) |
| 362 | type spot struct { |
| 363 | Active, Said, Live, Polite string |
| 364 | } |
| 365 | look := func() spot { |
| 366 | var s spot |
| 367 | fr.eval(t, `(() => { const a = document.activeElement; const r = document.querySelector('[slides-announce]'); |
| 368 | return { Active: a === document.body ? 'BODY' : a.matches('[slides-slide]') ? 'SLIDE' : (a.getAttribute('rel') || a.getAttribute('slides-op') || a.tagName), |
| 369 | Said: r ? r.textContent : '', Live: r ? r.getAttribute('role') : '', Polite: r ? r.getAttribute('aria-live') : '' } })()`, &s) |
| 370 | return s |
| 371 | } |
| 372 | check := func(where, active, said string) { |
| 373 | t.Helper() |
| 374 | got := look() |
| 375 | if got.Active != active { |
| 376 | t.Errorf("%s: focus is on %s, want %s", where, got.Active, active) |
| 377 | } |
| 378 | if got.Said != said { |
| 379 | t.Errorf("%s: the live region says %q, want %q", where, got.Said, said) |
| 380 | } |
| 381 | if got.Live != "status" || got.Polite != "polite" { |
| 382 | t.Errorf("%s: the announcement is not a polite status region (%+v)", where, got) |
| 383 | } |
| 384 | } |
| 385 | for _, mode := range []string{"", "&present=1"} { |
| 386 | fr.goTo(t, "/d/"+sqid+"?slide=2"+mode) |
| 387 | fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) |
| 388 | fr.eval(t, `document.querySelector('[slides-pager] a[rel="prev"]').focus(); true`, nil) |
| 389 | fr.rig.Run(chromedp.KeyEvent("\r")) |
| 390 | fr.until(t, `location.search.includes('slide=1') && document.querySelector('[slides-slide]').textContent.includes('A heading in serif')`) |
| 391 | check("viewer"+mode+", Previous to the first slide", "SLIDE", "Slide 1 of 3: A heading in serif") |
| 392 | fr.eval(t, `document.querySelector('[slides-pager] a[rel="next"]').focus(); true`, nil) |
| 393 | fr.rig.Run(chromedp.KeyEvent("\r")) |
| 394 | fr.until(t, `location.search.includes('slide=2') && document.querySelector('[slides-slide]').textContent.includes('Second')`) |
| 395 | check("viewer"+mode+", Next to slide 2", "next", "Slide 2 of 3: Second") |
| 396 | fr.rig.Run(chromedp.KeyEvent("\r")) |
| 397 | fr.until(t, `location.search.includes('slide=3') && document.querySelector('[slides-slide]').textContent.includes('Third')`) |
| 398 | check("viewer"+mode+", Next to the last slide", "SLIDE", "Slide 3 of 3: Third") |
| 399 | } |
| 400 | session, token := startPresenting(t, fr.app, "/d/"+sqid, fr.cookies) |
| 401 | fr.goTo(t, "/p/"+session+"?t="+token) |
| 402 | fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) |
| 403 | fr.eval(t, `document.querySelector('[slides-op="next"]').focus(); true`, nil) |
| 404 | fr.rig.Run(chromedp.KeyEvent("\r")) |
| 405 | fr.until(t, `document.querySelector('[slides-surface]').dataset.slide === '2' && document.querySelector('[slides-announce]').textContent !== ''`) |
| 406 | fr.rig.Run(chromedp.Sleep(500 * time.Millisecond)) |
| 407 | check("projector, the Next button", "next", "Slide 2 of 3: Second") |
| 408 | // A watcher is somebody who is not signed in: on a session with a |
| 409 | // position the signed-in presenter gets the controls here instead. |
| 410 | fr.rig.Run(cdpStep(network.ClearBrowserCookies, cdp.Empty{})) |
| 411 | fr.goTo(t, "/p/"+session+"?slide=2") |
| 412 | fr.rig.Run(chromedp.Sleep(300 * time.Millisecond)) |
| 413 | fr.eval(t, `document.querySelector('[slides-bar] a[rel="next"]').focus(); true`, nil) |
| 414 | fr.rig.Run(chromedp.KeyEvent("\r")) |
| 415 | fr.until(t, `document.querySelector('[slides-surface]').dataset.slide === '3' && document.querySelector('[slides-announce]').textContent !== ''`) |
| 416 | check("projector, a watcher's Next to the last slide", "SLIDE", "Slide 3 of 3: Third") |
| 417 | } |
| 418 | |