3 const HTML5_ELEMENTS = [
4 'a', 'abbr', 'address', 'area', 'article', 'aside',
5 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote',
6 'body', 'br', 'button', 'canvas', 'caption', 'cite',
7 'code', 'col', 'colgroup', 'data', 'datalist', 'dd',
8 'del', 'details', 'dfn', 'dialog', 'div', 'dl',
9 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure',
10 'footer', 'form', 'h1', 'h2', 'h3', 'h4',
11 'h5', 'h6', 'head', 'header', 'hr', 'html',
12 'i', 'iframe', 'img', 'input', 'ins', 'kbd',
13 'label', 'legend', 'li', 'link', 'main', 'map',
14 'mark', 'menu', 'meta', 'meter', 'nav', 'noscript',
15 'object', 'ol', 'optgroup', 'option', 'output', 'p',
16 'param', 'pre', 'progress', 'q', 'rp', 'rt',
17 'ruby', 's', 'samp', 'script', 'section', 'select',
18 'slot', 'small', 'source', 'span', 'strong', 'style',
19 'sub', 'sup', 'summary', 'table', 'tbody', 'td',
20 'template', 'textarea', 'tfoot', 'th', 'thead', 'time',
21 'title', 'tr', 'track', 'u', 'ul', 'var',
25 // only void (without end tag) HTML5 elements
26 var HTML5_VOID_ELEMENTS = [
27 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta',
28 'param', 'source', 'track', 'wbr'
31 // https://html.spec.whatwg.org/multipage/multipage/forms.html#form-associated-element
32 var HTML5_FORM_ASSOCIATED_ELEMENTS = [ 'button', 'fieldset', 'input',
33 'object', 'output', 'select', 'textarea' ];
35 const HTML5_SHADOW_ALLOWED_ELEMENTS = [
36 'article', 'aside', 'blockquote', 'body', 'div', 'footer', 'h1', 'h2', 'h3',
37 'h4', 'h5', 'h6', 'header', 'main', 'nav', 'p', 'section', 'span'
40 const HTML5_SHADOW_DISALLOWED_ELEMENTS =
41 HTML5_ELEMENTS.filter(el => !HTML5_SHADOW_ALLOWED_ELEMENTS.includes(el));
43 // These are *deprecated/removed* HTML5 element names.
44 const HTML5_DEPRECATED_ELEMENTS = [
45 'acronym', 'applet', 'basefont', 'bgsound', 'big', 'blink',
46 'center', 'command', 'content', 'dir', 'font', 'frame',
47 'frameset', 'hgroup', 'image', 'isindex', 'keygen', 'marquee',
48 'menuitem', 'nobr', 'noembed', 'noframes', 'plaintext', 'rb',
49 'rtc', 'shadow', 'spacer', 'strike', 'tt', 'xmp'
52 function newDocument() {
53 var d = document.implementation.createDocument();
57 function newHTMLDocument() {
58 var d = document.implementation.createHTMLDocument('Test Document');
62 function newXHTMLDocument() {
63 var doctype = document.implementation.createDocumentType('html',
64 '-//W3C//DTD XHTML 1.0 Transitional//EN',
65 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd');
67 var d = document.implementation.createDocument(
68 'http://www.w3.org/1999/xhtml', 'html', doctype);
72 function newIFrame(context, src) {
73 if (typeof (context) === 'undefined'
74 || typeof (context.iframes) !== 'object') {
75 assert_unreached('Illegal context object in newIFrame');
78 var iframe = document.createElement('iframe');
80 if (typeof (src) != 'undefined') {
83 document.body.appendChild(iframe);
84 context.iframes.push(iframe);
86 assert_true(typeof (iframe.contentWindow) != 'undefined'
87 && typeof (iframe.contentWindow.document) != 'undefined'
88 && iframe.contentWindow.document != document,
89 'Failed to create new rendered document');
93 function newRenderedHTMLDocument(context) {
94 var frame = newIFrame(context);
95 var d = frame.contentWindow.document;
99 function newContext() {
105 function cleanContext(context) {
106 context.iframes.forEach(function(e) {
107 e.parentNode.removeChild(e);
111 // run given test function in context
112 // the context is cleaned up after test completes.
113 function inContext(f) {
115 var context = newContext();
119 cleanContext(context);
124 // new context and iframe are created and url (if supplied) is asigned to
126 // function f is bound to the iframe onload event or executed directly after
128 // the context is passed to function as argument
129 function testInIFrame(url, f, testName, testProps) {
131 var t = async_test(testName);
133 var context = newContext();
134 var iframe = newIFrame(context, url);
135 iframe.onload = t.step_func(function() {
140 cleanContext(context);
145 test(inContext(function(context) {
146 newRenderedHTMLDocument(context);
152 function assert_nodelist_contents_equal_noorder(actual, expected, message) {
153 assert_equals(actual.length, expected.length, message);
155 for ( var i = 0; i < expected.length; i++) {
158 for (i = 0; i < expected.length; i++) {
160 for ( var j = 0; j < actual.length; j++) {
161 if (used[j] == false && expected[i] == actual[j]) {
168 assert_unreached(message + ". Fail reason: element not found: "
174 function isVoidElement(elementName) {
175 return HTML5_VOID_ELEMENTS.indexOf(elementName) >= 0;
178 function checkTemplateContent(d, obj, html, id, nodeName) {
180 obj.innerHTML = '<template id="tmpl">' + html + '</template>';
182 var t = d.querySelector('#tmpl');
185 assert_equals(t.content.childNodes.length, 1, 'Element ' + nodeName
186 + ' should present among template nodes');
187 assert_equals(t.content.firstChild.id, id, 'Wrong element ID');
189 if (nodeName != null) {
190 assert_equals(t.content.firstChild.nodeName, nodeName.toUpperCase(),
195 function checkBodyTemplateContent(d, html, id, nodeName) {
196 checkTemplateContent(d, d.body, html, id, nodeName);
199 function checkHeadTemplateContent(d, html, id, nodeName) {
200 checkTemplateContent(d, d.head, html, id, nodeName);