Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[MediaStream] enumerateDevices should not exposed devices that can no…
…t be used https://bugs.webkit.org/show_bug.cgi?id=258993 rdar://110210394 Reviewed by Jer Noble and Youenn Fablet. `enumerateDevices` should only include devices that are available for capture, so make sure each device can be instantiated before including it. * LayoutTests/fast/mediastream/camera-invalid-device-expected.txt: Added. * LayoutTests/fast/mediastream/camera-invalid-device.html: Added. * Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.cpp: (WebCore::RealtimeMediaSourceCenter::getCapabilities): Change to return a std::optional<> so it can signal failure. * Source/WebCore/platform/mediastream/RealtimeMediaSourceCenter.h: * Source/WebCore/platform/mock/MockMediaDevice.h: (WebCore::MockMediaDevice::captureDevice const): Combine the existing `IsEphemeral` bool with the new `Invalid` flag into a "Flags" bitfield. (WebCore::MockMediaDevice::encode const): Encode the new flags variable. (WebCore::MockMediaDevice::decodeMockMediaDevice): Decode it. (WebCore::MockMediaDevice::decode): Ditto. * Source/WebCore/platform/mock/MockRealtimeMediaSourceCenter.cpp: (WebCore::defaultDevices): Update for the struct change. (WebCore::MockRealtimeMediaSourceCenter::setDeviceIsEphemeral): Ditto. * Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in: Define the new bitfield. * Source/WebKit/UIProcess/API/C/WKMockMediaDevice.cpp: (WKAddMockMediaDevice): Both mock camera and microphone can now have properties. * Source/WebKit/UIProcess/UserMediaPermissionRequestManagerProxy.cpp: (WebKit::UserMediaPermissionRequestManagerProxy::platformGetMediaStreamDevices): Don't include a device if `RealtimeMediaSourceCenter::getCapabilities` returns null. * Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl: * Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp: (WTR::captureDeviceProperties): Convert the properties JS object to a WKDictionaryRef. (WTR::TestRunner::addMockCameraDevice): Call captureDeviceProperties. (WTR::TestRunner::addMockMicrophoneDevice): Add a properties parameter, call captureDeviceProperties to parse it. * Tools/WebKitTestRunner/InjectedBundle/TestRunner.h: Canonical link: https://commits.webkit.org/265923@main
- Loading branch information
1 parent
d88306b
commit f453768
Showing
13 changed files
with
184 additions
and
58 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
LayoutTests/fast/mediastream/camera-invalid-device-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
|
||
PASS Invalid cameras and microphones should not be exposed by enumerateDevices | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset='utf-8'> | ||
<title>Test that invalid capture devices are not exposed by enumerateDevices.</title> | ||
<script src='../../resources/testharness.js'></script> | ||
<script src='../../resources/testharnessreport.js'></script> | ||
</head> | ||
<body> | ||
<video id='video'></video> | ||
<script> | ||
let setup = async (test) => { | ||
if (!window.testRunner) | ||
return Promise.reject('test requires internal API'); | ||
|
||
test.add_cleanup(() => { testRunner.resetMockMediaDevices(); }); | ||
} | ||
|
||
async function getDeviceWithLabel(label) | ||
{ | ||
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true }); | ||
const devices = await navigator.mediaDevices.enumerateDevices(); | ||
let deviceId = undefined; | ||
devices.forEach(device => { | ||
if (device.label === label) | ||
deviceId = device.deviceId; | ||
}); | ||
|
||
stream.getTracks().forEach(track => { | ||
track.stop(); | ||
}); | ||
|
||
return deviceId; | ||
} | ||
|
||
promise_test(async (test) => { | ||
await setup(test); | ||
|
||
testRunner.addMockCameraDevice('BogusCamera', 'invalid camera', { invalid: 'true' }); | ||
let invalidDevice = await getDeviceWithLabel('invalid camera') | ||
assert_equals(invalidDevice, undefined); | ||
|
||
testRunner.resetMockMediaDevices(); | ||
testRunner.addMockMicrophoneDevice('BogusMicrophone', 'invalid microphone', { invalid: 'true' }); | ||
invalidDevice = await getDeviceWithLabel('invalid microphone') | ||
assert_equals(invalidDevice, undefined); | ||
|
||
}, 'Invalid cameras and microphones should not be exposed by enumerateDevices'); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.