2018-06-17 23:00:28 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
2018-12-20 02:44:30 +00:00
|
|
|
const { desktopCapturer, ipcRenderer, remote } = require('electron')
|
2018-12-05 09:34:09 +00:00
|
|
|
const { screen } = remote
|
2018-06-13 16:15:34 +00:00
|
|
|
const features = process.atomBinding('features')
|
2016-01-12 02:40:23 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = chai
|
2018-06-17 23:00:28 +00:00
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2017-10-27 00:44:06 +00:00
|
|
|
const isCI = remote.getGlobal('isCi')
|
2016-04-30 11:51:09 +00:00
|
|
|
|
2017-10-27 00:44:06 +00:00
|
|
|
describe('desktopCapturer', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2018-10-04 16:01:16 +00:00
|
|
|
if (!features.isDesktopCapturerEnabled() || process.arch.indexOf('arm') === 0) {
|
2018-06-13 16:15:34 +00:00
|
|
|
// It's been disabled during build time.
|
|
|
|
this.skip()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
if (isCI && process.platform === 'win32') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2016-04-30 11:51:09 +00:00
|
|
|
|
2018-06-17 23:00:28 +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) => {
|
2018-06-17 23:00:28 +00:00
|
|
|
expect(error).to.be.null()
|
2018-06-18 15:12:54 +00:00
|
|
|
expect(sources).to.be.an('array').that.is.not.empty()
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-01-19 18:57:18 +00:00
|
|
|
|
2018-06-17 23:00:28 +00:00
|
|
|
it('throws an error for invalid options', done => {
|
|
|
|
desktopCapturer.getSources(['window', 'screen'], error => {
|
|
|
|
expect(error.message).to.equal('Invalid options')
|
2016-08-09 22:31:24 +00:00
|
|
|
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++
|
2018-06-17 23:00:28 +00:00
|
|
|
expect(error).to.be.null()
|
2018-06-18 15:12:54 +00:00
|
|
|
expect(sources).to.be.an('array').that.is.not.empty()
|
2016-03-25 20:03:49 +00:00
|
|
|
if (callCount === 2) done()
|
|
|
|
}
|
2016-01-19 18:57:18 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
desktopCapturer.getSources({ types: ['window', 'screen'] }, callback)
|
|
|
|
desktopCapturer.getSources({ types: ['window', 'screen'] }, callback)
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-04-27 20:32:14 +00:00
|
|
|
|
2018-06-17 23:00:28 +00:00
|
|
|
it('responds to subsequent calls of different options', done => {
|
2017-10-27 00:44:06 +00:00
|
|
|
let callCount = 0
|
|
|
|
const callback = (error, sources) => {
|
2016-04-27 20:32:14 +00:00
|
|
|
callCount++
|
2018-06-17 23:00:28 +00:00
|
|
|
expect(error).to.be.null()
|
2016-04-27 20:32:14 +00:00
|
|
|
if (callCount === 2) done()
|
|
|
|
}
|
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
desktopCapturer.getSources({ types: ['window'] }, callback)
|
|
|
|
desktopCapturer.getSources({ types: ['screen'] }, callback)
|
2016-04-27 20:32:14 +00:00
|
|
|
})
|
2018-04-09 05:43:35 +00:00
|
|
|
|
2018-06-17 23:00:28 +00:00
|
|
|
it('returns an empty display_id for window sources on Windows and Mac', done => {
|
2018-04-09 05:43:35 +00:00
|
|
|
// Linux doesn't return any window sources.
|
|
|
|
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
|
|
|
return done()
|
|
|
|
}
|
2018-06-17 23:00:28 +00:00
|
|
|
|
2018-07-17 04:20:50 +00:00
|
|
|
const { BrowserWindow } = remote
|
|
|
|
const w = new BrowserWindow({ width: 200, height: 200 })
|
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
desktopCapturer.getSources({ types: ['window'] }, (error, sources) => {
|
2018-07-17 04:20:50 +00:00
|
|
|
w.destroy()
|
2018-06-17 23:00:28 +00:00
|
|
|
expect(error).to.be.null()
|
2018-06-18 15:12:54 +00:00
|
|
|
expect(sources).to.be.an('array').that.is.not.empty()
|
2018-09-13 16:10:51 +00:00
|
|
|
for (const { display_id: displayId } of sources) {
|
2018-06-18 15:12:54 +00:00
|
|
|
expect(displayId).to.be.a('string').and.be.empty()
|
|
|
|
}
|
2018-04-09 05:43:35 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-06-17 23:00:28 +00:00
|
|
|
it('returns display_ids matching the Screen API on Windows and Mac', done => {
|
2018-04-09 05:43:35 +00:00
|
|
|
if (process.platform !== 'win32' && process.platform !== 'darwin') {
|
|
|
|
return done()
|
|
|
|
}
|
2018-06-17 23:00:28 +00:00
|
|
|
|
2018-04-09 05:43:35 +00:00
|
|
|
const displays = screen.getAllDisplays()
|
2018-09-13 16:10:51 +00:00
|
|
|
desktopCapturer.getSources({ types: ['screen'] }, (error, sources) => {
|
2018-06-17 23:00:28 +00:00
|
|
|
expect(error).to.be.null()
|
2018-06-18 15:12:54 +00:00
|
|
|
expect(sources).to.be.an('array').of.length(displays.length)
|
2018-06-17 23:00:28 +00:00
|
|
|
|
2018-04-09 05:43:35 +00:00
|
|
|
for (let i = 0; i < sources.length; i++) {
|
2018-06-17 23:00:28 +00:00
|
|
|
expect(sources[i].display_id).to.equal(displays[i].id.toString())
|
2018-04-09 05:43:35 +00:00
|
|
|
}
|
|
|
|
done()
|
|
|
|
})
|
2018-12-20 02:44:30 +00:00
|
|
|
|
|
|
|
it('returns empty sources when blocked', done => {
|
|
|
|
ipcRenderer.send('handle-next-desktop-capturer-get-sources')
|
|
|
|
desktopCapturer.getSources({ types: ['screen'] }, (error, sources) => {
|
|
|
|
expect(error).to.be.null()
|
|
|
|
expect(sources).to.be.empty()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2018-04-09 05:43:35 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|