spec: Add test for sendInputEvent

This commit is contained in:
Cheng Zhao 2015-09-18 18:28:34 +08:00
parent 7b2980434c
commit b8d50f3a3a
3 changed files with 41 additions and 0 deletions

9
spec/fixtures/pages/onkeyup.html vendored Normal file
View file

@ -0,0 +1,9 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
document.onkeyup = function(e) {
require('ipc').sendToHost('keyup', e.keyCode, e.shiftKey, e.ctrlKey);
}
</script>
</body>
</html>

9
spec/fixtures/pages/onmouseup.html vendored Normal file
View file

@ -0,0 +1,9 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
document.onmouseup = function(e) {
require('ipc').sendToHost('mouseup', e.x, e.y, e.shiftKey, e.ctrlKey);
}
</script>
</body>
</html>

View file

@ -336,3 +336,26 @@ describe '<webview> tag', ->
webview.addEventListener 'did-finish-load', listener2
webview.src = "file://#{fixtures}/pages/fullscreen.html"
document.body.appendChild webview
describe 'sendInputEvent', ->
it 'can send keyboard event', (done) ->
webview.addEventListener 'ipc-message', (e) ->
assert.equal e.channel, 'keyup'
assert.deepEqual e.args, [67, true, false]
done()
webview.addEventListener 'dom-ready', ->
webview.sendInputEvent type: 'keyup', keyCode: 'c', modifiers: ['shift']
webview.src = "file://#{fixtures}/pages/onkeyup.html"
webview.setAttribute 'nodeintegration', 'on'
document.body.appendChild webview
it 'can send mouse event', (done) ->
webview.addEventListener 'ipc-message', (e) ->
assert.equal e.channel, 'mouseup'
assert.deepEqual e.args, [10, 20, false, true]
done()
webview.addEventListener 'dom-ready', ->
webview.sendInputEvent type: 'mouseup', modifiers: ['ctrl'], x: 10, y: 20
webview.src = "file://#{fixtures}/pages/onmouseup.html"
webview.setAttribute 'nodeintegration', 'on'
document.body.appendChild webview