Add failing spec for sandboxed window.open
authorKevin Sawicki <kevinsawicki@gmail.com>
Tue, 10 Jan 2017 23:34:29 +0000 (15:34 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 12 Jan 2017 18:28:08 +0000 (10:28 -0800)
spec/api-browser-window-spec.js
spec/static/main.js

index f19ff06..9f45492 100644 (file)
@@ -1012,6 +1012,25 @@ describe('BrowserWindow module', function () {
           })
         })
       })
+
+      it('supports calling preventDefault on new-window events', (done) => {
+        w.destroy()
+        w = new BrowserWindow({
+          show: false,
+          webPreferences: {
+            sandbox: true,
+          }
+        })
+        const initialWebContents = webContents.getAllWebContents()
+        ipcRenderer.send('prevent-next-new-window', w.webContents.id)
+        w.webContents.once('new-window', () => {
+          process.nextTick(() => {
+            assert.deepEqual(webContents.getAllWebContents().length, initialWebContents.length)
+            done()
+          })
+        })
+        w.loadURL('file://' + path.join(fixtures, 'pages', 'window-open.html'))
+      })
     })
   })
 
index b9d7d94..2b625fd 100644 (file)
@@ -245,3 +245,8 @@ ipcMain.on('create-window-with-options-cycle', (event) => {
   const window = new BrowserWindow({show: false, foo: foo})
   event.returnValue = window.id
 })
+
+
+ipcMain.on('prevent-next-new-window', (event, id) => {
+  webContents.fromId(id).once('new-window', event => event.preventDefault())
+})