Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 3 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /credential-management/credentialscontainer-get-basics.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>Credential Management API: get() basics.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async (t) => {
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get()
);
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({})
);
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({ x: "y" })
);
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({ x: "y", y: "z" })
);
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({ x: "y" })
);
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({ mediation: "required" })
);
const abortController = new AbortController();
const { signal } = abortController;
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({ signal })
);
await promise_rejects_dom(
t,
"NotSupportedError",
navigator.credentials.get({ signal, mediation: "required" })
);
}, "Calling navigator.credentials.get() without a valid matching interface.");
promise_test(function(t) {
const controller = new AbortController();
controller.abort("custom reason");
return promise_rejects_exactly(t, "custom reason",
navigator.credentials.get({ signal: controller.signal }));
}, "navigator.credentials.get() aborted with custom reason");
promise_test(async function(t) {
const reasons = [{}, [], new Error("custom error")];
for (let reason of reasons) {
const result = navigator.credentials.get({ signal: AbortSignal.abort(reason) });
await promise_rejects_exactly(t, reason, result);
}
}, "navigator.credentials.get() aborted with different objects");
promise_test(function(t) {
const error = new Error("custom error");
const controller = new AbortController();
const result = navigator.credentials.get({ signal: controller.signal });
controller.abort(error); // aborted after the promise is created
return promise_rejects_exactly(t, error, result);
}, "navigator.credentials.get() rejects when aborted after the promise creation");
</script>