| 1 | package home |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "regexp" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestHandoffInterstitialStaysHiddenWhileItAutoSubmits is spec |
| 11 | // shared-chrome §9.3: the assertion hand-off page submits itself, so its |
| 12 | // fallback copy is hidden for 1.5 s and appears only if the submit |
| 13 | // stalls. Without it every sign-in, and every app switch that needs an |
| 14 | // exchange, flashes "Continue to Oficina" mid-hop. With scripts off |
| 15 | // nothing submits, so a <noscript> rule shows the fallback at once. |
| 16 | func TestHandoffInterstitialStaysHiddenWhileItAutoSubmits(t *testing.T) { |
| 17 | app := newTestApp(t) |
| 18 | var buf bytes.Buffer |
| 19 | if err := app.renderer.pages["assertion.html"].ExecuteTemplate(&buf, "layout", page{Data: map[string]any{"Action": "https://blue.docs.oficina.works/auth/assertion", "Token": "sample-token"}}); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | page := buf.String() |
| 23 | head, body, ok := strings.Cut(page, "</head>") |
| 24 | if !ok { |
| 25 | t.Fatal("no head") |
| 26 | } |
| 27 | compact := regexp.MustCompile(`\s+`).ReplaceAllString(head, "") |
| 28 | for _, want := range []string{ |
| 29 | "[estilo-handoff]{animation:estilo-reveal0s1.5sboth;}", |
| 30 | "@keyframesestilo-reveal{from{visibility:hidden}to{visibility:visible}}", |
| 31 | "<noscript><style>[estilo-handoff]{animation:none;}</style></noscript>", |
| 32 | } { |
| 33 | if !strings.Contains(compact, want) { |
| 34 | t.Fatalf("head lacks %q:\n%s", want, head) |
| 35 | } |
| 36 | } |
| 37 | // Everything the person could read or press is inside the hidden |
| 38 | // card, and the form the script submits is still the one there. The |
| 39 | // bar and the sky's placeholder sit outside it, so the hop is never a |
| 40 | // blank page (r3 C2). |
| 41 | main := body[strings.Index(body, "<main"):strings.Index(body, "</main>")] |
| 42 | start := strings.Index(main, "<section estilo-signin estilo-handoff>") |
| 43 | if start < 0 || !strings.Contains(main[:start], `estilo-sky-layer="placeholder"`) { |
| 44 | t.Fatalf("content not wrapped in the hidden card on the sky:\n%s", main) |
| 45 | } |
| 46 | inner := main[start:strings.Index(main, "</section>")] |
| 47 | if !strings.Contains(inner, `data-assertion-handoff`) || !strings.Contains(inner, `<button type="submit" rst-btn="primary">Continue</button>`) { |
| 48 | t.Fatalf("hand-off form changed:\n%s", inner) |
| 49 | } |
| 50 | } |
| 51 | |