2013-08-24 08:38:19 +00:00
|
|
|
assert = require 'assert'
|
2013-08-25 04:36:06 +00:00
|
|
|
ipc = require 'ipc'
|
2013-08-24 08:38:19 +00:00
|
|
|
protocol = require('remote').require 'protocol'
|
|
|
|
|
|
|
|
describe 'protocol API', ->
|
|
|
|
describe 'protocol.registerProtocol', ->
|
|
|
|
it 'throws error when scheme is already registered', ->
|
2013-08-24 12:18:12 +00:00
|
|
|
register = -> protocol.registerProtocol('test1', ->)
|
2013-08-24 08:38:19 +00:00
|
|
|
register()
|
|
|
|
assert.throws register, /The scheme is already registered/
|
2013-08-24 12:18:12 +00:00
|
|
|
protocol.unregisterProtocol 'test1'
|
|
|
|
|
|
|
|
it 'calls the callback when scheme is visited', (done) ->
|
2013-08-25 07:07:07 +00:00
|
|
|
protocol.registerProtocol 'test2', (url) ->
|
|
|
|
assert.equal url, 'test2://test2'
|
|
|
|
done()
|
2013-08-24 12:18:12 +00:00
|
|
|
$.get 'test2://test2', ->
|
|
|
|
protocol.unregisterProtocol 'test2'
|
2013-08-24 08:38:19 +00:00
|
|
|
|
|
|
|
describe 'protocol.unregisterProtocol', ->
|
|
|
|
it 'throws error when scheme does not exist', ->
|
2013-08-24 12:18:12 +00:00
|
|
|
unregister = -> protocol.unregisterProtocol 'test3'
|
2013-08-24 08:38:19 +00:00
|
|
|
assert.throws unregister, /The scheme has not been registered/
|
2013-08-25 04:36:06 +00:00
|
|
|
|
|
|
|
describe 'registered protocol callback', ->
|
|
|
|
it 'returns string should send the string as request content', (done) ->
|
|
|
|
$.ajax
|
|
|
|
url: 'atom-string://something'
|
|
|
|
success: (data) ->
|
|
|
|
assert.equal data, 'atom-string://something'
|
|
|
|
done()
|
|
|
|
error: (xhr, errorType, error) ->
|
2013-08-25 07:07:07 +00:00
|
|
|
assert false, 'Got error: ' + errorType + ' ' + error
|
|
|
|
|
|
|
|
it 'returns RequestStringJob should send string', (done) ->
|
|
|
|
$.ajax
|
|
|
|
url: 'atom-string-job://something'
|
|
|
|
success: (data) ->
|
|
|
|
assert.equal data, 'atom-string-job://something'
|
|
|
|
done()
|
|
|
|
error: (xhr, errorType, error) ->
|
|
|
|
assert false, 'Got error: ' + errorType + ' ' + error
|