//go:build browser package browsertest import ( "strconv" "strings" "testing" "time" "github.com/chromedp/chromedp" "amadan.net/rastrillo/rastrillo/harness" "amadan.net/oficina/base/internal/equipo" ) // A card's Connect link (rel oficina_connect) to Base's own connect page // opens in the same tab; the same path on another host gets no such // treatment and keeps its new tab. func TestAskOficinaConnectLinkIsSameTab(t *testing.T) { rig, f := askBase(t) openPanel(t, rig) f.OficinaConsent(f.URL + "/consent") id := f.AskOutcome("Connect Oficina to go on.", nil, []equipo.Link{ {Label: "Connect", URL: rig.Origin + "/ask/oficina/connect", Rel: "oficina_connect"}, {Label: "Lookalike", URL: "https://evil.example.test/ask/oficina/connect", Rel: "oficina_connect"}, }) card := `#ask-panel [data-card="` + id + `"]` drive(t, rig, chromedp.Poll[chromedp.Void](`document.querySelectorAll(`+strconv.Quote(card+` a.card-link`)+`).length === 2`, chromedp.WithPollingTimeout(10*time.Second))) got := harness.Evaluate[string](rig, `[...document.querySelectorAll(`+strconv.Quote(card+` a.card-link`)+`)] .map(a => a.textContent + ":" + (a.getAttribute("target") || "-")).join("|")`) if got != "Connect:-|Lookalike:_blank" { t.Fatalf("link targets %q, want Connect:-|Lookalike:_blank", got) } // Clicking it leaves this tab for the consent address. drive(t, rig, chromedp.Click(chromedp.CSS(card+` a.card-link`)), chromedp.Sleep(500*time.Millisecond)) drive(t, rig, chromedp.Poll[chromedp.Void](`location.href.startsWith(`+strconv.Quote(f.URL)+`)`, chromedp.WithPollingTimeout(10*time.Second))) if n := strings.Count(harness.Evaluate[string](rig, `location.href`), f.URL); n != 1 { t.Errorf("not on the consent address") } }