| 1 | //go:build browser |
| 2 | |
| 3 | package thintest |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/wire" |
| 9 | ) |
| 10 | |
| 11 | // With script, a question asked about a Mac-made step while that Mac is |
| 12 | // offline says which Mac and to ask again when it is back, as text, beside |
| 13 | // the retry; nothing was asked. |
| 14 | func TestBrowserAskMacOffline(t *testing.T) { |
| 15 | r := newMacRig(t) |
| 16 | a := r.newMacEngineer("Tito Studio", wire.EngineeringReady) |
| 17 | task, d := r.macDispatch(a, "iOS offline page", sha(1)) |
| 18 | r.askableOn(a, d, sha(0xc1), "mac-c1", "sess-1") |
| 19 | r.macOffline(a) |
| 20 | p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") |
| 21 | defer p.stop() |
| 22 | p.open("/tasks/" + task) |
| 23 | p.wait(`!!document.querySelector('[data-chat-stream][data-task] #composer')`, "the task's composer") |
| 24 | p.check(`(()=>{const i=document.querySelector('#chat-body');i.value='What did you change?';i.dispatchEvent(new Event('input'));document.querySelector('#composer').requestSubmit();return true})()`, "ask") |
| 25 | p.wait(`!!document.querySelector('[data-send-failed] [data-retry-send]')`, "the send failed") |
| 26 | p.check(`(()=>{const e=document.querySelector('[data-send-failed] [data-send-error]');return !!e && e.textContent==='Tito Studio is offline. Ask again when it is back.' && e.children.length===0})()`, "the offline Mac named, with when to ask again, as text") |
| 27 | // The line is shown as text, whatever it holds. |
| 28 | hostile := `Mac <b>B</b><img src=x onerror="window.__pwned=1"> is offline. Ask again when it is back.` |
| 29 | p.check(`(()=>{const m=`+jsString(hostile)+`;window.fetch=()=>Promise.resolve(new Response(JSON.stringify({error:{code:'runner_offline',message:m}}),{status:409,headers:{'Content-Type':'application/json'}}));document.querySelector('[data-send-failed] [data-retry-send]').click();return true})()`, "retry, refused with markup in the line") |
| 30 | p.wait(`(()=>{const e=document.querySelector('[data-send-failed] [data-send-error]');return !!e && e.textContent.startsWith('Mac <b>')})()`, "the hostile line") |
| 31 | p.check(`(()=>{const es=document.querySelectorAll('[data-send-error]');return es.length===1 && es[0].children.length===0 && es[0].textContent===`+jsString(hostile)+` && !document.querySelector('[data-send-failed] img') && window.__pwned===undefined})()`, "the line as text only, once") |
| 32 | if k := r.task(task); len(k.Questions) != 0 { |
| 33 | t.Fatalf("a question was asked: %+v", k.Questions) |
| 34 | } |
| 35 | } |
| 36 | |