diff --git a/spec/chromium-spec.coffee b/spec/chromium-spec.coffee index e0695b58e217..5bec7bf8a897 100644 --- a/spec/chromium-spec.coffee +++ b/spec/chromium-spec.coffee @@ -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 diff --git a/spec/fixtures/workers/shared_worker.js b/spec/fixtures/workers/shared_worker.js new file mode 100644 index 000000000000..d35b47435e8a --- /dev/null +++ b/spec/fixtures/workers/shared_worker.js @@ -0,0 +1,7 @@ +onconnect = function(event) { + var port = event.ports[0]; + port.start(); + port.onmessage = function(event) { + port.postMessage(event.data); + } +} diff --git a/spec/fixtures/workers/worker.js b/spec/fixtures/workers/worker.js new file mode 100644 index 000000000000..6f9533708a0d --- /dev/null +++ b/spec/fixtures/workers/worker.js @@ -0,0 +1,3 @@ +this.onmessage = function(msg) { + this.postMessage(msg.data); +}