test: skip desktopCapturer / remote module tests when the features are disabled (#20566)

This commit is contained in:
Milan Burda 2019-10-14 22:49:21 +02:00 committed by Jeremy Apthorp
parent b085dac15b
commit eb100cdf9e
2 changed files with 85 additions and 78 deletions

View file

@ -10,6 +10,9 @@ import split = require('split')
import { app, BrowserWindow, Menu } from 'electron' import { app, BrowserWindow, Menu } from 'electron'
import { emittedOnce } from './events-helpers'; import { emittedOnce } from './events-helpers';
import { closeWindow } from './window-helpers'; import { closeWindow } from './window-helpers';
import { ifdescribe } from './spec-helpers';
const features = process.electronBinding('features')
const { expect } = chai const { expect } = chai
@ -426,103 +429,107 @@ describe('app module', () => {
expect(webContents).to.equal(w.webContents) expect(webContents).to.equal(w.webContents)
}) })
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => { ifdescribe(features.isDesktopCapturerEnabled())('desktopCapturer module filtering', () => {
w = new BrowserWindow({ it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
show: false, w = new BrowserWindow({
webPreferences: { show: false,
nodeIntegration: true webPreferences: {
} nodeIntegration: true
}
})
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'desktop-capturer-get-sources')
w.webContents.executeJavaScript(`require('electron').desktopCapturer.getSources({ types: ['screen'] })`)
const [, webContents] = await promise
expect(webContents).to.equal(w.webContents)
}) })
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'desktop-capturer-get-sources')
w.webContents.executeJavaScript(`require('electron').desktopCapturer.getSources({ types: ['screen'] })`)
const [, webContents] = await promise
expect(webContents).to.equal(w.webContents)
}) })
it('should emit remote-require event when remote.require() is invoked', async () => { ifdescribe(features.isRemoteModuleEnabled())('remote module filtering', () => {
w = new BrowserWindow({ it('should emit remote-require event when remote.require() is invoked', async () => {
show: false, w = new BrowserWindow({
webPreferences: { show: false,
nodeIntegration: true webPreferences: {
} nodeIntegration: true
}
})
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'remote-require')
w.webContents.executeJavaScript(`require('electron').remote.require('test')`)
const [, webContents, moduleName] = await promise
expect(webContents).to.equal(w.webContents)
expect(moduleName).to.equal('test')
}) })
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'remote-require') it('should emit remote-get-global event when remote.getGlobal() is invoked', async () => {
w.webContents.executeJavaScript(`require('electron').remote.require('test')`) w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
await w.loadURL('about:blank')
const [, webContents, moduleName] = await promise const promise = emittedOnce(app, 'remote-get-global')
expect(webContents).to.equal(w.webContents) w.webContents.executeJavaScript(`require('electron').remote.getGlobal('test')`)
expect(moduleName).to.equal('test')
})
it('should emit remote-get-global event when remote.getGlobal() is invoked', async () => { const [, webContents, globalName] = await promise
w = new BrowserWindow({ expect(webContents).to.equal(w.webContents)
show: false, expect(globalName).to.equal('test')
webPreferences: {
nodeIntegration: true
}
}) })
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'remote-get-global') it('should emit remote-get-builtin event when remote.getBuiltin() is invoked', async () => {
w.webContents.executeJavaScript(`require('electron').remote.getGlobal('test')`) w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
await w.loadURL('about:blank')
const [, webContents, globalName] = await promise const promise = emittedOnce(app, 'remote-get-builtin')
expect(webContents).to.equal(w.webContents) w.webContents.executeJavaScript(`require('electron').remote.app`)
expect(globalName).to.equal('test')
})
it('should emit remote-get-builtin event when remote.getBuiltin() is invoked', async () => { const [, webContents, moduleName] = await promise
w = new BrowserWindow({ expect(webContents).to.equal(w.webContents)
show: false, expect(moduleName).to.equal('app')
webPreferences: {
nodeIntegration: true
}
}) })
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'remote-get-builtin') it('should emit remote-get-current-window event when remote.getCurrentWindow() is invoked', async () => {
w.webContents.executeJavaScript(`require('electron').remote.app`) w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
await w.loadURL('about:blank')
const [, webContents, moduleName] = await promise const promise = emittedOnce(app, 'remote-get-current-window')
expect(webContents).to.equal(w.webContents) w.webContents.executeJavaScript(`{ require('electron').remote.getCurrentWindow() }`)
expect(moduleName).to.equal('app')
})
it('should emit remote-get-current-window event when remote.getCurrentWindow() is invoked', async () => { const [, webContents] = await promise
w = new BrowserWindow({ expect(webContents).to.equal(w.webContents)
show: false,
webPreferences: {
nodeIntegration: true
}
}) })
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'remote-get-current-window') it('should emit remote-get-current-web-contents event when remote.getCurrentWebContents() is invoked', async () => {
w.webContents.executeJavaScript(`{ require('electron').remote.getCurrentWindow() }`) w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
await w.loadURL('about:blank')
const [, webContents] = await promise const promise = emittedOnce(app, 'remote-get-current-web-contents')
expect(webContents).to.equal(w.webContents) w.webContents.executeJavaScript(`{ require('electron').remote.getCurrentWebContents() }`)
})
it('should emit remote-get-current-web-contents event when remote.getCurrentWebContents() is invoked', async () => { const [, webContents] = await promise
w = new BrowserWindow({ expect(webContents).to.equal(w.webContents)
show: false,
webPreferences: {
nodeIntegration: true
}
}) })
await w.loadURL('about:blank')
const promise = emittedOnce(app, 'remote-get-current-web-contents')
w.webContents.executeJavaScript(`{ require('electron').remote.getCurrentWebContents() }`)
const [, webContents] = await promise
expect(webContents).to.equal(w.webContents)
}) })
}) })

View file

@ -103,7 +103,7 @@ describe('webContents module', () => {
}) })
}) })
describe('webContents.print()', () => { ifdescribe(features.isPrintingEnabled())('webContents.print()', () => {
afterEach(closeAllWindows) afterEach(closeAllWindows)
it('throws when invalid settings are passed', () => { it('throws when invalid settings are passed', () => {
const w = new BrowserWindow({ show: false }) const w = new BrowserWindow({ show: false })