Add specs for web workers.
This commit is contained in:
parent
7b93a19e9b
commit
d81a34d3dd
3 changed files with 28 additions and 0 deletions
|
@ -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
|
||||
|
|
7
spec/fixtures/workers/shared_worker.js
vendored
Normal file
7
spec/fixtures/workers/shared_worker.js
vendored
Normal 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
3
spec/fixtures/workers/worker.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
this.onmessage = function(msg) {
|
||||
this.postMessage(msg.data);
|
||||
}
|
Loading…
Reference in a new issue