//go:build browser // The slide window's control bar is out of sight while presenting: the // slide has nothing over it. A pointer moving over the window, or focus // entering the bar, shows it; two seconds of stillness, or a key that // moves the talk, hides it again. With scripts off it stays, because it // is then the only way to drive the window. Both scripts do this: the // presenter bundle (a session with a position) and static/present.js // (the follow link). package slidestest import ( "net/url" "testing" "time" "amadan.net/rastrillo/rastrillo/harness" "github.com/chromedp/cdproto/emulation" "github.com/chromedp/cdproto/input" "github.com/chromedp/chromedp" "github.com/chromedp/chromedp/kb" ) // barShownJS: the bar can be seen. Opacity is what hides it, so the // bar stays in the accessibility tree and in the tab order. const barShownJS = `(() => { const b = document.querySelector('[slides-bar]'); return !!b && getComputedStyle(b).opacity === '1' })()` const barHiddenJS = `(() => { const b = document.querySelector('[slides-bar]'); return !!b && getComputedStyle(b).opacity === '0' })()` func mouseTo(x, y float64) chromedp.Action[chromedp.Void] { return cdpStep(input.DispatchMouseEvent, input.DispatchMouseEventParams{Type: chromedp.MouseMoved, X: x, Y: y}) } // checkQuietBar drives one window, loaded at page, through the whole // approved behaviour. func checkQuietBar(t *testing.T, rig *harness.Rig, page, ready string, keys bool) { t.Helper() rig.Run( cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 1280, Height: 720, DeviceScaleFactor: 1}), chromedp.Navigate(page), waitFor(ready), waitFor(barHiddenJS), ) var cursor string var inTree bool rig.Run( evalInto(&cursor, `getComputedStyle(document.querySelector('[slides-surface]')).cursor`), evalInto(&inTree, `(() => { const b = document.querySelector('[slides-bar]'); const s = getComputedStyle(b); return s.display !== 'none' && s.visibility !== 'hidden' && !b.hidden && b.querySelector('a, button') !== null })()`), ) if cursor != "none" { t.Errorf("the pointer over the quiet window is %q, want none", cursor) } if !inTree { t.Errorf("the hidden bar must stay displayed (in the accessibility tree) and hold its controls") } // Moving the pointer shows it, and the pointer comes back with it. rig.Run(mouseTo(400, 200), waitFor(barShownJS)) rig.Run(evalInto(&cursor, `getComputedStyle(document.querySelector('[slides-surface]')).cursor`)) if cursor == "none" { t.Errorf("the pointer is hidden while the bar shows") } rig.Run(chromedp.Sleep(2500*time.Millisecond), waitFor(barHiddenJS)) // A key that moves the talk hides it at once. var quiet bool rig.Run( mouseTo(420, 210), waitFor(barShownJS), chromedp.KeyEvent(kb.ArrowRight), chromedp.Sleep(800*time.Millisecond), evalInto(&quiet, barHiddenJS), ) // The follow link drives nothing, so a key there moves nothing. if keys && !quiet { t.Errorf("a key that moves the talk left the bar showing") } // Over the bar it stays up past the two seconds. var y float64 rig.Run( mouseTo(400, 200), waitFor(barShownJS), evalInto(&y, `(() => { const r = document.querySelector('[slides-bar]').getBoundingClientRect(); return r.top + r.height / 2 })()`), ) var still bool rig.Run(mouseTo(640, y), chromedp.Sleep(2500*time.Millisecond), evalInto(&still, barShownJS)) if !still { t.Errorf("the bar hid while the pointer was over it") } rig.Run(mouseTo(400, 100), chromedp.Sleep(2500*time.Millisecond), waitFor(barHiddenJS)) // A pointer that rests on the bar and then leaves the window is idle // from then on: the bar goes two seconds after it leaves. rig.Run(mouseTo(400, 200), waitFor(barShownJS), mouseTo(640, y), chromedp.Sleep(2500*time.Millisecond), mouseTo(640, 719), mouseTo(640, 760)) rig.Run(chromedp.Sleep(2500*time.Millisecond), waitFor(barHiddenJS)) // Tab reaches the hidden bar, and focus shows it and holds it. var inside, held bool rig.Run( chromedp.KeyEvent(kb.Tab), waitFor(barShownJS), evalInto(&inside, `!!document.activeElement?.closest('[slides-bar]')`), chromedp.Sleep(2500*time.Millisecond), evalInto(&held, barShownJS), ) if !inside { t.Errorf("Tab did not land in the bar") } if !held { t.Errorf("the bar hid while focus was inside it") } } // checkQuietBarFollowsTheTalk: the bar goes when the talk moves (a press // from anywhere, a blackout, a number and Enter), but never while focus // is inside it; then it goes on the ordinary idle rule. func checkQuietBarFollowsTheTalk(t *testing.T, rig *harness.Rig, page, ready string, press func(op string), keys bool) { t.Helper() rig.Run( cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 1280, Height: 720, DeviceScaleFactor: 1}), chromedp.Navigate(page), waitFor(ready), waitFor(barHiddenJS), ) settle := chromedp.Sleep(800 * time.Millisecond) var shown, hidden bool expect := func(what string, wantShown bool) { t.Helper() rig.Run(settle, evalInto(&shown, barShownJS), evalInto(&hidden, barHiddenJS)) if wantShown && !shown || !wantShown && !hidden { t.Errorf("%s: bar shown=%v hidden=%v, want shown=%v", what, shown, hidden, wantShown) } } for _, op := range []string{"next", "blackout", "blackout"} { rig.Run(mouseTo(400, 200), waitFor(barShownJS)) press(op) expect("after "+op+" from elsewhere", false) } if keys { rig.Run(mouseTo(400, 200), waitFor(barShownJS), chromedp.KeyEvent("3"), chromedp.KeyEvent(kb.Enter)) expect("after a number and Enter", false) } // Focus inside the bar holds it, whatever the talk does. rig.Run(chromedp.KeyEvent(kb.Tab), waitFor(barShownJS)) for _, op := range []string{"next", "blackout", "blackout"} { press(op) expect("focus in the bar, after "+op, true) } if keys { rig.Run(chromedp.KeyEvent(kb.ArrowLeft)) expect("focus in the bar, after a key that moves the talk", true) } // Focus leaves: the idle rule applies again. rig.Run(evalInto(&shown, `(document.activeElement.blur(), true)`), chromedp.Sleep(2500*time.Millisecond), waitFor(barHiddenJS)) } func TestTheSlideWindowBarIsOutOfSightWhilePresenting(t *testing.T) { rig, app := newRigApp(t, nil) cookies := signedIn(t, app, allowedAddress) deck := stepsDeck(t, app, cookies) session, token := startPresenting(t, app, deck, cookies) t.Run("positional session", func(t *testing.T) { checkQuietBar(t, rig, rig.Origin+"/p/"+session+"?t="+url.QueryEscape(token), `document.querySelector('[slides-surface][data-talk]')`, true) }) t.Run("positional session, the talk moves", func(t *testing.T) { s2, t2 := startPresenting(t, app, deck, cookies) checkQuietBarFollowsTheTalk(t, rig, rig.Origin+"/p/"+s2+"?t="+url.QueryEscape(t2), `document.querySelector('[slides-surface][data-talk]')`, func(name string) { press(t, app, s2, t2, op(t, name), nil) }, true) }) t.Run("follow link, the talk moves", func(t *testing.T) { s3, t3 := startPresenting(t, app, deck, cookies) share := mintShareLink(t, app, deck, cookies) checkQuietBarFollowsTheTalk(t, rig, rig.Origin+"/s/"+share+"?follow=1", `document.querySelector('[slides-surface]:not([data-talk])')`, func(name string) { press(t, app, s3, t3, op(t, name), nil) }, false) }) t.Run("follow link", func(t *testing.T) { share := mintShareLink(t, app, deck, cookies) checkQuietBar(t, rig, rig.Origin+"/s/"+share+"?follow=1", `document.querySelector('[slides-surface]:not([data-talk])')`, false) }) } func TestTheSlideWindowBarStaysWithScriptsOff(t *testing.T) { rig, app := newRigApp(t, nil) cookies := signedIn(t, app, allowedAddress) deck := stepsDeck(t, app, cookies) session, token := startPresenting(t, app, deck, cookies) rig.Run( cdpStep(emulation.SetScriptExecutionDisabled, emulation.SetScriptExecutionDisabledParams{Value: true}), chromedp.Navigate(rig.Origin+"/p/"+session+"?t="+url.QueryEscape(token)), chromedp.WaitVisible(chromedp.CSS(`[slides-bar]`)), chromedp.Sleep(2500*time.Millisecond), ) var shown bool rig.Run(evalInto(&shown, barShownJS)) if !shown { t.Errorf("with scripts off the bar must stay visible") } }