diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index b718a6aa49..eabd9209e8 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -267,6 +267,16 @@ describe('BrowserWindow module', function () { }) }) + describe('will-navigate event', function () { + it('allows the window to be closed from the event listener', (done) => { + ipcRenderer.send('close-on-will-navigate', w.id) + ipcRenderer.once('closed-on-will-navigate', () => { + done() + }) + w.loadURL('file://' + fixtures + '/pages/will-navigate.html') + }) + }) + describe('BrowserWindow.show()', function () { if (isCI) { return diff --git a/spec/static/main.js b/spec/static/main.js index 19b0739930..259350f959 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -221,3 +221,12 @@ ipcMain.on('set-client-certificate-option', function (event, skip) { }) event.returnValue = 'done' }) + +ipcMain.on('close-on-will-navigate', (event, id) => { + const contents = event.sender + const window = BrowserWindow.fromId(id) + window.webContents.once('will-navigate', (event, input) => { + window.close() + contents.send('closed-on-will-navigate') + }) +})