Skip to content

Commit c5da330

Browse files
committed
Add failing spec for sandboxed window.open
1 parent 070bbcf commit c5da330

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

spec/api-browser-window-spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,25 @@ describe('BrowserWindow module', function () {
10121012
})
10131013
})
10141014
})
1015+
1016+
it('supports calling preventDefault on new-window events', (done) => {
1017+
w.destroy()
1018+
w = new BrowserWindow({
1019+
show: false,
1020+
webPreferences: {
1021+
sandbox: true,
1022+
}
1023+
})
1024+
const initialWebContents = webContents.getAllWebContents()
1025+
ipcRenderer.send('prevent-next-new-window', w.webContents.id)
1026+
w.webContents.once('new-window', () => {
1027+
process.nextTick(() => {
1028+
assert.deepEqual(webContents.getAllWebContents().length, initialWebContents.length)
1029+
done()
1030+
})
1031+
})
1032+
w.loadURL('file://' + path.join(fixtures, 'pages', 'window-open.html'))
1033+
})
10151034
})
10161035
})
10171036

spec/static/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,8 @@ ipcMain.on('create-window-with-options-cycle', (event) => {
245245
const window = new BrowserWindow({show: false, foo: foo})
246246
event.returnValue = window.id
247247
})
248+
249+
250+
ipcMain.on('prevent-next-new-window', (event, id) => {
251+
webContents.fromId(id).once('new-window', event => event.preventDefault())
252+
})

0 commit comments

Comments
 (0)