Files
ladybird/Tests/LibWeb/Text/input/navigation/multiple-navigable-cross-document-navigation.html
Prajjwal 1f5ffe04c8 LibWeb: Fix race condition between read_all_bytes and stream population
There might be a race between read_all_bytes and stream population.
If document load reads stream before it is populated, the stream will
be empty and might lead to hang in SessionHistoryTraversalQueue which
is expecting a promise to be resolved on document load.

This race can occur when stream population and document source are set
very close to each other. For example, when a newly generated blob is
set as the source of an iframe.
- navigation/multiple-navigable-cross-document-navigation.html has been
modified to trigger this race.
2025-11-26 12:27:12 +01:00

36 lines
1.5 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<iframe id="a"></iframe>
<iframe id="b"></iframe>
<iframe id="c"></iframe>
<iframe id="d"></iframe>
<script>
asyncTest(done => {
let doneA = false, doneB = false, doneC = false, doneD = false;
function check() {if (doneA && doneB && doneC && doneD) done();}
function makeContent(id, n) {
let html = `<h3>${id} ${n}</h3>`;
if (n % 3 === 0) html += `<iframe id="nest1+${id}" srcdoc="${id} ${n}"></iframe>`;
if (n % 5 === 0) html += `<frame id="nest2${id} srcdoc="${id} ${n}"/>`;
return html;
}
function run(iframe, id, n, max, finish) {
if (n >= max) {println('PASS'); finish(); return;}
const blob = new Blob([makeContent(id, n)], {type: 'text/html'});
const url = URL.createObjectURL(blob);
iframe.onload = () => {
try {
iframe.contentDocument;
URL.revokeObjectURL(url);
} catch {println('FAIL'); finish(); return;}
run(iframe, id, n + 1, max, finish);
};
iframe.src = url;
}
run(document.getElementById('a'), 'a', 0, 101, () => {doneA = true; check();});
run(document.getElementById('b'), 'b', 0, 101, () => {doneB = true; check();});
run(document.getElementById('c'), 'c', 0, 101, () => {doneC = true; check();});
run(document.getElementById('d'), 'd', 0, 101, () => {doneD = true; check();});
});
</script>