Skip to content

Commit c99e5a0

Browse files
committed
Test displaced foster table with displaced ref_node and cross-realm stream errors
1 parent 42c8629 commit c99e5a0

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎domparsing/stream-insertion-logic.html‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,41 @@
686686
const parent = await stream_into_replaced_element_after_table_moves(t, create_unsafe_stream);
687687
assert_equals(parent.innerHTML, `${prefix}<script>window.move_table();<` + `/script>after<span></span>`);
688688
}, `${method_name}: children of a replaceWithChildrenElements element are dropped, without erroring the stream, when the table it was foster parented before is moved`);
689+
690+
promise_test(async (t) => {
691+
const parent = document.body.appendChild(document.createElement("div"));
692+
t.add_cleanup(() => parent.remove());
693+
const ref_node = parent.appendChild(document.createElement("span"));
694+
const elsewhere = document.createElement("div");
695+
window.move_table_and_ref = () => {
696+
elsewhere.append(parent.querySelector("table"));
697+
ref_node.remove();
698+
};
699+
window.restore_ref = () => parent.append(ref_node);
700+
t.add_cleanup(() => {
701+
delete window.move_table_and_ref;
702+
delete window.restore_ref;
703+
});
704+
705+
const writer = create_unsafe_stream(parent, ref_node, {
706+
runScripts: true,
707+
sanitizer: { replaceWithChildrenElements: ["span"] },
708+
}).getWriter();
709+
await writer.write(
710+
"<section><table><span>" +
711+
"<script>window.move_table_and_ref();<" + "/script>" +
712+
"text<b>bold</b>" +
713+
"</span></table>" +
714+
"<script>window.restore_ref();<" + "/script>" +
715+
"<em>kept</em></section>after"
716+
);
717+
await writer.close();
718+
719+
assert_equals(elsewhere.innerHTML, "<table></table>");
720+
assert_equals(parent.querySelector("section").querySelector("b"), null);
721+
assert_equals(parent.querySelector("em").textContent, "kept");
722+
assert_equals(parent.lastChild, ref_node);
723+
}, `${method_name}: displaced foster-parenting table for a replaceWithChildrenElements element does not error the stream even while ref_node is temporarily displaced`);
689724
}
690725

691726
promise_test(async (t) => {
@@ -843,5 +878,26 @@
843878
assert_false(iframe.contentWindow.script_after_adopt_ran, "streamed scripts must not run in the new document either");
844879
}, `${method}: adopting the target into another document mid-stream continues inserting nodes without running scripts`);
845880
}
881+
882+
promise_test(async (t) => {
883+
const iframe = await load_iframe(t);
884+
const otherWin = iframe.contentWindow;
885+
const otherDoc = iframe.contentDocument;
886+
const parent = otherDoc.body.appendChild(otherDoc.createElement("div"));
887+
const ref_node = parent.appendChild(otherDoc.createElement("span"));
888+
889+
const stream = Element.prototype.streamBeforeHTMLUnsafe.call(ref_node);
890+
assert_true(stream instanceof otherWin.WritableStream, "WritableStream is created in this's relevant realm");
891+
892+
ref_node.remove();
893+
const writer = stream.getWriter();
894+
try {
895+
await writer.write("<p>after removal</p>");
896+
assert_unreached("write() after referenceChild displacement must reject");
897+
} catch (err) {
898+
assert_true(err instanceof otherWin.DOMException, "HierarchyRequestError is created in this's relevant realm");
899+
assert_equals(err.name, "HierarchyRequestError");
900+
}
901+
}, "Cross-realm streamBeforeHTMLUnsafe creates WritableStream and HierarchyRequestError in this's relevant realm");
846902
</script>
847903
</body>

0 commit comments

Comments
 (0)