|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { installApiStub } from "./fixtures/api"; |
| 4 | + |
| 5 | +// THE TOP EDGE OF A HOME-SCREEN APP, laid out by the engine (index.css, "THE TOP EDGE"; #597). |
| 6 | +// Playwright cannot emulate a Home Screen launch, an `-webkit-touch-callout` WebView or a safe-area |
| 7 | +// inset, and it cannot draw the iOS 27 blur, so this cannot show the iPad case itself. What it does |
| 8 | +// prove, in WebKit and Chromium at phone and tablet width: with the standalone gate lifted from the |
| 9 | +// SHIPPED stylesheet (read back through the CSSOM, so a rule that moves or breaks fails here), the |
| 10 | +// element is a real, fixed, full-width, opaque box at y=0 in the header's own colour, as tall as the |
| 11 | +// floor (the inset is 0 in a browser), never in the way of a tap, and it moves nothing. |
| 12 | + |
| 13 | +// NO SERVICE WORKER: `page.route` cannot see a request the worker makes (see composer-clear.spec.ts). |
| 14 | +test.use({ serviceWorkers: "block" }); |
| 15 | + |
| 16 | +test.beforeEach(async ({ page }, testInfo) => { |
| 17 | + test.skip(testInfo.project.name.startsWith("states"), "the playground has no shell"); |
| 18 | + await installApiStub(page); |
| 19 | +}); |
| 20 | + |
| 21 | +/** Re-adds the shipped rules that sit behind the standalone iOS gate, without the gate. */ |
| 22 | +async function liftGate(page: import("@playwright/test").Page): Promise<void> { |
| 23 | + await page.evaluate(() => { |
| 24 | + const out: string[] = []; |
| 25 | + const walk = (rules: CSSRuleList, wrap: string[]): void => { |
| 26 | + for (const rule of Array.from(rules)) { |
| 27 | + if (rule instanceof CSSStyleRule) { |
| 28 | + if (rule.selectorText.includes("top-edge") || rule.cssText.includes("--top-edge-floor")) { |
| 29 | + out.push(wrap.reduceRight((inner, outer) => `${outer} { ${inner} }`, rule.cssText)); |
| 30 | + } |
| 31 | + } else if (rule instanceof CSSMediaRule || rule instanceof CSSSupportsRule) { |
| 32 | + const cond = rule instanceof CSSMediaRule ? rule.conditionText : ""; |
| 33 | + const sup = rule instanceof CSSSupportsRule ? rule.conditionText : ""; |
| 34 | + if (/display-mode|-webkit-touch-callout/u.test(cond + sup)) walk(rule.cssRules, wrap); |
| 35 | + else walk(rule.cssRules, [...wrap, `@media ${cond}`]); |
| 36 | + } |
| 37 | + } |
| 38 | + }; |
| 39 | + for (const sheet of Array.from(document.styleSheets)) walk(sheet.cssRules, []); |
| 40 | + const style = document.createElement("style"); |
| 41 | + style.dataset.lifted = "top-edge"; |
| 42 | + style.textContent = out.join("\n"); |
| 43 | + document.head.appendChild(style); |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +test("outside a Home Screen app the element draws nothing", async ({ page }) => { |
| 48 | + await page.goto("/"); |
| 49 | + const edge = page.locator('[data-slot="top-edge"]'); |
| 50 | + await expect(edge).toHaveCount(1); |
| 51 | + expect(await edge.evaluate((el) => getComputedStyle(el).display)).toBe("none"); |
| 52 | +}); |
| 53 | + |
| 54 | +test("with the gate lifted it is a fixed, opaque, full-width strip at the top in the header colour", async ({ page }) => { |
| 55 | + await page.goto("/"); |
| 56 | + await expect(page.getByRole("banner")).toBeVisible(); |
| 57 | + const before = await page.getByRole("banner").boundingBox(); |
| 58 | + await liftGate(page); |
| 59 | + |
| 60 | + const m = await page.evaluate(() => { |
| 61 | + const el = document.querySelector<HTMLElement>('[data-slot="top-edge"]'); |
| 62 | + const header = document.querySelector("header"); |
| 63 | + if (el === null || header === null) throw new Error("no strip or no header"); |
| 64 | + const s = getComputedStyle(el); |
| 65 | + const r = el.getBoundingClientRect(); |
| 66 | + return { |
| 67 | + display: s.display, |
| 68 | + position: s.position, |
| 69 | + pointerEvents: s.pointerEvents, |
| 70 | + zIndex: s.zIndex, |
| 71 | + bg: s.backgroundColor, |
| 72 | + headerBg: getComputedStyle(header).backgroundColor, |
| 73 | + x: r.x, |
| 74 | + y: r.y, |
| 75 | + width: r.width, |
| 76 | + height: r.height, |
| 77 | + innerWidth: window.innerWidth, |
| 78 | + }; |
| 79 | + }); |
| 80 | + expect(m.display).toBe("block"); |
| 81 | + expect(m.position).toBe("fixed"); |
| 82 | + expect(m.pointerEvents).toBe("none"); |
| 83 | + expect(Number(m.zIndex)).toBeGreaterThan(20); |
| 84 | + expect(m.y).toBe(0); |
| 85 | + expect(m.x).toBe(0); |
| 86 | + expect(m.width).toBe(m.innerWidth); |
| 87 | + // Opaque, and the header's own paint, so the two cannot show a seam. |
| 88 | + expect(m.bg).toBe(m.headerBg); |
| 89 | + expect(m.bg).not.toMatch(/rgba\(.*,\s*0\)$/u); |
| 90 | + // No inset in a browser: a phone gets no floor, a tablet gets the smallest height WebKit accepts. |
| 91 | + expect(m.height).toBe(m.innerWidth >= 768 ? 6 : 0); |
| 92 | + |
| 93 | + // It moves nothing: the banner sits where it sat. |
| 94 | + const after = await page.getByRole("banner").boundingBox(); |
| 95 | + expect(after).toEqual(before); |
| 96 | +}); |
0 commit comments