Add specs for web workers.

This commit is contained in:
Cheng Zhao 2014-07-09 15:55:01 +08:00
parent 7b93a19e9b
commit d81a34d3dd
3 changed files with 28 additions and 0 deletions

View file

@ -75,3 +75,21 @@ describe 'chromium feature', ->
return if process.platform is 'linux'
webgl = document.createElement('canvas').getContext 'webgl'
assert.notEqual webgl, null
describe 'web workers', ->
it 'Worker can work', (done) ->
worker = new Worker('../fixtures/workers/worker.js')
message = 'ping'
worker.onmessage = (event) ->
assert.equal event.data, message
worker.terminate()
done()
worker.postMessage message
it 'SharedWorker can work', (done) ->
worker = new SharedWorker('../fixtures/workers/shared_worker.js')
message = 'ping'
worker.port.onmessage = (event) ->
assert.equal event.data, message
done()
worker.port.postMessage message

View file

@ -0,0 +1,7 @@
onconnect = function(event) {
var port = event.ports[0];
port.start();
port.onmessage = function(event) {
port.postMessage(event.data);
}
}

3
spec/fixtures/workers/worker.js vendored Normal file
View file

@ -0,0 +1,3 @@
this.onmessage = function(msg) {
this.postMessage(msg.data);
}