2016-03-25 22:57:17 +03:00
|
|
|
const assert = require('assert')
|
|
|
|
const ChildProcess = require('child_process')
|
2016-04-18 19:23:44 +03:00
|
|
|
const https = require('https')
|
2016-06-03 06:12:20 +03:00
|
|
|
const net = require('net')
|
2016-04-18 19:23:44 +03:00
|
|
|
const fs = require('fs')
|
2016-03-25 22:57:17 +03:00
|
|
|
const path = require('path')
|
2016-12-02 20:34:16 +03:00
|
|
|
const {ipcRenderer, remote} = require('electron')
|
2016-08-03 22:47:53 +03:00
|
|
|
const {closeWindow} = require('./window-helpers')
|
2016-03-25 22:57:17 +03:00
|
|
|
|
2016-05-23 23:12:02 +03:00
|
|
|
const {app, BrowserWindow, ipcMain} = remote
|
2016-03-25 22:57:17 +03:00
|
|
|
|
2017-02-08 05:24:35 +03:00
|
|
|
const isCI = remote.getGlobal('isCi')
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('electron module', () => {
|
|
|
|
it('does not expose internal modules to require', () => {
|
|
|
|
assert.throws(() => {
|
2016-03-25 22:57:17 +03:00
|
|
|
require('clipboard')
|
2016-04-28 19:58:59 +03:00
|
|
|
}, /Cannot find module 'clipboard'/)
|
2016-03-25 22:57:17 +03:00
|
|
|
})
|
2016-05-23 23:12:02 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('require("electron")', () => {
|
2016-05-23 23:12:02 +03:00
|
|
|
let window = null
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
beforeEach(() => {
|
2016-05-23 23:12:02 +03:00
|
|
|
window = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
width: 400,
|
|
|
|
height: 400
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => {
|
|
|
|
return closeWindow(window).then(() => { window = null })
|
2016-05-23 23:12:02 +03:00
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('always returns the internal electron module', (done) => {
|
|
|
|
ipcMain.once('answer', () => done())
|
|
|
|
window.loadURL(`file://${path.join(__dirname, 'fixtures', 'api', 'electron-module-app', 'index.html')}`)
|
2016-05-23 23:12:02 +03:00
|
|
|
})
|
|
|
|
})
|
2016-03-25 22:57:17 +03:00
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app module', () => {
|
2016-12-02 20:34:16 +03:00
|
|
|
let server, secureUrl
|
|
|
|
const certPath = path.join(__dirname, 'fixtures', 'certificates')
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
before(() => {
|
2016-12-02 20:34:16 +03: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 23:45:58 +03:00
|
|
|
server = https.createServer(options, (req, res) => {
|
2016-12-02 20:34:16 +03: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 23:45:58 +03:00
|
|
|
server.listen(0, '127.0.0.1', () => {
|
2016-12-02 20:34:16 +03:00
|
|
|
const port = server.address().port
|
|
|
|
secureUrl = `https://127.0.0.1:${port}`
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
after(() => {
|
2016-12-02 20:34:16 +03:00
|
|
|
server.close()
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.getVersion()', () => {
|
|
|
|
it('returns the version field of package.json', () => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(app.getVersion(), '0.1.0')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.setVersion(version)', () => {
|
|
|
|
it('overrides the version', () => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(app.getVersion(), '0.1.0')
|
|
|
|
app.setVersion('test-version')
|
|
|
|
assert.equal(app.getVersion(), 'test-version')
|
|
|
|
app.setVersion('0.1.0')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.getName()', () => {
|
|
|
|
it('returns the name field of package.json', () => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(app.getName(), 'Electron Test')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.setName(name)', () => {
|
|
|
|
it('overrides the name', () => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(app.getName(), 'Electron Test')
|
|
|
|
app.setName('test-name')
|
|
|
|
assert.equal(app.getName(), 'test-name')
|
|
|
|
app.setName('Electron Test')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.getLocale()', () => {
|
|
|
|
it('should not be empty', () => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.notEqual(app.getLocale(), '')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.isInApplicationsFolder()', () => {
|
|
|
|
it('should be false during tests', () => {
|
2017-08-31 17:37:12 +03:00
|
|
|
if (process.platform !== 'darwin') return
|
|
|
|
assert.equal(app.isInApplicationsFolder(), false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.exit(exitCode)', () => {
|
|
|
|
let appProcess = null
|
2016-03-25 22:57:17 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => {
|
2016-11-30 01:19:20 +03:00
|
|
|
if (appProcess != null) appProcess.kill()
|
2016-03-25 22:57:17 +03:00
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('emits a process exit event with the code', (done) => {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
|
|
|
const electronPath = remote.getGlobal('process').execPath
|
|
|
|
let output = ''
|
2016-03-25 22:57:17 +03:00
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
2017-10-27 23:45:58 +03:00
|
|
|
appProcess.stdout.on('data', (data) => {
|
2016-03-25 22:57:17 +03:00
|
|
|
output += data
|
|
|
|
})
|
2017-10-27 23:45:58 +03:00
|
|
|
appProcess.on('close', (code) => {
|
2016-01-12 05:40:23 +03:00
|
|
|
if (process.platform !== 'win32') {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.notEqual(output.indexOf('Exit event with code: 123'), -1)
|
2016-01-12 05:40:23 +03:00
|
|
|
}
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(code, 123)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-04-07 01:02:32 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('closes all windows', (done) => {
|
2017-04-07 01:02:32 +03:00
|
|
|
var appPath = path.join(__dirname, 'fixtures', 'api', 'exit-closes-all-windows-app')
|
|
|
|
var electronPath = remote.getGlobal('process').execPath
|
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
|
|
|
appProcess.on('close', function (code) {
|
|
|
|
assert.equal(code, 123)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 22:57:17 +03:00
|
|
|
})
|
2016-02-17 04:09:41 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.makeSingleInstance', () => {
|
2017-09-20 05:58:10 +03:00
|
|
|
it('prevents the second launch of app', function (done) {
|
|
|
|
this.timeout(120000)
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
|
|
|
|
// First launch should exit with 0.
|
|
|
|
const first = ChildProcess.spawn(remote.process.execPath, [appPath])
|
|
|
|
first.once('exit', (code) => {
|
|
|
|
assert.equal(code, 0)
|
|
|
|
})
|
2017-09-25 05:19:25 +03:00
|
|
|
// Start second app when received output.
|
|
|
|
first.stdout.once('data', () => {
|
|
|
|
// Second launch should exit with 1.
|
|
|
|
const second = ChildProcess.spawn(remote.process.execPath, [appPath])
|
|
|
|
second.once('exit', (code) => {
|
|
|
|
assert.equal(code, 1)
|
2017-09-25 04:49:54 +03:00
|
|
|
done()
|
2017-09-25 05:19:25 +03:00
|
|
|
})
|
2017-09-20 05:58:10 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.relaunch', () => {
|
2016-06-03 06:12:20 +03:00
|
|
|
let server = null
|
2016-06-29 19:37:10 +03:00
|
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
|
2016-06-03 06:12:20 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
beforeEach((done) => {
|
2016-06-29 19:37:10 +03:00
|
|
|
fs.unlink(socketPath, () => {
|
2016-06-03 06:12:20 +03:00
|
|
|
server = net.createServer()
|
|
|
|
server.listen(socketPath)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach((done) => {
|
2016-06-03 06:12:20 +03:00
|
|
|
server.close(() => {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
done()
|
|
|
|
} else {
|
2017-10-27 23:45:58 +03:00
|
|
|
fs.unlink(socketPath, () => done())
|
2016-06-03 06:12:20 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('relaunches the app', function (done) {
|
2016-11-30 01:31:57 +03:00
|
|
|
this.timeout(120000)
|
|
|
|
|
2016-06-03 06:12:20 +03:00
|
|
|
let state = 'none'
|
2017-10-27 23:45:58 +03:00
|
|
|
server.once('error', (error) => done(error))
|
2016-06-03 06:12:20 +03:00
|
|
|
server.on('connection', (client) => {
|
2017-10-27 23:45:58 +03:00
|
|
|
client.once('data', (data) => {
|
2016-06-03 06:12:20 +03: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 23:45:58 +03:00
|
|
|
describe('app.setUserActivity(type, userInfo)', () => {
|
|
|
|
if (process.platform !== 'darwin') return
|
2016-05-04 09:33:40 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('sets the current activity', () => {
|
2016-06-29 19:37:10 +03:00
|
|
|
app.setUserActivity('com.electron.testActivity', {testData: '123'})
|
|
|
|
assert.equal(app.getCurrentActivityType(), 'com.electron.testActivity')
|
2016-05-04 01:51:31 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
xdescribe('app.importCertificate', () => {
|
2016-06-29 19:37:10 +03:00
|
|
|
if (process.platform !== 'linux') return
|
2016-04-18 19:23:44 +03:00
|
|
|
|
|
|
|
var w = null
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-04-18 19:23:44 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('can import certificate into platform cert store', (done) => {
|
2016-04-18 19:23:44 +03:00
|
|
|
let options = {
|
2016-04-20 06:15:49 +03:00
|
|
|
certificate: path.join(certPath, 'client.p12'),
|
2016-04-18 19:23:44 +03:00
|
|
|
password: 'electron'
|
|
|
|
}
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-04-18 19:23:44 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
w.webContents.on('did-finish-load', () => {
|
2016-12-02 20:34:16 +03:00
|
|
|
assert.equal(w.webContents.getTitle(), 'authorized')
|
2016-04-18 19:23:44 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
ipcRenderer.once('select-client-certificate', (event, webContentsId, list) => {
|
2016-12-07 13:03:56 +03:00
|
|
|
assert.equal(webContentsId, w.webContents.id)
|
|
|
|
assert.equal(list.length, 1)
|
|
|
|
assert.equal(list[0].issuerName, 'Intermediate CA')
|
|
|
|
assert.equal(list[0].subjectName, 'Client Cert')
|
|
|
|
assert.equal(list[0].issuer.commonName, 'Intermediate CA')
|
|
|
|
assert.equal(list[0].subject.commonName, 'Client Cert')
|
|
|
|
event.sender.send('client-certificate-response', list[0])
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
app.importCertificate(options, (result) => {
|
2016-04-18 19:23:44 +03:00
|
|
|
assert(!result)
|
2016-12-02 20:34:16 +03:00
|
|
|
ipcRenderer.sendSync('set-client-certificate-option', false)
|
|
|
|
w.loadURL(secureUrl)
|
2016-04-18 19:23:44 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('BrowserWindow events', () => {
|
|
|
|
let w = null
|
2016-02-17 04:09:41 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-03-25 22:57:17 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('should emit browser-window-focus event when window is focused', (done) => {
|
|
|
|
app.once('browser-window-focus', (e, window) => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(w.id, window.id)
|
|
|
|
done()
|
|
|
|
})
|
2017-10-27 23:45:58 +03:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-03-25 22:57:17 +03:00
|
|
|
w.emit('focus')
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('should emit browser-window-blur event when window is blured', (done) => {
|
|
|
|
app.once('browser-window-blur', (e, window) => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(w.id, window.id)
|
|
|
|
done()
|
|
|
|
})
|
2017-10-27 23:45:58 +03:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-03-25 22:57:17 +03:00
|
|
|
w.emit('blur')
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('should emit browser-window-created event when window is created', (done) => {
|
|
|
|
app.once('browser-window-created', (e, window) => {
|
|
|
|
setImmediate(() => {
|
2016-03-25 22:57:17 +03:00
|
|
|
assert.equal(w.id, window.id)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-10-27 23:45:58 +03:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-06-13 19:05:04 +03:00
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('should emit web-contents-created event when a webContents is created', (done) => {
|
|
|
|
app.once('web-contents-created', (e, webContents) => {
|
|
|
|
setImmediate(() => {
|
2016-06-13 19:05:04 +03:00
|
|
|
assert.equal(w.webContents.id, webContents.id)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-10-27 23:45:58 +03:00
|
|
|
w = new BrowserWindow({ show: false })
|
2016-03-25 22:57:17 +03:00
|
|
|
})
|
|
|
|
})
|
2016-06-29 20:47:20 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.setBadgeCount API', () => {
|
2016-07-01 16:18:39 +03:00
|
|
|
const shouldFail = process.platform === 'win32' ||
|
2016-07-02 04:36:11 +03:00
|
|
|
(process.platform === 'linux' && !app.isUnityRunning())
|
2016-07-01 16:18:39 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => {
|
2016-10-06 20:29:55 +03:00
|
|
|
app.setBadgeCount(0)
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('returns false when failed', () => {
|
2016-07-01 16:18:39 +03:00
|
|
|
assert.equal(app.setBadgeCount(42), !shouldFail)
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('should set a badge count', () => {
|
2016-07-01 11:39:01 +03:00
|
|
|
app.setBadgeCount(42)
|
2016-07-01 16:18:39 +03:00
|
|
|
assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42)
|
2016-06-29 20:47:20 +03:00
|
|
|
})
|
|
|
|
})
|
2016-07-06 23:34:14 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('app.get/setLoginItemSettings API', () => {
|
2016-07-11 22:30:40 +03:00
|
|
|
if (process.platform === 'linux') return
|
2016-07-06 23:34:14 +03:00
|
|
|
|
2017-02-02 19:01:47 +03:00
|
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
|
|
|
const processStartArgs = [
|
|
|
|
'--processStart', `"${path.basename(process.execPath)}"`,
|
|
|
|
'--process-start-args', `"--hidden"`
|
|
|
|
]
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
beforeEach(() => {
|
2016-07-08 02:29:09 +03:00
|
|
|
app.setLoginItemSettings({openAtLogin: false})
|
2017-02-02 19:01:47 +03:00
|
|
|
app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
|
2016-07-06 23:57:20 +03:00
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => {
|
2016-07-08 02:29:09 +03:00
|
|
|
app.setLoginItemSettings({openAtLogin: false})
|
2017-02-02 19:01:47 +03:00
|
|
|
app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
|
2016-07-06 23:34:14 +03:00
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('returns the login item status of the app', () => {
|
2016-07-08 02:29:09 +03:00
|
|
|
app.setLoginItemSettings({openAtLogin: true})
|
|
|
|
assert.deepEqual(app.getLoginItemSettings(), {
|
|
|
|
openAtLogin: true,
|
|
|
|
openAsHidden: false,
|
2016-07-08 02:29:58 +03:00
|
|
|
wasOpenedAtLogin: false,
|
|
|
|
wasOpenedAsHidden: false,
|
2016-07-08 02:29:09 +03:00
|
|
|
restoreState: false
|
|
|
|
})
|
|
|
|
|
|
|
|
app.setLoginItemSettings({openAtLogin: true, openAsHidden: true})
|
|
|
|
assert.deepEqual(app.getLoginItemSettings(), {
|
|
|
|
openAtLogin: true,
|
2016-07-11 22:30:40 +03:00
|
|
|
openAsHidden: process.platform === 'darwin', // Only available on macOS
|
2016-07-08 02:29:58 +03:00
|
|
|
wasOpenedAtLogin: false,
|
|
|
|
wasOpenedAsHidden: false,
|
2016-07-08 02:29:09 +03:00
|
|
|
restoreState: false
|
|
|
|
})
|
2016-07-06 23:34:14 +03:00
|
|
|
|
2016-07-08 02:29:09 +03:00
|
|
|
app.setLoginItemSettings({})
|
|
|
|
assert.deepEqual(app.getLoginItemSettings(), {
|
|
|
|
openAtLogin: false,
|
|
|
|
openAsHidden: false,
|
2016-07-08 02:29:58 +03:00
|
|
|
wasOpenedAtLogin: false,
|
|
|
|
wasOpenedAsHidden: false,
|
2016-07-08 02:29:09 +03:00
|
|
|
restoreState: false
|
|
|
|
})
|
2016-07-06 23:34:14 +03:00
|
|
|
})
|
2017-01-26 23:24:33 +03:00
|
|
|
|
|
|
|
it('allows you to pass a custom executable and arguments', () => {
|
|
|
|
if (process.platform !== 'win32') return
|
|
|
|
|
2017-01-31 01:01:40 +03:00
|
|
|
app.setLoginItemSettings({openAtLogin: true, path: updateExe, args: processStartArgs})
|
2017-01-26 23:35:46 +03:00
|
|
|
|
2017-01-31 01:01:40 +03:00
|
|
|
assert.equal(app.getLoginItemSettings().openAtLogin, false)
|
|
|
|
assert.equal(app.getLoginItemSettings({path: updateExe, args: processStartArgs}).openAtLogin, true)
|
2017-01-26 23:24:33 +03:00
|
|
|
})
|
2016-07-06 23:34:14 +03:00
|
|
|
})
|
2016-07-12 00:32:24 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('isAccessibilitySupportEnabled API', () => {
|
|
|
|
it('returns whether the Chrome has accessibility APIs enabled', () => {
|
2016-07-12 00:48:48 +03:00
|
|
|
assert.equal(typeof app.isAccessibilitySupportEnabled(), 'boolean')
|
2016-07-12 00:32:24 +03:00
|
|
|
})
|
|
|
|
})
|
2016-10-06 19:57:25 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('getPath(name)', () => {
|
|
|
|
it('returns paths that exist', () => {
|
2016-10-06 19:57:25 +03:00
|
|
|
assert.equal(fs.existsSync(app.getPath('exe')), true)
|
|
|
|
assert.equal(fs.existsSync(app.getPath('home')), true)
|
|
|
|
assert.equal(fs.existsSync(app.getPath('temp')), true)
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('throws an error when the name is invalid', () => {
|
|
|
|
assert.throws(() => {
|
2016-10-06 19:57:25 +03:00
|
|
|
app.getPath('does-not-exist')
|
|
|
|
}, /Failed to get 'does-not-exist' path/)
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('returns the overridden path', () => {
|
2016-10-06 19:57:25 +03:00
|
|
|
app.setPath('music', __dirname)
|
|
|
|
assert.equal(app.getPath('music'), __dirname)
|
|
|
|
})
|
|
|
|
})
|
2016-12-02 20:34:16 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
xdescribe('select-client-certificate event', () => {
|
2016-12-02 20:34:16 +03:00
|
|
|
let w = null
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
beforeEach(() => {
|
2016-12-02 20:34:16 +03:00
|
|
|
w = new BrowserWindow({
|
|
|
|
show: false,
|
|
|
|
webPreferences: {
|
|
|
|
partition: 'empty-certificate'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
2016-12-02 20:34:16 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('can respond with empty certificate list', (done) => {
|
|
|
|
w.webContents.on('did-finish-load', () => {
|
2016-12-02 20:34:16 +03:00
|
|
|
assert.equal(w.webContents.getTitle(), 'denied')
|
|
|
|
server.close()
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcRenderer.sendSync('set-client-certificate-option', true)
|
|
|
|
w.webContents.loadURL(secureUrl)
|
|
|
|
})
|
|
|
|
})
|
2017-02-02 19:11:34 +03:00
|
|
|
|
|
|
|
describe('setAsDefaultProtocolClient(protocol, path, args)', () => {
|
|
|
|
if (process.platform !== 'win32') return
|
|
|
|
|
2017-02-02 19:41:14 +03:00
|
|
|
const protocol = 'electron-test'
|
2017-02-02 19:11:34 +03:00
|
|
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
|
|
|
const processStartArgs = [
|
|
|
|
'--processStart', `"${path.basename(process.execPath)}"`,
|
|
|
|
'--process-start-args', `"--hidden"`
|
|
|
|
]
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-02-02 19:41:14 +03:00
|
|
|
app.removeAsDefaultProtocolClient(protocol)
|
|
|
|
app.removeAsDefaultProtocolClient(protocol, updateExe, processStartArgs)
|
2017-02-02 19:11:34 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
2017-02-02 19:41:14 +03:00
|
|
|
app.removeAsDefaultProtocolClient(protocol)
|
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol), false)
|
|
|
|
app.removeAsDefaultProtocolClient(protocol, updateExe, processStartArgs)
|
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs), false)
|
2017-02-02 19:11:34 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('sets the app as the default protocol client', () => {
|
2017-02-02 19:41:14 +03:00
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol), false)
|
|
|
|
app.setAsDefaultProtocolClient(protocol)
|
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol), true)
|
2017-02-02 19:11:34 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it('allows a custom path and args to be specified', () => {
|
2017-02-02 19:41:14 +03:00
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs), false)
|
|
|
|
app.setAsDefaultProtocolClient(protocol, updateExe, processStartArgs)
|
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol, updateExe, processStartArgs), true)
|
|
|
|
assert.equal(app.isDefaultProtocolClient(protocol), false)
|
2017-02-02 19:11:34 +03:00
|
|
|
})
|
|
|
|
})
|
2016-11-06 13:59:17 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('getFileIcon() API', () => {
|
2017-02-08 05:24:35 +03:00
|
|
|
// FIXME Get these specs running on Linux CI
|
|
|
|
if (process.platform === 'linux' && isCI) return
|
|
|
|
|
2016-11-10 21:34:30 +03:00
|
|
|
const iconPath = path.join(__dirname, 'fixtures/assets/icon.ico')
|
2016-11-06 13:59:17 +03:00
|
|
|
const sizes = {
|
|
|
|
small: 16,
|
|
|
|
normal: 32,
|
2017-02-07 22:20:27 +03:00
|
|
|
large: process.platform === 'win32' ? 32 : 48
|
2016-11-06 14:03:16 +03:00
|
|
|
}
|
2016-11-06 13:59:17 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('fetches a non-empty icon', (done) => {
|
|
|
|
app.getFileIcon(iconPath, (err, icon) => {
|
2016-11-06 13:59:17 +03:00
|
|
|
assert.equal(err, null)
|
|
|
|
assert.equal(icon.isEmpty(), false)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('fetches normal icon size by default', (done) => {
|
|
|
|
app.getFileIcon(iconPath, (err, icon) => {
|
2016-11-06 13:59:17 +03:00
|
|
|
const size = icon.getSize()
|
2016-11-06 14:03:16 +03:00
|
|
|
assert.equal(err, null)
|
2016-11-06 13:59:17 +03:00
|
|
|
assert.equal(size.height, sizes.normal)
|
|
|
|
assert.equal(size.width, sizes.normal)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('size option', () => {
|
|
|
|
it('fetches a small icon', (done) => {
|
|
|
|
app.getFileIcon(iconPath, { size: 'small' }, (err, icon) => {
|
2016-11-06 13:59:17 +03:00
|
|
|
const size = icon.getSize()
|
2016-11-06 14:03:16 +03:00
|
|
|
assert.equal(err, null)
|
2016-11-06 13:59:17 +03:00
|
|
|
assert.equal(size.height, sizes.small)
|
|
|
|
assert.equal(size.width, sizes.small)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('fetches a normal icon', (done) => {
|
2016-11-06 14:03:16 +03:00
|
|
|
app.getFileIcon(iconPath, { size: 'normal' }, function (err, icon) {
|
2016-11-06 13:59:17 +03:00
|
|
|
const size = icon.getSize()
|
2016-11-06 14:03:16 +03:00
|
|
|
assert.equal(err, null)
|
2016-11-06 13:59:17 +03:00
|
|
|
assert.equal(size.height, sizes.normal)
|
|
|
|
assert.equal(size.width, sizes.normal)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
it('fetches a large icon', (done) => {
|
2017-02-07 21:16:09 +03:00
|
|
|
// macOS does not support large icons
|
|
|
|
if (process.platform === 'darwin') return done()
|
|
|
|
|
2016-11-11 09:32:41 +03:00
|
|
|
app.getFileIcon(iconPath, { size: 'large' }, function (err, icon) {
|
2016-11-06 13:59:17 +03:00
|
|
|
const size = icon.getSize()
|
2016-11-06 14:03:16 +03:00
|
|
|
assert.equal(err, null)
|
2016-11-11 09:32:41 +03:00
|
|
|
assert.equal(size.height, sizes.large)
|
|
|
|
assert.equal(size.width, sizes.large)
|
2016-11-06 13:59:17 +03:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-04-27 18:38:17 +03:00
|
|
|
})
|
2017-04-27 07:04:53 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('getAppMetrics() API', () => {
|
|
|
|
it('returns memory and cpu stats of all running electron processes', () => {
|
2017-05-16 03:41:45 +03:00
|
|
|
const appMetrics = app.getAppMetrics()
|
|
|
|
assert.ok(appMetrics.length > 0, 'App memory info object is not > 0')
|
2017-05-26 18:53:26 +03:00
|
|
|
const types = []
|
2017-05-16 03:41:45 +03:00
|
|
|
for (const {memory, pid, type, cpu} of appMetrics) {
|
2017-05-04 23:43:45 +03:00
|
|
|
assert.ok(memory.workingSetSize > 0, 'working set size is not > 0')
|
|
|
|
assert.ok(memory.privateBytes > 0, 'private bytes is not > 0')
|
|
|
|
assert.ok(memory.sharedBytes > 0, 'shared bytes is not > 0')
|
|
|
|
assert.ok(pid > 0, 'pid is not > 0')
|
2017-05-16 03:41:45 +03:00
|
|
|
assert.ok(type.length > 0, 'process type is null')
|
2017-05-26 18:53:26 +03:00
|
|
|
types.push(type)
|
2017-05-16 03:41:45 +03:00
|
|
|
assert.equal(typeof cpu.percentCPUUsage, 'number')
|
|
|
|
assert.equal(typeof cpu.idleWakeupsPerSecond, 'number')
|
2017-05-04 23:43:45 +03:00
|
|
|
}
|
2017-05-26 18:53:26 +03:00
|
|
|
|
2017-05-26 20:10:56 +03:00
|
|
|
if (process.platform === 'darwin') {
|
2017-05-26 19:14:17 +03:00
|
|
|
assert.ok(types.includes('GPU'))
|
|
|
|
}
|
|
|
|
|
2017-05-26 18:53:26 +03:00
|
|
|
assert.ok(types.includes('Browser'))
|
|
|
|
assert.ok(types.includes('Tab'))
|
2017-04-27 07:04:53 +03:00
|
|
|
})
|
2016-11-06 13:59:17 +03:00
|
|
|
})
|
2017-05-30 23:00:00 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('getGPUFeatureStatus() API', () => {
|
|
|
|
it('returns the graphic features statuses', () => {
|
2017-05-30 23:00:00 +03:00
|
|
|
const features = app.getGPUFeatureStatus()
|
|
|
|
assert.equal(typeof features.webgl, 'string')
|
|
|
|
assert.equal(typeof features.gpu_compositing, 'string')
|
|
|
|
})
|
|
|
|
})
|
2017-06-28 18:33:06 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('mixed sandbox option', () => {
|
2017-06-29 00:35:50 +03:00
|
|
|
// FIXME Get these specs running on Linux
|
|
|
|
if (process.platform === 'linux') return
|
|
|
|
|
2017-06-28 19:27:19 +03:00
|
|
|
let appProcess = null
|
|
|
|
let server = null
|
|
|
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
|
2017-06-28 18:33:06 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
beforeEach((done) => {
|
2017-06-28 19:27:19 +03:00
|
|
|
fs.unlink(socketPath, () => {
|
|
|
|
server = net.createServer()
|
|
|
|
server.listen(socketPath)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
afterEach((done) => {
|
|
|
|
if (appProcess != null) appProcess.kill()
|
2017-06-28 19:27:19 +03:00
|
|
|
|
|
|
|
server.close(() => {
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
done()
|
|
|
|
} else {
|
2017-10-27 23:45:58 +03:00
|
|
|
fs.unlink(socketPath, () => done())
|
2017-06-28 19:27:19 +03:00
|
|
|
}
|
|
|
|
})
|
2017-06-28 18:33:06 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('when app.enableMixedSandbox() is called', () => {
|
|
|
|
it('adds --enable-sandbox to render processes created with sandbox: true', (done) => {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
2017-06-28 19:27:19 +03:00
|
|
|
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath])
|
2017-06-28 18:33:06 +03:00
|
|
|
|
2017-06-28 19:27:19 +03:00
|
|
|
server.once('error', (error) => {
|
|
|
|
done(error)
|
|
|
|
})
|
2017-06-28 18:33:06 +03:00
|
|
|
|
2017-06-28 19:27:19 +03:00
|
|
|
server.on('connection', (client) => {
|
|
|
|
client.once('data', function (data) {
|
|
|
|
const argv = JSON.parse(data)
|
|
|
|
assert.equal(argv.sandbox.includes('--enable-sandbox'), true)
|
|
|
|
assert.equal(argv.sandbox.includes('--no-sandbox'), false)
|
|
|
|
|
|
|
|
assert.equal(argv.noSandbox.includes('--enable-sandbox'), false)
|
|
|
|
assert.equal(argv.noSandbox.includes('--no-sandbox'), true)
|
|
|
|
|
|
|
|
done()
|
|
|
|
})
|
2017-06-28 18:33:06 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when the app is launched with --enable-mixed-sandbox', () => {
|
|
|
|
it('adds --enable-sandbox to render processes created with sandbox: true', (done) => {
|
|
|
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'mixed-sandbox-app')
|
2017-06-28 19:27:19 +03:00
|
|
|
appProcess = ChildProcess.spawn(remote.process.execPath, [appPath, '--enable-mixed-sandbox'])
|
2017-06-28 18:33:06 +03:00
|
|
|
|
2017-06-28 19:27:19 +03:00
|
|
|
server.once('error', (error) => {
|
|
|
|
done(error)
|
|
|
|
})
|
2017-06-28 18:33:06 +03:00
|
|
|
|
2017-06-28 19:27:19 +03:00
|
|
|
server.on('connection', (client) => {
|
|
|
|
client.once('data', function (data) {
|
|
|
|
const argv = JSON.parse(data)
|
|
|
|
assert.equal(argv.sandbox.includes('--enable-sandbox'), true)
|
|
|
|
assert.equal(argv.sandbox.includes('--no-sandbox'), false)
|
|
|
|
|
|
|
|
assert.equal(argv.noSandbox.includes('--enable-sandbox'), false)
|
|
|
|
assert.equal(argv.noSandbox.includes('--no-sandbox'), true)
|
|
|
|
|
2017-07-12 04:18:36 +03:00
|
|
|
assert.equal(argv.noSandboxDevtools, true)
|
|
|
|
assert.equal(argv.sandboxDevtools, true)
|
|
|
|
|
2017-06-28 19:27:19 +03:00
|
|
|
done()
|
|
|
|
})
|
2017-06-28 18:33:06 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2017-07-14 01:27:03 +03:00
|
|
|
|
2017-10-27 23:45:58 +03:00
|
|
|
describe('disableDomainBlockingFor3DAPIs() API', () => {
|
|
|
|
it('throws when called after app is ready', () => {
|
|
|
|
assert.throws(() => {
|
2017-07-14 01:27:03 +03:00
|
|
|
app.disableDomainBlockingFor3DAPIs()
|
|
|
|
}, /before app is ready/)
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 22:57:17 +03:00
|
|
|
})
|