Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: dom/base/test/chrome/chrome.toml
<?xml version="1.0"?>
<!--
-->
<script>
<![CDATA[
customElements.define("custom-element", class extends XULElement {
constructor() {
super();
const template = document.getElementById("template");
this.attachShadow({mode: "open"})
.appendChild(template.content.cloneNode(true));
}
});
]]>
</script>
<html:template id="template"><xul:box anonid="anon">Anonymous</xul:box></html:template>
<custom-element id="custom-element"/>
<!-- test results are displayed in the html:body -->
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
SimpleTest.waitForExplicitFinish();
function startTest() {
is(document.contains(document), true, "Document should contain itself!");
let box = document.getElementById("custom-element");
is(document.contains(box), true, "Document should contain element in it!");
is(box.contains(box), true, "Element should contain itself.")
let anon = box.shadowRoot.querySelector("[anonid=anon]");
is(document.contains(anon), false, "Document should not contain anonymous element in it!");
is(box.contains(anon), false, "Element should not contain anonymous element in it!");
is(anon.contains(anon), true, "Anonymous element should contain itself.")
is(document.documentElement.contains(box), true, "Element should contain element in it!");
is(document.contains(document.createXULElement("foo")), false, "Document shouldn't contain element which is't in the document");
is(document.contains(document.createTextNode("foo")), false, "Document shouldn't contain text node which is't in the document");
var link = document.getElementById("link");
is(document.contains(link.firstChild), true,
"Document should contain a text node in it.");
is(link.contains(link.firstChild), true,
"Element should contain a text node in it.");
is(link.firstChild.contains(link), false, "text node shouldn't contain its parent.");
is(document.contains(null), false, "Document shouldn't contain null.");
var pi = document.createProcessingInstruction("adf", "asd");
is(pi.contains(document), false, "Processing instruction shouldn't contain document");
document.documentElement.appendChild(pi);
document.contains(pi, true, "Document should contain processing instruction");
var df = document.createRange().createContextualFragment(`<div xmlns="${NS_HTML}">foo</div>`);
is(df.contains(df.firstChild), true, "Document fragment should contain its child");
is(df.contains(df.firstChild.firstChild), true,
"Document fragment should contain its descendant");
is(df.contains(df), true, "Document fragment should contain itself.");
var d = document.implementation.createHTMLDocument("");
is(document.contains(d), false,
"Document shouldn't contain another document.");
is(document.contains(d.createElement("div")), false,
"Document shouldn't contain an element from another document.");
SimpleTest.finish();
}
addLoadEvent(startTest);
]]>
</script>
</window>