An open source design system that's fully customizable and agent ready
TypeScript
test(interaction-harness): judge an entrance from its first frame (#10572)
Christopher Chedeaued2fd36d6db7
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.mdindex 41f384802a..345bd8fa32 100644--- a/internal/interaction-harness/README.md+++ b/internal/interaction-harness/README.md@@ -248,6 +248,11 @@ set before the block is excused. Pass that position as `setBeforeBlock`, suchas the drag's last position at the release. An animation frozen at the block'sstart holds a position of its own, and is judged as a stall. Every frame afterits first change is judged, so a freeze later in the block still fails.+An element off screen before the block, such as a card that enters from an+edge, is judged from its first position inside the block. The cast's frames+before the block must show the screen without it. A main-thread entrance+shows no frame during the block, so it still fails. With no frame before the+block at all, nothing is known, and the block is judged from its start.Any other element already moving is judged from the block's start. WebKit'scasts are 2 px quantized: their JPEG frames hold themarker's color in 2 by 2 pixel chroma blocks (4:2:0, which the frame headerdiff --git a/internal/interaction-harness/src/busy.control.test.ts b/internal/interaction-harness/src/busy.control.test.tsindex eabcea69fb..1ec96a268a 100644--- a/internal/interaction-harness/src/busy.control.test.ts+++ b/internal/interaction-harness/src/busy.control.test.ts@@ -268,6 +268,21 @@ describe('busyWindowProof against a control', () => {expect(proof.control?.belowStep).toBeGreaterThan(0);});+ it('judges a component that enters from off screen from its first position inside the block, against the control', () => {+ // A card pushed in from an edge first shows 20 ms into the block. The+ // cast's frames before the block show the screen without it.+ const entering = moving().map(f =>+ f.t < 1020+ ? ({...f, box: null} as TrackedFrame)+ : ({...f, box: {...f.box!, y: f.box!.y - 60}} as TrackedFrame),+ );+ const proof = busyWindowProof(entering, BLOCK, {+ control: asControl(moving()),+ });+ expect(proof.verdict.failures, proof.summary).toEqual([]);+ expect(proof.onScreenFromMs).toBeGreaterThanOrEqual(20);+ });+it('fails a window in which the control itself presented too little to judge', () => {const still = asControl(moving().map(f => ({...f, box: {...f.box!, y: 0}}) as TrackedFrame),diff --git a/internal/interaction-harness/src/busy.test.ts b/internal/interaction-harness/src/busy.test.tsindex 0135cfa82b..b7f302fd11 100644--- a/internal/interaction-harness/src/busy.test.ts+++ b/internal/interaction-harness/src/busy.test.ts@@ -370,6 +370,40 @@ describe('busyWindowProof on-screen start', () => {expect(proof.verdict.failures.join('\n')).toMatch(/longest stall/);});+ it('judges an element that enters from off screen from its first position inside the block, and reports when', () => {+ // The cast's frames before the block show the screen without it.+ const entering = moving().map(f =>+ f.t < 1020+ ? ({...f, box: null} as TrackedFrame)+ : ({...f, box: {...f.box!, y: f.box!.y - 60}} as TrackedFrame),+ );+ const proof = busyWindowProof(entering, BLOCK);+ expect(proof.verdict.failures).toEqual([]);+ expect(proof.onScreenFromMs).toBeGreaterThanOrEqual(20);+ expect(proof.onScreenFromMs).toBeLessThan(20 + FRAME);+ expect(proof.summary).toMatch(/\(off screen before the block\)/);+ });++ it('still fails an entrance the main thread drives: off screen before the block, and no frame in it shows the element', () => {+ const blocked = moving().map(f =>+ f.t < 1720 ? ({...f, box: null} as TrackedFrame) : f,+ );+ const proof = busyWindowProof(blocked, BLOCK);+ expect(proof.onScreenFromMs).toBeNull();+ expect(proof.verdict.failures.join('\n')).toMatch(/no frame presented/);+ });++ it('still fails an entrance the block delays: too few frames inside it from the first position', () => {+ const late = moving().map(f =>+ f.t < 1640 ? ({...f, box: null} as TrackedFrame) : f,+ );+ const proof = busyWindowProof(late, BLOCK);+ expect(proof.onScreenFromMs).toBeGreaterThanOrEqual(640);+ expect(proof.verdict.failures.join('\n')).toMatch(+ /frames < 4: the animation under test was not moving/,+ );+ });+it('still fails a start the block itself delays until it ends', () => {const proof = busyWindowProof(startingAt(1720), BLOCK);expect(proof.onScreenFromMs).toBeNull();diff --git a/internal/interaction-harness/src/busy.ts b/internal/interaction-harness/src/busy.tsindex 93f4117e81..b1959a97aa 100644--- a/internal/interaction-harness/src/busy.ts+++ b/internal/interaction-harness/src/busy.ts@@ -841,6 +841,10 @@ function motionStepPx(values: readonly number[]): number {* at `setBeforeBlock`, the value the page itself last set before the block,* is excused. Every frame after that first change is judged, so a freeze* later in the block fails.+ * An element off screen before the judged part is judged from its first+ * position inside the part, as a card that enters from an edge. The cast's+ * frames before the part must show the screen without it. A main-thread+ * entrance shows no frame during the block, so it still fails.* The judged part still ends with the block and the `minJudgedFrames` floor* applies to it, so a start the block itself delays fails; any other* animation that was already moving is judged from the block's start, and a@@ -1141,12 +1145,28 @@ export function busyWindowProof(prior[holdStart].t < window.from &&heldFrames >= 2 &&Math.abs(lead[lead.length - 1] - setBeforeBlock) <= matchPx;+ // Off screen before the judged part, as a card that enters from an edge:+ // the cast's frames there show the screen without it. Its first position+ // inside the part is then its on-screen start, and judging starts there.+ // With no frame before at all, nothing is known. A main-thread entrance+ // shows no frame during the block, so it has no such position.+ const shownWithout = tracked.some(+ f =>+ f.box == null &&+ f.t < inner.from &&+ f.t >= inner.from - BUSY_PROOF_LOOKAROUND_MS,+ );+ const firstShown = values.find(v => v.value != null);+ const entersAt =+ prior.length === 0 && shownWithout && firstShown != null+ ? firstShown.t+ : null;const onScreenFrom =prior.length > 0 &&(!movedBefore || heldFromBeforeBlock) &&inWindow.length > 0? inWindow[0]- : null;+ : entersAt;const judged = {from: onScreenFrom ?? inner.from, to: inner.to};const changes = inWindow.filter(t => t > judged.from || onScreenFrom == null);const edges = [judged.from, ...changes, judged.to];@@ -1545,7 +1565,7 @@ export function busyWindowProof(: `, compositor presenting every ${compositorFrameMs.toFixed(1)} ms`) +(onScreenFromMs == null? ''- : `, on screen from +${onScreenFromMs.toFixed(0)} ms (nothing moved before the block)`) ++ : `, on screen from +${onScreenFromMs.toFixed(0)} ms (${entersAt == null ? 'nothing moved before the block' : 'off screen before the block'})`) +(controlRead == null? '': `; against the control: moved on ${controlRead.movedWith} of its ${controlRead.moved} frames${controlRead.belowStep > 0 ? ` (${controlRead.belowStep} where the cast could not show the step)` : ''}, its longest stall ${controlRead.longestStallMs.toFixed(1)} ms`) +