test: move ipcRenderer spec to main runner (#20093)

This commit is contained in:
Jeremy Apthorp 2019-09-19 16:35:05 -04:00 committed by GitHub
parent b136819371
commit e83c299454
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 233 additions and 239 deletions

View file

@ -511,4 +511,40 @@ ifdescribe(features.isRemoteModuleEnabled())('remote module', () => {
w.loadURL('about:blank')
})
})
describe('remote listeners', () => {
let w = null
afterEach(() => closeWindow(w).then(() => { w = null }))
it('detaches listeners subscribed to destroyed renderers, and shows a warning', (done) => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
w.webContents.once('did-finish-load', () => {
w.webContents.once('did-finish-load', () => {
const expectedMessage = [
'Attempting to call a function in a renderer window that has been closed or released.',
'Function provided here: remote-event-handler.html:11:33',
'Remote event names: remote-handler, other-remote-handler'
].join('\n')
const results = ipcRenderer.sendSync('try-emit-web-contents-event', w.webContents.id, 'remote-handler')
expect(results).to.deep.equal({
warningMessage: expectedMessage,
listenerCountBefore: 2,
listenerCountAfter: 1
})
done()
})
w.webContents.reload()
})
w.loadFile(path.join(fixtures, 'api', 'remote-event-handler.html'))
})
})
})