Send error to global widget if missing screen sharing permissions (#2554)

This commit is contained in:
Claudio Costa
2023-02-16 10:20:50 -06:00
committed by GitHub
parent 5cc2e98a1d
commit 7127ec153a
4 changed files with 121 additions and 4 deletions

View File

@@ -4,7 +4,7 @@
/* eslint-disable max-lines */
'use strict';
import {app, systemPreferences} from 'electron';
import {app, systemPreferences, desktopCapturer} from 'electron';
import Config from 'common/config';
import {getTabViewName, TAB_MESSAGING} from 'common/tabs/TabView';
@@ -39,6 +39,10 @@ jest.mock('electron', () => ({
},
systemPreferences: {
getUserDefault: jest.fn(),
getMediaAccessStatus: jest.fn(() => 'granted'),
},
desktopCapturer: {
getSources: jest.fn(),
},
}));
@@ -1042,6 +1046,84 @@ describe('main/windows/windowManager', () => {
});
});
describe('handleGetDesktopSources', () => {
const windowManager = new WindowManager();
windowManager.viewManager = {
showByName: jest.fn(),
getCurrentView: jest.fn(),
};
beforeEach(() => {
windowManager.viewManager.views = new Map();
windowManager.callsWidgetWindow = new CallsWidgetWindow();
windowManager.callsWidgetWindow.win = {
webContents: {
send: jest.fn(),
},
};
});
afterEach(() => {
jest.resetAllMocks();
Config.teams = [];
});
it('should send sources back', async () => {
jest.spyOn(desktopCapturer, 'getSources').mockResolvedValue([
{
id: 'screen0',
thumbnail: {
toDataURL: jest.fn(),
},
},
{
id: 'window0',
thumbnail: {
toDataURL: jest.fn(),
},
},
]);
await windowManager.handleGetDesktopSources(null, 'widget', null);
expect(windowManager.callsWidgetWindow.win.webContents.send).toHaveBeenCalledWith('desktop-sources-result', [
{
id: 'screen0',
},
{
id: 'window0',
},
]);
});
it('should send error with no sources', async () => {
jest.spyOn(desktopCapturer, 'getSources').mockResolvedValue([]);
await windowManager.handleGetDesktopSources(null, 'widget', null);
expect(windowManager.callsWidgetWindow.win.webContents.send).toHaveBeenCalledWith('calls-error', {
err: 'screen-permissions',
});
});
it('should send error with no permissions', async () => {
jest.spyOn(desktopCapturer, 'getSources').mockResolvedValue([
{
id: 'screen0',
thumbnail: {
toDataURL: jest.fn(),
},
},
]);
jest.spyOn(systemPreferences, 'getMediaAccessStatus').mockReturnValue('denied');
await windowManager.handleGetDesktopSources(null, 'widget', null);
expect(systemPreferences.getMediaAccessStatus).toHaveBeenCalledWith('screen');
expect(windowManager.callsWidgetWindow.win.webContents.send).toHaveBeenCalledWith('calls-error', {
err: 'screen-permissions',
});
});
});
describe('handleDesktopSourcesModalRequest', () => {
const windowManager = new WindowManager();
windowManager.switchServer = jest.fn();