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

            let tests = [
                {
                    message: "set width, height, and frame rate to valid values.",
                    constraint: { width: 640, height: 480, frameRate: 30 }, 
                    expected: { width: 640, height: 480, frameRate: 30 }, 
                },
                {
                    message: "change width and height, frame rate should remain unchanged.",
                    constraint: { width: 320, height: 240 }, 
                    expected: { width: 320, height: 240, frameRate: 30 }, 
                },
                {
                    message: "the 'exact' constraint can't be satisfied, promise should reject and no settings should change.",
                    constraint: { width: { exact: 3000 } },
                    expected: { width: 320, height: 240, frameRate: 30 },
                    error: "width",
                },
                {
                    message: "the 'min' constraint can't be satisfied, promise should reject and no settings should change.",
                    constraint: { width: 640, height: {min: 3000}, }, 
                    expected: { width: 320, height: 240, frameRate: 30 },
                    error: "height",
                },
                {
                    message: "the 'max' constraint can't be satisfied, promise should reject and no settings should change.",
                    constraint: { frameRate: {max: 8}, }, 
                    expected: { frameRate: 30 },
                    error: "frameRate",
                },
                {
                    message: "the 'exact' constraint can be satisfied.",
                    constraint: { width: { exact: 640 } },
                    expected: { width: 640, height: 480 },
                },
                {
                    message: "the 'ideal' constraint can't be satisfied but the 'min' can, maximum value should be chosen.",
                    constraint: { width: {min: 300, ideal: 5000} }, 
                    expected: { width: 2560, height: 1440 },
                },
                {
                    message: "'ideal' and 'min' constraints can be satisfied, 'ideal' should be chosen.",
                    constraint: { width: {min: 320, ideal: 640}, height: {min: 480, ideal: 720}, }, 
                    expected: { width: 640, height: 720 },
                },
                {
                    message: "ideal width is greater than track capability, should be clamped to the maximum value.",
                    constraint: { width: 5000 },
                    expected: { width: 2560},
                },
                {
                    message: "frameRate value is less than track capabilities, should be clamped to the minimum values.",
                    constraint: { width: 100, height: 100, frameRate: 0.5 },
                    expected: { width: 100, height: 100, frameRate: 1 },
                },
                {
                    message: "set frame rate, width and height should remain unchanged",
                    constraint: { frameRate: 20 },
                    expected: { width: 100, height: 100, frameRate: 20 },
                },
                {
                    message: "illegal facing mode value should be ignored, height should change.",
                    constraint: { facingMode: "xnvironment", height: 720 },
                    expected: { facingMode: "user", width: 1280, height: 720 },
                },
                {
                    message: "unknown constraint should be ignored, frame rate should change.",
                    constraint: { WITDH: 400, frameRate: 30 }, 
                    expected: { width: 1280, frameRate: 30 },
                },
            ];

            let tester = new ConstraintsTest({ video: true }, tests, "Tests applyConstraints on a video stream track.")
                .onStreamReady((s) => {
                    stream = s;
                    shouldBe('stream.getVideoTracks().length', '1');
                    shouldBe('stream.getAudioTracks().length', '0');
                    tester.setStreamTrack(stream.getVideoTracks()[0]);
                })
                .onVideoReady((v) => {
                    video = v;
                    shouldBe('video.videoTracks.length', '1');
                    shouldBe('video.audioTracks.length', '0');
                })
                .start();

        </script>
        <script src="../../resources/js-test-post.js"></script>
    </head>
    <body>
        <video controls id="video"</video>
        <br>
        <div id="div"></div>

    </body>
</html>

