Browse Source

spec: WebView is disabled when nodeIntegration is disabled

Cheng Zhao 9 years ago
parent
commit
0140015500
2 changed files with 30 additions and 2 deletions
  1. 5 0
      spec/fixtures/module/preload-webview.js
  2. 25 2
      spec/webview-spec.js

+ 5 - 0
spec/fixtures/module/preload-webview.js

@@ -0,0 +1,5 @@
+const {ipcRenderer} = require('electron')
+
+window.onload = function () {
+  ipcRenderer.send('webview', typeof WebView)
+}

+ 25 - 2
spec/webview-spec.js

@@ -8,7 +8,9 @@ describe('<webview> 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('<webview> 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) {