template-content-node-document.html (2609B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>HTML Templates: Node document of the template content attribute must be template contents owner</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="Node document of the template content attribute must be template contents owner"> 8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-element"> 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 test(function() { 18 var doc = newHTMLDocument(); 19 var template = doc.createElement('template'); 20 var nestedTemplate = doc.createElement('template'); 21 template.appendChild(nestedTemplate); 22 23 assert_equals(nestedTemplate.content.ownerDocument, template.content.ownerDocument, 24 'Wrong node document of the template content attribute'); 25 26 }, 'Node document of the template content attribute must be template contents owner. ' + 27 'Nested template element created by createElement'); 28 29 30 test(function() { 31 var doc = newHTMLDocument(); 32 doc.body.innerHTML = '<template><template></template></template>'; 33 var template = doc.querySelector('template'); 34 var nestedTemplate = template.content.querySelector('template'); 35 36 assert_equals(nestedTemplate.content.ownerDocument, template.content.ownerDocument, 37 'Wrong node document of the template content attribute'); 38 39 }, 'Node document of the template content attribute must be template contents owner. ' + 40 'Nested template element created by innerHTML'); 41 42 testInIFrame('../resources/two-templates.html', function(context) { 43 var doc = context.iframes[0].contentDocument; 44 45 var template1 = doc.querySelector('#template1'); 46 var template2 = doc.querySelector('#template2'); 47 48 // when there is a browsing context, template contents owner is only accessible via template.content.ownerDocument 49 // because template contents owner is bounded to document 50 // verify that multiple templates share the same instance of template contents owner 51 52 assert_equals(template1.content.ownerDocument, template2.content.ownerDocument, 53 'Wrong node document of the template content attribute'); 54 }, 'Node document of the template content attribute must be template contents owner. ' + 55 'Load HTML file with multiple template elements'); 56 57 </script> 58 </body> 59 </html>