diff options
Diffstat (limited to 'testing/web-platform/tests/service-workers/service-worker/ServiceWorkerGlobalScope/resources/postmessage-ping-worker.js')
-rw-r--r-- | testing/web-platform/tests/service-workers/service-worker/ServiceWorkerGlobalScope/resources/postmessage-ping-worker.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/testing/web-platform/tests/service-workers/service-worker/ServiceWorkerGlobalScope/resources/postmessage-ping-worker.js b/testing/web-platform/tests/service-workers/service-worker/ServiceWorkerGlobalScope/resources/postmessage-ping-worker.js new file mode 100644 index 0000000000..ebb1eccce2 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/ServiceWorkerGlobalScope/resources/postmessage-ping-worker.js @@ -0,0 +1,15 @@ +self.addEventListener('message', function(event) { + if ('port' in event.data) { + var port = event.data.port; + + var channel = new MessageChannel(); + channel.port1.onmessage = function(event) { + if ('pong' in event.data) + port.postMessage(event.data.pong); + }; + + // Send a ping message to another service worker. + self.registration.waiting.postMessage({ping: channel.port2}, + [channel.port2]); + } + }); |