test_template_xhtml.html (2044B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1011831 5 --> 6 <head> 7 <title>Test for template element</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1011831">Bug 1011831</a> 13 <script> 14 var docSrc = 15 '<!DOCTYPE html>' + 16 '<html xmlns="http://www.w3.org/1999/xhtml">' + 17 '<body>' + 18 '<template id="t">Content<span>Content</span></template>' + 19 '<div id="container"><template>One</template><div>Two</div></div>' + 20 '<template id="t2"></template>' + 21 '</body>' + 22 '</html>'; 23 24 var doc = (new DOMParser()).parseFromString(docSrc, 'application/xhtml+xml'); 25 26 var t = doc.getElementById("t"); 27 is(t.childNodes.length, 0, "Template should have no children."); 28 is(t.content.childNodes.length, 2, "Template content should have two children, text node and a span."); 29 30 // Test serialization of template element. 31 is(t.innerHTML, 'Content<span xmlns="http://www.w3.org/1999/xhtml">Content</span>', "Template contents should be serialized."); 32 is(t.outerHTML, '<template xmlns="http://www.w3.org/1999/xhtml" id="t">Content<span>Content</span></template>', "Template contents should be serialized."); 33 34 var c = doc.getElementById("container"); 35 is(c.innerHTML, '<template xmlns="http://www.w3.org/1999/xhtml">One</template><div xmlns="http://www.w3.org/1999/xhtml">Two</div>', "Template contents should be serialized."); 36 is(c.outerHTML, '<div xmlns="http://www.w3.org/1999/xhtml" id="container"><template>One</template><div>Two</div></div>', "Template contents should be serialized."); 37 38 // Test setting innerHTML on template element. 39 var t2 = doc.getElementById("t2"); 40 t2.innerHTML = 'Three<span>Four</span>'; 41 is(t2.childNodes.length, 0, "Setting innerHTML should append children into template content."); 42 is(t2.content.childNodes.length, 2, "Setting innerHTML should append children into template content."); 43 44 </script> 45 </body> 46 </html>