Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /svg/struct/scripted/switch_reentrant_removal.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<title>SVG switch active child during reentrant removal</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<svg width="300" height="300">
<switch id="switch">
<foreignObject id="child" width="100" height="100">
<iframe id="trigger" srcdoc="<!doctype html><body>unload"></iframe>
</foreignObject>
<rect width="50" height="50"/>
</switch>
</svg>
<iframe id="destination" srcdoc="<!doctype html>
<svg width='300' height='300'>
<g id='target' transform='translate(1 1)'></g>
</svg>"></iframe>
<script>
async_test(t => {
window.addEventListener("load", () => {
const sw = document.getElementById("switch");
const child = document.getElementById("child");
const trigger = document.getElementById("trigger");
const destination = document.getElementById("destination").contentDocument;
const target = destination.getElementById("target");
assert_equals(sw.getBBox().width, 100, "The foreignObject is initially active");
let didUnload = false;
trigger.contentWindow.addEventListener("unload", () => {
didUnload = true;
assert_equals(child.parentNode, null, "The active child has been removed");
trigger.remove();
target.appendChild(child);
assert_equals(child.getBBox().width, 100, "The adopted child has a frame");
// Invalidate the old switch so its bounds have to be recomputed while
// removeChild is still on the stack.
sw.setAttribute("transform", "translate(2 2)");
assert_equals(sw.getBBox().width, 50, "Only the remaining child contributes bounds");
child.remove();
}, { once: true });
sw.removeChild(child);
assert_true(didUnload, "The unload handler ran during removeChild");
assert_equals(sw.getBBox().width, 50, "The remaining child is still active");
t.done();
}, { once: true });
}, "SVG switch active child during reentrant removal");
</script>
</script>
</html>