//go:build webkit package thintest import ( "encoding/base64" "encoding/json" "os" "os/exec" "path/filepath" "strings" "testing" "amadan.net/oficina/equipo/internal/attach/attachtest" ) // TestWebKitAttachments: Paul, staging 8334e25, Safari on an iPhone, dark: // the chip above the words was an empty dark square. The page's policy // allows data: images only and the preview was a blob: URL. In WebKit at // 390 on touch, dark and light, under production's policy: a picked photo // becomes a chip whose preview has loaded (a data: image); a pasted image // attaches; the sent thumbnail loads at once and, after a reload, from the // server's preview; nothing is refused by the policy; and the pill's edge // steps up only a little on focus, with no outline. Needs // EQUIPO_PLAYWRIGHT_CORE. EQUIPO_BROWSER_ARTIFACTS saves the shots. func TestWebKitAttachments(t *testing.T) { core := os.Getenv("EQUIPO_PLAYWRIGHT_CORE") if core == "" { t.Skip("EQUIPO_PLAYWRIGHT_CORE is not set") } inst := StartInstance(t) photo := filepath.Join(t.TempDir(), "IMG_0001.jpg") if err := os.WriteFile(photo, attachtest.Photo(1200, 900, 6), 0600); err != nil { t.Fatal(err) } c := inst.Cookie() raw, _ := json.Marshal(map[string]any{"base": inst.URL, "cookie": map[string]string{"name": c.Name, "value": c.Value}, "photo": photo, "small": base64.StdEncoding.EncodeToString(attachtest.PNG(8, 8)), "art": os.Getenv("EQUIPO_BROWSER_ARTIFACTS")}) cmd := exec.Command("node", "testdata/attach.mjs") cmd.Env = append(os.Environ(), "EQUIPO_ATTACH="+string(raw)) cmd.Stderr = os.Stderr got, err := cmd.Output() if err != nil { t.Fatalf("webkit: %v", err) } var res map[string]struct { Rest, Focused, Outline string Chip struct { Src string Width int Complete bool } Paste struct{ Supported, Taken bool } Sent string Server string Blocked []string } if err := json.Unmarshal(got, &res); err != nil { t.Fatalf("webkit output %q: %v", got, err) } for _, scheme := range []string{"dark", "light"} { r := res[scheme] if !strings.HasPrefix(r.Chip.Src, "data:image/") || r.Chip.Width == 0 || !r.Chip.Complete { t.Fatalf("%s: the chip's preview did not load: %+v", scheme, r.Chip) } if r.Paste.Supported && !r.Paste.Taken { t.Fatalf("%s: a pasted image was not attached", scheme) } if !strings.HasPrefix(r.Sent, "data:image/") && !strings.Contains(r.Sent, "/conversation/") { t.Fatalf("%s: the sent thumbnail %q", scheme, r.Sent) } if !strings.HasPrefix(r.Server, "/conversation/attachments/at_") || !strings.HasSuffix(r.Server, "/preview") { t.Fatalf("%s: after a reload the thumbnail is %q", scheme, r.Server) } if len(r.Blocked) > 0 { t.Fatalf("%s: the policy refused %v", scheme, r.Blocked) } if r.Rest == r.Focused || r.Outline != "none" { t.Fatalf("%s: focus edge %s to %s, outline %s", scheme, r.Rest, r.Focused, r.Outline) } t.Logf("%s: edge %s to %s; paste supported=%v taken=%v", scheme, r.Rest, r.Focused, r.Paste.Supported, r.Paste.Taken) } }