ladybird/Tests/LibWeb/Text/input/Messaging/Messaging-post-channel-over-channel.html
Aliaksandr Kalenik 87bffe7d22 Tests: Rearrange log order in Messaging-post-channel-over-channel.html
When a message is posted to multiple ports at once, the order in which
the callbacks for these messages are invoked is non-deterministic.
To account for this, the test has been rewritten to accumulate logs
for each port separately, and then print them grouped by port.
2025-04-11 17:13:06 +02:00

43 lines
1.3 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
asyncTest(done => {
let channel = new MessageChannel();
const port1Logs = [];
const port2Logs = [];
const port3Logs = [];
channel.port1.onmessage = (event) => {
port1Logs.push("Port1: " + JSON.stringify(event.data));
if (event.ports.length > 0) {
event.ports[0].postMessage("Hello from the transferred port");
return;
}
channel.port1.postMessage(event.data);
};
channel.port2.onmessage = (event) => {
port2Logs.push("Port2: " + JSON.stringify(event.data));
if (event.data === "DONE") {
for (let log of port1Logs)
println(log);
for (let log of port2Logs)
println(log);
for (let log of port3Logs)
println(log);
done();
}
};
let channel2 = new MessageChannel();
channel2.port2.onmessage = (event) => {
port3Logs.push("Port3: " + JSON.stringify(event.data));
channel.port2.postMessage("DONE");
}
channel.port2.postMessage("Hello");
channel.port2.postMessage({ foo: channel2.port1 }, { transfer: [channel2.port1] });
});
</script>