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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
<!DOCTYPE html>
<title>innerHTML in HTML</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<!-- test elments. Each has an expected innerHTML and outerHTML in an array in the <script>-->
<div id="test" style="display:none">
<span></span>
<span><a></a></span>
<span><a b=c></a></span>
<span><a b='c'></a></span>
<span><a b='&'></a></span>
<span><a b=' '></a></span>
<span><a b='"'></a></span>
<span><a b="<"></a></span>
<span><a b=">"></a></span>
<span><a href="javascript:"<>""></a></span>
<span><svg xlink:href="a"></svg></span>
<span><svg xmlns:svg="test"></svg></span>
<span>a</span>
<span>&</span>
<span> </span>
<span><</span>
<span>></span>
<span>"</span>
<span><style><&></style></span>
<span><script type="test"><&></script></span>
<script type="test"><&></script>
<span><xmp><&></xmp></span>
<span><iframe><&></iframe></span>
<span><noembed><&></noembed></span>
<span><noframes><&></noframes></span>
<span><noscript><&></noscript></span>
<span><!--data--></span>
<span><a><b><c></c></b><d>e</d><f><g>h</g></f></a></span>
<span b=c></span>
</div>
<!-- TODO: template element -->
<script>
var test_data = document.getElementById("test").children;
var expected = [
["", "<span></span>"],
["<a></a>", "<span><a></a></span>"],
["<a b=\"c\"></a>", "<span><a b=\"c\"></a></span>"],
["<a b=\"c\"></a>", "<span><a b=\"c\"></a></span>"],
["<a b=\"&\"></a>", "<span><a b=\"&\"></a></span>"],
["<a b=\" \"></a>", "<span><a b=\" \"></a></span>"],
["<a b=\""\"></a>", "<span><a b=\""\"></a></span>"],
["<a b=\"<\"></a>", "<span><a b=\"<\"></a></span>"],
["<a b=\">\"></a>", "<span><a b=\">\"></a></span>"],
["<a href=\"javascript:"<>"\"></a>", "<span><a href=\"javascript:"<>"\"></a></span>"],
["<svg xlink:href=\"a\"></svg>", "<span><svg xlink:href=\"a\"></svg></span>"],
["<svg xmlns:svg=\"test\"></svg>", "<span><svg xmlns:svg=\"test\"></svg></span>"],
["a", "<span>a</span>"],
["&", "<span>&</span>"],
[" ", "<span> </span>"],
["<", "<span><</span>"],
[">", "<span>></span>"],
["\"", "<span>\"</span>"],
["<style><&></style>", "<span><style><&></style></span>"],
["<script type=\"test\"><&><\/script>", "<span><script type=\"test\"><&><\/script></span>"],
["<&>", "<script type=\"test\"><&><\/script>"],
["<xmp><&></xmp>", "<span><xmp><&></xmp></span>"],
["<iframe><&></iframe>", "<span><iframe><&></iframe></span>"],
["<noembed><&></noembed>", "<span><noembed><&></noembed></span>"],
["<noframes><&></noframes>", "<span><noframes><&></noframes></span>"],
["<noscript><&></noscript>", "<span><noscript><&></noscript></span>"],
["<!--data-->", "<span><!--data--></span>"],
["<a><b><c></c></b><d>e</d><f><g>h</g></f></a>", "<span><a><b><c></c></b><d>e</d><f><g>h</g></f></a></span>"],
["", "<span b=\"c\"></span>"]
];
var dom_tests = [
["Attribute in the XML namespace",
function() {
var span = document.createElement("span");
var svg = document.createElement("svg");
svg.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:foo", "test");
span.appendChild(svg);
return span;
},
'<svg xml:foo="test"></svg>',
'<span><svg xml:foo="test"></svg></span>'],
["Attribute in the XML namespace with the prefix not set to xml:",
function() {
var span = document.createElement("span");
var svg = document.createElement("svg");
svg.setAttributeNS("http://www.w3.org/XML/1998/namespace", "abc:foo", "test");
span.appendChild(svg);
return span;
},
'<svg xml:foo="test"></svg>',
'<span><svg xml:foo="test"></svg></span>'],
["Non-'xmlns' attribute in the xmlns namespace",
function() {
var span = document.createElement("span");
var svg = document.createElement("svg");
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:foo", "test")
span.appendChild(svg);
return span;
},
'<svg xmlns:foo="test"></svg>',
'<span><svg xmlns:foo="test"></svg></span>'],
["'xmlns' attribute in the xmlns namespace",
function() {
var span = document.createElement("span");
var svg = document.createElement("svg");
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "test")
span.appendChild(svg);
return span;
},
'<svg xmlns="test"></svg>',
'<span><svg xmlns="test"></svg></span>'],
["Attribute in non-standard namespace",
function() {
var span = document.createElement("span");
var svg = document.createElement("svg");
svg.setAttributeNS("fake_ns", "abc:def", "test")
span.appendChild(svg);
return span;
},
'<svg abc:def="test"></svg>',
'<span><svg abc:def="test"></svg></span>'],
["<span> starting with U+000A",
function() {
var elem = document.createElement("span");
elem.appendChild(document.createTextNode("\x0A"));
return elem;
},
"\x0A",
"<span>\x0A</span>"],
//TODO: Processing instructions
]
var text_elements = ["pre", "textarea", "listing"];
var text_tests = [
["<%text> context starting with U+000A",
function(elem) {
elem.appendChild(document.createTextNode("\x0A"));
return elem;
},
"\x0A",
"<%text>\x0A</%text>"],
["<%text> context not starting with U+000A",
function(elem) {
elem.appendChild(document.createTextNode("a\x0A"));
return elem;
},
"a\x0A",
"<%text>a\x0A</%text>"],
["<%text> non-context starting with U+000A",
function(elem) {
var span = document.createElement("span");
elem.appendChild(document.createTextNode("\x0A"));
span.appendChild(elem);
return span;
},
"<%text>\x0A</%text>",
"<span><%text>\x0A</%text></span>"],
["<%text> non-context not starting with U+000A",
function(elem) {
var span = document.createElement("span");
elem.appendChild(document.createTextNode("a\x0A"));
span.appendChild(elem);
return span;
},
"<%text>a\x0A</%text>",
"<span><%text>a\x0A</%text></span>"],
]
var void_elements = [
"area", "base", "basefont", "bgsound", "br", "col", "embed",
"frame", "hr", "img", "input", "keygen", "link",
"meta", "param", "source", "track", "wbr"
];
var void_tests = [
["Void context node",
function (void_elem) {
return void_elem;
},
"",
"<%void>"
],
["void as first child with following siblings",
function (void_elem) {
var span = document.createElement("span");
span.appendChild(void_elem);
span.appendChild(document.createElement("a")).appendChild(document.createTextNode("test"));
span.appendChild(document.createElement("b"))
return span
},
"<%void><a>test</a><b></b>",
"<span><%void><a>test</a><b></b></span>"
],
["void as second child with following siblings",
function (void_elem) {
var span = document.createElement("span");
span.appendChild(document.createElement("a")).appendChild(document.createTextNode("test"));
span.appendChild(void_elem);
span.appendChild(document.createElement("b"))
return span;
},
"<a>test</a><%void><b></b>",
"<span><a>test</a><%void><b></b></span>"
],
["void as last child with preceding siblings",
function (void_elem) {
var span = document.createElement("span");
span.appendChild(document.createElement("a")).appendChild(document.createTextNode("test"));
span.appendChild(document.createElement("b"))
span.appendChild(void_elem);
return span;
},
"<a>test</a><b></b><%void>",
"<span><a>test</a><b></b><%void></span>"
],
]
function cross_map(a1, a2, f) {
var rv = [];
a1.forEach(function(a1_elem) {
a2.forEach(function(a2_elem) {
rv.push(f(a1_elem, a2_elem));
})
});
return rv;
}
function innerHTML_test(func, elem, expected) {
assert_equals(func(elem).innerHTML, expected);
}
function outerHTML_test(func, elem, expected) {
assert_equals(func(elem).outerHTML, expected);
}
function make_void(name) {
var rv = document.createElement(name);
rv.appendChild(document.createElement("a")).appendChild(document.createComment("abc"))
rv.appendChild(document.createElement("b")).
appendChild(document.createElement("c")).
appendChild(document.createTextNode("abc"))
return rv;
}
function make_text(name) {
return document.createElement(name);
}
generate_tests(innerHTML_test,
expected.map(function(item, i) {
return ["innerHTML " + i + " " + expected[i][0],
function() {return test_data[i]},
null,
item[0]];
}))
generate_tests(outerHTML_test,
expected.map(function(item, i) {
return ["outerHTML " + i + " " + expected[i][1],
function() {return test_data[i]},
null,
item[1]];
}))
generate_tests(innerHTML_test,
dom_tests.map(function(item) {
return ["innerHTML " + item[0],
item[1],
null,
item[2]];
}))
generate_tests(outerHTML_test,
dom_tests.map(function(item) {
return ["outerHTML " + item[0],
item[1],
null,
item[3]];
}))
generate_tests(innerHTML_test,
cross_map(text_tests, text_elements,
function(test_data, elem_name) {
var rv = ["innerHTML " + test_data[0].replace(/%text/g, elem_name),
test_data[1],
document.createElement(elem_name),
test_data[2].replace(/%text/g, elem_name)];
return rv;
}))
generate_tests(outerHTML_test,
cross_map(text_tests, text_elements,
function(test_data, elem_name) {
var rv = ["outerHTML " + test_data[0].replace(/%text/g, elem_name),
test_data[1],
document.createElement(elem_name),
test_data[3].replace(/%text/g, elem_name)];
return rv;
}))
generate_tests(innerHTML_test,
cross_map(void_tests, void_elements,
function(test_data, elem_name) {
var rv = ["innerHTML " + test_data[0] + " " + elem_name,
test_data[1],
make_void(elem_name),
test_data[2].replace(/%void/g, elem_name)];
return rv;
}))
generate_tests(outerHTML_test,
cross_map(void_tests, void_elements,
function(test_data, elem_name) {
var rv = ["outerHTML " + test_data[0] + " " + elem_name,
test_data[1],
make_void(elem_name),
test_data[3].replace(/%void/g, elem_name)];
return rv;
}))
</script>
|