Skip to content

Commit 37b3c4f

Browse files
committed
test(interaction-harness): the busy self-tests hold up at 16 workers, waitForPresentedMotion tracks in one scratch page, and the within note says what was measured
At 16 workers the self-tests this pull request adds failed in three ways, each with its own cause: - The 1-in-6 cast cases blocked for 700 ms. On a runner presenting half the rate the control showed 3 frames there, under the four the verdict needs, so the rAF case failed on that floor instead of its stall. They now block for 1.4 s. - The backdrop case started its dim just before the block, and WebKit presented that just-started animation late, as a stall at the block's start (3 of 8). The dim now runs from the dialog's open, endless and wrapping. - waitForPresentedMotion's case asserted that the box passed 100 px, which a loaded cast had not yet shown when it stopped. It now asserts the three positions that two moves make. waitForPresentedMotion now tracks in one scratch page for the whole wait (`trackMarkerIn`, which `trackMarker` uses), instead of opening one per poll. With the dim running before the block, the top-layer control and `within` both passed 24 of 24 in WebKit at 16 workers. The 5 of 24 stalls first reported for the top-layer control came from the just-started dim, not from the top layer. `within` rests on C17's BottomSheet traces: under the top-layer control the dim held for 155 to 225 ms into a block while the control moved, and inside the dialog it moves in step with the sheet. The README and its note now say that. [skip ci]
1 parent b01b033 commit 37b3c4f

4 files changed

Lines changed: 180 additions & 146 deletions

File tree

‎internal/interaction-harness/README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ Lightbox's double-tap zoom, pinned to two cores, missed a display-rate bound in
164164
a proof against a control instead of a rate: `startBusyControl(page)` shows a
165165
small `CONTROL_RGB` box in the top layer (a manual popover, so above a modal
166166
dialog opened before it; `raise()` after one opened later) whose transform
167-
moves it along the top edge for as long as the page runs. In WebKit a popover
168-
above an open modal dialog takes the dialog's `::backdrop` animation off the
169-
compositor, so a proof of a backdrop mounts the control inside the dialog with
167+
moves it along the top edge for as long as the page runs. A proof of a
168+
dialog's backdrop mounts the control inside the dialog with
170169
`startBusyControl(page, {within: dialog})`, a plain fixed box with no top-layer
171-
entry. Track it from the
170+
entry: in WebKit, with the popover above BottomSheet's open modal dialog, the
171+
sheet's dim held for 155 to 225 ms into a block while the control moved, and
172+
inside the dialog it moves in step with the sheet. Track it from the
172173
same screencast (`trackMarker(page, frames, {rgb: CONTROL_RGB})`) and pass it
173174
as `control`: the component passes when it moved on every frame the control
174175
moved and its longest stall is no longer than the control's. Both are read from

‎internal/interaction-harness/src/busy.ts‎

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
frameStats,
2424
inPresentationOrder,
2525
MARKER_RGB,
26-
trackMarker,
26+
trackMarkerIn,
2727
type FrameStats,
2828
type Screencast,
2929
type TrackedFrame,
@@ -48,13 +48,14 @@ const CONTROL_TRAVEL = 240;
4848
* The box is a manual popover, so it shows in the top layer, above a modal
4949
* dialog the page opened before it; `raise()` shows it again on top of one
5050
* opened after. With `within`, it is mounted inside that element instead (an
51-
* open modal dialog), as a plain fixed box with no top-layer entry: in WebKit
52-
* a popover shown above an open modal dialog takes the dialog's `::backdrop`
53-
* animation off the compositor, so a proof of a dialog's backdrop mounts its
54-
* control inside the dialog. Start it before the block: it resolves once the
55-
* animation is running and past its first frame (on the compositor; see
56-
* `blockMainThread`). Keep the component's marker out of the strip it crosses
57-
* (the top `CONTROL_SIDE` px, `CONTROL_SIDE + CONTROL_TRAVEL` px wide).
51+
* open modal dialog), as a plain fixed box with no top-layer entry, for a
52+
* proof of the dialog's `::backdrop`: in WebKit, with the popover above
53+
* BottomSheet's open modal dialog, the sheet's dim held for 155 to 225 ms
54+
* into a block while the control moved. Start it before the block: it
55+
* resolves once the animation is running and past its first frame (on the
56+
* compositor; see `blockMainThread`). Keep the component's marker out of the
57+
* strip it crosses (the top `CONTROL_SIDE` px, `CONTROL_SIDE +
58+
* CONTROL_TRAVEL` px wide).
5859
*/
5960
export async function startBusyControl(
6061
page: Page,
@@ -162,37 +163,45 @@ export async function waitForPresentedMotion(
162163
} = {},
163164
): Promise<void> {
164165
const deadline = Date.now() + timeout;
165-
const seen: TrackedFrame[] = [];
166-
let read = 0;
167-
for (;;) {
168-
const captured = cast.framesSoFar();
169-
if (captured.length > read) {
170-
seen.push(...(await trackMarker(page, captured.slice(read), {rgb})));
171-
read = captured.length;
172-
const ordered = inPresentationOrder(seen);
173-
let moved = 0;
174-
for (let i = ordered.length - 1; i > 0; i -= 1) {
175-
const now = ordered[i].box;
176-
const before = ordered[i - 1].box;
177-
if (
178-
now == null ||
179-
before == null ||
180-
(now.x === before.x && now.y === before.y)
181-
) {
182-
break;
166+
// One scratch page for the whole wait: each poll would otherwise open one.
167+
const scratch = await page.context().newPage();
168+
try {
169+
const seen: TrackedFrame[] = [];
170+
let read = 0;
171+
for (;;) {
172+
const captured = cast.framesSoFar();
173+
if (captured.length > read) {
174+
seen.push(
175+
...(await trackMarkerIn(scratch, captured.slice(read), {rgb})),
176+
);
177+
read = captured.length;
178+
const ordered = inPresentationOrder(seen);
179+
let moved = 0;
180+
for (let i = ordered.length - 1; i > 0; i -= 1) {
181+
const now = ordered[i].box;
182+
const before = ordered[i - 1].box;
183+
if (
184+
now == null ||
185+
before == null ||
186+
(now.x === before.x && now.y === before.y)
187+
) {
188+
break;
189+
}
190+
moved += 1;
191+
}
192+
if (moved >= frames) {
193+
return;
183194
}
184-
moved += 1;
185195
}
186-
if (moved >= frames) {
187-
return;
196+
if (Date.now() > deadline) {
197+
throw new Error(
198+
`waitForPresentedMotion: the screencast did not present the element moving on ${frames} consecutive frames within ${timeout} ms`,
199+
);
188200
}
201+
await new Promise(resolve => setTimeout(resolve, 16));
189202
}
190-
if (Date.now() > deadline) {
191-
throw new Error(
192-
`waitForPresentedMotion: the screencast did not present the element moving on ${frames} consecutive frames within ${timeout} ms`,
193-
);
194-
}
195-
await new Promise(resolve => setTimeout(resolve, 16));
203+
} finally {
204+
await scratch.close();
196205
}
197206
}
198207

‎internal/interaction-harness/src/frames.ts‎

Lines changed: 99 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -308,103 +308,115 @@ export interface TrackedFrame {
308308
export async function trackMarker(
309309
page: Page,
310310
frames: readonly CastFrame[],
311+
options: {rgb?: readonly [number, number, number]; tolerance?: number} = {},
312+
): Promise<TrackedFrame[]> {
313+
const scratch = await page.context().newPage();
314+
try {
315+
return await trackMarkerIn(scratch, frames, options);
316+
} finally {
317+
await scratch.close();
318+
}
319+
}
320+
321+
/**
322+
* `trackMarker` in a scratch page the caller opened and closes, for a caller
323+
* that tracks the frames of a running cast more than once.
324+
*/
325+
export async function trackMarkerIn(
326+
scratch: Page,
327+
frames: readonly CastFrame[],
311328
{
312329
rgb = MARKER_RGB,
313330
tolerance = 40,
314331
}: {rgb?: readonly [number, number, number]; tolerance?: number} = {},
315332
): Promise<TrackedFrame[]> {
316-
const scratch = await page.context().newPage();
317-
try {
318-
const out: TrackedFrame[] = [];
319-
// Batches keep each evaluate payload moderate.
320-
for (let i = 0; i < frames.length; i += 12) {
321-
const batch = frames.slice(i, i + 12);
322-
const boxes = await scratch.evaluate(
323-
async ({batch: items, color, tol}) => {
324-
const results: {
325-
box: {x: number; y: number; width: number; height: number} | null;
326-
pixels: number;
327-
}[] = [];
328-
for (const item of items) {
329-
const blob = await (
330-
await fetch(`data:image/${item.format};base64,${item.data}`)
331-
).blob();
332-
const bitmap = await createImageBitmap(blob);
333-
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
334-
const context = canvas.getContext('2d');
335-
if (context == null) {
336-
throw new Error('no 2d context');
337-
}
338-
context.drawImage(bitmap, 0, 0);
339-
const {data, width, height} = context.getImageData(
340-
0,
341-
0,
342-
bitmap.width,
343-
bitmap.height,
344-
);
345-
let minX = Infinity;
346-
let minY = Infinity;
347-
let maxX = -Infinity;
348-
let maxY = -Infinity;
349-
let pixels = 0;
350-
for (let y = 0; y < height; y += 1) {
351-
for (let x = 0; x < width; x += 1) {
352-
const o = (y * width + x) * 4;
353-
if (
354-
Math.abs(data[o] - color[0]) <= tol &&
355-
Math.abs(data[o + 1] - color[1]) <= tol &&
356-
Math.abs(data[o + 2] - color[2]) <= tol
357-
) {
358-
pixels += 1;
359-
if (x < minX) {
360-
minX = x;
361-
}
362-
if (x > maxX) {
363-
maxX = x;
364-
}
365-
if (y < minY) {
366-
minY = y;
367-
}
368-
if (y > maxY) {
369-
maxY = y;
370-
}
333+
const out: TrackedFrame[] = [];
334+
// Batches keep each evaluate payload moderate.
335+
for (let i = 0; i < frames.length; i += 12) {
336+
const batch = frames.slice(i, i + 12);
337+
const boxes = await scratch.evaluate(
338+
async ({batch: items, color, tol}) => {
339+
const results: {
340+
box: {x: number; y: number; width: number; height: number} | null;
341+
pixels: number;
342+
}[] = [];
343+
for (const item of items) {
344+
const blob = await (
345+
await fetch(`data:image/${item.format};base64,${item.data}`)
346+
).blob();
347+
const bitmap = await createImageBitmap(blob);
348+
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
349+
const context = canvas.getContext('2d');
350+
if (context == null) {
351+
throw new Error('no 2d context');
352+
}
353+
context.drawImage(bitmap, 0, 0);
354+
const {data, width, height} = context.getImageData(
355+
0,
356+
0,
357+
bitmap.width,
358+
bitmap.height,
359+
);
360+
let minX = Infinity;
361+
let minY = Infinity;
362+
let maxX = -Infinity;
363+
let maxY = -Infinity;
364+
let pixels = 0;
365+
for (let y = 0; y < height; y += 1) {
366+
for (let x = 0; x < width; x += 1) {
367+
const o = (y * width + x) * 4;
368+
if (
369+
Math.abs(data[o] - color[0]) <= tol &&
370+
Math.abs(data[o + 1] - color[1]) <= tol &&
371+
Math.abs(data[o + 2] - color[2]) <= tol
372+
) {
373+
pixels += 1;
374+
if (x < minX) {
375+
minX = x;
376+
}
377+
if (x > maxX) {
378+
maxX = x;
379+
}
380+
if (y < minY) {
381+
minY = y;
382+
}
383+
if (y > maxY) {
384+
maxY = y;
371385
}
372386
}
373387
}
374-
const scale = width / item.viewportWidth;
375-
results.push({
376-
box:
377-
pixels === 0
378-
? null
379-
: {
380-
x: minX / scale,
381-
y: minY / scale,
382-
width: (maxX - minX + 1) / scale,
383-
height: (maxY - minY + 1) / scale,
384-
},
385-
pixels,
386-
});
387388
}
388-
return results;
389-
},
390-
{
391-
batch: batch.map(f => ({
392-
data: f.data,
393-
format: f.format,
394-
viewportWidth: f.viewportWidth,
395-
})),
396-
color: [...rgb],
397-
tol: tolerance,
398-
},
399-
);
400-
boxes.forEach((result, k) =>
401-
out.push({t: batch[k].t, box: result.box, pixels: result.pixels}),
402-
);
403-
}
404-
return out;
405-
} finally {
406-
await scratch.close();
389+
const scale = width / item.viewportWidth;
390+
results.push({
391+
box:
392+
pixels === 0
393+
? null
394+
: {
395+
x: minX / scale,
396+
y: minY / scale,
397+
width: (maxX - minX + 1) / scale,
398+
height: (maxY - minY + 1) / scale,
399+
},
400+
pixels,
401+
});
402+
}
403+
return results;
404+
},
405+
{
406+
batch: batch.map(f => ({
407+
data: f.data,
408+
format: f.format,
409+
viewportWidth: f.viewportWidth,
410+
})),
411+
color: [...rgb],
412+
tol: tolerance,
413+
},
414+
);
415+
boxes.forEach((result, k) =>
416+
out.push({t: batch[k].t, box: result.box, pixels: result.pixels}),
417+
);
407418
}
419+
return out;
408420
}
409421

410422
export interface FrameStats {

0 commit comments

Comments
 (0)