Make sure protocol module's specs do not pollute main.js.
This commit is contained in:
parent
9e16e41bb3
commit
0f6617ec26
2 changed files with 25 additions and 23 deletions
|
@ -1,6 +1,7 @@
|
||||||
assert = require 'assert'
|
assert = require 'assert'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc'
|
||||||
protocol = require('remote').require 'protocol'
|
remote = require 'remote'
|
||||||
|
protocol = remote.require 'protocol'
|
||||||
|
|
||||||
describe 'protocol API', ->
|
describe 'protocol API', ->
|
||||||
describe 'protocol.registerProtocol', ->
|
describe 'protocol.registerProtocol', ->
|
||||||
|
@ -24,29 +25,47 @@ describe 'protocol API', ->
|
||||||
|
|
||||||
describe 'registered protocol callback', ->
|
describe 'registered protocol callback', ->
|
||||||
it 'returns string should send the string as request content', (done) ->
|
it 'returns string should send the string as request content', (done) ->
|
||||||
|
handler = remote.createFunctionWithReturnValue 'valar morghulis'
|
||||||
|
protocol.registerProtocol 'atom-string', handler
|
||||||
|
|
||||||
$.ajax
|
$.ajax
|
||||||
url: 'atom-string://something'
|
url: 'atom-string://fake-host'
|
||||||
success: (data) ->
|
success: (data) ->
|
||||||
assert.equal data, 'atom-string://something'
|
assert.equal data, handler()
|
||||||
|
protocol.unregisterProtocol 'atom-string'
|
||||||
done()
|
done()
|
||||||
error: (xhr, errorType, error) ->
|
error: (xhr, errorType, error) ->
|
||||||
assert false, 'Got error: ' + errorType + ' ' + error
|
assert false, 'Got error: ' + errorType + ' ' + error
|
||||||
|
protocol.unregisterProtocol 'atom-string'
|
||||||
|
|
||||||
it 'returns RequestStringJob should send string', (done) ->
|
it 'returns RequestStringJob should send string', (done) ->
|
||||||
|
data = 'valar morghulis'
|
||||||
|
job = new protocol.RequestStringJob(mimeType: 'text/html', data: data)
|
||||||
|
handler = remote.createFunctionWithReturnValue job
|
||||||
|
protocol.registerProtocol 'atom-string-job', handler
|
||||||
|
|
||||||
$.ajax
|
$.ajax
|
||||||
url: 'atom-string-job://something'
|
url: 'atom-string-job://fake-host'
|
||||||
success: (data) ->
|
success: (response) ->
|
||||||
assert.equal data, 'atom-string-job://something'
|
assert.equal response, data
|
||||||
|
protocol.unregisterProtocol 'atom-string-job'
|
||||||
done()
|
done()
|
||||||
error: (xhr, errorType, error) ->
|
error: (xhr, errorType, error) ->
|
||||||
assert false, 'Got error: ' + errorType + ' ' + error
|
assert false, 'Got error: ' + errorType + ' ' + error
|
||||||
|
protocol.unregisterProtocol 'atom-string-job'
|
||||||
|
|
||||||
it 'returns RequestFileJob should send file', (done) ->
|
it 'returns RequestFileJob should send file', (done) ->
|
||||||
|
job = new protocol.RequestFileJob(__filename)
|
||||||
|
handler = remote.createFunctionWithReturnValue job
|
||||||
|
protocol.registerProtocol 'atom-file-job', handler
|
||||||
|
|
||||||
$.ajax
|
$.ajax
|
||||||
url: 'atom-file-job://' + __filename
|
url: 'atom-file-job://' + __filename
|
||||||
success: (data) ->
|
success: (data) ->
|
||||||
content = require('fs').readFileSync __filename
|
content = require('fs').readFileSync __filename
|
||||||
assert.equal data, String(content)
|
assert.equal data, String(content)
|
||||||
|
protocol.unregisterProtocol 'atom-file-job'
|
||||||
done()
|
done()
|
||||||
error: (xhr, errorType, error) ->
|
error: (xhr, errorType, error) ->
|
||||||
assert false, 'Got error: ' + errorType + ' ' + error
|
assert false, 'Got error: ' + errorType + ' ' + error
|
||||||
|
protocol.unregisterProtocol 'atom-file-job'
|
||||||
|
|
17
spec/main.js
17
spec/main.js
|
@ -34,23 +34,6 @@ app.on('window-all-closed', function() {
|
||||||
app.terminate();
|
app.terminate();
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('will-finish-launching', function() {
|
|
||||||
// Reigster some protocols, used by the protocol spec.
|
|
||||||
// FIXME(zcbenz): move this to somewhere else.
|
|
||||||
var protocol = require('protocol');
|
|
||||||
protocol.registerProtocol('atom-string', function(url) {
|
|
||||||
return url;
|
|
||||||
});
|
|
||||||
|
|
||||||
protocol.registerProtocol('atom-string-job', function(url) {
|
|
||||||
return new protocol.RequestStringJob({mimeType: 'text/html', data: url});
|
|
||||||
});
|
|
||||||
|
|
||||||
protocol.registerProtocol('atom-file-job', function(url) {
|
|
||||||
return new protocol.RequestFileJob(url.substr(16));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
app.on('finish-launching', function() {
|
app.on('finish-launching', function() {
|
||||||
window = new BrowserWindow({
|
window = new BrowserWindow({
|
||||||
title: 'atom-shell tests',
|
title: 'atom-shell tests',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue