summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html')
-rw-r--r--testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html35
1 files changed, 35 insertions, 0 deletions
diff --git a/testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html b/testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html
new file mode 100644
index 0000000000..bc5c9bdb83
--- /dev/null
+++ b/testing/web-platform/tests/web-locks/resources/sw-controlled-iframe.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>iframe used in clientId test</title>
+<script>
+
+self.onmessage = async event => {
+ try {
+ if (event.data === 'get_sw_client_id') {
+ // Use the controlling service worker to determine
+ // this client's id according to the Service Worker.
+ const response = await fetch('/clientId');
+ const data = await response.json();
+ window.parent.postMessage(data.clientId, '*');
+ return;
+ }
+
+ if (event.data === 'get_lock_client_id') {
+ // Grab a lock, then query the lock manager for state to
+ // determine this client's id according to the lock manager.
+ await navigator.locks.request('lock-name', async lock => {
+ const lock_state = await navigator.locks.query();
+ const held_lock = lock_state.held.filter(l => l.name === lock.name)[0];
+ window.parent.postMessage(held_lock.clientId, '*');
+ });
+ return;
+ }
+
+ window.parent.postMessage(`unknown request: ${event.data}`, '*');
+ } catch (ex) {
+ // In case of test failure, don't leave parent window hanging.
+ window.parent.postMessage(`${ex.name}: ${ex.message}`, '*');
+ }
+};
+
+</script>