From d4cbf7cadbed1f0dcd01c40ca07639799901b1a6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 10 Sep 2015 15:30:41 +0800 Subject: [PATCH] spec: node-integration should work in web-preferences --- spec/api-browser-window-spec.coffee | 39 ++++++++++++++++++++++------- spec/fixtures/api/blank.html | 5 ++++ spec/fixtures/api/preload.html | 2 +- spec/fixtures/module/send-later.js | 4 +++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 spec/fixtures/api/blank.html create mode 100644 spec/fixtures/module/send-later.js diff --git a/spec/api-browser-window-spec.coffee b/spec/api-browser-window-spec.coffee index fa7a8ae33a9c..15cd621ba271 100644 --- a/spec/api-browser-window-spec.coffee +++ b/spec/api-browser-window-spec.coffee @@ -182,15 +182,36 @@ describe 'browser-window module', -> assert.equal after[0], size.width assert.equal after[1], size.height - describe '"preload" options', -> - it 'loads the script before other scripts in window', (done) -> - preload = path.join fixtures, 'module', 'set-global.js' - remote.require('ipc').once 'preload', (event, test) -> - assert.equal(test, 'preload') - done() - w.destroy() - w = new BrowserWindow(show: false, width: 400, height: 400, preload: preload) - w.loadUrl 'file://' + path.join(fixtures, 'api', 'preload.html') + describe '"web-preferences" option', -> + afterEach -> + remote.require('ipc').removeAllListeners('answer') + + describe '"preload" option', -> + it 'loads the script before other scripts in window', (done) -> + preload = path.join fixtures, 'module', 'set-global.js' + remote.require('ipc').once 'answer', (event, test) -> + assert.equal(test, 'preload') + done() + w.destroy() + w = new BrowserWindow + show: false + 'web-preferences': + preload: preload + w.loadUrl 'file://' + path.join(fixtures, 'api', 'preload.html') + + describe '"node-integration" option', -> + it 'disables node integration when specified to false', (done) -> + preload = path.join fixtures, 'module', 'send-later.js' + remote.require('ipc').once 'answer', (event, test) -> + assert.equal(test, 'undefined') + done() + w.destroy() + w = new BrowserWindow + show: false + 'web-preferences': + preload: preload + 'node-integration': false + w.loadUrl 'file://' + path.join(fixtures, 'api', 'blank.html') describe 'beforeunload handler', -> it 'returning true would not prevent close', (done) -> diff --git a/spec/fixtures/api/blank.html b/spec/fixtures/api/blank.html new file mode 100644 index 000000000000..accfb421446d --- /dev/null +++ b/spec/fixtures/api/blank.html @@ -0,0 +1,5 @@ + + + diff --git a/spec/fixtures/api/preload.html b/spec/fixtures/api/preload.html index 22dee23444fa..ece481f92413 100644 --- a/spec/fixtures/api/preload.html +++ b/spec/fixtures/api/preload.html @@ -3,7 +3,7 @@ diff --git a/spec/fixtures/module/send-later.js b/spec/fixtures/module/send-later.js new file mode 100644 index 000000000000..fce96b84b787 --- /dev/null +++ b/spec/fixtures/module/send-later.js @@ -0,0 +1,4 @@ +var ipc = require('ipc'); +window.onload = function() { + ipc.send('answer', typeof window.process); +}