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
|
<!DOCTYPE html>
<title>Node.normalize()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
test(function() {
var df = document.createDocumentFragment(),
t1 = document.createTextNode("1"),
t2 = document.createTextNode("2"),
t3 = document.createTextNode("3"),
t4 = document.createTextNode("4")
df.appendChild(t1)
df.appendChild(t2)
assert_equals(df.childNodes.length, 2)
assert_equals(df.textContent, "12")
var el = document.createElement('x')
df.appendChild(el)
el.appendChild(t3)
el.appendChild(t4)
document.normalize()
assert_equals(el.childNodes.length, 2)
assert_equals(el.textContent, "34")
assert_equals(df.childNodes.length, 3)
assert_equals(t1.data, "1")
df.normalize()
assert_equals(df.childNodes.length, 2)
assert_equals(df.firstChild, t1)
assert_equals(t1.data, "12")
assert_equals(t2.data, "2")
assert_equals(el.firstChild, t3)
assert_equals(t3.data, "34")
assert_equals(t4.data, "4")
})
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=19837
test(function() {
var div = document.createElement("div")
var t1 = div.appendChild(document.createTextNode(""))
var t2 = div.appendChild(document.createTextNode("a"))
var t3 = div.appendChild(document.createTextNode(""))
assert_array_equals(div.childNodes, [t1, t2, t3])
div.normalize();
assert_array_equals(div.childNodes, [t2])
}, "Empty text nodes separated by a non-empty text node")
test(function() {
var div = document.createElement("div")
var t1 = div.appendChild(document.createTextNode(""))
var t2 = div.appendChild(document.createTextNode(""))
assert_array_equals(div.childNodes, [t1, t2])
div.normalize();
assert_array_equals(div.childNodes, [])
}, "Empty text nodes")
</script>
|