From 706b9f6cbf9d0532b21fe9b3d00fbc47555749be Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 3 Feb 2017 12:21:46 -0800 Subject: [PATCH] Add new-webview specs --- spec/static/main.js | 10 ++++++++++ spec/webview-spec.js | 27 ++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/spec/static/main.js b/spec/static/main.js index f29bd00e68b8..735e7e8b5f83 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -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 diff --git a/spec/webview-spec.js b/spec/webview-spec.js index 9af3e01a4cb7..02354eb8633a 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -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(' 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