test_bug683852.xhtml (3914B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 4 <!-- 5 https://bugzilla.mozilla.org/show_bug.cgi?id=683852 6 --> 7 <window title="Mozilla Bug 683852" 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 9 xmlns:html="http://www.w3.org/1999/xhtml" 10 xmlns:xul="http://www.mozilla.org/keymaster/gaktekeeper/there.is.only.xul"> 11 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 12 <script> 13 <![CDATA[ 14 customElements.define("custom-element", class extends XULElement { 15 constructor() { 16 super(); 17 const template = document.getElementById("template"); 18 this.attachShadow({mode: "open"}) 19 .appendChild(template.content.cloneNode(true)); 20 } 21 }); 22 ]]> 23 </script> 24 <html:template id="template"><xul:box anonid="anon">Anonymous</xul:box></html:template> 25 <custom-element id="custom-element"/> 26 27 <!-- test results are displayed in the html:body --> 28 <body xmlns="http://www.w3.org/1999/xhtml"> 29 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=683852" 30 target="_blank" id="link">Mozilla Bug 683852</a> 31 </body> 32 33 <!-- test code goes here --> 34 <script type="application/javascript"> 35 <![CDATA[ 36 /** Test for Bug 683852 */ 37 SimpleTest.waitForExplicitFinish(); 38 39 const NS_HTML = "http://www.w3.org/1999/xhtml"; 40 41 function startTest() { 42 is(document.contains(document), true, "Document should contain itself!"); 43 44 let box = document.getElementById("custom-element"); 45 is(document.contains(box), true, "Document should contain element in it!"); 46 is(box.contains(box), true, "Element should contain itself.") 47 let anon = box.shadowRoot.querySelector("[anonid=anon]"); 48 is(document.contains(anon), false, "Document should not contain anonymous element in it!"); 49 is(box.contains(anon), false, "Element should not contain anonymous element in it!"); 50 is(anon.contains(anon), true, "Anonymous element should contain itself.") 51 is(document.documentElement.contains(box), true, "Element should contain element in it!"); 52 is(document.contains(document.createXULElement("foo")), false, "Document shouldn't contain element which is't in the document"); 53 is(document.contains(document.createTextNode("foo")), false, "Document shouldn't contain text node which is't in the document"); 54 55 var link = document.getElementById("link"); 56 is(document.contains(link.firstChild), true, 57 "Document should contain a text node in it."); 58 is(link.contains(link.firstChild), true, 59 "Element should contain a text node in it."); 60 is(link.firstChild.contains(link), false, "text node shouldn't contain its parent."); 61 62 is(document.contains(null), false, "Document shouldn't contain null."); 63 64 var pi = document.createProcessingInstruction("adf", "asd"); 65 is(pi.contains(document), false, "Processing instruction shouldn't contain document"); 66 document.documentElement.appendChild(pi); 67 document.contains(pi, true, "Document should contain processing instruction"); 68 69 var df = document.createRange().createContextualFragment(`<div xmlns="${NS_HTML}">foo</div>`); 70 is(df.contains(df.firstChild), true, "Document fragment should contain its child"); 71 is(df.contains(df.firstChild.firstChild), true, 72 "Document fragment should contain its descendant"); 73 is(df.contains(df), true, "Document fragment should contain itself."); 74 75 var d = document.implementation.createHTMLDocument(""); 76 is(document.contains(d), false, 77 "Document shouldn't contain another document."); 78 is(document.contains(d.createElement("div")), false, 79 "Document shouldn't contain an element from another document."); 80 81 SimpleTest.finish(); 82 } 83 84 addLoadEvent(startTest); 85 ]]> 86 </script> 87 </window>