Skip to content

Truly independent web browser

2.8 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<svg xmlns="http://www.w3.org/2000/svg" id="svg-element">
    <linearGradient id="linear-gradient-element" />
    <svg id="nested-svg"></svg>
    <use id="use-element" href="#nested-svg" />
    <foreignObject>
        <svg id="foreign-object-svg"></svg>
        <div id="shadow-host">
            <template shadowrootmode="open">
                <svg id="shadow-svg">
                    <foreignObject>
                        <!-- NB: This keeps the slot in the HTML namespace while retaining a shadow-tree SVG ancestor. -->
                        <slot name="test"></slot>
                    </foreignObject>
                </svg>
            </template>
            <svg id="slotted-svg" slot="test"></svg>
        </div>
    </foreignObject>
</svg>
<script>
    test(() => {
        const svgElement = document.getElementById("svg-element");
        println(`svg.ownerSVGElement = '${svgElement.ownerSVGElement}'`);

        const linearGradientElement = document.getElementById("linear-gradient-element");
        println(`linearGradient.ownerSVGElement = '${linearGradientElement.ownerSVGElement}'`);
        println(`linearGradient.ownerSVGElement == svg = '${linearGradientElement.ownerSVGElement === svgElement}'`);

        const nestedSVG = document.getElementById("nested-svg");
        println(`nestedSVG.ownerSVGElement == svg = '${nestedSVG.ownerSVGElement === svgElement}'`);

        const foreignObjectSVG = document.getElementById("foreign-object-svg");
        println(`foreignObjectSVG.ownerSVGElement = '${foreignObjectSVG.ownerSVGElement}'`);

        const shadowSVG = document.getElementById("shadow-host").shadowRoot.getElementById("shadow-svg");
        println(`shadowSVG.ownerSVGElement = '${shadowSVG.ownerSVGElement}'`);

        const useShadowSVG = internals.getShadowRoot(document.getElementById("use-element")).firstElementChild;
        println(`useShadowSVG.ownerSVGElement == svg = '${useShadowSVG.ownerSVGElement === svgElement}'`);

        const detachedSVG = document.createElementNS("http://www.w3.org/2000/svg", "svg");
        println(`detachedSVG.ownerSVGElement = '${detachedSVG.ownerSVGElement}'`);

        const slottedSVG = document.getElementById("slotted-svg");
        println(`slottedSVG is assigned to the named slot = '${slottedSVG.assignedSlot?.name === "test"}'`);
        println(`slottedSVG.ownerSVGElement = '${slottedSVG.ownerSVGElement}'`);

        const slottedGroup = document.createElementNS("http://www.w3.org/2000/svg", "g");
        slottedGroup.setAttribute("slot", "test");
        document.getElementById("shadow-host").append(slottedGroup);
        println(`slottedGroup is assigned to the named slot = '${slottedGroup.assignedSlot?.name === "test"}'`);
        println(`slottedGroup.ownerSVGElement == svg = '${slottedGroup.ownerSVGElement === svgElement}'`);
    });
</script>