Add new-webview specs
This commit is contained in:
parent
c3f3a6f133
commit
706b9f6cbf
2 changed files with 36 additions and 1 deletions
|
@ -250,6 +250,16 @@ ipcMain.on('prevent-next-new-window', (event, id) => {
|
|||
webContents.fromId(id).once('new-window', event => event.preventDefault())
|
||||
})
|
||||
|
||||
ipcMain.on('prevent-next-new-webview', (event) => {
|
||||
event.sender.once('new-webview', event => event.preventDefault())
|
||||
})
|
||||
|
||||
ipcMain.on('disable-node-on-next-new-webview', (event, id) => {
|
||||
event.sender.once('new-webview', (event, guest, webPreferences) => {
|
||||
webPreferences.nodeIntegration = false
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.on('try-emit-web-contents-event', (event, id, eventName) => {
|
||||
const consoleWarn = console.warn
|
||||
let warningMessage = null
|
||||
|
|
|
@ -2,7 +2,7 @@ const assert = require('assert')
|
|||
const path = require('path')
|
||||
const http = require('http')
|
||||
const url = require('url')
|
||||
const {remote} = require('electron')
|
||||
const {ipcRenderer, remote} = require('electron')
|
||||
const {app, session, getGuestWebContents, ipcMain, BrowserWindow, webContents} = remote
|
||||
const {closeWindow} = require('./window-helpers')
|
||||
|
||||
|
@ -1100,6 +1100,31 @@ describe('<webview> tag', function () {
|
|||
w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html')
|
||||
})
|
||||
|
||||
describe('new-webview event', () => {
|
||||
it('supports changing the web preferences', (done) => {
|
||||
ipcRenderer.send('disable-node-on-next-new-webview')
|
||||
webview.addEventListener('console-message', (event) => {
|
||||
assert.equal(event.message, 'undefined undefined undefined undefined')
|
||||
done()
|
||||
})
|
||||
webview.setAttribute('nodeintegration', 'yes')
|
||||
webview.src = 'file://' + fixtures + '/pages/c.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
it('supports preventing a webview from being created', (done) => {
|
||||
ipcRenderer.send('prevent-next-new-webview')
|
||||
webview.addEventListener('destroyed', () => {
|
||||
done()
|
||||
})
|
||||
webview.src = 'file://' + fixtures + '/pages/c.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
})
|
||||
|
||||
it('emits a new-webview event when first attached that ', () => {
|
||||
})
|
||||
|
||||
it('loads devtools extensions registered on the parent window', function (done) {
|
||||
w = new BrowserWindow({
|
||||
show: false
|
||||
|
|
Loading…
Reference in a new issue