blob: 29b72c74a6fc78f3cdaed7ff5704797914bf1abd [file] [edit]
<!DOCTYPE html>
<title>Digital Identity Credential tests.</title>
<link rel="help" href="https://wicg.github.io/digital-identities/">
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<body>
<script type="module">
import { buildValidNavigatorIdentityRequest, requestIdentityWithActivation } from './support/helper.js';
// This regex removes the filename from the path so that we just get
// the directory.
const host = get_host_info();
const basePath = window.location.pathname.replace(/\/[^\/]*$/, '/');
const remoteBaseURL = host.HTTPS_REMOTE_ORIGIN + basePath;
async function createIframeAndWaitForMessage(test, iframeUrl) {
const messageWatcher = new EventWatcher(test, window, "message");
var iframe = document.createElement("iframe");
iframe.src = iframeUrl;
document.body.appendChild(iframe);
const message = await messageWatcher.wait_for("message");
return message.data;
}
// Requires browser to have mode where OS-presented digital-identity-prompt is
// bypassed in favour of returning "fake_test_token" directly.
promise_test(async t => {
let request = buildValidNavigatorIdentityRequest();
request.digital.providers = undefined;
await promise_rejects_js(t, TypeError, requestIdentityWithActivation(test_driver, request));
}, "navigator.identity.get() API fails if DigitalCredentialRequestOptions::providers is not specified.");
promise_test(async t => {
let request = buildValidNavigatorIdentityRequest();
request.digital.providers = [];
await promise_rejects_js(t, TypeError, requestIdentityWithActivation(test_driver, request));
}, "navigator.identity.get() API fails if there are no providers.");
promise_test(async t=> {
const message = await createIframeAndWaitForMessage(
t, remoteBaseURL + "support/iframe.html");
assert_equals(message.result, "Fail");
assert_equals(message.errorType, "NotAllowedError");
}, "navigator.identity.get() fails in cross-origin iframe");
</script>