summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_postMessage_originAttributes.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/test_postMessage_originAttributes.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/test_postMessage_originAttributes.html')
-rw-r--r--dom/base/test/test_postMessage_originAttributes.html53
1 files changed, 53 insertions, 0 deletions
diff --git a/dom/base/test/test_postMessage_originAttributes.html b/dom/base/test/test_postMessage_originAttributes.html
new file mode 100644
index 0000000000..7dab671ec1
--- /dev/null
+++ b/dom/base/test/test_postMessage_originAttributes.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Test window.postMessages from system principal to window with non-default originAttributes</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+
+<body>
+<iframe id="target-iframe"></iframe>
+<script type="application/javascript">
+
+add_task(async function() {
+ let iframe = document.querySelector("#target-iframe");
+
+ let win = SpecialPowers.wrap(iframe).contentWindow;
+ let docShell = win.docShell;
+
+ // Add private browsing ID to docShell origin and load document.
+ docShell.setOriginAttributes({privateBrowsingId: 1});
+
+ await new Promise(resolve => {
+ iframe.addEventListener("load", resolve, true);
+
+ iframe.src = SimpleTest.getTestFileURL("file_receiveMessage.html");
+ });
+
+ // Set up console monitor to wait for warning.
+ const expectedMessage = (
+ 'Attempting to post a message to window with url ' +
+ '"http://mochi.test:8888/tests/dom/base/test/file_receiveMessage.html" ' +
+ 'and origin "http://mochi.test:8888^privateBrowsingId=1" from a system ' +
+ 'principal scope with mismatched origin "[System Principal]".');
+
+ let consolePromise = new Promise(resolve => {
+ SimpleTest.monitorConsole(resolve, [e => e.message == expectedMessage]);
+ });
+
+ // Post to the content window via SpecialPowers' system principal scope.
+ win.postMessage("Hello. o/", "http://mochi.test:8888");
+ await new Promise(resolve => setTimeout(resolve, 0));
+
+ SimpleTest.endMonitorConsole();
+ await consolePromise;
+
+ // Check that the window received and handled the message.
+ is(win.document.body.textContent, "|Hello. o/",
+ "Content window received the expected message");
+});
+</script>
+</body>
+</html>
+