ladybird/Tests/LibWeb/Text/input/navigation/location-reload-srcdoc.html
Timothy Flynn 96082d6ae1 LibWeb: Port some manually async tests to use asyncTest
These tests were mostly async tests written in a manual way. This ports
them to use the standard asyncTest() infrastructure.

This is mostly just to reduce calls to internals.signalTextTestIsDone,
which will have a required parameter in an upcoming test.
2024-10-03 07:07:28 -04:00

42 lines
1.3 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<script>
let reloaded = false;
asyncTest(done => {
window.addEventListener("message", event => {
switch (event.data.action) {
case "loaded":
println("iframe is loaded");
if (!reloaded) {
event.source.postMessage({ action: "reload" });
reloaded = true;
} else {
done();
}
break;
case "acknowledge-asked-to-reload":
println("iframe is going to reload");
break;
default:
break;
}
});
const iframeScript = `
window.addEventListener('message', event => {
if (event.data && event.data.action === 'reload') {
window.parent.postMessage({ action: 'acknowledge-asked-to-reload' });
location.reload();
}
});
window.addEventListener('load', () => {
window.parent.postMessage({ action: 'loaded' });
});
`;
const iframe = document.createElement("iframe");
iframe.srcdoc = "<script>" + iframeScript + "<\/script>";
document.body.appendChild(iframe);
});
</script>