<!DOCTYPE HTML>
<html>
    <head>
        <script src="../../resources/testharness.js"></script>
        <script src="../../resources/testharnessreport.js"></script>
    </head>
    <body>
        <script>
promise_test(async (test) => {
    if (window.testRunner)
        testRunner.setUserMediaPermission(false);

    await navigator.mediaDevices.getUserMedia({audio:false, video:true}).then(assert_unreached, (e) => { });
    await navigator.mediaDevices.getUserMedia({audio:true, video:false}).then(assert_unreached, (e) => { });
    await navigator.mediaDevices.getUserMedia({audio:true, video:true}).then(assert_unreached, (e) => { });

    if (window.testRunner)
        testRunner.setUserMediaPermission(true);

    await navigator.mediaDevices.getUserMedia({audio:false, video:true}).then(assert_unreached, (e) => {
        assert_equals(e.name, "NotAllowedError");
    });

    let promise;
    internals.withUserGesture(() => {
        promise = navigator.mediaDevices.getUserMedia({audio:false, video:true});
    });
    await promise;

    // We still have audio denied.
    await navigator.mediaDevices.getUserMedia({audio:true, video:false}).then(assert_unreached, (e) => { });
    await navigator.mediaDevices.getUserMedia({audio:true, video:true}).then(assert_unreached, (e) => { });

    await navigator.mediaDevices.getUserMedia({audio:false, video:true});

    internals.withUserGesture(() => {
        promise = navigator.mediaDevices.getUserMedia({audio:true, video:false});
    });
    await promise;

    // We should neither have audio nor video denied anymore.
    await navigator.mediaDevices.getUserMedia({audio:true, video:false});
    await navigator.mediaDevices.getUserMedia({audio:true, video:true});
}, "Testing getUserMedia with and without user gesture after user denied access");
        </script>
    </body>
</html>
