also looking at this
fix(android): resolve share() with whether the person picked an app
#210
12 files
+399
-56
| @@ -2,7 +2,7 @@ import type { LegOutcome, RunnerOptions } from './types' | ||
| 2 | 2 | import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs' |
| 3 | 3 | import { join } from 'node:path' |
| 4 | 4 | import { init } from '../../packages/android/src/index' |
| 5 | import { androidDeclines, evaluateRun, hasTerminated } from './protocol' | |
| 5 | import { androidDeclines, awaitedNeeds, DISMISS_SHARE_MENU, evaluateRun, hasTerminated, shareMenuInFront } from './protocol' | |
| 6 | 6 | import { command, driverPage, waitForFile } from './support' |
| 7 | 7 | |
| 8 | 8 | /** |
| @@ -149,6 +149,24 @@ async function runLeg(leg: Leg, options: RunnerOptions): Promise<LegOutcome> { | ||
| 149 | 149 | await adb(['shell', 'am', 'force-stop', PACKAGE], { serial, allowFailure: true }) |
| 150 | 150 | await adb(['shell', 'am', 'start', '-n', `${PACKAGE}/.MainActivity`], { serial, logPath: join(evidence, 'adb.log') }) |
| 151 | 151 | |
| 152 | // The share case needs its menu dismissed, and nothing on the device will | |
| 153 | // do that: the harness plays the person. It acts only once the page has | |
| 154 | // asked and the menu is really in front, and it keeps a screenshot of the | |
| 155 | // menu, which is the evidence that there was one to dismiss. | |
| 156 | let shareMenu: 'not asked' | 'asked' | 'dismissed' = 'not asked' | |
| 157 | ||
| 158 | async function dismissShareMenuWhenAsked(log: string): Promise<void> { | |
| 159 | if (shareMenu === 'dismissed' || !awaitedNeeds(log).includes(DISMISS_SHARE_MENU)) return | |
| 160 | shareMenu = 'asked' | |
| 161 | ||
| 162 | const windows = await command(['adb', '-s', serial, 'shell', 'dumpsys', 'window'], { allowFailure: true }) | |
| 163 | if (!shareMenuInFront(windows.stdout)) return | |
| 164 | ||
| 165 | await command(['adb', '-s', serial, 'exec-out', 'screencap', '-p'], { allowFailure: true, outPath: join(evidence, 'share-menu.png') }) | |
| 166 | await adb(['shell', 'input', 'keyevent', 'KEYCODE_BACK'], { serial, logPath: join(evidence, 'adb.log') }) | |
| 167 | shareMenu = 'dismissed' | |
| 168 | } | |
| 169 | ||
| 152 | 170 | // logcat -d dumps and exits, so poll it into the evidence file rather than |
| 153 | 171 | // streaming: a stream would have to be killed at exactly the right moment, |
| 154 | 172 | // and the dump is cheap. |
| @@ -156,6 +174,7 @@ async function runLeg(leg: Leg, options: RunnerOptions): Promise<LegOutcome> { | ||
| 156 | 174 | const finished = await waitForFile(logPath, options.timeoutMs, hasTerminated, async () => { |
| 157 | 175 | const dumped = await command(['adb', '-s', serial, 'logcat', '-d', ...LOGCAT_FILTER], { allowFailure: true }) |
| 158 | 176 | writeFileSync(logPath, dumped.stdout) |
| 177 | await dismissShareMenuWhenAsked(dumped.stdout) | |
| 159 | 178 | }) |
| 160 | 179 | |
| 161 | 180 | await command(['adb', '-s', serial, 'exec-out', 'screencap', '-p'], { allowFailure: true, outPath: join(evidence, 'screen.png') }) |
| @@ -170,6 +189,16 @@ async function runLeg(leg: Leg, options: RunnerOptions): Promise<LegOutcome> { | ||
| 170 | 189 | const verdict = evaluateRun('android', logText, nonce) |
| 171 | 190 | failures.push(...verdict.failures) |
| 172 | 191 | |
| 192 | // The page's case only sees that share resolved false. That is also what a | |
| 193 | // share that never opened a menu at all would resolve, so the harness says | |
| 194 | // whether there was a menu to dismiss. | |
| 195 | if (verdict.planned.includes('share.dismissed.resolvesFalse')) { | |
| 196 | if (shareMenu === 'not asked') | |
| 197 | failures.push('the page never asked for the share menu to be dismissed, so the dismissal case did not reach the menu') | |
| 198 | else if (shareMenu === 'asked') | |
| 199 | failures.push('the page asked for the share menu to be dismissed, and no share menu ever came to the front') | |
| 200 | } | |
| 201 | ||
| 173 | 202 | // The page reported the SDK level the bridge told it; the host asked the |
| 174 | 203 | // device directly. Agreement means the value crossed the bridge rather than |
| 175 | 204 | // being invented in JavaScript - this leg's substitute for the pasteboard |