33// (motion-signature.browser.test.ts) mocks getComputedStyle, so it asserts the
44// classifier's control flow against a fake; this suite asserts the same
55// branches against the platform — Blink's attr() substitution in computed
6- // pseudo content, unsubstituted counter(), display:none subtrees, clip-path,
6+ // pseudo content, unsubstituted counter(), display:none and
7+ // content-visibility:hidden subtrees, opt-outs on a measured scope, clip-path,
78// and form control state — using the exact scripts `hyperframes check` injects.
8- // Skipped when no Chrome/Chromium binary is available without downloading.
9+ // Skipped when no Chrome/Chromium binary is available without downloading. On
10+ // Windows the suite is opt-in (HYPERFRAMES_BROWSER_TESTS=1): in the shared
11+ // Windows package test lane the launch of the runner's Chrome did not complete
12+ // within the package hookTimeout (cause not established; no other suite in this
13+ // package launches a browser), and the suite already runs on Linux CI, where
14+ // the runner's Chrome is found as a system browser.
915import { existsSync , readFileSync } from "node:fs" ;
1016import { dirname , join } from "node:path" ;
1117import { fileURLToPath } from "node:url" ;
@@ -26,6 +32,12 @@ function resolveExecutable(): string | undefined {
2632}
2733
2834const executablePath = resolveExecutable ( ) ;
35+ const RUNS_CHROMIUM =
36+ ! ! executablePath &&
37+ ( process . platform !== "win32" || process . env . HYPERFRAMES_BROWSER_TESTS === "1" ) ;
38+ // The package hookTimeout is sized for cold module imports, not for launching
39+ // a browser; give the launch its own ceiling.
40+ const BROWSER_LAUNCH_TIMEOUT_MS = 120_000 ;
2941
3042interface Samples {
3143 sweep : string ;
@@ -52,7 +64,7 @@ function composition(css: string, body: string): string {
5264 </body></html>` ;
5365}
5466
55- describe . skipIf ( ! executablePath ) ( "motion-signature.browser in Chromium" , ( ) => {
67+ describe . skipIf ( ! RUNS_CHROMIUM ) ( "motion-signature.browser in Chromium" , ( ) => {
5668 let browser : Browser ;
5769 let page : Page ;
5870
@@ -65,7 +77,7 @@ describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => {
6577 } ) ;
6678 page = await browser . newPage ( ) ;
6779 await page . setViewport ( { width : 640 , height : 360 } ) ;
68- } ) ;
80+ } , BROWSER_LAUNCH_TIMEOUT_MS ) ;
6981
7082 afterAll ( async ( ) => {
7183 await browser ?. close ( ) ;
@@ -77,11 +89,17 @@ describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => {
7789 await page . addScriptTag ( { content : motionSampleScript } ) ;
7890 }
7991
80- async function sample ( ) : Promise < Samples > {
81- return page . evaluate ( ( ) => ( {
82- sweep : window . __hyperframesLayoutGeometry ( ) ,
83- liveness : window . __hyperframesMotionSample ( { livenessScopes : [ "*" ] } ) . liveness [ "*" ] ?? "" ,
84- } ) ) ;
92+ async function sample ( scope = "*" ) : Promise < Samples > {
93+ return page . evaluate (
94+ ( livenessScope ) => ( {
95+ sweep : window . __hyperframesLayoutGeometry ( ) ,
96+ liveness :
97+ window . __hyperframesMotionSample ( { livenessScopes : [ livenessScope ] } ) . liveness [
98+ livenessScope
99+ ] ?? "" ,
100+ } ) ,
101+ scope ,
102+ ) ;
85103 }
86104
87105 async function mutate ( script : string ) : Promise < void > {
@@ -381,4 +399,164 @@ describe.skipIf(!executablePath)("motion-signature.browser in Chromium", () => {
381399
382400 expect ( after ) . toEqual ( before ) ;
383401 } ) ;
402+
403+ // A keepsMoving scope names the element explicitly, so the layout-audit
404+ // opt-out on the scope itself does not empty its signature (which the Node
405+ // side would otherwise report as motion_selector_missing for an element that
406+ // exists). Opt-outs INSIDE the scope still apply.
407+ it ( "measures a keepsMoving scope that is itself data-layout-ignore, but not opted-out layers inside it" , async ( ) => {
408+ await load (
409+ composition (
410+ "#scene { position: absolute; width: 300px; height: 200px; } #logo, #glow { position: absolute; width: 50px; height: 50px; background: #00f; }" ,
411+ '<div id="scene" data-layout-ignore><div id="logo"></div><div id="glow" data-layout-ignore></div></div>' ,
412+ ) ,
413+ ) ;
414+ const before = await sample ( "#scene" ) ;
415+ expect ( before . liveness ) . not . toBe ( "" ) ;
416+ await mutate ( 'document.getElementById("glow").style.left = "100px"' ) ;
417+ const afterIgnoredMove = await sample ( "#scene" ) ;
418+ await mutate ( 'document.getElementById("logo").style.left = "100px"' ) ;
419+ const afterMove = await sample ( "#scene" ) ;
420+
421+ expect ( afterIgnoredMove . liveness ) . toBe ( before . liveness ) ;
422+ expect ( afterMove . liveness ) . not . toBe ( before . liveness ) ;
423+ } ) ;
424+
425+ it ( "ignores text mutations inside content-visibility:hidden contents" , async ( ) => {
426+ await load (
427+ composition (
428+ "#wrap { content-visibility: hidden; }" ,
429+ '<div id="wrap"><span id="skipped" class="fixed">10</span></div><span class="fixed">10</span>' ,
430+ ) ,
431+ ) ;
432+ const before = await sample ( ) ;
433+ await mutate ( 'document.getElementById("skipped").textContent = "09"' ) ;
434+ const after = await sample ( ) ;
435+
436+ expect ( after ) . toEqual ( before ) ;
437+ } ) ;
438+
439+ it ( "ignores a decoy counter owner inside content-visibility:hidden contents" , async ( ) => {
440+ await load (
441+ composition (
442+ "#wrap { content-visibility: hidden; } #decoy { counter-reset: countdown 10; } #countdown::after { content: counter(countdown); }" ,
443+ '<div id="wrap"><div id="decoy"></div></div><span id="countdown" class="fixed"></span>' ,
444+ ) ,
445+ ) ;
446+ const before = await sample ( ) ;
447+ await mutate ( 'document.getElementById("decoy").style.counterReset = "countdown 9"' ) ;
448+ const after = await sample ( ) ;
449+
450+ expect ( after ) . toEqual ( before ) ;
451+ } ) ;
452+
453+ it ( "ignores a decoy counter owner inside off-screen content-visibility:auto contents" , async ( ) => {
454+ await load (
455+ composition (
456+ "#far { content-visibility: auto; position: absolute; top: 5000px; width: 10px; height: 10px; } #decoy { counter-reset: countdown 10; } #countdown::after { content: counter(countdown); }" ,
457+ '<div id="far"><div id="decoy"></div></div><span id="countdown" class="fixed"></span>' ,
458+ ) ,
459+ ) ;
460+ const before = await sample ( ) ;
461+ await mutate ( 'document.getElementById("decoy").style.counterReset = "countdown 9"' ) ;
462+ const after = await sample ( ) ;
463+
464+ expect ( after ) . toEqual ( before ) ;
465+ } ) ;
466+
467+ it ( "ignores a repaint of a canvas whose contents are skipped by content-visibility:hidden" , async ( ) => {
468+ await load (
469+ composition (
470+ "#c { content-visibility: hidden; width: 100px; height: 100px; }" ,
471+ '<canvas id="c" width="100" height="100"></canvas>' ,
472+ ) ,
473+ ) ;
474+ const before = await sample ( ) ;
475+ await mutate (
476+ 'const ctx = document.getElementById("c").getContext("2d"); ctx.fillStyle = "#f00"; ctx.fillRect(0, 0, 100, 100);' ,
477+ ) ;
478+ const after = await sample ( ) ;
479+
480+ expect ( after ) . toEqual ( before ) ;
481+ } ) ;
482+
483+ // content-visibility only skips contents where size containment applies; on
484+ // a non-atomic inline host it is a no-op and everything inside still paints.
485+ it ( "keeps signing text and pseudo content inside an inline content-visibility:hidden host" , async ( ) => {
486+ await load (
487+ composition (
488+ "#host { content-visibility: hidden; } #host::after { content: attr(data-txt); }" ,
489+ '<span id="host" data-txt="10"><span id="kid" class="fixed">10</span></span>' ,
490+ ) ,
491+ ) ;
492+ const start = await sample ( ) ;
493+ await mutate ( 'document.getElementById("kid").textContent = "09"' ) ;
494+ const afterText = await sample ( ) ;
495+ await mutate ( 'document.getElementById("host").setAttribute("data-txt", "09")' ) ;
496+ const afterPseudo = await sample ( ) ;
497+
498+ expect ( afterText . sweep ) . not . toBe ( start . sweep ) ;
499+ expect ( afterText . liveness ) . not . toBe ( start . liveness ) ;
500+ expect ( afterPseudo . sweep ) . not . toBe ( afterText . sweep ) ;
501+ } ) ;
502+
503+ it ( "sees a checkbox toggle on a content-visibility:hidden control" , async ( ) => {
504+ await load (
505+ composition (
506+ "#toggle { content-visibility: hidden; width: 24px; height: 24px; }" ,
507+ '<input id="toggle" type="checkbox" />' ,
508+ ) ,
509+ ) ;
510+ const before = await sample ( ) ;
511+ await mutate ( 'document.getElementById("toggle").checked = true' ) ;
512+ const after = await sample ( ) ;
513+
514+ expect ( after . sweep ) . not . toBe ( before . sweep ) ;
515+ } ) ;
516+
517+ it ( "ignores a value change on a text input whose contents are skipped by content-visibility:hidden" , async ( ) => {
518+ await load (
519+ composition (
520+ "#note { content-visibility: hidden; width: 120px; height: 40px; font: 24px monospace; }" ,
521+ '<input id="note" value="10" />' ,
522+ ) ,
523+ ) ;
524+ const before = await sample ( ) ;
525+ await mutate ( 'document.getElementById("note").value = "09"' ) ;
526+ const after = await sample ( ) ;
527+
528+ expect ( after ) . toEqual ( before ) ;
529+ } ) ;
530+
531+ it ( "sees a counter painted only by a display:contents host's pseudo-element" , async ( ) => {
532+ await load (
533+ composition (
534+ "body { counter-reset: countdown 10; } #host { display: contents; } #host::after { content: counter(countdown); font: 32px/48px monospace; }" ,
535+ '<div id="host"></div>' ,
536+ ) ,
537+ ) ;
538+ const before = await sample ( ) ;
539+ await mutate ( 'document.body.style.counterReset = "countdown 9"' ) ;
540+ const after = await sample ( ) ;
541+
542+ expect ( after . sweep ) . not . toBe ( before . sweep ) ;
543+ } ) ;
544+
545+ it ( "ignores a content-visibility:hidden host's own text and pseudo content but still sees its box move" , async ( ) => {
546+ await load (
547+ composition (
548+ "#host { content-visibility: hidden; position: absolute; width: 80px; height: 48px; background: #f00; } #host::after { content: attr(data-txt); }" ,
549+ '<div id="host" data-txt="10">10</div>' ,
550+ ) ,
551+ ) ;
552+ const start = await sample ( ) ;
553+ await mutate ( 'document.getElementById("host").firstChild.textContent = "09"' ) ;
554+ await mutate ( 'document.getElementById("host").setAttribute("data-txt", "09")' ) ;
555+ const afterContents = await sample ( ) ;
556+ await mutate ( 'document.getElementById("host").style.left = "100px"' ) ;
557+ const afterMove = await sample ( ) ;
558+
559+ expect ( afterContents ) . toEqual ( start ) ;
560+ expect ( afterMove . sweep ) . not . toBe ( start . sweep ) ;
561+ } ) ;
384562} ) ;
0 commit comments