| 1 | //go:build browser |
| 2 | |
| 3 | // Arranging the presenter window, its ⋯ menu, and pairing a phone from |
| 4 | // it (Task 13, spec §5.4, §5.6 and §6 "Who may drive"). The panels move |
| 5 | // and resize on the 12×12 grid by pointer and by keyboard, never leave |
| 6 | // the window, never overlap, and are remembered in the cookie the |
| 7 | // server draws the first paint from. |
| 8 | package slidestest |
| 9 | |
| 10 | import ( |
| 11 | "context" |
| 12 | "fmt" |
| 13 | "math" |
| 14 | "net/http" |
| 15 | "net/url" |
| 16 | "strings" |
| 17 | "testing" |
| 18 | "time" |
| 19 | |
| 20 | "amadan.net/rastrillo/rastrillo/harness" |
| 21 | "github.com/chromedp/cdproto/accessibility" |
| 22 | "github.com/chromedp/cdproto/cdp" |
| 23 | "github.com/chromedp/cdproto/emulation" |
| 24 | "github.com/chromedp/cdproto/input" |
| 25 | "github.com/chromedp/cdproto/network" |
| 26 | "github.com/chromedp/cdproto/target" |
| 27 | "github.com/chromedp/chromedp" |
| 28 | "github.com/chromedp/chromedp/kb" |
| 29 | ) |
| 30 | |
| 31 | // arrangeRig is a talk on stepsDeck, with the browser signed in as its |
| 32 | // presenter: the window is theirs by the cookie, no token in it. |
| 33 | type arrangeRig struct { |
| 34 | rig *harness.Rig |
| 35 | app *testApp |
| 36 | cookies []*http.Cookie |
| 37 | session, token string |
| 38 | window string |
| 39 | } |
| 40 | |
| 41 | func newArrangeRig(t *testing.T) *arrangeRig { |
| 42 | t.Helper() |
| 43 | rig, app := newRigApp(t, nil) |
| 44 | cookies := signedIn(t, app, allowedAddress) |
| 45 | var set []chromedp.Action[chromedp.Void] |
| 46 | for _, c := range cookies { |
| 47 | set = append(set, cdpStep(network.SetCookie, network.SetCookieParams{Name: c.Name, Value: c.Value, URL: rig.Origin + "/", |
| 48 | HTTPOnly: new(c.HttpOnly), Secure: new(c.Secure), SameSite: network.CookieSameSiteLax})) |
| 49 | } |
| 50 | set = append(set, cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 1280, Height: 720, DeviceScaleFactor: 1, Mobile: false})) |
| 51 | rig.Run(set...) |
| 52 | session, token := startPresenting(t, app, stepsDeck(t, app, cookies), cookies) |
| 53 | return &arrangeRig{rig: rig, app: app, cookies: cookies, session: session, token: token, |
| 54 | window: rig.Origin + "/p/" + session + "/notes"} |
| 55 | } |
| 56 | |
| 57 | // prefs sets the window's cookie as its script writes it. |
| 58 | func (ar *arrangeRig) prefs(value string) { |
| 59 | ar.rig.Run(cdpStep(network.SetCookie, network.SetCookieParams{Name: "slides-presenter", Value: url.QueryEscape(value), |
| 60 | URL: ar.rig.Origin + "/p/", Path: "/p", SameSite: network.CookieSameSiteLax})) |
| 61 | } |
| 62 | |
| 63 | // open loads the window and waits for its script to have the talk. |
| 64 | func (ar *arrangeRig) open(t *testing.T) { |
| 65 | t.Helper() |
| 66 | ar.rig.Run(chromedp.Navigate(ar.window), |
| 67 | waitFor(`document.querySelector('[presenter]')?.getAttribute('data-loaded') === 'all'`)) |
| 68 | } |
| 69 | |
| 70 | // arrange opens the ⋯ menu and chooses Arrange this window. |
| 71 | func (ar *arrangeRig) arrange(t *testing.T) { |
| 72 | t.Helper() |
| 73 | ar.rig.Run( |
| 74 | chromedp.Click(chromedp.CSS(`[presenter-more]`)), |
| 75 | waitFor(`document.querySelector('[presenter-more-menu]').open`), |
| 76 | chromedp.Click(chromedp.CSS(`[presenter-arrange]`)), |
| 77 | waitFor(`document.querySelector('[presenter]').hasAttribute('data-arranging') && !document.querySelector('[presenter-arrange-bar]').hidden`)) |
| 78 | } |
| 79 | |
| 80 | // keys presses key n times, with Shift when shift is true. |
| 81 | func keys(key string, n int, shift bool) chromedp.Action[chromedp.Void] { |
| 82 | return chromedp.Func(func(ctx context.Context, t *chromedp.Target) error { |
| 83 | for range n { |
| 84 | var opts []chromedp.KeyOption |
| 85 | if shift { |
| 86 | opts = append(opts, chromedp.KeyModifiers(chromedp.ModifierShift)) |
| 87 | } |
| 88 | if _, err := chromedp.KeyEvent(key, opts...)(ctx, t); err != nil { |
| 89 | return err |
| 90 | } |
| 91 | } |
| 92 | return nil |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | // focus puts the keyboard on a panel. |
| 97 | func focusPanel(name string) chromedp.Action[chromedp.Void] { |
| 98 | return chromedp.Evaluate[chromedp.Void](`document.querySelector('[presenter-panel="` + name + `"]').focus()`) |
| 99 | } |
| 100 | |
| 101 | // cookieValue is the window's cookie, decoded, or "". |
| 102 | const cookieValueJS = `(() => { const m = document.cookie.split('; ').find(c => c.startsWith('slides-presenter=')); |
| 103 | return m ? decodeURIComponent(m.slice('slides-presenter='.length)) : '' })()` |
| 104 | |
| 105 | type panelRect struct{ L, T, R, B float64 } |
| 106 | |
| 107 | func (r panelRect) String() string { return fmt.Sprintf("(%.1f,%.1f)-(%.1f,%.1f)", r.L, r.T, r.R, r.B) } |
| 108 | |
| 109 | func near(a, b panelRect) bool { |
| 110 | return math.Abs(a.L-b.L) <= 0.5 && math.Abs(a.T-b.T) <= 0.5 && math.Abs(a.R-b.R) <= 0.5 && math.Abs(a.B-b.B) <= 0.5 |
| 111 | } |
| 112 | |
| 113 | // panelRects is each panel and each frame, by name. |
| 114 | const panelRectsJS = `(() => { const out = {}; |
| 115 | for (const n of ['now', 'next', 'notes']) { |
| 116 | const r = document.querySelector('[presenter-panel="' + n + '"]').getBoundingClientRect(); |
| 117 | out[n] = { L: r.left, T: r.top, R: r.right, B: r.bottom }; |
| 118 | const f = document.querySelector('[presenter-panel="' + n + '"] [presenter-frame]'); |
| 119 | if (f) { const q = f.getBoundingClientRect(); out[n + '-frame'] = { L: q.left, T: q.top, R: q.right, B: q.bottom } } |
| 120 | const fit = document.querySelector('[presenter-panel="' + n + '"] [presenter-fit]'); |
| 121 | if (fit) { const q = fit.getBoundingClientRect(); out[n + '-fit'] = { L: q.left, T: q.top, R: q.right, B: q.bottom } } |
| 122 | } |
| 123 | return out })()` |
| 124 | |
| 125 | func (ar *arrangeRig) rects(t *testing.T) map[string]panelRect { |
| 126 | t.Helper() |
| 127 | var out map[string]panelRect |
| 128 | ar.rig.Run(evalInto(&out, panelRectsJS)) |
| 129 | return out |
| 130 | } |
| 131 | |
| 132 | // inside fails for a document that scrolls or a box outside the window, |
| 133 | // or one with no size. arranging is the one exception, and only while |
| 134 | // arranging: a slide's frame may shrink to nothing in a 2×2 panel while |
| 135 | // the arranging bar takes its height. Done, a reload, any window not |
| 136 | // being arranged: every preview has a size. |
| 137 | func inside(t *testing.T, ar *arrangeRig, what string, arranging bool) { |
| 138 | t.Helper() |
| 139 | var g presenterGeometry |
| 140 | ar.rig.Run(evalInto(&g, presenterGeometryJS)) |
| 141 | // The arranging bar and the selected panel's buttons, while shown. |
| 142 | var extra []presenterBox |
| 143 | ar.rig.Run(evalInto(&extra, `[['bar', '[presenter-arrange-bar]'], ['tools', '[presenter-arrange-tools]'], |
| 144 | ...[...document.querySelectorAll('[presenter-arrange-tools] button')].map((b, i) => ['tool ' + i, b])].flatMap(([name, sel]) => { |
| 145 | const b = typeof sel === 'string' ? document.querySelector(sel) : sel; |
| 146 | if (!b || b.closest('[hidden]')) return []; |
| 147 | const r = b.getBoundingClientRect(); return [{ name, l: r.left, t: r.top, r: r.right, b: r.bottom }] })`)) |
| 148 | g.Boxes = append(g.Boxes, extra...) |
| 149 | if g.SH != g.VH || g.SW != g.VW || g.BSH > g.VH || g.BSW > g.VW || g.ScrollY != 0 { |
| 150 | t.Errorf("%s: the document is %.0f×%.0f (body %.0f×%.0f, scrolled %.0f) in a %.0f×%.0f window", |
| 151 | what, g.SW, g.SH, g.BSW, g.BSH, g.ScrollY, g.VW, g.VH) |
| 152 | } |
| 153 | if len(g.Boxes) < 6 { |
| 154 | t.Fatalf("%s: %d boxes measured, want the header, three panels and two frames", what, len(g.Boxes)) |
| 155 | } |
| 156 | for _, b := range g.Boxes { |
| 157 | empty := b.R <= b.L || b.B <= b.T |
| 158 | if arranging && b.Name == "frame" { |
| 159 | empty = b.R < b.L || b.B < b.T |
| 160 | } |
| 161 | if b.L < 0 || b.T < 0 || b.R > g.VW || b.B > g.VH || empty { |
| 162 | t.Errorf("%s: %s at (%.0f,%.0f)-(%.0f,%.0f) is not inside the %.0f×%.0f window", |
| 163 | what, b.Name, b.L, b.T, b.R, b.B, g.VW, g.VH) |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | // overlapping is two panels sharing any area, beyond a rounding. |
| 169 | func overlapping(a, b panelRect) bool { |
| 170 | return a.L < b.R-1 && b.L < a.R-1 && a.T < b.B-1 && b.T < a.B-1 |
| 171 | } |
| 172 | |
| 173 | // TestArrangedPanelsStayInsideTheWindow: however the panels are |
| 174 | // arranged, at each of the ten window sizes nothing leaves the window |
| 175 | // and the document never scrolls; the panels never overlap; Next fills |
| 176 | // its own panel. Below 720×560 the arrangement is ignored and the |
| 177 | // panels stack, and Arrange is not offered there. While arranging, |
| 178 | // with the bar showing, the window still holds. |
| 179 | func TestArrangedPanelsStayInsideTheWindow(t *testing.T) { |
| 180 | ar := newArrangeRig(t) |
| 181 | arrangements := []string{ |
| 182 | "fit.24.0,0,4,4;0,4,4,4;8,0,4,12", |
| 183 | "fit.24.10,10,2,2;0,0,2,2;5,5,2,2", |
| 184 | "scroll.48.0,0,12,6;0,6,6,6;6,6,6,6", |
| 185 | } |
| 186 | for _, size := range presenterSizes { |
| 187 | stacked := size.w < 720 || size.h < 560 |
| 188 | t.Run(fmt.Sprintf("%dx%d", size.w, size.h), func(t *testing.T) { |
| 189 | ar.rig.Run(cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: size.w, Height: size.h, DeviceScaleFactor: 1, Mobile: false})) |
| 190 | for _, prefs := range arrangements { |
| 191 | ar.prefs(prefs) |
| 192 | ar.open(t) |
| 193 | inside(t, ar, prefs, false) |
| 194 | r := ar.rects(t) |
| 195 | if stacked { |
| 196 | if !(r["now"].B <= r["next"].T+1 && r["next"].B <= r["notes"].T+1) { |
| 197 | t.Errorf("%s: stacked panels are not now, next, notes: %v %v %v", prefs, r["now"], r["next"], r["notes"]) |
| 198 | } |
| 199 | continue |
| 200 | } |
| 201 | for _, pair := range [][2]string{{"now", "next"}, {"now", "notes"}, {"next", "notes"}} { |
| 202 | if overlapping(r[pair[0]], r[pair[1]]) { |
| 203 | t.Errorf("%s: %s %v and %s %v overlap", prefs, pair[0], r[pair[0]], pair[1], r[pair[1]]) |
| 204 | } |
| 205 | } |
| 206 | fit, frame := r["next-fit"], r["next-frame"] |
| 207 | want := math.Min(fit.R-fit.L, (fit.B-fit.T)*16/9) |
| 208 | if got := frame.R - frame.L; math.Abs(got-want) > 1 { |
| 209 | t.Errorf("%s: Next is %.1fpx wide in a panel with room for %.1fpx: an arranged Next fills its panel", prefs, got, want) |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | // Arranging, with the bar over the panels. |
| 214 | ar.prefs(arrangements[0]) |
| 215 | ar.open(t) |
| 216 | var shown bool |
| 217 | ar.rig.Run(evalInto(&shown, `getComputedStyle(document.querySelector('[presenter-arrange]')).display !== 'none'`)) |
| 218 | if stacked { |
| 219 | if shown { |
| 220 | t.Errorf("Arrange is offered where the panels stack and the arrangement is ignored") |
| 221 | } |
| 222 | return |
| 223 | } |
| 224 | if !shown { |
| 225 | t.Fatalf("Arrange is not offered at %dx%d", size.w, size.h) |
| 226 | } |
| 227 | ar.rig.Run(keys(kb.Escape, 1, false)) |
| 228 | for _, prefs := range arrangements { |
| 229 | ar.prefs(prefs) |
| 230 | ar.open(t) |
| 231 | ar.arrange(t) |
| 232 | ar.toolsReachable(t, prefs) |
| 233 | ar.rig.Run(keys(kb.Escape, 1, false), |
| 234 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 235 | } |
| 236 | }) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // unreachableToolsJS is each of the selected panel's buttons that a |
| 241 | // pointer cannot reach at its centre: off the window, or under |
| 242 | // something else. |
| 243 | const unreachableToolsJS = `[...document.querySelectorAll('[presenter-arrange-tools] button')].filter(b => { |
| 244 | const r = b.getBoundingClientRect(); |
| 245 | const e = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); |
| 246 | return !(e && b.contains(e)) }).map(b => b.getAttribute('aria-label'))` |
| 247 | |
| 248 | // toolsReachable selects each panel in turn and insists its eight |
| 249 | // buttons are all inside the window and each can be pressed. |
| 250 | func (ar *arrangeRig) toolsReachable(t *testing.T, what string) { |
| 251 | t.Helper() |
| 252 | for _, name := range []string{"now", "next", "notes"} { |
| 253 | var tools int |
| 254 | var lost []string |
| 255 | ar.rig.Run(focusPanel(name), |
| 256 | waitFor(`document.querySelector('[presenter-panel="`+name+`"]').hasAttribute('data-selected')`), |
| 257 | evalInto(&tools, `document.querySelectorAll('[presenter-arrange-tools]:not([hidden]) button').length`), |
| 258 | evalInto(&lost, unreachableToolsJS)) |
| 259 | if tools != 8 { |
| 260 | t.Errorf("%s, %s selected: %d buttons shown, want 8", what, name, tools) |
| 261 | } |
| 262 | if len(lost) > 0 { |
| 263 | t.Errorf("%s, %s selected: %v cannot be reached", what, name, lost) |
| 264 | } |
| 265 | inside(t, ar, what+", arranging "+name, true) |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // TestArrangeToolsStayInsideTheWindow: a 2×2 panel in each corner of |
| 270 | // the grid, selected, keeps all eight of its buttons inside the window |
| 271 | // and within reach, from the smallest window that arranges (720×560) |
| 272 | // up, the panel's buttons turning towards the middle as they must. |
| 273 | func TestArrangeToolsStayInsideTheWindow(t *testing.T) { |
| 274 | ar := newArrangeRig(t) |
| 275 | sizes := []struct{ w, h int64 }{{720, 560}, {1280, 720}} |
| 276 | for _, s := range presenterSizes { |
| 277 | if s.w >= 720 && s.h >= 560 { |
| 278 | sizes = append(sizes, s) |
| 279 | } |
| 280 | } |
| 281 | corners := []string{ |
| 282 | "fit.24.0,0,2,2;10,0,2,2;0,10,2,2", |
| 283 | "fit.24.10,10,2,2;4,4,2,2;6,6,2,2", |
| 284 | } |
| 285 | for _, size := range sizes { |
| 286 | t.Run(fmt.Sprintf("%dx%d", size.w, size.h), func(t *testing.T) { |
| 287 | ar.rig.Run(cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: size.w, Height: size.h, DeviceScaleFactor: 1, Mobile: false})) |
| 288 | for _, prefs := range corners { |
| 289 | ar.prefs(prefs) |
| 290 | ar.open(t) |
| 291 | ar.arrange(t) |
| 292 | ar.toolsReachable(t, prefs) |
| 293 | ar.rig.Run(keys(kb.Escape, 1, false), |
| 294 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 295 | } |
| 296 | }) |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | // TestArrangeButtonsKeepTheirMeaningRightToLeft: in a right-to-left |
| 301 | // window the grid runs the other way, so Move left and Move right are |
| 302 | // mirrored to go where they say; Narrower and Wider still narrow and |
| 303 | // widen. |
| 304 | func TestArrangeButtonsKeepTheirMeaningRightToLeft(t *testing.T) { |
| 305 | ar := newArrangeRig(t) |
| 306 | ar.open(t) |
| 307 | ar.rig.Run(chromedp.Evaluate[chromedp.Void](`document.documentElement.dir = 'rtl'`)) |
| 308 | ar.arrange(t) |
| 309 | disabled := func(label string) bool { |
| 310 | var d string |
| 311 | ar.rig.Run(evalInto(&d, `document.querySelector('[presenter-arrange-tools] button[aria-label="`+label+`"]').getAttribute('aria-disabled') || ''`)) |
| 312 | return d == "true" |
| 313 | } |
| 314 | if disabled("Narrower") || !disabled("Wider") { |
| 315 | t.Errorf("right to left, Now in the default window: Narrower disabled %v, Wider disabled %v; want Narrower only", disabled("Narrower"), disabled("Wider")) |
| 316 | } |
| 317 | ar.rig.Run(arrangeTool("Narrower")) |
| 318 | if got, want := ar.arrangeStatus(t), "On screen now: 6 by 8, column 1, row 1"; got != want { |
| 319 | t.Errorf("Narrower right to left says %q, want %q", got, want) |
| 320 | } |
| 321 | // Column 1 is on the right: Move right cannot go, Move left can, |
| 322 | // and goes to column 2. |
| 323 | if !disabled("Move right") || disabled("Move left") { |
| 324 | t.Errorf("right to left, Now at column 1: Move right disabled %v, Move left disabled %v", disabled("Move right"), disabled("Move left")) |
| 325 | } |
| 326 | var before, after panelRect |
| 327 | ar.rig.Run(evalInto(&before, `(() => { const r = document.querySelector('[presenter-panel="now"]').getBoundingClientRect(); return { L: r.left, T: r.top, R: r.right, B: r.bottom } })()`)) |
| 328 | ar.rig.Run(arrangeTool("Move left")) |
| 329 | ar.rig.Run(evalInto(&after, `(() => { const r = document.querySelector('[presenter-panel="now"]').getBoundingClientRect(); return { L: r.left, T: r.top, R: r.right, B: r.bottom } })()`)) |
| 330 | if got, want := ar.arrangeStatus(t), "On screen now: 6 by 8, column 2, row 1"; got != want { |
| 331 | t.Errorf("Move left right to left says %q, want %q", got, want) |
| 332 | } |
| 333 | if after.L >= before.L { |
| 334 | t.Errorf("Move left moved Now from %v to %v, not to the left", before, after) |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | // TestArrangeByKeyboardAndPointer: a focused panel moves a cell with an |
| 339 | // arrow key and resizes with Shift and an arrow, so arranging is not |
| 340 | // mouse-only; dragging a panel moves it and dragging its corner resizes |
| 341 | // it, snapped to the grid. Done writes the cookie, keeping the notes' |
| 342 | // part. While arranging, only the clicker's keys move the talk. |
| 343 | func TestArrangeByKeyboardAndPointer(t *testing.T) { |
| 344 | ar := newArrangeRig(t) |
| 345 | ar.prefs("scroll.30.0,0,7,8;0,8,7,4;7,0,5,12") |
| 346 | ar.open(t) |
| 347 | ar.arrange(t) |
| 348 | |
| 349 | var focused string |
| 350 | ar.rig.Run(evalInto(&focused, `document.activeElement.getAttribute('presenter-panel') || ''`)) |
| 351 | if focused != "now" { |
| 352 | t.Errorf("arranging puts the focus on %q, want the first panel, now", focused) |
| 353 | } |
| 354 | // Now 7×8 to 5×5; Next up three cells into the room that leaves. |
| 355 | ar.rig.Run(focusPanel("now"), keys(kb.ArrowLeft, 2, true), keys(kb.ArrowUp, 3, true), |
| 356 | focusPanel("next"), keys(kb.ArrowUp, 3, false)) |
| 357 | |
| 358 | // While arranging, B blacks nothing and the arrows move no slide; |
| 359 | // the clicker's PageDown still presses. |
| 360 | _, step, _ := rowPosition(t, ar.app, ar.session) |
| 361 | ar.rig.Run(keys("b", 1, false), keys(kb.ArrowRight, 1, false), keys(kb.ArrowLeft, 1, false)) |
| 362 | time.Sleep(300 * time.Millisecond) |
| 363 | if _, now, _ := rowPosition(t, ar.app, ar.session); now != step { |
| 364 | t.Errorf("a key while arranging moved the talk from step %d to %d", step, now) |
| 365 | } |
| 366 | var black string |
| 367 | ar.rig.Run(evalInto(&black, `document.querySelector('[presenter]').getAttribute('data-blackout')`)) |
| 368 | if black != "false" { |
| 369 | t.Errorf("B while arranging blacked the screen") |
| 370 | } |
| 371 | ar.rig.Run(keys(kb.PageDown, 1, false), waitFor(`document.querySelector('[presenter]').getAttribute('data-step') === '`+fmt.Sprint(step+1)+`'`)) |
| 372 | |
| 373 | // The pointer: the notes' corner dragged two cells left narrows |
| 374 | // them, and Now dragged a little over a cell right snaps to one. |
| 375 | var cell struct{ W, H float64 } |
| 376 | ar.rig.Run(evalInto(&cell, `(() => { const r = document.querySelector('[presenter-panels]').getBoundingClientRect(); return { W: r.width / 12, H: r.height / 12 } })()`)) |
| 377 | drag := func(sel string, dx, dy float64) chromedp.Action[chromedp.Void] { |
| 378 | return chromedp.Func(func(ctx context.Context, t *chromedp.Target) error { |
| 379 | var at struct{ X, Y float64 } |
| 380 | if _, err := evalInto(&at, `(() => { const r = document.querySelector('`+sel+`').getBoundingClientRect(); return { X: r.left + r.width / 2, Y: r.top + r.height / 2 } })()`)(ctx, t); err != nil { |
| 381 | return err |
| 382 | } |
| 383 | if _, err := cdp.Call(ctx, t, input.DispatchMouseEvent, input.DispatchMouseEventParams{Type: chromedp.MousePressed, X: at.X, Y: at.Y, Button: input.MouseButtonLeft, Buttons: 1, ClickCount: 1}); err != nil { |
| 384 | return err |
| 385 | } |
| 386 | for i := 1; i <= 8; i++ { |
| 387 | f := float64(i) / 8 |
| 388 | if _, err := cdp.Call(ctx, t, input.DispatchMouseEvent, input.DispatchMouseEventParams{Type: chromedp.MouseMoved, X: at.X + dx*f, Y: at.Y + dy*f, Button: input.MouseButtonLeft, Buttons: 1}); err != nil { |
| 389 | return err |
| 390 | } |
| 391 | } |
| 392 | _, err := cdp.Call(ctx, t, input.DispatchMouseEvent, input.DispatchMouseEventParams{Type: chromedp.MouseReleased, X: at.X + dx, Y: at.Y + dy, Button: input.MouseButtonLeft, Buttons: 0, ClickCount: 1}) |
| 393 | return err |
| 394 | }) |
| 395 | } |
| 396 | ar.rig.Run(drag(`[presenter-panel="notes"] [presenter-arrange-handle]`, -2*cell.W, 0)) |
| 397 | ar.rig.Run(drag(`[presenter-panel="now"]`, 1.2*cell.W, 0)) |
| 398 | |
| 399 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-arrange-done]`)), |
| 400 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 401 | var saved string |
| 402 | ar.rig.Run(evalInto(&saved, cookieValueJS)) |
| 403 | if want := "scroll.30.1,0,5,5;0,5,7,4;7,0,3,12"; saved != want { |
| 404 | t.Errorf("Done saved %q, want %q", saved, want) |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | // TestArrangeEscapeLeavesWithoutSaving: Esc puts the panels back where |
| 409 | // arranging found them and writes nothing. |
| 410 | func TestArrangeEscapeLeavesWithoutSaving(t *testing.T) { |
| 411 | ar := newArrangeRig(t) |
| 412 | ar.open(t) |
| 413 | before := ar.rects(t) |
| 414 | ar.arrange(t) |
| 415 | ar.rig.Run(focusPanel("now"), keys(kb.ArrowLeft, 3, true)) |
| 416 | if near(ar.rects(t)["now"], before["now"]) { |
| 417 | t.Fatalf("Shift+ArrowLeft did not narrow Now") |
| 418 | } |
| 419 | ar.rig.Run(keys(kb.Escape, 1, false), waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 420 | after := ar.rects(t) |
| 421 | for _, n := range []string{"now", "next", "notes"} { |
| 422 | if !near(before[n], after[n]) { |
| 423 | t.Errorf("after Esc %s is at %v, was %v", n, after[n], before[n]) |
| 424 | } |
| 425 | } |
| 426 | var saved string |
| 427 | ar.rig.Run(evalInto(&saved, cookieValueJS)) |
| 428 | if saved != "" { |
| 429 | t.Errorf("Esc wrote the cookie: %q", saved) |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | // TestArrangeResetReturnsTheDefault: Reset puts the panels where a |
| 434 | // window with no cookie has them, Next half of Now again, and writes it, |
| 435 | // keeping the notes' choice. |
| 436 | func TestArrangeResetReturnsTheDefault(t *testing.T) { |
| 437 | ar := newArrangeRig(t) |
| 438 | ar.open(t) |
| 439 | def := ar.rects(t) |
| 440 | |
| 441 | ar.prefs("scroll.30.0,0,4,4;0,4,4,4;8,0,4,12") |
| 442 | ar.open(t) |
| 443 | if near(ar.rects(t)["now"], def["now"]) { |
| 444 | t.Fatalf("the arranged window looks like the default") |
| 445 | } |
| 446 | ar.arrange(t) |
| 447 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-arrange-reset]`))) |
| 448 | var saved string |
| 449 | ar.rig.Run(evalInto(&saved, cookieValueJS)) |
| 450 | if want := "scroll.30.0,0,7,8;0,8,7,4;7,0,5,12"; saved != want { |
| 451 | t.Errorf("Reset saved %q, want %q", saved, want) |
| 452 | } |
| 453 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-arrange-done]`)), |
| 454 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 455 | check := func(when string) { |
| 456 | got := ar.rects(t) |
| 457 | for _, n := range []string{"now", "next", "notes", "now-frame", "next-frame"} { |
| 458 | if !near(got[n], def[n]) { |
| 459 | t.Errorf("%s: %s is at %v, the default window has it at %v", when, n, got[n], def[n]) |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | check("after Reset") |
| 464 | ar.open(t) |
| 465 | check("reloaded after Reset") |
| 466 | } |
| 467 | |
| 468 | // TestArrangementIsFinalAtFirstPaint: the window the server draws from |
| 469 | // the cookie, before any script, is the window the arranging left on |
| 470 | // screen, frames and all. |
| 471 | func TestArrangementIsFinalAtFirstPaint(t *testing.T) { |
| 472 | ar := newArrangeRig(t) |
| 473 | ar.open(t) |
| 474 | ar.arrange(t) |
| 475 | ar.rig.Run(focusPanel("now"), keys(kb.ArrowLeft, 2, true), keys(kb.ArrowUp, 3, true), |
| 476 | focusPanel("next"), keys(kb.ArrowUp, 3, false), keys(kb.ArrowDown, 1, true), |
| 477 | chromedp.Click(chromedp.CSS(`[presenter-arrange-done]`)), |
| 478 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 479 | live := ar.rects(t) |
| 480 | |
| 481 | ar.rig.Run(cdpStep(emulation.SetScriptExecutionDisabled, emulation.SetScriptExecutionDisabledParams{Value: true}), chromedp.Navigate(ar.window), |
| 482 | chromedp.WaitReady(chromedp.CSS(`[presenter-panel="notes"]`))) |
| 483 | painted := ar.rects(t) |
| 484 | ar.rig.Run(cdpStep(emulation.SetScriptExecutionDisabled, emulation.SetScriptExecutionDisabledParams{Value: false})) |
| 485 | for _, n := range []string{"now", "next", "notes", "now-frame", "next-frame"} { |
| 486 | if !near(live[n], painted[n]) { |
| 487 | t.Errorf("%s is at %v as arranged and at %v as first painted", n, live[n], painted[n]) |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // TestTheMenuHasItsSixRows: the ⋯ menu's rows, in the spec's order, |
| 493 | // each doing what it says: Pair posts to /pair in a window of its own, |
| 494 | // the slide window opens in its own, Arrange shows the bar in the |
| 495 | // approved words. |
| 496 | func TestTheMenuHasItsSixRows(t *testing.T) { |
| 497 | ar := newArrangeRig(t) |
| 498 | ar.rig.Run(cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 1440, Height: 900, DeviceScaleFactor: 1, Mobile: false})) |
| 499 | ar.open(t) |
| 500 | var rows []struct { |
| 501 | Label, Tag, Href, Action, Target, Method, Op string |
| 502 | Shown bool |
| 503 | } |
| 504 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-more]`)), |
| 505 | waitFor(`document.querySelector('[presenter-more-menu]').open`), |
| 506 | evalInto(&rows, `[...document.querySelectorAll('[presenter-menu] button, [presenter-menu] a')].map(e => { |
| 507 | const f = e.closest('form'); const r = e.getBoundingClientRect(); |
| 508 | return { Label: e.textContent.trim(), Tag: e.tagName.toLowerCase(), Href: e.getAttribute('href') || '', |
| 509 | Action: f ? f.getAttribute('action') : '', Target: (f || e).getAttribute('target') || '', |
| 510 | Method: f ? f.getAttribute('method') : '', Op: f && f.elements.op ? f.elements.op.value : '', |
| 511 | Shown: r.width > 0 && r.height > 0 } })`)) |
| 512 | want := []string{"Pair a phone as a remote…", "Open the slide window", "Switch to the full version", |
| 513 | "Arrange this window…", "Back to the deck", "End presenting"} |
| 514 | if len(rows) != len(want) { |
| 515 | t.Fatalf("the menu has %d rows, want %d: %+v", len(rows), len(want), rows) |
| 516 | } |
| 517 | for i, w := range want { |
| 518 | if rows[i].Label != w || !rows[i].Shown { |
| 519 | t.Errorf("row %d is %q (shown %v), want %q", i+1, rows[i].Label, rows[i].Shown, w) |
| 520 | } |
| 521 | } |
| 522 | session := "/p/" + ar.session |
| 523 | if r := rows[0]; r.Action != session+"/pair" || r.Method != "post" || r.Target != "slides-pair" { |
| 524 | t.Errorf("Pair is %+v, want a POST to %s/pair in the window slides-pair", r, session) |
| 525 | } |
| 526 | if r := rows[1]; r.Href != session || r.Target != "slides-window" { |
| 527 | t.Errorf("the slide window row is %+v, want %s in the window slides-window", r, session) |
| 528 | } |
| 529 | if r := rows[2]; r.Action != session+"/command" || r.Op != "mode" { |
| 530 | t.Errorf("the mode row is %+v, want the mode press", r) |
| 531 | } |
| 532 | if r := rows[3]; r.Tag != "button" { |
| 533 | t.Errorf("Arrange is a %s, want a button", r.Tag) |
| 534 | } |
| 535 | if r := rows[4]; !strings.HasSuffix(r.Href, "/edit") { |
| 536 | t.Errorf("Back to the deck goes to %q, want the editor", r.Href) |
| 537 | } |
| 538 | if r := rows[5]; r.Action != session+"/command" || r.Op != "end" { |
| 539 | t.Errorf("End presenting is %+v, want the end press", r) |
| 540 | } |
| 541 | |
| 542 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-arrange]`)), |
| 543 | waitFor(`document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 544 | var bar struct { |
| 545 | Text, Reset, Done string |
| 546 | MenuOpen bool |
| 547 | } |
| 548 | ar.rig.Run(evalInto(&bar, `(() => { const b = document.querySelector('[presenter-arrange-bar]'); |
| 549 | return { Text: b.querySelector('span').textContent, Reset: b.querySelector('[presenter-arrange-reset]').textContent, |
| 550 | Done: b.querySelector('[presenter-arrange-done]').textContent, MenuOpen: document.querySelector('[presenter-more-menu]').open } })()`)) |
| 551 | if bar.Text != "Drag a panel to move it; drag its corner to resize it." || bar.Reset != "Reset to the default" || bar.Done != "Done" { |
| 552 | t.Errorf("the arranging bar says %+v", bar) |
| 553 | } |
| 554 | if bar.MenuOpen { |
| 555 | t.Errorf("the menu stays open while arranging") |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | // TestPairingLeavesTheWindowItsTalk: Pair opens the pairing page in a |
| 560 | // window of its own, with the code, the address and the QR; the |
| 561 | // presenter window stays where it was and keeps driving, the old phone |
| 562 | // is retired, and the new one moves the window. |
| 563 | func TestPairingLeavesTheWindowItsTalk(t *testing.T) { |
| 564 | ar := newArrangeRig(t) |
| 565 | ar.open(t) |
| 566 | ar.rig.Run(keys(kb.ArrowRight, 1, false), |
| 567 | waitFor(`document.querySelector('[presenter]').getAttribute('data-step') === '1'`)) |
| 568 | |
| 569 | opened := chromedp.WaitNewTarget(ar.rig.Context(), func(info *target.Info) bool { |
| 570 | return strings.HasSuffix(info.URL, "/p/"+ar.session+"/pair") |
| 571 | }) |
| 572 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-more]`)), |
| 573 | waitFor(`document.querySelector('[presenter-more-menu]').open`), |
| 574 | chromedp.Click(chromedp.CSS(`[presenter-menu] form[action$="/pair"] button`))) |
| 575 | var id target.ID |
| 576 | select { |
| 577 | case id = <-opened: |
| 578 | case <-time.After(20 * time.Second): |
| 579 | t.Fatal("Pair opened no window of its own") |
| 580 | } |
| 581 | pairCtx, cancel := chromedp.NewContext(ar.rig.Context(), chromedp.WithTargetID(id)) |
| 582 | defer cancel() |
| 583 | var page, code string |
| 584 | if err := chromedp.Do(pairCtx, waitFor(`document.querySelector('[slides-qr]')`), |
| 585 | evalInto(&page, `document.documentElement.outerHTML`), |
| 586 | evalInto(&code, `document.querySelector('[slides-code]').textContent`)); err != nil { |
| 587 | t.Fatalf("read the pairing window: %v", err) |
| 588 | } |
| 589 | fresh := tokenOn(t, page) |
| 590 | if code != sessionCode(t, ar.app, ar.session) { |
| 591 | t.Errorf("the pairing window shows code %q, not the session's", code) |
| 592 | } |
| 593 | |
| 594 | var where struct { |
| 595 | Path, Name string |
| 596 | Step string |
| 597 | MenuOpen bool |
| 598 | } |
| 599 | ar.rig.Run(evalInto(&where, `({ Path: location.pathname, Name: window.name, Step: document.querySelector('[presenter]').getAttribute('data-step'), |
| 600 | MenuOpen: document.querySelector('[presenter-more-menu]').open })`)) |
| 601 | if where.Path != "/p/"+ar.session+"/notes" || where.Step != "1" { |
| 602 | t.Errorf("pairing moved the window: %+v", where) |
| 603 | } |
| 604 | if where.MenuOpen { |
| 605 | t.Errorf("the menu stays open after pairing") |
| 606 | } |
| 607 | |
| 608 | if rec := pressRequest(t, ar.app, ar.session, ar.token, op(t, "next"), nil); rec.Code != http.StatusNotFound { |
| 609 | t.Errorf("the retired phone still presses: status %d", rec.Code) |
| 610 | } |
| 611 | // The window still drives, by its presenter being signed in. |
| 612 | ar.rig.Run(keys(kb.ArrowRight, 1, false)) |
| 613 | deadline := time.Now().Add(10 * time.Second) |
| 614 | for { |
| 615 | if _, step, _ := rowPosition(t, ar.app, ar.session); step == 2 { |
| 616 | break |
| 617 | } |
| 618 | if time.Now().After(deadline) { |
| 619 | t.Fatal("the window's press after pairing never reached the talk") |
| 620 | } |
| 621 | time.Sleep(50 * time.Millisecond) |
| 622 | } |
| 623 | // And the new phone moves the window. |
| 624 | press(t, ar.app, ar.session, fresh, op(t, "next"), nil) |
| 625 | ar.rig.Run(waitFor(`document.querySelector('[presenter]').getAttribute('data-step') === '3'`)) |
| 626 | } |
| 627 | |
| 628 | // arrangeTool is one of the selected panel's eight buttons, by its name. |
| 629 | func arrangeTool(label string) chromedp.Action[chromedp.Void] { |
| 630 | return chromedp.Click(chromedp.CSS(`[presenter-arrange-tools] button[aria-label="` + label + `"]`)) |
| 631 | } |
| 632 | |
| 633 | // arrangeStatus is what the arranging's live region last said. |
| 634 | func (ar *arrangeRig) arrangeStatus(t *testing.T) string { |
| 635 | t.Helper() |
| 636 | var s string |
| 637 | ar.rig.Run(evalInto(&s, `document.querySelector('[presenter-arrange-status]').textContent`)) |
| 638 | return s |
| 639 | } |
| 640 | |
| 641 | // TestArrangeWithoutDragging: arranging needs neither a drag nor a |
| 642 | // keyboard. A tap selects a panel, which shows its eight buttons; each |
| 643 | // press moves or resizes it one cell, a move that cannot be made is |
| 644 | // disabled, and each change is said aloud. |
| 645 | func TestArrangeWithoutDragging(t *testing.T) { |
| 646 | ar := newArrangeRig(t) |
| 647 | ar.open(t) |
| 648 | ar.arrange(t) |
| 649 | |
| 650 | disabled := func(label string) bool { |
| 651 | var d string |
| 652 | ar.rig.Run(evalInto(&d, `document.querySelector('[presenter-arrange-tools] button[aria-label="`+label+`"]').getAttribute('aria-disabled') || ''`)) |
| 653 | return d == "true" |
| 654 | } |
| 655 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-panel="now"]`)), |
| 656 | waitFor(`document.querySelector('[presenter-panel="now"]').hasAttribute('data-selected')`)) |
| 657 | for label, want := range map[string]bool{"Move left": true, "Move up": true, "Move right": true, "Move down": true, |
| 658 | "Wider": true, "Taller": true, "Narrower": false, "Shorter": false} { |
| 659 | if got := disabled(label); got != want { |
| 660 | t.Errorf("Now in the default window: %s disabled %v, want %v", label, got, want) |
| 661 | } |
| 662 | } |
| 663 | ar.rig.Run(arrangeTool("Narrower"), arrangeTool("Narrower"), arrangeTool("Shorter"), arrangeTool("Shorter"), arrangeTool("Shorter")) |
| 664 | if got, want := ar.arrangeStatus(t), "On screen now: 5 by 5, column 1, row 1"; got != want { |
| 665 | t.Errorf("after resizing Now the live region says %q, want %q", got, want) |
| 666 | } |
| 667 | // Pressing a disabled one does nothing. |
| 668 | ar.rig.Run(arrangeTool("Move left")) |
| 669 | |
| 670 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-panel="next"]`)), |
| 671 | waitFor(`document.querySelector('[presenter-panel="next"]').hasAttribute('data-selected')`), |
| 672 | arrangeTool("Move up"), arrangeTool("Move up"), arrangeTool("Move up")) |
| 673 | if got, want := ar.arrangeStatus(t), "Coming next: 7 by 4, column 1, row 6"; got != want { |
| 674 | t.Errorf("after moving Next the live region says %q, want %q", got, want) |
| 675 | } |
| 676 | if !disabled("Move up") { |
| 677 | t.Errorf("Next against Now can still move up") |
| 678 | } |
| 679 | |
| 680 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-arrange-done]`)), |
| 681 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 682 | var saved string |
| 683 | ar.rig.Run(evalInto(&saved, cookieValueJS)) |
| 684 | if want := "fit.24.0,0,5,5;0,5,7,4;7,0,5,12"; saved != want { |
| 685 | t.Errorf("Done saved %q, want %q", saved, want) |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | // axNode is one node of the accessibility tree, flattened. |
| 690 | type axNode struct { |
| 691 | Role, Name, Description string |
| 692 | Props map[string]string |
| 693 | } |
| 694 | |
| 695 | // axValue is a value in the accessibility tree, read loosely: the |
| 696 | // protocol's own types refuse property names newer than they are. |
| 697 | type axValue struct { |
| 698 | Value any `json:"value"` |
| 699 | } |
| 700 | |
| 701 | func (v *axValue) text() string { |
| 702 | if v == nil || v.Value == nil { |
| 703 | return "" |
| 704 | } |
| 705 | return fmt.Sprint(v.Value) |
| 706 | } |
| 707 | |
| 708 | // axTree is the page's accessibility tree, as a screen reader is given it. |
| 709 | func (ar *arrangeRig) axTree(t *testing.T) []axNode { |
| 710 | t.Helper() |
| 711 | var res struct { |
| 712 | Nodes []struct { |
| 713 | Ignored bool `json:"ignored"` |
| 714 | Role *axValue `json:"role"` |
| 715 | Name *axValue `json:"name"` |
| 716 | Description *axValue `json:"description"` |
| 717 | Properties []struct { |
| 718 | Name string `json:"name"` |
| 719 | Value *axValue `json:"value"` |
| 720 | } `json:"properties"` |
| 721 | } `json:"nodes"` |
| 722 | } |
| 723 | ar.rig.Run(chromedp.Func(func(ctx context.Context, t *chromedp.Target) error { |
| 724 | return t.Call(ctx, accessibility.CommandGetFullAXTree, nil, &res) |
| 725 | })) |
| 726 | var out []axNode |
| 727 | for _, n := range res.Nodes { |
| 728 | if n.Ignored { |
| 729 | continue |
| 730 | } |
| 731 | a := axNode{Role: n.Role.text(), Name: n.Name.text(), Description: n.Description.text(), Props: map[string]string{}} |
| 732 | for _, p := range n.Properties { |
| 733 | a.Props[p.Name] = p.Value.text() |
| 734 | } |
| 735 | out = append(out, a) |
| 736 | } |
| 737 | return out |
| 738 | } |
| 739 | |
| 740 | func findAX(nodes []axNode, role, name string) *axNode { |
| 741 | for i := range nodes { |
| 742 | if nodes[i].Role == role && nodes[i].Name == name { |
| 743 | return &nodes[i] |
| 744 | } |
| 745 | } |
| 746 | return nil |
| 747 | } |
| 748 | |
| 749 | // TestArrangePanelsAreNamedControls: while arranging, each panel is a |
| 750 | // focusable group with its name and the keys described; the selected |
| 751 | // panel's buttons are named and say when they are disabled; every move |
| 752 | // or resize, by keyboard as by button, is said in a polite live region |
| 753 | // with the panel's size and place. |
| 754 | func TestArrangePanelsAreNamedControls(t *testing.T) { |
| 755 | ar := newArrangeRig(t) |
| 756 | ar.open(t) |
| 757 | ar.arrange(t) |
| 758 | help := "Arrow keys move this panel. Shift and an arrow key resize it." |
| 759 | |
| 760 | tree := ar.axTree(t) |
| 761 | for _, name := range []string{"On screen now", "Coming next", "Speaker notes"} { |
| 762 | n := findAX(tree, "group", name) |
| 763 | if n == nil { |
| 764 | t.Errorf("no group named %q while arranging", name) |
| 765 | continue |
| 766 | } |
| 767 | if n.Description != help || n.Props["focusable"] != "true" { |
| 768 | t.Errorf("the %q panel is described %q (focusable %q), want %q and focusable", name, n.Description, n.Props["focusable"], help) |
| 769 | } |
| 770 | } |
| 771 | for _, label := range []string{"Move left", "Move right", "Move up", "Move down", "Narrower", "Wider", "Shorter", "Taller"} { |
| 772 | b := findAX(tree, "button", label) |
| 773 | if b == nil { |
| 774 | t.Errorf("no button named %q on the selected panel", label) |
| 775 | continue |
| 776 | } |
| 777 | want := label == "Narrower" || label == "Shorter" |
| 778 | if got := b.Props["disabled"] != "true"; got != want { |
| 779 | t.Errorf("%q enabled %v, want %v", label, got, want) |
| 780 | } |
| 781 | } |
| 782 | var bar string |
| 783 | ar.rig.Run(evalInto(&bar, `document.querySelector('[presenter-arrange-bar]').innerText`)) |
| 784 | if !strings.Contains(bar, help) { |
| 785 | t.Errorf("the arranging bar does not show the keys: %q", bar) |
| 786 | } |
| 787 | |
| 788 | // The keyboard, with the focus where arranging put it, on Now. |
| 789 | ar.rig.Run(keys(kb.ArrowLeft, 1, true)) |
| 790 | if got, want := ar.arrangeStatus(t), "On screen now: 6 by 8, column 1, row 1"; got != want { |
| 791 | t.Errorf("after Shift+ArrowLeft the live region says %q, want %q", got, want) |
| 792 | } |
| 793 | tree = ar.axTree(t) |
| 794 | var live *axNode |
| 795 | for i := range tree { |
| 796 | if tree[i].Role == "status" && tree[i].Props["live"] == "polite" { |
| 797 | live = &tree[i] |
| 798 | } |
| 799 | } |
| 800 | if live == nil { |
| 801 | t.Fatalf("no polite live region while arranging") |
| 802 | } |
| 803 | if b := findAX(tree, "button", "Wider"); b == nil || b.Props["disabled"] == "true" { |
| 804 | t.Errorf("Now narrowed by a cell cannot be widened again: %+v", b) |
| 805 | } |
| 806 | ar.rig.Run(focusPanel("notes"), keys(kb.ArrowDown, 1, true)) |
| 807 | if got, want := ar.arrangeStatus(t), "Speaker notes: 5 by 12, column 8, row 1"; got != want { |
| 808 | t.Errorf("a resize that cannot be made says %q, want the notes' place %q", got, want) |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | // TestArrangedPreviewsAreNeverEmpty: at the smallest window that |
| 813 | // arranges, 720×560, the smallest panels the grid allows still show |
| 814 | // their slide: every preview has a size when the window opens on that |
| 815 | // arrangement, after arranging to it and pressing Done, and after a |
| 816 | // reload. |
| 817 | func TestArrangedPreviewsAreNeverEmpty(t *testing.T) { |
| 818 | ar := newArrangeRig(t) |
| 819 | ar.rig.Run(cdpStep(emulation.SetDeviceMetricsOverride, emulation.SetDeviceMetricsOverrideParams{Width: 720, Height: 560, DeviceScaleFactor: 1, Mobile: false})) |
| 820 | smallest := []string{ |
| 821 | "fit.24.10,10,2,2;0,0,2,2;5,5,2,2", |
| 822 | "fit.24.0,0,2,2;10,0,2,2;0,10,2,2", |
| 823 | } |
| 824 | for _, prefs := range smallest { |
| 825 | ar.prefs(prefs) |
| 826 | ar.open(t) |
| 827 | inside(t, ar, prefs+", opened", false) |
| 828 | } |
| 829 | |
| 830 | // Arranged down to the smallest by keyboard, then Done. |
| 831 | ar.prefs("fit.24.0,0,7,8;0,8,7,4;7,0,5,12") |
| 832 | ar.open(t) |
| 833 | ar.arrange(t) |
| 834 | ar.rig.Run(focusPanel("now"), keys(kb.ArrowLeft, 10, true), keys(kb.ArrowUp, 10, true), |
| 835 | focusPanel("next"), keys(kb.ArrowLeft, 10, true), keys(kb.ArrowUp, 10, true)) |
| 836 | ar.rig.Run(chromedp.Click(chromedp.CSS(`[presenter-arrange-done]`)), |
| 837 | waitFor(`!document.querySelector('[presenter]').hasAttribute('data-arranging')`)) |
| 838 | var saved string |
| 839 | ar.rig.Run(evalInto(&saved, cookieValueJS)) |
| 840 | inside(t, ar, "after Done ("+saved+")", false) |
| 841 | ar.open(t) |
| 842 | inside(t, ar, "reloaded ("+saved+")", false) |
| 843 | } |
| 844 | |