4 <title>HTML Templates: In body insertion mode: parser should ignore BODY token</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="http://www.w3.org/TR/2013/WD-html-templates-20130214/#in-body-addition">
8 <link rel="help" href="http://www.w3.org/TR/2013/WD-html-templates-20130214/#in-body-addition">
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">
19 * According to http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-contents-insertion-mode
20 * when parser is in "template content" mode and meets <body> tag it should be switched to
21 * "in body" insertion mode.
22 * According to http://www.w3.org/TR/2013/WD-html-templates-20130214/#in-body-addition
23 * this token (BODY) should be ignored
28 var doc = newHTMLDocument();
29 var template = doc.createElement('template');
31 template.innerHTML = '<body></body>';
33 doc.body.appendChild(template);
35 assert_equals(template.content.childNodes.length, 0,
36 'Template cannot contain BODY element');
38 }, 'Ignore BODY token. Test empty BODY element assigned to template innerHTML');
42 var doc = newHTMLDocument();
43 var template = doc.createElement('template');
45 template.innerHTML = '<body><div>Some content</div></body>';
47 doc.body.appendChild(template);
49 assert_equals(template.content.childNodes.length, 1,
50 'Wrong number of template content children');
51 assert_equals(template.content.firstChild.nodeName, 'DIV',
52 'Template should contain children of ignored BODY element');
54 }, 'Ignore BODY token. Test not empty BODY element assigned to template innerHTML');
58 var doc = newHTMLDocument();
59 var template = doc.createElement('template');
61 template.innerHTML = '<body><div <div id="div1">Some content</div></body><div id="div2">Some valid content</div>';
63 doc.body.appendChild(template);
65 assert_equals(template.content.childNodes.length, 2,
66 'Wrong number of template content children');
67 assert_not_equals(template.content.querySelector('#div1'), null,
68 'Template should contain children of the ignored BODY element');
69 assert_not_equals(template.content.querySelector('#div2'), null,
70 'Template should contain valid element');
72 }, 'Ignore BODY token. '
73 + 'Test BODY element and some valid element after BODY tag assigned to template innerHTML');
77 var doc = newHTMLDocument();
78 var template = doc.createElement('template');
80 template.innerHTML = '<div id="div1">Some valid content</div><body><div id="div2">Some content</div></body>';
82 doc.body.appendChild(template);
84 assert_equals(template.content.childNodes.length, 2,
85 'Template cannot contain BODY element');
86 assert_not_equals(template.content.querySelector('#div1'), null,
87 'Template should contain valid element');
88 assert_not_equals(template.content.querySelector('#div2'), null,
89 'Template should contain children of the ignored BODY element');
91 }, 'Ignore BODY token. '
92 + 'Test BODY element and some valid element before BODY tag assigned to template innerHTML');
96 var doc = newHTMLDocument();
97 var template = doc.createElement('template');
99 template.innerHTML = '<template id="t2"><body><span>Body!<span></body></template>';
101 doc.body.appendChild(template);
103 assert_equals(template.content.childNodes.length, 1,
104 'Template should contain nested template');
105 assert_not_equals(template.content.querySelector('#t2'), null,
106 'Template should contain nested element');
108 var nestedTemplate = template.content.querySelector('#t2');
110 assert_equals(nestedTemplate.content.childNodes.length, 1,
111 'Template cannot contain BODY element');
112 assert_equals(nestedTemplate.content.firstChild.nodeName, 'SPAN',
113 'Template cannot contain BODY element');
115 }, 'Ignore BODY token. '
116 + 'Test template with not empty BODY element inside assigned to another '
117 + 'template\'s innerHTML');
120 testInIFrame('../../resources/template-contents-body.html', function(context) {
121 var doc = context.iframes[0].contentDocument;
123 var template = doc.body.querySelector('template');
125 assert_equals(template.content.childNodes.length, 0,
126 'Template cannot contain BODY element');
128 }, 'Ignore BODY token. '
129 + 'Test loading a HTML file with BODY tag inside template');