blob: 19888254730f16832a02599cc9d05be458604121 [file] [log] [blame]
<!DOCTYPE html>
<title>Credential Management API: store() basics.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function asciiToUint8Array(str)
{
var chars = [];
for (var i = 0; i < str.length; ++i)
chars.push(str.charCodeAt(i));
return new Uint8Array(chars);
}
function hexStringToUint8Array(hexString)
{
if (hexString.length % 2 != 0)
throw "Invalid hexString";
var arrayBuffer = new Uint8Array(hexString.length / 2);
for (var i = 0; i < hexString.length; i += 2) {
var byteValue = parseInt(hexString.substr(i, 2), 16);
if (byteValue == NaN)
throw "Invalid hexString";
arrayBuffer[i/2] = byteValue;
}
return arrayBuffer;
}
promise_test(async function(t) {
const options = {
publicKey: {
rp: {
name: "localhost",
},
user: {
name: "John Appleseed",
id: asciiToUint8Array("123456"),
displayName: "Appleseed",
},
challenge: asciiToUint8Array("123456"),
pubKeyCredParams: [{ type: "public-key", alg: -7 }],
}
};
// A mock attestation object
internals.mockCredentialsMessenger.setCreationReturnBundle(hexStringToUint8Array('00'), hexStringToUint8Array('01'));
const credential = await navigator.credentials.create(options);
return promise_rejects(t, "NotSupportedError",
navigator.credentials.store(credential));
}, "navigator.credentials.store().");
</script>