Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /html/webappapis/dynamic-markup-insertion/the-innerhtml-property/innerhtml-and-xml-namespaces.svg - WPT Dashboard Interop Dashboard
<?xml version="1.0" encoding="UTF-8"?>
width="800px" height="1000px">
<title>innerHTML setter and XML namespaces</title>
<metadata>
<h:link rel="help" href="https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#the-innerhtml-property"/>
</metadata>
<h:script src="/resources/testharness.js"/>
<h:script src="/resources/testharnessreport.js"/>
<foreignObject>
<h:body>
<h:div/>
<g/>
<element xmlns=""/>
<h:script><![CDATA[
"use strict";
const body = document.querySelector("body");
const prefixedContainer = body.firstElementChild;
const unprefixedContainer = prefixedContainer.nextElementSibling;
const noDefaultNsContainer = unprefixedContainer.nextElementSibling;
const newDefaultNsContainer = noDefaultNsContainer.nextElementSibling;
test(() => {
assert_equals(prefixedContainer.namespaceURI, XHTML_NS);
assert_true(prefixedContainer.isDefaultNamespace(SVG_NS));
assert_equals(unprefixedContainer.namespaceURI, SVG_NS);
assert_true(unprefixedContainer.isDefaultNamespace(SVG_NS));
assert_equals(noDefaultNsContainer.namespaceURI, null);
assert_true(noDefaultNsContainer.isDefaultNamespace(""));
}, "prerequisites");
test(() => {
prefixedContainer.innerHTML = "<e></e>";
assert_equals(prefixedContainer.firstChild.namespaceURI, SVG_NS);
}, "default namespace applies to children of namespaced element");
test(() => {
unprefixedContainer.innerHTML = "<e></e>";
assert_equals(unprefixedContainer.firstChild.namespaceURI, SVG_NS);
}, "default namespace applies to children of default-namespaced element");
test(() => {
noDefaultNsContainer.innerHTML = "<e></e>";
assert_equals(noDefaultNsContainer.firstChild.namespaceURI, null);
}, "default namespace applies to children of non-namespaced element");
test(() => {
newDefaultNsContainer.innerHTML = "<e></e>";
}, "default namespace applies to children of namespaced element with new default namespace");
test(() => {
prefixedContainer.innerHTML = "<e><h:span></h:span></e>";
assert_equals(prefixedContainer.firstChild.firstChild.namespaceURI, XHTML_NS);
}, "namespace prefix applies to children of namespaced element");
test(() => {
prefixedContainer.innerHTML = "<e><h:span><f></f></h:span></e>";
assert_equals(prefixedContainer.firstChild.firstChild.firstChild.namespaceURI, SVG_NS);
}, "default namespace prefix applies to descendants of namespaced element");
test(() => {
prefixedContainer.innerHTML = "<e><f xmlns=''><g></g></f></e>";
assert_equals(prefixedContainer.firstChild.firstChild.namespaceURI, null);
}, "unsetting default namespace works inside parse of fragment (on element)");
test(() => {
prefixedContainer.innerHTML = "<e><f xmlns=''><g></g></f></e>";
assert_equals(prefixedContainer.firstChild.firstChild.firstChild.namespaceURI, null);
}, "unsetting default namespace works inside parse of fragment (on child of element)");
test(() => {
prefixedContainer.innerHTML = "<e><h:f xmlns:h='https://example.com/new-h'><g><h:d></h:d></g></h:f></e>";
assert_equals(prefixedContainer.firstChild.firstChild.firstChild.namespaceURI, SVG_NS);
assert_equals(prefixedContainer.firstChild.firstChild.firstChild.firstChild.namespaceURI, "https://example.com/new-h");
}, "declaring namespace with prefix inside of fragment parsed by innerHTML");
test(() => {
prefixedContainer.innerHTML = "<e><f xmlns='https://example.com/new-default'><h:g><d></d></h:g></f></e>";
assert_equals(prefixedContainer.firstChild.firstChild.namespaceURI, "https://example.com/new-default");
assert_equals(prefixedContainer.firstChild.firstChild.firstChild.namespaceURI, XHTML_NS);
assert_equals(prefixedContainer.firstChild.firstChild.firstChild.firstChild.namespaceURI, "https://example.com/new-default");
}, "declaring default namespace inside of fragment parsed by innerHTML");
]]></h:script>
</h:body>
</foreignObject>
</svg>