✅ add tests for will-navigate, did-navigate-to-different-page, did-navigate-in-page events in webview
This commit is contained in:
parent
9e2b76361f
commit
26397d9155
3 changed files with 53 additions and 0 deletions
12
spec/fixtures/pages/webview-did-navigate-in-page.html
vendored
Normal file
12
spec/fixtures/pages/webview-did-navigate-in-page.html
vendored
Normal 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>
|
11
spec/fixtures/pages/webview-will-navigate.html
vendored
Normal file
11
spec/fixtures/pages/webview-will-navigate.html
vendored
Normal 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>
|
|
@ -271,6 +271,36 @@ describe '<webview> tag', ->
|
|||
webview.src = "file://#{fixtures}/pages/a.html"
|
||||
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', ->
|
||||
it 'should fire when interior page calls window.close', (done) ->
|
||||
webview.addEventListener 'close', ->
|
||||
|
|
Loading…
Reference in a new issue