/
test_node_normalize.html
35 lines (29 loc) · 1.27 KB
/
test_node_normalize.html
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
<!DOCTYPE html>
<html>
<head>
<script src="harness.js"></script>
</head>
<body>
<script>
// test1: Node.normalize
var parent1 = document.createElement("div");
var child1 = document.createTextNode("aaa");
var child2 = document.createTextNode("");
var child3 = document.createTextNode("bb");
var parent2 = document.createElement("div");
parent1.appendChild(child1);
parent1.appendChild(child2);
parent1.appendChild(child3);
parent2.appendChild(document.createTextNode(""));
parent1.normalize();
parent2.normalize();
is(Array.prototype.map.call(parent1.childNodes, function(el) {return el.length}).indexOf(0), -1, "Node.normalize removes empty text nodes");
is(parent1.childNodes.length, 1, "Node.normalize merges text nodes in one");
is(parent1.childNodes[0].length, 5, "test 1-2, Node.normalize merges text nodes values");
is(parent2.childNodes.length, 0, "Node.normalize removes empty text nodes even if there is only one text node");
is(child2.textContent, "", "Node.normalize doesn't change removed children original content")
is(child3.textContent, "bb", "Node.normalize doesn't change removed children original content")
finish();
</script>
</body>
</html>