test: fix test for desktopCapturer preventDefault (#20100)

This commit is contained in:
Jeremy Apthorp 2019-09-04 13:54:40 -07:00 committed by GitHub
parent 8b523cf88a
commit a453f2ae6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

View file

@ -1,7 +1,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import { desktopCapturer, ipcRenderer, screen, BrowserWindow, SourcesOptions } from 'electron' import { desktopCapturer, screen, BrowserWindow, SourcesOptions } from 'electron'
import { emittedOnce } from './events-helpers' import { emittedOnce } from './events-helpers'
import { ifdescribe } from './spec-helpers'; import { ifdescribe, ifit } from './spec-helpers';
import { closeAllWindows } from './window-helpers'; import { closeAllWindows } from './window-helpers';
const features = process.electronBinding('features') const features = process.electronBinding('features')
@ -46,10 +46,8 @@ ifdescribe(features.isDesktopCapturerEnabled() && !process.arch.includes('arm')
expect(promise2).to.not.eventually.be.rejected() expect(promise2).to.not.eventually.be.rejected()
}) })
it('returns an empty display_id for window sources on Windows and Mac', async () => { // Linux doesn't return any window sources.
// Linux doesn't return any window sources. ifit(process.platform !== 'linux')('returns an empty display_id for window sources on Windows and Mac', async () => {
if (process.platform !== 'win32' && process.platform !== 'darwin') return
const w = new BrowserWindow({ width: 200, height: 200 }) const w = new BrowserWindow({ width: 200, height: 200 })
const sources = await getSources({ types: ['window'] }) const sources = await getSources({ types: ['window'] })
@ -60,9 +58,7 @@ ifdescribe(features.isDesktopCapturerEnabled() && !process.arch.includes('arm')
} }
}) })
it('returns display_ids matching the Screen API on Windows and Mac', async () => { ifit(process.platform !== 'linux')('returns display_ids matching the Screen API on Windows and Mac', async () => {
if (process.platform !== 'win32' && process.platform !== 'darwin') return
const displays = screen.getAllDisplays() const displays = screen.getAllDisplays()
const sources = await getSources({ types: ['screen'] }) const sources = await getSources({ types: ['screen'] })
expect(sources).to.be.an('array').of.length(displays.length) expect(sources).to.be.an('array').of.length(displays.length)
@ -70,12 +66,14 @@ ifdescribe(features.isDesktopCapturerEnabled() && !process.arch.includes('arm')
for (let i = 0; i < sources.length; i++) { for (let i = 0; i < sources.length; i++) {
expect(sources[i].display_id).to.equal(displays[i].id.toString()) expect(sources[i].display_id).to.equal(displays[i].id.toString())
} }
})
it('returns empty sources when blocked', async () => { ifit(process.platform !== 'linux')('returns an empty source list if blocked by the main process', async () => {
ipcRenderer.send('handle-next-desktop-capturer-get-sources') w.webContents.once('desktop-capturer-get-sources', (event) => {
const sources = await getSources({ types: ['screen'] }) event.preventDefault()
expect(sources).to.be.empty()
}) })
const sources = await getSources({ types: ['screen'] })
expect(sources).to.be.empty()
}) })
it('disabling thumbnail should return empty images', async () => { it('disabling thumbnail should return empty images', async () => {

View file

@ -168,7 +168,6 @@ ipcMain.on('handle-next-ipc-message-sync', function (event, returnValue) {
}) })
for (const eventName of [ for (const eventName of [
'desktop-capturer-get-sources',
'remote-get-guest-web-contents' 'remote-get-guest-web-contents'
]) { ]) {
ipcMain.on(`handle-next-${eventName}`, function (event, returnValue) { ipcMain.on(`handle-next-${eventName}`, function (event, returnValue) {