<!DOCTYPE HTML>
<html>
    <head>
        <script src="../../resources/js-test-pre.js"></script>
        <script>

            window.jsTestIsAsync = true;

            if (window.internals)
                internals.settings.setMediaCaptureRequiresSecureConnection(true);

            if (window.testRunner) {
                testRunner.waitUntilDone();
                testRunner.setUserMediaPermission(true);
                testRunner.dumpAsText();
            }

            window.addEventListener("load", async () => {
                if (location.protocol != "http:" || location.host != "127.0.0.1:8000") {
                    testFailed("This test must be run from http://127.0.0.1:8000");
                    finishJSTest();
                    return;
                }

                try {
                    await window.navigator.mediaDevices.getUserMedia({audio:true});
                    testPassed("getUserMedia succeeded");
                } catch(err) {
                    testFailed(`getUserMedia should have succeeded but failed with error "${err}"`);
                }

                finishJSTest();
            });

            description("Tests that getUserMedia is allowed from the loopback IP address when secure connection is required.");
        </script>
        <script src="../../js-test-resources/js-test-post.js"></script>
    </head>
    <body>
        <div id="console"></div>
    </body>
</html>
