Browse Source

Add failing spec

Kevin Sawicki 9 years ago
parent
commit
e4bd592e0e

+ 4 - 0
spec/fixtures/module/answer.js

@@ -0,0 +1,4 @@
+var ipcRenderer = require('electron').ipcRenderer
+window.answer = function (answer) {
+  ipcRenderer.send('answer', answer)
+}

+ 13 - 0
spec/fixtures/pages/web-view-log-process.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <title>test</title>
+    <script>
+      console.log(typeof process)
+    </script>
+  </head>
+  <body>
+    test?
+  </body>
+</html>

+ 23 - 0
spec/fixtures/pages/webview-no-node-integration-on-window.html

@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <script>
+      document.addEventListener('DOMContentLoaded', function () {
+        var windowUrl = decodeURIComponent(window.location.search.substring(3))
+
+        var wv = new WebView()
+        wv.setAttribute('nodeintegration', 'yes')
+        wv.setAttribute('src', windowUrl)
+        wv.setAttribute('style', 'display:inline-block; width:200px; height:200px')
+
+        wv.addEventListener('console-message', function(e) {
+          window.answer(e.message)
+        })
+
+        document.body.appendChild(wv)
+      })
+    </script>
+  </head>
+  <body>
+  </body>
+</html>

+ 33 - 0
spec/webview-spec.js

@@ -84,6 +84,39 @@ describe('<webview> tag', function () {
       document.body.appendChild(webview)
     })
 
+    it('disables node integration when disabled on the parent BrowserWindow', function (done) {
+      var b = undefined
+
+      ipcMain.once('answer', function (event, typeofProcess) {
+        try {
+          assert.equal(typeofProcess, 'undefined')
+          done()
+        } finally {
+          b.close()
+        }
+      })
+
+      var windowUrl = require('url').format({
+        pathname: `${fixtures}/pages/webview-no-node-integration-on-window.html`,
+        protocol: 'file',
+        query: {
+          p: `${fixtures}/pages/web-view-log-process.html`
+        },
+        slashes: true
+      })
+      var preload = path.join(fixtures, 'module', 'answer.js')
+
+      b = new BrowserWindow({
+        height: 400,
+        width: 400,
+        show: false,
+        webPreferences: {
+          preload: preload,
+          nodeIntegration: false,
+        }
+      })
+      b.loadURL(windowUrl)
+    })
 
     it('disables node integration on child windows when it is disabled on the webview', function (done) {
       app.once('browser-window-created', function (event, window) {