From 014001550043ceef6ea815825325f8432add6c58 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 May 2016 17:04:13 +0900 Subject: [PATCH] spec: WebView is disabled when nodeIntegration is disabled --- spec/fixtures/module/preload-webview.js | 5 +++++ spec/webview-spec.js | 27 +++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/module/preload-webview.js diff --git a/spec/fixtures/module/preload-webview.js b/spec/fixtures/module/preload-webview.js new file mode 100644 index 0000000..273065c --- /dev/null +++ b/spec/fixtures/module/preload-webview.js @@ -0,0 +1,5 @@ +const {ipcRenderer} = require('electron') + +window.onload = function () { + ipcRenderer.send('webview', typeof WebView) +} diff --git a/spec/webview-spec.js b/spec/webview-spec.js index e8a82a1..aca18a2 100644 --- a/spec/webview-spec.js +++ b/spec/webview-spec.js @@ -8,7 +8,9 @@ describe(' tag', function () { this.timeout(20000) var fixtures = path.join(__dirname, 'fixtures') + var webview = null + let w = null beforeEach(function () { webview = new WebView() @@ -18,17 +20,38 @@ describe(' tag', function () { if (document.body.contains(webview)) { document.body.removeChild(webview) } + if (w) { + w.destroy() + w = null + } }) it('works without script tag in page', function (done) { - let w = new BrowserWindow({show: false}) + w = new BrowserWindow({show: false}) ipcMain.once('pong', function () { - w.destroy() done() }) w.loadURL('file://' + fixtures + '/pages/webview-no-script.html') }) + it('is disabled when nodeIntegration is disabled', function (done) { + w = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: false, + preload: path.join(fixtures, 'module', 'preload-webview.js') + }, + }) + ipcMain.once('webview', function (event, type) { + if (type === 'undefined') { + done() + } else { + done('WebView still exists') + } + }) + w.loadURL('file://' + fixtures + '/pages/webview-no-script.html') + }) + describe('src attribute', function () { it('specifies the page to load', function (done) { webview.addEventListener('console-message', function (e) { -- 2.7.4