parent
04cce89fdc
commit
e4214a6cbe
11 changed files with 1712 additions and 1945 deletions
|
@ -11,17 +11,17 @@ const {app, BrowserWindow, ipcMain} = remote
|
||||||
|
|
||||||
const isCI = remote.getGlobal('isCi')
|
const isCI = remote.getGlobal('isCi')
|
||||||
|
|
||||||
describe('electron module', function () {
|
describe('electron module', () => {
|
||||||
it('does not expose internal modules to require', function () {
|
it('does not expose internal modules to require', () => {
|
||||||
assert.throws(function () {
|
assert.throws(() => {
|
||||||
require('clipboard')
|
require('clipboard')
|
||||||
}, /Cannot find module 'clipboard'/)
|
}, /Cannot find module 'clipboard'/)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('require("electron")', function () {
|
describe('require("electron")', () => {
|
||||||
let window = null
|
let window = null
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
window = new BrowserWindow({
|
window = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 400,
|
width: 400,
|
||||||
|
@ -29,24 +29,22 @@ describe('electron module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
return closeWindow(window).then(function () { window = null })
|
return closeWindow(window).then(() => { window = null })
|
||||||
})
|
})
|
||||||
|
|
||||||
it('always returns the internal electron module', function (done) {
|
it('always returns the internal electron module', (done) => {
|
||||||
ipcMain.once('answer', function () {
|
ipcMain.once('answer', () => done())
|
||||||
done()
|
window.loadURL(`file://${path.join(__dirname, 'fixtures', 'api', 'electron-module-app', 'index.html')}`)
|
||||||
})
|
|
||||||
window.loadURL('file://' + path.join(__dirname, 'fixtures', 'api', 'electron-module-app', 'index.html'))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app module', function () {
|
describe('app module', () => {
|
||||||
let server, secureUrl
|
let server, secureUrl
|
||||||
const certPath = path.join(__dirname, 'fixtures', 'certificates')
|
const certPath = path.join(__dirname, 'fixtures', 'certificates')
|
||||||
|
|
||||||
before(function () {
|
before(() => {
|
||||||
const options = {
|
const options = {
|
||||||
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
||||||
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
||||||
|
@ -58,7 +56,7 @@ describe('app module', function () {
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}
|
}
|
||||||
|
|
||||||
server = https.createServer(options, function (req, res) {
|
server = https.createServer(options, (req, res) => {
|
||||||
if (req.client.authorized) {
|
if (req.client.authorized) {
|
||||||
res.writeHead(200)
|
res.writeHead(200)
|
||||||
res.end('<title>authorized</title>')
|
res.end('<title>authorized</title>')
|
||||||
|
@ -68,24 +66,24 @@ describe('app module', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
server.listen(0, '127.0.0.1', function () {
|
server.listen(0, '127.0.0.1', () => {
|
||||||
const port = server.address().port
|
const port = server.address().port
|
||||||
secureUrl = `https://127.0.0.1:${port}`
|
secureUrl = `https://127.0.0.1:${port}`
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(() => {
|
||||||
server.close()
|
server.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.getVersion()', function () {
|
describe('app.getVersion()', () => {
|
||||||
it('returns the version field of package.json', function () {
|
it('returns the version field of package.json', () => {
|
||||||
assert.equal(app.getVersion(), '0.1.0')
|
assert.equal(app.getVersion(), '0.1.0')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.setVersion(version)', function () {
|
describe('app.setVersion(version)', () => {
|
||||||
it('overrides the version', function () {
|
it('overrides the version', () => {
|
||||||
assert.equal(app.getVersion(), '0.1.0')
|
assert.equal(app.getVersion(), '0.1.0')
|
||||||
app.setVersion('test-version')
|
app.setVersion('test-version')
|
||||||
assert.equal(app.getVersion(), 'test-version')
|
assert.equal(app.getVersion(), 'test-version')
|
||||||
|
@ -93,14 +91,14 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.getName()', function () {
|
describe('app.getName()', () => {
|
||||||
it('returns the name field of package.json', function () {
|
it('returns the name field of package.json', () => {
|
||||||
assert.equal(app.getName(), 'Electron Test')
|
assert.equal(app.getName(), 'Electron Test')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.setName(name)', function () {
|
describe('app.setName(name)', () => {
|
||||||
it('overrides the name', function () {
|
it('overrides the name', () => {
|
||||||
assert.equal(app.getName(), 'Electron Test')
|
assert.equal(app.getName(), 'Electron Test')
|
||||||
app.setName('test-name')
|
app.setName('test-name')
|
||||||
assert.equal(app.getName(), 'test-name')
|
assert.equal(app.getName(), 'test-name')
|
||||||
|
@ -108,36 +106,35 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.getLocale()', function () {
|
describe('app.getLocale()', () => {
|
||||||
it('should not be empty', function () {
|
it('should not be empty', () => {
|
||||||
assert.notEqual(app.getLocale(), '')
|
assert.notEqual(app.getLocale(), '')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.isInApplicationsFolder()', function () {
|
describe('app.isInApplicationsFolder()', () => {
|
||||||
it('should be false during tests', function () {
|
it('should be false during tests', () => {
|
||||||
if (process.platform !== 'darwin') return
|
if (process.platform !== 'darwin') return
|
||||||
|
|
||||||
assert.equal(app.isInApplicationsFolder(), false)
|
assert.equal(app.isInApplicationsFolder(), false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.exit(exitCode)', function () {
|
describe('app.exit(exitCode)', () => {
|
||||||
var appProcess = null
|
let appProcess = null
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
if (appProcess != null) appProcess.kill()
|
if (appProcess != null) appProcess.kill()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits a process exit event with the code', function (done) {
|
it('emits a process exit event with the code', (done) => {
|
||||||
var appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
||||||
var electronPath = remote.getGlobal('process').execPath
|
const electronPath = remote.getGlobal('process').execPath
|
||||||
var output = ''
|
let output = ''
|
||||||
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
||||||
appProcess.stdout.on('data', function (data) {
|
appProcess.stdout.on('data', (data) => {
|
||||||
output += data
|
output += data
|
||||||
})
|
})
|
||||||
appProcess.on('close', function (code) {
|
appProcess.on('close', (code) => {
|
||||||
if (process.platform !== 'win32') {
|
if (process.platform !== 'win32') {
|
||||||
assert.notEqual(output.indexOf('Exit event with code: 123'), -1)
|
assert.notEqual(output.indexOf('Exit event with code: 123'), -1)
|
||||||
}
|
}
|
||||||
|
@ -146,7 +143,7 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('closes all windows', function (done) {
|
it('closes all windows', (done) => {
|
||||||
var appPath = path.join(__dirname, 'fixtures', 'api', 'exit-closes-all-windows-app')
|
var appPath = path.join(__dirname, 'fixtures', 'api', 'exit-closes-all-windows-app')
|
||||||
var electronPath = remote.getGlobal('process').execPath
|
var electronPath = remote.getGlobal('process').execPath
|
||||||
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
||||||
|
@ -157,7 +154,7 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.makeSingleInstance', function () {
|
describe('app.makeSingleInstance', () => {
|
||||||
it('prevents the second launch of app', function (done) {
|
it('prevents the second launch of app', function (done) {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
|
const appPath = path.join(__dirname, 'fixtures', 'api', 'singleton')
|
||||||
|
@ -178,11 +175,11 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.relaunch', function () {
|
describe('app.relaunch', () => {
|
||||||
let server = null
|
let server = null
|
||||||
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-app-relaunch' : '/tmp/electron-app-relaunch'
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach((done) => {
|
||||||
fs.unlink(socketPath, () => {
|
fs.unlink(socketPath, () => {
|
||||||
server = net.createServer()
|
server = net.createServer()
|
||||||
server.listen(socketPath)
|
server.listen(socketPath)
|
||||||
|
@ -190,14 +187,12 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function (done) {
|
afterEach((done) => {
|
||||||
server.close(() => {
|
server.close(() => {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
done()
|
done()
|
||||||
} else {
|
} else {
|
||||||
fs.unlink(socketPath, () => {
|
fs.unlink(socketPath, () => done())
|
||||||
done()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -206,11 +201,9 @@ describe('app module', function () {
|
||||||
this.timeout(120000)
|
this.timeout(120000)
|
||||||
|
|
||||||
let state = 'none'
|
let state = 'none'
|
||||||
server.once('error', (error) => {
|
server.once('error', (error) => done(error))
|
||||||
done(error)
|
|
||||||
})
|
|
||||||
server.on('connection', (client) => {
|
server.on('connection', (client) => {
|
||||||
client.once('data', function (data) {
|
client.once('data', (data) => {
|
||||||
if (String(data) === 'false' && state === 'none') {
|
if (String(data) === 'false' && state === 'none') {
|
||||||
state = 'first-launch'
|
state = 'first-launch'
|
||||||
} else if (String(data) === 'true' && state === 'first-launch') {
|
} else if (String(data) === 'true' && state === 'first-launch') {
|
||||||
|
@ -226,42 +219,36 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.setUserActivity(type, userInfo)', function () {
|
describe('app.setUserActivity(type, userInfo)', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
it('sets the current activity', function () {
|
it('sets the current activity', () => {
|
||||||
app.setUserActivity('com.electron.testActivity', {testData: '123'})
|
app.setUserActivity('com.electron.testActivity', {testData: '123'})
|
||||||
assert.equal(app.getCurrentActivityType(), 'com.electron.testActivity')
|
assert.equal(app.getCurrentActivityType(), 'com.electron.testActivity')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
xdescribe('app.importCertificate', function () {
|
xdescribe('app.importCertificate', () => {
|
||||||
if (process.platform !== 'linux') return
|
if (process.platform !== 'linux') return
|
||||||
|
|
||||||
var w = null
|
var w = null
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||||
return closeWindow(w).then(function () { w = null })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can import certificate into platform cert store', function (done) {
|
it('can import certificate into platform cert store', (done) => {
|
||||||
let options = {
|
let options = {
|
||||||
certificate: path.join(certPath, 'client.p12'),
|
certificate: path.join(certPath, 'client.p12'),
|
||||||
password: 'electron'
|
password: 'electron'
|
||||||
}
|
}
|
||||||
|
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({ show: false })
|
||||||
show: false
|
|
||||||
})
|
|
||||||
|
|
||||||
w.webContents.on('did-finish-load', function () {
|
w.webContents.on('did-finish-load', () => {
|
||||||
assert.equal(w.webContents.getTitle(), 'authorized')
|
assert.equal(w.webContents.getTitle(), 'authorized')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcRenderer.once('select-client-certificate', function (event, webContentsId, list) {
|
ipcRenderer.once('select-client-certificate', (event, webContentsId, list) => {
|
||||||
assert.equal(webContentsId, w.webContents.id)
|
assert.equal(webContentsId, w.webContents.id)
|
||||||
assert.equal(list.length, 1)
|
assert.equal(list.length, 1)
|
||||||
assert.equal(list[0].issuerName, 'Intermediate CA')
|
assert.equal(list[0].issuerName, 'Intermediate CA')
|
||||||
|
@ -271,7 +258,7 @@ describe('app module', function () {
|
||||||
event.sender.send('client-certificate-response', list[0])
|
event.sender.send('client-certificate-response', list[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
app.importCertificate(options, function (result) {
|
app.importCertificate(options, (result) => {
|
||||||
assert(!result)
|
assert(!result)
|
||||||
ipcRenderer.sendSync('set-client-certificate-option', false)
|
ipcRenderer.sendSync('set-client-certificate-option', false)
|
||||||
w.loadURL(secureUrl)
|
w.loadURL(secureUrl)
|
||||||
|
@ -279,79 +266,69 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('BrowserWindow events', function () {
|
describe('BrowserWindow events', () => {
|
||||||
var w = null
|
let w = null
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||||
return closeWindow(w).then(function () { w = null })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should emit browser-window-focus event when window is focused', function (done) {
|
it('should emit browser-window-focus event when window is focused', (done) => {
|
||||||
app.once('browser-window-focus', function (e, window) {
|
app.once('browser-window-focus', (e, window) => {
|
||||||
assert.equal(w.id, window.id)
|
assert.equal(w.id, window.id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({ show: false })
|
||||||
show: false
|
|
||||||
})
|
|
||||||
w.emit('focus')
|
w.emit('focus')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should emit browser-window-blur event when window is blured', function (done) {
|
it('should emit browser-window-blur event when window is blured', (done) => {
|
||||||
app.once('browser-window-blur', function (e, window) {
|
app.once('browser-window-blur', (e, window) => {
|
||||||
assert.equal(w.id, window.id)
|
assert.equal(w.id, window.id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({ show: false })
|
||||||
show: false
|
|
||||||
})
|
|
||||||
w.emit('blur')
|
w.emit('blur')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should emit browser-window-created event when window is created', function (done) {
|
it('should emit browser-window-created event when window is created', (done) => {
|
||||||
app.once('browser-window-created', function (e, window) {
|
app.once('browser-window-created', (e, window) => {
|
||||||
setImmediate(function () {
|
setImmediate(() => {
|
||||||
assert.equal(w.id, window.id)
|
assert.equal(w.id, window.id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({ show: false })
|
||||||
show: false
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should emit web-contents-created event when a webContents is created', function (done) {
|
it('should emit web-contents-created event when a webContents is created', (done) => {
|
||||||
app.once('web-contents-created', function (e, webContents) {
|
app.once('web-contents-created', (e, webContents) => {
|
||||||
setImmediate(function () {
|
setImmediate(() => {
|
||||||
assert.equal(w.webContents.id, webContents.id)
|
assert.equal(w.webContents.id, webContents.id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({ show: false })
|
||||||
show: false
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.setBadgeCount API', function () {
|
describe('app.setBadgeCount API', () => {
|
||||||
const shouldFail = process.platform === 'win32' ||
|
const shouldFail = process.platform === 'win32' ||
|
||||||
(process.platform === 'linux' && !app.isUnityRunning())
|
(process.platform === 'linux' && !app.isUnityRunning())
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
app.setBadgeCount(0)
|
app.setBadgeCount(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns false when failed', function () {
|
it('returns false when failed', () => {
|
||||||
assert.equal(app.setBadgeCount(42), !shouldFail)
|
assert.equal(app.setBadgeCount(42), !shouldFail)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set a badge count', function () {
|
it('should set a badge count', () => {
|
||||||
app.setBadgeCount(42)
|
app.setBadgeCount(42)
|
||||||
assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42)
|
assert.equal(app.getBadgeCount(), shouldFail ? 0 : 42)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('app.get/setLoginItemSettings API', function () {
|
describe('app.get/setLoginItemSettings API', () => {
|
||||||
if (process.platform === 'linux') return
|
if (process.platform === 'linux') return
|
||||||
|
|
||||||
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe')
|
||||||
|
@ -360,17 +337,17 @@ describe('app module', function () {
|
||||||
'--process-start-args', `"--hidden"`
|
'--process-start-args', `"--hidden"`
|
||||||
]
|
]
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
app.setLoginItemSettings({openAtLogin: false})
|
app.setLoginItemSettings({openAtLogin: false})
|
||||||
app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
|
app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
app.setLoginItemSettings({openAtLogin: false})
|
app.setLoginItemSettings({openAtLogin: false})
|
||||||
app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
|
app.setLoginItemSettings({openAtLogin: false, path: updateExe, args: processStartArgs})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns the login item status of the app', function () {
|
it('returns the login item status of the app', () => {
|
||||||
app.setLoginItemSettings({openAtLogin: true})
|
app.setLoginItemSettings({openAtLogin: true})
|
||||||
assert.deepEqual(app.getLoginItemSettings(), {
|
assert.deepEqual(app.getLoginItemSettings(), {
|
||||||
openAtLogin: true,
|
openAtLogin: true,
|
||||||
|
@ -409,35 +386,35 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('isAccessibilitySupportEnabled API', function () {
|
describe('isAccessibilitySupportEnabled API', () => {
|
||||||
it('returns whether the Chrome has accessibility APIs enabled', function () {
|
it('returns whether the Chrome has accessibility APIs enabled', () => {
|
||||||
assert.equal(typeof app.isAccessibilitySupportEnabled(), 'boolean')
|
assert.equal(typeof app.isAccessibilitySupportEnabled(), 'boolean')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getPath(name)', function () {
|
describe('getPath(name)', () => {
|
||||||
it('returns paths that exist', function () {
|
it('returns paths that exist', () => {
|
||||||
assert.equal(fs.existsSync(app.getPath('exe')), true)
|
assert.equal(fs.existsSync(app.getPath('exe')), true)
|
||||||
assert.equal(fs.existsSync(app.getPath('home')), true)
|
assert.equal(fs.existsSync(app.getPath('home')), true)
|
||||||
assert.equal(fs.existsSync(app.getPath('temp')), true)
|
assert.equal(fs.existsSync(app.getPath('temp')), true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('throws an error when the name is invalid', function () {
|
it('throws an error when the name is invalid', () => {
|
||||||
assert.throws(function () {
|
assert.throws(() => {
|
||||||
app.getPath('does-not-exist')
|
app.getPath('does-not-exist')
|
||||||
}, /Failed to get 'does-not-exist' path/)
|
}, /Failed to get 'does-not-exist' path/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns the overridden path', function () {
|
it('returns the overridden path', () => {
|
||||||
app.setPath('music', __dirname)
|
app.setPath('music', __dirname)
|
||||||
assert.equal(app.getPath('music'), __dirname)
|
assert.equal(app.getPath('music'), __dirname)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
xdescribe('select-client-certificate event', function () {
|
xdescribe('select-client-certificate event', () => {
|
||||||
let w = null
|
let w = null
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
|
@ -446,12 +423,10 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||||
return closeWindow(w).then(function () { w = null })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can respond with empty certificate list', function (done) {
|
it('can respond with empty certificate list', (done) => {
|
||||||
w.webContents.on('did-finish-load', function () {
|
w.webContents.on('did-finish-load', () => {
|
||||||
assert.equal(w.webContents.getTitle(), 'denied')
|
assert.equal(w.webContents.getTitle(), 'denied')
|
||||||
server.close()
|
server.close()
|
||||||
done()
|
done()
|
||||||
|
@ -498,7 +473,7 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getFileIcon() API', function () {
|
describe('getFileIcon() API', () => {
|
||||||
// FIXME Get these specs running on Linux CI
|
// FIXME Get these specs running on Linux CI
|
||||||
if (process.platform === 'linux' && isCI) return
|
if (process.platform === 'linux' && isCI) return
|
||||||
|
|
||||||
|
@ -509,16 +484,16 @@ describe('app module', function () {
|
||||||
large: process.platform === 'win32' ? 32 : 48
|
large: process.platform === 'win32' ? 32 : 48
|
||||||
}
|
}
|
||||||
|
|
||||||
it('fetches a non-empty icon', function (done) {
|
it('fetches a non-empty icon', (done) => {
|
||||||
app.getFileIcon(iconPath, function (err, icon) {
|
app.getFileIcon(iconPath, (err, icon) => {
|
||||||
assert.equal(err, null)
|
assert.equal(err, null)
|
||||||
assert.equal(icon.isEmpty(), false)
|
assert.equal(icon.isEmpty(), false)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fetches normal icon size by default', function (done) {
|
it('fetches normal icon size by default', (done) => {
|
||||||
app.getFileIcon(iconPath, function (err, icon) {
|
app.getFileIcon(iconPath, (err, icon) => {
|
||||||
const size = icon.getSize()
|
const size = icon.getSize()
|
||||||
assert.equal(err, null)
|
assert.equal(err, null)
|
||||||
assert.equal(size.height, sizes.normal)
|
assert.equal(size.height, sizes.normal)
|
||||||
|
@ -527,9 +502,9 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('size option', function () {
|
describe('size option', () => {
|
||||||
it('fetches a small icon', function (done) {
|
it('fetches a small icon', (done) => {
|
||||||
app.getFileIcon(iconPath, { size: 'small' }, function (err, icon) {
|
app.getFileIcon(iconPath, { size: 'small' }, (err, icon) => {
|
||||||
const size = icon.getSize()
|
const size = icon.getSize()
|
||||||
assert.equal(err, null)
|
assert.equal(err, null)
|
||||||
assert.equal(size.height, sizes.small)
|
assert.equal(size.height, sizes.small)
|
||||||
|
@ -538,7 +513,7 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fetches a normal icon', function (done) {
|
it('fetches a normal icon', (done) => {
|
||||||
app.getFileIcon(iconPath, { size: 'normal' }, function (err, icon) {
|
app.getFileIcon(iconPath, { size: 'normal' }, function (err, icon) {
|
||||||
const size = icon.getSize()
|
const size = icon.getSize()
|
||||||
assert.equal(err, null)
|
assert.equal(err, null)
|
||||||
|
@ -548,7 +523,7 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('fetches a large icon', function (done) {
|
it('fetches a large icon', (done) => {
|
||||||
// macOS does not support large icons
|
// macOS does not support large icons
|
||||||
if (process.platform === 'darwin') return done()
|
if (process.platform === 'darwin') return done()
|
||||||
|
|
||||||
|
@ -563,8 +538,8 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getAppMetrics() API', function () {
|
describe('getAppMetrics() API', () => {
|
||||||
it('returns memory and cpu stats of all running electron processes', function () {
|
it('returns memory and cpu stats of all running electron processes', () => {
|
||||||
const appMetrics = app.getAppMetrics()
|
const appMetrics = app.getAppMetrics()
|
||||||
assert.ok(appMetrics.length > 0, 'App memory info object is not > 0')
|
assert.ok(appMetrics.length > 0, 'App memory info object is not > 0')
|
||||||
const types = []
|
const types = []
|
||||||
|
@ -588,15 +563,15 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getGPUFeatureStatus() API', function () {
|
describe('getGPUFeatureStatus() API', () => {
|
||||||
it('returns the graphic features statuses', function () {
|
it('returns the graphic features statuses', () => {
|
||||||
const features = app.getGPUFeatureStatus()
|
const features = app.getGPUFeatureStatus()
|
||||||
assert.equal(typeof features.webgl, 'string')
|
assert.equal(typeof features.webgl, 'string')
|
||||||
assert.equal(typeof features.gpu_compositing, 'string')
|
assert.equal(typeof features.gpu_compositing, 'string')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mixed sandbox option', function () {
|
describe('mixed sandbox option', () => {
|
||||||
// FIXME Get these specs running on Linux
|
// FIXME Get these specs running on Linux
|
||||||
if (process.platform === 'linux') return
|
if (process.platform === 'linux') return
|
||||||
|
|
||||||
|
@ -604,7 +579,7 @@ describe('app module', function () {
|
||||||
let server = null
|
let server = null
|
||||||
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
|
const socketPath = process.platform === 'win32' ? '\\\\.\\pipe\\electron-mixed-sandbox' : '/tmp/electron-mixed-sandbox'
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach((done) => {
|
||||||
fs.unlink(socketPath, () => {
|
fs.unlink(socketPath, () => {
|
||||||
server = net.createServer()
|
server = net.createServer()
|
||||||
server.listen(socketPath)
|
server.listen(socketPath)
|
||||||
|
@ -612,18 +587,14 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function (done) {
|
afterEach((done) => {
|
||||||
if (appProcess != null) {
|
if (appProcess != null) appProcess.kill()
|
||||||
appProcess.kill()
|
|
||||||
}
|
|
||||||
|
|
||||||
server.close(() => {
|
server.close(() => {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
done()
|
done()
|
||||||
} else {
|
} else {
|
||||||
fs.unlink(socketPath, () => {
|
fs.unlink(socketPath, () => done())
|
||||||
done()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -680,9 +651,9 @@ describe('app module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('disableDomainBlockingFor3DAPIs() API', function () {
|
describe('disableDomainBlockingFor3DAPIs() API', () => {
|
||||||
it('throws when called after app is ready', function () {
|
it('throws when called after app is ready', () => {
|
||||||
assert.throws(function () {
|
assert.throws(() => {
|
||||||
app.disableDomainBlockingFor3DAPIs()
|
app.disableDomainBlockingFor3DAPIs()
|
||||||
}, /before app is ready/)
|
}, /before app is ready/)
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ const {closeWindow} = require('./window-helpers')
|
||||||
const {ipcRenderer, remote} = require('electron')
|
const {ipcRenderer, remote} = require('electron')
|
||||||
const {ipcMain, webContents, BrowserWindow} = remote
|
const {ipcMain, webContents, BrowserWindow} = remote
|
||||||
|
|
||||||
const comparePaths = function (path1, path2) {
|
const comparePaths = (path1, path2) => {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
path1 = path1.toLowerCase()
|
path1 = path1.toLowerCase()
|
||||||
path2 = path2.toLowerCase()
|
path2 = path2.toLowerCase()
|
||||||
|
@ -16,29 +16,27 @@ const comparePaths = function (path1, path2) {
|
||||||
assert.equal(path1, path2)
|
assert.equal(path1, path2)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('ipc module', function () {
|
describe('ipc module', () => {
|
||||||
var fixtures = path.join(__dirname, 'fixtures')
|
const fixtures = path.join(__dirname, 'fixtures')
|
||||||
|
|
||||||
var w = null
|
let w = null
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||||
return closeWindow(w).then(function () { w = null })
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('remote.require', function () {
|
describe('remote.require', () => {
|
||||||
it('should returns same object for the same module', function () {
|
it('should returns same object for the same module', () => {
|
||||||
var dialog1 = remote.require('electron')
|
const dialog1 = remote.require('electron')
|
||||||
var dialog2 = remote.require('electron')
|
const dialog2 = remote.require('electron')
|
||||||
assert.equal(dialog1, dialog2)
|
assert.equal(dialog1, dialog2)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work when object contains id property', function () {
|
it('should work when object contains id property', () => {
|
||||||
var a = remote.require(path.join(fixtures, 'module', 'id.js'))
|
const a = remote.require(path.join(fixtures, 'module', 'id.js'))
|
||||||
assert.equal(a.id, 1127)
|
assert.equal(a.id, 1127)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work when object has no prototype', function () {
|
it('should work when object has no prototype', () => {
|
||||||
var a = remote.require(path.join(fixtures, 'module', 'no-prototype.js'))
|
const a = remote.require(path.join(fixtures, 'module', 'no-prototype.js'))
|
||||||
assert.equal(a.foo.constructor.name, '')
|
assert.equal(a.foo.constructor.name, '')
|
||||||
assert.equal(a.foo.bar, 'baz')
|
assert.equal(a.foo.bar, 'baz')
|
||||||
assert.equal(a.foo.baz, false)
|
assert.equal(a.foo.baz, false)
|
||||||
|
@ -48,13 +46,13 @@ describe('ipc module', function () {
|
||||||
assert.equal(a.getConstructorName(new (class {})()), '')
|
assert.equal(a.getConstructorName(new (class {})()), '')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should search module from the user app', function () {
|
it('should search module from the user app', () => {
|
||||||
comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js'))
|
comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js'))
|
||||||
comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'))
|
comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with function properties', function () {
|
it('should work with function properties', () => {
|
||||||
var a = remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js'))
|
let a = remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js'))
|
||||||
assert.equal(typeof a, 'function')
|
assert.equal(typeof a, 'function')
|
||||||
assert.equal(a.bar, 'baz')
|
assert.equal(a.bar, 'baz')
|
||||||
|
|
||||||
|
@ -75,36 +73,36 @@ describe('ipc module', function () {
|
||||||
assert.equal(a.bar.baz, undefined)
|
assert.equal(a.bar.baz, undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with static class members', function () {
|
it('should work with static class members', () => {
|
||||||
var a = remote.require(path.join(fixtures, 'module', 'remote-static.js'))
|
const a = remote.require(path.join(fixtures, 'module', 'remote-static.js'))
|
||||||
assert.equal(typeof a.Foo, 'function')
|
assert.equal(typeof a.Foo, 'function')
|
||||||
assert.equal(a.Foo.foo(), 3)
|
assert.equal(a.Foo.foo(), 3)
|
||||||
assert.equal(a.Foo.bar, 'baz')
|
assert.equal(a.Foo.bar, 'baz')
|
||||||
|
|
||||||
var foo = new a.Foo()
|
const foo = new a.Foo()
|
||||||
assert.equal(foo.baz(), 123)
|
assert.equal(foo.baz(), 123)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('includes the length of functions specified as arguments', function () {
|
it('includes the length of functions specified as arguments', () => {
|
||||||
var a = remote.require(path.join(fixtures, 'module', 'function-with-args.js'))
|
const a = remote.require(path.join(fixtures, 'module', 'function-with-args.js'))
|
||||||
assert.equal(a(function (a, b, c, d, f) {}), 5)
|
assert.equal(a((a, b, c, d, f) => {}), 5)
|
||||||
assert.equal(a((a) => {}), 1)
|
assert.equal(a((a) => {}), 1)
|
||||||
assert.equal(a((...args) => {}), 0)
|
assert.equal(a((...args) => {}), 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handles circular references in arrays and objects', function () {
|
it('handles circular references in arrays and objects', () => {
|
||||||
var a = remote.require(path.join(fixtures, 'module', 'circular.js'))
|
const a = remote.require(path.join(fixtures, 'module', 'circular.js'))
|
||||||
|
|
||||||
var arrayA = ['foo']
|
let arrayA = ['foo']
|
||||||
var arrayB = [arrayA, 'bar']
|
const arrayB = [arrayA, 'bar']
|
||||||
arrayA.push(arrayB)
|
arrayA.push(arrayB)
|
||||||
assert.deepEqual(a.returnArgs(arrayA, arrayB), [
|
assert.deepEqual(a.returnArgs(arrayA, arrayB), [
|
||||||
['foo', [null, 'bar']],
|
['foo', [null, 'bar']],
|
||||||
[['foo', null], 'bar']
|
[['foo', null], 'bar']
|
||||||
])
|
])
|
||||||
|
|
||||||
var objectA = {foo: 'bar'}
|
let objectA = {foo: 'bar'}
|
||||||
var objectB = {baz: objectA}
|
const objectB = {baz: objectA}
|
||||||
objectA.objectB = objectB
|
objectA.objectB = objectB
|
||||||
assert.deepEqual(a.returnArgs(objectA, objectB), [
|
assert.deepEqual(a.returnArgs(objectA, objectB), [
|
||||||
{foo: 'bar', objectB: {baz: null}},
|
{foo: 'bar', objectB: {baz: null}},
|
||||||
|
@ -145,35 +143,35 @@ describe('ipc module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote.createFunctionWithReturnValue', function () {
|
describe('remote.createFunctionWithReturnValue', () => {
|
||||||
it('should be called in browser synchronously', function () {
|
it('should be called in browser synchronously', () => {
|
||||||
var buf = new Buffer('test')
|
const buf = new Buffer('test')
|
||||||
var call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
const call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
||||||
var result = call.call(remote.createFunctionWithReturnValue(buf))
|
const result = call.call(remote.createFunctionWithReturnValue(buf))
|
||||||
assert.equal(result.constructor.name, 'Buffer')
|
assert.equal(result.constructor.name, 'Buffer')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote modules', function () {
|
describe('remote modules', () => {
|
||||||
it('includes browser process modules as properties', function () {
|
it('includes browser process modules as properties', () => {
|
||||||
assert.equal(typeof remote.app.getPath, 'function')
|
assert.equal(typeof remote.app.getPath, 'function')
|
||||||
assert.equal(typeof remote.webContents.getFocusedWebContents, 'function')
|
assert.equal(typeof remote.webContents.getFocusedWebContents, 'function')
|
||||||
assert.equal(typeof remote.clipboard.readText, 'function')
|
assert.equal(typeof remote.clipboard.readText, 'function')
|
||||||
assert.equal(typeof remote.shell.openExternal, 'function')
|
assert.equal(typeof remote.shell.openExternal, 'function')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns toString() of original function via toString()', function () {
|
it('returns toString() of original function via toString()', () => {
|
||||||
const {readText} = remote.clipboard
|
const {readText} = remote.clipboard
|
||||||
assert(readText.toString().startsWith('function'))
|
assert(readText.toString().startsWith('function'))
|
||||||
|
|
||||||
var {functionWithToStringProperty} = remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'))
|
const {functionWithToStringProperty} = remote.require(path.join(fixtures, 'module', 'to-string-non-function.js'))
|
||||||
assert.equal(functionWithToStringProperty.toString, 'hello')
|
assert.equal(functionWithToStringProperty.toString, 'hello')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote object in renderer', function () {
|
describe('remote object in renderer', () => {
|
||||||
it('can change its properties', function () {
|
it('can change its properties', () => {
|
||||||
var property = remote.require(path.join(fixtures, 'module', 'property.js'))
|
const property = remote.require(path.join(fixtures, 'module', 'property.js'))
|
||||||
assert.equal(property.property, 1127)
|
assert.equal(property.property, 1127)
|
||||||
|
|
||||||
property.property = null
|
property.property = null
|
||||||
|
@ -188,70 +186,70 @@ describe('ipc module', function () {
|
||||||
assert.equal(property.getFunctionProperty(), 'bar-browser')
|
assert.equal(property.getFunctionProperty(), 'bar-browser')
|
||||||
property.func.property = 'foo' // revert back
|
property.func.property = 'foo' // revert back
|
||||||
|
|
||||||
var property2 = remote.require(path.join(fixtures, 'module', 'property.js'))
|
const property2 = remote.require(path.join(fixtures, 'module', 'property.js'))
|
||||||
assert.equal(property2.property, 1007)
|
assert.equal(property2.property, 1007)
|
||||||
property.property = 1127
|
property.property = 1127
|
||||||
})
|
})
|
||||||
|
|
||||||
it('rethrows errors getting/setting properties', function () {
|
it('rethrows errors getting/setting properties', () => {
|
||||||
const foo = remote.require(path.join(fixtures, 'module', 'error-properties.js'))
|
const foo = remote.require(path.join(fixtures, 'module', 'error-properties.js'))
|
||||||
|
|
||||||
assert.throws(function () {
|
assert.throws(() => {
|
||||||
foo.bar
|
foo.bar
|
||||||
}, /getting error/)
|
}, /getting error/)
|
||||||
|
|
||||||
assert.throws(function () {
|
assert.throws(() => {
|
||||||
foo.bar = 'test'
|
foo.bar = 'test'
|
||||||
}, /setting error/)
|
}, /setting error/)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can set a remote property with a remote object', function () {
|
it('can set a remote property with a remote object', () => {
|
||||||
const foo = remote.require(path.join(fixtures, 'module', 'remote-object-set.js'))
|
const foo = remote.require(path.join(fixtures, 'module', 'remote-object-set.js'))
|
||||||
|
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
foo.bar = remote.getCurrentWindow()
|
foo.bar = remote.getCurrentWindow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can construct an object from its member', function () {
|
it('can construct an object from its member', () => {
|
||||||
var call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
const call = remote.require(path.join(fixtures, 'module', 'call.js'))
|
||||||
var obj = new call.constructor()
|
const obj = new call.constructor()
|
||||||
assert.equal(obj.test, 'test')
|
assert.equal(obj.test, 'test')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can reassign and delete its member functions', function () {
|
it('can reassign and delete its member functions', () => {
|
||||||
var remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'))
|
const remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js'))
|
||||||
assert.equal(remoteFunctions.aFunction(), 1127)
|
assert.equal(remoteFunctions.aFunction(), 1127)
|
||||||
|
|
||||||
remoteFunctions.aFunction = function () { return 1234 }
|
remoteFunctions.aFunction = () => { return 1234 }
|
||||||
assert.equal(remoteFunctions.aFunction(), 1234)
|
assert.equal(remoteFunctions.aFunction(), 1234)
|
||||||
|
|
||||||
assert.equal(delete remoteFunctions.aFunction, true)
|
assert.equal(delete remoteFunctions.aFunction, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('is referenced by its members', function () {
|
it('is referenced by its members', () => {
|
||||||
let stringify = remote.getGlobal('JSON').stringify
|
let stringify = remote.getGlobal('JSON').stringify
|
||||||
global.gc()
|
global.gc()
|
||||||
stringify({})
|
stringify({})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote value in browser', function () {
|
describe('remote value in browser', () => {
|
||||||
const print = path.join(fixtures, 'module', 'print_name.js')
|
const print = path.join(fixtures, 'module', 'print_name.js')
|
||||||
const printName = remote.require(print)
|
const printName = remote.require(print)
|
||||||
|
|
||||||
it('keeps its constructor name for objects', function () {
|
it('keeps its constructor name for objects', () => {
|
||||||
const buf = new Buffer('test')
|
const buf = new Buffer('test')
|
||||||
assert.equal(printName.print(buf), 'Buffer')
|
assert.equal(printName.print(buf), 'Buffer')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports instanceof Date', function () {
|
it('supports instanceof Date', () => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
assert.equal(printName.print(now), 'Date')
|
assert.equal(printName.print(now), 'Date')
|
||||||
assert.deepEqual(printName.echo(now), now)
|
assert.deepEqual(printName.echo(now), now)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports instanceof Buffer', function () {
|
it('supports instanceof Buffer', () => {
|
||||||
const buffer = Buffer.from('test')
|
const buffer = Buffer.from('test')
|
||||||
assert.ok(buffer.equals(printName.echo(buffer)))
|
assert.ok(buffer.equals(printName.echo(buffer)))
|
||||||
|
|
||||||
|
@ -262,7 +260,7 @@ describe('ipc module', function () {
|
||||||
assert.ok(arrayWithBuffer[2].equals(printName.echo(arrayWithBuffer)[2]))
|
assert.ok(arrayWithBuffer[2].equals(printName.echo(arrayWithBuffer)[2]))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports TypedArray', function () {
|
it('supports TypedArray', () => {
|
||||||
const values = [1, 2, 3, 4]
|
const values = [1, 2, 3, 4]
|
||||||
assert.deepEqual(printName.typedArray(values), values)
|
assert.deepEqual(printName.typedArray(values), values)
|
||||||
|
|
||||||
|
@ -271,93 +269,93 @@ describe('ipc module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote promise', function () {
|
describe('remote promise', () => {
|
||||||
it('can be used as promise in each side', function (done) {
|
it('can be used as promise in each side', (done) => {
|
||||||
var promise = remote.require(path.join(fixtures, 'module', 'promise.js'))
|
const promise = remote.require(path.join(fixtures, 'module', 'promise.js'))
|
||||||
promise.twicePromise(Promise.resolve(1234)).then(function (value) {
|
promise.twicePromise(Promise.resolve(1234)).then((value) => {
|
||||||
assert.equal(value, 2468)
|
assert.equal(value, 2468)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handles rejections via catch(onRejected)', function (done) {
|
it('handles rejections via catch(onRejected)', (done) => {
|
||||||
var promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
|
const promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
|
||||||
promise.reject(Promise.resolve(1234)).catch(function (error) {
|
promise.reject(Promise.resolve(1234)).catch((error) => {
|
||||||
assert.equal(error.message, 'rejected')
|
assert.equal(error.message, 'rejected')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('handles rejections via then(onFulfilled, onRejected)', function (done) {
|
it('handles rejections via then(onFulfilled, onRejected)', (done) => {
|
||||||
var promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
|
const promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js'))
|
||||||
promise.reject(Promise.resolve(1234)).then(function () {}, function (error) {
|
promise.reject(Promise.resolve(1234)).then(() => {}, (error) => {
|
||||||
assert.equal(error.message, 'rejected')
|
assert.equal(error.message, 'rejected')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not emit unhandled rejection events in the main process', function (done) {
|
it('does not emit unhandled rejection events in the main process', (done) => {
|
||||||
remote.process.once('unhandledRejection', function (reason) {
|
remote.process.once('unhandledRejection', function (reason) {
|
||||||
done(reason)
|
done(reason)
|
||||||
})
|
})
|
||||||
|
|
||||||
var promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
|
const promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
|
||||||
promise.reject().then(function () {
|
promise.reject().then(() => {
|
||||||
done(new Error('Promise was not rejected'))
|
done(new Error('Promise was not rejected'))
|
||||||
}).catch(function (error) {
|
}).catch((error) => {
|
||||||
assert.equal(error.message, 'rejected')
|
assert.equal(error.message, 'rejected')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits unhandled rejection events in the renderer process', function (done) {
|
it('emits unhandled rejection events in the renderer process', (done) => {
|
||||||
window.addEventListener('unhandledrejection', function (event) {
|
window.addEventListener('unhandledrejection', function (event) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
assert.equal(event.reason.message, 'rejected')
|
assert.equal(event.reason.message, 'rejected')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
var promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
|
const promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js'))
|
||||||
promise.reject().then(function () {
|
promise.reject().then(() => {
|
||||||
done(new Error('Promise was not rejected'))
|
done(new Error('Promise was not rejected'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote webContents', function () {
|
describe('remote webContents', () => {
|
||||||
it('can return same object with different getters', function () {
|
it('can return same object with different getters', () => {
|
||||||
var contents1 = remote.getCurrentWindow().webContents
|
const contents1 = remote.getCurrentWindow().webContents
|
||||||
var contents2 = remote.getCurrentWebContents()
|
const contents2 = remote.getCurrentWebContents()
|
||||||
assert(contents1 === contents2)
|
assert(contents1 === contents2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote class', function () {
|
describe('remote class', () => {
|
||||||
let cl = remote.require(path.join(fixtures, 'module', 'class.js'))
|
const cl = remote.require(path.join(fixtures, 'module', 'class.js'))
|
||||||
let base = cl.base
|
const base = cl.base
|
||||||
let derived = cl.derived
|
let derived = cl.derived
|
||||||
|
|
||||||
it('can get methods', function () {
|
it('can get methods', () => {
|
||||||
assert.equal(base.method(), 'method')
|
assert.equal(base.method(), 'method')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can get properties', function () {
|
it('can get properties', () => {
|
||||||
assert.equal(base.readonly, 'readonly')
|
assert.equal(base.readonly, 'readonly')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can change properties', function () {
|
it('can change properties', () => {
|
||||||
assert.equal(base.value, 'old')
|
assert.equal(base.value, 'old')
|
||||||
base.value = 'new'
|
base.value = 'new'
|
||||||
assert.equal(base.value, 'new')
|
assert.equal(base.value, 'new')
|
||||||
base.value = 'old'
|
base.value = 'old'
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has unenumerable methods', function () {
|
it('has unenumerable methods', () => {
|
||||||
assert(!base.hasOwnProperty('method'))
|
assert(!base.hasOwnProperty('method'))
|
||||||
assert(Object.getPrototypeOf(base).hasOwnProperty('method'))
|
assert(Object.getPrototypeOf(base).hasOwnProperty('method'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('keeps prototype chain in derived class', function () {
|
it('keeps prototype chain in derived class', () => {
|
||||||
assert.equal(derived.method(), 'method')
|
assert.equal(derived.method(), 'method')
|
||||||
assert.equal(derived.readonly, 'readonly')
|
assert.equal(derived.readonly, 'readonly')
|
||||||
assert(!derived.hasOwnProperty('method'))
|
assert(!derived.hasOwnProperty('method'))
|
||||||
|
@ -366,7 +364,7 @@ describe('ipc module', function () {
|
||||||
assert(Object.getPrototypeOf(proto).hasOwnProperty('method'))
|
assert(Object.getPrototypeOf(proto).hasOwnProperty('method'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('is referenced by methods in prototype chain', function () {
|
it('is referenced by methods in prototype chain', () => {
|
||||||
let method = derived.method
|
let method = derived.method
|
||||||
derived = null
|
derived = null
|
||||||
global.gc()
|
global.gc()
|
||||||
|
@ -374,9 +372,9 @@ describe('ipc module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ipc.sender.send', function () {
|
describe('ipc.sender.send', () => {
|
||||||
it('should work when sending an object containing id property', function (done) {
|
it('should work when sending an object containing id property', (done) => {
|
||||||
var obj = {
|
const obj = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'ly'
|
name: 'ly'
|
||||||
}
|
}
|
||||||
|
@ -387,7 +385,7 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', obj)
|
ipcRenderer.send('message', obj)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send instances of Date', function (done) {
|
it('can send instances of Date', (done) => {
|
||||||
const currentDate = new Date()
|
const currentDate = new Date()
|
||||||
ipcRenderer.once('message', function (event, value) {
|
ipcRenderer.once('message', function (event, value) {
|
||||||
assert.equal(value, currentDate.toISOString())
|
assert.equal(value, currentDate.toISOString())
|
||||||
|
@ -396,7 +394,7 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', currentDate)
|
ipcRenderer.send('message', currentDate)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send instances of Buffer', function (done) {
|
it('can send instances of Buffer', (done) => {
|
||||||
const buffer = Buffer.from('hello')
|
const buffer = Buffer.from('hello')
|
||||||
ipcRenderer.once('message', function (event, message) {
|
ipcRenderer.once('message', function (event, message) {
|
||||||
assert.ok(buffer.equals(message))
|
assert.ok(buffer.equals(message))
|
||||||
|
@ -405,7 +403,7 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', buffer)
|
ipcRenderer.send('message', buffer)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send objects with DOM class prototypes', function (done) {
|
it('can send objects with DOM class prototypes', (done) => {
|
||||||
ipcRenderer.once('message', function (event, value) {
|
ipcRenderer.once('message', function (event, value) {
|
||||||
assert.equal(value.protocol, 'file:')
|
assert.equal(value.protocol, 'file:')
|
||||||
assert.equal(value.hostname, '')
|
assert.equal(value.hostname, '')
|
||||||
|
@ -414,7 +412,7 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', document.location)
|
ipcRenderer.send('message', document.location)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send Electron API objects', function (done) {
|
it('can send Electron API objects', (done) => {
|
||||||
const webContents = remote.getCurrentWebContents()
|
const webContents = remote.getCurrentWebContents()
|
||||||
ipcRenderer.once('message', function (event, value) {
|
ipcRenderer.once('message', function (event, value) {
|
||||||
assert.deepEqual(value.browserWindowOptions, webContents.browserWindowOptions)
|
assert.deepEqual(value.browserWindowOptions, webContents.browserWindowOptions)
|
||||||
|
@ -423,10 +421,10 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', webContents)
|
ipcRenderer.send('message', webContents)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash on external objects (regression)', function (done) {
|
it('does not crash on external objects (regression)', (done) => {
|
||||||
const request = http.request({port: 5000, hostname: '127.0.0.1', method: 'GET', path: '/'})
|
const request = http.request({port: 5000, hostname: '127.0.0.1', method: 'GET', path: '/'})
|
||||||
const stream = request.agent.sockets['127.0.0.1:5000:'][0]._handle._externalStream
|
const stream = request.agent.sockets['127.0.0.1:5000:'][0]._handle._externalStream
|
||||||
request.on('error', function () {})
|
request.on('error', () => {})
|
||||||
ipcRenderer.once('message', function (event, requestValue, externalStreamValue) {
|
ipcRenderer.once('message', function (event, requestValue, externalStreamValue) {
|
||||||
assert.equal(requestValue.method, 'GET')
|
assert.equal(requestValue.method, 'GET')
|
||||||
assert.equal(requestValue.path, '/')
|
assert.equal(requestValue.path, '/')
|
||||||
|
@ -437,7 +435,7 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', request, stream)
|
ipcRenderer.send('message', request, stream)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send objects that both reference the same object', function (done) {
|
it('can send objects that both reference the same object', (done) => {
|
||||||
const child = {hello: 'world'}
|
const child = {hello: 'world'}
|
||||||
const foo = {name: 'foo', child: child}
|
const foo = {name: 'foo', child: child}
|
||||||
const bar = {name: 'bar', child: child}
|
const bar = {name: 'bar', child: child}
|
||||||
|
@ -453,7 +451,7 @@ describe('ipc module', function () {
|
||||||
ipcRenderer.send('message', array, foo, bar, child)
|
ipcRenderer.send('message', array, foo, bar, child)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('inserts null for cyclic references', function (done) {
|
it('inserts null for cyclic references', (done) => {
|
||||||
const array = [5]
|
const array = [5]
|
||||||
array.push(array)
|
array.push(array)
|
||||||
|
|
||||||
|
@ -473,17 +471,17 @@ describe('ipc module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ipc.sendSync', function () {
|
describe('ipc.sendSync', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ipcMain.removeAllListeners('send-sync-message')
|
ipcMain.removeAllListeners('send-sync-message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can be replied by setting event.returnValue', function () {
|
it('can be replied by setting event.returnValue', () => {
|
||||||
var msg = ipcRenderer.sendSync('echo', 'test')
|
const msg = ipcRenderer.sendSync('echo', 'test')
|
||||||
assert.equal(msg, 'test')
|
assert.equal(msg, 'test')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash when reply is not sent and browser is destroyed', function (done) {
|
it('does not crash when reply is not sent and browser is destroyed', (done) => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
})
|
})
|
||||||
|
@ -494,7 +492,7 @@ describe('ipc module', function () {
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'send-sync-message.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash when reply is sent by multiple listeners', function (done) {
|
it('does not crash when reply is sent by multiple listeners', (done) => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
})
|
})
|
||||||
|
@ -509,36 +507,36 @@ describe('ipc module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ipcRenderer.sendTo', function () {
|
describe('ipcRenderer.sendTo', () => {
|
||||||
let contents = null
|
let contents = null
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
contents = webContents.create({})
|
contents = webContents.create({})
|
||||||
})
|
})
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ipcRenderer.removeAllListeners('pong')
|
ipcRenderer.removeAllListeners('pong')
|
||||||
contents.destroy()
|
contents.destroy()
|
||||||
contents = null
|
contents = null
|
||||||
})
|
})
|
||||||
|
|
||||||
it('sends message to WebContents', function (done) {
|
it('sends message to WebContents', (done) => {
|
||||||
const webContentsId = remote.getCurrentWebContents().id
|
const webContentsId = remote.getCurrentWebContents().id
|
||||||
ipcRenderer.once('pong', function (event, id) {
|
ipcRenderer.once('pong', function (event, id) {
|
||||||
assert.equal(webContentsId, id)
|
assert.equal(webContentsId, id)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
contents.once('did-finish-load', function () {
|
contents.once('did-finish-load', () => {
|
||||||
ipcRenderer.sendTo(contents.id, 'ping', webContentsId)
|
ipcRenderer.sendTo(contents.id, 'ping', webContentsId)
|
||||||
})
|
})
|
||||||
contents.loadURL('file://' + path.join(fixtures, 'pages', 'ping-pong.html'))
|
contents.loadURL('file://' + path.join(fixtures, 'pages', 'ping-pong.html'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote listeners', function () {
|
describe('remote listeners', () => {
|
||||||
it('can be added and removed correctly', function () {
|
it('can be added and removed correctly', () => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
})
|
})
|
||||||
var listener = function () {}
|
const listener = () => {}
|
||||||
w.on('test', listener)
|
w.on('test', listener)
|
||||||
assert.equal(w.listenerCount('test'), 1)
|
assert.equal(w.listenerCount('test'), 1)
|
||||||
w.removeListener('test', listener)
|
w.removeListener('test', listener)
|
||||||
|
@ -592,8 +590,8 @@ describe('ipc module', function () {
|
||||||
assert.equal(ipcRenderer.listenerCount('test-event'), 0)
|
assert.equal(ipcRenderer.listenerCount('test-event'), 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote objects registry', function () {
|
describe('remote objects registry', () => {
|
||||||
it('does not dereference until the render view is deleted (regression)', function (done) {
|
it('does not dereference until the render view is deleted (regression)', (done) => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false
|
show: false
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,9 +4,9 @@ const {ipcRenderer, remote} = require('electron')
|
||||||
const {BrowserWindow, Menu, MenuItem} = remote
|
const {BrowserWindow, Menu, MenuItem} = remote
|
||||||
const {closeWindow} = require('./window-helpers')
|
const {closeWindow} = require('./window-helpers')
|
||||||
|
|
||||||
describe('menu module', function () {
|
describe('Menu module', () => {
|
||||||
describe('Menu.buildFromTemplate', function () {
|
describe('Menu.buildFromTemplate', () => {
|
||||||
it('should be able to attach extra fields', function () {
|
it('should be able to attach extra fields', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'text',
|
label: 'text',
|
||||||
|
@ -16,7 +16,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[0].extra, 'field')
|
assert.equal(menu.items[0].extra, 'field')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not modify the specified template', function () {
|
it('does not modify the specified template', () => {
|
||||||
const template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;")
|
const template = ipcRenderer.sendSync('eval', "var template = [{label: 'text', submenu: [{label: 'sub'}]}];\nrequire('electron').Menu.buildFromTemplate(template);\ntemplate;")
|
||||||
assert.deepStrictEqual(template, [
|
assert.deepStrictEqual(template, [
|
||||||
{
|
{
|
||||||
|
@ -30,8 +30,8 @@ describe('menu module', function () {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not throw exceptions for undefined/null values', function () {
|
it('does not throw exceptions for undefined/null values', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
Menu.buildFromTemplate([
|
Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'text',
|
label: 'text',
|
||||||
|
@ -45,8 +45,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Menu.buildFromTemplate should reorder based on item position specifiers', function () {
|
describe('Menu.buildFromTemplate should reorder based on item position specifiers', () => {
|
||||||
it('should position before existing item', function () {
|
it('should position before existing item', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '2',
|
label: '2',
|
||||||
|
@ -65,7 +65,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[2].label, '3')
|
assert.equal(menu.items[2].label, '3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should position after existing item', function () {
|
it('should position after existing item', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '1',
|
label: '1',
|
||||||
|
@ -84,7 +84,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[2].label, '3')
|
assert.equal(menu.items[2].label, '3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should position at endof existing separator groups', function () {
|
it('should position at endof existing separator groups', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
type: 'separator',
|
type: 'separator',
|
||||||
|
@ -128,7 +128,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[7].label, 'c')
|
assert.equal(menu.items[7].label, 'c')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should create separator group if endof does not reference existing separator group', function () {
|
it('should create separator group if endof does not reference existing separator group', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'a',
|
label: 'a',
|
||||||
|
@ -166,7 +166,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[7].label, '3')
|
assert.equal(menu.items[7].label, '3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should continue inserting items at next index when no specifier is present', function () {
|
it('should continue inserting items at next index when no specifier is present', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '4',
|
label: '4',
|
||||||
|
@ -195,8 +195,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Menu.getMenuItemById', function () {
|
describe('Menu.getMenuItemById', () => {
|
||||||
it('should return the item with the given id', function () {
|
it('should return the item with the given id', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'View',
|
label: 'View',
|
||||||
|
@ -218,8 +218,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Menu.insert', function () {
|
describe('Menu.insert', () => {
|
||||||
it('should store item in @items by its index', function () {
|
it('should store item in @items by its index', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '1'
|
label: '1'
|
||||||
|
@ -240,8 +240,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Menu.append', function () {
|
describe('Menu.append', () => {
|
||||||
it('should add the item to the end of the menu', function () {
|
it('should add the item to the end of the menu', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '1'
|
label: '1'
|
||||||
|
@ -261,7 +261,7 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Menu.popup', function () {
|
describe('Menu.popup', () => {
|
||||||
let w = null
|
let w = null
|
||||||
let menu
|
let menu
|
||||||
|
|
||||||
|
@ -279,18 +279,18 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
return closeWindow(w).then(function () { w = null })
|
return closeWindow(w).then(() => { w = null })
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when called with async: true', function () {
|
describe('when called with async: true', () => {
|
||||||
it('returns immediately', function () {
|
it('returns immediately', () => {
|
||||||
menu.popup(w, {x: 100, y: 100, async: true})
|
menu.popup(w, {x: 100, y: 100, async: true})
|
||||||
menu.closePopup(w)
|
menu.closePopup(w)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Menu.setApplicationMenu', function () {
|
describe('Menu.setApplicationMenu', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: '1'
|
label: '1'
|
||||||
|
@ -302,7 +302,7 @@ describe('menu module', function () {
|
||||||
assert.notEqual(Menu.getApplicationMenu(), null)
|
assert.notEqual(Menu.getApplicationMenu(), null)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem.click', function () {
|
describe('MenuItem.click', () => {
|
||||||
it('should be called with the item object passed', function (done) {
|
it('should be called with the item object passed', function (done) {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
|
@ -318,8 +318,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem with checked property', function () {
|
describe('MenuItem with checked property', () => {
|
||||||
it('clicking an checkbox item should flip the checked property', function () {
|
it('clicking an checkbox item should flip the checked property', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'text',
|
label: 'text',
|
||||||
|
@ -331,7 +331,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[0].checked, true)
|
assert.equal(menu.items[0].checked, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('clicking an radio item should always make checked property true', function () {
|
it('clicking an radio item should always make checked property true', () => {
|
||||||
const menu = Menu.buildFromTemplate([
|
const menu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
label: 'text',
|
label: 'text',
|
||||||
|
@ -344,7 +344,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[0].checked, true)
|
assert.equal(menu.items[0].checked, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('at least have one item checked in each group', function () {
|
it('at least have one item checked in each group', () => {
|
||||||
const template = []
|
const template = []
|
||||||
for (let i = 0; i <= 10; i++) {
|
for (let i = 0; i <= 10; i++) {
|
||||||
template.push({
|
template.push({
|
||||||
|
@ -365,7 +365,7 @@ describe('menu module', function () {
|
||||||
assert.equal(menu.items[12].checked, true)
|
assert.equal(menu.items[12].checked, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should assign groupId automatically', function () {
|
it('should assign groupId automatically', () => {
|
||||||
const template = []
|
const template = []
|
||||||
for (let i = 0; i <= 10; i++) {
|
for (let i = 0; i <= 10; i++) {
|
||||||
template.push({
|
template.push({
|
||||||
|
@ -390,7 +390,7 @@ describe('menu module', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it("setting 'checked' should flip other items' 'checked' property", function () {
|
it("setting 'checked' should flip other items' 'checked' property", () => {
|
||||||
const template = []
|
const template = []
|
||||||
for (let i = 0; i <= 10; i++) {
|
for (let i = 0; i <= 10; i++) {
|
||||||
template.push({
|
template.push({
|
||||||
|
@ -435,8 +435,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem command id', function () {
|
describe('MenuItem command id', () => {
|
||||||
it('cannot be overwritten', function () {
|
it('cannot be overwritten', () => {
|
||||||
const item = new MenuItem({label: 'item'})
|
const item = new MenuItem({label: 'item'})
|
||||||
|
|
||||||
const commandId = item.commandId
|
const commandId = item.commandId
|
||||||
|
@ -446,8 +446,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem with invalid type', function () {
|
describe('MenuItem with invalid type', () => {
|
||||||
it('throws an exception', function () {
|
it('throws an exception', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
Menu.buildFromTemplate([
|
Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
|
@ -459,8 +459,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem with submenu type and missing submenu', function () {
|
describe('MenuItem with submenu type and missing submenu', () => {
|
||||||
it('throws an exception', function () {
|
it('throws an exception', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
Menu.buildFromTemplate([
|
Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
|
@ -472,8 +472,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem role', function () {
|
describe('MenuItem role', () => {
|
||||||
it('includes a default label and accelerator', function () {
|
it('includes a default label and accelerator', () => {
|
||||||
let item = new MenuItem({role: 'close'})
|
let item = new MenuItem({role: 'close'})
|
||||||
assert.equal(item.label, process.platform === 'darwin' ? 'Close Window' : 'Close')
|
assert.equal(item.label, process.platform === 'darwin' ? 'Close Window' : 'Close')
|
||||||
assert.equal(item.accelerator, undefined)
|
assert.equal(item.accelerator, undefined)
|
||||||
|
@ -506,8 +506,8 @@ describe('menu module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem editMenu', function () {
|
describe('MenuItem editMenu', () => {
|
||||||
it('includes a default submenu layout when submenu is empty', function () {
|
it('includes a default submenu layout when submenu is empty', () => {
|
||||||
const item = new MenuItem({role: 'editMenu'})
|
const item = new MenuItem({role: 'editMenu'})
|
||||||
assert.equal(item.label, 'Edit')
|
assert.equal(item.label, 'Edit')
|
||||||
assert.equal(item.submenu.items[0].role, 'undo')
|
assert.equal(item.submenu.items[0].role, 'undo')
|
||||||
|
@ -530,15 +530,15 @@ describe('menu module', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('overrides default layout when submenu is specified', function () {
|
it('overrides default layout when submenu is specified', () => {
|
||||||
const item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]})
|
const item = new MenuItem({role: 'editMenu', submenu: [{role: 'close'}]})
|
||||||
assert.equal(item.label, 'Edit')
|
assert.equal(item.label, 'Edit')
|
||||||
assert.equal(item.submenu.items[0].role, 'close')
|
assert.equal(item.submenu.items[0].role, 'close')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem windowMenu', function () {
|
describe('MenuItem windowMenu', () => {
|
||||||
it('includes a default submenu layout when submenu is empty', function () {
|
it('includes a default submenu layout when submenu is empty', () => {
|
||||||
const item = new MenuItem({role: 'windowMenu'})
|
const item = new MenuItem({role: 'windowMenu'})
|
||||||
assert.equal(item.label, 'Window')
|
assert.equal(item.label, 'Window')
|
||||||
assert.equal(item.submenu.items[0].role, 'minimize')
|
assert.equal(item.submenu.items[0].role, 'minimize')
|
||||||
|
@ -550,15 +550,15 @@ describe('menu module', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it('overrides default layout when submenu is specified', function () {
|
it('overrides default layout when submenu is specified', () => {
|
||||||
const item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]})
|
const item = new MenuItem({role: 'windowMenu', submenu: [{role: 'copy'}]})
|
||||||
assert.equal(item.label, 'Window')
|
assert.equal(item.label, 'Window')
|
||||||
assert.equal(item.submenu.items[0].role, 'copy')
|
assert.equal(item.submenu.items[0].role, 'copy')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('MenuItem with custom properties in constructor', function () {
|
describe('MenuItem with custom properties in constructor', () => {
|
||||||
it('preserves the custom properties', function () {
|
it('preserves the custom properties', () => {
|
||||||
const template = [{
|
const template = [{
|
||||||
label: 'menu 1',
|
label: 'menu 1',
|
||||||
customProp: 'foo',
|
customProp: 'foo',
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,13 +10,13 @@ const {closeWindow} = require('./window-helpers')
|
||||||
const {ipcRenderer, remote} = require('electron')
|
const {ipcRenderer, remote} = require('electron')
|
||||||
const {ipcMain, session, BrowserWindow, net} = remote
|
const {ipcMain, session, BrowserWindow, net} = remote
|
||||||
|
|
||||||
describe('session module', function () {
|
describe('session module', () => {
|
||||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
let fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
var w = null
|
let w = null
|
||||||
var webview = null
|
let webview = null
|
||||||
var url = 'http://127.0.0.1'
|
const url = 'http://127.0.0.1'
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 400,
|
width: 400,
|
||||||
|
@ -24,7 +24,7 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
if (webview != null) {
|
if (webview != null) {
|
||||||
if (!document.body.contains(webview)) {
|
if (!document.body.contains(webview)) {
|
||||||
document.body.appendChild(webview)
|
document.body.appendChild(webview)
|
||||||
|
@ -32,21 +32,21 @@ describe('session module', function () {
|
||||||
webview.remove()
|
webview.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
return closeWindow(w).then(function () { w = null })
|
return closeWindow(w).then(() => { w = null })
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('session.defaultSession', function () {
|
describe('session.defaultSession', () => {
|
||||||
it('returns the default session', function () {
|
it('returns the default session', () => {
|
||||||
assert.equal(session.defaultSession, session.fromPartition(''))
|
assert.equal(session.defaultSession, session.fromPartition(''))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('session.fromPartition(partition, options)', function () {
|
describe('session.fromPartition(partition, options)', () => {
|
||||||
it('returns existing session with same partition', function () {
|
it('returns existing session with same partition', () => {
|
||||||
assert.equal(session.fromPartition('test'), session.fromPartition('test'))
|
assert.equal(session.fromPartition('test'), session.fromPartition('test'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('created session is ref-counted', function () {
|
it('created session is ref-counted', () => {
|
||||||
const partition = 'test2'
|
const partition = 'test2'
|
||||||
const userAgent = 'test-agent'
|
const userAgent = 'test-agent'
|
||||||
const ses1 = session.fromPartition(partition)
|
const ses1 = session.fromPartition(partition)
|
||||||
|
@ -58,104 +58,83 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.cookies', function () {
|
describe('ses.cookies', () => {
|
||||||
it('should get cookies', function (done) {
|
it('should get cookies', (done) => {
|
||||||
var server = http.createServer(function (req, res) {
|
const server = http.createServer((req, res) => {
|
||||||
res.setHeader('Set-Cookie', ['0=0'])
|
res.setHeader('Set-Cookie', ['0=0'])
|
||||||
res.end('finished')
|
res.end('finished')
|
||||||
server.close()
|
server.close()
|
||||||
})
|
})
|
||||||
server.listen(0, '127.0.0.1', function () {
|
server.listen(0, '127.0.0.1', () => {
|
||||||
var port = server.address().port
|
const port = server.address().port
|
||||||
w.loadURL(url + ':' + port)
|
w.loadURL(`${url}:${port}`)
|
||||||
w.webContents.on('did-finish-load', function () {
|
w.webContents.on('did-finish-load', () => {
|
||||||
w.webContents.session.cookies.get({
|
w.webContents.session.cookies.get({url}, (error, list) => {
|
||||||
url: url
|
if (error) return done(error)
|
||||||
}, function (error, list) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
var cookie, i, len
|
const cookie = list[i]
|
||||||
if (error) {
|
|
||||||
return done(error)
|
|
||||||
}
|
|
||||||
for (i = 0, len = list.length; i < len; i++) {
|
|
||||||
cookie = list[i]
|
|
||||||
if (cookie.name === '0') {
|
if (cookie.name === '0') {
|
||||||
if (cookie.value === '0') {
|
if (cookie.value === '0') {
|
||||||
return done()
|
return done()
|
||||||
} else {
|
} else {
|
||||||
return done('cookie value is ' + cookie.value + ' while expecting 0')
|
return done(`cookie value is ${cookie.value} while expecting 0`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done('Can not find cookie')
|
done('Can\'t find cookie')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('calls back with an error when setting a cookie with missing required fields', function (done) {
|
it('calls back with an error when setting a cookie with missing required fields', (done) => {
|
||||||
session.defaultSession.cookies.set({
|
session.defaultSession.cookies.set({
|
||||||
url: '',
|
url: '',
|
||||||
name: '1',
|
name: '1',
|
||||||
value: '1'
|
value: '1'
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
assert.equal(error.message, 'Setting cookie failed')
|
assert.equal(error.message, 'Setting cookie failed')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should over-write the existent cookie', function (done) {
|
it('should over-write the existent cookie', (done) => {
|
||||||
session.defaultSession.cookies.set({
|
session.defaultSession.cookies.set({
|
||||||
url: url,
|
url,
|
||||||
name: '1',
|
name: '1',
|
||||||
value: '1'
|
value: '1'
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error) {
|
if (error) return done(error)
|
||||||
return done(error)
|
session.defaultSession.cookies.get({url}, (error, list) => {
|
||||||
}
|
if (error) return done(error)
|
||||||
session.defaultSession.cookies.get({
|
for (let i = 0; i < list.length; i++) {
|
||||||
url: url
|
const cookie = list[i]
|
||||||
}, function (error, list) {
|
|
||||||
var cookie, i, len
|
|
||||||
if (error) {
|
|
||||||
return done(error)
|
|
||||||
}
|
|
||||||
for (i = 0, len = list.length; i < len; i++) {
|
|
||||||
cookie = list[i]
|
|
||||||
if (cookie.name === '1') {
|
if (cookie.name === '1') {
|
||||||
if (cookie.value === '1') {
|
if (cookie.value === '1') {
|
||||||
return done()
|
return done()
|
||||||
} else {
|
} else {
|
||||||
return done('cookie value is ' + cookie.value + ' while expecting 1')
|
return done(`cookie value is ${cookie.value} while expecting 1`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done('Can not find cookie')
|
done('Can\'t find cookie')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should remove cookies', function (done) {
|
it('should remove cookies', (done) => {
|
||||||
session.defaultSession.cookies.set({
|
session.defaultSession.cookies.set({
|
||||||
url: url,
|
url: url,
|
||||||
name: '2',
|
name: '2',
|
||||||
value: '2'
|
value: '2'
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error) {
|
if (error) return done(error)
|
||||||
return done(error)
|
session.defaultSession.cookies.remove(url, '2', () => {
|
||||||
}
|
session.defaultSession.cookies.get({url}, (error, list) => {
|
||||||
session.defaultSession.cookies.remove(url, '2', function () {
|
if (error) return done(error)
|
||||||
session.defaultSession.cookies.get({
|
for (let i = 0; i < list.length; i++) {
|
||||||
url: url
|
const cookie = list[i]
|
||||||
}, function (error, list) {
|
if (cookie.name === '2') return done('Cookie not deleted')
|
||||||
var cookie, i, len
|
|
||||||
if (error) {
|
|
||||||
return done(error)
|
|
||||||
}
|
|
||||||
for (i = 0, len = list.length; i < len; i++) {
|
|
||||||
cookie = list[i]
|
|
||||||
if (cookie.name === '2') {
|
|
||||||
return done('Cookie not deleted')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -163,23 +142,17 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set cookie for standard scheme', function (done) {
|
it('should set cookie for standard scheme', (done) => {
|
||||||
const standardScheme = remote.getGlobal('standardScheme')
|
const standardScheme = remote.getGlobal('standardScheme')
|
||||||
const origin = standardScheme + '://fake-host'
|
const origin = standardScheme + '://fake-host'
|
||||||
session.defaultSession.cookies.set({
|
session.defaultSession.cookies.set({
|
||||||
url: origin,
|
url: origin,
|
||||||
name: 'custom',
|
name: 'custom',
|
||||||
value: '1'
|
value: '1'
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error) {
|
if (error) return done(error)
|
||||||
return done(error)
|
session.defaultSession.cookies.get({url: origin}, (error, list) => {
|
||||||
}
|
if (error) return done(error)
|
||||||
session.defaultSession.cookies.get({
|
|
||||||
url: origin
|
|
||||||
}, function (error, list) {
|
|
||||||
if (error) {
|
|
||||||
return done(error)
|
|
||||||
}
|
|
||||||
assert.equal(list.length, 1)
|
assert.equal(list.length, 1)
|
||||||
assert.equal(list[0].name, 'custom')
|
assert.equal(list[0].name, 'custom')
|
||||||
assert.equal(list[0].value, '1')
|
assert.equal(list[0].value, '1')
|
||||||
|
@ -189,16 +162,16 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits a changed event when a cookie is added or removed', function (done) {
|
it('emits a changed event when a cookie is added or removed', (done) => {
|
||||||
const {cookies} = session.fromPartition('cookies-changed')
|
const {cookies} = session.fromPartition('cookies-changed')
|
||||||
|
|
||||||
cookies.once('changed', function (event, cookie, cause, removed) {
|
cookies.once('changed', (event, cookie, cause, removed) => {
|
||||||
assert.equal(cookie.name, 'foo')
|
assert.equal(cookie.name, 'foo')
|
||||||
assert.equal(cookie.value, 'bar')
|
assert.equal(cookie.value, 'bar')
|
||||||
assert.equal(cause, 'explicit')
|
assert.equal(cause, 'explicit')
|
||||||
assert.equal(removed, false)
|
assert.equal(removed, false)
|
||||||
|
|
||||||
cookies.once('changed', function (event, cookie, cause, removed) {
|
cookies.once('changed', (event, cookie, cause, removed) => {
|
||||||
assert.equal(cookie.name, 'foo')
|
assert.equal(cookie.name, 'foo')
|
||||||
assert.equal(cookie.value, 'bar')
|
assert.equal(cookie.value, 'bar')
|
||||||
assert.equal(cause, 'explicit')
|
assert.equal(cause, 'explicit')
|
||||||
|
@ -206,7 +179,7 @@ describe('session module', function () {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
cookies.remove(url, 'foo', function (error) {
|
cookies.remove(url, 'foo', (error) => {
|
||||||
if (error) return done(error)
|
if (error) return done(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -215,13 +188,13 @@ describe('session module', function () {
|
||||||
url: url,
|
url: url,
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
value: 'bar'
|
value: 'bar'
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error) return done(error)
|
if (error) return done(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.cookies.flushStore(callback)', function () {
|
describe('ses.cookies.flushStore(callback)', () => {
|
||||||
it('flushes the cookies to disk and invokes the callback when done', function (done) {
|
it('flushes the cookies to disk and invokes the callback when done', (done) => {
|
||||||
session.defaultSession.cookies.set({
|
session.defaultSession.cookies.set({
|
||||||
url: url,
|
url: url,
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
|
@ -236,30 +209,30 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.clearStorageData(options)', function () {
|
describe('ses.clearStorageData(options)', () => {
|
||||||
fixtures = path.resolve(__dirname, 'fixtures')
|
fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
it('clears localstorage data', function (done) {
|
it('clears localstorage data', (done) => {
|
||||||
ipcMain.on('count', function (event, count) {
|
ipcMain.on('count', (event, count) => {
|
||||||
ipcMain.removeAllListeners('count')
|
ipcMain.removeAllListeners('count')
|
||||||
assert.equal(count, 0)
|
assert.equal(count, 0)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'localstorage.html'))
|
||||||
w.webContents.on('did-finish-load', function () {
|
w.webContents.on('did-finish-load', () => {
|
||||||
var options = {
|
const options = {
|
||||||
origin: 'file://',
|
origin: 'file://',
|
||||||
storages: ['localstorage'],
|
storages: ['localstorage'],
|
||||||
quotas: ['persistent']
|
quotas: ['persistent']
|
||||||
}
|
}
|
||||||
w.webContents.session.clearStorageData(options, function () {
|
w.webContents.session.clearStorageData(options, () => {
|
||||||
w.webContents.send('getcount')
|
w.webContents.send('getcount')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('will-download event', function () {
|
describe('will-download event', () => {
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
if (w != null) w.destroy()
|
if (w != null) w.destroy()
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
|
@ -268,10 +241,10 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can cancel default download behavior', function (done) {
|
it('can cancel default download behavior', (done) => {
|
||||||
const mockFile = new Buffer(1024)
|
const mockFile = new Buffer(1024)
|
||||||
const contentDisposition = 'inline; filename="mockFile.txt"'
|
const contentDisposition = 'inline; filename="mockFile.txt"'
|
||||||
const downloadServer = http.createServer(function (req, res) {
|
const downloadServer = http.createServer((req, res) => {
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Length': mockFile.length,
|
'Content-Length': mockFile.length,
|
||||||
'Content-Type': 'application/plain',
|
'Content-Type': 'application/plain',
|
||||||
|
@ -281,13 +254,13 @@ describe('session module', function () {
|
||||||
downloadServer.close()
|
downloadServer.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
downloadServer.listen(0, '127.0.0.1', function () {
|
downloadServer.listen(0, '127.0.0.1', () => {
|
||||||
const port = downloadServer.address().port
|
const port = downloadServer.address().port
|
||||||
const url = 'http://127.0.0.1:' + port + '/'
|
const url = `http://127.0.0.1:${port}/`
|
||||||
|
|
||||||
ipcRenderer.sendSync('set-download-option', false, true)
|
ipcRenderer.sendSync('set-download-option', false, true)
|
||||||
w.loadURL(url)
|
w.loadURL(url)
|
||||||
ipcRenderer.once('download-error', function (event, downloadUrl, filename, error) {
|
ipcRenderer.once('download-error', (event, downloadUrl, filename, error) => {
|
||||||
assert.equal(downloadUrl, url)
|
assert.equal(downloadUrl, url)
|
||||||
assert.equal(filename, 'mockFile.txt')
|
assert.equal(filename, 'mockFile.txt')
|
||||||
assert.equal(error, 'Object has been destroyed')
|
assert.equal(error, 'Object has been destroyed')
|
||||||
|
@ -297,14 +270,12 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('DownloadItem', function () {
|
describe('DownloadItem', () => {
|
||||||
var mockPDF = new Buffer(1024 * 1024 * 5)
|
const mockPDF = new Buffer(1024 * 1024 * 5)
|
||||||
var contentDisposition = 'inline; filename="mock.pdf"'
|
let contentDisposition = 'inline; filename="mock.pdf"'
|
||||||
var downloadFilePath = path.join(fixtures, 'mock.pdf')
|
const downloadFilePath = path.join(fixtures, 'mock.pdf')
|
||||||
var downloadServer = http.createServer(function (req, res) {
|
const downloadServer = http.createServer((req, res) => {
|
||||||
if (req.url === '/?testFilename') {
|
if (req.url === '/?testFilename') contentDisposition = 'inline'
|
||||||
contentDisposition = 'inline'
|
|
||||||
}
|
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Length': mockPDF.length,
|
'Content-Length': mockPDF.length,
|
||||||
'Content-Type': 'application/pdf',
|
'Content-Type': 'application/pdf',
|
||||||
|
@ -313,13 +284,13 @@ describe('session module', function () {
|
||||||
res.end(mockPDF)
|
res.end(mockPDF)
|
||||||
downloadServer.close()
|
downloadServer.close()
|
||||||
})
|
})
|
||||||
var assertDownload = function (event, state, url, mimeType,
|
const assertDownload = (event, state, url, mimeType,
|
||||||
receivedBytes, totalBytes, disposition,
|
receivedBytes, totalBytes, disposition,
|
||||||
filename, port, savePath) {
|
filename, port, savePath) => {
|
||||||
assert.equal(state, 'completed')
|
assert.equal(state, 'completed')
|
||||||
assert.equal(filename, 'mock.pdf')
|
assert.equal(filename, 'mock.pdf')
|
||||||
assert.equal(savePath, path.join(__dirname, 'fixtures', 'mock.pdf'))
|
assert.equal(savePath, path.join(__dirname, 'fixtures', 'mock.pdf'))
|
||||||
assert.equal(url, 'http://127.0.0.1:' + port + '/')
|
assert.equal(url, `http://127.0.0.1:${port}/`)
|
||||||
assert.equal(mimeType, 'application/pdf')
|
assert.equal(mimeType, 'application/pdf')
|
||||||
assert.equal(receivedBytes, mockPDF.length)
|
assert.equal(receivedBytes, mockPDF.length)
|
||||||
assert.equal(totalBytes, mockPDF.length)
|
assert.equal(totalBytes, mockPDF.length)
|
||||||
|
@ -328,15 +299,15 @@ describe('session module', function () {
|
||||||
fs.unlinkSync(downloadFilePath)
|
fs.unlinkSync(downloadFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can download using WebContents.downloadURL', function (done) {
|
it('can download using WebContents.downloadURL', (done) => {
|
||||||
downloadServer.listen(0, '127.0.0.1', function () {
|
downloadServer.listen(0, '127.0.0.1', () => {
|
||||||
var port = downloadServer.address().port
|
const port = downloadServer.address().port
|
||||||
ipcRenderer.sendSync('set-download-option', false, false)
|
ipcRenderer.sendSync('set-download-option', false, false)
|
||||||
w.webContents.downloadURL(url + ':' + port)
|
w.webContents.downloadURL(`${url}:${port}`)
|
||||||
ipcRenderer.once('download-done', function (event, state, url,
|
ipcRenderer.once('download-done', (event, state, url,
|
||||||
mimeType, receivedBytes,
|
mimeType, receivedBytes,
|
||||||
totalBytes, disposition,
|
totalBytes, disposition,
|
||||||
filename, savePath) {
|
filename, savePath) => {
|
||||||
assertDownload(event, state, url, mimeType, receivedBytes,
|
assertDownload(event, state, url, mimeType, receivedBytes,
|
||||||
totalBytes, disposition, filename, port, savePath)
|
totalBytes, disposition, filename, port, savePath)
|
||||||
done()
|
done()
|
||||||
|
@ -344,19 +315,19 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can download using WebView.downloadURL', function (done) {
|
it('can download using WebView.downloadURL', (done) => {
|
||||||
downloadServer.listen(0, '127.0.0.1', function () {
|
downloadServer.listen(0, '127.0.0.1', () => {
|
||||||
var port = downloadServer.address().port
|
const port = downloadServer.address().port
|
||||||
ipcRenderer.sendSync('set-download-option', false, false)
|
ipcRenderer.sendSync('set-download-option', false, false)
|
||||||
webview = new WebView()
|
webview = new WebView()
|
||||||
webview.src = 'file://' + fixtures + '/api/blank.html'
|
webview.src = `file://${fixtures}/api/blank.html`
|
||||||
webview.addEventListener('did-finish-load', function () {
|
webview.addEventListener('did-finish-load', () => {
|
||||||
webview.downloadURL(url + ':' + port + '/')
|
webview.downloadURL(`${url}:${port}/`)
|
||||||
})
|
})
|
||||||
ipcRenderer.once('download-done', function (event, state, url,
|
ipcRenderer.once('download-done', (event, state, url,
|
||||||
mimeType, receivedBytes,
|
mimeType, receivedBytes,
|
||||||
totalBytes, disposition,
|
totalBytes, disposition,
|
||||||
filename, savePath) {
|
filename, savePath) => {
|
||||||
assertDownload(event, state, url, mimeType, receivedBytes,
|
assertDownload(event, state, url, mimeType, receivedBytes,
|
||||||
totalBytes, disposition, filename, port, savePath)
|
totalBytes, disposition, filename, port, savePath)
|
||||||
document.body.removeChild(webview)
|
document.body.removeChild(webview)
|
||||||
|
@ -366,15 +337,15 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can cancel download', function (done) {
|
it('can cancel download', (done) => {
|
||||||
downloadServer.listen(0, '127.0.0.1', function () {
|
downloadServer.listen(0, '127.0.0.1', () => {
|
||||||
var port = downloadServer.address().port
|
const port = downloadServer.address().port
|
||||||
ipcRenderer.sendSync('set-download-option', true, false)
|
ipcRenderer.sendSync('set-download-option', true, false)
|
||||||
w.webContents.downloadURL(url + ':' + port + '/')
|
w.webContents.downloadURL(`${url}:${port}/`)
|
||||||
ipcRenderer.once('download-done', function (event, state, url,
|
ipcRenderer.once('download-done', (event, state, url,
|
||||||
mimeType, receivedBytes,
|
mimeType, receivedBytes,
|
||||||
totalBytes, disposition,
|
totalBytes, disposition,
|
||||||
filename) {
|
filename) => {
|
||||||
assert.equal(state, 'cancelled')
|
assert.equal(state, 'cancelled')
|
||||||
assert.equal(filename, 'mock.pdf')
|
assert.equal(filename, 'mock.pdf')
|
||||||
assert.equal(mimeType, 'application/pdf')
|
assert.equal(mimeType, 'application/pdf')
|
||||||
|
@ -386,18 +357,17 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can generate a default filename', function (done) {
|
it('can generate a default filename', (done) => {
|
||||||
// Somehow this test always fail on appveyor.
|
|
||||||
if (process.env.APPVEYOR === 'True') return done()
|
if (process.env.APPVEYOR === 'True') return done()
|
||||||
|
|
||||||
downloadServer.listen(0, '127.0.0.1', function () {
|
downloadServer.listen(0, '127.0.0.1', () => {
|
||||||
var port = downloadServer.address().port
|
const port = downloadServer.address().port
|
||||||
ipcRenderer.sendSync('set-download-option', true, false)
|
ipcRenderer.sendSync('set-download-option', true, false)
|
||||||
w.webContents.downloadURL(url + ':' + port + '/?testFilename')
|
w.webContents.downloadURL(`${url}:${port}/?testFilename`)
|
||||||
ipcRenderer.once('download-done', function (event, state, url,
|
ipcRenderer.once('download-done', (event, state, url,
|
||||||
mimeType, receivedBytes,
|
mimeType, receivedBytes,
|
||||||
totalBytes, disposition,
|
totalBytes, disposition,
|
||||||
filename) {
|
filename) => {
|
||||||
assert.equal(state, 'cancelled')
|
assert.equal(state, 'cancelled')
|
||||||
assert.equal(filename, 'download.pdf')
|
assert.equal(filename, 'download.pdf')
|
||||||
assert.equal(mimeType, 'application/pdf')
|
assert.equal(mimeType, 'application/pdf')
|
||||||
|
@ -409,28 +379,28 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when a save path is specified and the URL is unavailable', function () {
|
describe('when a save path is specified and the URL is unavailable', () => {
|
||||||
it('does not display a save dialog and reports the done state as interrupted', function (done) {
|
it('does not display a save dialog and reports the done state as interrupted', (done) => {
|
||||||
ipcRenderer.sendSync('set-download-option', false, false)
|
ipcRenderer.sendSync('set-download-option', false, false)
|
||||||
ipcRenderer.once('download-done', (event, state) => {
|
ipcRenderer.once('download-done', (event, state) => {
|
||||||
assert.equal(state, 'interrupted')
|
assert.equal(state, 'interrupted')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.webContents.downloadURL('file://' + path.join(__dirname, 'does-not-exist.txt'))
|
w.webContents.downloadURL(`file://${path.join(__dirname, 'does-not-exist.txt')}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.protocol', function () {
|
describe('ses.protocol', () => {
|
||||||
const partitionName = 'temp'
|
const partitionName = 'temp'
|
||||||
const protocolName = 'sp'
|
const protocolName = 'sp'
|
||||||
const partitionProtocol = session.fromPartition(partitionName).protocol
|
const partitionProtocol = session.fromPartition(partitionName).protocol
|
||||||
const protocol = session.defaultSession.protocol
|
const protocol = session.defaultSession.protocol
|
||||||
const handler = function (ignoredError, callback) {
|
const handler = (ignoredError, callback) => {
|
||||||
callback({data: 'test', mimeType: 'text/html'})
|
callback({data: 'test', mimeType: 'text/html'})
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach((done) => {
|
||||||
if (w != null) w.destroy()
|
if (w != null) w.destroy()
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
|
@ -438,53 +408,49 @@ describe('session module', function () {
|
||||||
partition: partitionName
|
partition: partitionName
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
partitionProtocol.registerStringProtocol(protocolName, handler, function (error) {
|
partitionProtocol.registerStringProtocol(protocolName, handler, (error) => {
|
||||||
done(error != null ? error : undefined)
|
done(error != null ? error : undefined)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function (done) {
|
afterEach((done) => {
|
||||||
partitionProtocol.unregisterProtocol(protocolName, () => done())
|
partitionProtocol.unregisterProtocol(protocolName, () => done())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not affect defaultSession', function (done) {
|
it('does not affect defaultSession', (done) => {
|
||||||
protocol.isProtocolHandled(protocolName, function (result) {
|
protocol.isProtocolHandled(protocolName, (result) => {
|
||||||
assert.equal(result, false)
|
assert.equal(result, false)
|
||||||
partitionProtocol.isProtocolHandled(protocolName, function (result) {
|
partitionProtocol.isProtocolHandled(protocolName, (result) => {
|
||||||
assert.equal(result, true)
|
assert.equal(result, true)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
xit('handles requests from partition', function (done) {
|
xit('handles requests from partition', (done) => {
|
||||||
w.webContents.on('did-finish-load', function () {
|
w.webContents.on('did-finish-load', () => done())
|
||||||
done()
|
|
||||||
})
|
|
||||||
w.loadURL(`${protocolName}://fake-host`)
|
w.loadURL(`${protocolName}://fake-host`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.setProxy(options, callback)', function () {
|
describe('ses.setProxy(options, callback)', () => {
|
||||||
it('allows configuring proxy settings', function (done) {
|
it('allows configuring proxy settings', (done) => {
|
||||||
const config = {
|
const config = {proxyRules: 'http=myproxy:80'}
|
||||||
proxyRules: 'http=myproxy:80'
|
session.defaultSession.setProxy(config, () => {
|
||||||
}
|
session.defaultSession.resolveProxy('http://localhost', (proxy) => {
|
||||||
session.defaultSession.setProxy(config, function () {
|
|
||||||
session.defaultSession.resolveProxy('http://localhost', function (proxy) {
|
|
||||||
assert.equal(proxy, 'PROXY myproxy:80')
|
assert.equal(proxy, 'PROXY myproxy:80')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('allows bypassing proxy settings', function (done) {
|
it('allows bypassing proxy settings', (done) => {
|
||||||
const config = {
|
const config = {
|
||||||
proxyRules: 'http=myproxy:80',
|
proxyRules: 'http=myproxy:80',
|
||||||
proxyBypassRules: '<local>'
|
proxyBypassRules: '<local>'
|
||||||
}
|
}
|
||||||
session.defaultSession.setProxy(config, function () {
|
session.defaultSession.setProxy(config, () => {
|
||||||
session.defaultSession.resolveProxy('http://localhost', function (proxy) {
|
session.defaultSession.resolveProxy('http://localhost', (proxy) => {
|
||||||
assert.equal(proxy, 'DIRECT')
|
assert.equal(proxy, 'DIRECT')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -492,17 +458,17 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.getBlobData(identifier, callback)', function () {
|
describe('ses.getBlobData(identifier, callback)', () => {
|
||||||
it('returns blob data for uuid', function (done) {
|
it('returns blob data for uuid', (done) => {
|
||||||
const scheme = 'temp'
|
const scheme = 'temp'
|
||||||
const protocol = session.defaultSession.protocol
|
const protocol = session.defaultSession.protocol
|
||||||
const url = scheme + '://host'
|
const url = `${scheme}://host`
|
||||||
before(function () {
|
before(() => {
|
||||||
if (w != null) w.destroy()
|
if (w != null) w.destroy()
|
||||||
w = new BrowserWindow({show: false})
|
w = new BrowserWindow({show: false})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function (done) {
|
after((done) => {
|
||||||
protocol.unregisterProtocol(scheme, () => {
|
protocol.unregisterProtocol(scheme, () => {
|
||||||
closeWindow(w).then(() => {
|
closeWindow(w).then(() => {
|
||||||
w = null
|
w = null
|
||||||
|
@ -525,30 +491,30 @@ describe('session module', function () {
|
||||||
</script>
|
</script>
|
||||||
</html>`
|
</html>`
|
||||||
|
|
||||||
protocol.registerStringProtocol(scheme, function (request, callback) {
|
protocol.registerStringProtocol(scheme, (request, callback) => {
|
||||||
if (request.method === 'GET') {
|
if (request.method === 'GET') {
|
||||||
callback({data: content, mimeType: 'text/html'})
|
callback({data: content, mimeType: 'text/html'})
|
||||||
} else if (request.method === 'POST') {
|
} else if (request.method === 'POST') {
|
||||||
let uuid = request.uploadData[1].blobUUID
|
let uuid = request.uploadData[1].blobUUID
|
||||||
assert(uuid)
|
assert(uuid)
|
||||||
session.defaultSession.getBlobData(uuid, function (result) {
|
session.defaultSession.getBlobData(uuid, (result) => {
|
||||||
assert.equal(result.toString(), postData)
|
assert.equal(result.toString(), postData)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, function (error) {
|
}, (error) => {
|
||||||
if (error) return done(error)
|
if (error) return done(error)
|
||||||
w.loadURL(url)
|
w.loadURL(url)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.setCertificateVerifyProc(callback)', function () {
|
describe('ses.setCertificateVerifyProc(callback)', () => {
|
||||||
var server = null
|
let server = null
|
||||||
|
|
||||||
beforeEach(function (done) {
|
beforeEach((done) => {
|
||||||
var certPath = path.join(__dirname, 'fixtures', 'certificates')
|
const certPath = path.join(__dirname, 'fixtures', 'certificates')
|
||||||
var options = {
|
const options = {
|
||||||
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
key: fs.readFileSync(path.join(certPath, 'server.key')),
|
||||||
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
cert: fs.readFileSync(path.join(certPath, 'server.pem')),
|
||||||
ca: [
|
ca: [
|
||||||
|
@ -559,54 +525,54 @@ describe('session module', function () {
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
}
|
}
|
||||||
|
|
||||||
server = https.createServer(options, function (req, res) {
|
server = https.createServer(options, (req, res) => {
|
||||||
res.writeHead(200)
|
res.writeHead(200)
|
||||||
res.end('<title>hello</title>')
|
res.end('<title>hello</title>')
|
||||||
})
|
})
|
||||||
server.listen(0, '127.0.0.1', done)
|
server.listen(0, '127.0.0.1', done)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
session.defaultSession.setCertificateVerifyProc(null)
|
session.defaultSession.setCertificateVerifyProc(null)
|
||||||
server.close()
|
server.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('accepts the request when the callback is called with 0', function (done) {
|
it('accepts the request when the callback is called with 0', (done) => {
|
||||||
session.defaultSession.setCertificateVerifyProc(function ({hostname, certificate, verificationResult, errorCode}, callback) {
|
session.defaultSession.setCertificateVerifyProc(({hostname, certificate, verificationResult, errorCode}, callback) => {
|
||||||
assert(['net::ERR_CERT_AUTHORITY_INVALID', 'net::ERR_CERT_COMMON_NAME_INVALID'].includes(verificationResult), verificationResult)
|
assert(['net::ERR_CERT_AUTHORITY_INVALID', 'net::ERR_CERT_COMMON_NAME_INVALID'].includes(verificationResult), verificationResult)
|
||||||
assert([-202, -200].includes(errorCode), errorCode)
|
assert([-202, -200].includes(errorCode), errorCode)
|
||||||
callback(0)
|
callback(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
w.webContents.once('did-finish-load', function () {
|
w.webContents.once('did-finish-load', () => {
|
||||||
assert.equal(w.webContents.getTitle(), 'hello')
|
assert.equal(w.webContents.getTitle(), 'hello')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.loadURL(`https://127.0.0.1:${server.address().port}`)
|
w.loadURL(`https://127.0.0.1:${server.address().port}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('deprecated function signature', function () {
|
describe('deprecated function signature', () => {
|
||||||
it('supports accepting the request', function (done) {
|
it('supports accepting the request', (done) => {
|
||||||
session.defaultSession.setCertificateVerifyProc(function (hostname, certificate, callback) {
|
session.defaultSession.setCertificateVerifyProc((hostname, certificate, callback) => {
|
||||||
assert.equal(hostname, '127.0.0.1')
|
assert.equal(hostname, '127.0.0.1')
|
||||||
callback(true)
|
callback(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
w.webContents.once('did-finish-load', function () {
|
w.webContents.once('did-finish-load', () => {
|
||||||
assert.equal(w.webContents.getTitle(), 'hello')
|
assert.equal(w.webContents.getTitle(), 'hello')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.loadURL(`https://127.0.0.1:${server.address().port}`)
|
w.loadURL(`https://127.0.0.1:${server.address().port}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports rejecting the request', function (done) {
|
it('supports rejecting the request', (done) => {
|
||||||
session.defaultSession.setCertificateVerifyProc(function (hostname, certificate, callback) {
|
session.defaultSession.setCertificateVerifyProc((hostname, certificate, callback) => {
|
||||||
assert.equal(hostname, '127.0.0.1')
|
assert.equal(hostname, '127.0.0.1')
|
||||||
callback(false)
|
callback(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
var url = `https://127.0.0.1:${server.address().port}`
|
const url = `https://127.0.0.1:${server.address().port}`
|
||||||
w.webContents.once('did-finish-load', function () {
|
w.webContents.once('did-finish-load', () => {
|
||||||
assert.equal(w.webContents.getTitle(), url)
|
assert.equal(w.webContents.getTitle(), url)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -614,8 +580,8 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('rejects the request when the callback is called with -2', function (done) {
|
it('rejects the request when the callback is called with -2', (done) => {
|
||||||
session.defaultSession.setCertificateVerifyProc(function ({hostname, certificate, verificationResult}, callback) {
|
session.defaultSession.setCertificateVerifyProc(({hostname, certificate, verificationResult}, callback) => {
|
||||||
assert.equal(hostname, '127.0.0.1')
|
assert.equal(hostname, '127.0.0.1')
|
||||||
assert.equal(certificate.issuerName, 'Intermediate CA')
|
assert.equal(certificate.issuerName, 'Intermediate CA')
|
||||||
assert.equal(certificate.subjectName, 'localhost')
|
assert.equal(certificate.subjectName, 'localhost')
|
||||||
|
@ -630,8 +596,8 @@ describe('session module', function () {
|
||||||
callback(-2)
|
callback(-2)
|
||||||
})
|
})
|
||||||
|
|
||||||
var url = `https://127.0.0.1:${server.address().port}`
|
const url = `https://127.0.0.1:${server.address().port}`
|
||||||
w.webContents.once('did-finish-load', function () {
|
w.webContents.once('did-finish-load', () => {
|
||||||
assert.equal(w.webContents.getTitle(), url)
|
assert.equal(w.webContents.getTitle(), url)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -639,8 +605,8 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.createInterruptedDownload(options)', function () {
|
describe('ses.createInterruptedDownload(options)', () => {
|
||||||
it('can create an interrupted download item', function (done) {
|
it('can create an interrupted download item', (done) => {
|
||||||
ipcRenderer.sendSync('set-download-option', true, false)
|
ipcRenderer.sendSync('set-download-option', true, false)
|
||||||
const filePath = path.join(__dirname, 'fixtures', 'mock.pdf')
|
const filePath = path.join(__dirname, 'fixtures', 'mock.pdf')
|
||||||
const options = {
|
const options = {
|
||||||
|
@ -651,10 +617,10 @@ describe('session module', function () {
|
||||||
length: 5242880
|
length: 5242880
|
||||||
}
|
}
|
||||||
w.webContents.session.createInterruptedDownload(options)
|
w.webContents.session.createInterruptedDownload(options)
|
||||||
ipcRenderer.once('download-created', function (event, state, urlChain,
|
ipcRenderer.once('download-created', (event, state, urlChain,
|
||||||
mimeType, receivedBytes,
|
mimeType, receivedBytes,
|
||||||
totalBytes, filename,
|
totalBytes, filename,
|
||||||
savePath) {
|
savePath) => {
|
||||||
assert.equal(state, 'interrupted')
|
assert.equal(state, 'interrupted')
|
||||||
assert.deepEqual(urlChain, ['http://127.0.0.1/'])
|
assert.deepEqual(urlChain, ['http://127.0.0.1/'])
|
||||||
assert.equal(mimeType, 'application/pdf')
|
assert.equal(mimeType, 'application/pdf')
|
||||||
|
@ -665,26 +631,22 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can be resumed', function (done) {
|
it('can be resumed', (done) => {
|
||||||
const fixtures = path.join(__dirname, 'fixtures')
|
const fixtures = path.join(__dirname, 'fixtures')
|
||||||
const downloadFilePath = path.join(fixtures, 'logo.png')
|
const downloadFilePath = path.join(fixtures, 'logo.png')
|
||||||
const rangeServer = http.createServer(function (req, res) {
|
const rangeServer = http.createServer((req, res) => {
|
||||||
let options = {
|
let options = { root: fixtures }
|
||||||
root: fixtures
|
|
||||||
}
|
|
||||||
send(req, req.url, options)
|
send(req, req.url, options)
|
||||||
.on('error', function (error) {
|
.on('error', (error) => { done(error) }).pipe(res)
|
||||||
done(error)
|
|
||||||
}).pipe(res)
|
|
||||||
})
|
})
|
||||||
ipcRenderer.sendSync('set-download-option', true, false, downloadFilePath)
|
ipcRenderer.sendSync('set-download-option', true, false, downloadFilePath)
|
||||||
rangeServer.listen(0, '127.0.0.1', function () {
|
rangeServer.listen(0, '127.0.0.1', () => {
|
||||||
const port = rangeServer.address().port
|
const port = rangeServer.address().port
|
||||||
const downloadUrl = `http://127.0.0.1:${port}/assets/logo.png`
|
const downloadUrl = `http://127.0.0.1:${port}/assets/logo.png`
|
||||||
const callback = function (event, state, url, mimeType,
|
const callback = (event, state, url, mimeType,
|
||||||
receivedBytes, totalBytes, disposition,
|
receivedBytes, totalBytes, disposition,
|
||||||
filename, savePath, urlChain,
|
filename, savePath, urlChain,
|
||||||
lastModifiedTime, eTag) {
|
lastModifiedTime, eTag) => {
|
||||||
if (state === 'cancelled') {
|
if (state === 'cancelled') {
|
||||||
const options = {
|
const options = {
|
||||||
path: savePath,
|
path: savePath,
|
||||||
|
@ -718,11 +680,11 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ses.clearAuthCache(options[, callback])', function () {
|
describe('ses.clearAuthCache(options[, callback])', () => {
|
||||||
it('can clear http auth info from cache', function (done) {
|
it('can clear http auth info from cache', (done) => {
|
||||||
const ses = session.fromPartition('auth-cache')
|
const ses = session.fromPartition('auth-cache')
|
||||||
const server = http.createServer(function (req, res) {
|
const server = http.createServer((req, res) => {
|
||||||
var credentials = auth(req)
|
const credentials = auth(req)
|
||||||
if (!credentials || credentials.name !== 'test' || credentials.pass !== 'test') {
|
if (!credentials || credentials.name !== 'test' || credentials.pass !== 'test') {
|
||||||
res.statusCode = 401
|
res.statusCode = 401
|
||||||
res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"')
|
res.setHeader('WWW-Authenticate', 'Basic realm="Restricted"')
|
||||||
|
@ -731,7 +693,7 @@ describe('session module', function () {
|
||||||
res.end('authenticated')
|
res.end('authenticated')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
server.listen(0, '127.0.0.1', function () {
|
server.listen(0, '127.0.0.1', () => {
|
||||||
const port = server.address().port
|
const port = server.address().port
|
||||||
function issueLoginRequest (attempt = 1) {
|
function issueLoginRequest (attempt = 1) {
|
||||||
if (attempt > 2) {
|
if (attempt > 2) {
|
||||||
|
@ -742,27 +704,25 @@ describe('session module', function () {
|
||||||
url: `http://127.0.0.1:${port}`,
|
url: `http://127.0.0.1:${port}`,
|
||||||
session: ses
|
session: ses
|
||||||
})
|
})
|
||||||
request.on('login', function (info, callback) {
|
request.on('login', (info, callback) => {
|
||||||
attempt++
|
attempt += 1
|
||||||
assert.equal(info.scheme, 'basic')
|
assert.equal(info.scheme, 'basic')
|
||||||
assert.equal(info.realm, 'Restricted')
|
assert.equal(info.realm, 'Restricted')
|
||||||
callback('test', 'test')
|
callback('test', 'test')
|
||||||
})
|
})
|
||||||
request.on('response', function (response) {
|
request.on('response', (response) => {
|
||||||
let data = ''
|
let data = ''
|
||||||
response.pause()
|
response.pause()
|
||||||
response.on('data', function (chunk) {
|
response.on('data', (chunk) => {
|
||||||
data += chunk
|
data += chunk
|
||||||
})
|
})
|
||||||
response.on('end', function () {
|
response.on('end', () => {
|
||||||
assert.equal(data, 'authenticated')
|
assert.equal(data, 'authenticated')
|
||||||
ses.clearAuthCache({type: 'password'}, function () {
|
ses.clearAuthCache({type: 'password'}, () => {
|
||||||
issueLoginRequest(attempt)
|
issueLoginRequest(attempt)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
response.on('error', function (error) {
|
response.on('error', (error) => { done(error) })
|
||||||
done(error)
|
|
||||||
})
|
|
||||||
response.resume()
|
response.resume()
|
||||||
})
|
})
|
||||||
// Internal api to bypass cache for testing.
|
// Internal api to bypass cache for testing.
|
||||||
|
@ -782,12 +742,12 @@ describe('session module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
webview = new WebView()
|
webview = new WebView()
|
||||||
webview.addEventListener('ipc-message', function (e) {
|
webview.addEventListener('ipc-message', (e) => {
|
||||||
assert.equal(e.channel, 'message')
|
assert.equal(e.channel, 'message')
|
||||||
assert.deepEqual(e.args, ['SecurityError'])
|
assert.deepEqual(e.args, ['SecurityError'])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
webview.src = 'file://' + fixtures + '/pages/permissions/midi-sysex.html'
|
webview.src = `file://${fixtures}/pages/permissions/midi-sysex.html`
|
||||||
webview.partition = 'permissionTest'
|
webview.partition = 'permissionTest'
|
||||||
webview.setAttribute('nodeintegration', 'on')
|
webview.setAttribute('nodeintegration', 'on')
|
||||||
document.body.appendChild(webview)
|
document.body.appendChild(webview)
|
||||||
|
|
|
@ -10,11 +10,11 @@ const {BrowserWindow, webContents, ipcMain, session} = remote
|
||||||
|
|
||||||
const isCi = remote.getGlobal('isCi')
|
const isCi = remote.getGlobal('isCi')
|
||||||
|
|
||||||
describe('webContents module', function () {
|
describe('webContents module', () => {
|
||||||
const fixtures = path.resolve(__dirname, 'fixtures')
|
const fixtures = path.resolve(__dirname, 'fixtures')
|
||||||
let w
|
let w
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(() => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
width: 400,
|
width: 400,
|
||||||
|
@ -25,14 +25,12 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||||
return closeWindow(w).then(function () { w = null })
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getAllWebContents() API', function () {
|
describe('getAllWebContents() API', () => {
|
||||||
it('returns an array of web contents', function (done) {
|
it('returns an array of web contents', (done) => {
|
||||||
w.webContents.on('devtools-opened', function () {
|
w.webContents.on('devtools-opened', () => {
|
||||||
const all = webContents.getAllWebContents().sort(function (a, b) {
|
const all = webContents.getAllWebContents().sort((a, b) => {
|
||||||
return a.getId() - b.getId()
|
return a.getId() - b.getId()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -44,24 +42,24 @@ describe('webContents module', function () {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|
||||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'webview-zoom-factor.html'))
|
w.loadURL(`file://${path.join(fixtures, 'pages', 'webview-zoom-factor.html')}`)
|
||||||
w.webContents.openDevTools()
|
w.webContents.openDevTools()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getFocusedWebContents() API', function () {
|
describe('getFocusedWebContents() API', () => {
|
||||||
it('returns the focused web contents', function (done) {
|
it('returns the focused web contents', (done) => {
|
||||||
if (isCi) return done()
|
if (isCi) return done()
|
||||||
|
|
||||||
const specWebContents = remote.getCurrentWebContents()
|
const specWebContents = remote.getCurrentWebContents()
|
||||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||||
|
|
||||||
specWebContents.once('devtools-opened', function () {
|
specWebContents.once('devtools-opened', () => {
|
||||||
assert.equal(specWebContents.devToolsWebContents.getId(), webContents.getFocusedWebContents().getId())
|
assert.equal(specWebContents.devToolsWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||||
specWebContents.closeDevTools()
|
specWebContents.closeDevTools()
|
||||||
})
|
})
|
||||||
|
|
||||||
specWebContents.once('devtools-closed', function () {
|
specWebContents.once('devtools-closed', () => {
|
||||||
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
assert.equal(specWebContents.getId(), webContents.getFocusedWebContents().getId())
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -69,18 +67,18 @@ describe('webContents module', function () {
|
||||||
specWebContents.openDevTools()
|
specWebContents.openDevTools()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash when called on a detached dev tools window', function (done) {
|
it('does not crash when called on a detached dev tools window', (done) => {
|
||||||
const specWebContents = w.webContents
|
const specWebContents = w.webContents
|
||||||
|
|
||||||
specWebContents.once('devtools-opened', function () {
|
specWebContents.once('devtools-opened', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
webContents.getFocusedWebContents()
|
webContents.getFocusedWebContents()
|
||||||
})
|
})
|
||||||
specWebContents.closeDevTools()
|
specWebContents.closeDevTools()
|
||||||
})
|
})
|
||||||
|
|
||||||
specWebContents.once('devtools-closed', function () {
|
specWebContents.once('devtools-closed', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
webContents.getFocusedWebContents()
|
webContents.getFocusedWebContents()
|
||||||
})
|
})
|
||||||
done()
|
done()
|
||||||
|
@ -91,9 +89,9 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('isFocused() API', function () {
|
describe('isFocused() API', () => {
|
||||||
it('returns false when the window is hidden', function () {
|
it('returns false when the window is hidden', () => {
|
||||||
BrowserWindow.getAllWindows().forEach(function (window) {
|
BrowserWindow.getAllWindows().forEach((window) => {
|
||||||
assert.equal(!window.isVisible() && window.webContents.isFocused(), false)
|
assert.equal(!window.isVisible() && window.webContents.isFocused(), false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -101,7 +99,7 @@ describe('webContents module', function () {
|
||||||
|
|
||||||
describe('before-input-event event', () => {
|
describe('before-input-event event', () => {
|
||||||
it('can prevent document keyboard events', (done) => {
|
it('can prevent document keyboard events', (done) => {
|
||||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'key-events.html'))
|
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)
|
||||||
w.webContents.once('did-finish-load', () => {
|
w.webContents.once('did-finish-load', () => {
|
||||||
ipcMain.once('keydown', (event, key) => {
|
ipcMain.once('keydown', (event, key) => {
|
||||||
assert.equal(key, 'b')
|
assert.equal(key, 'b')
|
||||||
|
@ -115,7 +113,7 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has the correct properties', (done) => {
|
it('has the correct properties', (done) => {
|
||||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
|
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'base-page.html')}`)
|
||||||
w.webContents.once('did-finish-load', () => {
|
w.webContents.once('did-finish-load', () => {
|
||||||
const testBeforeInput = (opts) => {
|
const testBeforeInput = (opts) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -199,16 +197,14 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('sendInputEvent(event)', function () {
|
describe('sendInputEvent(event)', () => {
|
||||||
beforeEach(function (done) {
|
beforeEach((done) => {
|
||||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'key-events.html'))
|
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'key-events.html')}`)
|
||||||
w.webContents.once('did-finish-load', function () {
|
w.webContents.once('did-finish-load', () => done())
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send keydown events', function (done) {
|
it('can send keydown events', (done) => {
|
||||||
ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||||
assert.equal(key, 'a')
|
assert.equal(key, 'a')
|
||||||
assert.equal(code, 'KeyA')
|
assert.equal(code, 'KeyA')
|
||||||
assert.equal(keyCode, 65)
|
assert.equal(keyCode, 65)
|
||||||
|
@ -220,8 +216,8 @@ describe('webContents module', function () {
|
||||||
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'A'})
|
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'A'})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send keydown events with modifiers', function (done) {
|
it('can send keydown events with modifiers', (done) => {
|
||||||
ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||||
assert.equal(key, 'Z')
|
assert.equal(key, 'Z')
|
||||||
assert.equal(code, 'KeyZ')
|
assert.equal(code, 'KeyZ')
|
||||||
assert.equal(keyCode, 90)
|
assert.equal(keyCode, 90)
|
||||||
|
@ -233,8 +229,8 @@ describe('webContents module', function () {
|
||||||
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Z', modifiers: ['shift', 'ctrl']})
|
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Z', modifiers: ['shift', 'ctrl']})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send keydown events with special keys', function (done) {
|
it('can send keydown events with special keys', (done) => {
|
||||||
ipcMain.once('keydown', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
ipcMain.once('keydown', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||||
assert.equal(key, 'Tab')
|
assert.equal(key, 'Tab')
|
||||||
assert.equal(code, 'Tab')
|
assert.equal(code, 'Tab')
|
||||||
assert.equal(keyCode, 9)
|
assert.equal(keyCode, 9)
|
||||||
|
@ -246,8 +242,8 @@ describe('webContents module', function () {
|
||||||
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Tab', modifiers: ['alt']})
|
w.webContents.sendInputEvent({type: 'keyDown', keyCode: 'Tab', modifiers: ['alt']})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send char events', function (done) {
|
it('can send char events', (done) => {
|
||||||
ipcMain.once('keypress', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
ipcMain.once('keypress', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||||
assert.equal(key, 'a')
|
assert.equal(key, 'a')
|
||||||
assert.equal(code, 'KeyA')
|
assert.equal(code, 'KeyA')
|
||||||
assert.equal(keyCode, 65)
|
assert.equal(keyCode, 65)
|
||||||
|
@ -260,8 +256,8 @@ describe('webContents module', function () {
|
||||||
w.webContents.sendInputEvent({type: 'char', keyCode: 'A'})
|
w.webContents.sendInputEvent({type: 'char', keyCode: 'A'})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can send char events with modifiers', function (done) {
|
it('can send char events with modifiers', (done) => {
|
||||||
ipcMain.once('keypress', function (event, key, code, keyCode, shiftKey, ctrlKey, altKey) {
|
ipcMain.once('keypress', (event, key, code, keyCode, shiftKey, ctrlKey, altKey) => {
|
||||||
assert.equal(key, 'Z')
|
assert.equal(key, 'Z')
|
||||||
assert.equal(code, 'KeyZ')
|
assert.equal(code, 'KeyZ')
|
||||||
assert.equal(keyCode, 90)
|
assert.equal(keyCode, 90)
|
||||||
|
@ -275,7 +271,7 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports inserting CSS', function (done) {
|
it('supports inserting CSS', (done) => {
|
||||||
w.loadURL('about:blank')
|
w.loadURL('about:blank')
|
||||||
w.webContents.insertCSS('body { background-repeat: round; }')
|
w.webContents.insertCSS('body { background-repeat: round; }')
|
||||||
w.webContents.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")', (result) => {
|
w.webContents.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")', (result) => {
|
||||||
|
@ -284,9 +280,9 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports inspecting an element in the devtools', function (done) {
|
it('supports inspecting an element in the devtools', (done) => {
|
||||||
w.loadURL('about:blank')
|
w.loadURL('about:blank')
|
||||||
w.webContents.once('devtools-opened', function () {
|
w.webContents.once('devtools-opened', () => {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.webContents.inspectElement(10, 10)
|
w.webContents.inspectElement(10, 10)
|
||||||
|
@ -310,22 +306,22 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('focus()', function () {
|
describe('focus()', () => {
|
||||||
describe('when the web contents is hidden', function () {
|
describe('when the web contents is hidden', () => {
|
||||||
it('does not blur the focused window', function (done) {
|
it('does not blur the focused window', (done) => {
|
||||||
ipcMain.once('answer', (event, parentFocused, childFocused) => {
|
ipcMain.once('answer', (event, parentFocused, childFocused) => {
|
||||||
assert.equal(parentFocused, true)
|
assert.equal(parentFocused, true)
|
||||||
assert.equal(childFocused, false)
|
assert.equal(childFocused, false)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.show()
|
w.show()
|
||||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html'))
|
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html')}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getOSProcessId()', function () {
|
describe('getOSProcessId()', () => {
|
||||||
it('returns a valid procress id', function (done) {
|
it('returns a valid procress id', (done) => {
|
||||||
assert.strictEqual(w.webContents.getOSProcessId(), 0)
|
assert.strictEqual(w.webContents.getOSProcessId(), 0)
|
||||||
|
|
||||||
w.webContents.once('did-finish-load', () => {
|
w.webContents.once('did-finish-load', () => {
|
||||||
|
@ -386,9 +382,7 @@ describe('webContents module', function () {
|
||||||
let finalNavigation = false
|
let finalNavigation = false
|
||||||
ipcMain.on('set-zoom', (e, host) => {
|
ipcMain.on('set-zoom', (e, host) => {
|
||||||
const zoomLevel = hostZoomMap[host]
|
const zoomLevel = hostZoomMap[host]
|
||||||
if (!finalNavigation) {
|
if (!finalNavigation) w.webContents.setZoomLevel(zoomLevel)
|
||||||
w.webContents.setZoomLevel(zoomLevel)
|
|
||||||
}
|
|
||||||
e.sender.send(`${host}-zoom-set`)
|
e.sender.send(`${host}-zoom-set`)
|
||||||
})
|
})
|
||||||
ipcMain.on('host1-zoom-level', (e, zoomLevel) => {
|
ipcMain.on('host1-zoom-level', (e, zoomLevel) => {
|
||||||
|
@ -467,12 +461,12 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can persist when it contains iframe', (done) => {
|
it('can persist when it contains iframe', (done) => {
|
||||||
const server = http.createServer(function (req, res) {
|
const server = http.createServer((req, res) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
res.end()
|
res.end()
|
||||||
}, 200)
|
}, 200)
|
||||||
})
|
})
|
||||||
server.listen(0, '127.0.0.1', function () {
|
server.listen(0, '127.0.0.1', () => {
|
||||||
const url = 'http://127.0.0.1:' + server.address().port
|
const url = 'http://127.0.0.1:' + server.address().port
|
||||||
const content = `<iframe src=${url}></iframe>`
|
const content = `<iframe src=${url}></iframe>`
|
||||||
w.webContents.on('did-frame-finish-load', (e, isMainFrame) => {
|
w.webContents.on('did-frame-finish-load', (e, isMainFrame) => {
|
||||||
|
@ -557,12 +551,12 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('will-prevent-unload event', function () {
|
describe('will-prevent-unload event', () => {
|
||||||
it('does not emit if beforeunload returns undefined', function (done) {
|
it('does not emit if beforeunload returns undefined', (done) => {
|
||||||
w.once('closed', function () {
|
w.once('closed', () => {
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
w.webContents.on('will-prevent-unload', function (e) {
|
w.webContents.on('will-prevent-unload', (e) => {
|
||||||
assert.fail('should not have fired')
|
assert.fail('should not have fired')
|
||||||
})
|
})
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
|
||||||
|
@ -575,15 +569,15 @@ describe('webContents module', function () {
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports calling preventDefault on will-prevent-unload events', function (done) {
|
it('supports calling preventDefault on will-prevent-unload events', (done) => {
|
||||||
ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id)
|
ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id)
|
||||||
w.once('closed', () => done())
|
w.once('closed', () => done())
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('setIgnoreMenuShortcuts(ignore)', function () {
|
describe('setIgnoreMenuShortcuts(ignore)', () => {
|
||||||
it('does not throw', function () {
|
it('does not throw', () => {
|
||||||
assert.equal(w.webContents.setIgnoreMenuShortcuts(true), undefined)
|
assert.equal(w.webContents.setIgnoreMenuShortcuts(true), undefined)
|
||||||
assert.equal(w.webContents.setIgnoreMenuShortcuts(false), undefined)
|
assert.equal(w.webContents.setIgnoreMenuShortcuts(false), undefined)
|
||||||
})
|
})
|
||||||
|
@ -594,7 +588,7 @@ describe('webContents module', function () {
|
||||||
xdescribe('destroy()', () => {
|
xdescribe('destroy()', () => {
|
||||||
let server
|
let server
|
||||||
|
|
||||||
before(function (done) {
|
before((done) => {
|
||||||
server = http.createServer((request, response) => {
|
server = http.createServer((request, response) => {
|
||||||
switch (request.url) {
|
switch (request.url) {
|
||||||
case '/404':
|
case '/404':
|
||||||
|
@ -619,7 +613,7 @@ describe('webContents module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(() => {
|
||||||
server.close()
|
server.close()
|
||||||
server = null
|
server = null
|
||||||
})
|
})
|
||||||
|
@ -659,18 +653,18 @@ describe('webContents module', function () {
|
||||||
|
|
||||||
describe('did-change-theme-color event', () => {
|
describe('did-change-theme-color event', () => {
|
||||||
it('is triggered with correct theme color', (done) => {
|
it('is triggered with correct theme color', (done) => {
|
||||||
var count = 0
|
let count = 0
|
||||||
w.webContents.on('did-change-theme-color', (e, color) => {
|
w.webContents.on('did-change-theme-color', (e, color) => {
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
count++
|
count += 1
|
||||||
assert.equal(color, '#FFEEDD')
|
assert.equal(color, '#FFEEDD')
|
||||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'base-page.html'))
|
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'base-page.html')}`)
|
||||||
} else if (count === 1) {
|
} else if (count === 1) {
|
||||||
assert.equal(color, null)
|
assert.equal(color, null)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'theme-color.html'))
|
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'pages', 'theme-color.html')}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,89 +4,79 @@ const qs = require('querystring')
|
||||||
const remote = require('electron').remote
|
const remote = require('electron').remote
|
||||||
const session = remote.session
|
const session = remote.session
|
||||||
|
|
||||||
describe('webRequest module', function () {
|
describe('webRequest module', () => {
|
||||||
var ses = session.defaultSession
|
const ses = session.defaultSession
|
||||||
var server = http.createServer(function (req, res) {
|
const server = http.createServer((req, res) => {
|
||||||
if (req.url === '/serverRedirect') {
|
if (req.url === '/serverRedirect') {
|
||||||
res.statusCode = 301
|
res.statusCode = 301
|
||||||
res.setHeader('Location', 'http://' + req.rawHeaders[1])
|
res.setHeader('Location', 'http://' + req.rawHeaders[1])
|
||||||
res.end()
|
res.end()
|
||||||
} else {
|
} else {
|
||||||
res.setHeader('Custom', ['Header'])
|
res.setHeader('Custom', ['Header'])
|
||||||
var content = req.url
|
let content = req.url
|
||||||
if (req.headers.accept === '*/*;test/header') {
|
if (req.headers.accept === '*/*;test/header') {
|
||||||
content += 'header/received'
|
content += 'header/received'
|
||||||
}
|
}
|
||||||
res.end(content)
|
res.end(content)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var defaultURL = null
|
let defaultURL = null
|
||||||
|
|
||||||
before(function (done) {
|
before((done) => {
|
||||||
server.listen(0, '127.0.0.1', function () {
|
server.listen(0, '127.0.0.1', () => {
|
||||||
var port = server.address().port
|
const port = server.address().port
|
||||||
defaultURL = 'http://127.0.0.1:' + port + '/'
|
defaultURL = 'http://127.0.0.1:' + port + '/'
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
after(function () {
|
after(() => {
|
||||||
server.close()
|
server.close()
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onBeforeRequest', function () {
|
describe('webRequest.onBeforeRequest', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onBeforeRequest(null)
|
ses.webRequest.onBeforeRequest(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can cancel the request', function (done) {
|
it('can cancel the request', (done) => {
|
||||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||||
callback({
|
callback({
|
||||||
cancel: true
|
cancel: true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function () {
|
success: () => {
|
||||||
done('unexpected success')
|
done('unexpected success')
|
||||||
},
|
},
|
||||||
error: function () {
|
error: () => {
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can filter URLs', function (done) {
|
it('can filter URLs', (done) => {
|
||||||
var filter = {
|
const filter = { urls: [defaultURL + 'filter/*'] }
|
||||||
urls: [defaultURL + 'filter/*']
|
ses.webRequest.onBeforeRequest(filter, (details, callback) => {
|
||||||
}
|
callback({cancel: true})
|
||||||
ses.webRequest.onBeforeRequest(filter, function (details, callback) {
|
|
||||||
callback({
|
|
||||||
cancel: true
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL + 'nofilter/test',
|
url: `${defaultURL}nofilter/test`,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/nofilter/test')
|
assert.equal(data, '/nofilter/test')
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL + 'filter/test',
|
url: `${defaultURL}filter/test`,
|
||||||
success: function () {
|
success: () => done('unexpected success'),
|
||||||
done('unexpected success')
|
error: () => done()
|
||||||
},
|
|
||||||
error: function () {
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||||
assert.equal(typeof details.id, 'number')
|
assert.equal(typeof details.id, 'number')
|
||||||
assert.equal(typeof details.timestamp, 'number')
|
assert.equal(typeof details.timestamp, 'number')
|
||||||
assert.equal(typeof details.webContentsId, 'number')
|
assert.equal(typeof details.webContentsId, 'number')
|
||||||
|
@ -98,162 +88,138 @@ describe('webRequest module', function () {
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives post data in details object', function (done) {
|
it('receives post data in details object', (done) => {
|
||||||
var postData = {
|
const postData = {
|
||||||
name: 'post test',
|
name: 'post test',
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||||
assert.equal(details.url, defaultURL)
|
assert.equal(details.url, defaultURL)
|
||||||
assert.equal(details.method, 'POST')
|
assert.equal(details.method, 'POST')
|
||||||
assert.equal(details.uploadData.length, 1)
|
assert.equal(details.uploadData.length, 1)
|
||||||
var data = qs.parse(details.uploadData[0].bytes.toString())
|
const data = qs.parse(details.uploadData[0].bytes.toString())
|
||||||
assert.deepEqual(data, postData)
|
assert.deepEqual(data, postData)
|
||||||
callback({
|
callback({ cancel: true })
|
||||||
cancel: true
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: postData,
|
data: postData,
|
||||||
success: function () {},
|
success: () => {},
|
||||||
error: function () {
|
error: () => done()
|
||||||
done()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can redirect the request', function (done) {
|
it('can redirect the request', (done) => {
|
||||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||||
if (details.url === defaultURL) {
|
if (details.url === defaultURL) {
|
||||||
callback({
|
callback({ redirectURL: `${defaultURL}redirect` })
|
||||||
redirectURL: defaultURL + 'redirect'
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
callback({})
|
callback({})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/redirect')
|
assert.equal(data, '/redirect')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onBeforeSendHeaders', function () {
|
describe('webRequest.onBeforeSendHeaders', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onBeforeSendHeaders(null)
|
ses.webRequest.onBeforeSendHeaders(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onBeforeSendHeaders(function (details, callback) {
|
ses.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||||
assert.equal(typeof details.requestHeaders, 'object')
|
assert.equal(typeof details.requestHeaders, 'object')
|
||||||
assert.equal(details.requestHeaders['Foo.Bar'], 'baz')
|
assert.equal(details.requestHeaders['Foo.Bar'], 'baz')
|
||||||
callback({})
|
callback({})
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
headers: {
|
headers: { 'Foo.Bar': 'baz' },
|
||||||
'Foo.Bar': 'baz'
|
success: (data) => {
|
||||||
},
|
|
||||||
success: function (data) {
|
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can change the request headers', function (done) {
|
it('can change the request headers', (done) => {
|
||||||
ses.webRequest.onBeforeSendHeaders(function (details, callback) {
|
ses.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||||
var requestHeaders = details.requestHeaders
|
const requestHeaders = details.requestHeaders
|
||||||
requestHeaders.Accept = '*/*;test/header'
|
requestHeaders.Accept = '*/*;test/header'
|
||||||
callback({
|
callback({ requestHeaders: requestHeaders })
|
||||||
requestHeaders: requestHeaders
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/header/received')
|
assert.equal(data, '/header/received')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('resets the whole headers', function (done) {
|
it('resets the whole headers', (done) => {
|
||||||
var requestHeaders = {
|
const requestHeaders = {
|
||||||
Test: 'header'
|
Test: 'header'
|
||||||
}
|
}
|
||||||
ses.webRequest.onBeforeSendHeaders(function (details, callback) {
|
ses.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||||
callback({
|
callback({ requestHeaders: requestHeaders })
|
||||||
requestHeaders: requestHeaders
|
|
||||||
})
|
})
|
||||||
})
|
ses.webRequest.onSendHeaders((details) => {
|
||||||
ses.webRequest.onSendHeaders(function (details) {
|
|
||||||
assert.deepEqual(details.requestHeaders, requestHeaders)
|
assert.deepEqual(details.requestHeaders, requestHeaders)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onSendHeaders', function () {
|
describe('webRequest.onSendHeaders', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onSendHeaders(null)
|
ses.webRequest.onSendHeaders(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onSendHeaders(function (details) {
|
ses.webRequest.onSendHeaders((details) => {
|
||||||
assert.equal(typeof details.requestHeaders, 'object')
|
assert.equal(typeof details.requestHeaders, 'object')
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onHeadersReceived', function () {
|
describe('webRequest.onHeadersReceived', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onHeadersReceived(null)
|
ses.webRequest.onHeadersReceived(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
||||||
assert.equal(details.statusCode, 200)
|
assert.equal(details.statusCode, 200)
|
||||||
assert.equal(details.responseHeaders['Custom'], 'Header')
|
assert.equal(details.responseHeaders['Custom'], 'Header')
|
||||||
|
@ -261,76 +227,64 @@ describe('webRequest module', function () {
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can change the response header', function (done) {
|
it('can change the response header', (done) => {
|
||||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||||
var responseHeaders = details.responseHeaders
|
const responseHeaders = details.responseHeaders
|
||||||
responseHeaders['Custom'] = ['Changed']
|
responseHeaders['Custom'] = ['Changed']
|
||||||
callback({
|
callback({ responseHeaders: responseHeaders })
|
||||||
responseHeaders: responseHeaders
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data, status, xhr) {
|
success: (data, status, xhr) => {
|
||||||
assert.equal(xhr.getResponseHeader('Custom'), 'Changed')
|
assert.equal(xhr.getResponseHeader('Custom'), 'Changed')
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not change header by default', function (done) {
|
it('does not change header by default', (done) => {
|
||||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||||
callback({})
|
callback({})
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data, status, xhr) {
|
success: (data, status, xhr) => {
|
||||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('follows server redirect', function (done) {
|
it('follows server redirect', (done) => {
|
||||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||||
var responseHeaders = details.responseHeaders
|
const responseHeaders = details.responseHeaders
|
||||||
callback({
|
callback({ responseHeaders: responseHeaders })
|
||||||
responseHeaders: responseHeaders
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL + 'serverRedirect',
|
url: defaultURL + 'serverRedirect',
|
||||||
success: function (data, status, xhr) {
|
success: (data, status, xhr) => {
|
||||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can change the header status', function (done) {
|
it('can change the header status', (done) => {
|
||||||
ses.webRequest.onHeadersReceived(function (details, callback) {
|
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||||
var responseHeaders = details.responseHeaders
|
const responseHeaders = details.responseHeaders
|
||||||
callback({
|
callback({
|
||||||
responseHeaders: responseHeaders,
|
responseHeaders: responseHeaders,
|
||||||
statusLine: 'HTTP/1.1 404 Not Found'
|
statusLine: 'HTTP/1.1 404 Not Found'
|
||||||
|
@ -338,9 +292,8 @@ describe('webRequest module', function () {
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data, status, xhr) {
|
success: (data, status, xhr) => {},
|
||||||
},
|
error: (xhr, errorType) => {
|
||||||
error: function (xhr, errorType) {
|
|
||||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
@ -348,13 +301,13 @@ describe('webRequest module', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onResponseStarted', function () {
|
describe('webRequest.onResponseStarted', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onResponseStarted(null)
|
ses.webRequest.onResponseStarted(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onResponseStarted(function (details) {
|
ses.webRequest.onResponseStarted((details) => {
|
||||||
assert.equal(typeof details.fromCache, 'boolean')
|
assert.equal(typeof details.fromCache, 'boolean')
|
||||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
||||||
assert.equal(details.statusCode, 200)
|
assert.equal(details.statusCode, 200)
|
||||||
|
@ -362,36 +315,32 @@ describe('webRequest module', function () {
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data, status, xhr) {
|
success: (data, status, xhr) => {
|
||||||
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
assert.equal(xhr.getResponseHeader('Custom'), 'Header')
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onBeforeRedirect', function () {
|
describe('webRequest.onBeforeRedirect', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onBeforeRedirect(null)
|
ses.webRequest.onBeforeRedirect(null)
|
||||||
ses.webRequest.onBeforeRequest(null)
|
ses.webRequest.onBeforeRequest(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
var redirectURL = defaultURL + 'redirect'
|
const redirectURL = defaultURL + 'redirect'
|
||||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||||
if (details.url === defaultURL) {
|
if (details.url === defaultURL) {
|
||||||
callback({
|
callback({ redirectURL: redirectURL })
|
||||||
redirectURL: redirectURL
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
callback({})
|
callback({})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
ses.webRequest.onBeforeRedirect(function (details) {
|
ses.webRequest.onBeforeRedirect((details) => {
|
||||||
assert.equal(typeof details.fromCache, 'boolean')
|
assert.equal(typeof details.fromCache, 'boolean')
|
||||||
assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect')
|
assert.equal(details.statusLine, 'HTTP/1.1 307 Internal Redirect')
|
||||||
assert.equal(details.statusCode, 307)
|
assert.equal(details.statusCode, 307)
|
||||||
|
@ -399,62 +348,54 @@ describe('webRequest module', function () {
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/redirect')
|
assert.equal(data, '/redirect')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onCompleted', function () {
|
describe('webRequest.onCompleted', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onCompleted(null)
|
ses.webRequest.onCompleted(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onCompleted(function (details) {
|
ses.webRequest.onCompleted((details) => {
|
||||||
assert.equal(typeof details.fromCache, 'boolean')
|
assert.equal(typeof details.fromCache, 'boolean')
|
||||||
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
assert.equal(details.statusLine, 'HTTP/1.1 200 OK')
|
||||||
assert.equal(details.statusCode, 200)
|
assert.equal(details.statusCode, 200)
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function (data) {
|
success: (data) => {
|
||||||
assert.equal(data, '/')
|
assert.equal(data, '/')
|
||||||
done()
|
done()
|
||||||
},
|
},
|
||||||
error: function (xhr, errorType) {
|
error: (xhr, errorType) => done(errorType)
|
||||||
done(errorType)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('webRequest.onErrorOccurred', function () {
|
describe('webRequest.onErrorOccurred', () => {
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
ses.webRequest.onErrorOccurred(null)
|
ses.webRequest.onErrorOccurred(null)
|
||||||
ses.webRequest.onBeforeRequest(null)
|
ses.webRequest.onBeforeRequest(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('receives details object', function (done) {
|
it('receives details object', (done) => {
|
||||||
ses.webRequest.onBeforeRequest(function (details, callback) {
|
ses.webRequest.onBeforeRequest((details, callback) => {
|
||||||
callback({
|
callback({ cancel: true })
|
||||||
cancel: true
|
|
||||||
})
|
})
|
||||||
})
|
ses.webRequest.onErrorOccurred((details) => {
|
||||||
ses.webRequest.onErrorOccurred(function (details) {
|
|
||||||
assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT')
|
assert.equal(details.error, 'net::ERR_BLOCKED_BY_CLIENT')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: defaultURL,
|
url: defaultURL,
|
||||||
success: function () {
|
success: () => done('unexpected success')
|
||||||
done('unexpected success')
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,45 +7,45 @@ const {closeWindow} = require('./window-helpers')
|
||||||
|
|
||||||
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
|
const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled')
|
||||||
|
|
||||||
describe('modules support', function () {
|
describe('modules support', () => {
|
||||||
var fixtures = path.join(__dirname, 'fixtures')
|
const fixtures = path.join(__dirname, 'fixtures')
|
||||||
|
|
||||||
describe('third-party module', function () {
|
describe('third-party module', () => {
|
||||||
describe('runas', function () {
|
describe('runas', () => {
|
||||||
if (!nativeModulesEnabled) return
|
if (!nativeModulesEnabled) return
|
||||||
|
|
||||||
it('can be required in renderer', function () {
|
it('can be required in renderer', () => {
|
||||||
require('runas')
|
require('runas')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can be required in node binary', function (done) {
|
it('can be required in node binary', (done) => {
|
||||||
var runas = path.join(fixtures, 'module', 'runas.js')
|
const runas = path.join(fixtures, 'module', 'runas.js')
|
||||||
var child = require('child_process').fork(runas)
|
const child = require('child_process').fork(runas)
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.equal(msg, 'ok')
|
assert.equal(msg, 'ok')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('ffi', function () {
|
describe('ffi', () => {
|
||||||
if (!nativeModulesEnabled) return
|
if (!nativeModulesEnabled) return
|
||||||
if (process.platform === 'win32') return
|
if (process.platform === 'win32') return
|
||||||
|
|
||||||
it('does not crash', function () {
|
it('does not crash', () => {
|
||||||
var ffi = require('ffi')
|
const ffi = require('ffi')
|
||||||
var libm = ffi.Library('libm', {
|
const libm = ffi.Library('libm', {
|
||||||
ceil: ['double', ['double']]
|
ceil: ['double', ['double']]
|
||||||
})
|
})
|
||||||
assert.equal(libm.ceil(1.5), 2)
|
assert.equal(libm.ceil(1.5), 2)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('q', function () {
|
describe('q', () => {
|
||||||
var Q = require('q')
|
const Q = require('q')
|
||||||
describe('Q.when', function () {
|
describe('Q.when', () => {
|
||||||
it('emits the fullfil callback', function (done) {
|
it('emits the fullfil callback', (done) => {
|
||||||
Q(true).then(function (val) {
|
Q(true).then((val) => {
|
||||||
assert.equal(val, true)
|
assert.equal(val, true)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -53,9 +53,9 @@ describe('modules support', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('coffee-script', function () {
|
describe('coffee-script', () => {
|
||||||
it('can be registered and used to require .coffee files', function () {
|
it('can be registered and used to require .coffee files', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
require('coffee-script').register()
|
require('coffee-script').register()
|
||||||
})
|
})
|
||||||
assert.strictEqual(require('./fixtures/module/test.coffee'), true)
|
assert.strictEqual(require('./fixtures/module/test.coffee'), true)
|
||||||
|
@ -63,36 +63,36 @@ describe('modules support', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('global variables', function () {
|
describe('global variables', () => {
|
||||||
describe('process', function () {
|
describe('process', () => {
|
||||||
it('can be declared in a module', function () {
|
it('can be declared in a module', () => {
|
||||||
assert.strictEqual(require('./fixtures/module/declare-process'), 'declared process')
|
assert.strictEqual(require('./fixtures/module/declare-process'), 'declared process')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('global', function () {
|
describe('global', () => {
|
||||||
it('can be declared in a module', function () {
|
it('can be declared in a module', () => {
|
||||||
assert.strictEqual(require('./fixtures/module/declare-global'), 'declared global')
|
assert.strictEqual(require('./fixtures/module/declare-global'), 'declared global')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Buffer', function () {
|
describe('Buffer', () => {
|
||||||
it('can be declared in a module', function () {
|
it('can be declared in a module', () => {
|
||||||
assert.strictEqual(require('./fixtures/module/declare-buffer'), 'declared Buffer')
|
assert.strictEqual(require('./fixtures/module/declare-buffer'), 'declared Buffer')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Module._nodeModulePaths', function () {
|
describe('Module._nodeModulePaths', () => {
|
||||||
describe('when the path is inside the resources path', function () {
|
describe('when the path is inside the resources path', () => {
|
||||||
it('does not include paths outside of the resources path', function () {
|
it('does not include paths outside of the resources path', () => {
|
||||||
let modulePath = process.resourcesPath
|
let modulePath = process.resourcesPath
|
||||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||||
path.join(process.resourcesPath, 'node_modules')
|
path.join(process.resourcesPath, 'node_modules')
|
||||||
])
|
])
|
||||||
|
|
||||||
modulePath = process.resourcesPath + '-foo'
|
modulePath = process.resourcesPath + '-foo'
|
||||||
let nodeModulePaths = Module._nodeModulePaths(modulePath)
|
const nodeModulePaths = Module._nodeModulePaths(modulePath)
|
||||||
assert(nodeModulePaths.includes(path.join(modulePath, 'node_modules')))
|
assert(nodeModulePaths.includes(path.join(modulePath, 'node_modules')))
|
||||||
assert(nodeModulePaths.includes(path.join(modulePath, '..', 'node_modules')))
|
assert(nodeModulePaths.includes(path.join(modulePath, '..', 'node_modules')))
|
||||||
|
|
||||||
|
@ -124,8 +124,8 @@ describe('modules support', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when the path is outside the resources path', function () {
|
describe('when the path is outside the resources path', () => {
|
||||||
it('includes paths outside of the resources path', function () {
|
it('includes paths outside of the resources path', () => {
|
||||||
let modulePath = path.resolve('/foo')
|
let modulePath = path.resolve('/foo')
|
||||||
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
assert.deepEqual(Module._nodeModulePaths(modulePath), [
|
||||||
path.join(modulePath, 'node_modules'),
|
path.join(modulePath, 'node_modules'),
|
||||||
|
@ -140,9 +140,7 @@ describe('modules support', function () {
|
||||||
let w
|
let w
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({show: false})
|
||||||
show: false
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|
|
@ -7,80 +7,80 @@ const {ipcRenderer, remote} = require('electron')
|
||||||
|
|
||||||
const isCI = remote.getGlobal('isCi')
|
const isCI = remote.getGlobal('isCi')
|
||||||
|
|
||||||
describe('node feature', function () {
|
describe('node feature', () => {
|
||||||
var fixtures = path.join(__dirname, 'fixtures')
|
const fixtures = path.join(__dirname, 'fixtures')
|
||||||
|
|
||||||
describe('child_process', function () {
|
describe('child_process', () => {
|
||||||
describe('child_process.fork', function () {
|
describe('child_process.fork', () => {
|
||||||
it('works in current process', function (done) {
|
it('works in current process', (done) => {
|
||||||
var child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.equal(msg, 'message')
|
assert.equal(msg, 'message')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('preserves args', function (done) {
|
it('preserves args', (done) => {
|
||||||
var args = ['--expose_gc', '-test', '1']
|
const args = ['--expose_gc', '-test', '1']
|
||||||
var child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args)
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args)
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.deepEqual(args, msg.slice(2))
|
assert.deepEqual(args, msg.slice(2))
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works in forked process', function (done) {
|
it('works in forked process', (done) => {
|
||||||
var child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'))
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'))
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.equal(msg, 'message')
|
assert.equal(msg, 'message')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works in forked process when options.env is specifed', function (done) {
|
it('works in forked process when options.env is specifed', (done) => {
|
||||||
var child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
|
||||||
path: process.env['PATH']
|
path: process.env['PATH']
|
||||||
})
|
})
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.equal(msg, 'message')
|
assert.equal(msg, 'message')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works in browser process', function (done) {
|
it('works in browser process', (done) => {
|
||||||
var fork = remote.require('child_process').fork
|
const fork = remote.require('child_process').fork
|
||||||
var child = fork(path.join(fixtures, 'module', 'ping.js'))
|
const child = fork(path.join(fixtures, 'module', 'ping.js'))
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.equal(msg, 'message')
|
assert.equal(msg, 'message')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has String::localeCompare working in script', function (done) {
|
it('has String::localeCompare working in script', (done) => {
|
||||||
var child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'))
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'))
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.deepEqual(msg, [0, -1, 1])
|
assert.deepEqual(msg, [0, -1, 1])
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('has setImmediate working in script', function (done) {
|
it('has setImmediate working in script', (done) => {
|
||||||
var child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'))
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'))
|
||||||
child.on('message', function (msg) {
|
child.on('message', (msg) => {
|
||||||
assert.equal(msg, 'ok')
|
assert.equal(msg, 'ok')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
child.send('message')
|
child.send('message')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('pipes stdio', function (done) {
|
it('pipes stdio', (done) => {
|
||||||
let child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), {silent: true})
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), {silent: true})
|
||||||
let data = ''
|
let data = ''
|
||||||
child.stdout.on('data', (chunk) => {
|
child.stdout.on('data', (chunk) => {
|
||||||
data += String(chunk)
|
data += String(chunk)
|
||||||
|
@ -92,7 +92,7 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works when sending a message to a process forked with the --eval argument', function (done) {
|
it('works when sending a message to a process forked with the --eval argument', (done) => {
|
||||||
const source = "process.on('message', (message) => { process.send(message) })"
|
const source = "process.on('message', (message) => { process.send(message) })"
|
||||||
const forked = ChildProcess.fork('--eval', [source])
|
const forked = ChildProcess.fork('--eval', [source])
|
||||||
forked.once('message', (message) => {
|
forked.once('message', (message) => {
|
||||||
|
@ -103,16 +103,14 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('child_process.spawn', function () {
|
describe('child_process.spawn', () => {
|
||||||
let child
|
let child
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(() => {
|
||||||
if (child != null) {
|
if (child != null) child.kill()
|
||||||
child.kill()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', function (done) {
|
it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', (done) => {
|
||||||
child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
|
child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
|
||||||
env: {
|
env: {
|
||||||
ELECTRON_RUN_AS_NODE: true
|
ELECTRON_RUN_AS_NODE: true
|
||||||
|
@ -120,10 +118,10 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
let output = ''
|
let output = ''
|
||||||
child.stdout.on('data', function (data) {
|
child.stdout.on('data', (data) => {
|
||||||
output += data
|
output += data
|
||||||
})
|
})
|
||||||
child.stdout.on('close', function () {
|
child.stdout.on('close', () => {
|
||||||
assert.deepEqual(JSON.parse(output), {
|
assert.deepEqual(JSON.parse(output), {
|
||||||
processLog: process.platform === 'win32' ? 'function' : 'undefined',
|
processLog: process.platform === 'win32' ? 'function' : 'undefined',
|
||||||
processType: 'undefined',
|
processType: 'undefined',
|
||||||
|
@ -133,7 +131,7 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('supports starting the v8 inspector with --inspect/--inspect-brk', function (done) {
|
it('supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
|
||||||
child = ChildProcess.spawn(process.execPath, ['--inspect-brk', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
|
child = ChildProcess.spawn(process.execPath, ['--inspect-brk', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
|
||||||
env: {
|
env: {
|
||||||
ELECTRON_RUN_AS_NODE: true
|
ELECTRON_RUN_AS_NODE: true
|
||||||
|
@ -141,36 +139,31 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
let output = ''
|
let output = ''
|
||||||
child.stderr.on('data', function (data) {
|
child.stderr.on('data', (data) => {
|
||||||
output += data
|
output += data
|
||||||
|
if (output.trim().startsWith('Debugger listening on ws://')) done()
|
||||||
if (output.trim().startsWith('Debugger listening on ws://')) {
|
|
||||||
done()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
child.stdout.on('data', function (data) {
|
child.stdout.on('data', (data) => {
|
||||||
done(new Error(`Unexpected output: ${data.toString()}`))
|
done(new Error(`Unexpected output: ${data.toString()}`))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('contexts', function () {
|
describe('contexts', () => {
|
||||||
describe('setTimeout in fs callback', function () {
|
describe('setTimeout in fs callback', () => {
|
||||||
if (process.env.TRAVIS === 'true') {
|
if (process.env.TRAVIS === 'true') return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
it('does not crash', function (done) {
|
it('does not crash', (done) => {
|
||||||
fs.readFile(__filename, function () {
|
fs.readFile(__filename, () => {
|
||||||
setTimeout(done, 0)
|
setTimeout(done, 0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('error thrown in renderer process node context', function () {
|
describe('error thrown in renderer process node context', () => {
|
||||||
it('gets emitted as a process uncaughtException event', function (done) {
|
it('gets emitted as a process uncaughtException event', (done) => {
|
||||||
const error = new Error('boo!')
|
const error = new Error('boo!')
|
||||||
const listeners = process.listeners('uncaughtException')
|
const listeners = process.listeners('uncaughtException')
|
||||||
process.removeAllListeners('uncaughtException')
|
process.removeAllListeners('uncaughtException')
|
||||||
|
@ -188,30 +181,31 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('error thrown in main process node context', function () {
|
describe('error thrown in main process node context', () => {
|
||||||
it('gets emitted as a process uncaughtException event', function () {
|
it('gets emitted as a process uncaughtException event', () => {
|
||||||
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
|
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
|
||||||
assert.equal(error, 'hello')
|
assert.equal(error, 'hello')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('promise rejection in main process node context', function () {
|
describe('promise rejection in main process node context', () => {
|
||||||
it('gets emitted as a process unhandledRejection event', function () {
|
it('gets emitted as a process unhandledRejection event', () => {
|
||||||
const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello')
|
const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello')
|
||||||
assert.equal(error, 'hello')
|
assert.equal(error, 'hello')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('setTimeout called under Chromium event loop in browser process', function () {
|
describe('setTimeout called under Chromium event loop in browser process', () => {
|
||||||
it('can be scheduled in time', function (done) {
|
it('can be scheduled in time', (done) => {
|
||||||
remote.getGlobal('setTimeout')(done, 0)
|
remote.getGlobal('setTimeout')(done, 0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('setInterval called under Chromium event loop in browser process', function () {
|
describe('setInterval called under Chromium event loop in browser process', () => {
|
||||||
it('can be scheduled in time', function (done) {
|
it('can be scheduled in time', (done) => {
|
||||||
var clear, interval
|
let clear
|
||||||
clear = function () {
|
let interval
|
||||||
|
clear = () => {
|
||||||
remote.getGlobal('clearInterval')(interval)
|
remote.getGlobal('clearInterval')(interval)
|
||||||
done()
|
done()
|
||||||
}
|
}
|
||||||
|
@ -220,29 +214,29 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('message loop', function () {
|
describe('message loop', () => {
|
||||||
describe('process.nextTick', function () {
|
describe('process.nextTick', () => {
|
||||||
it('emits the callback', function (done) {
|
it('emits the callback', (done) => {
|
||||||
process.nextTick(done)
|
process.nextTick(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works in nested calls', function (done) {
|
it('works in nested calls', (done) => {
|
||||||
process.nextTick(function () {
|
process.nextTick(() => {
|
||||||
process.nextTick(function () {
|
process.nextTick(() => {
|
||||||
process.nextTick(done)
|
process.nextTick(done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('setImmediate', function () {
|
describe('setImmediate', () => {
|
||||||
it('emits the callback', function (done) {
|
it('emits the callback', (done) => {
|
||||||
setImmediate(done)
|
setImmediate(done)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works in nested calls', function (done) {
|
it('works in nested calls', (done) => {
|
||||||
setImmediate(function () {
|
setImmediate(() => {
|
||||||
setImmediate(function () {
|
setImmediate(() => {
|
||||||
setImmediate(done)
|
setImmediate(done)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -250,19 +244,17 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('net.connect', function () {
|
describe('net.connect', () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') return
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
it('emit error when connect to a socket path without listeners', function (done) {
|
it('emit error when connect to a socket path without listeners', (done) => {
|
||||||
var socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock')
|
const socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock')
|
||||||
var script = path.join(fixtures, 'module', 'create_socket.js')
|
const script = path.join(fixtures, 'module', 'create_socket.js')
|
||||||
var child = ChildProcess.fork(script, [socketPath])
|
const child = ChildProcess.fork(script, [socketPath])
|
||||||
child.on('exit', function (code) {
|
child.on('exit', (code) => {
|
||||||
assert.equal(code, 0)
|
assert.equal(code, 0)
|
||||||
var client = require('net').connect(socketPath)
|
const client = require('net').connect(socketPath)
|
||||||
client.on('error', function (error) {
|
client.on('error', (error) => {
|
||||||
assert.equal(error.code, 'ECONNREFUSED')
|
assert.equal(error.code, 'ECONNREFUSED')
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
@ -270,45 +262,45 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Buffer', function () {
|
describe('Buffer', () => {
|
||||||
it('can be created from WebKit external string', function () {
|
it('can be created from WebKit external string', () => {
|
||||||
var p = document.createElement('p')
|
const p = document.createElement('p')
|
||||||
p.innerText = '闲云潭影日悠悠,物换星移几度秋'
|
p.innerText = '闲云潭影日悠悠,物换星移几度秋'
|
||||||
var b = new Buffer(p.innerText)
|
const b = new Buffer(p.innerText)
|
||||||
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋')
|
assert.equal(b.toString(), '闲云潭影日悠悠,物换星移几度秋')
|
||||||
assert.equal(Buffer.byteLength(p.innerText), 45)
|
assert.equal(Buffer.byteLength(p.innerText), 45)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('correctly parses external one-byte UTF8 string', function () {
|
it('correctly parses external one-byte UTF8 string', () => {
|
||||||
var p = document.createElement('p')
|
const p = document.createElement('p')
|
||||||
p.innerText = 'Jøhänñéß'
|
p.innerText = 'Jøhänñéß'
|
||||||
var b = new Buffer(p.innerText)
|
const b = new Buffer(p.innerText)
|
||||||
assert.equal(b.toString(), 'Jøhänñéß')
|
assert.equal(b.toString(), 'Jøhänñéß')
|
||||||
assert.equal(Buffer.byteLength(p.innerText), 13)
|
assert.equal(Buffer.byteLength(p.innerText), 13)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not crash when creating large Buffers', function () {
|
it('does not crash when creating large Buffers', () => {
|
||||||
var buffer = new Buffer(new Array(4096).join(' '))
|
let buffer = new Buffer(new Array(4096).join(' '))
|
||||||
assert.equal(buffer.length, 4095)
|
assert.equal(buffer.length, 4095)
|
||||||
buffer = new Buffer(new Array(4097).join(' '))
|
buffer = new Buffer(new Array(4097).join(' '))
|
||||||
assert.equal(buffer.length, 4096)
|
assert.equal(buffer.length, 4096)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('process.stdout', function () {
|
describe('process.stdout', () => {
|
||||||
it('does not throw an exception when accessed', function () {
|
it('does not throw an exception when accessed', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
process.stdout
|
process.stdout
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does not throw an exception when calling write()', function () {
|
it('does not throw an exception when calling write()', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
process.stdout.write('test')
|
process.stdout.write('test')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should have isTTY defined on Mac and Linux', function () {
|
it('should have isTTY defined on Mac and Linux', () => {
|
||||||
if (isCI) return
|
if (isCI) return
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
|
@ -319,26 +311,26 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('process.stdin', function () {
|
describe('process.stdin', () => {
|
||||||
it('does not throw an exception when accessed', function () {
|
it('does not throw an exception when accessed', () => {
|
||||||
assert.doesNotThrow(function () {
|
assert.doesNotThrow(() => {
|
||||||
process.stdin
|
process.stdin
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null when read from', function () {
|
it('returns null when read from', () => {
|
||||||
assert.equal(process.stdin.read(), null)
|
assert.equal(process.stdin.read(), null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('process.version', function () {
|
describe('process.version', () => {
|
||||||
it('should not have -pre', function () {
|
it('should not have -pre', () => {
|
||||||
assert(!process.version.endsWith('-pre'))
|
assert(!process.version.endsWith('-pre'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('vm.createContext', function () {
|
describe('vm.createContext', () => {
|
||||||
it('should not crash', function () {
|
it('should not crash', () => {
|
||||||
require('vm').runInNewContext('')
|
require('vm').runInNewContext('')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue