electron/spec/api-desktop-capturer-spec.js

84 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-03-25 20:03:49 +00:00
const assert = require('assert')
const {desktopCapturer, remote, screen} = require('electron')
2016-01-12 02:40:23 +00:00
2017-10-27 00:44:06 +00:00
const isCI = remote.getGlobal('isCi')
2017-10-27 00:44:06 +00:00
describe('desktopCapturer', () => {
before(function () {
if (isCI && process.platform === 'win32') {
this.skip()
}
})
2017-10-27 00:44:06 +00:00
it('should return a non-empty array of sources', (done) => {
2016-01-19 18:54:12 +00:00
desktopCapturer.getSources({
2016-01-12 02:40:23 +00:00
types: ['window', 'screen']
2017-10-27 00:44:06 +00:00
}, (error, sources) => {
2016-03-25 20:03:49 +00:00
assert.equal(error, null)
assert.notEqual(sources.length, 0)
done()
})
})
2016-01-19 18:57:18 +00:00
2017-10-27 00:44:06 +00:00
it('throws an error for invalid options', (done) => {
desktopCapturer.getSources(['window', 'screen'], (error) => {
2016-08-09 22:31:24 +00:00
assert.equal(error.message, 'Invalid options')
done()
})
})
2017-10-27 00:44:06 +00:00
it('does not throw an error when called more than once (regression)', (done) => {
let callCount = 0
const callback = (error, sources) => {
2016-03-25 20:03:49 +00:00
callCount++
assert.equal(error, null)
assert.notEqual(sources.length, 0)
if (callCount === 2) done()
}
2016-01-19 18:57:18 +00:00
2016-03-25 20:03:49 +00:00
desktopCapturer.getSources({types: ['window', 'screen']}, callback)
desktopCapturer.getSources({types: ['window', 'screen']}, callback)
})
it('responds to subsequent calls of different options', (done) => {
2017-10-27 00:44:06 +00:00
let callCount = 0
const callback = (error, sources) => {
callCount++
assert.equal(error, null)
if (callCount === 2) done()
}
desktopCapturer.getSources({types: ['window']}, callback)
desktopCapturer.getSources({types: ['screen']}, callback)
})
it('returns an empty display_id for window sources on Windows and Mac', (done) => {
// Linux doesn't return any window sources.
if (process.platform !== 'win32' && process.platform !== 'darwin') {
return done()
}
desktopCapturer.getSources({types: ['window']}, (error, sources) => {
assert.equal(error, null)
assert.notEqual(sources.length, 0)
sources.forEach((source) => { assert.equal(source.display_id.length, 0) })
done()
})
})
it('returns display_ids matching the Screen API on Windows and Mac', (done) => {
if (process.platform !== 'win32' && process.platform !== 'darwin') {
return done()
}
const displays = screen.getAllDisplays()
desktopCapturer.getSources({types: ['screen']}, (error, sources) => {
assert.equal(error, null)
assert.notEqual(sources.length, 0)
assert.equal(sources.length, displays.length)
for (let i = 0; i < sources.length; i++) {
assert.equal(sources[i].display_id, displays[i].id)
}
done()
})
})
2016-03-25 20:03:49 +00:00
})