| index d0a44eb..3411237 100644 |
| --- a/internal/slidestest/presenter_window_browser_test.go |
| +++ b/internal/slidestest/presenter_window_browser_test.go |
| @@ -9,6 +9,7 @@ package slidestest |
| |
| import ( |
| "fmt" |
| + "net/http" |
| "net/url" |
| "strconv" |
| "strings" |
| @@ -81,9 +82,13 @@ func TestPresenterNeverScrolls(t *testing.T) { |
| rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false)) |
| // Each step as the session reaches it: with scripts on, a |
| // page naming a state the talk is not in goes to where it is. |
| - press(t, app, session, token, url.Values{"op": {"goto"}, "slide": {"1"}, "press": {newPressID(t)}}, nil) |
| for step := range 5 { |
| - if step > 0 { |
| + // Off the window before the talk moves, so its stream's |
| + // reload cannot race this navigation. |
| + rig.Run(chromedp.Navigate("about:blank")) |
| + if step == 0 { |
| + press(t, app, session, token, url.Values{"op": {"goto"}, "slide": {"1"}, "press": {newPressID(t)}}, nil) |
| + } else { |
| press(t, app, session, token, op(t, "next"), nil) |
| } |
| var g presenterGeometry |
| @@ -122,3 +127,159 @@ func TestPresenterNeverScrolls(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// columnsDeck is two two-column slides, each with a box hidden on a |
| +// phone: what slides.css's phone layer would change if a small frame |
| +// were taken for a phone. |
| +func columnsDeck(t *testing.T, a *testApp, cookies []*http.Cookie) string { |
| + t.Helper() |
| + token := mintAgent(t, a, cookies, "columns-deck") |
| + sqid := apiDeck(t, a, token, "Columns") |
| + view := apiJSON(t, a, http.MethodGet, "/api/v1/decks/"+sqid, token, "", http.StatusOK) |
| + var ops []string |
| + for _, s := range view["slides"].([]any) { |
| + ops = append(ops, `{"op":"remove_slide","id":`+quote(s.(map[string]any)["id"].(string))+`}`) |
| + } |
| + for _, id := range []string{"colsone", "colstwo"} { |
| + ops = append(ops, |
| + `{"op":"add_slide","id":"`+id+`","layout":"flow","template":"two-column"}`, |
| + `{"op":"add_block","slide":"`+id+`","id":"`+id+`h","type":"heading","region":"heading","props":{"level":1},"markdown":"Two columns"}`, |
| + `{"op":"add_block","slide":"`+id+`","id":"`+id+`l","type":"text","region":"body","markdown":"The left column, long enough to wrap onto a second line at the projector's size."}`, |
| + `{"op":"add_block","slide":"`+id+`","id":"`+id+`r","type":"text","region":"aside","markdown":"The right column."}`, |
| + `{"op":"add_block","slide":"`+id+`","id":"`+id+`x","type":"text","region":"aside","markdown":"Hidden on a phone."}`, |
| + `{"op":"set_phone","slide":"`+id+`","id":"`+id+`x","phone":{"hidden":true}}`) |
| + } |
| + apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqid+"/ops", token, `{"ops":[`+strings.Join(ops, ",")+`]}`, http.StatusOK) |
| + return "/d/" + sqid |
| +} |
| + |
| +// blockLayoutJS is each box of the first slide under root, as fractions |
| +// of the slide: where it is, how big, and whether it is drawn at all. |
| +const blockLayoutJS = `((root) => { |
| + const s = document.querySelector(root + ' [slides-slide]'); |
| + const r = s.getBoundingClientRect(); |
| + return [...s.querySelectorAll('[slides-block]')].map(b => { |
| + const q = b.getBoundingClientRect(); |
| + return { id: b.getAttribute('data-id'), shown: getComputedStyle(b).display !== 'none', |
| + x: (q.left - r.left) / r.width, y: (q.top - r.top) / r.height, |
| + w: q.width / r.width, h: q.height / r.height }; |
| + }).concat([{ id: 'clipped', shown: s.scrollHeight > s.clientHeight + 1 }]); |
| +})` |
| + |
| +type blockBox struct { |
| + ID string |
| + Shown bool |
| + X, Y, W, H float64 |
| +} |
| + |
| +func sameBoxes(want, got []blockBox) string { |
| + if len(want) != len(got) { |
| + return fmt.Sprintf("%d boxes, want %d", len(got), len(want)) |
| + } |
| + for i := range want { |
| + w, g := want[i], got[i] |
| + off := func(a, b float64) bool { return a-b > 0.005 || b-a > 0.005 } |
| + if w.ID != g.ID || w.Shown != g.Shown || off(w.X, g.X) || off(w.Y, g.Y) || off(w.W, g.W) || off(w.H, g.H) { |
| + return fmt.Sprintf("%s: %+v, the projector has %+v", w.ID, g, w) |
| + } |
| + } |
| + return "" |
| +} |
| + |
| +// TestPresenterDrawsWhatTheProjectorShows: Now and Next are the |
| +// projector's own layout scaled down, at any window size: two columns |
| +// stay side by side, a box hidden on a phone is still there, and |
| +// nothing is cut off. A small frame is not a phone. |
| +func TestPresenterDrawsWhatTheProjectorShows(t *testing.T) { |
| + rig, app := newRigApp(t, nil) |
| + cookies := signedIn(t, app, allowedAddress) |
| + session, token := startPresenting(t, app, columnsDeck(t, app, cookies), cookies) |
| + |
| + // The projector at 1920×1080, on the session's own slide: a page |
| + // named for another slide is put back on the session's by its stream. |
| + projector := func(n string) []blockBox { |
| + var out []blockBox |
| + rig.Run(chromedp.Navigate("about:blank")) |
| + press(t, app, session, token, url.Values{"op": {"goto"}, "slide": {n}, "press": {newPressID(t)}}, nil) |
| + rig.Run(emulation.SetDeviceMetricsOverride(1920, 1080, 1, false), |
| + chromedp.Navigate(rig.Origin+"/p/"+session), |
| + waitFor(`document.querySelector('[slides-surface]')?.getAttribute('data-slide') === '`+n+`' && document.querySelector('[slides-stage] [slides-slide]')`), |
| + chromedp.Evaluate(blockLayoutJS+`('[slides-stage]')`, &out)) |
| + return out |
| + } |
| + two, one := projector("2"), projector("1") |
| + if len(one) < 4 || !one[3].Shown || one[2].X < 0.4 || one[1].X > 0.1 { |
| + t.Fatalf("the projector itself does not draw two columns with the phone-hidden box: %+v", one) |
| + } |
| + |
| + window := rig.Origin + "/p/" + session + "/notes?t=" + url.QueryEscape(token) |
| + for _, size := range presenterSizes { |
| + var now, next []blockBox |
| + rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false), |
| + chromedp.Navigate(window), |
| + waitFor(`document.querySelector('[presenter-panel="next"] [slides-slide]')`), |
| + chromedp.Evaluate(blockLayoutJS+`('[presenter-panel="now"]')`, &now), |
| + chromedp.Evaluate(blockLayoutJS+`('[presenter-panel="next"]')`, &next)) |
| + if diff := sameBoxes(one, now); diff != "" { |
| + t.Errorf("%dx%d: Now is not the projector's slide 1: %s", size.w, size.h, diff) |
| + } |
| + if diff := sameBoxes(two, next); diff != "" { |
| + t.Errorf("%dx%d: Next is not the projector's slide 2: %s", size.w, size.h, diff) |
| + } |
| + } |
| +} |
| + |
| +// TestPresenterNextIsHalfOfNow: in the default window Next is drawn at |
| +// half the width of Now, tall windows and short, stacked or arranged. |
| +func TestPresenterNextIsHalfOfNow(t *testing.T) { |
| + rig, app := newRigApp(t, nil) |
| + cookies := signedIn(t, app, allowedAddress) |
| + session, token := startPresenting(t, app, stepsDeck(t, app, cookies), cookies) |
| + window := rig.Origin + "/p/" + session + "/notes?t=" + url.QueryEscape(token) |
| + for _, size := range presenterSizes { |
| + var w struct{ Now, Next float64 } |
| + rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false), |
| + chromedp.Navigate(window), |
| + waitFor(`document.querySelector('[presenter-panel="next"] [presenter-frame]')`), |
| + chromedp.Evaluate(`({ Now: document.querySelector('[presenter-panel="now"] [presenter-frame]').getBoundingClientRect().width, |
| + Next: document.querySelector('[presenter-panel="next"] [presenter-frame]').getBoundingClientRect().width })`, &w)) |
| + if d := w.Next - w.Now/2; d > 1 || d < -1 { |
| + t.Errorf("%dx%d: Now is %.1fpx wide and Next %.1fpx, want half", size.w, size.h, w.Now, w.Next) |
| + } |
| + } |
| +} |
| + |
| +// TestPresenterMenuFitsTheWindow: the ⋯ menu, open, lies inside the |
| +// window at every size, and every row of it can be reached. |
| +func TestPresenterMenuFitsTheWindow(t *testing.T) { |
| + rig, app := newRigApp(t, nil) |
| + cookies := signedIn(t, app, allowedAddress) |
| + session, token := startPresenting(t, app, stepsDeck(t, app, cookies), cookies) |
| + window := rig.Origin + "/p/" + session + "/notes?t=" + url.QueryEscape(token) |
| + for _, size := range presenterSizes { |
| + var m struct { |
| + Top, Bottom, Left, Right, VW, VH float64 |
| + Rows int |
| + Reach bool |
| + SH float64 |
| + } |
| + rig.Run(emulation.SetDeviceMetricsOverride(size.w, size.h, 1, false), |
| + chromedp.Navigate(window), |
| + waitFor(`document.querySelector('[presenter-more]')`), |
| + chromedp.Click(`[presenter-more]`, chromedp.ByQuery), |
| + waitFor(`document.querySelector('[presenter-more-menu]').open`), |
| + chromedp.Evaluate(`(() => { const menu = document.querySelector('[presenter-menu]'); const r = menu.getBoundingClientRect(); |
| + const rows = menu.querySelectorAll('button, a'); |
| + const style = getComputedStyle(menu); |
| + return { Top: r.top, Bottom: r.bottom, Left: r.left, Right: r.right, VW: innerWidth, VH: innerHeight, |
| + Rows: rows.length, SH: document.documentElement.scrollHeight, |
| + Reach: menu.scrollHeight <= menu.clientHeight + 1 || style.overflowY === 'auto' }; })()`, &m)) |
| + if m.Rows != 6 { |
| + t.Errorf("%dx%d: the menu has %d rows, want 6", size.w, size.h, m.Rows) |
| + } |
| + if m.Top < 0 || m.Left < 0 || m.Bottom > m.VH || m.Right > m.VW || !m.Reach || m.SH != m.VH { |
| + t.Errorf("%dx%d: the open menu at (%.0f,%.0f)-(%.0f,%.0f) leaves the %.0f×%.0f window, or cannot reach its rows (document %.0f tall)", |
| + size.w, size.h, m.Left, m.Top, m.Right, m.Bottom, m.VW, m.VH, m.SH) |
| + } |
| + } |
| +} |