blob: af5438625eaaf0f8999f8827034acaffc54783de [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test passing capture device IDs to getUserMedia</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
let deviceIds = [];
if (window.testRunner)
testRunner.setUserMediaPermission(true);
promise_test((test) => {
return navigator.mediaDevices.enumerateDevices()
.then((devices) => {
devices.forEach((device) => {
let kind = device.kind == "audioinput" ? "audio" : "video";
deviceIds.push({ type: kind, id : device.deviceId});
});
});
}, "Collect device IDs");
let constraints = { };
promise_test((test) => {
deviceIds.forEach((info) => {
constraints[info.type] = { deviceId: { exact: info.id } };
});
var audioTrack, videoTrack;
return navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
assert_equals(stream.getAudioTracks().length, 1, "correct number of audio tracks");
assert_equals(stream.getVideoTracks().length, 1, "correct number of audio tracks");
videoTrack = stream.getVideoTracks()[0];
audioTrack = stream.getAudioTracks()[0];
return navigator.mediaDevices.enumerateDevices();
}).then(devices => {
var ids = devices.map(device => device.deviceId);
assert_true(ids.indexOf(videoTrack.getSettings().deviceId) !== -1 , "deviceId for video track should be respected");
assert_true(ids.indexOf(audioTrack.getSettings().deviceId) !== -1 , "deviceId for audio track should be respected");
assert_equals(audioTrack.getSettings().groupId, videoTrack.getSettings().groupId, "groupId should match");
})
}, "Pass device IDs as exact constraints");
promise_test((test) => {
deviceIds.forEach((info) => {
constraints[info.type] = { deviceId: info.id };
});
return navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
assert_equals(stream.getAudioTracks().length, 1, "correct number of audio tracks");
assert_equals(stream.getVideoTracks().length, 1, "correct number of audio tracks");
})
}, "Pass device IDs as optional constraints");
</script>
</head>
<body>
</body>
</html>