summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fenced-frame/resources/background-sync-sw.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/fenced-frame/resources/background-sync-sw.js')
-rw-r--r--testing/web-platform/tests/fenced-frame/resources/background-sync-sw.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fenced-frame/resources/background-sync-sw.js b/testing/web-platform/tests/fenced-frame/resources/background-sync-sw.js
new file mode 100644
index 0000000000..5b0c791f0d
--- /dev/null
+++ b/testing/web-platform/tests/fenced-frame/resources/background-sync-sw.js
@@ -0,0 +1,21 @@
+import {getOneShotSyncPromise, getPeriodicSyncPromise} from './background-sync-helper.js';
+
+self.addEventListener('install', e => e.waitUntil(skipWaiting()));
+self.addEventListener('activate', e => e.waitUntil(clients.claim()));
+
+self.addEventListener('message', async e => {
+ const {method, isPeriodic} = e.data;
+ const promise = isPeriodic ?
+ getPeriodicSyncPromise(self.registration, method) :
+ getOneShotSyncPromise(self.registration, method);
+ const message =
+ await promise
+ .then(() => {
+ return `[background synnc ${method}] Unexpectedly started`;
+ })
+ .catch((e) => {
+ return e.message;
+ });
+
+ e.source.postMessage(message);
+});