Repository navigation
Expand file tree
/
Copy pathdialogs.sh
More file actions
executable file
·325 lines (310 loc) · 16.4 KB
/
Copy pathdialogs.sh
File metadata and controls
executable file
·325 lines (310 loc) · 16.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/sh
# Dialogs, end to end, on MobiumApp's Dialog Demo: every kind the app can
# raise, each judged by what the app says it received rather than by the
# dialog going away.
#
# docs/checks/dialogs.sh <android-serial | simulator-udid>
# MOBIUMAPP_BUNDLE=<path to MobiumApp.app> docs/checks/dialogs.sh <iphone-udid>
#
# What it holds each platform to is what was measured (CHALLENGES 106, 305):
# accept and dismiss are yes and no, so they answer a dialog of one or two
# buttons and say which they pressed, and a dialog of three or more — the
# three-button alert, the action sheet, the location prompt, and Android's
# camera prompt — is refused, naming its buttons. alert --button presses one
# by caption or position on any of them, and answering by the button's
# caption with tap is checked for every kind too. Then the refusals: a
# target under a dialog, and under the keyboard (CHALLENGES 105 and its
# keyboard half).
#
# Needs MobiumApp installed (mobiumdev/mobium-app). Permissions are reset for
# MobiumApp alone, on a phone too — except a real iPhone, which cannot reset
# them from outside, so there it needs MOBIUMAPP_BUNDLE (the .app) and
# reinstalls the app instead. An iPhone's clipboard cannot be seeded, so paste is not
# checked there.
set -e
DEV="$1"
if [ -z "$DEV" ]; then echo "usage: $0 <serial|udid>" >&2; exit 2; fi
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
. "$ROOT/docs/checks/lib.sh"
check_lock "$DEV"
fail() { echo "FAIL: $*" >&2; exit 1; }
row() { printf ' %-18s %-50s ok\n' "$1" "$2"; }
APP=dev.mobium.mobiumapp
case "$DEV" in
????????-????????????????)
# A phone cannot reset a permission from outside; reinstalling the app
# is the one reset it has, so the bundle is required here.
[ -n "$MOBIUMAPP_BUNDLE" ] || { echo "on a real iPhone set MOBIUMAPP_BUNDLE=<path to MobiumApp.app>: reinstalling is the only permission reset a phone has" >&2; exit 2; }
PLATFORM=ios; PHONE=1; M="$ROOT/bin/mobium --driver wda --device $DEV"
RESET=reinstall; CAP=label ;;
*-*-*-*-*) PLATFORM=ios; M="$ROOT/bin/mobium --driver wda --device $DEV"; RESET="$M reset-permissions $APP"; CAP=label ;;
emulator-*) PLATFORM=android; M="$ROOT/bin/mobium --device $DEV"; RESET="$M reset-permissions $APP"; CAP=text ;;
*)
# A reset names the app, so on a person's phone only MobiumApp's
# permissions go back to asking.
PLATFORM=android; PHONE=1; M="$ROOT/bin/mobium --device $DEV"; RESET="$M reset-permissions $APP"; CAP=text ;;
esac
echo "--- $DEV ($PLATFORM)"
reinstall() { $M uninstall "$APP" >/dev/null 2>&1 || true; $M install "$MOBIUMAPP_BUNDLE" >/dev/null; }
# A reset that fails says why: under set -e with its output discarded, the
# check once stopped after "share sheet" with nothing on the screen.
reset_perms() { $RESET >/dev/null || fail "resetting MobiumApp's permissions failed (above)"; }
fresh() {
$M alert dismiss >/dev/null 2>&1 || true
$M terminate "$APP" >/dev/null 2>&1 || true
$M launch "$APP" >/dev/null
$M tap "label=Dialog Demo" >/dev/null
}
# raise <button>: tap it and wait for a dialog to be up.
raise() {
$M tap "testid=$1" >/dev/null
i=0
until $M alert 2>/dev/null | grep -q 'a dialog is on screen'; do
i=$((i + 1)); [ $i -lt 8 ] || fail "$1 raised no dialog"
sleep 1
done
}
# outcome <text>: the app says it received exactly that.
outcome() {
$M scroll-to testid=dialogOutcome --direction up >/dev/null 2>&1 || true
got=$($M text testid=dialogOutcome)
[ "$got" = "$1" ] || fail "the app received \"$got\", want \"$1\""
}
# verb <button> <accept|dismiss> <outcome>: the answer must say what it pressed.
verb() {
fresh; raise "$1"
out=$($M alert "$2" 2>&1) || fail "alert $2 on $1: $out"
echo "$out" | grep -q 'pressed "' || fail "alert $2 on $1 did not say what it pressed: $out"
sleep 1; outcome "$3"
}
# refused <button> <accept|dismiss>: a dialog of three or more is refused as
# unsupported (exit 5), naming its buttons, and is still up.
refused() {
fresh; raise "$1"
st=0; out=$($M alert "$2" 2>&1) || st=$?
[ $st -eq 5 ] || fail "alert $2 on $1 exited $st, want 5 (refused): $out"
echo "$out" | grep -q 'buttons' || fail "the refusal of $2 on $1 did not name the buttons: $out"
$M alert 2>/dev/null | grep -q 'a dialog is on screen' || fail "a refused $2 on $1 answered the dialog anyway"
# Out of the way, as dismiss cannot: the next check resets what this chose.
$M alert --button 1 >/dev/null
}
# pick <button> <caption or position> <outcome>: alert --button, which says what it pressed.
pick() {
fresh; raise "$1"
out=$($M alert --button "$2" 2>&1) || fail "alert --button $2 on $1: $out"
echo "$out" | grep -q 'pressed "' || fail "alert --button $2 on $1 did not say what it pressed: $out"
sleep 1; outcome "$3"
}
# press <button> <caption> <outcome>: answer by the caption, the way that
# means the same thing on every platform. Captions match case-insensitively,
# since Android draws alert buttons in capitals, and are narrowed to buttons,
# since a message can contain one: "Stay signed in?" and Stay. A caption is
# a button's text on Android and its label on iOS — map prints it the same on
# both, but no one locator kind matches it on both, so CAP names the kind.
press() { fresh; raise "$1"; $M tap "$CAP=$2,role=button" >/dev/null; sleep 1; outcome "$3"; }
# --- the app's own ----------------------------------------------------------
verb oneButtonBtn accept "one-button: OK"
verb oneButtonBtn dismiss "one-button: OK"
row "one button" "accept and dismiss both press OK"
verb twoButtonBtn dismiss "two-button: Keep Editing"
verb twoButtonBtn accept "two-button: Discard"
press twoButtonBtn "Keep Editing" "two-button: Keep Editing"
row "two buttons" "accept confirms, dismiss cancels, each says which"
# Three: accept pressed Save on Android and Cancel on iOS, which moves the
# cancel button to the bottom, and dismiss the middle one on Android. Refused.
refused threeButtonBtn accept
refused threeButtonBtn dismiss
pick threeButtonBtn "Save" "three-button: Save"
pick threeButtonBtn "cancel" "three-button: Cancel"
# By position, in the order each platform shows them: Android lays them out
# Cancel, Don't Save, Save; iOS stacks Don't Save, Save, Cancel.
if [ "$PLATFORM" = android ]; then pick threeButtonBtn 2 "three-button: Don't Save"
else pick threeButtonBtn 2 "three-button: Save"; fi
press threeButtonBtn "Cancel" "three-button: Cancel"
row "three buttons" "accept, dismiss refused; --button caption, place"
fresh
$M tap testid=lateAlertBtn >/dev/null
$M alert 2>/dev/null | grep -q 'no dialog is on screen' || fail "the late alert came at once"
i=0; until $M alert 2>/dev/null | grep -q 'Session expiring'; do i=$((i + 1)); [ $i -lt 8 ] || fail "the late alert never came"; sleep 1; done
$M tap "$CAP=Stay,role=button" >/dev/null; sleep 1; outcome "late: Stay"
row "late" "absent at first, answered once it came"
if [ "$PLATFORM" = ios ]; then
# Three options: accept pressed Copy Link, a sheet's first. Refused.
refused actionSheetBtn accept
pick actionSheetBtn "Delete Photo" "action sheet: Delete Photo"
press actionSheetBtn "Copy Link" "action sheet: Copy Link"
row "action sheet" "accept refused; --button and a tap press one"
else
fresh; $M tap testid=actionSheetBtn >/dev/null; sleep 1
outcome "action sheet: none on android: ActionSheetIOS is iOS-only"
row "action sheet" "none on Android, and the app says so"
fi
# --- the system's -----------------------------------------------------------
# The share sheet is not an alert to either platform's server. On Android it
# is another activity; on iOS a view hosted in the app.
fresh
$M tap testid=shareBtn >/dev/null; sleep 3
$M alert 2>/dev/null | grep -q 'no dialog is on screen' || fail "the share sheet was seen as an alert"
if [ "$PLATFORM" = android ]; then
[ "$($M current)" = com.android.intentresolver ] || fail "the share sheet is not the intent resolver: $($M current)"
$M press back >/dev/null
else
# iOS 26's sheet has no close button in the tree, only its targets; a
# swipe down closes it, as it does for a person.
$M swipe down >/dev/null
fi
sleep 2
if [ "$PLATFORM" = android ]; then
# Android's share API reports "shared" however the sheet closed.
outcome "share: closed (android cannot tell shared from dismissed)"
else
outcome "share: dismissed"
fi
row "share sheet" "no alert to app_alert; closed without it"
# Permissions. A prompt of two buttons is yes or no, and accept grants and
# dismiss denies on both platforms. Three — iOS's and Android's location,
# Android's camera — offer two ways to say yes, and are answered with
# --button; its caption matches with a straight apostrophe where the prompt
# has Don’t, curly (CHALLENGES 305).
if [ "$PLATFORM" = ios ]; then
reset_perms; verb cameraBtn dismiss "camera: denied"
reset_perms; verb cameraBtn accept "camera: granted"
row "camera" "two buttons: dismiss denied, accept granted"
reset_perms; refused locationBtn accept
reset_perms; pick locationBtn "Allow While Using App" "location: granted"
reset_perms; pick locationBtn "Don't Allow" "location: denied"
row "location" "three: accept refused; --button granted, denied"
reset_perms; verb trackingBtn dismiss "tracking: denied"
row "tracking" "App Tracking Transparency, from SpringBoard"
else
reset_perms; verb notificationsBtn dismiss "notifications: denied"
reset_perms; verb notificationsBtn accept "notifications: granted"
row "notifications" "two, stacked Allow first: by id, not place"
reset_perms; refused cameraBtn accept
reset_perms; pick cameraBtn "Only this time" "camera: granted"
reset_perms; pick cameraBtn "Don't allow" "camera: denied"
row "camera" "three: accept refused; --button granted, denied"
reset_perms; refused locationBtn dismiss
reset_perms; pick locationBtn "While using the app" "location: granted"
row "location" "three: refused; --button granted it"
fi
# Back to asking: a later check that meets the prompt, or expects to, must
# not find the answer this one gave last — mobium-app.sh's location section
# failed on a denial left here.
reset_perms
# Paste: iOS asks before an app reads what another app put on the clipboard —
# SpringBoard's prompt, Don't Allow Paste first and Allow Paste last — and
# Android does not ask at all. The clipboard is seeded from outside, so on
# iOS the text is another app's, which is what raises the prompt.
CLIP='seeded by mobium'
# below <button>: bring a button under the fold into view, once the screen
# has come up — a scroll sent while it is still arriving scrolls Home.
below() { $M wait testid=dialogOutcome >/dev/null; $M scroll-to "testid=$1" >/dev/null; }
# paste_can_prompt: false only when a tap on Paste raised no prompt and the
# simulator's log says why — SpringBoard refusing to post pasted's alert.
# A prompt that does come up is dismissed, and the steps below raise it again.
paste_can_prompt() {
since=$(date '+%Y-%m-%d %H:%M:%S')
fresh; below pasteBtn; $M tap testid=pasteBtn >/dev/null
i=0
while [ $i -lt 8 ]; do
if $M alert 2>/dev/null | grep -q 'a dialog is on screen'; then
$M alert dismiss >/dev/null; return 0
fi
i=$((i + 1)); sleep 1
done
xcrun simctl spawn "$DEV" log show --start "$since" --style compact \
--predicate 'process == "SpringBoard" AND eventMessage CONTAINS "CFUserNotification authorization failure: pasted"' 2>/dev/null \
| grep -q 'authorization failure: pasted' && return 1
return 0
}
if [ -n "$PHONE" ] && [ "$PLATFORM" = ios ]; then
# An iPhone's clipboard cannot be written from outside, so nothing can put
# another app's text there for the prompt to be about.
printf ' %-18s %s\n' "paste" "NOT CHECKED — an iPhone's clipboard cannot be seeded from outside"
elif ! $M clipboard "$CLIP" >/dev/null; then
fail "the clipboard could not be seeded"
elif [ "$PLATFORM" = ios ] && ! paste_can_prompt; then
# The iOS 27 simulator runtimes cannot show the prompt at all: pasted asks
# SpringBoard to post it, SpringBoard refuses pasted for lacking an
# entitlement, and the read fails as not authorized with nothing on the
# screen. Text copied inside Settings does the same, so it is not the
# seeding; iOS 26.5's runtime prompts. Named only on that log line, so
# any other missing prompt still fails below.
printf ' %-18s %s\n' "paste" "NOT CHECKED — this simulator's SpringBoard refuses pasted's prompt (iOS 27)"
elif [ "$PLATFORM" = ios ]; then
fresh; below pasteBtn; raise pasteBtn; $M alert dismiss >/dev/null; sleep 1; outcome "paste: empty, or not allowed"
fresh; below pasteBtn; raise pasteBtn; $M alert accept >/dev/null; sleep 1; outcome "paste: ${#CLIP} characters"
row "paste" "dismiss refused it, accept read ${#CLIP} characters"
else
fresh; below pasteBtn; $M tap testid=pasteBtn >/dev/null; sleep 1
$M alert 2>/dev/null | grep -q 'no dialog' || fail "Android asked before a paste"
outcome "paste: ${#CLIP} characters"
row "paste" "no prompt on Android; read ${#CLIP} characters"
fi
# --- declared rules ---------------------------------------------------------
# A rule names the button, and an action that meets the dialog carries on:
# the dialog answered, the action done, and the result saying which.
$M dialogs --clear >/dev/null
$M dialogs --when "Discard changes" --press "Keep Editing" >/dev/null
fresh
raise twoButtonBtn
out=$($M tap testid=oneButtonBtn 2>&1) || fail "the rule did not carry the tap through: $out"
echo "$out" | grep -q '"Discard changes?" — pressed "Keep Editing"' || fail "the tap did not say which dialog it answered: $out"
i=0; until $M alert 2>/dev/null | grep -q 'Saved'; do i=$((i + 1)); [ $i -lt 8 ] || fail "the tap after the rule never raised its own alert"; sleep 1; done
$M alert accept >/dev/null; sleep 1; outcome "one-button: OK"
$M dialogs | grep -q 'answered 1' || fail "the rule's count did not move"
row "a rule" "answered on the way, and the tap went on"
# A rule for a button the dialog does not have is refused, with the ones it has.
$M dialogs --when "Discard changes" --press "Delete" >/dev/null
fresh
raise twoButtonBtn
out=$($M tap testid=oneButtonBtn 2>&1) && fail "a rule for a missing button went through: $out"
echo "$out" | grep -qi 'keep editing' || fail "the refusal did not list the dialog's buttons: $out"
$M dialogs --clear >/dev/null
row "a wrong rule" "refused, listing the dialog's buttons"
# --- refusals ---------------------------------------------------------------
fresh
raise twoButtonBtn
out=$($M tap testid=backBtn 2>&1) && fail "a tap under a dialog went through: $out"
echo "$out" | grep -q 'a dialog is over the app' || fail "the refusal did not name the dialog: $out"
$M tap "$CAP=Keep Editing,role=button" >/dev/null
row "under a dialog" "refused, naming it; its own button still works"
fresh
$M scroll-to testid=coverField >/dev/null
$M tap testid=coverField >/dev/null; sleep 1
# With a hardware keyboard attached nothing covers the button: a simulator
# keeps its software keyboard below the screen's edge, and a headed emulator
# shows only Gboard's floating toolbar, at the left. That is a reason to
# skip, not a failure — so the check asks whether the button is covered.
covered=yes
if ! $M keyboard --json | grep -q '"shown": true'; then
covered=""
elif [ "$PLATFORM" = android ]; then
b=$($M find testid=coveredBtn --json 2>/dev/null | python3 -c '
import json,sys
e=json.load(sys.stdin)["elements"]
print("%d %d" % ((e[0]["bounds"]["x1"]+e[0]["bounds"]["x2"])//2, (e[0]["bounds"]["y1"]+e[0]["bounds"]["y2"])//2) if e else "")')
if [ -n "$b" ]; then
covered=$(adb -s "$DEV" shell dumpsys window InputMethod | python3 -c '
import re,sys
out=sys.stdin.read(); x,y=map(int,sys.argv[1:3])
m=re.search(r"touchable region=SkRegion\(((?:\(-?\d+,-?\d+,-?\d+,-?\d+\))+)\)", out)
rects=[tuple(map(int,r)) for r in re.findall(r"\((-?\d+),(-?\d+),(-?\d+),(-?\d+)\)", m.group(1))] if m and "isVisible=true" in out else []
print("yes" if any(a<=x<c and b<=y<d for a,b,c,d in rects) else "")' $b)
fi
fi
if [ -z "$covered" ]; then
printf ' %-18s %s\n' "under keyboard" "SKIPPED — the keyboard covers nothing there (a hardware keyboard is attached)"
$M terminate "$APP" >/dev/null 2>&1 || true
echo PASS
exit 0
fi
out=$($M tap testid=coveredBtn 2>&1) && fail "a tap under the keyboard went through: $out"
echo "$out" | grep -q 'keyboard' || fail "the refusal did not name the keyboard: $out"
if [ "$PLATFORM" = ios ]; then $M keyboard --key enter >/dev/null; else $M keyboard --hide >/dev/null; fi
sleep 1
$M tap testid=coveredBtn >/dev/null; outcome "pinned button: tapped"
row "under keyboard" "refused, naming it; tapped once it was hidden"
$M terminate "$APP" >/dev/null 2>&1 || true
echo PASS