<!DOCTYPE html><!-- webkit-test-runner [ WebAuthenticationModernEnabled=true ] -->
<title>Web Authentication API: PublicKeyCredential's [[create]] success cases with a mock u2f authenticator.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./resources/util.js"></script>
<script src="./resources/cbor.js"></script>
<script>
    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential);
        });
    }, "PublicKeyCredential's [[create]] with minimum options in a mock u2f authenticator.");

    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential);
        });
    }, "PublicKeyCredential's [[create]] with excludeCredentials in a mock u2f authenticator.");

    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }], // The content doesn't matter.
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential);
        });
    }, "PublicKeyCredential's [[create]] with excludeCredentials in a mock u2f authenticator. 2");

    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential);
        });
    }, "PublicKeyCredential's [[create]] with test of user presence in a mock u2f authenticator.");

    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                attestation: "none",
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential);
        });
    }, "PublicKeyCredential's [[create]] with none attestation in a mock u2f authenticator.");

    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                attestation: "indirect",
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential, false);
        });
    }, "PublicKeyCredential's [[create]] with indirect attestation in a mock u2f authenticator.");

    promise_test(t => {
        const options = {
            publicKey: {
                rp: {
                    name: "localhost",
                },
                user: {
                    name: "John Appleseed",
                    id: Base64URL.parse(testUserhandleBase64),
                    displayName: "Appleseed",
                },
                challenge: Base64URL.parse("MTIzNDU2"),
                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                attestation: "direct",
            }
        };

        if (window.internals)
            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
        return navigator.credentials.create(options).then(credential => {
            checkU2fMakeCredentialResult(credential, false);
        });
    }, "PublicKeyCredential's [[create]] with direct attestation in a mock u2f authenticator.");
</script>
