rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser
2
3// Package history holds the gallery's browser legs that need a real
4// back/forward cache restore or a real new-tab click: the headless
5// shell the cloud runner links as chromium never gives either, so
6// these legs need full Chromium (the Makefile's FULL_CHROMIUM), and
7// they are a package of their own so that cost falls on only them.
8package history
9
10import (
11 "context"
12 "net/http"
13 "testing"
14
15 "github.com/chromedp/chromedp"
16
17 "amadan.net/rastrillo/fiesta"
18 "amadan.net/rastrillo/fiesta/internal/gallery"
19 "amadan.net/rastrillo/fiesta/internal/gallery/galleryrig"
20 "amadan.net/rastrillo/fiesta/internal/harness"
21)
22
23// The gallery's addresses and the shared drive helpers, under the
24// names these legs are written with. One line each: the
25// implementations are galleryrig's. The page files are written here
26// by name, since the page-kind table is the gallery package's own.
27
28const (
29 mountPath = "/gallery"
30 mountPrefix = mountPath + "/"
31)
32
33func pageHref(theme, locale, file string) string {
34 return mountPrefix + theme + "/" + locale + "/" + file
35}
36
37// indexHref is the Overview's address: the one page every index drive
38// navigates to by name.
39func indexHref(theme, locale string) string { return pageHref(theme, locale, "index.html") }
40
41func treeHandler(t *testing.T) http.Handler {
42 t.Helper()
43 files, err := gallery.Render(fiesta.FS(), gallery.Options{Mount: mountPath})
44 if err != nil {
45 t.Fatalf("Render: %v", err)
46 }
47 return galleryrig.Tree(t, files, mountPrefix)
48}
49
50func addInit(js string) chromedp.Action { return galleryrig.AddInit(js) }
51
52func phoneRig(t *testing.T) *harness.Rig {
53 t.Helper()
54 return galleryrig.PhoneRig(t, func() http.Handler { return treeHandler(t) })
55}
56
57func requireCoarse(t *testing.T, ctx context.Context) {
58 t.Helper()
59 galleryrig.RequireCoarse(t, ctx)
60}
61
62func until(t *testing.T, ctx context.Context, where, expr string) {
63 t.Helper()
64 galleryrig.Until(t, ctx, where, expr)
65}
66