Skip to content

Commit 9901700

Browse files
miniakJohn Kleinschmidt
authored andcommitted
test: skip desktopCapturer / remote module tests when the features are disabled (electron#20566) (electron#20577)
1 parent d5b088b commit 9901700

File tree

2 files changed

+87
-76
lines changed

2 files changed

+87
-76
lines changed

spec-main/api-app-spec.ts

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import split = require('split')
99
import { app, BrowserWindow, Menu } from 'electron'
1010
import { emittedOnce } from './events-helpers';
1111
import { closeWindow } from './window-helpers';
12+
import { ifdescribe } from './spec-helpers';
13+
14+
const features = process.electronBinding('features')
1215

1316
const { expect } = chai
1417

@@ -405,103 +408,107 @@ describe('app module', () => {
405408
expect(webContents).to.equal(w.webContents)
406409
})
407410

408-
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
409-
w = new BrowserWindow({
410-
show: false,
411-
webPreferences: {
412-
nodeIntegration: true
413-
}
414-
})
415-
await w.loadURL('about:blank')
416-
417-
const promise = emittedOnce(app, 'desktop-capturer-get-sources')
418-
w.webContents.executeJavaScript(`require('electron').desktopCapturer.getSources({ types: ['screen'] }, () => {})`)
411+
ifdescribe(features.isDesktopCapturerEnabled())('desktopCapturer module filtering', () => {
412+
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
413+
w = new BrowserWindow({
414+
show: false,
415+
webPreferences: {
416+
nodeIntegration: true
417+
}
418+
})
419+
await w.loadURL('about:blank')
419420

420-
const [, webContents] = await promise
421-
expect(webContents).to.equal(w.webContents)
422-
})
421+
const promise = emittedOnce(app, 'desktop-capturer-get-sources')
422+
w.webContents.executeJavaScript(`require('electron').desktopCapturer.getSources({ types: ['screen'] }, () => {})`)
423423

424-
it('should emit remote-require event when remote.require() is invoked', async () => {
425-
w = new BrowserWindow({
426-
show: false,
427-
webPreferences: {
428-
nodeIntegration: true
429-
}
424+
const [, webContents] = await promise
425+
expect(webContents).to.equal(w.webContents)
430426
})
431-
await w.loadURL('about:blank')
427+
})
432428

433-
const promise = emittedOnce(app, 'remote-require')
434-
w.webContents.executeJavaScript(`require('electron').remote.require('test')`)
429+
describe('remote module filtering', () => {
430+
it('should emit remote-require event when remote.require() is invoked', async () => {
431+
w = new BrowserWindow({
432+
show: false,
433+
webPreferences: {
434+
nodeIntegration: true
435+
}
436+
})
437+
await w.loadURL('about:blank')
435438

436-
const [, webContents, moduleName] = await promise
437-
expect(webContents).to.equal(w.webContents)
438-
expect(moduleName).to.equal('test')
439-
})
439+
const promise = emittedOnce(app, 'remote-require')
440+
w.webContents.executeJavaScript(`require('electron').remote.require('test')`)
440441

441-
it('should emit remote-get-global event when remote.getGlobal() is invoked', async () => {
442-
w = new BrowserWindow({
443-
show: false,
444-
webPreferences: {
445-
nodeIntegration: true
446-
}
442+
const [, webContents, moduleName] = await promise
443+
expect(webContents).to.equal(w.webContents)
444+
expect(moduleName).to.equal('test')
447445
})
448-
await w.loadURL('about:blank')
449446

450-
const promise = emittedOnce(app, 'remote-get-global')
451-
w.webContents.executeJavaScript(`require('electron').remote.getGlobal('test')`)
447+
it('should emit remote-get-global event when remote.getGlobal() is invoked', async () => {
448+
w = new BrowserWindow({
449+
show: false,
450+
webPreferences: {
451+
nodeIntegration: true
452+
}
453+
})
454+
await w.loadURL('about:blank')
452455

453-
const [, webContents, globalName] = await promise
454-
expect(webContents).to.equal(w.webContents)
455-
expect(globalName).to.equal('test')
456-
})
456+
const promise = emittedOnce(app, 'remote-get-global')
457+
w.webContents.executeJavaScript(`require('electron').remote.getGlobal('test')`)
457458

458-
it('should emit remote-get-builtin event when remote.getBuiltin() is invoked', async () => {
459-
w = new BrowserWindow({
460-
show: false,
461-
webPreferences: {
462-
nodeIntegration: true
463-
}
459+
const [, webContents, globalName] = await promise
460+
expect(webContents).to.equal(w.webContents)
461+
expect(globalName).to.equal('test')
464462
})
465-
await w.loadURL('about:blank')
466463

467-
const promise = emittedOnce(app, 'remote-get-builtin')
468-
w.webContents.executeJavaScript(`require('electron').remote.app`)
464+
it('should emit remote-get-builtin event when remote.getBuiltin() is invoked', async () => {
465+
w = new BrowserWindow({
466+
show: false,
467+
webPreferences: {
468+
nodeIntegration: true
469+
}
470+
})
471+
await w.loadURL('about:blank')
469472

470-
const [, webContents, moduleName] = await promise
471-
expect(webContents).to.equal(w.webContents)
472-
expect(moduleName).to.equal('app')
473-
})
473+
const promise = emittedOnce(app, 'remote-get-builtin')
474+
w.webContents.executeJavaScript(`require('electron').remote.app`)
474475

475-
it('should emit remote-get-current-window event when remote.getCurrentWindow() is invoked', async () => {
476-
w = new BrowserWindow({
477-
show: false,
478-
webPreferences: {
479-
nodeIntegration: true
480-
}
476+
const [, webContents, moduleName] = await promise
477+
expect(webContents).to.equal(w.webContents)
478+
expect(moduleName).to.equal('app')
481479
})
482-
await w.loadURL('about:blank')
483480

484-
const promise = emittedOnce(app, 'remote-get-current-window')
485-
w.webContents.executeJavaScript(`require('electron').remote.getCurrentWindow()`)
481+
it('should emit remote-get-current-window event when remote.getCurrentWindow() is invoked', async () => {
482+
w = new BrowserWindow({
483+
show: false,
484+
webPreferences: {
485+
nodeIntegration: true
486+
}
487+
})
488+
await w.loadURL('about:blank')
486489

487-
const [, webContents] = await promise
488-
expect(webContents).to.equal(w.webContents)
489-
})
490+
const promise = emittedOnce(app, 'remote-get-current-window')
491+
w.webContents.executeJavaScript(`require('electron').remote.getCurrentWindow()`)
490492

491-
it('should emit remote-get-current-web-contents event when remote.getCurrentWebContents() is invoked', async () => {
492-
w = new BrowserWindow({
493-
show: false,
494-
webPreferences: {
495-
nodeIntegration: true
496-
}
493+
const [, webContents] = await promise
494+
expect(webContents).to.equal(w.webContents)
497495
})
498-
await w.loadURL('about:blank')
499496

500-
const promise = emittedOnce(app, 'remote-get-current-web-contents')
501-
w.webContents.executeJavaScript(`require('electron').remote.getCurrentWebContents()`)
497+
it('should emit remote-get-current-web-contents event when remote.getCurrentWebContents() is invoked', async () => {
498+
w = new BrowserWindow({
499+
show: false,
500+
webPreferences: {
501+
nodeIntegration: true
502+
}
503+
})
504+
await w.loadURL('about:blank')
505+
506+
const promise = emittedOnce(app, 'remote-get-current-web-contents')
507+
w.webContents.executeJavaScript(`require('electron').remote.getCurrentWebContents()`)
502508

503-
const [, webContents] = await promise
504-
expect(webContents).to.equal(w.webContents)
509+
const [, webContents] = await promise
510+
expect(webContents).to.equal(w.webContents)
511+
})
505512
})
506513
})
507514

spec-main/spec-helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const ifit = (condition: boolean) => (condition ? it : it.skip)
2+
export const ifdescribe = (condition: boolean) => (condition ? describe : describe.skip)
3+
4+
export const delay = (time: number) => new Promise(r => setTimeout(r, time))

0 commit comments

Comments
 (0)