|
1 | 1 | import assert from 'node:assert/strict'; |
2 | 2 | import { test } from 'vitest'; |
3 | | -import { resolveKeyboardTapOcclusion } from '@agent-device/contracts/tap-keyboard-occlusion'; |
4 | 3 | import { SnapshotSourceError } from './errors.ts'; |
5 | 4 | import { decodeSnapshotBridgeTree } from './tree.ts'; |
6 | 5 | import type { SnapshotSourceLimits } from './types.ts'; |
@@ -329,111 +328,3 @@ test('a window reporting the app box quarter-turned is counted as an unresolved |
329 | 328 | 0, |
330 | 329 | ); |
331 | 330 | }); |
332 | | - |
333 | | -// The keyboard band the bridge publishes (#2660). The bridge cannot query the keyboard the way the |
334 | | -// runner does, so what it publishes has to BE the band the shared rule measures over the tree it |
335 | | -// decoded — anything else would move the tap guard's decision without anyone deciding to. |
336 | | - |
337 | | -const PORTRAIT_KEYBOARD_TREE = { |
338 | | - [application]: 'Application', |
339 | | - [frame]: { X: 0, Y: 0, Width: 402, Height: 874 }, |
340 | | - [children]: [ |
341 | | - { |
342 | | - [application]: 'UIRemoteKeyboardWindow', |
343 | | - [automationType]: 4, |
344 | | - [frame]: { X: 0, Y: 583, Width: 402, Height: 233 }, |
345 | | - [children]: [ |
346 | | - { |
347 | | - [automationType]: 19, |
348 | | - [frame]: { X: 0, Y: 583, Width: 402, Height: 233 }, |
349 | | - [children]: [0, 1, 2, 3].map((column) => ({ |
350 | | - [automationType]: 20, |
351 | | - [frame]: { X: column * 100.5, Y: 600, Width: 100.5, Height: 60 }, |
352 | | - [children]: [], |
353 | | - })), |
354 | | - }, |
355 | | - ], |
356 | | - }, |
357 | | - ], |
358 | | -}; |
359 | | - |
360 | | -test('a portrait keyboard-up capture publishes the band the tree rule measures', () => { |
361 | | - const decoded = decodeSnapshotBridgeTree(PORTRAIT_KEYBOARD_TREE, { truncated: false }, limits); |
362 | | - |
363 | | - // Reported key plane bottoms out at 816 of an 874 pt viewport, and the band still owns the strip |
364 | | - // below it: the same frame the tap guard computed from this tree before the fact existed. |
365 | | - assert.deepEqual(decoded.keyboard, { |
366 | | - kind: 'visible', |
367 | | - frame: { x: 0, y: 583, width: 402, height: 291 }, |
368 | | - }); |
369 | | - |
370 | | - const point = { x: 201, y: 832 }; |
371 | | - const measuredByTheRule = resolveKeyboardTapOcclusion({ |
372 | | - nodes: decoded.nodes, |
373 | | - viewport: decoded.viewport.kind === 'missing' ? null : decoded.viewport.rect, |
374 | | - point, |
375 | | - }); |
376 | | - assert.equal(measuredByTheRule.kind, 'occluded'); |
377 | | - assert.deepEqual( |
378 | | - decoded.keyboard.kind === 'visible' ? decoded.keyboard.frame : null, |
379 | | - measuredByTheRule.surface.frame, |
380 | | - 'the published band must be the band the rule measures', |
381 | | - ); |
382 | | -}); |
383 | | - |
384 | | -test('a tree with no keyboard window publishes a proven absence', () => { |
385 | | - const decoded = decodeSnapshotBridgeTree( |
386 | | - { |
387 | | - [application]: 'Application', |
388 | | - [frame]: { X: 0, Y: 0, Width: 402, Height: 874 }, |
389 | | - [children]: [ |
390 | | - { |
391 | | - [application]: 'UIWindow', |
392 | | - [automationType]: 4, |
393 | | - [frame]: { X: 0, Y: 0, Width: 402, Height: 874 }, |
394 | | - [children]: [], |
395 | | - }, |
396 | | - ], |
397 | | - }, |
398 | | - { truncated: false }, |
399 | | - limits, |
400 | | - ); |
401 | | - |
402 | | - assert.deepEqual(decoded.keyboard, { kind: 'absent' }); |
403 | | -}); |
404 | | - |
405 | | -test('a keyboard this tree cannot measure is published as unmeasurable, not as absent', () => { |
406 | | - // An iPad floating keyboard reports a band the rule refuses to extend to the bottom edge. The |
407 | | - // screen is not clear of a keyboard, and the guard has to be able to say it abstained. |
408 | | - const decoded = decodeSnapshotBridgeTree( |
409 | | - { |
410 | | - [application]: 'Application', |
411 | | - [frame]: { X: 0, Y: 0, Width: 402, Height: 874 }, |
412 | | - [children]: [ |
413 | | - { |
414 | | - [application]: 'UIRemoteKeyboardWindow', |
415 | | - [automationType]: 4, |
416 | | - [frame]: { X: 21, Y: 480, Width: 360, Height: 200 }, |
417 | | - [children]: [ |
418 | | - { |
419 | | - [automationType]: 19, |
420 | | - [frame]: { X: 21, Y: 480, Width: 360, Height: 200 }, |
421 | | - [children]: [0, 1, 2].map((column) => ({ |
422 | | - [automationType]: 20, |
423 | | - [frame]: { X: 21 + column * 120, Y: 500, Width: 120, Height: 60 }, |
424 | | - [children]: [], |
425 | | - })), |
426 | | - }, |
427 | | - ], |
428 | | - }, |
429 | | - ], |
430 | | - }, |
431 | | - { truncated: false }, |
432 | | - limits, |
433 | | - ); |
434 | | - |
435 | | - assert.deepEqual(decoded.keyboard, { |
436 | | - kind: 'unmeasurable', |
437 | | - reason: 'tree-keyboard-band-unmeasurable', |
438 | | - }); |
439 | | -}); |
0 commit comments