From a775058a487203049c8b4d281310420a1ff8f71e Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Wed, 1 Dec 2021 21:53:32 +0000 Subject: [PATCH] Bug 1743524 don't expose speaker device info after getUserMedia({audio: true, fake: true}) r=jib Differential Revision: https://phabricator.services.mozilla.com/D132434 --- dom/media/MediaDevices.cpp | 8 +- dom/media/webrtc/tests/mochitests/head.js | 9 +++ .../webrtc/tests/mochitests/mochitest.ini | 1 + ...est_enumerateDevices_getUserMediaFake.html | 75 +++++++++++++++++++ 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 dom/media/webrtc/tests/mochitests/test_enumerateDevices_getUserMediaFake.html diff --git a/dom/media/MediaDevices.cpp b/dom/media/MediaDevices.cpp index 2be6f8c35102..e9a9e53c10d8 100644 --- a/dom/media/MediaDevices.cpp +++ b/dom/media/MediaDevices.cpp @@ -93,11 +93,13 @@ already_AddRefed 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 self(this); MediaManager::Get() ->GetUserMedia(owner, aConstraints, aCallerType) diff --git a/dom/media/webrtc/tests/mochitests/head.js b/dom/media/webrtc/tests/mochitests/head.js index 5ab6d7509c97..75bdc38aedf1 100644 --- a/dom/media/webrtc/tests/mochitests/head.js +++ b/dom/media/webrtc/tests/mochitests/head.js @@ -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: [ diff --git a/dom/media/webrtc/tests/mochitests/mochitest.ini b/dom/media/webrtc/tests/mochitests/mochitest.ini index 1704a900031f..a974a53e1beb 100644 --- a/dom/media/webrtc/tests/mochitests/mochitest.ini +++ b/dom/media/webrtc/tests/mochitests/mochitest.ini @@ -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 = diff --git a/dom/media/webrtc/tests/mochitests/test_enumerateDevices_getUserMediaFake.html b/dom/media/webrtc/tests/mochitests/test_enumerateDevices_getUserMediaFake.html new file mode 100644 index 000000000000..4ffb39c3bb4e --- /dev/null +++ b/dom/media/webrtc/tests/mochitests/test_enumerateDevices_getUserMediaFake.html @@ -0,0 +1,75 @@ + + + + + + + + + +