[WebAuthN] Implement authenticatorMakeCredential
[WebKit-https.git] / LayoutTests / http / wpt / credential-management / credentialscontainer-store-basics.https.html
1 <!DOCTYPE html>
2 <title>Credential Management API: store() basics.</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script>
6     function asciiToUint8Array(str)
7     {
8         var chars = [];
9         for (var i = 0; i < str.length; ++i)
10             chars.push(str.charCodeAt(i));
11         return new Uint8Array(chars);
12     }
13     function hexStringToUint8Array(hexString)
14     {
15         if (hexString.length % 2 != 0)
16             throw "Invalid hexString";
17         var arrayBuffer = new Uint8Array(hexString.length / 2);
18
19         for (var i = 0; i < hexString.length; i += 2) {
20             var byteValue = parseInt(hexString.substr(i, 2), 16);
21             if (byteValue == NaN)
22                 throw "Invalid hexString";
23             arrayBuffer[i/2] = byteValue;
24         }
25
26         return arrayBuffer;
27     }
28
29     promise_test(async function(t) {
30         const options = {
31             publicKey: {
32                 rp: {
33                     name: "localhost",
34                 },
35                 user: {
36                     name: "John Appleseed",
37                     id: asciiToUint8Array("123456"),
38                     displayName: "Appleseed",
39                 },
40                 challenge: asciiToUint8Array("123456"),
41                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
42             }
43         };
44         // A mock attestation object
45         internals.mockCredentialsMessenger.setCreationReturnBundle(hexStringToUint8Array('00'), hexStringToUint8Array('01'));
46         const credential = await navigator.credentials.create(options);
47
48         return promise_rejects(t, "NotSupportedError",
49             navigator.credentials.store(credential));
50     }, "navigator.credentials.store().");
51 </script>