Add new-webview specs

This commit is contained in:
Kevin Sawicki 2017-02-03 12:21:46 -08:00
parent c3f3a6f133
commit 706b9f6cbf
2 changed files with 36 additions and 1 deletions

View file

@ -250,6 +250,16 @@ ipcMain.on('prevent-next-new-window', (event, id) => {
webContents.fromId(id).once('new-window', event => event.preventDefault()) 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) => { ipcMain.on('try-emit-web-contents-event', (event, id, eventName) => {
const consoleWarn = console.warn const consoleWarn = console.warn
let warningMessage = null let warningMessage = null

View file

@ -2,7 +2,7 @@ const assert = require('assert')
const path = require('path') const path = require('path')
const http = require('http') const http = require('http')
const url = require('url') const url = require('url')
const {remote} = require('electron') const {ipcRenderer, remote} = require('electron')
const {app, session, getGuestWebContents, ipcMain, BrowserWindow, webContents} = remote const {app, session, getGuestWebContents, ipcMain, BrowserWindow, webContents} = remote
const {closeWindow} = require('./window-helpers') const {closeWindow} = require('./window-helpers')
@ -1100,6 +1100,31 @@ describe('<webview> tag', function () {
w.loadURL('file://' + fixtures + '/pages/webview-visibilitychange.html') 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) { it('loads devtools extensions registered on the parent window', function (done) {
w = new BrowserWindow({ w = new BrowserWindow({
show: false show: false