<!DOCTYPEHTML>
<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>
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.40 Sekunden
(vorverarbeitet am 2026-06-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.