summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js')
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js
new file mode 100644
index 0000000000..a3d17b9c65
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js
@@ -0,0 +1,15 @@
+let promise_func = null;
+let promise = new Promise(resolve => promise_func = resolve);
+
+const SERVICE_WORKER_TEST_CHANNEL_NAME = 'service worker';
+const bc3 = new BroadcastChannel(SERVICE_WORKER_TEST_CHANNEL_NAME);
+bc3.onmessage = e => {
+ bc3.postMessage('done');
+ promise_func();
+};
+bc3.postMessage('from worker');
+
+// Ensure that the worker stays alive for the duration of the test
+self.addEventListener('install', evt => {
+ evt.waitUntil(promise);
+});