summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging/multi-globals
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/webmessaging/multi-globals
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webmessaging/multi-globals')
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-current.sub.html45
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-incumbent.sub.html34
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/messageport-current.html39
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/messageport-incumbent.html35
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/support/current-document-domain.sub.html10
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/support/current.html5
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/support/incumbent-document-domain.sub.html14
-rw-r--r--testing/web-platform/tests/webmessaging/multi-globals/support/incumbent.html13
8 files changed, 195 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-current.sub.html b/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-current.sub.html
new file mode 100644
index 0000000000..ae2369394e
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-current.sub.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>The current page being cross-origin must prevent the BroadcastChannel message from being seen</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<!-- This is the entry global -->
+
+<iframe src="support/incumbent-document-domain.sub.html" id="incumbent"></iframe>
+<iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/current-document-domain.sub.html" id="current"></iframe>
+
+<script>
+"use strict";
+document.domain = "{{hosts[][]}}";
+
+setup({ explicit_done: true });
+
+const incumbentIframe = document.querySelector("#incumbent");
+const currentIframe = document.querySelector("#current");
+
+window.onload = () => {
+ promise_test(async t => {
+ const createdCrossOrigin = frames[0].createBroadcastChannel("current");
+ const createdSameOrigin = new BroadcastChannel("current");
+
+ createdSameOrigin.onmessage = t.unreached_func("message event fired");
+ createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired");
+
+ createdCrossOrigin.postMessage("the message");
+
+ // BroadcastChannel messages are guaranteed to be ordered within an event loop, as they all use
+ // the DOM manipulation task source. So, any messages from the "current" channel, if they are
+ // going to be erroneously delivered, would have to be delivered before those from this
+ // channel. I.e., if we recieve a message from this channel without first recieving one from
+ // the "current" channel, then the test passes.
+ const testEnder = new BroadcastChannel("current / test-ender");
+ const testEnder2 = new BroadcastChannel("current / test-ender");
+
+ testEnder.postMessage("end test");
+ await new Promise(resolve => testEnder2.onmessage = resolve);
+ });
+
+ done();
+};
+</script>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-incumbent.sub.html b/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-incumbent.sub.html
new file mode 100644
index 0000000000..31a4221c1d
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/broadcastchannel-incumbent.sub.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>The incumbent page being cross-origin must not prevent the BroadcastChannel message from being seen</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<!-- This is the entry global -->
+
+<iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/incumbent-document-domain.sub.html" id="incumbent"></iframe>
+<iframe src="support/current-document-domain.sub.html" id="current"></iframe>
+
+<script>
+"use strict";
+document.domain = "{{hosts[][]}}";
+
+setup({ explicit_done: true });
+
+const incumbentIframe = document.querySelector("#incumbent");
+const currentIframe = document.querySelector("#current");
+
+window.onload = () => {
+ async_test(t => {
+ const createdThroughCrossOrigin = frames[0].createBroadcastChannel("incumbent");
+ const createdSameOrigin = new BroadcastChannel("incumbent");
+
+ createdSameOrigin.onmessage = () => t.done();
+ createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired");
+
+ createdThroughCrossOrigin.postMessage("the message");
+ });
+
+ done();
+};
+</script>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/messageport-current.html b/testing/web-platform/tests/webmessaging/multi-globals/messageport-current.html
new file mode 100644
index 0000000000..ee172c6138
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/messageport-current.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Making the current page become non-active must prevent message transmission</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<!-- This is the entry global -->
+
+<iframe src="support/incumbent.html" id="incumbent"></iframe>
+<iframe src="support/current.html" id="current"></iframe>
+
+<script>
+"use strict";
+const incumbentIframe = document.querySelector("#incumbent");
+const currentIframe = document.querySelector("#current");
+
+window.addEventListener("load", () => {
+ promise_test(async t => {
+ // This will invoke the constructor from currentIframe, but with incumbentIframe as the incumbent.
+ const messageChannel = incumbentIframe.contentWindow.createMessageChannel();
+
+ await new Promise((resolve, reject) => {
+ currentIframe.onload = () => resolve();
+ currentIframe.onerror = () => reject(new Error("Could not navigate the iframe"));
+ currentIframe.src = "/common/blank.html";
+ });
+
+ messageChannel.port1.onmessage = t.unreached_func("message event recieved");
+ messageChannel.port1.onmessageerror = t.unreached_func("messageerror event recieved");
+ messageChannel.port2.postMessage("boo");
+
+ // We are testing that neither of the above two events fire. We assume that a 3 second timeout
+ // is good enough. We can't use any other API for an end condition because each MessagePort has
+ // its own independent port message queue, which has no ordering guarantees relative to other
+ // APIs.
+ await new Promise(resolve => t.step_timeout(resolve, 3000));
+ });
+});
+</script>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/messageport-incumbent.html b/testing/web-platform/tests/webmessaging/multi-globals/messageport-incumbent.html
new file mode 100644
index 0000000000..4d47fb8124
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/messageport-incumbent.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Making the incumbent page become non-active must not prevent message transmission</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<!-- This is the entry global -->
+
+<iframe src="support/incumbent.html" id="incumbent"></iframe>
+<iframe src="support/current.html" id="current"></iframe>
+
+<script>
+"use strict";
+const incumbentIframe = document.querySelector("#incumbent");
+const currentIframe = document.querySelector("#current");
+
+window.addEventListener("load", () => {
+ promise_test(async () => {
+ // This will invoke the constructor from currentIframe, but with incumbentIframe as the incumbent.
+ const messageChannel = incumbentIframe.contentWindow.createMessageChannel();
+
+ await new Promise((resolve, reject) => {
+ incumbentIframe.onload = () => resolve();
+ incumbentIframe.onerror = () => reject(new Error("Could not navigate the iframe"));
+ incumbentIframe.src = "/common/blank.html";
+ });
+
+ await new Promise((resolve, reject) => {
+ messageChannel.port1.onmessage = () => resolve();
+ messageChannel.port1.onmessageerror = () => reject("messageerror event recieved");
+ messageChannel.port2.postMessage("boo");
+ });
+ });
+});
+</script>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/support/current-document-domain.sub.html b/testing/web-platform/tests/webmessaging/multi-globals/support/current-document-domain.sub.html
new file mode 100644
index 0000000000..1b15f72ca4
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/support/current-document-domain.sub.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Current page used as a test helper</title>
+
+<h1>Current</h1>
+
+<script>
+"use strict";
+document.domain = "{{hosts[][]}}";
+</script>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/support/current.html b/testing/web-platform/tests/webmessaging/multi-globals/support/current.html
new file mode 100644
index 0000000000..d05709dd43
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/support/current.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Current page used as a test helper</title>
+
+<h1>Current</h1>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/support/incumbent-document-domain.sub.html b/testing/web-platform/tests/webmessaging/multi-globals/support/incumbent-document-domain.sub.html
new file mode 100644
index 0000000000..4791c29be7
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/support/incumbent-document-domain.sub.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Incumbent page used as a test helper</title>
+
+<h1>Incumbent</h1>
+
+<script>
+"use strict";
+document.domain = "{{hosts[][]}}";
+
+window.createBroadcastChannel = (...args) => {
+ return new parent.frames[1].BroadcastChannel(...args);
+};
+</script>
diff --git a/testing/web-platform/tests/webmessaging/multi-globals/support/incumbent.html b/testing/web-platform/tests/webmessaging/multi-globals/support/incumbent.html
new file mode 100644
index 0000000000..a06e93c7ab
--- /dev/null
+++ b/testing/web-platform/tests/webmessaging/multi-globals/support/incumbent.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Incumbent page used as a test helper</title>
+
+<h1>Incumbent</h1>
+
+<script>
+"use strict";
+
+window.createMessageChannel = () => {
+ return new parent.frames[1].MessageChannel();
+};
+</script>