split ipc tests into three files
This commit is contained in:
parent
c2ee0854f4
commit
00e8713eac
3 changed files with 289 additions and 236 deletions
87
spec/api-ipc-main-spec.js
Normal file
87
spec/api-ipc-main-spec.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
'use strict'
|
||||
|
||||
const assert = require('assert')
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
const {closeWindow} = require('./window-helpers')
|
||||
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
const {ipcMain, webContents, BrowserWindow} = remote
|
||||
|
||||
const comparePaths = (path1, path2) => {
|
||||
if (process.platform === 'win32') {
|
||||
path1 = path1.toLowerCase()
|
||||
path2 = path2.toLowerCase()
|
||||
}
|
||||
assert.equal(path1, path2)
|
||||
}
|
||||
|
||||
describe.only('ipc main module', () => {
|
||||
const fixtures = path.join(__dirname, 'fixtures')
|
||||
|
||||
let w = null
|
||||
|
||||
afterEach(() => closeWindow(w).then(() => { w = null }))
|
||||
|
||||
describe('ipc.sendSync', () => {
|
||||
afterEach(() => { ipcMain.removeAllListeners('send-sync-message') })
|
||||
|
||||
it('does not crash when reply is not sent and browser is destroyed', (done) => {
|
||||
w = new BrowserWindow({ show: false })
|
||||
ipcMain.once('send-sync-message', (event) => {
|
||||
event.returnValue = null
|
||||
done()
|
||||
})
|
||||
w.loadURL(`file://${path.join(fixtures, 'api', 'send-sync-message.html')}`)
|
||||
})
|
||||
|
||||
it('does not crash when reply is sent by multiple listeners', (done) => {
|
||||
w = new BrowserWindow({ show: false })
|
||||
ipcMain.on('send-sync-message', (event) => {
|
||||
event.returnValue = null
|
||||
})
|
||||
ipcMain.on('send-sync-message', (event) => {
|
||||
event.returnValue = null
|
||||
done()
|
||||
})
|
||||
w.loadURL(`file://${path.join(fixtures, 'api', 'send-sync-message.html')}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('remote listeners', () => {
|
||||
it('can be added and removed correctly', () => {
|
||||
w = new BrowserWindow({ show: false })
|
||||
const listener = () => {}
|
||||
|
||||
w.on('test', listener)
|
||||
assert.equal(w.listenerCount('test'), 1)
|
||||
w.removeListener('test', listener)
|
||||
assert.equal(w.listenerCount('test'), 0)
|
||||
})
|
||||
})
|
||||
|
||||
it('throws an error when removing all the listeners', () => {
|
||||
ipcMain.on('test-event', () => {})
|
||||
assert.equal(ipcMain.listenerCount('test-event'), 1)
|
||||
|
||||
assert.throws(() => {
|
||||
ipcMain.removeAllListeners()
|
||||
}, /Removing all listeners from ipcMain will make Electron internals stop working/)
|
||||
|
||||
ipcMain.removeAllListeners('test-event')
|
||||
assert.equal(ipcMain.listenerCount('test-event'), 0)
|
||||
})
|
||||
|
||||
describe('remote objects registry', () => {
|
||||
it('does not dereference until the render view is deleted (regression)', (done) => {
|
||||
w = new BrowserWindow({ show: false })
|
||||
|
||||
ipcMain.once('error-message', (event, message) => {
|
||||
assert(message.startsWith('Cannot call function \'getURL\' on missing remote object'), message)
|
||||
done()
|
||||
})
|
||||
|
||||
w.loadURL(`file://${path.join(fixtures, 'api', 'render-view-deleted.html')}`)
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue