| 1 | //go:build webkit |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "encoding/base64" |
| 7 | "encoding/json" |
| 8 | "os" |
| 9 | "os/exec" |
| 10 | "path/filepath" |
| 11 | "strings" |
| 12 | "testing" |
| 13 | |
| 14 | "amadan.net/oficina/equipo/internal/attach/attachtest" |
| 15 | ) |
| 16 | |
| 17 | // TestWebKitAttachments: Paul, staging 8334e25, Safari on an iPhone, dark: |
| 18 | // the chip above the words was an empty dark square. The page's policy |
| 19 | // allows data: images only and the preview was a blob: URL. In WebKit at |
| 20 | // 390 on touch, dark and light, under production's policy: a picked photo |
| 21 | // becomes a chip whose preview has loaded (a data: image); a pasted image |
| 22 | // attaches; the sent thumbnail loads at once and, after a reload, from the |
| 23 | // server's preview; nothing is refused by the policy; and the pill's edge |
| 24 | // steps up only a little on focus, with no outline. Needs |
| 25 | // EQUIPO_PLAYWRIGHT_CORE. EQUIPO_BROWSER_ARTIFACTS saves the shots. |
| 26 | func TestWebKitAttachments(t *testing.T) { |
| 27 | core := os.Getenv("EQUIPO_PLAYWRIGHT_CORE") |
| 28 | if core == "" { |
| 29 | t.Skip("EQUIPO_PLAYWRIGHT_CORE is not set") |
| 30 | } |
| 31 | inst := StartInstance(t) |
| 32 | photo := filepath.Join(t.TempDir(), "IMG_0001.jpg") |
| 33 | if err := os.WriteFile(photo, attachtest.Photo(1200, 900, 6), 0600); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | c := inst.Cookie() |
| 37 | 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")}) |
| 38 | cmd := exec.Command("node", "testdata/attach.mjs") |
| 39 | cmd.Env = append(os.Environ(), "EQUIPO_ATTACH="+string(raw)) |
| 40 | cmd.Stderr = os.Stderr |
| 41 | got, err := cmd.Output() |
| 42 | if err != nil { |
| 43 | t.Fatalf("webkit: %v", err) |
| 44 | } |
| 45 | var res map[string]struct { |
| 46 | Rest, Focused, Outline string |
| 47 | Chip struct { |
| 48 | Src string |
| 49 | Width int |
| 50 | Complete bool |
| 51 | } |
| 52 | Paste struct{ Supported, Taken bool } |
| 53 | Sent string |
| 54 | Server string |
| 55 | Blocked []string |
| 56 | } |
| 57 | if err := json.Unmarshal(got, &res); err != nil { |
| 58 | t.Fatalf("webkit output %q: %v", got, err) |
| 59 | } |
| 60 | for _, scheme := range []string{"dark", "light"} { |
| 61 | r := res[scheme] |
| 62 | if !strings.HasPrefix(r.Chip.Src, "data:image/") || r.Chip.Width == 0 || !r.Chip.Complete { |
| 63 | t.Fatalf("%s: the chip's preview did not load: %+v", scheme, r.Chip) |
| 64 | } |
| 65 | if r.Paste.Supported && !r.Paste.Taken { |
| 66 | t.Fatalf("%s: a pasted image was not attached", scheme) |
| 67 | } |
| 68 | if !strings.HasPrefix(r.Sent, "data:image/") && !strings.Contains(r.Sent, "/conversation/") { |
| 69 | t.Fatalf("%s: the sent thumbnail %q", scheme, r.Sent) |
| 70 | } |
| 71 | if !strings.HasPrefix(r.Server, "/conversation/attachments/at_") || !strings.HasSuffix(r.Server, "/preview") { |
| 72 | t.Fatalf("%s: after a reload the thumbnail is %q", scheme, r.Server) |
| 73 | } |
| 74 | if len(r.Blocked) > 0 { |
| 75 | t.Fatalf("%s: the policy refused %v", scheme, r.Blocked) |
| 76 | } |
| 77 | if r.Rest == r.Focused || r.Outline != "none" { |
| 78 | t.Fatalf("%s: focus edge %s to %s, outline %s", scheme, r.Rest, r.Focused, r.Outline) |
| 79 | } |
| 80 | t.Logf("%s: edge %s to %s; paste supported=%v taken=%v", scheme, r.Rest, r.Focused, r.Paste.Supported, r.Paste.Taken) |
| 81 | } |
| 82 | } |
| 83 | |