|
| 1 | +<!DOCTYPE html> |
| 2 | +<title>Digital Credential API: get() webdriver tests.</title> |
| 3 | +<link rel="help" href="https://wicg.github.io/digital-credentials/"> |
| 4 | +<script src="/resources/testharness.js"></script> |
| 5 | +<script src="/resources/testharnessreport.js"></script> |
| 6 | +<script src="/resources/testdriver.js?feature=bidi"></script> |
| 7 | +<script src="/resources/testdriver-vendor.js"></script> |
| 8 | +<body></body> |
| 9 | +<script type="module"> |
| 10 | + import { makeGetOptions } from "../support/helper.js"; |
| 11 | + |
| 12 | + promise_test(async (t) => { |
| 13 | + const responseData = "test-response-data"; |
| 14 | + await test_driver.set_virtual_wallet_behavior("respond", "openid4vp-v1-unsigned", { "value": responseData }); |
| 15 | + t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear")); |
| 16 | + await test_driver.bless("user activation"); |
| 17 | + |
| 18 | + const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned" }); |
| 19 | + const result = await navigator.credentials.get(options); |
| 20 | + |
| 21 | + assert_equals(result.protocol, "openid4vp-v1-unsigned"); |
| 22 | + assert_equals(result.data.value, responseData); |
| 23 | + }, "navigator.credentials.get() with respond mode should resolve with the specified data."); |
| 24 | + |
| 25 | + promise_test(async (t) => { |
| 26 | + const complexData = { "a": 1, "b": [2, 3], "c": { "d": 4 } }; |
| 27 | + await test_driver.set_virtual_wallet_behavior("respond", "openid4vp-v1-unsigned", complexData); |
| 28 | + t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear")); |
| 29 | + await test_driver.bless("user activation"); |
| 30 | + |
| 31 | + const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned" }); |
| 32 | + const result = await navigator.credentials.get(options); |
| 33 | + |
| 34 | + assert_equals(result.protocol, "openid4vp-v1-unsigned"); |
| 35 | + assert_equals(result.data.a, 1); |
| 36 | + assert_array_equals(result.data.b, [2, 3]); |
| 37 | + assert_equals(result.data.c.d, 4); |
| 38 | + }, "navigator.credentials.get() with complex data response should resolve with structured data."); |
| 39 | + |
| 40 | + promise_test(async (t) => { |
| 41 | + await test_driver.set_virtual_wallet_behavior("decline"); |
| 42 | + t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear")); |
| 43 | + await test_driver.bless("user activation"); |
| 44 | + |
| 45 | + const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned" }); |
| 46 | + await promise_rejects_dom(t, "NotAllowedError", navigator.credentials.get(options)); |
| 47 | + }, "navigator.credentials.get() with decline mode should reject with NotAllowedError."); |
| 48 | + |
| 49 | + promise_test(async (t) => { |
| 50 | + await test_driver.set_virtual_wallet_behavior("wait"); |
| 51 | + t.add_cleanup(() => test_driver.set_virtual_wallet_behavior("clear")); |
| 52 | + await test_driver.bless("user activation"); |
| 53 | + |
| 54 | + const controller = new AbortController(); |
| 55 | + const options = makeGetOptions({ protocol: "openid4vp-v1-unsigned", signal: controller.signal }); |
| 56 | + const promise = navigator.credentials.get(options); |
| 57 | + |
| 58 | + // Give it some time to make sure it's pending. |
| 59 | + await new Promise(resolve => t.step_timeout(resolve, 100)); |
| 60 | + |
| 61 | + controller.abort(); |
| 62 | + await promise_rejects_dom(t, "AbortError", promise); |
| 63 | + }, "navigator.credentials.get() with wait mode should remain pending until aborted."); |
| 64 | +</script> |
0 commit comments