template-child-nodes.html (4653B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>HTML Templates: HTML parser appends child nodes only to the template contents node</title> 5 <meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru"> 6 <meta name="author" title="Aleksei Yu. Semenov" href="mailto:a.semenov@unipro.ru"> 7 <meta name="assert" content="HTML parser must append template's child nodes only to the template contents node."> 8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#appending-to-a-template"> 9 <script src="/resources/testharness.js"></script> 10 <script src="/resources/testharnessreport.js"></script> 11 <script src="/html/resources/common.js"></script> 12 </head> 13 <body> 14 <div id="log"></div> 15 <script type="text/javascript"> 16 17 18 test(function () { 19 var doc = newHTMLDocument(); 20 doc.body.innerHTML = '<template id="tmpl1">' + 21 '<div id="div1">This is div inside template</div>' + 22 '<div id="div2">This is another div inside template</div>' + 23 '</template>'; 24 25 var template = doc.querySelector('#tmpl1'); 26 27 assert_equals(template.childNodes.length, 0, 'Wrong number of template child nodes'); 28 assert_equals(template.content.childNodes.length, 2, 29 'Wrong number of template content child nodes'); 30 31 assert_not_equals(template.content.querySelector('#div1'), null, 32 'Element is absent in the template content'); 33 assert_not_equals(template.content.querySelector('#div2'), null, 34 'Element is absent in the template content'); 35 36 }, 'Template child nodes must be appended to template content node'); 37 38 39 40 test(function () { 41 var doc = newHTMLDocument(); 42 doc.body.innerHTML = '<template id="tmpl1">' + 43 '<div id="div1">This is div inside template</div>' + 44 '<div id="div2">This is another div inside template</div>' + 45 '<template id="tmpl2">' + 46 '<div id="div3">This is div inside nested template</div>' + 47 '<div id="div4">This is another div inside nested template</div>' + 48 '</template>' + 49 '</template>'; 50 51 var template = doc.querySelector('#tmpl1'); 52 53 assert_equals(template.childNodes.length, 0, 54 'Wrong number of template child nodes'); 55 assert_equals(template.content.childNodes.length, 3, 56 'Wrong number of template content child nodes'); 57 58 assert_not_equals(template.content.querySelector('#div1'), null, 59 'Element is absent in the template content'); 60 assert_not_equals(template.content.querySelector('#div2'), null, 61 'Element is absent in the template content'); 62 63 var nestedTemplate = template.content.querySelector('#tmpl2'); 64 65 assert_equals(nestedTemplate.childNodes.length, 0, 66 'Wrong number of template child nodes'); 67 assert_equals(nestedTemplate.content.childNodes.length, 2, 68 'Wrong number of nested template content child nodes'); 69 70 assert_not_equals(nestedTemplate.content.querySelector('#div3'), null, 71 'Element is absent in the template content'); 72 assert_not_equals(nestedTemplate.content.querySelector('#div4'), null, 73 'Element is absent in the template content'); 74 75 }, 'Template child nodes must be appended to template content. Test nested template'); 76 77 78 79 testInIFrame('/html/semantics/scripting-1/the-template-element/resources/template-contents.html', function(context) { 80 var doc = context.iframes[0].contentDocument; 81 82 var template = doc.querySelector('template'); 83 84 assert_equals(template.childNodes.length, 0, 'Wrong number of template child nodes'); 85 86 assert_not_equals(template.content.querySelector('div'), null, 87 'Element is absent in the template content'); 88 89 }, 'Template child nodes must be appended to template content node. ' 90 + 'Load HTML document from a file'); 91 92 93 testInIFrame('/html/semantics/scripting-1/the-template-element/resources/template-contents-nested.html', function(context) { 94 var doc = context.iframes[0].contentDocument; 95 96 var template = doc.querySelector('template'); 97 98 assert_equals(template.childNodes.length, 0, 'Wrong number of template child nodes'); 99 100 var nestedTemplate = template.content.querySelector('template'); 101 102 assert_not_equals(nestedTemplate, null, 103 'Element is absent in the template content'); 104 105 assert_equals(nestedTemplate.childNodes.length, 0, 106 'Wrong number of template child nodes'); 107 108 assert_not_equals(nestedTemplate.content.querySelector('div'), null, 109 'Element is absent in the template content'); 110 111 }, 'Template child nodes must be appended to nested template content node. ' 112 + 'Load HTML document from a file'); 113 114 </script> 115 </body> 116 </html>