]> khamidou — GitHub mirrors - electron.git/commitdiff
spec: Native modules should work after navigation in webview
authorCheng Zhao <zcbenz@gmail.com>
Sun, 26 Apr 2015 07:49:26 +0000 (15:49 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 27 Apr 2015 07:11:59 +0000 (15:11 +0800)
spec/fixtures/pages/native-module.html [new file with mode: 0644]
spec/webview-spec.coffee

diff --git a/spec/fixtures/pages/native-module.html b/spec/fixtures/pages/native-module.html
new file mode 100644 (file)
index 0000000..a0ae0fe
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  var path = require('path');
+  console.log(typeof require(path.join(__dirname, '..', '..', 'node_modules', 'runas')));
+</script>
+</body>
+</html>
+
index 1936731f3541d42e46cc50fc5c3e89a097a6a061..ea50f632b31c2ebb2dd90f489f9a76a84199113c 100644 (file)
@@ -47,6 +47,19 @@ describe '<webview> tag', ->
       webview.src = "file://#{fixtures}/pages/d.html"
       document.body.appendChild webview
 
+    it 'loads native modules when navigation happens', (done) ->
+      listener = (e) ->
+        webview.removeEventListener 'did-finish-load', listener
+        listener2 = (e) ->
+          assert.equal e.message, 'function'
+          done()
+        webview.addEventListener 'console-message', listener2
+        webview.src = "file://#{fixtures}/pages/native-module.html"
+      webview.addEventListener 'did-finish-load', listener
+      webview.setAttribute 'nodeintegration', 'on'
+      webview.src = "file://#{fixtures}/pages/native-module.html"
+      document.body.appendChild webview
+
   describe 'preload attribute', ->
     it 'loads the script before other scripts in window', (done) ->
       listener = (e) ->