//go:build webkit package thintest import ( "encoding/json" "math" "os" "os/exec" "testing" ) type keyboardSpot struct { VVTop, VVBottom, ScrollY float64 ComposerTop, ComposerBottom *float64 LastTop, LastBottom *float64 } // TestWebKitKeyboard: Paul, staging f2eac36, Safari on an iPhone: the // composer jumped to the top of the screen when the keyboard opened. In // WebKit at 390x844 with the keyboard simulated as Safari does it (the // visual viewport shrinks to 450 and pans down; the layout viewport // stays), the chat's composer sits on the keyboard (its bottom on the // visual viewport's), well below the status bar, the newest message just // above it, and back at the bottom when the keyboard closes. The empty // conversation and the task thread's composer too. Needs // EQUIPO_PLAYWRIGHT_CORE (a playwright-core directory with its WebKit). func TestWebKitKeyboard(t *testing.T) { core := os.Getenv("EQUIPO_PLAYWRIGHT_CORE") if core == "" { t.Skip("EQUIPO_PLAYWRIGHT_CORE is not set") } g := newGallery(t) owner, member := g.a.inst.Cookie(), g.a.memberCookie() type pageCfg struct { Name string `json:"name"` Path string `json:"path"` Selector string `json:"selector"` Scheme string `json:"scheme"` Cookie map[string]string `json:"cookie"` ScrollToComposer bool `json:"scrollToComposer"` } ck := func(name, value string) map[string]string { return map[string]string{"name": name, "value": value} } pages := []pageCfg{ {Name: "chat", Path: "/conversation", Selector: "#chat-composer", Cookie: ck(owner.Name, owner.Value)}, {Name: "chat-dark", Path: "/conversation", Selector: "#chat-composer", Scheme: "dark", Cookie: ck(owner.Name, owner.Value)}, {Name: "empty", Path: "/conversation", Selector: "#chat-composer", Cookie: ck(member.Name, member.Value)}, {Name: "task", Path: "/tasks/" + g.unchecked, Selector: "#chat-composer", Cookie: ck(owner.Name, owner.Value), ScrollToComposer: true}, } when := os.Getenv("EQUIPO_KEYBOARD_WHEN") if when == "" { when = "after" } raw, _ := json.Marshal(map[string]any{"base": g.a.inst.URL, "pages": pages, "art": os.Getenv("EQUIPO_BROWSER_ARTIFACTS"), "when": when}) cmd := exec.Command("node", "testdata/keyboard.mjs") cmd.Env = append(os.Environ(), "EQUIPO_KEYBOARD="+string(raw)) cmd.Stderr = os.Stderr got, err := cmd.Output() if err != nil { t.Fatalf("webkit: %v", err) } var res map[string]map[string]keyboardSpot if err := json.Unmarshal(got, &res); err != nil { t.Fatalf("webkit output %q: %v", got, err) } near := func(a, b float64) bool { return math.Abs(a-b) <= 2 } for _, name := range []string{"chat", "chat-dark", "empty"} { for _, state := range []string{"closed", "open", "reclosed"} { s := res[name][state] if s.ComposerBottom == nil { t.Fatalf("%s %s: no composer", name, state) } if !near(*s.ComposerBottom, s.VVBottom) { t.Fatalf("%s %s: composer bottom %.1f, visual viewport bottom %.1f (%+v)", name, state, *s.ComposerBottom, s.VVBottom, s) } // Below the status bar: well into the visible area, never at its top. if *s.ComposerTop < s.VVTop+200 { t.Fatalf("%s %s: composer top %.1f at the top of the visible area from %.1f", name, state, *s.ComposerTop, s.VVTop) } if name != "empty" && s.LastBottom != nil && (*s.LastBottom > *s.ComposerTop+1 || *s.LastBottom < *s.ComposerTop-160 || *s.LastBottom < s.VVTop) { t.Fatalf("%s %s: newest message %.1f..%.1f not just above the composer at %.1f", name, state, *s.LastTop, *s.LastBottom, *s.ComposerTop) } } } // The task thread's composer is in the page's flow: with Safari's pan it // stays where the focused field is, inside the visible area. for _, state := range []string{"closed", "open"} { s := res["task"][state] if s.ComposerBottom == nil || *s.ComposerBottom > s.VVBottom+2 || *s.ComposerTop < s.VVTop-2 { t.Fatalf("task %s: composer %v..%v outside %.1f..%.1f", state, s.ComposerTop, s.ComposerBottom, s.VVTop, s.VVBottom) } } }