node-document.html (6223B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>HTML Templates: Parsing XHTML: Node's node document</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="Parsing XHTML: Node's node document must be set to that of the element to which it will be appended"> 8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#parsing-xhtml-documents"> 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 19 test(function() { 20 var doc = newXHTMLDocument(); 21 doc.body = doc.createElement('body'); 22 doc.body.innerHTML = '<template id="tmpl"></template>'; 23 24 var template = doc.querySelector('#tmpl'); 25 26 assert_not_equals(template, null, 'Template element should not be null'); 27 assert_not_equals(template.content, undefined, 28 'Content attribute of template element should not be undefined'); 29 assert_not_equals(template.content, null, 30 'Content attribute of template element should not be null'); 31 32 assert_equals(template.ownerDocument, doc.body.ownerDocument, 33 'Wrong template node owner document'); 34 var ownerDoc = template.content.ownerDocument; 35 assert_not_equals(ownerDoc, doc, 'Wrong template content owner document'); 36 assert_not_equals(ownerDoc, document, 'Wrong template content owner document'); 37 assert_equals(ownerDoc.defaultView, null, 38 'Template content owner document should not have a browsing context'); 39 40 }, 'Parsing XHTML: Node\'s node document must be set to that of the element ' 41 + 'to which it will be appended. Test empty template'); 42 43 44 45 test(function() { 46 var doc = newXHTMLDocument(); 47 48 doc.body = doc.createElement('body'); 49 doc.body.innerHTML = '<template id="tmpl"><div>Div content</div></template>'; 50 51 var template = doc.querySelector('#tmpl'); 52 53 assert_equals(template.ownerDocument, doc.body.ownerDocument, 54 'Wrong template node owner document'); 55 56 assert_not_equals(template, null, 'Template element should not be null'); 57 assert_not_equals(template.content, undefined, 58 'Content attribute of template element should not be undefined'); 59 assert_not_equals(template.content, null, 60 'Content attribute of template element should not be null'); 61 62 var div = template.content.querySelector('div'); 63 assert_equals(template.content.ownerDocument, div.ownerDocument, 64 'Wrong DIV node owner document'); 65 66 }, 'Parsing XHTML: Node\'s node document must be set to that of the element ' 67 + 'to which it will be appended. Test not empty template'); 68 69 70 71 test(function() { 72 var doc = newXHTMLDocument(); 73 doc.body = doc.createElement('body'); 74 doc.body.innerHTML = '' 75 + '<template id="tmpl"><div>Div content</div> And some more text' 76 + '<template id="tmpl2"><div>Template content</div></template>' 77 + '</template>'; 78 79 var template = doc.querySelector('#tmpl'); 80 assert_not_equals(template, null, 'Template element should not be null'); 81 assert_equals(template.ownerDocument, doc, 'Wrong template node owner document'); 82 assert_not_equals(template.content, undefined, 83 'Content attribute of template element should not be undefined'); 84 assert_not_equals(template.content, null, 85 'Content attribute of template element should not be null'); 86 87 var nestedTemplate = template.content.querySelector('#tmpl2'); 88 assert_not_equals(nestedTemplate, null, 'Nested template element should not be null'); 89 assert_not_equals(nestedTemplate.content, undefined, 90 'Content attribute of nested template element should not be undefined'); 91 assert_not_equals(nestedTemplate.content, null, 92 'Content attribute of nested template element should not be null'); 93 94 assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument, 95 'Wrong nested template node owner document'); 96 97 98 var div = nestedTemplate.content.querySelector('div'); 99 assert_equals(nestedTemplate.content.ownerDocument, div.ownerDocument, 100 'Wrong DIV node owner document'); 101 102 }, 'Parsing XHTML: Node\'s node document must be set to that of the element ' 103 + 'to which it will be appended. Test nested templates'); 104 105 106 107 testInIFrame('../resources/template-child-nodes-div.xhtml', function(context) { 108 var doc = context.iframes[0].contentDocument; 109 110 var template = doc.querySelector('template'); 111 112 assert_equals(template.ownerDocument, doc, 'Wrong template node owner document'); 113 114 assert_not_equals(template.content, undefined, 115 'Content attribute of template element should not be undefined'); 116 assert_not_equals(template.content, null, 117 'Content attribute of template element should not be null'); 118 119 var div = template.content.querySelector('div'); 120 assert_equals(template.content.ownerDocument, div.ownerDocument, 121 'Wrong DIV node owner document'); 122 123 }, 'Parsing XHTML: Node\'s node document must be set to that of the element ' 124 + 'to which it will be appended. Test loading XHTML document from a file'); 125 126 127 128 testInIFrame('../resources/template-child-nodes-nested.xhtml', function(context) { 129 var doc = context.iframes[0].contentDocument; 130 131 var template = doc.querySelector('template'); 132 133 assert_equals(template.ownerDocument, doc, 'Wrong template node owner document'); 134 135 var nestedTemplate = template.content.querySelector('template'); 136 137 assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument, 138 'Wrong template node owner document'); 139 140 var div = nestedTemplate.content.querySelector('div'); 141 assert_equals(nestedTemplate.content.ownerDocument, div.ownerDocument, 142 'Wrong DIV node owner document'); 143 144 }, 'Parsing XHTML: Node\'s node document must be set to that of the element ' 145 + 'to which it will be appended. Test loading of XHTML document ' 146 + 'with nested templates from a file'); 147 148 </script> 149 </body> 150 </html>