2013-07-23 03:59:07 +00:00
|
|
|
assert = require 'assert'
|
2013-12-06 14:23:02 +00:00
|
|
|
ipc = require 'ipc'
|
|
|
|
path = require 'path'
|
2013-07-23 03:59:07 +00:00
|
|
|
remote = require 'remote'
|
2013-09-26 03:27:09 +00:00
|
|
|
|
2013-12-06 14:23:02 +00:00
|
|
|
BrowserWindow = remote.require 'browser-window'
|
2013-07-23 03:59:07 +00:00
|
|
|
|
2013-12-06 14:23:02 +00:00
|
|
|
describe 'ipc module', ->
|
|
|
|
fixtures = path.join __dirname, 'fixtures'
|
2013-08-14 05:27:50 +00:00
|
|
|
|
2013-07-23 03:59:07 +00:00
|
|
|
describe 'remote.require', ->
|
|
|
|
it 'should returns same object for the same module', ->
|
|
|
|
dialog1 = remote.require 'dialog'
|
|
|
|
dialog2 = remote.require 'dialog'
|
|
|
|
assert.equal dialog1, dialog2
|
2013-07-26 07:53:00 +00:00
|
|
|
|
|
|
|
it 'should work when object contains id property', ->
|
2013-08-14 05:27:50 +00:00
|
|
|
a = remote.require path.join(fixtures, 'module', 'id.js')
|
2013-07-26 07:53:00 +00:00
|
|
|
assert.equal a.id, 1127
|
|
|
|
|
2013-08-25 09:22:36 +00:00
|
|
|
describe 'remote.createFunctionWithReturnValue', ->
|
|
|
|
it 'should be called in browser synchronously', ->
|
|
|
|
buf = new Buffer('test')
|
|
|
|
call = remote.require path.join(fixtures, 'module', 'call.js')
|
|
|
|
result = call.call remote.createFunctionWithReturnValue(buf)
|
|
|
|
assert.equal result.constructor.name, 'Buffer'
|
|
|
|
|
|
|
|
describe 'remote object in renderer', ->
|
2013-08-14 05:27:50 +00:00
|
|
|
it 'can change its properties', ->
|
|
|
|
property = remote.require path.join(fixtures, 'module', 'property.js')
|
|
|
|
assert.equal property.property, 1127
|
|
|
|
property.property = 1007
|
|
|
|
assert.equal property.property, 1007
|
|
|
|
property2 = remote.require path.join(fixtures, 'module', 'property.js')
|
|
|
|
assert.equal property2.property, 1007
|
|
|
|
|
2013-08-14 13:19:26 +00:00
|
|
|
# Restore.
|
|
|
|
property.property = 1127
|
|
|
|
|
2013-08-25 12:44:52 +00:00
|
|
|
it 'can construct an object from its member', ->
|
|
|
|
call = remote.require path.join(fixtures, 'module', 'call.js')
|
|
|
|
obj = new call.constructor
|
|
|
|
assert.equal obj.test, 'test'
|
|
|
|
|
2013-08-25 09:22:36 +00:00
|
|
|
describe 'remote value in browser', ->
|
|
|
|
it 'keeps its constructor name for objects', ->
|
|
|
|
buf = new Buffer('test')
|
|
|
|
print_name = remote.require path.join(fixtures, 'module', 'print_name.js')
|
|
|
|
assert.equal print_name.print(buf), 'Buffer'
|
|
|
|
|
2013-07-26 07:53:00 +00:00
|
|
|
describe 'ipc.send', ->
|
|
|
|
it 'should work when sending an object containing id property', (done) ->
|
|
|
|
obj = id: 1, name: 'ly'
|
2013-09-22 04:06:41 +00:00
|
|
|
ipc.once 'message', (message) ->
|
2013-07-26 07:53:00 +00:00
|
|
|
assert.deepEqual message, obj
|
|
|
|
done()
|
|
|
|
ipc.send obj
|
2013-09-22 04:06:41 +00:00
|
|
|
|
|
|
|
describe 'ipc.sendSync', ->
|
|
|
|
it 'can be replied by setting event.returnValue', ->
|
|
|
|
msg = ipc.sendChannelSync 'echo', 'test'
|
|
|
|
assert.equal msg, 'test'
|
2013-09-26 03:27:09 +00:00
|
|
|
|
2014-04-17 09:14:05 +00:00
|
|
|
it 'does not crash when reply is not sent and browser is destroyed', (done) ->
|
2013-09-26 03:27:09 +00:00
|
|
|
w = new BrowserWindow(show: false)
|
|
|
|
remote.require('ipc').once 'send-sync-message', (event) ->
|
|
|
|
event.returnValue = null
|
|
|
|
w.destroy()
|
|
|
|
done()
|
|
|
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'send-sync-message.html')
|