add tests for will-navigate, did-navigate-to-different-page, did-navigate-in-page events in webview

This commit is contained in:
leethomas 2016-01-01 18:13:07 -08:00
parent 9e2b76361f
commit 26397d9155
3 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,12 @@
<html>
<body>
<a href="#test_content" id="test_link">Click me.</a>
<span id="test_content">This is content.</span>
<script type="text/javascript">
onload = function() {
var a = document.getElementById('test_link');
a.click();
}
</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<html>
<body>
<a id="test_link" href="http://host/">Test</a>
<script type="text/javascript">
onload = function() {
var a = document.getElementById('test_link');
a.click();
}
</script>
</body>
</html>

View file

@ -271,6 +271,36 @@ describe '<webview> tag', ->
webview.src = "file://#{fixtures}/pages/a.html" webview.src = "file://#{fixtures}/pages/a.html"
document.body.appendChild webview document.body.appendChild webview
describe 'will-navigate event', ->
it 'emits when a url that leads to oustide of the page is clicked', (done) ->
webview.addEventListener 'will-navigate', (e) ->
assert.equal e.url, "http://host/"
done()
webview.src = "file://#{fixtures}/pages/webview-will-navigate.html"
document.body.appendChild webview
describe 'did-navigate-to-different-page event', ->
page_url = "file://#{fixtures}/pages/webview-will-navigate.html"
it 'emits when a url that leads to outside of the page is clicked', (done) ->
webview.addEventListener 'did-navigate-to-different-page', (e) ->
assert.equal e.url, page_url
done()
webview.src = page_url
document.body.appendChild webview
describe 'did-navigate-in-page event', ->
it 'emits when an anchor link is clicked', (done) ->
page_url = "file://#{fixtures}/pages/webview-did-navigate-in-page.html"
webview.addEventListener 'did-navigate-in-page', (e) ->
assert.equal e.url, "#{page_url}#test_content"
done()
webview.src = page_url
document.body.appendChild webview
describe 'close event', -> describe 'close event', ->
it 'should fire when interior page calls window.close', (done) -> it 'should fire when interior page calls window.close', (done) ->
webview.addEventListener 'close', -> webview.addEventListener 'close', ->