2013-12-05 05:37:01 +00:00
|
|
|
assert = require 'assert'
|
2015-12-08 01:05:08 +00:00
|
|
|
ChildProcess = require 'child_process'
|
|
|
|
path = require 'path'
|
2015-11-12 10:28:04 +00:00
|
|
|
{remote} = require 'electron'
|
|
|
|
{app, BrowserWindow} = remote.require 'electron'
|
2013-12-05 05:37:01 +00:00
|
|
|
|
|
|
|
describe 'app module', ->
|
|
|
|
describe 'app.getVersion()', ->
|
|
|
|
it 'returns the version field of package.json', ->
|
|
|
|
assert.equal app.getVersion(), '0.1.0'
|
|
|
|
|
|
|
|
describe 'app.setVersion(version)', ->
|
|
|
|
it 'overrides the version', ->
|
|
|
|
assert.equal app.getVersion(), '0.1.0'
|
|
|
|
app.setVersion 'test-version'
|
|
|
|
assert.equal app.getVersion(), 'test-version'
|
2013-12-06 06:54:29 +00:00
|
|
|
app.setVersion '0.1.0'
|
2013-12-05 05:37:01 +00:00
|
|
|
|
|
|
|
describe 'app.getName()', ->
|
|
|
|
it 'returns the name field of package.json', ->
|
2015-04-14 07:59:45 +00:00
|
|
|
assert.equal app.getName(), 'Electron Test'
|
2013-12-05 05:37:01 +00:00
|
|
|
|
|
|
|
describe 'app.setName(name)', ->
|
|
|
|
it 'overrides the name', ->
|
2015-04-14 07:59:45 +00:00
|
|
|
assert.equal app.getName(), 'Electron Test'
|
2013-12-05 05:37:01 +00:00
|
|
|
app.setName 'test-name'
|
|
|
|
assert.equal app.getName(), 'test-name'
|
2015-04-21 10:55:44 +00:00
|
|
|
app.setName 'Electron Test'
|
2015-06-18 05:59:08 +00:00
|
|
|
|
2015-09-16 08:16:21 +00:00
|
|
|
describe 'app.getLocale()', ->
|
|
|
|
it 'should not be empty', ->
|
|
|
|
assert.notEqual app.getLocale(), ''
|
|
|
|
|
2015-12-08 01:05:08 +00:00
|
|
|
describe 'app.exit(exitCode)', ->
|
|
|
|
appProcess = null
|
|
|
|
afterEach ->
|
|
|
|
appProcess?.kill()
|
|
|
|
|
|
|
|
it 'emits a process exit event with the code', (done) ->
|
|
|
|
appPath = path.join(__dirname, 'fixtures', 'api', 'quit-app')
|
|
|
|
electronPath = remote.getGlobal('process').execPath
|
|
|
|
appProcess = ChildProcess.spawn(electronPath, [appPath])
|
|
|
|
|
|
|
|
output = ''
|
|
|
|
appProcess.stdout.on 'data', (data) -> output += data
|
|
|
|
appProcess.on 'close', (code) ->
|
|
|
|
assert.notEqual output.indexOf('Exit event with code: 123'), -1
|
|
|
|
assert.equal code, 123
|
|
|
|
done()
|
|
|
|
|
2015-09-14 09:02:45 +00:00
|
|
|
describe 'BrowserWindow events', ->
|
2015-06-18 05:59:08 +00:00
|
|
|
w = null
|
|
|
|
afterEach ->
|
|
|
|
w.destroy() if w?
|
|
|
|
w = null
|
2015-09-14 09:02:45 +00:00
|
|
|
|
|
|
|
it 'should emit browser-window-focus event when window is focused', (done) ->
|
2015-06-18 05:59:08 +00:00
|
|
|
app.once 'browser-window-focus', (e, window) ->
|
|
|
|
assert.equal w.id, window.id
|
2015-09-14 09:02:45 +00:00
|
|
|
done()
|
|
|
|
w = new BrowserWindow(show: false)
|
2015-06-18 08:31:55 +00:00
|
|
|
w.emit 'focus'
|
2015-09-14 09:02:45 +00:00
|
|
|
|
|
|
|
it 'should emit browser-window-blur event when window is blured', (done) ->
|
|
|
|
app.once 'browser-window-blur', (e, window) ->
|
|
|
|
assert.equal w.id, window.id
|
|
|
|
done()
|
|
|
|
w = new BrowserWindow(show: false)
|
|
|
|
w.emit 'blur'
|
|
|
|
|
|
|
|
it 'should emit browser-window-created event when window is created', (done) ->
|
|
|
|
app.once 'browser-window-created', (e, window) ->
|
|
|
|
setImmediate ->
|
|
|
|
assert.equal w.id, window.id
|
|
|
|
done()
|
|
|
|
w = new BrowserWindow(show: false)
|
|
|
|
w.emit 'blur'
|