<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="../../resources/testharness.js"></script>
    <script src="../../resources/testharnessreport.js"></script>
</head>
<body>
    <video id="video"></video>
    <script>
    let setup = async (test) => {
        if (!window.testRunner)
            return Promise.reject("test requires internal API");

        test.add_cleanup(() => {
            testRunner.resetMockMediaDevices();
        });
    }

    promise_test(async (test) => {
        await setup(test);

        // camera device should be the default device.
        testRunner.addMockCameraDevice("myCamera", "my new camera", { facingMode: "unknown", fillColor: "green" });

        let stream = await navigator.mediaDevices.getUserMedia({ video: true });
        assert_equals(stream.getVideoTracks()[0].label, "my new camera");

        stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } });
        assert_equals(stream.getVideoTracks()[0].label, "Mock video device 1");

        stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } });
        assert_equals(stream.getVideoTracks()[0].label, "Mock video device 2");
    }, "Check default cameras in case of default device having an unknown facing mode");
    </script>
</body>
</html>
