@@ -66,6 +66,24 @@ async function withMockedAdb(
6666 }
6767}
6868
69+ function androidOpenAdbScript ( ) : string {
70+ return [
71+ '#!/bin/sh' ,
72+ 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
73+ 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
74+ 'if [ "$1" = "-s" ]; then' ,
75+ ' shift' ,
76+ ' shift' ,
77+ 'fi' ,
78+ 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
79+ ' echo "Status: ok"' ,
80+ ' exit 0' ,
81+ 'fi' ,
82+ 'exit 0' ,
83+ '' ,
84+ ] . join ( '\n' ) ;
85+ }
86+
6987test ( 'parseUiHierarchy reads double-quoted Android node attributes' , ( ) => {
7088 const xml =
7189 '<hierarchy><node class="android.widget.TextView" text="Hello" content-desc="Greeting" resource-id="com.demo:id/title" bounds="[10,20][110,60]" clickable="true" enabled="true"/></hierarchy>' ;
@@ -1121,25 +1139,7 @@ test('installAndroidInstallablePath invalidates cached display-name package matc
11211139test ( 'openAndroidApp default launch uses -p package flag' , async ( ) => {
11221140 await withMockedAdb (
11231141 'agent-device-android-open-default-' ,
1124- [
1125- '#!/bin/sh' ,
1126- 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1127- 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1128- 'if [ "$1" = "-s" ]; then' ,
1129- ' shift' ,
1130- ' shift' ,
1131- 'fi' ,
1132- 'if [ "$1" = "shell" ] && [ "$2" = "pm" ] && [ "$3" = "list" ]; then' ,
1133- ' echo "package:com.example.app"' ,
1134- ' exit 0' ,
1135- 'fi' ,
1136- 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
1137- ' echo "Status: ok"' ,
1138- ' exit 0' ,
1139- 'fi' ,
1140- 'exit 0' ,
1141- '' ,
1142- ] . join ( '\n' ) ,
1142+ androidOpenAdbScript ( ) ,
11431143 async ( { argsLogPath, device } ) => {
11441144 await openAndroidApp ( device , 'com.example.app' ) ;
11451145 const logged = await fs . readFile ( argsLogPath , 'utf8' ) ;
@@ -1152,25 +1152,7 @@ test('openAndroidApp default launch uses -p package flag', async () => {
11521152test ( 'openAndroidApp appends launchArgs to am start when launching by package' , async ( ) => {
11531153 await withMockedAdb (
11541154 'agent-device-android-open-launch-args-' ,
1155- [
1156- '#!/bin/sh' ,
1157- 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1158- 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1159- 'if [ "$1" = "-s" ]; then' ,
1160- ' shift' ,
1161- ' shift' ,
1162- 'fi' ,
1163- 'if [ "$1" = "shell" ] && [ "$2" = "pm" ] && [ "$3" = "list" ]; then' ,
1164- ' echo "package:com.example.app"' ,
1165- ' exit 0' ,
1166- 'fi' ,
1167- 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
1168- ' echo "Status: ok"' ,
1169- ' exit 0' ,
1170- 'fi' ,
1171- 'exit 0' ,
1172- '' ,
1173- ] . join ( '\n' ) ,
1155+ androidOpenAdbScript ( ) ,
11741156 async ( { argsLogPath, device } ) => {
11751157 await openAndroidApp ( device , 'com.example.app' , {
11761158 launchArgs : [ '--es' , 'screen' , 'home' , '--ez' , 'fresh' , 'true' ] ,
@@ -1184,88 +1166,36 @@ test('openAndroidApp appends launchArgs to am start when launching by package',
11841166test ( 'openAndroidApp appends launchArgs to am start when activity override is set' , async ( ) => {
11851167 await withMockedAdb (
11861168 'agent-device-android-open-launch-args-activity-' ,
1187- [
1188- '#!/bin/sh' ,
1189- 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1190- 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1191- 'if [ "$1" = "-s" ]; then' ,
1192- ' shift' ,
1193- ' shift' ,
1194- 'fi' ,
1195- 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
1196- ' echo "Status: ok"' ,
1197- ' exit 0' ,
1198- 'fi' ,
1199- 'exit 0' ,
1200- '' ,
1201- ] . join ( '\n' ) ,
1169+ androidOpenAdbScript ( ) ,
12021170 async ( { argsLogPath, device } ) => {
12031171 await openAndroidApp ( device , 'com.example.app' , {
12041172 activity : '.MainActivity' ,
12051173 launchArgs : [ '--es' , 'mode' , 'debug' ] ,
12061174 } ) ;
12071175 const logged = await fs . readFile ( argsLogPath , 'utf8' ) ;
1208- assert . match (
1209- logged ,
1210- / - n \n c o m \. e x a m p l e \. a p p \/ \. M a i n A c t i v i t y \n - - e s \n m o d e \n d e b u g / ,
1211- ) ;
1176+ assert . match ( logged , / - n \n c o m \. e x a m p l e \. a p p \/ \. M a i n A c t i v i t y \n - - e s \n m o d e \n d e b u g / ) ;
12121177 } ,
12131178 ) ;
12141179} ) ;
12151180
12161181test ( 'openAndroidApp appends launchArgs to am start for deep link URL opens' , async ( ) => {
12171182 await withMockedAdb (
12181183 'agent-device-android-open-launch-args-url-' ,
1219- [
1220- '#!/bin/sh' ,
1221- 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1222- 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1223- 'if [ "$1" = "-s" ]; then' ,
1224- ' shift' ,
1225- ' shift' ,
1226- 'fi' ,
1227- 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
1228- ' echo "Status: ok"' ,
1229- ' exit 0' ,
1230- 'fi' ,
1231- 'exit 0' ,
1232- '' ,
1233- ] . join ( '\n' ) ,
1184+ androidOpenAdbScript ( ) ,
12341185 async ( { argsLogPath, device } ) => {
12351186 await openAndroidApp ( device , 'myapp://item/42' , {
12361187 launchArgs : [ '--es' , 'ref' , 'campaign' ] ,
12371188 } ) ;
12381189 const logged = await fs . readFile ( argsLogPath , 'utf8' ) ;
1239- assert . match (
1240- logged ,
1241- / - d \n m y a p p : \/ \/ i t e m \/ 4 2 \n - - e s \n r e f \n c a m p a i g n / ,
1242- ) ;
1190+ assert . match ( logged , / - d \n m y a p p : \/ \/ i t e m \/ 4 2 \n - - e s \n r e f \n c a m p a i g n / ) ;
12431191 } ,
12441192 ) ;
12451193} ) ;
12461194
12471195test ( 'openAndroidApp appends launchArgs to am start for app-bound URL opens' , async ( ) => {
12481196 await withMockedAdb (
12491197 'agent-device-android-open-launch-args-app-bound-url-' ,
1250- [
1251- '#!/bin/sh' ,
1252- 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1253- 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1254- 'if [ "$1" = "-s" ]; then' ,
1255- ' shift' ,
1256- ' shift' ,
1257- 'fi' ,
1258- 'if [ "$1" = "shell" ] && [ "$2" = "pm" ] && [ "$3" = "list" ]; then' ,
1259- ' echo "package:com.example.app"' ,
1260- ' exit 0' ,
1261- 'fi' ,
1262- 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
1263- ' echo "Status: ok"' ,
1264- ' exit 0' ,
1265- 'fi' ,
1266- 'exit 0' ,
1267- '' ,
1268- ] . join ( '\n' ) ,
1198+ androidOpenAdbScript ( ) ,
12691199 async ( { argsLogPath, device } ) => {
12701200 await openAndroidApp ( device , 'com.example.app' , {
12711201 url : 'https://example.com/promo' ,
@@ -1283,25 +1213,7 @@ test('openAndroidApp appends launchArgs to am start for app-bound URL opens', as
12831213test ( 'openAndroidApp shell-quotes launchArgs containing JSON or shell metacharacters' , async ( ) => {
12841214 await withMockedAdb (
12851215 'agent-device-android-open-launch-args-quoting-' ,
1286- [
1287- '#!/bin/sh' ,
1288- 'printf "__CMD__\\n" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1289- 'printf "%s\\n" "$@" >> "$AGENT_DEVICE_TEST_ARGS_FILE"' ,
1290- 'if [ "$1" = "-s" ]; then' ,
1291- ' shift' ,
1292- ' shift' ,
1293- 'fi' ,
1294- 'if [ "$1" = "shell" ] && [ "$2" = "pm" ] && [ "$3" = "list" ]; then' ,
1295- ' echo "package:com.example.app"' ,
1296- ' exit 0' ,
1297- 'fi' ,
1298- 'if [ "$1" = "shell" ] && [ "$2" = "am" ] && [ "$3" = "start" ]; then' ,
1299- ' echo "Status: ok"' ,
1300- ' exit 0' ,
1301- 'fi' ,
1302- 'exit 0' ,
1303- '' ,
1304- ] . join ( '\n' ) ,
1216+ androidOpenAdbScript ( ) ,
13051217 async ( { argsLogPath, device } ) => {
13061218 // Value contains characters the device shell would otherwise re-interpret:
13071219 // `#` (comment), `;` (statement separator), `&` (background), `*` (glob),
@@ -1313,10 +1225,7 @@ test('openAndroidApp shell-quotes launchArgs containing JSON or shell metacharac
13131225 const logged = await fs . readFile ( argsLogPath , 'utf8' ) ;
13141226 // `--es` and the safe extra key pass through unquoted; the JSON value
13151227 // is single-quoted so `adb shell` re-tokenisation preserves it.
1316- assert . match (
1317- logged ,
1318- / - - e s \n E X T R A _ C O N F I G \n ' \{ " a " : " x # y ; z & w " , " b " : " p a t h \/ \* " \} ' / ,
1319- ) ;
1228+ assert . match ( logged , / - - e s \n E X T R A _ C O N F I G \n ' \{ " a " : " x # y ; z & w " , " b " : " p a t h \/ \* " \} ' / ) ;
13201229 } ,
13211230 ) ;
13221231} ) ;
0 commit comments