1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
<!DOCTYPE html>
<html is="my-html">
<head>
<meta charset="utf-8">
<meta name="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#element-definition">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body is="my-body">
<div id="container"></div>
<script>
let testData = [
{tag: 'a', interface: 'HTMLAnchorElement'},
{tag: 'abbr', interface: 'HTMLElement'},
{tag: 'address', interface: 'HTMLElement'},
{tag: 'area', interface: 'HTMLAreaElement'},
{tag: 'article', interface: 'HTMLElement'},
{tag: 'aside', interface: 'HTMLElement'},
{tag: 'audio', interface: 'HTMLAudioElement'},
{tag: 'b', interface: 'HTMLElement'},
{tag: 'base', interface: 'HTMLBaseElement'},
{tag: 'bdi', interface: 'HTMLElement'},
{tag: 'bdo', interface: 'HTMLElement'},
{tag: 'blockquote', interface: 'HTMLQuoteElement'},
{tag: 'body', interface: 'HTMLBodyElement', parsing: 'document'},
{tag: 'br', interface: 'HTMLBRElement'},
{tag: 'button', interface: 'HTMLButtonElement'},
{tag: 'canvas', interface: 'HTMLCanvasElement'},
{tag: 'caption', interface: 'HTMLTableCaptionElement', parsing: 'table'},
{tag: 'cite', interface: 'HTMLElement'},
{tag: 'code', interface: 'HTMLElement'},
{tag: 'col', interface: 'HTMLTableColElement', parsing: 'table'},
{tag: 'colgroup', interface: 'HTMLTableColElement', parsing: 'table'},
{tag: 'data', interface: 'HTMLDataElement'},
{tag: 'dd', interface: 'HTMLElement'},
{tag: 'del', interface: 'HTMLModElement'},
{tag: 'details', interface: 'HTMLDetailsElement'},
{tag: 'dfn', interface: 'HTMLElement'},
{tag: 'div', interface: 'HTMLDivElement'},
{tag: 'dl', interface: 'HTMLDListElement'},
{tag: 'dt', interface: 'HTMLElement'},
{tag: 'em', interface: 'HTMLElement'},
{tag: 'embed', interface: 'HTMLEmbedElement'},
{tag: 'fieldset', interface: 'HTMLFieldSetElement'},
{tag: 'figcaption', interface: 'HTMLElement'},
{tag: 'figure', interface: 'HTMLElement'},
{tag: 'footer', interface: 'HTMLElement'},
{tag: 'form', interface: 'HTMLFormElement'},
{tag: 'h1', interface: 'HTMLHeadingElement'},
{tag: 'h2', interface: 'HTMLHeadingElement'},
{tag: 'h3', interface: 'HTMLHeadingElement'},
{tag: 'h4', interface: 'HTMLHeadingElement'},
{tag: 'h5', interface: 'HTMLHeadingElement'},
{tag: 'h6', interface: 'HTMLHeadingElement'},
{tag: 'header', interface: 'HTMLElement'},
{tag: 'hgroup', interface: 'HTMLElement'},
{tag: 'hr', interface: 'HTMLHRElement'},
{tag: 'html', interface: 'HTMLHtmlElement', parsing: 'document'},
{tag: 'i', interface: 'HTMLElement'},
{tag: 'iframe', interface: 'HTMLIFrameElement'},
{tag: 'img', interface: 'HTMLImageElement'},
{tag: 'input', interface: 'HTMLInputElement'},
{tag: 'ins', interface: 'HTMLModElement'},
{tag: 'kbd', interface: 'HTMLElement'},
{tag: 'label', interface: 'HTMLLabelElement'},
{tag: 'legend', interface: 'HTMLLegendElement'},
{tag: 'li', interface: 'HTMLLIElement'},
{tag: 'link', interface: 'HTMLLinkElement'},
{tag: 'main', interface: 'HTMLElement'},
{tag: 'map', interface: 'HTMLMapElement'},
{tag: 'mark', interface: 'HTMLElement'},
{tag: 'menu', interface: 'HTMLMenuElement'},
{tag: 'meta', interface: 'HTMLMetaElement'},
{tag: 'meter', interface: 'HTMLMeterElement'},
{tag: 'nav', interface: 'HTMLElement'},
{tag: 'noscript', interface: 'HTMLElement'},
{tag: 'object', interface: 'HTMLObjectElement'},
{tag: 'ol', interface: 'HTMLOListElement'},
{tag: 'optgroup', interface: 'HTMLOptGroupElement'},
{tag: 'option', interface: 'HTMLOptionElement'},
{tag: 'output', interface: 'HTMLOutputElement'},
{tag: 'p', interface: 'HTMLParagraphElement'},
{tag: 'param', interface: 'HTMLParamElement'},
{tag: 'picture', interface: 'HTMLPictureElement'},
{tag: 'pre', interface: 'HTMLPreElement'},
{tag: 'progress', interface: 'HTMLProgressElement'},
{tag: 'q', interface: 'HTMLQuoteElement'},
{tag: 'rp', interface: 'HTMLElement'},
{tag: 'rt', interface: 'HTMLElement'},
{tag: 'ruby', interface: 'HTMLElement'},
{tag: 's', interface: 'HTMLElement'},
{tag: 'samp', interface: 'HTMLElement'},
{tag: 'script', interface: 'HTMLScriptElement'},
{tag: 'section', interface: 'HTMLElement'},
{tag: 'select', interface: 'HTMLSelectElement'},
{tag: 'small', interface: 'HTMLElement'},
{tag: 'source', interface: 'HTMLSourceElement'},
{tag: 'span', interface: 'HTMLSpanElement'},
{tag: 'strong', interface: 'HTMLElement'},
{tag: 'style', interface: 'HTMLStyleElement'},
{tag: 'sub', interface: 'HTMLElement'},
{tag: 'summary', interface: 'HTMLElement'},
{tag: 'sup', interface: 'HTMLElement'},
{tag: 'table', interface: 'HTMLTableElement'},
{tag: 'tbody', interface: 'HTMLTableSectionElement', parsing: 'table'},
{tag: 'td', interface: 'HTMLTableCellElement', parsing: 'table'},
{tag: 'template', interface: 'HTMLTemplateElement'},
{tag: 'textarea', interface: 'HTMLTextAreaElement'},
{tag: 'tfoot', interface: 'HTMLTableSectionElement', parsing: 'table'},
{tag: 'th', interface: 'HTMLTableCellElement', parsing: 'table'},
{tag: 'thead', interface: 'HTMLTableSectionElement', parsing: 'table'},
{tag: 'time', interface: 'HTMLTimeElement'},
{tag: 'title', interface: 'HTMLTitleElement'},
{tag: 'tr', interface: 'HTMLTableRowElement', parsing: 'table'},
{tag: 'track', interface: 'HTMLTrackElement'},
{tag: 'u', interface: 'HTMLElement'},
{tag: 'ul', interface: 'HTMLUListElement'},
{tag: 'var', interface: 'HTMLElement'},
{tag: 'video', interface: 'HTMLVideoElement'},
{tag: 'wbr', interface: 'HTMLElement'},
];
// HTMLDataListElement isn't implemented by all major browsers yet.
if (window.HTMLDataListElement) {
testData.push({tag: 'datalist', interface: 'HTMLDataListElement'});
}
// HTMLDialogElement isn't implemented by all major browsers yet.
if (window.HTMLDialogElement) {
testData.push({tag: 'dialog', interface: 'HTMLDialogElement'});
}
// HTMLSlotElement isn't implemented by all major browsers yet.
if (window.HTMLSlotElement) {
testData.push({tag: 'slot', interface: 'HTMLSlotElement'});
}
for (const t of testData) {
test(() => {
let name = 'my-' + t.tag;
let klass = eval(`(class extends ${t.interface} {})`);
customElements.define(name, klass, { extends: t.tag });
test(() => {
let customized = new klass();
assert_equals(customized.constructor, klass);
assert_equals(customized.cloneNode().constructor, klass,
'Cloning a customized built-in element should succeed.');
}, `${t.tag}: Operator 'new' should instantiate a customized built-in element`);
test(() => {
let customized = document.createElement(t.tag, { is: name });
assert_equals(customized.constructor, klass);
assert_equals(customized.cloneNode().constructor, klass,
'Cloning a customized built-in element should succeed.');
}, `${t.tag}: document.createElement() should instantiate a customized built-in element`);
if (t.parsing == 'document') {
let test = async_test(`${t.tag}: document parser should instantiate a customized built-in element`);
window.addEventListener('load', test.step_func_done(() => {
let customized = document.querySelector(t.tag);
assert_equals(customized.constructor, klass);
assert_equals(customized.cloneNode().constructor, klass,
'Cloning a customized built-in element should succeed.');
}));
return;
}
test(() => {
let container = document.getElementById('container');
if (t.parsing == 'table') {
container.innerHTML = `<table><${t.tag} is="${name}" id="${name}">`;
} else {
container.innerHTML = `<${t.tag} is="${name}" id="${name}">`;
}
let customized = document.getElementById(name);
assert_equals(customized.constructor, klass);
assert_equals(customized.cloneNode().constructor, klass,
'Cloning a customized built-in element should succeed.');
}, `${t.tag}: innerHTML should instantiate a customized built-in element`);
}, `${t.tag}: Define a customized built-in element`);
}
</script>
</body>
</html>
|