ReviewOS

also looking at this

craft-native/craft

fix(android): resolve share() with whether the person picked an app

#210
Merged glennmichael123 wants to merge fix/android-share-outcome into main
12 files +399 -56
scripts/mobile-e2e/protocol.tsmodified+51-1
Changes to scripts/mobile-e2e/protocol.ts
@@ -43,7 +43,19 @@ export interface ObservedEvent {
4343 value: unknown
4444}
4545
46export type DriverEvent = PlanEvent | CaseEvent | DoneEvent | FatalEvent | ObservedEvent
46/**
47 * The page asking the harness to do what a person would. Emitted just before
48 * the call that needs it, because the page cannot tap the device itself.
49 */
50export interface AwaitingEvent {
51 event: 'awaiting'
52 /** The case that is waiting. */
53 name: string
54 /** What it is waiting for, one of the needs the harness knows how to meet. */
55 need: string
56}
57
58export type DriverEvent = PlanEvent | CaseEvent | DoneEvent | FatalEvent | ObservedEvent | AwaitingEvent
4759
4860export type MobilePlatform = 'ios' | 'android'
4961
@@ -74,6 +86,8 @@ export const REQUIRED_CASES: Record<MobilePlatform, string[]> = {
7486 'deviceInfo.isEmulator',
7587 'clipboard.roundTrip',
7688 'push.disabled.rejects',
89 'share.empty.rejects',
90 'share.dismissed.resolvesFalse',
7791 ],
7892}
7993
@@ -303,6 +317,42 @@ export function evaluateRun(platform: MobilePlatform, text: string, expectedRun?
303317 return { ok: failures.length === 0, failures, planned, passed, failed }
304318}
305319
320/** The need the Android share case announces before it opens the menu. */
321export const DISMISS_SHARE_MENU = 'dismiss-share-menu'
322
323/** The needs the page has announced so far, in order, without repeats. */
324export function awaitedNeeds(text: string): string[] {
325 const needs: string[] = []
326 for (const event of parseDriverOutput(text).events) {
327 if (event.event === 'awaiting' && !needs.includes(event.need))
328 needs.push(event.need)
329 }
330 return needs
331}
332
333/**
334 * Whether Android's share menu holds input focus, read from
335 * `adb shell dumpsys window`.
336 *
337 * The harness presses Back only once this is true, because Back goes to the
338 * focused window. Focus rather than the activity being *resumed*, which is
339 * what this first checked: the activity manager marks the chooser resumed
340 * before its process has even created it. On the first CI run the chooser was
341 * resumed at 50.37s and took focus at 52.63s. Back pressed in that gap goes to
342 * the app, which closes, and the page never reports anything. That run passed
343 * only because the harness happened to poll late.
344 *
345 * Matched by class name rather than by package, because the chooser moved:
346 * `android/com.android.internal.app.ChooserActivity` up to Android 13, and
347 * `com.android.intentresolver/com.android.intentresolver.ChooserActivity` from
348 * 14.
349 */
350export function shareMenuInFront(dumpsysWindow: string): boolean {
351 return dumpsysWindow
352 .split('\n')
353 .some(line => /mCurrentFocus=/.test(line) && /ChooserActivity/.test(line))
354}
355
306356/**
307357 * The actions the Zig dispatcher saw, by name.
308358 *