summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging/broadcastchannel/resources
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/webmessaging/broadcastchannel/resources
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/webmessaging/broadcastchannel/resources')
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/cross-origin.html15
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/ordering.html78
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/origin.html8
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/sandboxed.html10
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/service-worker.js15
-rw-r--r--testing/web-platform/tests/webmessaging/broadcastchannel/resources/worker.js37
6 files changed, 163 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webmessaging/broadcastchannel/resources/cross-origin.html b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/cross-origin.html
new file mode 100644
index 0000000000..5078b6fc8e
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/cross-origin.html
@@ -0,0 +1,15 @@
+<body></body>
+<script>
+ window.onload = function() {
+ bc1 = new BroadcastChannel('no-cross-origin-messages');
+ bc2 = new BroadcastChannel('no-cross-origin-messages');
+ bc2.onmessage = e => {
+ parent.postMessage('done', "*");
+ };
+ // Post a message on bc1 and once we receive it in bc2, we know that the
+ // message should have been sent to bc0 if messages were being passed
+ // across origin (assuming compliance with the spec regarding message
+ // delivery in port creation order).
+ bc1.postMessage('ignition');
+ }
+</script>
diff --git a/testing/web-platform/tests/webmessaging/broadcastchannel/resources/ordering.html b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/ordering.html
new file mode 100644
index 0000000000..b7f12d865a
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/ordering.html
@@ -0,0 +1,78 @@
+<body></body>
+<script>
+ const BC0_FIRST_MSG = 'from BC0 - first';
+ const BC1_FIRST_MSG = 'from BC1 - first';
+ const BC2_FIRST_MSG = 'from BC2 - first';
+ const BC3_FIRST_MSG = 'from BC3 - first';
+ const BC0_SECOND_MSG = 'from BC0 - second';
+ const BC1_SECOND_MSG = 'from BC1 - second';
+ const BC2_SECOND_MSG = 'from BC2 - second';
+ const BC3_SECOND_MSG = 'done';
+ const BC0_TARGET_NAME = 'BC1';
+ const BC1_TARGET_NAME = 'BC1';
+ const BC2_TARGET_NAME = 'BC2';
+ const BC3_TARGET_NAME = 'BC3';
+ const MULTI_FRAME_ORDERING_TEST_CHANNEL_NAME = 'multi-frame-order';
+
+ var bc1, bc2, bc3;
+ var sentMessageCountForBc1 = 0;
+ var sentMessageCountForBc2 = 0;
+ var sentMessageCountForBc3 = 0;
+
+ var bc1_handler = e => {
+ window.top.logReceivedMessage(BC1_TARGET_NAME, e);
+ switch(sentMessageCountForBc1) {
+ case 0:
+ bc3 = new BroadcastChannel(MULTI_FRAME_ORDERING_TEST_CHANNEL_NAME);
+ bc3.onmessage = bc3_handler;
+ bc1.postMessage(BC1_FIRST_MSG);
+ break;
+ case 1:
+ bc1.postMessage(BC1_SECOND_MSG);
+ break;
+ case 2:
+ bc1.close();
+ return;
+ }
+ sentMessageCountForBc1 += 1;
+ }
+ var bc2_handler = e => {
+ window.top.logReceivedMessage(BC2_TARGET_NAME, e);
+ switch(sentMessageCountForBc2) {
+ case 0:
+ bc2.postMessage(BC2_FIRST_MSG);
+ bc2.postMessage(BC2_SECOND_MSG);
+ sentMessageCountForBc2 += 2;
+ break;
+ case 2:
+ bc2.close();
+ return;
+ }
+ };
+ var bc3_handler = e => {
+ window.top.logReceivedMessage(BC3_TARGET_NAME, e);
+ switch(sentMessageCountForBc3) {
+ case 0:
+ bc3.postMessage(BC3_FIRST_MSG);
+ break;
+ case 1:
+ bc3.postMessage(BC3_SECOND_MSG);
+ break;
+ case 2:
+ bc3.close();
+ return;
+ }
+ sentMessageCountForBc3 += 1;
+ };
+
+ window.onload = function() {
+ const params = new URLSearchParams(window.location.search);
+ if (params.get('id') === 'iframe1') {
+ bc1 = new BroadcastChannel(MULTI_FRAME_ORDERING_TEST_CHANNEL_NAME);
+ bc1.onmessage = bc1_handler;
+ } else if (params.get('id') === 'iframe2') {
+ bc2 = new BroadcastChannel(MULTI_FRAME_ORDERING_TEST_CHANNEL_NAME);
+ bc2.onmessage = bc2_handler;
+ }
+ }
+</script>
diff --git a/testing/web-platform/tests/webmessaging/broadcastchannel/resources/origin.html b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/origin.html
new file mode 100644
index 0000000000..f57d582bbb
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/origin.html
@@ -0,0 +1,8 @@
+<script>
+const bc1 = new BroadcastChannel("ladila"),
+ bc2 = new BroadcastChannel("ladila");
+bc2.onmessage = e => {
+ parent.postMessage(e.origin, "*");
+}
+bc1.postMessage("does not matter");
+</script>
diff --git a/testing/web-platform/tests/webmessaging/broadcastchannel/resources/sandboxed.html b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/sandboxed.html
new file mode 100644
index 0000000000..e32962cdfd
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/sandboxed.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<script>
+try {
+ let c = new BroadcastChannel('foo');
+ parent.postMessage('Created', '*');
+} catch (e) {
+ parent.postMessage('Exception: ' + e.name, '*');
+}
+</script>
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);
+});
diff --git a/testing/web-platform/tests/webmessaging/broadcastchannel/resources/worker.js b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/worker.js
new file mode 100644
index 0000000000..ee2d51a254
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/broadcastchannel/resources/worker.js
@@ -0,0 +1,37 @@
+importScripts("/common/gc.js");
+
+var c;
+
+async function handler(e, reply) {
+ if (e.data.ping) {
+ c.postMessage(e.data.ping);
+ return;
+ }
+ if (e.data.blob) {
+ (() => {
+ c.postMessage({blob: new Blob(e.data.blob)});
+ })();
+ await garbageCollect();
+ }
+ c = new BroadcastChannel(e.data.channel);
+ let messages = [];
+ c.onmessage = e => {
+ if (e.data === 'ready') {
+ // Ignore any 'ready' messages from the other thread since there could
+ // be some race conditions between this BroadcastChannel instance
+ // being created / ready to receive messages and the message being sent.
+ return;
+ }
+ messages.push(e.data);
+ if (e.data == 'done')
+ reply(messages);
+ };
+ c.postMessage('from worker');
+}
+
+onmessage = e => handler(e, postMessage);
+
+onconnect = e => {
+ let port = e.ports[0];
+ port.onmessage = e => handler(e, msg => port.postMessage(msg));
+};