Add specs for the beforeunload handler.
This commit is contained in:
parent
e423f601c0
commit
cfb957a603
5 changed files with 91 additions and 3 deletions
|
@ -21,10 +21,20 @@ describe 'window module', ->
|
||||||
done()
|
done()
|
||||||
w.loadUrl 'file://' + path.join(fixtures, 'api', 'unload.html')
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'unload.html')
|
||||||
|
|
||||||
xdescribe 'window.close()', ->
|
it 'should emit beforeunload handler', (done) ->
|
||||||
it 'should emit unload handler', (done) ->
|
|
||||||
w = new BrowserWindow(show: false)
|
w = new BrowserWindow(show: false)
|
||||||
w.on 'destroyed', ->
|
w.on 'onbeforeunload', ->
|
||||||
|
w.destroy()
|
||||||
|
done()
|
||||||
|
w.on 'loading-state-changed', (event, isLoading) ->
|
||||||
|
if (!isLoading)
|
||||||
|
w.close()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'beforeunload-false.html')
|
||||||
|
|
||||||
|
describe 'window.close()', ->
|
||||||
|
xit 'should emit unload handler', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'closed', ->
|
||||||
test = path.join(fixtures, 'api', 'close')
|
test = path.join(fixtures, 'api', 'close')
|
||||||
content = fs.readFileSync(test)
|
content = fs.readFileSync(test)
|
||||||
fs.unlinkSync(test)
|
fs.unlinkSync(test)
|
||||||
|
@ -32,6 +42,11 @@ describe 'window module', ->
|
||||||
done()
|
done()
|
||||||
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html')
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html')
|
||||||
|
|
||||||
|
it 'should emit beforeunload handler', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'onbeforeunload', done
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-true.html')
|
||||||
|
|
||||||
describe 'BrowserWindow.loadUrl(url)', ->
|
describe 'BrowserWindow.loadUrl(url)', ->
|
||||||
it 'should emit loading-state-changed event', (done) ->
|
it 'should emit loading-state-changed event', (done) ->
|
||||||
w = new BrowserWindow(show: false)
|
w = new BrowserWindow(show: false)
|
||||||
|
@ -49,3 +64,24 @@ describe 'window module', ->
|
||||||
|
|
||||||
++count
|
++count
|
||||||
w.loadUrl 'about:blank'
|
w.loadUrl 'about:blank'
|
||||||
|
|
||||||
|
describe 'beforeunload handler', ->
|
||||||
|
it 'returning true would not prevent close', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'closed', ->
|
||||||
|
done()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-true.html')
|
||||||
|
|
||||||
|
it 'returning false would prevent close', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'onbeforeunload', ->
|
||||||
|
w.destroy()
|
||||||
|
done()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')
|
||||||
|
|
||||||
|
it 'returning non-empty string would prevent close', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'onbeforeunload', ->
|
||||||
|
w.destroy()
|
||||||
|
done()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')
|
||||||
|
|
12
spec/fixtures/api/beforeunload-false.html
vendored
Normal file
12
spec/fixtures/api/beforeunload-false.html
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
setImmediate(function() {
|
||||||
|
require('remote').getCurrentWindow().emit('onbeforeunload');
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
13
spec/fixtures/api/close-beforeunload-false.html
vendored
Normal file
13
spec/fixtures/api/close-beforeunload-false.html
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
setImmediate(function() {
|
||||||
|
require('remote').getCurrentWindow().emit('onbeforeunload');
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
13
spec/fixtures/api/close-beforeunload-string.html
vendored
Normal file
13
spec/fixtures/api/close-beforeunload-string.html
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
setImmediate(function() {
|
||||||
|
require('remote').getCurrentWindow().emit('onbeforeunload');
|
||||||
|
});
|
||||||
|
return 'string';
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
14
spec/fixtures/api/close-beforeunload-true.html
vendored
Normal file
14
spec/fixtures/api/close-beforeunload-true.html
vendored
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
setImmediate(function() {
|
||||||
|
require('remote').getCurrentWindow().emit('onbeforeunload');
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue