test_webauthn_webdriver_virtual_authenticator.html (1852B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <head> 4 <title>Tests for WebDriver Virtual Authenticator Extension for W3C Web Authentication</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script type="text/javascript" src="u2futil.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 </head> 9 <body> 10 11 <h1>Tests for WebDriver Virtual Authenticator Extension for W3C Web Authentication</h1> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1460986">Mozilla Bug 1460986</a> 13 14 <script class="testbody" type="text/javascript"> 15 "use strict"; 16 17 function arrivingHereIsGood(aResult) { 18 ok(true, "Good result! Received a: " + aResult); 19 } 20 21 function arrivingHereIsBad(aResult) { 22 ok(false, "Bad result! Received a: " + aResult); 23 } 24 25 function expectNotAllowedError(aResult) { 26 ok(aResult == "NotAllowedError", "Expecting a NotAllowedError, got " + aResult); 27 } 28 29 function getAssertion(id) { 30 let chall = new Uint8Array(16); 31 crypto.getRandomValues(chall); 32 33 let options = { 34 challenge: chall, 35 allowCredentials: [ { type: "public-key", id } ], 36 }; 37 38 return navigator.credentials.get({publicKey: options}); 39 } 40 41 add_task(async function test_add_and_remove_credential() { 42 let authenticatorId = await addVirtualAuthenticator(); 43 let credIdB64 = await addCredential(authenticatorId, document.domain); 44 let credId = base64ToBytesUrlSafe(credIdB64); 45 46 await getAssertion(credId) 47 .then(arrivingHereIsGood) 48 .catch(arrivingHereIsBad); 49 50 await removeCredential(authenticatorId, credIdB64); 51 await getAssertion(credId) 52 .then(arrivingHereIsBad) 53 .catch(e => expectNotAllowedError(e.name)); 54 }); 55 </script> 56 57 </body> 58 </html>