summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/bugs/test_postmessage.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/tests/mochitest/bugs/test_postmessage.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/tests/mochitest/bugs/test_postmessage.html')
-rw-r--r--dom/tests/mochitest/bugs/test_postmessage.html65
1 files changed, 65 insertions, 0 deletions
diff --git a/dom/tests/mochitest/bugs/test_postmessage.html b/dom/tests/mochitest/bugs/test_postmessage.html
new file mode 100644
index 0000000000..8dee4ec4a5
--- /dev/null
+++ b/dom/tests/mochitest/bugs/test_postmessage.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 1574017</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/ChromeTask.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+ <script type="application/javascript">
+ async function waitForErrorMessage(err) {
+ return ChromeTask.spawn(err, async err => {
+ await new Promise(resolve => {
+ let console = Services.console;
+ console.reset();
+ console.registerListener(function listener(aMessage) {
+ var sourceName = `http://mochi.test:8888/tests/dom/tests/mochitest/bugs/test_postmessage.html`;
+ if (
+ aMessage.message.includes(err) &&
+ aMessage instanceof Ci.nsIScriptError &&
+ aMessage.sourceName == sourceName
+ ) {
+ console.unregisterListener(listener);
+ resolve();
+ }
+ });
+ });
+ });
+ }
+ add_task(async function testNoCallerURI() {
+ var Cu = SpecialPowers.Cu;
+ var princ = SpecialPowers.wrap(window.document).nodePrincipal;
+ var sandbox = Cu.Sandbox(princ, { sameZoneAs: this });
+ SpecialPowers.unwrap(sandbox).win = window.frames.diffDomain;
+ var err = `Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://example.com’) does not match the recipient window’s origin (‘https://example.org’).`;
+ let consolePromise = waitForErrorMessage(err);
+ Cu.evalInSandbox(
+ 'win.postMessage("We should not be able to post this message", "https://example.com");',
+ sandbox
+ );
+ await consolePromise;
+ ok(true, "Error message was logged correctly to the console");
+ Cu.nukeSandbox(sandbox);
+ });
+ add_task(async function testWithWindowID() {
+ var err = `Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://example.ru’) does not match the recipient window’s origin (‘https://example.org’).`;
+ let consolePromise = waitForErrorMessage(err);
+ window.frames.diffDomain.postMessage(
+ "The window should not receive this",
+ "https://example.ru"
+ );
+ await consolePromise;
+ ok(true, "Error message was logged correctly to the console");
+ });
+ </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1574017">Mozilla Bug 1574017</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+<iframe id="diffDomain" name="diffDomain" src="https://example.org/tests/dom/tests/mochitest/bugs/file_empty.html"></iframe>
+</body>
+</html>