2018-04-20 07:09:23 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const chaiAsPromised = require('chai-as-promised')
|
2018-06-14 16:44:27 +00:00
|
|
|
const dirtyChai = require('dirty-chai')
|
2016-03-25 19:57:17 +00:00
|
|
|
const ChildProcess = require('child_process')
|
2016-04-18 16:23:44 +00:00
|
|
|
const https = require('https')
|
2016-06-03 03:12:20 +00:00
|
|
|
const net = require('net')
|
2016-04-18 16:23:44 +00:00
|
|
|
const fs = require('fs')
|
2016-03-25 19:57:17 +00:00
|
|
|
const path = require('path')
|
2019-01-07 15:48:27 +00:00
|
|
|
const cp = require('child_process')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { ipcRenderer, remote } = require('electron')
|
|
|
|
const { emittedOnce } = require('./events-helpers')
|
|
|
|
const { closeWindow } = require('./window-helpers')
|
2016-03-25 19:57:17 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
const { expect } = chai
|
|
|
|
const { app, BrowserWindow, Menu, ipcMain } = remote
|
2016-03-25 19:57:17 +00:00
|
|
|
|
2017-02-08 02:24:35 +00:00
|
|
|
const isCI = remote.getGlobal('isCi')
|
|
|
|
|
2018-04-20 07:09:23 +00:00
|
|
|
chai.use(chaiAsPromised)
|
2018-06-14 16:44:27 +00:00
|
|
|
chai.use(dirtyChai)
|
2018-04-20 07:09:23 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('electron module', () => {
|
|
|
|
it('does not expose internal modules to require', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(() => {
|
2016-03-25 19:57:17 +00:00
|
|
|
require('clipboard')
|
2018-06-14 16:44:27 +00:00
|
|
|
}).to.throw(/Cannot find module 'clipboard'/)
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-05-23 20:12:02 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('require("electron")', () => {
|
2016-05-23 20:12:02 +00:00
|
|
|
let window = null
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
beforeEach(() => {
|
2016-05-23 20:12:02 +00:00
|
|
|
window = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
2019-01-07 19:19:27 +00:00
|
|
|
height: 400,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
2016-05-23 20:12:02 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => {
|
|
|
|
return closeWindow(window).then(() => { window = null })
|
2016-05-23 20:12:02 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('always returns the internal electron module', (done) => {
|
|
|
|
ipcMain.once('answer', () => done())
|
2018-09-04 14:50:53 +00:00
|
|
|
window.loadFile(path.join(__dirname, 'fixtures', 'api', 'electron-module-app', 'index.html'))
|
2016-05-23 20:12:02 +00:00
|
|
|
})
|
|
|
|
})
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app module', () => {
|
2016-12-02 17:34:16 +00:00
|
|
|
let server, secureUrl
|
|
|
|
const certPath = path.join(__dirname, 'fixtures', 'certificates')
|
|
|
|
|
2018-03-07 05:40:27 +00:00
|
|
|
before((done) => {
|
2016-12-02 17:34:16 +00:00
|
|
|
const options = {
|
|
|
|
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
|
|
|
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
|
|
|
ca: [
|
|
|
|
fs.readFileSync(path.join(certPath, 'rootCA.pem')),
|
|
|
|
fs.readFileSync(path.join(certPath, 'intermediateCA.pem'))
|
|
|
|
],
|
|
|
|
requestCert: true,
|
|
|
|
rejectUnauthorized: false
|
|
|
|
}
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
server = https.createServer(options, (req, res) => {
|
2016-12-02 17:34:16 +00:00
|
|
|
if (req.client.authorized) {
|
|
|
|
res.writeHead(200)
|
|
|
|
res.end('<title>authorized</title>')
|
|
|
|
} else {
|
|
|
|
res.writeHead(401)
|
|
|
|
res.end('<title>denied</title>')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
server.listen(0, '127.0.0.1', () => {
|
2016-12-02 17:34:16 +00:00
|
|
|
const port = server.address().port
|
|
|
|
secureUrl = `https://127.0.0.1:${port}`
|
2018-03-07 05:40:27 +00:00
|
|
|
done()
|
2016-12-02 17:34:16 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
after(done => {
|
2018-03-07 05:40:27 +00:00
|
|
|
server.close(() => done())
|
2016-12-02 17:34:16 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.getVersion()', () => {
|
|
|
|
it('returns the version field of package.json', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getVersion()).to.equal('0.1.0')
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.setVersion(version)', () => {
|
|
|
|
it('overrides the version', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getVersion()).to.equal('0.1.0')
|
2016-03-25 19:57:17 +00:00
|
|
|
app.setVersion('test-version')
|
2018-06-14 16:44:27 +00:00
|
|
|
|
|
|
|
expect(app.getVersion()).to.equal('test-version')
|
2016-03-25 19:57:17 +00:00
|
|
|
app.setVersion('0.1.0')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.getName()', () => {
|
|
|
|
it('returns the name field of package.json', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getName()).to.equal('Electron Test')
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.setName(name)', () => {
|
|
|
|
it('overrides the name', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getName()).to.equal('Electron Test')
|
2016-03-25 19:57:17 +00:00
|
|
|
app.setName('test-name')
|
2018-06-14 16:44:27 +00:00
|
|
|
|
|
|
|
expect(app.getName()).to.equal('test-name')
|
2016-03-25 19:57:17 +00:00
|
|
|
app.setName('Electron Test')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.getLocale()', () => {
|
|
|
|
it('should not be empty', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getLocale()).to.not.be.empty()
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-11-20 20:33:23 +00:00
|
|
|
describe('app.getLocaleCountryCode()', () => {
|
|
|
|
it('should be empty or have length of two', () => {
|
|
|
|
let expectedLength = 2
|
|
|
|
if (isCI && process.platform === 'linux') {
|
|
|
|
// Linux CI machines have no locale.
|
|
|
|
expectedLength = 0
|
|
|
|
}
|
|
|
|
expect(app.getLocaleCountryCode()).to.be.a('string').and.have.lengthOf(expectedLength)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-05-08 06:15:31 +00:00
|
|
|
describe('app.isPackaged', () => {
|
|
|
|
it('should be false durings tests', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isPackaged).to.be.false()
|
2018-05-08 06:15:31 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.isInApplicationsFolder()', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('should be false during tests', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isInApplicationsFolder()).to.be.false()
|
2017-08-31 14:37:12 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.exit(exitCode)', () => {
|
|
|
|
let appProcess = null
|
2016-03-25 19:57:17 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => {
|
2016-11-29 22:19:20 +00:00
|
|
|
if (appProcess != null) appProcess.kill()
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
|
|
|
|
2018-08-26 13:54:51 +00:00
|
|
|
it('emits a process exit event with the code', async () => {
|
2017-10-27 20:45:58 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
|
|
|
let output = ''
|
2018-06-14 16:44:27 +00:00
|
|
|
|
2016-03-25 19:57:17 +00:00
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
2018-06-14 16:44:27 +00:00
|
|
|
appProcess.stdout.on('data', data => { output += data })
|
2018-08-26 13:54:51 +00:00
|
|
|
const [code] = await emittedOnce(appProcess, 'close')
|
2018-06-14 16:44:27 +00:00
|
|
|
|
2018-08-26 13:54:51 +00:00
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
expect(output).to.include('Exit event with code: 123')
|
|
|
|
}
|
|
|
|
expect(code).to.equal(123)
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2017-04-06 22:02:32 +00:00
|
|
|
|
2018-08-26 13:55:50 +00:00
|
|
|
it('closes all windows', async function () {
|
2018-06-14 16:44:27 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'exit-closes-all-windows-app')
|
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
|
|
|
|
2017-04-06 22:02:32 +00:00
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
2018-08-26 13:54:51 +00:00
|
|
|
const [code, signal] = await emittedOnce(appProcess, 'close')
|
|
|
|
|
|
|
|
expect(signal).to.equal(null, 'exit signal should be null, if you see this please tag @MarshallOfSound')
|
|
|
|
expect(code).to.equal(123, 'exit code should be 123, if you see this please tag @MarshallOfSound')
|
2017-04-06 22:02:32 +00:00
|
|
|
})
|
2018-01-11 22:50:35 +00:00
|
|
|
|
2018-08-26 13:54:51 +00:00
|
|
|
it('exits gracefully', async function () {
|
2018-03-07 03:01:17 +00:00
|
|
|
if (!['darwin', 'linux'].includes(process.platform)) {
|
2018-01-12 18:40:48 +00:00
|
|
|
this.skip()
|
2018-08-26 13:54:51 +00:00
|
|
|
return
|
2018-01-11 22:50:35 +00:00
|
|
|
}
|
2018-03-07 03:01:17 +00:00
|
|
|
|
2018-01-11 22:50:35 +00:00
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
2018-03-07 03:01:17 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
|
2018-01-11 22:50:35 +00:00
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
2018-03-07 03:01:17 +00:00
|
|
|
|
|
|
|
// Singleton will send us greeting data to let us know it's running.
|
|
|
|
// After that, ask it to exit gracefully and confirm that it does.
|
2018-06-14 16:44:27 +00:00
|
|
|
appProcess.stdout.on('data', data => appProcess.kill())
|
2018-08-26 13:54:51 +00:00
|
|
|
const [code, signal] = await emittedOnce(appProcess, 'close')
|
|
|
|
|
|
|
|
const message = `code:\n${code}\nsignal:\n${signal}`
|
|
|
|
expect(code).to.equal(0, message)
|
|
|
|
expect(signal).to.be.null(message)
|
2018-01-11 22:50:35 +00:00
|
|
|
})
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2018-05-07 15:29:18 +00:00
|
|
|
describe('app.requestSingleInstanceLock', () => {
|
2017-09-20 02:58:10 +00:00
|
|
|
it('prevents the second launch of app', function (done) {
|
|
|
|
this.timeout(120000)
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
|
|
|
|
const first = ChildProcess.spawn(remote.process.execPath, [appPath])
|
2018-06-14 16:44:27 +00:00
|
|
|
first.once('exit', code => {
|
|
|
|
expect(code).to.equal(0)
|
2017-09-20 02:58:10 +00:00
|
|
|
})
|
2017-09-25 02:19:25 +00:00
|
|
|
// Start second app when received output.
|
|
|
|
first.stdout.once('data', () => {
|
|
|
|
const second = ChildProcess.spawn(remote.process.execPath, [appPath])
|
2018-06-14 16:44:27 +00:00
|
|
|
second.once('exit', code => {
|
|
|
|
expect(code).to.equal(1)
|
2017-09-25 01:49:54 +00:00
|
|
|
done()
|
2017-09-25 02:19:25 +00:00
|
|
|
})
|
2017-09-20 02:58:10 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.relaunch', () => {
|
2016-06-03 03:12:20 +00:00
|
|
|
let server = null
|
2016-06-29 16:37:10 +00:00
|
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
|
2016-06-03 03:12:20 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
beforeEach(done => {
|
2016-06-29 16:37:10 +00:00
|
|
|
fs.unlink(socketPath, () => {
|
2016-06-03 03:12:20 +00:00
|
|
|
server = net.createServer()
|
|
|
|
server.listen(socketPath)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach((done) => {
|
2016-06-03 03:12:20 +00:00
|
|
|
server.close(() => {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
done()
|
|
|
|
} else {
|
2017-10-27 20:45:58 +00:00
|
|
|
fs.unlink(socketPath, () => done())
|
2016-06-03 03:12:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('relaunches the app', function (done) {
|
2016-11-29 22:31:57 +00:00
|
|
|
this.timeout(120000)
|
|
|
|
|
2016-06-03 03:12:20 +00:00
|
|
|
let state = 'none'
|
2018-06-14 16:44:27 +00:00
|
|
|
server.once('error', error => done(error))
|
|
|
|
server.on('connection', client => {
|
|
|
|
client.once('data', data => {
|
2016-06-03 03:12:20 +00:00
|
|
|
if (String(data) === 'false' && state === 'none') {
|
|
|
|
state = 'first-launch'
|
|
|
|
} else if (String(data) === 'true' && state === 'first-launch') {
|
|
|
|
done()
|
|
|
|
} else {
|
|
|
|
done(`Unexpected state: ${state}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'relaunch')
|
|
|
|
ChildProcess.spawn(remote.process.execPath, [appPath])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('app.setUserActivity(type, userInfo)', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2016-05-04 06:33:40 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('sets the current activity', () => {
|
2018-09-13 16:10:51 +00:00
|
|
|
app.setUserActivity('com.electron.testActivity', { testData: '123' })
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getCurrentActivityType()).to.equal('com.electron.testActivity')
|
2016-05-03 22:51:31 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
xdescribe('app.importCertificate', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
let w = null
|
2016-04-18 16:23:44 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'linux') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-04-18 16:23:44 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
it('can import certificate into platform cert store', done => {
|
|
|
|
const options = {
|
2016-04-20 03:15:49 +00:00
|
|
|
certificate: path.join(certPath, 'client.p12'),
|
2016-04-18 16:23:44 +00:00
|
|
|
password: 'electron'
|
|
|
|
}
|
|
|
|
|
2019-01-07 19:19:27 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
2016-04-18 16:23:44 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
w.webContents.on('did-finish-load', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(w.webContents.getTitle()).to.equal('authorized')
|
2016-04-18 16:23:44 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
ipcRenderer.once('select-client-certificate', (event, webContentsId, list) => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(webContentsId).to.equal(w.webContents.id)
|
|
|
|
expect(list).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
expect(list[0]).to.deep.equal({
|
|
|
|
issuerName: 'Intermediate CA',
|
|
|
|
subjectName: 'Client Cert',
|
|
|
|
issuer: { commonName: 'Intermediate CA' },
|
|
|
|
subject: { commonName: 'Client Cert' }
|
|
|
|
})
|
|
|
|
|
2016-12-07 10:03:56 +00:00
|
|
|
event.sender.send('client-certificate-response', list[0])
|
|
|
|
})
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
app.importCertificate(options, result => {
|
|
|
|
expect(result).toNotExist()
|
2016-12-02 17:34:16 +00:00
|
|
|
ipcRenderer.sendSync('set-client-certificate-option', false)
|
|
|
|
w.loadURL(secureUrl)
|
2016-04-18 16:23:44 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('BrowserWindow events', () => {
|
|
|
|
let w = null
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-03-25 19:57:17 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('should emit browser-window-focus event when window is focused', (done) => {
|
|
|
|
app.once('browser-window-focus', (e, window) => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(w.id).to.equal(window.id)
|
2016-03-25 19:57:17 +00:00
|
|
|
done()
|
|
|
|
})
|
2017-10-27 20:45:58 +00:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-03-25 19:57:17 +00:00
|
|
|
w.emit('focus')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('should emit browser-window-blur event when window is blured', (done) => {
|
|
|
|
app.once('browser-window-blur', (e, window) => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(w.id).to.equal(window.id)
|
2016-03-25 19:57:17 +00:00
|
|
|
done()
|
|
|
|
})
|
2017-10-27 20:45:58 +00:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-03-25 19:57:17 +00:00
|
|
|
w.emit('blur')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('should emit browser-window-created event when window is created', (done) => {
|
|
|
|
app.once('browser-window-created', (e, window) => {
|
|
|
|
setImmediate(() => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(w.id).to.equal(window.id)
|
2016-03-25 19:57:17 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-10-27 20:45:58 +00:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-06-13 16:05:04 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('should emit web-contents-created event when a webContents is created', (done) => {
|
|
|
|
app.once('web-contents-created', (e, webContents) => {
|
|
|
|
setImmediate(() => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(w.webContents.id).to.equal(webContents.id)
|
2016-06-13 16:05:04 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-10-27 20:45:58 +00:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2018-10-18 03:36:45 +00:00
|
|
|
|
2019-01-08 22:27:56 +00:00
|
|
|
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
|
2019-01-07 19:19:27 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
2019-01-08 22:27:56 +00:00
|
|
|
await w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const promise = emittedOnce(app, 'desktop-capturer-get-sources')
|
2018-12-20 02:44:30 +00:00
|
|
|
w.webContents.executeJavaScript(`require('electron').desktopCapturer.getSources({ types: ['screen'] }, () => {})`)
|
2019-01-08 22:27:56 +00:00
|
|
|
|
|
|
|
const [, webContents] = await promise
|
|
|
|
expect(webContents).to.equal(w.webContents)
|
2018-12-20 02:44:30 +00:00
|
|
|
})
|
|
|
|
|
2019-01-08 22:27:56 +00:00
|
|
|
it('should emit remote-require event when remote.require() is invoked', async () => {
|
2019-01-07 19:19:27 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
2019-01-08 22:27:56 +00:00
|
|
|
await w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const promise = emittedOnce(app, 'remote-require')
|
2018-10-18 03:36:45 +00:00
|
|
|
w.webContents.executeJavaScript(`require('electron').remote.require('test')`)
|
2019-01-08 22:27:56 +00:00
|
|
|
|
|
|
|
const [, webContents, moduleName] = await promise
|
|
|
|
expect(webContents).to.equal(w.webContents)
|
|
|
|
expect(moduleName).to.equal('test')
|
2018-10-18 03:36:45 +00:00
|
|
|
})
|
|
|
|
|
2019-01-08 22:27:56 +00:00
|
|
|
it('should emit remote-get-global event when remote.getGlobal() is invoked', async () => {
|
2019-01-07 19:19:27 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
2019-01-08 22:27:56 +00:00
|
|
|
await w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const promise = emittedOnce(app, 'remote-get-global')
|
2018-10-18 03:36:45 +00:00
|
|
|
w.webContents.executeJavaScript(`require('electron').remote.getGlobal('test')`)
|
2019-01-08 22:27:56 +00:00
|
|
|
|
|
|
|
const [, webContents, globalName] = await promise
|
|
|
|
expect(webContents).to.equal(w.webContents)
|
|
|
|
expect(globalName).to.equal('test')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should emit remote-get-builtin event when remote.getBuiltin() is invoked', async () => {
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const promise = emittedOnce(app, 'remote-get-builtin')
|
|
|
|
w.webContents.executeJavaScript(`require('electron').remote.app`)
|
|
|
|
|
|
|
|
const [, webContents, moduleName] = await promise
|
|
|
|
expect(webContents).to.equal(w.webContents)
|
|
|
|
expect(moduleName).to.equal('app')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should emit remote-get-current-window event when remote.getCurrentWindow() is invoked', async () => {
|
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
await w.loadURL('about:blank')
|
|
|
|
|
|
|
|
const promise = emittedOnce(app, 'remote-get-current-window')
|
|
|
|
w.webContents.executeJavaScript(`require('electron').remote.getCurrentWindow()`)
|
|
|
|
|
|
|
|
const [, webContents] = await promise
|
|
|
|
expect(webContents).to.equal(w.webContents)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should emit remote-get-current-web-contents event when remote.getCurrentWebContents() is invoked', async () => {
|
|
|
|
w = new BrowserWindow({
|
|
|
|
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)
|
2018-10-18 03:36:45 +00:00
|
|
|
})
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2016-06-29 17:47:20 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('app.setBadgeCount', () => {
|
|
|
|
const platformIsNotSupported =
|
|
|
|
(process.platform === 'win32') ||
|
|
|
|
(process.platform === 'linux' && !app.isUnityRunning())
|
|
|
|
const platformIsSupported = !platformIsNotSupported
|
2016-07-01 13:18:39 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
const expectedBadgeCount = 42
|
|
|
|
let returnValue = null
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
beforeEach(() => { returnValue = app.setBadgeCount(expectedBadgeCount) })
|
2017-11-15 21:05:46 +00:00
|
|
|
|
|
|
|
after(() => {
|
|
|
|
// Remove the badge.
|
2016-10-06 17:29:55 +00:00
|
|
|
app.setBadgeCount(0)
|
|
|
|
})
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('on supported platform', () => {
|
|
|
|
before(function () {
|
|
|
|
if (platformIsNotSupported) {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns true', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(returnValue).to.be.true()
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('sets a badge count', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getBadgeCount()).to.equal(expectedBadgeCount)
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-07-01 13:18:39 +00:00
|
|
|
})
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('on unsupported platform', () => {
|
|
|
|
before(function () {
|
|
|
|
if (platformIsSupported) {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns false', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(returnValue).to.be.false()
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('does not set a badge count', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getBadgeCount()).to.equal(0)
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-06-29 17:47:20 +00:00
|
|
|
})
|
|
|
|
})
|
2016-07-06 20:34:14 +00:00
|
|
|
|
2019-01-10 22:15:47 +00:00
|
|
|
describe('app.get/setLoginItemSettings API', function () {
|
|
|
|
// allow up to three retries to account for flaky mas results
|
|
|
|
this.retries(3)
|
|
|
|
|
2017-02-02 16:01:47 +00:00
|
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
|
|
|
const processStartArgs = [
|
|
|
|
'--processStart', `"${path.basename(process.execPath)}"`,
|
|
|
|
'--process-start-args', `"--hidden"`
|
|
|
|
]
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2019-01-10 22:15:47 +00:00
|
|
|
if (process.platform === 'linux') this.skip()
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
beforeEach(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
app.setLoginItemSettings({ openAtLogin: false })
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false, path: updateExe, args: processStartArgs })
|
2016-07-06 20:57:20 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => {
|
2018-09-13 16:10:51 +00:00
|
|
|
app.setLoginItemSettings({ openAtLogin: false })
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false, path: updateExe, args: processStartArgs })
|
2016-07-06 20:34:14 +00:00
|
|
|
})
|
|
|
|
|
2018-10-13 07:52:19 +00:00
|
|
|
it('sets and returns the app as a login item', done => {
|
2018-09-13 16:10:51 +00:00
|
|
|
app.setLoginItemSettings({ openAtLogin: true })
|
2017-11-20 01:15:45 +00:00
|
|
|
// Wait because login item settings are not applied immediately in MAS build
|
2018-10-19 20:11:11 +00:00
|
|
|
const delay = process.mas ? 250 : 0
|
2017-11-20 01:15:45 +00:00
|
|
|
setTimeout(() => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
2018-10-13 07:52:19 +00:00
|
|
|
openAtLogin: true,
|
2017-11-20 01:15:45 +00:00
|
|
|
openAsHidden: false,
|
|
|
|
wasOpenedAtLogin: false,
|
|
|
|
wasOpenedAsHidden: false,
|
|
|
|
restoreState: false
|
|
|
|
})
|
|
|
|
done()
|
2017-11-20 01:17:34 +00:00
|
|
|
}, delay)
|
2016-07-06 20:34:14 +00:00
|
|
|
})
|
2017-01-26 20:24:33 +00:00
|
|
|
|
2018-10-19 20:11:11 +00:00
|
|
|
it('adds a login item that loads in hidden mode', done => {
|
2018-10-13 07:52:19 +00:00
|
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: true })
|
2018-10-19 20:11:11 +00:00
|
|
|
// Wait because login item settings are not applied immediately in MAS build
|
|
|
|
const delay = process.mas ? 250 : 0
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(app.getLoginItemSettings()).to.deep.equal({
|
|
|
|
openAtLogin: true,
|
|
|
|
openAsHidden: process.platform === 'darwin' && !process.mas, // Only available on macOS
|
|
|
|
wasOpenedAtLogin: false,
|
|
|
|
wasOpenedAsHidden: false,
|
|
|
|
restoreState: false
|
|
|
|
})
|
|
|
|
done()
|
|
|
|
}, delay)
|
2018-10-13 07:52:19 +00:00
|
|
|
})
|
|
|
|
|
2018-11-06 19:31:32 +00:00
|
|
|
it('correctly sets and unsets the LoginItem', function () {
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.false()
|
|
|
|
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true })
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.true()
|
|
|
|
|
|
|
|
app.setLoginItemSettings({ openAtLogin: false })
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.false()
|
|
|
|
})
|
|
|
|
|
2018-10-12 22:19:27 +00:00
|
|
|
it('correctly sets and unsets the LoginItem as hidden', function () {
|
|
|
|
if (process.platform !== 'darwin' || process.mas) this.skip()
|
|
|
|
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.false()
|
|
|
|
expect(app.getLoginItemSettings().openAsHidden).to.be.false()
|
|
|
|
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: true })
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.true()
|
|
|
|
expect(app.getLoginItemSettings().openAsHidden).to.be.true()
|
|
|
|
|
|
|
|
app.setLoginItemSettings({ openAtLogin: true, openAsHidden: false })
|
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.true()
|
|
|
|
expect(app.getLoginItemSettings().openAsHidden).to.be.false()
|
|
|
|
})
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
it('allows you to pass a custom executable and arguments', function () {
|
2019-01-10 22:15:47 +00:00
|
|
|
if (process.platform !== 'win32') this.skip()
|
2017-01-26 20:24:33 +00:00
|
|
|
|
2018-09-13 16:10:51 +00:00
|
|
|
app.setLoginItemSettings({ openAtLogin: true, path: updateExe, args: processStartArgs })
|
2017-01-26 20:35:46 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getLoginItemSettings().openAtLogin).to.be.false()
|
|
|
|
expect(app.getLoginItemSettings({
|
|
|
|
path: updateExe,
|
|
|
|
args: processStartArgs
|
|
|
|
}).openAtLogin).to.be.true()
|
2017-01-26 20:24:33 +00:00
|
|
|
})
|
2016-07-06 20:34:14 +00:00
|
|
|
})
|
2016-07-11 21:32:24 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('isAccessibilitySupportEnabled API', () => {
|
|
|
|
it('returns whether the Chrome has accessibility APIs enabled', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isAccessibilitySupportEnabled()).to.be.a('boolean')
|
2016-07-11 21:32:24 +00:00
|
|
|
})
|
|
|
|
})
|
2016-10-06 16:57:25 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('getPath(name)', () => {
|
|
|
|
it('returns paths that exist', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
const paths = [
|
|
|
|
fs.existsSync(app.getPath('exe')),
|
|
|
|
fs.existsSync(app.getPath('home')),
|
|
|
|
fs.existsSync(app.getPath('temp'))
|
|
|
|
]
|
|
|
|
expect(paths).to.deep.equal([true, true, true])
|
2016-10-06 16:57:25 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('throws an error when the name is invalid', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(() => {
|
2016-10-06 16:57:25 +00:00
|
|
|
app.getPath('does-not-exist')
|
2018-06-14 16:44:27 +00:00
|
|
|
}).to.throw(/Failed to get 'does-not-exist' path/)
|
2016-10-06 16:57:25 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('returns the overridden path', () => {
|
2016-10-06 16:57:25 +00:00
|
|
|
app.setPath('music', __dirname)
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.getPath('music')).to.equal(__dirname)
|
2016-10-06 16:57:25 +00:00
|
|
|
})
|
|
|
|
})
|
2016-12-02 17:34:16 +00:00
|
|
|
|
2017-10-23 07:54:38 +00:00
|
|
|
describe('select-client-certificate event', () => {
|
2016-12-02 17:34:16 +00:00
|
|
|
let w = null
|
|
|
|
|
2018-03-09 05:43:49 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform === 'linux') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
beforeEach(() => {
|
2016-12-02 17:34:16 +00:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
2019-01-07 19:19:27 +00:00
|
|
|
nodeIntegration: true,
|
2016-12-02 17:34:16 +00:00
|
|
|
partition: 'empty-certificate'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-12-02 17:34:16 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
it('can respond with empty certificate list', done => {
|
2017-10-27 20:45:58 +00:00
|
|
|
w.webContents.on('did-finish-load', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(w.webContents.getTitle()).to.equal('denied')
|
2016-12-02 17:34:16 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcRenderer.sendSync('set-client-certificate-option', true)
|
|
|
|
w.webContents.loadURL(secureUrl)
|
|
|
|
})
|
|
|
|
})
|
2017-02-02 16:11:34 +00:00
|
|
|
|
|
|
|
describe('setAsDefaultProtocolClient(protocol, path, args)', () => {
|
2017-02-02 16:41:14 +00:00
|
|
|
const protocol = 'electron-test'
|
2017-02-02 16:11:34 +00:00
|
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
|
|
|
const processStartArgs = [
|
|
|
|
'--processStart', `"${path.basename(process.execPath)}"`,
|
|
|
|
'--process-start-args', `"--hidden"`
|
|
|
|
]
|
|
|
|
|
2017-12-05 19:28:39 +00:00
|
|
|
let Winreg
|
|
|
|
let classesKey
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
this.skip()
|
2017-12-05 19:28:39 +00:00
|
|
|
} else {
|
|
|
|
Winreg = require('winreg')
|
|
|
|
|
|
|
|
classesKey = new Winreg({
|
|
|
|
hive: Winreg.HKCU,
|
|
|
|
key: '\\Software\\Classes\\'
|
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-12-05 19:31:40 +00:00
|
|
|
after(function (done) {
|
2017-12-06 01:07:22 +00:00
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
done()
|
|
|
|
} else {
|
2017-12-05 20:14:19 +00:00
|
|
|
const protocolKey = new Winreg({
|
|
|
|
hive: Winreg.HKCU,
|
|
|
|
key: `\\Software\\Classes\\${protocol}`
|
|
|
|
})
|
2017-12-05 19:31:40 +00:00
|
|
|
|
2017-12-05 20:14:19 +00:00
|
|
|
// The last test leaves the registry dirty,
|
|
|
|
// delete the protocol key for those of us who test at home
|
|
|
|
protocolKey.destroy(() => done())
|
2017-12-05 21:20:34 +00:00
|
|
|
}
|
2017-12-05 19:31:40 +00:00
|
|
|
})
|
|
|
|
|
2017-02-02 16:11:34 +00:00
|
|
|
beforeEach(() => {
|
2017-02-02 16:41:14 +00:00
|
|
|
app.removeAsDefaultProtocolClient(protocol)
|
|
|
|
app.removeAsDefaultProtocolClient(protocol, updateExe, processStartArgs)
|
2017-02-02 16:11:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
2017-02-02 16:41:14 +00:00
|
|
|
app.removeAsDefaultProtocolClient(protocol)
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isDefaultProtocolClient(protocol)).to.be.false()
|
|
|
|
|
2017-02-02 16:41:14 +00:00
|
|
|
app.removeAsDefaultProtocolClient(protocol, updateExe, processStartArgs)
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs)).to.be.false()
|
2017-02-02 16:11:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('sets the app as the default protocol client', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isDefaultProtocolClient(protocol)).to.be.false()
|
2017-02-02 16:41:14 +00:00
|
|
|
app.setAsDefaultProtocolClient(protocol)
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isDefaultProtocolClient(protocol)).to.be.true()
|
2017-02-02 16:11:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('allows a custom path and args to be specified', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs)).to.be.false()
|
2017-02-02 16:41:14 +00:00
|
|
|
app.setAsDefaultProtocolClient(protocol, updateExe, processStartArgs)
|
2018-06-14 16:44:27 +00:00
|
|
|
|
|
|
|
expect(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs)).to.be.true()
|
|
|
|
expect(app.isDefaultProtocolClient(protocol)).to.be.false()
|
2017-02-02 16:11:34 +00:00
|
|
|
})
|
2017-12-05 19:28:39 +00:00
|
|
|
|
|
|
|
it('creates a registry entry for the protocol class', (done) => {
|
|
|
|
app.setAsDefaultProtocolClient(protocol)
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2017-12-05 19:28:39 +00:00
|
|
|
classesKey.keys((error, keys) => {
|
2018-06-14 16:44:27 +00:00
|
|
|
if (error) throw error
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
const exists = !!keys.find(key => key.key.includes(protocol))
|
|
|
|
expect(exists).to.be.true()
|
2017-12-05 19:28:39 +00:00
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('completely removes a registry entry for the protocol class', (done) => {
|
|
|
|
app.setAsDefaultProtocolClient(protocol)
|
|
|
|
app.removeAsDefaultProtocolClient(protocol)
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2017-12-05 19:28:39 +00:00
|
|
|
classesKey.keys((error, keys) => {
|
2018-06-14 16:44:27 +00:00
|
|
|
if (error) throw error
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
const exists = !!keys.find(key => key.key.includes(protocol))
|
|
|
|
expect(exists).to.be.false()
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2017-12-05 19:28:39 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('only unsets a class registry key if it contains other data', (done) => {
|
|
|
|
app.setAsDefaultProtocolClient(protocol)
|
|
|
|
|
|
|
|
const protocolKey = new Winreg({
|
|
|
|
hive: Winreg.HKCU,
|
|
|
|
key: `\\Software\\Classes\\${protocol}`
|
|
|
|
})
|
|
|
|
|
|
|
|
protocolKey.set('test-value', 'REG_BINARY', '123', () => {
|
|
|
|
app.removeAsDefaultProtocolClient(protocol)
|
|
|
|
|
|
|
|
classesKey.keys((error, keys) => {
|
2018-06-14 16:44:27 +00:00
|
|
|
if (error) throw error
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
const exists = !!keys.find(key => key.key.includes(protocol))
|
|
|
|
expect(exists).to.be.true()
|
2017-12-05 19:38:19 +00:00
|
|
|
|
2017-12-05 19:28:39 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-02-02 16:11:34 +00:00
|
|
|
})
|
2016-11-06 10:59:17 +00:00
|
|
|
|
2018-01-22 22:49:30 +00:00
|
|
|
describe('app launch through uri', () => {
|
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
it('does not launch for argument following a URL', done => {
|
2018-01-22 22:49:30 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
|
|
|
// App should exit with non 123 code.
|
2018-05-22 16:51:03 +00:00
|
|
|
const first = ChildProcess.spawn(remote.process.execPath, [appPath, 'electron-test:?', 'abc'])
|
2018-06-14 16:44:27 +00:00
|
|
|
first.once('exit', code => {
|
|
|
|
expect(code).to.not.equal(123)
|
2018-01-22 22:49:30 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
it('launches successfully for argument following a file path', done => {
|
2018-01-22 22:49:30 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
|
|
|
// App should exit with code 123.
|
2018-05-22 16:51:03 +00:00
|
|
|
const first = ChildProcess.spawn(remote.process.execPath, [appPath, 'e:\\abc', 'abc'])
|
2018-06-14 16:44:27 +00:00
|
|
|
first.once('exit', code => {
|
|
|
|
expect(code).to.equal(123)
|
2018-01-22 22:49:30 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
it('launches successfully for multiple URIs following --', done => {
|
2018-01-22 22:49:30 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
2018-05-22 16:51:03 +00:00
|
|
|
// App should exit with code 123.
|
|
|
|
const first = ChildProcess.spawn(remote.process.execPath, [appPath, '--', 'http://electronjs.org', 'electron-test://testdata'])
|
2018-06-14 16:44:27 +00:00
|
|
|
first.once('exit', code => {
|
|
|
|
expect(code).to.equal(123)
|
2018-01-22 22:49:30 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-01-17 22:17:16 +00:00
|
|
|
describe('getFileIcon() API', (done) => {
|
2016-11-10 18:34:30 +00:00
|
|
|
const iconPath = path.join(__dirname, 'fixtures/assets/icon.ico')
|
2016-11-06 10:59:17 +00:00
|
|
|
const sizes = {
|
|
|
|
small: 16,
|
|
|
|
normal: 32,
|
2017-02-07 19:20:27 +00:00
|
|
|
large: process.platform === 'win32' ? 32 : 48
|
2016-11-06 11:03:16 +00:00
|
|
|
}
|
2016-11-06 10:59:17 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
// (alexeykuzmin): `.skip()` called in `before`
|
|
|
|
// doesn't affect nested `describe`s.
|
|
|
|
beforeEach(function () {
|
|
|
|
// FIXME Get these specs running on Linux CI
|
|
|
|
if (process.platform === 'linux' && isCI) {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
it('fetches a non-empty icon', async () => {
|
|
|
|
const icon = await app.getFileIcon(iconPath)
|
|
|
|
expect(icon.isEmpty()).to.be.false()
|
2016-11-06 10:59:17 +00:00
|
|
|
})
|
|
|
|
|
2019-01-17 22:17:16 +00:00
|
|
|
// TODO(codebytere): remove when promisification is complete
|
|
|
|
it('fetches a non-empty icon (callback)', () => {
|
|
|
|
app.getFileIcon(iconPath, (icon) => {
|
|
|
|
expect(icon.isEmpty()).to.be.false()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
it('fetches normal icon size by default', async () => {
|
|
|
|
const icon = await app.getFileIcon(iconPath)
|
|
|
|
const size = icon.getSize()
|
2018-06-14 16:44:27 +00:00
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
expect(size.height).to.equal(sizes.normal)
|
|
|
|
expect(size.width).to.equal(sizes.normal)
|
2016-11-06 10:59:17 +00:00
|
|
|
})
|
|
|
|
|
2019-01-17 22:17:16 +00:00
|
|
|
// TODO(codebytere): remove when promisification is complete
|
|
|
|
it('fetches normal icon size by default (callback)', () => {
|
|
|
|
app.getFileIcon(iconPath, (icon) => {
|
|
|
|
const size = icon.getSize()
|
|
|
|
|
|
|
|
expect(size.height).to.equal(sizes.normal)
|
|
|
|
expect(size.width).to.equal(sizes.normal)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('size option', () => {
|
2018-12-05 16:50:12 +00:00
|
|
|
it('fetches a small icon', async () => {
|
|
|
|
const icon = await app.getFileIcon(iconPath, { size: 'small' })
|
|
|
|
const size = icon.getSize()
|
|
|
|
|
|
|
|
expect(size.height).to.equal(sizes.small)
|
|
|
|
expect(size.width).to.equal(sizes.small)
|
2016-11-06 10:59:17 +00:00
|
|
|
})
|
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
it('fetches a normal icon', async () => {
|
|
|
|
const icon = await app.getFileIcon(iconPath, { size: 'normal' })
|
|
|
|
const size = icon.getSize()
|
|
|
|
|
|
|
|
expect(size.height).to.equal(sizes.normal)
|
|
|
|
expect(size.width).to.equal(sizes.normal)
|
2016-11-06 10:59:17 +00:00
|
|
|
})
|
|
|
|
|
2019-01-17 22:17:16 +00:00
|
|
|
// TODO(codebytere): remove when promisification is complete
|
|
|
|
it('fetches a normal icon (callback)', () => {
|
|
|
|
app.getFileIcon(iconPath, { size: 'normal' }, (icon) => {
|
|
|
|
const size = icon.getSize()
|
|
|
|
|
|
|
|
expect(size.height).to.equal(sizes.normal)
|
|
|
|
expect(size.width).to.equal(sizes.normal)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
it('fetches a large icon', async () => {
|
2017-02-07 18:16:09 +00:00
|
|
|
// macOS does not support large icons
|
2018-12-05 16:50:12 +00:00
|
|
|
if (process.platform === 'darwin') return
|
2017-02-07 18:16:09 +00:00
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
const icon = await app.getFileIcon(iconPath, { size: 'large' })
|
|
|
|
const size = icon.getSize()
|
|
|
|
|
|
|
|
expect(size.height).to.equal(sizes.large)
|
|
|
|
expect(size.width).to.equal(sizes.large)
|
2016-11-06 10:59:17 +00:00
|
|
|
})
|
|
|
|
})
|
2017-04-27 15:38:17 +00:00
|
|
|
})
|
2017-04-27 04:04:53 +00:00
|
|
|
|
2018-08-09 18:35:29 +00:00
|
|
|
describe('getAppMetrics() API', () => {
|
2018-06-18 04:00:17 +00:00
|
|
|
it('returns memory and cpu stats of all running electron processes', () => {
|
2017-05-16 00:41:45 +00:00
|
|
|
const appMetrics = app.getAppMetrics()
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(appMetrics).to.be.an('array').and.have.lengthOf.at.least(1, 'App memory info object is not > 0')
|
|
|
|
|
2017-05-26 15:53:26 +00:00
|
|
|
const types = []
|
2018-09-13 16:10:51 +00:00
|
|
|
for (const { pid, type, cpu } of appMetrics) {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(pid).to.be.above(0, 'pid is not > 0')
|
|
|
|
expect(type).to.be.a('string').that.is.not.empty()
|
|
|
|
|
2017-05-26 15:53:26 +00:00
|
|
|
types.push(type)
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(cpu).to.have.own.property('percentCPUUsage').that.is.a('number')
|
|
|
|
expect(cpu).to.have.own.property('idleWakeupsPerSecond').that.is.a('number')
|
2017-05-04 20:43:45 +00:00
|
|
|
}
|
2017-05-26 15:53:26 +00:00
|
|
|
|
2017-05-26 17:10:56 +00:00
|
|
|
if (process.platform === 'darwin') {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(types).to.include('GPU')
|
2017-05-26 16:14:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(types).to.include('Browser')
|
|
|
|
expect(types).to.include('Tab')
|
2017-04-27 04:04:53 +00:00
|
|
|
})
|
2016-11-06 10:59:17 +00:00
|
|
|
})
|
2017-05-30 20:00:00 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('getGPUFeatureStatus() API', () => {
|
|
|
|
it('returns the graphic features statuses', () => {
|
2017-05-30 20:00:00 +00:00
|
|
|
const features = app.getGPUFeatureStatus()
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(features).to.have.own.property('webgl').that.is.a('string')
|
|
|
|
expect(features).to.have.own.property('gpu_compositing').that.is.a('string')
|
2017-05-30 20:00:00 +00:00
|
|
|
})
|
|
|
|
})
|
2017-06-28 15:33:06 +00:00
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
describe('getGPUInfo() API', () => {
|
2018-10-02 01:34:52 +00:00
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'gpu-info.js')
|
|
|
|
|
|
|
|
const getGPUInfo = async (type) => {
|
|
|
|
const appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, type])
|
|
|
|
let gpuInfoData = ''
|
|
|
|
let errorData = ''
|
|
|
|
appProcess.stdout.on('data', (data) => {
|
|
|
|
gpuInfoData += data
|
|
|
|
})
|
|
|
|
appProcess.stderr.on('data', (data) => {
|
|
|
|
errorData += data
|
|
|
|
})
|
|
|
|
const [exitCode] = await emittedOnce(appProcess, 'exit')
|
|
|
|
if (exitCode === 0) {
|
|
|
|
// return info data on successful exit
|
|
|
|
return JSON.parse(gpuInfoData)
|
|
|
|
} else {
|
|
|
|
// return error if not clean exit
|
|
|
|
return Promise.reject(new Error(errorData))
|
2018-10-01 02:57:38 +00:00
|
|
|
}
|
2018-10-02 01:34:52 +00:00
|
|
|
}
|
|
|
|
const verifyBasicGPUInfo = async (gpuInfo) => {
|
|
|
|
// Devices information is always present in the available info.
|
|
|
|
expect(gpuInfo).to.have.own.property('gpuDevice')
|
|
|
|
.that.is.an('array')
|
|
|
|
.and.is.not.empty()
|
|
|
|
|
|
|
|
const device = gpuInfo.gpuDevice[0]
|
|
|
|
expect(device).to.be.an('object')
|
|
|
|
.and.to.have.property('deviceId')
|
|
|
|
.that.is.a('number')
|
|
|
|
.not.lessThan(0)
|
|
|
|
}
|
2018-10-01 02:57:38 +00:00
|
|
|
|
2018-10-02 01:34:52 +00:00
|
|
|
it('succeeds with basic GPUInfo', async () => {
|
|
|
|
const gpuInfo = await getGPUInfo('basic')
|
|
|
|
await verifyBasicGPUInfo(gpuInfo)
|
2018-09-27 14:59:23 +00:00
|
|
|
})
|
|
|
|
|
2018-10-15 15:26:47 +00:00
|
|
|
it('succeeds with complete GPUInfo', async () => {
|
2018-10-02 01:34:52 +00:00
|
|
|
const completeInfo = await getGPUInfo('complete')
|
2018-10-15 15:26:47 +00:00
|
|
|
if (process.platform === 'linux') {
|
2018-10-08 04:06:50 +00:00
|
|
|
// For linux and macOS complete info is same as basic info
|
2018-10-02 01:34:52 +00:00
|
|
|
await verifyBasicGPUInfo(completeInfo)
|
|
|
|
const basicInfo = await getGPUInfo('basic')
|
|
|
|
expect(completeInfo).to.deep.equal(basicInfo)
|
|
|
|
} else {
|
|
|
|
// Gl version is present in the complete info.
|
|
|
|
expect(completeInfo).to.have.own.property('auxAttributes')
|
|
|
|
.that.is.an('object')
|
|
|
|
expect(completeInfo.auxAttributes).to.have.own.property('glVersion')
|
|
|
|
.that.is.a('string')
|
|
|
|
.and.not.empty()
|
|
|
|
}
|
2018-09-27 14:59:23 +00:00
|
|
|
})
|
|
|
|
|
2018-10-02 01:34:52 +00:00
|
|
|
it('fails for invalid info_type', () => {
|
|
|
|
const invalidType = 'invalid'
|
2018-10-15 15:26:47 +00:00
|
|
|
const expectedErrorMessage = "Invalid info type. Use 'basic' or 'complete'"
|
|
|
|
return expect(app.getGPUInfo(invalidType)).to.eventually.be.rejectedWith(expectedErrorMessage)
|
2018-09-27 14:59:23 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-10-10 04:32:09 +00:00
|
|
|
describe('sandbox options', () => {
|
2017-06-28 16:27:19 +00:00
|
|
|
let appProcess = null
|
|
|
|
let server = null
|
|
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
|
2017-06-28 15:33:06 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
beforeEach(function (done) {
|
2018-12-06 01:42:12 +00:00
|
|
|
if (process.platform === 'linux' && (process.arch === 'arm64' || process.arch === 'arm')) {
|
|
|
|
// Our ARM tests are run on VSTS rather than CircleCI, and the Docker
|
|
|
|
// setup on VSTS disallows syscalls that Chrome requires for setting up
|
|
|
|
// sandboxing.
|
|
|
|
// See:
|
|
|
|
// - https://docs.docker.com/engine/security/seccomp/#significant-syscalls-blocked-by-the-default-profile
|
|
|
|
// - https://chromium.googlesource.com/chromium/src/+/70.0.3538.124/sandbox/linux/services/credentials.cc#292
|
|
|
|
// - https://github.com/docker/docker-ce/blob/ba7dfc59ccfe97c79ee0d1379894b35417b40bca/components/engine/profiles/seccomp/seccomp_default.go#L497
|
|
|
|
// - https://blog.jessfraz.com/post/how-to-use-new-docker-seccomp-profiles/
|
|
|
|
//
|
|
|
|
// Adding `--cap-add SYS_ADMIN` or `--security-opt seccomp=unconfined`
|
|
|
|
// to the Docker invocation allows the syscalls that Chrome needs, but
|
|
|
|
// are probably more permissive than we'd like.
|
2017-11-15 21:05:46 +00:00
|
|
|
this.skip()
|
|
|
|
}
|
2017-06-28 16:27:19 +00:00
|
|
|
fs.unlink(socketPath, () => {
|
|
|
|
server = net.createServer()
|
|
|
|
server.listen(socketPath)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-06-14 16:44:27 +00:00
|
|
|
afterEach(done => {
|
2017-10-27 20:45:58 +00:00
|
|
|
if (appProcess != null) appProcess.kill()
|
2017-06-28 16:27:19 +00:00
|
|
|
|
|
|
|
server.close(() => {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
done()
|
|
|
|
} else {
|
2017-10-27 20:45:58 +00:00
|
|
|
fs.unlink(socketPath, () => done())
|
2017-06-28 16:27:19 +00:00
|
|
|
}
|
|
|
|
})
|
2017-06-28 15:33:06 +00:00
|
|
|
})
|
|
|
|
|
2018-10-10 04:32:09 +00:00
|
|
|
describe('when app.enableSandbox() is called', () => {
|
|
|
|
it('adds --enable-sandbox to all renderer processes', done => {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
|
|
|
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, '--app-enable-sandbox'])
|
|
|
|
|
|
|
|
server.once('error', error => { done(error) })
|
|
|
|
|
|
|
|
server.on('connection', client => {
|
|
|
|
client.once('data', data => {
|
|
|
|
const argv = JSON.parse(data)
|
|
|
|
expect(argv.sandbox).to.include('--enable-sandbox')
|
|
|
|
expect(argv.sandbox).to.not.include('--no-sandbox')
|
|
|
|
|
|
|
|
expect(argv.noSandbox).to.include('--enable-sandbox')
|
|
|
|
expect(argv.noSandbox).to.not.include('--no-sandbox')
|
|
|
|
|
|
|
|
expect(argv.noSandboxDevtools).to.be.true()
|
|
|
|
expect(argv.sandboxDevtools).to.be.true()
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the app is launched with --enable-sandbox', () => {
|
|
|
|
it('adds --enable-sandbox to all renderer processes', done => {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
|
|
|
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, '--enable-sandbox'])
|
|
|
|
|
|
|
|
server.once('error', error => { done(error) })
|
|
|
|
|
|
|
|
server.on('connection', client => {
|
|
|
|
client.once('data', data => {
|
|
|
|
const argv = JSON.parse(data)
|
|
|
|
expect(argv.sandbox).to.include('--enable-sandbox')
|
|
|
|
expect(argv.sandbox).to.not.include('--no-sandbox')
|
|
|
|
|
|
|
|
expect(argv.noSandbox).to.include('--enable-sandbox')
|
|
|
|
expect(argv.noSandbox).to.not.include('--no-sandbox')
|
|
|
|
|
|
|
|
expect(argv.noSandboxDevtools).to.be.true()
|
|
|
|
expect(argv.sandboxDevtools).to.be.true()
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-06-28 15:33:06 +00:00
|
|
|
})
|
2017-07-13 22:27:03 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('disableDomainBlockingFor3DAPIs() API', () => {
|
|
|
|
it('throws when called after app is ready', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(() => {
|
2017-07-13 22:27:03 +00:00
|
|
|
app.disableDomainBlockingFor3DAPIs()
|
2018-06-14 16:44:27 +00:00
|
|
|
}).to.throw(/before app is ready/)
|
2017-07-13 22:27:03 +00:00
|
|
|
})
|
|
|
|
})
|
2018-02-27 06:15:06 +00:00
|
|
|
|
|
|
|
describe('dock.setMenu', () => {
|
|
|
|
before(function () {
|
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('keeps references to the menu', () => {
|
|
|
|
app.dock.setMenu(new Menu())
|
|
|
|
const v8Util = process.atomBinding('v8_util')
|
|
|
|
v8Util.requestGarbageCollectionForTesting()
|
|
|
|
})
|
|
|
|
})
|
2018-04-20 07:09:23 +00:00
|
|
|
|
|
|
|
describe('whenReady', () => {
|
|
|
|
it('returns a Promise', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.whenReady()).to.be.a('promise')
|
2018-04-20 07:09:23 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('becomes fulfilled if the app is already ready', () => {
|
2018-06-14 16:44:27 +00:00
|
|
|
expect(app.isReady()).to.be.true()
|
2018-04-20 07:09:23 +00:00
|
|
|
return expect(app.whenReady()).to.be.eventually.fulfilled
|
|
|
|
})
|
|
|
|
})
|
2019-01-07 15:48:27 +00:00
|
|
|
|
|
|
|
describe('commandLine.hasSwitch', () => {
|
|
|
|
it('returns true when present', () => {
|
|
|
|
app.commandLine.appendSwitch('foobar1')
|
|
|
|
expect(app.commandLine.hasSwitch('foobar1')).to.be.true()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns false when not present', () => {
|
|
|
|
expect(app.commandLine.hasSwitch('foobar2')).to.be.false()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('commandLine.hasSwitch (existing argv)', () => {
|
|
|
|
it('returns true when present', async () => {
|
2019-01-15 20:35:53 +00:00
|
|
|
const { hasSwitch } = await runTestApp('command-line', '--foobar')
|
2019-01-07 15:48:27 +00:00
|
|
|
expect(hasSwitch).to.be.true()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns false when not present', async () => {
|
2019-01-15 20:35:53 +00:00
|
|
|
const { hasSwitch } = await runTestApp('command-line')
|
2019-01-07 15:48:27 +00:00
|
|
|
expect(hasSwitch).to.be.false()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('commandLine.getSwitchValue', () => {
|
|
|
|
it('returns the value when present', () => {
|
|
|
|
app.commandLine.appendSwitch('foobar', 'æøåü')
|
|
|
|
expect(app.commandLine.getSwitchValue('foobar')).to.equal('æøåü')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns an empty string when present without value', () => {
|
|
|
|
app.commandLine.appendSwitch('foobar1')
|
|
|
|
expect(app.commandLine.getSwitchValue('foobar1')).to.equal('')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns an empty string when not present', () => {
|
|
|
|
expect(app.commandLine.getSwitchValue('foobar2')).to.equal('')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('commandLine.getSwitchValue (existing argv)', () => {
|
|
|
|
it('returns the value when present', async () => {
|
2019-01-15 20:35:53 +00:00
|
|
|
const { getSwitchValue } = await runTestApp('command-line', '--foobar=test')
|
2019-01-07 15:48:27 +00:00
|
|
|
expect(getSwitchValue).to.equal('test')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns an empty string when present without value', async () => {
|
2019-01-15 20:35:53 +00:00
|
|
|
const { getSwitchValue } = await runTestApp('command-line', '--foobar')
|
2019-01-07 15:48:27 +00:00
|
|
|
expect(getSwitchValue).to.equal('')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('returns an empty string when not present', async () => {
|
2019-01-15 20:35:53 +00:00
|
|
|
const { getSwitchValue } = await runTestApp('command-line')
|
2019-01-07 15:48:27 +00:00
|
|
|
expect(getSwitchValue).to.equal('')
|
|
|
|
})
|
|
|
|
})
|
2019-01-15 20:35:53 +00:00
|
|
|
})
|
2019-01-07 15:48:27 +00:00
|
|
|
|
2019-01-15 20:35:53 +00:00
|
|
|
describe('default behavior', () => {
|
|
|
|
describe('application menu', () => {
|
|
|
|
it('creates the default menu if the app does not set it', async () => {
|
|
|
|
const result = await runTestApp('default-menu')
|
|
|
|
expect(result).to.equal(false)
|
|
|
|
})
|
2019-01-07 15:48:27 +00:00
|
|
|
|
2019-01-15 20:35:53 +00:00
|
|
|
it('does not create the default menu if the app sets a custom menu', async () => {
|
|
|
|
const result = await runTestApp('default-menu', '--custom-menu')
|
|
|
|
expect(result).to.equal(true)
|
|
|
|
})
|
2019-01-07 15:48:27 +00:00
|
|
|
|
2019-01-15 20:35:53 +00:00
|
|
|
it('does not create the default menu if the app sets a null menu', async () => {
|
|
|
|
const result = await runTestApp('default-menu', '--null-menu')
|
|
|
|
expect(result).to.equal(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('window-all-closed', () => {
|
|
|
|
it('quits when the app does not handle the event', async () => {
|
|
|
|
const result = await runTestApp('window-all-closed')
|
|
|
|
expect(result).to.equal(false)
|
|
|
|
})
|
2019-01-07 15:48:27 +00:00
|
|
|
|
2019-01-15 20:35:53 +00:00
|
|
|
it('does not quit when the app handles the event', async () => {
|
|
|
|
const result = await runTestApp('window-all-closed', '--handle-event')
|
|
|
|
expect(result).to.equal(true)
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 19:57:17 +00:00
|
|
|
})
|
2019-01-15 20:35:53 +00:00
|
|
|
|
|
|
|
async function runTestApp (name, ...args) {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', name)
|
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
|
|
|
const appProcess = cp.spawn(electronPath, [appPath, ...args])
|
|
|
|
|
|
|
|
let output = ''
|
|
|
|
appProcess.stdout.on('data', (data) => { output += data })
|
|
|
|
|
|
|
|
await emittedOnce(appProcess.stdout, 'end')
|
|
|
|
|
|
|
|
return JSON.parse(output)
|
|
|
|
}
|