also looking at this
fix(android): resolve share() with whether the person picked an app
#210
12 files
+399
-56
| @@ -64,14 +64,14 @@ | ||
| 64 | 64 | return { code: String(error.code || ''), message: String(error.message || error) } |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | function withTimeout(run) { | |
| 67 | function withTimeout(run, timeoutMs) { | |
| 68 | 68 | return new Promise(function (resolve) { |
| 69 | 69 | var settled = false |
| 70 | 70 | var timer = setTimeout(function () { |
| 71 | 71 | if (settled) return |
| 72 | 72 | settled = true |
| 73 | 73 | resolve({ state: 'timeout' }) |
| 74 | }, CASE_TIMEOUT_MS) | |
| 74 | }, timeoutMs || CASE_TIMEOUT_MS) | |
| 75 | 75 | |
| 76 | 76 | function finish(value) { |
| 77 | 77 | if (settled) return |
| @@ -198,6 +198,43 @@ | ||
| 198 | 198 | }) |
| 199 | 199 | } |
| 200 | 200 | }, |
| 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 | }, | |
| 201 | 238 | { |
| 202 | 239 | // Android's equivalent gate. With push disabled the generator emits a |
| 203 | 240 | // literal reject call rather than a Firebase block, so the rejection |