Add spec for #70.
This commit is contained in:
parent
19aa2b7979
commit
e00d3d4b37
3 changed files with 52 additions and 0 deletions
33
spec/api/window.coffee
Normal file
33
spec/api/window.coffee
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
assert = require 'assert'
|
||||||
|
fs = require 'fs'
|
||||||
|
path = require 'path'
|
||||||
|
remote = require 'remote'
|
||||||
|
BrowserWindow = remote.require 'browser-window'
|
||||||
|
|
||||||
|
fixtures = path.resolve __dirname, '..', 'fixtures'
|
||||||
|
|
||||||
|
describe 'window module', ->
|
||||||
|
describe 'BrowserWindow.close()', ->
|
||||||
|
it 'should emit unload handler', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'loading-state-changed', (event, isLoading) ->
|
||||||
|
if (!isLoading)
|
||||||
|
w.close()
|
||||||
|
w.on 'destroyed', ->
|
||||||
|
test = path.join(fixtures, 'api', 'test')
|
||||||
|
content = fs.readFileSync(test)
|
||||||
|
fs.unlinkSync(test)
|
||||||
|
assert.equal String(content), 'unload'
|
||||||
|
done()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'unload.html')
|
||||||
|
|
||||||
|
describe 'window.close()', ->
|
||||||
|
it 'should emit unload handler', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
w.on 'destroyed', ->
|
||||||
|
test = path.join(fixtures, 'api', 'close')
|
||||||
|
content = fs.readFileSync(test)
|
||||||
|
fs.unlinkSync(test)
|
||||||
|
assert.equal String(content), 'close'
|
||||||
|
done()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'close.html')
|
10
spec/fixtures/api/close.html
vendored
Normal file
10
spec/fixtures/api/close.html
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.addEventListener('unload', function (e) {
|
||||||
|
require('fs').writeFileSync(__dirname + '/test', 'close');
|
||||||
|
}, false);
|
||||||
|
window.close();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
9
spec/fixtures/api/unload.html
vendored
Normal file
9
spec/fixtures/api/unload.html
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.addEventListener('unload', function (e) {
|
||||||
|
require('fs').writeFileSync(__dirname + '/test', 'unload');
|
||||||
|
}, false);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue