mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 19:47:17 +02:00
Tests/LibWeb: Import some MessageEvent Origin API tests
This commit is contained in:
committed by
Shannon Booth
parent
c5465e7ef1
commit
fa1c046e68
Notes:
github-actions[bot]
2026-03-23 21:33:55 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/fa1c046e680 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8458
@@ -0,0 +1,8 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>`Origin.from(MessageEvent)` from opaque origins.</title>
|
||||
<script src="../../../../resources/testharness.js"></script>
|
||||
<script src="../../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../../common/get-host-info.sub.js"></script>
|
||||
<div id=log></div>
|
||||
<script src="../../../../html/browsers/origin/api/origin-from-messageevent-opaque.window.js"></script>
|
||||
@@ -0,0 +1,68 @@
|
||||
// META: title=`Origin.from(MessageEvent)` from opaque origins.
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
||||
async_test(t => {
|
||||
const el = document.createElement('iframe');
|
||||
el.sandbox = "allow-scripts";
|
||||
el.srcdoc = `<script>window.top.postMessage("Hi.", "*");<\/script>`;
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === el.contentWindow) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_true(origin.opaque);
|
||||
t.done();
|
||||
}
|
||||
}));
|
||||
document.body.appendChild(el);
|
||||
}, `Origin.from(MessageEvent) returns an opaque origin for a sandboxed frame.`);
|
||||
|
||||
async_test(t => {
|
||||
const el = document.createElement('iframe');
|
||||
el.sandbox = "allow-scripts";
|
||||
el.srcdoc = `
|
||||
<script>
|
||||
window.top.postMessage("Hi.", "*");
|
||||
window.top.postMessage("Bye.", "*");
|
||||
<\/script>`;
|
||||
let eventOrigin = null;
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === el.contentWindow) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_true(origin.opaque);
|
||||
if (eventOrigin) {
|
||||
assert_true(eventOrigin.isSameOrigin(origin));
|
||||
t.done();
|
||||
} else {
|
||||
eventOrigin = origin;
|
||||
}
|
||||
}
|
||||
}));
|
||||
document.body.appendChild(el);
|
||||
}, `Origin.from(MessageEvent) returns the same opaque origin for each message from a sandboxed frame.`);
|
||||
|
||||
async_test(t => {
|
||||
const el = document.createElement('iframe');
|
||||
el.sandbox = "allow-scripts";
|
||||
el.srcdoc = `
|
||||
<script>
|
||||
window.top.postMessage("Hi.", "*");
|
||||
window.addEventListener("message", e => { navigation.reload(); });
|
||||
<\/script>`;
|
||||
let eventOrigin = null;
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === el.contentWindow) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_true(origin.opaque);
|
||||
if (eventOrigin) {
|
||||
assert_false(eventOrigin.isSameOrigin(origin));
|
||||
t.done();
|
||||
} else {
|
||||
eventOrigin = origin;
|
||||
e.source.postMessage("Reload thyself.", "*");
|
||||
}
|
||||
}
|
||||
}));
|
||||
document.body.appendChild(el);
|
||||
}, `Origin.from(MessageEvent) returns distinct opaque origins for each message from a reloaded sandboxed frame.`);
|
||||
@@ -0,0 +1,8 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>`Origin.from(MessageEvent)`</title>
|
||||
<script src="../../../../resources/testharness.js"></script>
|
||||
<script src="../../../../resources/testharnessreport.js"></script>
|
||||
<script src="../../../../common/get-host-info.sub.js"></script>
|
||||
<div id=log></div>
|
||||
<script src="../../../../html/browsers/origin/api/origin-from-messageevent.window.js"></script>
|
||||
@@ -0,0 +1,80 @@
|
||||
// META: title=`Origin.from(MessageEvent)`
|
||||
// META: script=/common/get-host-info.sub.js
|
||||
|
||||
console.log("hi")
|
||||
test(t => {
|
||||
const e = new MessageEvent("message", { origin: get_host_info().ORIGIN });
|
||||
assert_throws_js(TypeError, _ => Origin.from(e));
|
||||
}, "Constructed `MessageEvent` objects have no real origins.");
|
||||
|
||||
async_test(t => {
|
||||
const el = document.createElement('iframe');
|
||||
el.src = "/html/browsers/windows/resources/message-parent.html"
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === el.contentWindow) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_false(origin.opaque);
|
||||
assert_true(origin.isSameOrigin(Origin.from(get_host_info().ORIGIN)));
|
||||
t.done();
|
||||
}
|
||||
}));
|
||||
document.body.appendChild(el);
|
||||
}, `Origin.from(MessageEvent) returns a tuple origin for messages from same-origin frames.`);
|
||||
|
||||
async_test(t => {
|
||||
const el = document.createElement('iframe');
|
||||
el.src = get_host_info().REMOTE_ORIGIN + "/html/browsers/windows/resources/message-parent.html"
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === el.contentWindow) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_false(origin.opaque);
|
||||
assert_true(origin.isSameOrigin(Origin.from(get_host_info().REMOTE_ORIGIN)));
|
||||
t.done();
|
||||
}
|
||||
}));
|
||||
document.body.appendChild(el);
|
||||
}, `Origin.from(MessageEvent) returns a tuple origin for messages from cross-origin frames.`);
|
||||
|
||||
async_test(t => {
|
||||
const el = document.createElement('iframe');
|
||||
el.src = get_host_info().REMOTE_ORIGIN + "/html/browsers/windows/resources/message-parent.html"
|
||||
el.sandbox = "allow-scripts";
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === el.contentWindow) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_true(origin.opaque);
|
||||
assert_false(origin.isSameOrigin(Origin.from(get_host_info().REMOTE_ORIGIN)));
|
||||
t.done();
|
||||
}
|
||||
}));
|
||||
document.body.appendChild(el);
|
||||
}, `Origin.from(MessageEvent) returns an opaque origin for messages from sandboxed frames.`);
|
||||
|
||||
async_test(t => {
|
||||
const w = window.open("/html/browsers/windows/resources/post-to-opener.html");
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === w) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_false(origin.opaque);
|
||||
assert_true(origin.isSameOrigin(Origin.from(get_host_info().ORIGIN)));
|
||||
t.done();
|
||||
}
|
||||
}));
|
||||
}, `Origin.from(MessageEvent) returns a tuple origin for same-origin windows.`);
|
||||
|
||||
async_test(t => {
|
||||
const w = window.open(get_host_info().REMOTE_ORIGIN + "/html/browsers/windows/resources/post-to-opener.html");
|
||||
window.addEventListener("message", t.step_func(e => {
|
||||
if (e.source === w) {
|
||||
const origin = Origin.from(e);
|
||||
assert_true(!!origin);
|
||||
assert_false(origin.opaque);
|
||||
assert_true(origin.isSameOrigin(Origin.from(get_host_info().REMOTE_ORIGIN)));
|
||||
t.done();
|
||||
}
|
||||
}));
|
||||
}, `Origin.from(MessageEvent) returns a tuple origin for cross-origin windows.`);
|
||||
@@ -0,0 +1,5 @@
|
||||
<script>
|
||||
window.parent.postMessage({
|
||||
"name": window.name,
|
||||
}, "*");
|
||||
</script>
|
||||
@@ -0,0 +1,8 @@
|
||||
<script>
|
||||
if (window.opener) {
|
||||
window.opener.postMessage({
|
||||
"name": window.name,
|
||||
"isTop": window.top === window
|
||||
}, "*");
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user