fix: video and audio capture should be separate (#42808)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-07-08 16:49:10 +02:00 committed by GitHub
parent 8d1b4652ff
commit 26d5583c6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 5 deletions

View file

@ -1770,7 +1770,7 @@ describe('chromium features', () => {
expect(labels.some((l: any) => l)).to.be.true();
});
it('does not return labels of enumerated devices when permission denied', async () => {
it('does not return labels of enumerated devices when all permission denied', async () => {
session.defaultSession.setPermissionCheckHandler(() => false);
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
@ -1778,6 +1778,40 @@ describe('chromium features', () => {
expect(labels.some((l: any) => l)).to.be.false();
});
it('does not return labels of enumerated audio devices when permission denied', async () => {
session.defaultSession.setPermissionCheckHandler((wc, permission, origin, { mediaType }) => {
return permission !== 'media' || mediaType !== 'audio';
});
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const devices = await w.webContents.executeJavaScript(
`navigator.mediaDevices.enumerateDevices().then(ds => ds.map(d => {
return ({ label: d.label, kind: d.kind })
}));
`);
const audioDevices = devices.filter((d: any) => d.kind === 'audioinput');
expect(audioDevices.some((d: any) => d.label)).to.be.false();
const videoDevices = devices.filter((d: any) => d.kind === 'videoinput');
expect(videoDevices.some((d: any) => d.label)).to.be.true();
});
it('does not return labels of enumerated video devices when permission denied', async () => {
session.defaultSession.setPermissionCheckHandler((wc, permission, origin, { mediaType }) => {
return permission !== 'media' || mediaType !== 'video';
});
const w = new BrowserWindow({ show: false });
w.loadFile(path.join(fixturesPath, 'pages', 'blank.html'));
const devices = await w.webContents.executeJavaScript(
`navigator.mediaDevices.enumerateDevices().then(ds => ds.map(d => {
return ({ label: d.label, kind: d.kind })
}));
`);
const audioDevices = devices.filter((d: any) => d.kind === 'audioinput');
expect(audioDevices.some((d: any) => d.label)).to.be.true();
const videoDevices = devices.filter((d: any) => d.kind === 'videoinput');
expect(videoDevices.some((d: any) => d.label)).to.be.false();
});
it('returns the same device ids across reloads', async () => {
const ses = session.fromPartition('persist:media-device-id');
const w = new BrowserWindow({