spec: Test user agent in websocket

This commit is contained in:
Cheng Zhao 2015-07-14 11:38:30 -07:00
parent 3ffd774405
commit 56dfef8d0d
2 changed files with 25 additions and 1 deletions

View file

@ -2,6 +2,7 @@ assert = require 'assert'
http = require 'http'
https = require 'https'
path = require 'path'
ws = require 'ws'
describe 'chromium feature', ->
fixtures = path.resolve __dirname, 'fixtures'
@ -88,3 +89,25 @@ describe 'chromium feature', ->
navigator.webkitPersistentStorage.requestQuota 1024 * 1024, (grantedBytes) ->
assert.equal grantedBytes, 1048576
done()
describe 'websockets', ->
wss = null
server = null
WebSocketServer = ws.Server
afterEach ->
wss.close()
server.close()
it 'has user agent', (done) ->
server = http.createServer()
server.listen 0, '127.0.0.1', ->
port = server.address().port
wss = new WebSocketServer(server: server)
wss.on 'error', done
wss.on 'connection', (ws) ->
if ws.upgradeReq.headers['user-agent']
done()
else
done('user agent is empty')
websocket = new WebSocket("ws://127.0.0.1:#{port}")

View file

@ -11,6 +11,7 @@
"q": "0.9.7",
"runas": "2.x",
"temp": "0.8.1",
"walkdir": "0.0.7"
"walkdir": "0.0.7",
"ws": "0.7.2"
}
}