Add 'will-prevent-unload' event.
This commit is contained in:
parent
0c3f80c334
commit
4044548f3e
9 changed files with 88 additions and 17 deletions
|
@ -543,6 +543,31 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('will-prevent-unload event', function () {
|
||||
it('does not emit if beforeunload returns undefined', function (done) {
|
||||
w.once('closed', function () {
|
||||
done()
|
||||
})
|
||||
w.webContents.on('will-prevent-unload', function (e) {
|
||||
assert.fail('should not have fired')
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html'))
|
||||
})
|
||||
|
||||
it('emits if beforeunload returns false', (done) => {
|
||||
w.webContents.on('will-prevent-unload', () => {
|
||||
done()
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||
})
|
||||
|
||||
it('supports calling preventDefault on will-prevent-unload events', function (done) {
|
||||
ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id)
|
||||
w.once('closed', () => done())
|
||||
w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('destroy()', () => {
|
||||
let server
|
||||
|
||||
|
|
|
@ -266,6 +266,10 @@ ipcMain.on('prevent-next-will-attach-webview', (event) => {
|
|||
event.sender.once('will-attach-webview', event => event.preventDefault())
|
||||
})
|
||||
|
||||
ipcMain.on('prevent-next-will-prevent-unload', (event, id) => {
|
||||
webContents.fromId(id).once('will-prevent-unload', event => event.preventDefault())
|
||||
})
|
||||
|
||||
ipcMain.on('disable-node-on-next-will-attach-webview', (event, id) => {
|
||||
event.sender.once('will-attach-webview', (event, webPreferences, params) => {
|
||||
params.src = `file://${path.join(__dirname, '..', 'fixtures', 'pages', 'c.html')}`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue