Skip to content

Commit

Permalink
Add successful gUM calls to existing WPT and mochitests to let them c…
Browse files Browse the repository at this point in the history
…ontinue to test full device information exposure in enumerateDevices().

This is required by spec. See
w3c/mediacapture-main#641 and
w3c/mediacapture-main#773 for details.

Also fixes test_enumerateDevices_getUserMediaFake.html to run on macOS outside automation.

Differential Revision: https://phabricator.services.mozilla.com/D154302

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1528042
gecko-commit: 173f133fb868ce50a9feec4e26496be7f7aeae11
gecko-reviewers: karlt
  • Loading branch information
jan-ivar authored and moz-wptsync-bot committed May 26, 2023
1 parent cba1008 commit afd6965
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
assert_equals(device1.deviceId, "", "deviceId is empty before capture");
assert_equals(device1.groupId, "", "groupId is empty before capture");
assert_equals(device1.label, "", "label is empty before capture");
assert_in_array(device1.kind, ["audioinput", "audiooutput", "videoinput", "kind is set to a valid value before capture"]);
assert_in_array(device1.kind, ["audioinput", "audiooutput", "videoinput"],
"kind is set to a valid value before capture");
}
}
/* Additionally, at most one device of each kind
Expand All @@ -52,8 +53,8 @@
}, testName);
}

doTest(false, "enumerateDevices returns expected mostly empty objects in case device-info permission is not granted");
doTest(true, "enumerateDevices returns expected objects in case device-info permission is granted");
doTest(false, "enumerateDevices exposes mostly empty objects ahead of successful getUserMedia call");
doTest(true, "enumerateDevices exposes expected objects after successful getUserMedia call");
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions mediacapture-streams/MediaDevices-getUserMedia.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ <h1 class="instructions">Description</h1>
promise_test(async t => {
// Both permissions are needed at some point, asking both at once
await setMediaPermission();
// A successful camera gUM call is needed to expose camera information
const afterGum = await navigator.mediaDevices.getUserMedia({video: true});
afterGum.getTracks()[0].stop();

assert_true(navigator.mediaDevices.getSupportedConstraints()["groupId"],
"groupId should be supported");
const devices = await navigator.mediaDevices.enumerateDevices();
Expand All @@ -66,6 +70,10 @@ <h1 class="instructions">Description</h1>
}, 'groupId is correctly supported by getUserMedia() for video devices');

promise_test(async t => {
// A successful microphone gUM call is needed to expose microphone information
const afterGum = await navigator.mediaDevices.getUserMedia({audio: true});
afterGum.getTracks()[0].stop();

assert_true(navigator.mediaDevices.getSupportedConstraints()["groupId"],
"groupId should be supported");
const devices = await navigator.mediaDevices.enumerateDevices();
Expand Down
29 changes: 18 additions & 11 deletions mediacapture-streams/MediaStreamTrack-getSettings.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,25 @@
}, 'A device can be opened twice with different resolutions requested');

promise_test(async t => {
// getUserMedia needs to be called before deviceIds and groupIds are exposed
const afterGum = await navigator.mediaDevices.getUserMedia({
video: true, audio: true
});
afterGum.getTracks().forEach(track => track.stop());

const devices = await navigator.mediaDevices.enumerateDevices();
const inputDevices = devices.filter(d => d.kind != "audiooutput");
assert_greater_than(inputDevices.length, 0);
for (const device of inputDevices) {
const device_id_constraint = {deviceId: {exact: device.deviceId}};
const constraints = device.kind == "audioinput"
? {audio: device_id_constraint}
: {video: device_id_constraint};

const stream = await navigator.mediaDevices.getUserMedia(constraints);
assert_true(stream.getTracks()[0].getSettings().groupId === device.groupId, "device groupId");
assert_greater_than(device.groupId.length, 0);
const inputDevices = devices.filter(({kind}) => kind != "audiooutput");
assert_greater_than(inputDevices.length, 1, "have at least 2 test devices");
for (const {kind, deviceId, groupId} of inputDevices) {
const type = {videoinput: "video", audioinput: "audio"}[kind];
const stream = await navigator.mediaDevices.getUserMedia({
[type]: {deviceId: {exact: deviceId}}
});
const [track] = stream.getTracks();
const settings = track.getSettings();
track.stop();
assert_true(settings.groupId == groupId, "device groupId");
assert_greater_than(settings.groupId.length, 0, "groupId is not empty");
}
}, 'groupId is correctly reported by getSettings() for all input devices');

Expand Down

0 comments on commit afd6965

Please sign in to comment.