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/driver.htmlmodified+39-2
Changes to scripts/mobile-e2e/driver.html
@@ -64,14 +64,14 @@
6464 return { code: String(error.code || ''), message: String(error.message || error) }
6565 }
6666
67 function withTimeout(run) {
67 function withTimeout(run, timeoutMs) {
6868 return new Promise(function (resolve) {
6969 var settled = false
7070 var timer = setTimeout(function () {
7171 if (settled) return
7272 settled = true
7373 resolve({ state: 'timeout' })
74 }, CASE_TIMEOUT_MS)
74 }, timeoutMs || CASE_TIMEOUT_MS)
7575
7676 function finish(value) {
7777 if (settled) return
@@ -198,6 +198,43 @@
198198 })
199199 }
200200 },
201 {
202 // Android does not gate sharing on a flag, so its refusal is the one
203 // both platforms share: an empty string is nothing to share. It is
204 // refused before any menu opens, and used to be refused by nobody -
205 // the call returned undefined whatever happened (#203).
206 name: 'share.empty.rejects',
207 platforms: ['android'],
208 run: function () {
209 return withTimeout(function () { return window.craft.share('') }).then(function (outcome) {
210 if (outcome.state === 'timeout') return 'share never settled'
211 if (outcome.state === 'resolved') return 'share resolved with ' + JSON.stringify(outcome.value) + ' for an empty string'
212 if (outcome.error.message.indexOf('Nothing to share') === -1)
213 return 'message is ' + JSON.stringify(outcome.error.message)
214 })
215 }
216 },
217 {
218 // The cancellation path, and the one case that needs a person. The
219 // page announces that it is about to open the share menu, the harness
220 // waits until the menu is really in front, screenshots it and presses
221 // Back, and the promise has to resolve false. False, not a rejection:
222 // dismissing the menu is a choice the person made, not an error.
223 //
224 // A share that resolved false on its own would pass this without a
225 // menu ever appearing, which is why the harness also fails the run
226 // when it was asked to dismiss a menu and never saw one.
227 name: 'share.dismissed.resolvesFalse',
228 platforms: ['android'],
229 run: function () {
230 emit({ event: 'awaiting', name: 'share.dismissed.resolvesFalse', need: 'dismiss-share-menu' })
231 return withTimeout(function () { return window.craft.share('craft e2e ' + NONCE, 'Craft E2E') }, 60000).then(function (outcome) {
232 if (outcome.state === 'timeout') return 'share never settled after the menu was dismissed'
233 if (outcome.state === 'rejected') return 'share rejected: ' + outcome.error.message
234 if (outcome.value !== false) return 'share resolved with ' + JSON.stringify(outcome.value) + ', expected false for a dismissed menu'
235 })
236 }
237 },
201238 {
202239 // Android's equivalent gate. With push disabled the generator emits a
203240 // literal reject call rather than a Firebase block, so the rejection