blob: 3d6917a28a1cab52b3579471c519611bae8eba1d [file] [log] [blame]
<!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: 2000 } },
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: 6}, },
expected: { frameRate: 30 },
error: "frameRate",
},
{
message: "the 'exact' constraint can be satisfied.",
constraint: { width: { exact: 400 } },
expected: { width: 400, height: 240 },
},
{
message: "the 'ideal' constraint can't be satisfied but the 'min' can, max should be chosen.",
constraint: { width: {min: 300, ideal: 5000} },
expected: { width: 1920, height: 240 },
},
{
message: "'ideal' and 'min' constraints can be satisfied, 'ideal' should be chosen.",
constraint: { width: {min: 320, ideal: 1280}, height: {min: 480, ideal: 720}, },
expected: { width: 1280, height: 720 },
},
{
message: "ideal width is greater than track capability, should be clamped to the maximum value.",
constraint: { width: 3000 },
expected: { width: 1920},
},
{
message: "all values are less than track capabilities, should be clamped to the minimum values.",
constraint: { width: 160, height: 120, frameRate: 10 },
expected: { width: 320, height: 240, frameRate: 15 },
},
{
message: "set frame rate, width and height should remain unchanged",
constraint: { frameRate: 20 },
expected: { width: 320, height: 240, frameRate: 20 },
},
{
message: "illegal facing mode value should be ignored, height should change.",
constraint: { facingMode: "environment", height: 400 },
expected: { facingMode: "user", width: 320, height: 400 },
},
{
message: "unknown constraint should be ignored, frame rate should change.",
constraint: { WITDH: 400, frameRate: 30 },
expected: { width: 320, frameRate: 30 },
},
{
message: "aspect ratio should change width and height.",
constraint: { aspectRatio: (4/3).toFixed(4) },
expected: { width: 320, height: 240 },
},
{
message: "new aspect ratio should again change width and height.",
constraint: { aspectRatio: (16/9).toFixed(4) },
expected: { width: 320, height: 180 },
},
{
message: "when aspect ratio has been set, changing width should change height.",
constraint: { width: 1920 },
expected: { width: 1920, height: 1080},
},
{
message: "when aspect ratio has been set, changing height should change width.",
constraint: { height: 576 },
expected: { width: 1024, height: 576},
},
];
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>