[sms] Expose manual cancellations/aborts to developers
Bug: 979265
Change-Id: I8b080fe35fc44c16af5b149bb23c9a5e7e57af06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1707827
Reviewed-by: Ayu Ishii <ayui@chromium.org>
Commit-Queue: Sam Goto <goto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679667}
diff --git a/sms/interceptor.https.html b/sms/interceptor.https.html
index b7e8fd5..86b2192 100644
--- a/sms/interceptor.https.html
+++ b/sms/interceptor.https.html
@@ -165,4 +165,21 @@
let sms = await navigator.sms.receive({timeout: undefined});
assert_equals(sms.content, "hello");
}, 'Should use default value for timeout (undefined)');
+
+promise_test(async t => {
+ await expect(receive).andReturn((timeout) => {
+ return Promise.resolve({
+ status: Status.kCancelled,
+ });
+ });
+
+ try {
+ await navigator.sms.receive();
+ assert_unreached('Expected CancelledError to be thrown.');
+ } catch (error) {
+ assert_equals(error.name, "AbortError");
+ assert_equals(error.message, "SMSReceiver was aborted.");
+ }
+}, 'Deal with cancelled requests');
+
</script>
diff --git a/sms/sms_provider.js b/sms/sms_provider.js
index 6a54e47..4506135 100644
--- a/sms/sms_provider.js
+++ b/sms/sms_provider.js
@@ -73,6 +73,7 @@
Status.kSuccess = blink.mojom.SmsStatus.kSuccess;
Status.kTimeout = blink.mojom.SmsStatus.kTimeout;
+ Status.kCancelled = blink.mojom.SmsStatus.kCancelled;
return smsReceiverImpl;
}