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='../testcommon.js'></script>
12 <link rel="stylesheet" href="../../../../resources/testharness.css">
16 <script type="text/javascript">
21 var doc = newXHTMLDocument();
22 doc.body = doc.createElement('body');
23 doc.body.innerHTML = '<template id="tmpl"></template>';
25 var template = doc.querySelector('#tmpl');
27 assert_not_equals(template, null, 'Template element should not be null');
28 assert_not_equals(template.content, undefined,
29 'Content attribute of template element should not be undefined');
30 assert_not_equals(template.content, null,
31 'Content attribute of template element should not be null');
33 assert_equals(template.ownerDocument, doc.body.ownerDocument,
34 'Wrong template node owner document');
35 assert_equals(template.content.ownerDocument, doc,
36 'Wrong template content owner document');
38 }, 'Parsing XHTML: Node\'s node document must be set to that of the element '
39 + 'to which it will be appended. Test empty template');
44 var doc = newXHTMLDocument();
46 doc.body = doc.createElement('body');
47 doc.body.innerHTML = '<template id="tmpl"><div>Div content</div></template>';
49 var template = doc.querySelector('#tmpl');
51 assert_equals(template.ownerDocument, doc.body.ownerDocument,
52 'Wrong template node owner document');
54 assert_not_equals(template, null, 'Template element should not be null');
55 assert_not_equals(template.content, undefined,
56 'Content attribute of template element should not be undefined');
57 assert_not_equals(template.content, null,
58 'Content attribute of template element should not be null');
60 var div = template.content.querySelector('div');
61 assert_equals(template.content.ownerDocument, div.ownerDocument,
62 'Wrong DIV node owner document');
64 }, 'Parsing XHTML: Node\'s node document must be set to that of the element '
65 + 'to which it will be appended. Test not empty template');
70 var doc = newXHTMLDocument();
71 doc.body = doc.createElement('body');
72 doc.body.innerHTML = ''
73 + '<template id="tmpl"><div>Div content</div> And some more text'
74 + '<template id="tmpl2"><div>Template content</div></template>'
77 var template = doc.querySelector('#tmpl');
78 assert_not_equals(template, null, 'Template element should not be null');
79 assert_equals(template.ownerDocument, doc, 'Wrong template node owner document');
80 assert_not_equals(template.content, undefined,
81 'Content attribute of template element should not be undefined');
82 assert_not_equals(template.content, null,
83 'Content attribute of template element should not be null');
85 var nestedTemplate = template.content.querySelector('#tmpl2');
86 assert_not_equals(nestedTemplate, null, 'Nested template element should not be null');
87 assert_not_equals(nestedTemplate.content, undefined,
88 'Content attribute of nested template element should not be undefined');
89 assert_not_equals(nestedTemplate.content, null,
90 'Content attribute of nested template element should not be null');
92 assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument,
93 'Wrong nested template node owner document');
96 var div = nestedTemplate.content.querySelector('div');
97 assert_equals(nestedTemplate.content.ownerDocument, div.ownerDocument,
98 'Wrong DIV node owner document');
100 }, 'Parsing XHTML: Node\'s node document must be set to that of the element '
101 + 'to which it will be appended. Test nested templates');
105 testInIFrame('../resources/template-child-nodes-div.xhtml', function(context) {
106 var doc = context.iframes[0].contentDocument;
108 var template = doc.querySelector('template');
110 assert_equals(template.ownerDocument, doc, 'Wrong template node owner document');
112 assert_not_equals(template.content, undefined,
113 'Content attribute of template element should not be undefined');
114 assert_not_equals(template.content, null,
115 'Content attribute of template element should not be null');
117 var div = template.content.querySelector('div');
118 assert_equals(template.content.ownerDocument, div.ownerDocument,
119 'Wrong DIV node owner document');
121 }, 'Parsing XHTML: Node\'s node document must be set to that of the element '
122 + 'to which it will be appended. Test loading XHTML document from a file');
126 testInIFrame('../resources/template-child-nodes-nested.xhtml', function(context) {
127 var doc = context.iframes[0].contentDocument;
129 var template = doc.querySelector('template');
131 assert_equals(template.ownerDocument, doc, 'Wrong template node owner document');
133 var nestedTemplate = template.content.querySelector('template');
135 assert_equals(nestedTemplate.ownerDocument, template.content.ownerDocument,
136 'Wrong template node owner document');
138 var div = nestedTemplate.content.querySelector('div');
139 assert_equals(nestedTemplate.content.ownerDocument, div.ownerDocument,
140 'Wrong DIV node owner document');
142 }, 'Parsing XHTML: Node\'s node document must be set to that of the element '
143 + 'to which it will be appended. Test loading of XHTML document '
144 + 'with nested templates from a file');