| 1 | //go:build browser |
| 2 | |
| 3 | package gallery |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | "net/http" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | "time" |
| 11 | |
| 12 | "github.com/chromedp/cdproto/emulation" |
| 13 | "github.com/chromedp/chromedp" |
| 14 | |
| 15 | "amadan.net/rastrillo/fiesta" |
| 16 | "amadan.net/rastrillo/fiesta/internal/harness" |
| 17 | ) |
| 18 | |
| 19 | // TestEveryPageKindFitsAPhoneAt320: WCAG 2.2 AA 1.4.10 Reflow on one |
| 20 | // page of every kind in the shell, in English and Arabic: the index, |
| 21 | // Tokens, Icons, a family page and an example page at a 320 CSS-pixel |
| 22 | // viewport must not need horizontal scrolling. Fiesta's own drive |
| 23 | // over every example page in a11y_browser_test.go stays beside this |
| 24 | // one; this reads the shell's other pages, in the other direction too. |
| 25 | func TestEveryPageKindFitsAPhoneAt320(t *testing.T) { |
| 26 | rig := harness.New(t, func(string) http.Handler { return treeHandler(t) }) |
| 27 | ctx, cancel := context.WithTimeout(rig.Context(), 3*time.Minute) |
| 28 | defer cancel() |
| 29 | theme := fiesta.ThemeNames()[0] |
| 30 | measured := 0 |
| 31 | for _, locale := range []string{"en", "ar"} { |
| 32 | for _, file := range []string{"index.html", "tokens.html", "icons.html", "form.html", "button.html"} { |
| 33 | where := theme + "/" + locale + "/" + file |
| 34 | mustRun(t, ctx, |
| 35 | chromedp.ActionFunc(func(c context.Context) error { |
| 36 | return emulation.SetDeviceMetricsOverride(320, 640, 1, false).Do(c) |
| 37 | }), |
| 38 | chromedp.Navigate(rig.Origin+pageAt(theme, locale, file)), |
| 39 | chromedp.WaitReady("body"), |
| 40 | ) |
| 41 | present(t, ctx, where, "[rst-shell-sidebar]") |
| 42 | var got struct { |
| 43 | Doc, Client, Body int |
| 44 | Over []string |
| 45 | } |
| 46 | at(t, ctx, measureJS, &got) |
| 47 | if got.Doc > got.Client || got.Body > got.Client { |
| 48 | t.Errorf("%s scrolls sideways at 320px (WCAG 1.4.10): document %dpx, body %dpx in a %dpx page\n widest: %s", |
| 49 | where, got.Doc, got.Body, got.Client, strings.Join(got.Over, "\n ")) |
| 50 | } |
| 51 | measured++ |
| 52 | } |
| 53 | } |
| 54 | t.Logf("%d pages measured", measured) |
| 55 | } |
| 56 | |