diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html')
-rw-r--r-- | testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html b/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html new file mode 100644 index 0000000000..3907f85450 --- /dev/null +++ b/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html @@ -0,0 +1,77 @@ +<!DOCTYPE html> +<link rel="help" href="https://github.com/WICG/WebOTP"> +<title>Tests OTPCredential</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script type="module"> +import {Status, expectOTPRequest} from './support/otpcredential-helper.js'; + +promise_test(async t => { + await expectOTPRequest().andReturn( + () => ({status: Status.SUCCESS, otp: "ABC"})); + + let cred = await navigator.credentials.get({otp: {transport: ["sms"]}}); + + assert_equals(cred.code, "ABC"); +}, 'Basic usage'); + +promise_test(async t => { + await expectOTPRequest().andReturn( + () => ({status: Status.SUCCESS, otp: "ABC"})); + await expectOTPRequest().andReturn( + () => ({status: Status.SUCCESS, otp: "ABC2"})); + + let sms1 = navigator.credentials.get({otp: {transport: ["sms"]}}); + let sms2 = navigator.credentials.get({otp: {transport: ["sms"]}}); + + let cred2 = await sms2; + let cred1 = await sms1; + + assert_equals(cred1.code, "ABC"); + assert_equals(cred2.code, "ABC2"); +}, 'Handle multiple requests in different order.'); + +promise_test(async t => { + await expectOTPRequest().andReturn(() => ({status: Status.CANCELLED})); + await expectOTPRequest().andReturn( + () => ({status: Status.SUCCESS, otp: "success"})); + + let cancelledRequest = navigator.credentials.get({otp: {transport: ["sms"]}}); + let successfulCred = + await navigator.credentials.get({otp: {transport: ["sms"]}}); + + assert_equals(successfulCred.code, "success"); + + try { + await cancelledRequest; + assert_unreached('Expected AbortError to be thrown.'); + } catch (error) { + assert_equals(error.name, "AbortError"); + } +}, 'Handle multiple requests with success and error.'); + +promise_test(async t => { + await expectOTPRequest().andReturn(() => ({status: Status.CANCELLED})); + + await promise_rejects_dom(t, 'AbortError', navigator.credentials.get( + {otp: {transport: ["sms"]}})); +}, 'Deal with cancelled requests'); + +promise_test(async t => { + const controller = new AbortController(); + const signal = controller.signal; + + controller.abort(); + await promise_rejects_dom(t, 'AbortError', navigator.credentials.get( + {otp: {transport: ["sms"]}, signal: signal})); +}, 'Should abort request'); + +promise_test(async t => { + const controller = new AbortController(); + const signal = controller.signal; + + controller.abort('CustomError'); + await promise_rejects_exactly(t, 'CustomError', navigator.credentials.get( + {otp: {transport: ["sms"]}, signal: signal})); +}, 'Should abort request with reason'); +</script> |