]> khamidou — GitHub mirrors - electron.git/commitdiff
spec: Test beforeunload handler in webview
authorCheng Zhao <zcbenz@gmail.com>
Fri, 1 May 2015 05:48:23 +0000 (13:48 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 1 May 2015 05:48:23 +0000 (13:48 +0800)
spec/fixtures/pages/beforeunload-false.html [new file with mode: 0644]
spec/webview-spec.coffee

diff --git a/spec/fixtures/pages/beforeunload-false.html b/spec/fixtures/pages/beforeunload-false.html
new file mode 100644 (file)
index 0000000..7ae4edf
--- /dev/null
@@ -0,0 +1,13 @@
+<html>
+<body>
+<script type="text/javascript" charset="utf-8">
+  window.onbeforeunload = function() {
+    setTimeout(function() {
+      var ipc = require('ipc');
+      ipc.sendToHost('onbeforeunload');
+    }, 0);
+    return false;
+  }
+</script>
+</body>
+</html>
index 51058ad695e9bd4822c21a97148283612dd8ab6d..92a77351ee68428f95be9a95bcfa8be7ce4003aa 100644 (file)
@@ -178,3 +178,18 @@ describe '<webview> tag', ->
         done()
       webview.src = "file://#{fixtures}/pages/a.html"
       document.body.appendChild webview
+
+  describe '<webview>.reload()', ->
+    it 'should emit beforeunload handler', (done) ->
+      webview.addEventListener 'did-finish-load', (e) ->
+        webview.reload()
+      listener = (e) ->
+        assert.equal e.channel, 'onbeforeunload'
+        webview.removeEventListener 'ipc-message', listener
+        done()
+      webview.addEventListener 'console-message', (e) ->
+        console.log(e)
+      webview.addEventListener 'ipc-message', listener
+      webview.setAttribute 'nodeintegration', 'on'
+      webview.src = "file://#{fixtures}/pages/beforeunload-false.html"
+      document.body.appendChild webview