spec: Test beforeunload handler in webview

This commit is contained in:
Cheng Zhao 2015-05-01 13:48:23 +08:00
parent 817dfbdc27
commit 36d2512ff8
2 changed files with 28 additions and 0 deletions

View file

@ -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>

View 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