Bug 1743524 don't expose speaker device info after getUserMedia({audio: true, fake: true}) r=jib

Differential Revision: https://phabricator.services.mozilla.com/D132434
This commit is contained in:
Karl Tomlinson 2021-12-01 21:53:32 +00:00
Родитель 079496ab6c
Коммит a775058a48
4 изменённых файлов: 90 добавлений и 3 удалений

Просмотреть файл

@ -93,11 +93,13 @@ already_AddRefed<Promise> MediaDevices::GetUserMedia(
}
}
}
bool haveFake = aConstraints.mFake.WasPassed() && aConstraints.mFake.Value();
const OwningBooleanOrMediaTrackConstraints& audio = aConstraints.mAudio;
bool isMicrophone =
audio.IsBoolean()
? audio.GetAsBoolean()
: !audio.GetAsMediaTrackConstraints().mMediaSource.WasPassed();
!haveFake &&
(audio.IsBoolean()
? audio.GetAsBoolean()
: !audio.GetAsMediaTrackConstraints().mMediaSource.WasPassed());
RefPtr<MediaDevices> self(this);
MediaManager::Get()
->GetUserMedia(owner, aConstraints, aCallerType)

Просмотреть файл

@ -418,6 +418,15 @@ function pushPrefs(...p) {
return SpecialPowers.pushPrefEnv({ set: p });
}
async function withPrefs(prefs, func) {
await SpecialPowers.pushPrefEnv({ set: prefs });
try {
return await func();
} finally {
await SpecialPowers.popPrefEnv();
}
}
function setupEnvironment() {
var defaultMochitestPrefs = {
set: [

Просмотреть файл

@ -61,6 +61,7 @@ scheme=http
[test_enumerateDevices.html]
[test_enumerateDevices_navigation.html]
skip-if = true # Disabled because it is a racy test and causes timeouts, see bug 1650932
[test_enumerateDevices_getUserMediaFake.html]
[test_groupId.html]
[test_setSinkId.html]
skip-if =

Просмотреть файл

@ -0,0 +1,75 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="mediaStreamPlayback.js"></script>
</head>
<body>
<script>
"use strict";
createHTML({
title: "Test enumerateDevices() after fake getUserMedia()",
bug: "1743524"
});
runTest(async () => {
await pushPrefs(
["media.setsinkid.enabled", true],
// This test uses real devices because fake devices are not grouped with
// audiooutput devices.
["media.navigator.streams.fake", false],
// Non empty media.audio_loopback_dev would disable fake:true for streams
// returned from getUserMedia().
["media.audio_loopback_dev", ""]);
const devices = navigator.mediaDevices;
{
// `fake:true` means that getUserMedia() resolves without any permission
// check, and so this should not be sufficient to expose real device info.
const stream = await devices.getUserMedia({ audio: true, fake: true });
// permission.disabled exposes labels - bug 1528042
const list = await withPrefs(
[["media.navigator.permission.disabled", false]],
async () => devices.enumerateDevices());
stream.getTracks()[0].stop();
const labeledDevices = list.filter(({label}) => label != "");
is(labeledDevices.length, 0, "number of labeled devices after fake gUM");
const outputDevices = list.filter(({kind}) => kind == "audiooutput");
is(outputDevices.length, 0, "number of output devices after fake gUM");
}
{
// Check without `fake:true` to verify assumptions about existing devices.
const streamPromise = devices.getUserMedia({ audio: true });
if (navigator.userAgent.includes("Mac OS X")) {
let rejection = "resolved";
try {
await streamPromise;
} catch (e) {
rejection = e.name;
}
todo_isnot(rejection, "NotFoundError",
"Expecting no real audioinput device on Mac.");
return;
}
const stream = await streamPromise;
{
const list = await devices.enumerateDevices();
// input labels disappear when the track is stopped - bug 1528042
const unlabeledAudioDevices =
list.filter(({ kind, label }) => {
return kind != "videoinput" && label == ""
});
is(unlabeledAudioDevices.length, 0,
"number of unlabeled audio devices after real gUM");
}
stream.getTracks()[0].stop();
const list = await devices.enumerateDevices();
const outputDevices = list.filter(({ kind, label }) => {
return kind == "audiooutput" && label != "";
});
isnot(outputDevices.length, 0, "number of output devices after real gUM");
}
});
</script>
</body>
</html>