Add specs for <webview>

This commit is contained in:
Cheng Zhao 2014-10-25 23:23:49 +08:00
parent 24b4fcea15
commit db071f8d8e
6 changed files with 78 additions and 0 deletions

7
spec/fixtures/pages/a.html vendored Normal file
View file

@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
console.log('a');
</script>
</body>
</html>

8
spec/fixtures/pages/b.html vendored Normal file
View file

@ -0,0 +1,8 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
console.log('b');
</script>
</body>
</html>

7
spec/fixtures/pages/c.html vendored Normal file
View file

@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
console.log([typeof require, typeof module, typeof process].join(' '));
</script>
</body>
</html>

7
spec/fixtures/pages/d.html vendored Normal file
View file

@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
console.log([typeof require, typeof module, typeof process].join(' '));
</script>
</body>
</html>

View file

@ -141,6 +141,7 @@ app.on('ready', function() {
width: 800,
height: 600,
'web-preferences': {
plugins: true, // Required by <webview>.
javascript: true // Test whether web-preferences crashes.
},
});

48
spec/webview-spec.coffee Normal file
View file

@ -0,0 +1,48 @@
assert = require 'assert'
path = require 'path'
describe '<webview> tag', ->
fixtures = path.join __dirname, 'fixtures'
webview = null
beforeEach ->
webview = new WebView
afterEach ->
document.body.removeChild webview
describe 'src attribute', ->
it 'specifies the page to load', (done) ->
webview.addEventListener 'console-message', (e) ->
assert.equal e.message, 'a'
done()
webview.src = "file://#{fixtures}/pages/a.html"
document.body.appendChild webview
it 'navigates to new page when changed', (done) ->
listener = (e) ->
webview.src = "file://#{fixtures}/pages/b.html"
webview.addEventListener 'console-message', (e) ->
assert.equal e.message, 'b'
done()
webview.removeEventListener 'did-finish-load', listener
webview.addEventListener 'did-finish-load', listener
webview.src = "file://#{fixtures}/pages/a.html"
document.body.appendChild webview
describe 'nodeintegration attribute', ->
it 'inserts no node symbols when not set', (done) ->
webview.addEventListener 'console-message', (e) ->
assert.equal e.message, 'undefined undefined undefined'
done()
webview.src = "file://#{fixtures}/pages/c.html"
document.body.appendChild webview
it 'inserts node symbols when set', (done) ->
webview.addEventListener 'console-message', (e) ->
assert.equal e.message, 'function object object'
done()
webview.setAttribute 'nodeintegration', 'on'
webview.src = "file://#{fixtures}/pages/d.html"
document.body.appendChild webview