ignore-head-token.html (4789B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>HTML Templates: In body insertion mode: parser should ignore HEAD 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="If parser is in 'in body' insertion mode and meets HEAD token it should be ignored"> 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="/html/resources/common.js"></script> 12 </head> 13 <body> 14 <div id="log"></div> 15 <script type="text/javascript"> 16 17 /* 18 * According to http://www.w3.org/TR/2013/WD-html-templates-20130214/#template-contents-insertion-mode 19 * when parser is in "template content" mode and meets <head> tag it should be switched to 20 * "in body" insertion mode. 21 * According to https://html.spec.whatwg.org/multipage/#parsing-main-inbody 22 * this token (HEAD) should be ignored 23 */ 24 25 test(function() { 26 var doc = newHTMLDocument(); 27 var template = doc.createElement('template'); 28 29 template.innerHTML = '<head></head>'; 30 31 doc.body.appendChild(template); 32 33 assert_equals(template.content.childNodes.length, 0, 34 'Template cannot contain HEAD element'); 35 36 }, 'Ignore HEAD token. Test empty HEAD element assigned to template innerHTML'); 37 38 39 test(function() { 40 var doc = newHTMLDocument(); 41 var template = doc.createElement('template'); 42 43 template.innerHTML = '<head><title>test</title></head>'; 44 45 doc.body.appendChild(template); 46 47 assert_equals(template.content.childNodes.length, 1, 48 'Wrong number of template content children'); 49 assert_equals(template.content.firstChild.nodeName, 'TITLE', 50 'Template should contain children of ignored HEAD element'); 51 52 }, 'Ignore HEAD token. Test not empty HEAD element assigned to template innerHTML'); 53 54 55 test(function() { 56 var doc = newHTMLDocument(); 57 var template = doc.createElement('template'); 58 59 template.innerHTML = '<div id="div1">Some text</div><head><title>test</title></head>'; 60 61 doc.body.appendChild(template); 62 63 assert_equals(template.content.childNodes.length, 2, 64 'Wrong number of template content children'); 65 assert_not_equals(template.content.querySelector('#div1'), null, 66 'Template should contain valid element'); 67 assert_equals(template.content.lastChild.tagName, 'TITLE', 68 'Template should contain children of ignored HEAD element'); 69 70 }, 'Ignore HEAD token. ' 71 + 'Test HEAD element and some valid element before it, assigned to template innerHTML'); 72 73 74 test(function() { 75 var doc = newHTMLDocument(); 76 var template = doc.createElement('template'); 77 78 template.innerHTML = '<head><title>test</title></head><div id="div1">Some text</div>'; 79 80 doc.body.appendChild(template); 81 82 assert_equals(template.content.childNodes.length, 2, 83 'Wrong number of template content children'); 84 assert_equals(template.content.firstChild.tagName, 'TITLE', 85 'Template should contain children of ignored HEAD element'); 86 assert_not_equals(template.content.querySelector('#div1'), null, 87 'Template should contain valid element'); 88 89 }, 'Ignore HEAD token. ' 90 + 'Test HEAD element and some valid element after it, assigned to template innerHTML'); 91 92 93 test(function() { 94 var doc = newHTMLDocument(); 95 var template = doc.createElement('template'); 96 97 template.innerHTML = '<template id="t2"><head><title>test</title></head></template>'; 98 99 doc.body.appendChild(template); 100 101 assert_equals(template.content.childNodes.length, 1, 102 'Template should contain nested template'); 103 assert_not_equals(template.content.querySelector('#t2'), null, 104 'Template should contain nested element'); 105 106 var nestedTemplate = template.content.querySelector('#t2'); 107 108 assert_equals(nestedTemplate.content.childNodes.length, 1, 109 'Wrong number of template content children'); 110 assert_equals(nestedTemplate.content.firstChild.tagName, 'TITLE', 111 'Template should contain children of ignored HEAD element'); 112 113 }, 'Ignore HEAD token. ' 114 + 'Test HEAD tag inside template tag assigned to another template\'s innerHTML'); 115 116 117 testInIFrame('/html/semantics/scripting-1/the-template-element/resources/template-contents-head.html', function(context) { 118 var doc = context.iframes[0].contentDocument; 119 120 var template = doc.body.querySelector('template'); 121 122 assert_equals(template.content.childNodes.length, 0, 123 'Template cannot contain HEAD element'); 124 125 }, 'Ignore HEAD token. Test loading a HTML file with HEAD tag inside template'); 126 127 </script> 128 </body> 129 </html>