<!DOCTYPE html><!-- webkit-test-runner [ WebAuthenticationModernEnabled=true ] -->
<title>Web Authentication API: PublicKeyCredential's [[create]] failure cases with a mock hid authenticator.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/util.js"></script>
<script>
   promise_test(function(t) {
        const options = {
            publicKey: {
                rp: {
                    name: "example.com"
                },
                user: {
                    name: "John Appleseed",
                    id: asciiToUint8Array("123456"),
                    displayName: "John",
                },
                challenge: asciiToUint8Array("123456"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                timeout: 10
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testDummyMessagePayloadBase64] } });
        return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
    }, "PublicKeyCredential's [[create]] with malicious payload in a mock hid authenticator.");

    promise_test(function(t) {
        const options = {
            publicKey: {
                rp: {
                    name: "example.com"
                },
                user: {
                    name: "John Appleseed",
                    id: asciiToUint8Array("123456"),
                    displayName: "John",
                },
                challenge: asciiToUint8Array("123456"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                authenticatorSelection: { requireResidentKey: true },
                timeout: 10
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
        return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
    }, "PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator.");

    promise_test(function(t) {
        const options = {
            publicKey: {
                rp: {
                    name: "example.com"
                },
                user: {
                    name: "John Appleseed",
                    id: asciiToUint8Array("123456"),
                    displayName: "John",
                },
                challenge: asciiToUint8Array("123456"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                authenticatorSelection: { authenticatorAttachment: "cross-platform", requireResidentKey: true, userVerification: "required" },
                timeout: 10
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
        return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
    }, "PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.");

   promise_test(function(t) {
       const options = {
           publicKey: {
               rp: {
                   name: "example.com"
               },
               user: {
                   name: "John Appleseed",
                   id: asciiToUint8Array("123456"),
                   displayName: "John",
               },
               challenge: asciiToUint8Array("123456"),
               pubKeyCredParams: [{ type: "public-key", alg: -7 }]
           }
       };

       if (window.internals)
           internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testCtapErrCredentialExcludedOnlyResponseBase64] } });
       return promiseRejects(t, "InvalidStateError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the authenticator.");
   }, "PublicKeyCredential's [[create]] with InvalidStateError in a mock hid authenticator.");
</script>
