blob: cf436bc33974b36c6ff3c74ccf1ca61d289f6c15 [file] [log] [blame]
<!DOCTYPE html>
<title>Credential Manager: unit test for the Web Authentication Testing API.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="/gen/layout_test_data/mojo/public/js/mojo_bindings_lite.js"></script>
<script src="/gen/mojo/public/mojom/base/time.mojom-lite.js"></script>
<script src="/gen/url/mojom/url.mojom-lite.js"></script>
<script src="/gen/third_party/blink/public/mojom/webauthn/authenticator.mojom-lite.js"></script>
<script src="/gen/third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-lite.js"></script>
<script src="resources/test-inputs.js"></script>
<script src="resources/virtual-navigator-credentials.js"></script>
<script>
promise_test(async _ => {
assert_true(!!navigator.credentials.test);
assert_false(!!window.mockAuthenticator);
}, "The WebAuthn Testing API should be active, and the mocked out API should not.");
promise_test(async _ => {
let authenticators = await navigator.credentials.test.authenticators();
assert_equals(authenticators.length, 0);
let testAuthenticator1 = await navigator.credentials.test.createAuthenticator();
let testAuthenticator2 = await navigator.credentials.test.createAuthenticator();
let id1 = await testAuthenticator1.id();
let id2 = await testAuthenticator2.id();
authenticators = await navigator.credentials.test.authenticators();
assert_equals(authenticators.length, 2);
assert_true(await navigator.credentials.test.removeAuthenticator(id1));
assert_false(await navigator.credentials.test.removeAuthenticator(id1));
authenticators = await navigator.credentials.test.authenticators();
assert_equals(authenticators.length, 1);
assert_equals(await authenticators[0].id(), id2);
await navigator.credentials.test.clearAuthenticators();
authenticators = await navigator.credentials.test.authenticators();
assert_equals(authenticators.length, 0);
}, "Methods of VirtualAuthenticatorManager work.");
promise_test(async _ => {
let testAuthenticator = await navigator.credentials.test.createAuthenticator();
let id = await testAuthenticator.id();
assert_equals(await testAuthenticator.uniqueId(), id);
let keys = await testAuthenticator.registeredKeys();
assert_equals(keys.length, 0);
let keyHandle1 = new TextEncoder("utf-8").encode("foo");
assert_true(await testAuthenticator.generateAndRegisterKey(keyHandle1, "test.domain"));
// Re-registrations (with the same key handle) should not be allowed.
assert_false(await testAuthenticator.generateAndRegisterKey(keyHandle1, "test.domain"));
// SHA-256 digest of UTF-8 string "test.domain".
let expectedApplicationParameter = new Uint8Array([
0xf8, 0x9c, 0x97, 0x3e, 0x36, 0xf6, 0xf6, 0x26, 0x09, 0x6e, 0xab, 0xf2, 0xe2, 0xd2, 0xcb, 0xf2,
0x23, 0x39, 0xf9, 0x41, 0x36, 0x9a, 0x0a, 0x20, 0x33, 0x6c, 0x56, 0x95, 0x5d, 0x59, 0xbc, 0x54]);
keys = await testAuthenticator.registeredKeys();
assert_equals(keys.length, 1);
assert_equals(keys[0].applicationParameter.toString(), expectedApplicationParameter.toString());
assert_equals(keys[0].keyHandle.toString(), keyHandle1.toString());
assert_equals(keys[0].counter, 1);
let keyHandle2 = new TextEncoder("utf-8").encode("bar");
assert_true(await testAuthenticator.generateAndRegisterKey(keyHandle2, "test.domain"));
keys = await testAuthenticator.registeredKeys();
assert_equals(keys.length, 2);
keys = await testAuthenticator.clearRegisteredKeys();
keys = await testAuthenticator.registeredKeys();
assert_equals(keys.length, 0);
}, "Methods of VirtualAuthenticator work.");
promise_test(_ => navigator.credentials.test.clearAuthenticators(), "Clean up testing environment.");
</script>