Skip to content

Commit aa9221d

Browse files
committed
test: cover android swipe helper fallback
1 parent db17659 commit aa9221d

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/platforms/android/__tests__/multitouch-helper.test.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test('runAndroidMultiTouchHelperGesture preserves helper failure messages', asyn
166166
);
167167
});
168168

169-
test('swipeAndroid and multi-touch gestures prefer provider-native touch injection', async () => {
169+
test('swipeGestureAndroid and multi-touch gestures prefer provider-native touch injection', async () => {
170170
const calls: unknown[] = [];
171171
await withAndroidAdbProvider(
172172
{
@@ -226,6 +226,55 @@ test('swipeAndroid and multi-touch gestures prefer provider-native touch injecti
226226
]);
227227
});
228228

229+
test('swipeGestureAndroid falls back to adb input swipe when helper injection fails', async () => {
230+
const adbCalls: string[][] = [];
231+
const result = await withAndroidAdbProvider(
232+
{
233+
exec: async (args) => {
234+
adbCalls.push(args);
235+
if (args.includes('--show-versioncode')) {
236+
return {
237+
exitCode: 0,
238+
stdout: `package:${manifest.packageName} versionCode:999999`,
239+
stderr: '',
240+
};
241+
}
242+
if (args.includes('instrument')) {
243+
return {
244+
exitCode: 1,
245+
stdout: [
246+
resultRecord({
247+
ok: 'false',
248+
errorType: 'java.lang.IllegalStateException',
249+
message: 'injectInputEvent returned false',
250+
}),
251+
'INSTRUMENTATION_CODE: 1',
252+
].join('\n'),
253+
stderr: '',
254+
};
255+
}
256+
if (args.join(' ') === 'shell input swipe 340 400 60 400 300') {
257+
return { exitCode: 0, stdout: '', stderr: '' };
258+
}
259+
throw new Error(`unexpected adb call: ${args.join(' ')}`);
260+
},
261+
},
262+
{ serial: ANDROID_EMULATOR.id },
263+
async () =>
264+
await swipeGestureAndroid(ANDROID_EMULATOR, {
265+
x1: 340,
266+
y1: 400,
267+
x2: 60,
268+
y2: 400,
269+
durationMs: 300,
270+
}),
271+
);
272+
273+
assert.deepEqual(result, { backend: 'adb-input-swipe-fallback' });
274+
assert.ok(adbCalls.some((args) => args.join(' ').includes('am instrument')));
275+
assert.ok(adbCalls.some((args) => args.join(' ') === 'shell input swipe 340 400 60 400 300'));
276+
});
277+
229278
test('rotateGestureAndroid rejects zero velocity before provider dispatch', async () => {
230279
await withAndroidAdbProvider(
231280
{

src/platforms/android/multitouch-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ async function resolveAndroidMultiTouchHelperArtifact(): Promise<AndroidMultiTou
473473
} catch (error) {
474474
throw new AppError(
475475
'UNSUPPORTED_OPERATION',
476-
'gesture pinch/rotate/transform on Android requires the bundled Android multi-touch helper artifact, but it was not found or could not be read',
476+
'Android touch gestures require the bundled Android touch helper artifact, but it was not found or could not be read',
477477
{ manifestPath, error: normalizeError(error).message },
478478
error,
479479
);

src/utils/cli-help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Command shape:
108108
Snapshot refs look like @e12. After snapshot -i, use the exact @eN ref from that output.
109109
If the exact ref is not known yet, first output snapshot -i, then use a concrete example shape like press @e12 in the next command; do not write @<ref>, @ref, @Label_Name, or @eN placeholders.
110110
Close means agent-device close. App-owned back means back; system back means back --system.
111-
Taps are press or click. Gestures use swipe, longpress, or gesture <pan|fling|swipe|pinch|rotate|transform>. Use gesture swipe left|right for reliable in-page horizontal swipes, and gesture swipe right-edge for left-edge navigation/back gestures. Android pinch, rotate, and transform use provider-native touch injection when available, then the bundled multi-touch helper. iOS simulator transform uses private XCTest synthesis for a continuous two-finger pan/scale/rotation path; otherwise it reports UNSUPPORTED_OPERATION.
111+
Taps are press or click. Gestures use swipe, longpress, or gesture <pan|fling|swipe|pinch|rotate|transform>. Use gesture swipe left|right for reliable in-page horizontal swipes, and gesture swipe right-edge for left-edge navigation/back gestures. Android swipe, pinch, rotate, and transform use provider-native touch injection when available, then the bundled touch helper. iOS simulator transform uses private XCTest synthesis for a continuous two-finger pan/scale/rotation path; otherwise it reports UNSUPPORTED_OPERATION.
112112
113113
Bootstrap:
114114
agent-device devices --platform ios

0 commit comments

Comments
 (0)