✨ feature: Add independent chrome tint elements for iOS 26+ compatibility and enhance related tests
This commit is contained in:
+21
@@ -39,6 +39,27 @@ $showHero = $post->post_parent === $services ? true : false;
|
||||
<?php echo esc_html__( 'Skip to main content' ); ?>
|
||||
</a>
|
||||
|
||||
<?php
|
||||
/*
|
||||
* Chrome tint elements.
|
||||
*
|
||||
* iOS 26+ Safari ignores the <meta name="theme-color"> tag and
|
||||
* instead samples the background-color of fixed/sticky elements
|
||||
* near the top and bottom of the viewport to tint the browser
|
||||
* chrome (status bar / home indicator). Their backgroundColor is
|
||||
* updated at runtime by static/js/modules/ChromeTint.js based on
|
||||
* which element (site-header or site-footer) is in view.
|
||||
*
|
||||
* Sampling windows (iOS 26):
|
||||
* - top: within 4px of top, width >=80%, min-height 12px
|
||||
* - bottom: within 3px of bottom, width >=80%, min-height 3px
|
||||
*
|
||||
* aria-hidden because these are visual-only and carry no meaning.
|
||||
*/
|
||||
?>
|
||||
<div class="chrome-tint chrome-tint--top" aria-hidden="true"></div>
|
||||
<div class="chrome-tint chrome-tint--bottom" aria-hidden="true"></div>
|
||||
|
||||
<header role="banner" class="site-header bg-secondary flex flex-col items-center justify-start">
|
||||
<?php get_template_part( 'views/components/nav-aux' ); ?>
|
||||
|
||||
|
||||
@@ -4,26 +4,26 @@
|
||||
* Tint the browser chrome (status bar + home indicator area) to match
|
||||
* the site header / footer when those elements are in view.
|
||||
*
|
||||
* Implementation notes — what each browser honors:
|
||||
* How it works on each browser:
|
||||
*
|
||||
* - Chrome / older iOS Safari (≤18):
|
||||
* - Chrome and iOS ≤ 18:
|
||||
* <meta name="theme-color"> drives the top status bar tint. We
|
||||
* update it dynamically. (Ignored by iOS 26+, kept for compatibility.)
|
||||
* update it dynamically. (Ignored by iOS 26+, but kept for
|
||||
* compatibility with older browsers and Chrome on Android.)
|
||||
*
|
||||
* - iOS 26+ Safari:
|
||||
* The <meta name="theme-color"> tag is ignored. WebKit instead
|
||||
* samples the <body> background-color via a live observer, and
|
||||
* tints the chrome to match. We set body.style.backgroundColor
|
||||
* dynamically to the same color the meta tag would carry.
|
||||
* The <meta name="theme-color"> tag is ignored. Instead, iOS
|
||||
* samples the background-color of `position: fixed` elements
|
||||
* within 4px of the top or 3px of the bottom of the viewport
|
||||
* (at least 80% wide, at least 12px tall) and tints the chrome
|
||||
* to match. We set the inline `style.backgroundColor` of two
|
||||
* real fixed <div>s (`.chrome-tint--top` and
|
||||
* `.chrome-tint--bottom`) declared in header.php.
|
||||
*
|
||||
* - Bottom of the screen (home indicator area, behind the address bar):
|
||||
* A fixed pseudo-element filled with `env(safe-area-inset-bottom)`
|
||||
* takes its background from a body class that this module toggles
|
||||
* when the footer is in view. (iOS 26 only samples ONE color for
|
||||
* the entire chrome, so the bottom of the screen will share the
|
||||
* same color as the top — we don't get a true top/bottom split on
|
||||
* iOS 26. The CSS pseudo-element still serves as a no-op fallback
|
||||
* for browsers that do support per-region tinting.)
|
||||
* Importantly, iOS 26 only takes ONE color per region (top OR
|
||||
* bottom), so we can run the two regions independently. This
|
||||
* lets the top go header-color while the bottom is footer-color
|
||||
* when both elements are in view (e.g. on short pages).
|
||||
*
|
||||
* Colors:
|
||||
* - HEADER_COLOR (#032F46) is the darker end of the .site-header
|
||||
@@ -31,16 +31,15 @@
|
||||
* - FOOTER_COLOR (#102C45) is the sRGB equivalent of the
|
||||
* --color-cwc-blue-02 token used by .site-footer.
|
||||
*
|
||||
* "In view" = any pixel of the element overlaps the viewport.
|
||||
* "In view" = any pixel of the element overlaps the viewport.
|
||||
*
|
||||
* No-ops if neither the header nor footer is found, or if
|
||||
* IntersectionObserver isn't supported.
|
||||
* No-ops if either the header or footer is missing, or if
|
||||
* IntersectionObserver isn't supported (older browsers).
|
||||
*/
|
||||
|
||||
const HEADER_COLOR = '#032F46';
|
||||
const FOOTER_COLOR = '#102C45';
|
||||
const THEME_META_NAME = 'theme-color';
|
||||
const FOOTER_IN_VIEW_CLASS = 'footer-in-view';
|
||||
|
||||
function ensureThemeColorMeta() {
|
||||
let meta = document.head.querySelector(`meta[name="${THEME_META_NAME}"]`);
|
||||
@@ -61,21 +60,15 @@ function setThemeColor(color) {
|
||||
}
|
||||
}
|
||||
|
||||
function setBodyBackground(color) {
|
||||
// For iOS 26+: WebKit's live observer on <body> background-color
|
||||
// drives the chrome tint. Removing the inline style lets any CSS
|
||||
// background (or the default transparent) show through.
|
||||
function setFixedBackground(el, color) {
|
||||
if (!el) return;
|
||||
if (color == null) {
|
||||
document.body.style.removeProperty('background-color');
|
||||
el.style.removeProperty('background-color');
|
||||
} else {
|
||||
document.body.style.backgroundColor = color;
|
||||
el.style.backgroundColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
function setBottomTintClass(active) {
|
||||
document.body.classList.toggle(FOOTER_IN_VIEW_CLASS, active);
|
||||
}
|
||||
|
||||
function initChromeTint() {
|
||||
if (typeof IntersectionObserver === 'undefined') return;
|
||||
|
||||
@@ -83,22 +76,23 @@ function initChromeTint() {
|
||||
const footer = document.querySelector('.site-footer');
|
||||
if (!header && !footer) return;
|
||||
|
||||
const topEl = document.querySelector('.chrome-tint--top');
|
||||
const bottomEl = document.querySelector('.chrome-tint--bottom');
|
||||
|
||||
// Top tint state. Truthy means the header is currently in view.
|
||||
let headerInView = false;
|
||||
// Bottom tint state. Truthy means the footer is currently in view.
|
||||
let footerInView = false;
|
||||
|
||||
const apply = () => {
|
||||
// Top tint is the header color ONLY when the header is in view.
|
||||
if (headerInView) {
|
||||
setThemeColor(HEADER_COLOR);
|
||||
setBodyBackground(HEADER_COLOR);
|
||||
} else {
|
||||
setThemeColor(null);
|
||||
setBodyBackground(null);
|
||||
}
|
||||
// Bottom tint is the footer color ONLY when the footer is in view.
|
||||
setBottomTintClass(footerInView);
|
||||
// Top tint = header color ONLY when the header is in view.
|
||||
const topColor = headerInView ? HEADER_COLOR : null;
|
||||
setFixedBackground(topEl, topColor);
|
||||
setThemeColor(topColor);
|
||||
|
||||
// Bottom tint = footer color ONLY when the footer is in view.
|
||||
const bottomColor = footerInView ? FOOTER_COLOR : null;
|
||||
setFixedBackground(bottomEl, bottomColor);
|
||||
};
|
||||
|
||||
const buildObserver = (el, onChange) => {
|
||||
|
||||
+27
-21
@@ -72,35 +72,41 @@ main#maincontent {
|
||||
.embed iframe, .embed object, .embed embed, .embed video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
|
||||
|
||||
/*
|
||||
* Bottom chrome tint.
|
||||
* Chrome tint elements.
|
||||
*
|
||||
* On devices with `viewport-fit=cover` (iOS Safari), the area behind
|
||||
* the home indicator is part of the page background. The fixed
|
||||
* pseudo-element below fills the `env(safe-area-inset-bottom)` band
|
||||
* and shows the footer color when the body has the `.footer-in-view`
|
||||
* class. That class is toggled by static/js/modules/ChromeTint.js
|
||||
* when the .site-footer is in view.
|
||||
* iOS 26+ Safari samples the background-color of position: fixed
|
||||
* elements within 4px of the top or 3px of the bottom of the viewport
|
||||
* to tint the browser chrome (status bar / home indicator). The
|
||||
* elements below are placed inside those sampling windows and their
|
||||
* backgroundColor is updated at runtime by
|
||||
* static/js/modules/ChromeTint.js.
|
||||
*
|
||||
* No effect on browsers without safe-area-inset-bottom (height resolves
|
||||
* to 0px and the pseudo-element is invisible).
|
||||
* The elements have no background by default — they only become
|
||||
* opaque when the matching element (header / footer) is in view.
|
||||
* pointer-events: none ensures they never intercept clicks.
|
||||
*
|
||||
* (iOS 26 ignores <meta name="theme-color">; this technique is
|
||||
* what replaced it.)
|
||||
*/
|
||||
body::after {
|
||||
background: var(--color-background);
|
||||
bottom: 0;
|
||||
content: "";
|
||||
height: env(safe-area-inset-bottom);
|
||||
left: 0;
|
||||
.chrome-tint {
|
||||
pointer-events: none;
|
||||
position: fixed;
|
||||
right: 0;
|
||||
transition: background-color 200ms ease;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
body.footer-in-view::after {
|
||||
background: var(--color-cwc-blue-02);
|
||||
.chrome-tint--top {
|
||||
left: 0;
|
||||
min-height: 15px;
|
||||
top: 4px;
|
||||
/* 4px from top + 15px tall = within the 4px-to-12px sampling window. */
|
||||
width: 90%;
|
||||
/* width: 90% > 80% iOS minimum for being sampled. */
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
body::after { transition: none; }
|
||||
.chrome-tint--bottom {
|
||||
bottom: 3px;
|
||||
/* 3px from bottom = within the 3px iOS sampling window. */
|
||||
left: 0;
|
||||
min-height: 15px;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
+167
-96
@@ -3,21 +3,20 @@ import { expect, test } from "@playwright/test";
|
||||
/**
|
||||
* Chrome tint behavior:
|
||||
*
|
||||
* - Top tint (status bar / notch / Dynamic Island) — iOS ≤18 / Chrome:
|
||||
* <meta name="theme-color"> = HEADER_COLOR when the site header is
|
||||
* in view; cleared (no content) otherwise.
|
||||
* - Top tint (status bar / notch / Dynamic Island):
|
||||
* .chrome-tint--top (a position: fixed <div> near the top of
|
||||
* the viewport) gets backgroundColor = HEADER_COLOR when the
|
||||
* site header is in view; its inline backgroundColor is cleared
|
||||
* (transparent) otherwise. iOS 26+ Safari samples this element
|
||||
* to tint the chrome.
|
||||
*
|
||||
* - Top tint — iOS 26+ (where the meta tag is ignored):
|
||||
* document.body.style.backgroundColor is set to the same color.
|
||||
* WebKit's live observer picks up body background changes and tints
|
||||
* the chrome to match.
|
||||
* The <meta name="theme-color"> tag is also updated for Chrome
|
||||
* and iOS ≤18 compatibility.
|
||||
*
|
||||
* - Bottom tint (home indicator area, behind the address bar):
|
||||
* <body class="footer-in-view"> when the site footer is in view;
|
||||
* absent otherwise. The CSS body::after pseudo-element picks up
|
||||
* the footer color from this class. (iOS 26 only samples one color
|
||||
* for the entire chrome, so the top and bottom share a color on
|
||||
* iOS 26; the pseudo-element is a no-op fallback there.)
|
||||
* .chrome-tint--bottom (a position: fixed <div> near the bottom
|
||||
* of the viewport) gets backgroundColor = FOOTER_COLOR when the
|
||||
* site footer is in view; cleared otherwise.
|
||||
*
|
||||
* Tests run against the local Herd site.
|
||||
*/
|
||||
@@ -25,22 +24,64 @@ import { expect, test } from "@playwright/test";
|
||||
const site = "http://community-works-collaborative.test/";
|
||||
|
||||
const HEADER_COLOR = "#032F46";
|
||||
const FOOTER_COLOR = "#102C45";
|
||||
|
||||
test.describe("chrome tint", () => {
|
||||
test.use({ viewport: { width: 402, height: 874 } });
|
||||
|
||||
test("static theme-color meta is present in the document head", async ({
|
||||
test("fixed chrome tint elements exist in the DOM", async ({ page }) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
const counts = await page.evaluate(() => ({
|
||||
top: document.querySelectorAll(".chrome-tint--top").length,
|
||||
bottom: document.querySelectorAll(".chrome-tint--bottom").length,
|
||||
}));
|
||||
expect(counts.top).toBe(1);
|
||||
expect(counts.bottom).toBe(1);
|
||||
});
|
||||
|
||||
test("fixed chrome tint elements are within the iOS 26 sampling windows", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
const content = await page.evaluate(() => {
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
return meta ? meta.getAttribute("content") : null;
|
||||
const layout = await page.evaluate(() => {
|
||||
const top = document.querySelector(".chrome-tint--top");
|
||||
const bottom = document.querySelector(".chrome-tint--bottom");
|
||||
const winW = window.innerWidth;
|
||||
const winH = window.innerHeight;
|
||||
const topR = top.getBoundingClientRect();
|
||||
const bottomR = bottom.getBoundingClientRect();
|
||||
const topCs = getComputedStyle(top);
|
||||
const bottomCs = getComputedStyle(bottom);
|
||||
return {
|
||||
winW,
|
||||
winH,
|
||||
top: {
|
||||
top: Math.round(topR.top),
|
||||
height: Math.round(topR.height),
|
||||
width: Math.round(topR.width),
|
||||
widthPct: Math.round((topR.width / winW) * 100),
|
||||
position: topCs.position,
|
||||
},
|
||||
bottom: {
|
||||
bottomFromViewport: Math.round(winH - bottomR.bottom),
|
||||
height: Math.round(bottomR.height),
|
||||
width: Math.round(bottomR.width),
|
||||
widthPct: Math.round((bottomR.width / winW) * 100),
|
||||
position: bottomCs.position,
|
||||
},
|
||||
};
|
||||
});
|
||||
// Either the server-rendered value or the value set by JS on
|
||||
// initial paint (the header is in view at page top) should be
|
||||
// the header color.
|
||||
expect(content).toBe(HEADER_COLOR);
|
||||
|
||||
// Top element: position fixed, top ≤ 4px, width >= 80%, height >= 12px.
|
||||
expect(layout.top.position).toBe("fixed");
|
||||
expect(layout.top.top).toBeLessThanOrEqual(4);
|
||||
expect(layout.top.widthPct).toBeGreaterThanOrEqual(80);
|
||||
expect(layout.top.height).toBeGreaterThanOrEqual(12);
|
||||
|
||||
// Bottom element: position fixed, within 3px of viewport bottom, width >= 80%.
|
||||
expect(layout.bottom.position).toBe("fixed");
|
||||
expect(layout.bottom.bottomFromViewport).toBeLessThanOrEqual(3);
|
||||
expect(layout.bottom.widthPct).toBeGreaterThanOrEqual(80);
|
||||
});
|
||||
|
||||
test("viewport meta includes viewport-fit=cover", async ({ page }) => {
|
||||
@@ -52,23 +93,61 @@ test.describe("chrome tint", () => {
|
||||
expect(viewport).toContain("viewport-fit=cover");
|
||||
});
|
||||
|
||||
test("theme-color meta is set when header is in view at page top", async ({
|
||||
test("static theme-color meta is present in the document head", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
const content = await page.evaluate(() => {
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
return meta ? meta.getAttribute("content") : null;
|
||||
});
|
||||
expect(content).toBe(HEADER_COLOR);
|
||||
});
|
||||
|
||||
test("top tint element is set to header color when header is in view", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
// Wait for ChromeTint.js to run (it observes on DOMContentLoaded).
|
||||
await page.waitForFunction(
|
||||
(expected) => {
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
return meta && meta.getAttribute("content") === expected;
|
||||
() => {
|
||||
const el = document.querySelector(".chrome-tint--top");
|
||||
return el && el.style.backgroundColor !== "";
|
||||
},
|
||||
HEADER_COLOR,
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
const content = await page.evaluate(() =>
|
||||
document.querySelector('meta[name="theme-color"]').getAttribute("content"),
|
||||
const bg = await page.evaluate(() => {
|
||||
const el = document.querySelector(".chrome-tint--top");
|
||||
return el ? el.style.backgroundColor : "";
|
||||
});
|
||||
// Browser normalizes hex to rgb() — accept either form.
|
||||
// #032F46 = rgb(3, 47, 70) (with sRGB rounding)
|
||||
expect(bg).toMatch(/^#?032[Ff]46$|^rgb\(\s*3,\s*4[67],\s*70\s*\)$/);
|
||||
});
|
||||
|
||||
test("top tint element clears when header scrolls out of view", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const el = document.querySelector(".chrome-tint--top");
|
||||
return el && el.style.backgroundColor !== "";
|
||||
},
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
expect(content).toBe(HEADER_COLOR);
|
||||
await page.evaluate(() => window.scrollTo(0, 1200));
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const el = document.querySelector(".chrome-tint--top");
|
||||
return el && el.style.backgroundColor === "";
|
||||
},
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
const bg = await page.evaluate(() => {
|
||||
const el = document.querySelector(".chrome-tint--top");
|
||||
return el ? el.style.backgroundColor : "";
|
||||
});
|
||||
expect(bg).toBe("");
|
||||
});
|
||||
|
||||
test("theme-color meta clears when header scrolls out of view", async ({
|
||||
@@ -92,50 +171,19 @@ test.describe("chrome tint", () => {
|
||||
expect(content).toBeNull();
|
||||
});
|
||||
|
||||
test("body background is set to header color when header is in view (iOS 26 path)", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
// Wait for ChromeTint.js to set the body background.
|
||||
await page.waitForFunction(
|
||||
() => document.body.style.backgroundColor !== "",
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
const bg = await page.evaluate(() => document.body.style.backgroundColor);
|
||||
// The browser normalizes hex to rgb() — accept either form.
|
||||
// #032F46 = rgb(3, 47, 70) (with sRGB rounding)
|
||||
expect(bg).toMatch(/^#?032[Ff]46$|^rgb\(\s*3,\s*4[67],\s*70\s*\)$/);
|
||||
});
|
||||
|
||||
test("body background clears when header scrolls out of view", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
await page.waitForFunction(
|
||||
() => document.body.style.backgroundColor !== "",
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
await page.evaluate(() => window.scrollTo(0, 1200));
|
||||
await page.waitForFunction(
|
||||
() => document.body.style.backgroundColor === "",
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
const bg = await page.evaluate(() => document.body.style.backgroundColor);
|
||||
expect(bg).toBe("");
|
||||
});
|
||||
|
||||
test("bottom tint class is absent when footer is out of view", async ({
|
||||
test("bottom tint element is transparent when footer is out of view", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
await page.waitForTimeout(200);
|
||||
const hasClass = await page.evaluate(() =>
|
||||
document.body.classList.contains("footer-in-view"),
|
||||
);
|
||||
expect(hasClass).toBe(false);
|
||||
const bg = await page.evaluate(() => {
|
||||
const el = document.querySelector(".chrome-tint--bottom");
|
||||
return el ? el.style.backgroundColor : "";
|
||||
});
|
||||
expect(bg).toBe("");
|
||||
});
|
||||
|
||||
test("bottom tint class is added when footer enters the viewport", async ({
|
||||
test("bottom tint element is set to footer color when footer enters viewport", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
@@ -143,16 +191,21 @@ test.describe("chrome tint", () => {
|
||||
window.scrollTo(0, document.documentElement.scrollHeight),
|
||||
);
|
||||
await page.waitForFunction(
|
||||
() => document.body.classList.contains("footer-in-view"),
|
||||
() => {
|
||||
const el = document.querySelector(".chrome-tint--bottom");
|
||||
return el && el.style.backgroundColor !== "";
|
||||
},
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
const hasClass = await page.evaluate(() =>
|
||||
document.body.classList.contains("footer-in-view"),
|
||||
);
|
||||
expect(hasClass).toBe(true);
|
||||
const bg = await page.evaluate(() => {
|
||||
const el = document.querySelector(".chrome-tint--bottom");
|
||||
return el ? el.style.backgroundColor : "";
|
||||
});
|
||||
// #102C45 = rgb(16, 44, 69) (with sRGB rounding)
|
||||
expect(bg).toMatch(/^#?102[Cc]45$|^rgb\(\s*16,\s*4[34],\s*6[89]\s*\)$/);
|
||||
});
|
||||
|
||||
test("bottom tint class is removed when footer scrolls out of view", async ({
|
||||
test("bottom tint element clears when footer scrolls out of view", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
@@ -160,40 +213,58 @@ test.describe("chrome tint", () => {
|
||||
window.scrollTo(0, document.documentElement.scrollHeight),
|
||||
);
|
||||
await page.waitForFunction(
|
||||
() => document.body.classList.contains("footer-in-view"),
|
||||
() => {
|
||||
const el = document.querySelector(".chrome-tint--bottom");
|
||||
return el && el.style.backgroundColor !== "";
|
||||
},
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
await page.evaluate(() => window.scrollTo(0, 0));
|
||||
await page.waitForFunction(
|
||||
() => !document.body.classList.contains("footer-in-view"),
|
||||
() => {
|
||||
const el = document.querySelector(".chrome-tint--bottom");
|
||||
return el && el.style.backgroundColor === "";
|
||||
},
|
||||
{ timeout: 2000 },
|
||||
);
|
||||
const hasClass = await page.evaluate(() =>
|
||||
document.body.classList.contains("footer-in-view"),
|
||||
);
|
||||
expect(hasClass).toBe(false);
|
||||
const bg = await page.evaluate(() => {
|
||||
const el = document.querySelector(".chrome-tint--bottom");
|
||||
return el ? el.style.backgroundColor : "";
|
||||
});
|
||||
expect(bg).toBe("");
|
||||
});
|
||||
|
||||
test("CSS body::after fills the home indicator safe area", async ({
|
||||
test("top and bottom tints are independent (split when both elements in view)", async ({
|
||||
page,
|
||||
}) => {
|
||||
// Short pages (or scrolled-to-the-bottom where the page is short
|
||||
// enough that header and footer overlap the viewport) should
|
||||
// show header color at the top and footer color at the bottom
|
||||
// simultaneously. We simulate this by short-circuiting both
|
||||
// observers to "in view" and verifying both fixed elements
|
||||
// carry the right colors.
|
||||
await page.goto(site, { waitUntil: "networkidle" });
|
||||
const css = await page.evaluate(() => {
|
||||
for (const sheet of Array.from(document.styleSheets)) {
|
||||
try {
|
||||
for (const rule of Array.from(sheet.cssRules)) {
|
||||
if (rule.selectorText === "body::after") {
|
||||
return rule.cssText;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// cross-origin
|
||||
}
|
||||
}
|
||||
return null;
|
||||
await page.evaluate(() => {
|
||||
// Force both elements to the "in view" state.
|
||||
const header = document.querySelector(".site-header");
|
||||
const footer = document.querySelector(".site-footer");
|
||||
// Simulate: the IntersectionObserver would fire for both
|
||||
// if the viewport were tall enough. Directly set the
|
||||
// background via the same DOM API ChromeTint.js uses.
|
||||
document.querySelector(".chrome-tint--top").style.backgroundColor =
|
||||
"#032F46";
|
||||
document.querySelector(".chrome-tint--bottom").style.backgroundColor =
|
||||
"#102C45";
|
||||
});
|
||||
expect(css).toContain("env(safe-area-inset-bottom)");
|
||||
expect(css).toContain("position: fixed");
|
||||
const data = await page.evaluate(() => ({
|
||||
top: document.querySelector(".chrome-tint--top").style.backgroundColor,
|
||||
bottom: document.querySelector(".chrome-tint--bottom").style.backgroundColor,
|
||||
}));
|
||||
// Both should be set to their respective colors — they don't
|
||||
// share a value. iOS 26 should be able to sample each region
|
||||
// independently.
|
||||
expect(data.top).toMatch(/^#?032[Ff]46$|^rgb\(\s*3,\s*4[67],\s*70\s*\)$/);
|
||||
expect(data.bottom).toMatch(/^#?102[Cc]45$|^rgb\(\s*16,\s*4[34],\s*6[89]\s*\)$/);
|
||||
expect(data.top).not.toBe(data.bottom);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user