4 <script src=
"../../resources/js-test.js"></script>
8 var testCases
= [["div0", "div1", "div2"],
9 ["div0", "div2", "div1"],
10 ["div1", "div0", "div2"],
11 ["div1", "div2", "div0"],
12 ["div2", "div0", "div1"],
13 ["div2", "div1", "div0"]];
15 var rootDiv
= document
.createElement("div");
16 document
.body
.appendChild(rootDiv
);
17 var testHtml
= "<div id='div0-parent'><div id='div0'><div id='div0-child'></div></div><div id='div1-parent'><div id='div1'><div id='div1-child'></div></div><div id='div2-parent'><div id='div2'><div id='div2-child'></div></div></div></div></div>";
19 testCases
.forEach(function (test
) {
21 debug("=== Initial state ===");
22 rootDiv
.innerHTML
= testHtml
;
23 divX
= document
.getElementById(test
[0]);
24 divY
= document
.getElementById(test
[1]);
25 divZ
= document
.getElementById(test
[2]);
26 checkParentAndChildAlive(divX
, test
[0]);
27 checkParentAndChildAlive(divY
, test
[1]);
28 checkParentAndChildAlive(divZ
, test
[2]);
30 debug("=== After clearing innerHTML ===");
31 rootDiv
.innerHTML
= testHtml
;
32 divX
= document
.getElementById(test
[0]);
33 divY
= document
.getElementById(test
[1]);
34 divZ
= document
.getElementById(test
[2]);
35 rootDiv
.innerHTML
= "";
36 checkParentAndChildAlive(divX
, test
[0]);
37 checkParentAndChildAlive(divY
, test
[1]);
38 checkParentAndChildAlive(divZ
, test
[2]);
40 debug("=== After clearing innerHTML and divX ===");
41 rootDiv
.innerHTML
= testHtml
;
42 divX
= document
.getElementById(test
[0]);
43 divY
= document
.getElementById(test
[1]);
44 divZ
= document
.getElementById(test
[2]);
45 rootDiv
.innerHTML
= "";
48 checkParentAndChildAlive(divY
, test
[1]);
49 checkParentAndChildAlive(divZ
, test
[2]);
51 debug("=== After clearing innerHTML, divX and divY ===");
52 rootDiv
.innerHTML
= testHtml
;
53 divX
= document
.getElementById(test
[0]);
54 divY
= document
.getElementById(test
[1]);
55 divZ
= document
.getElementById(test
[2]);
56 rootDiv
.innerHTML
= "";
60 checkParentAndChildAlive(divZ
, test
[2]);
62 debug("=== After clearing innerHTML, divX, divY and divZ ===");
63 rootDiv
.innerHTML
= testHtml
;
64 divX
= document
.getElementById(test
[0]);
65 divY
= document
.getElementById(test
[1]);
66 divZ
= document
.getElementById(test
[2]);
68 prevNodes
= window
.internals
.numberOfLiveNodes();
69 rootDiv
.innerHTML
= "";
74 if (window
.internals
) {
75 // If all the Node objects in testHtml are successfully destructed,
76 // at least 9 <div>s objects will be removed.
77 // (Actually, since testHtml rendering requires more than 9 Node objects.)
78 if (window
.internals
.numberOfLiveNodes() <= prevNodes
- 9)
79 testPassed("All <div> objects in a DOM tree are successfully destructed.");
81 testFailed("<div> objects in a DOM tree are not destructed.");
85 function checkParentAndChildAlive(div
, name
) {
87 shouldBeEqualToString('globalDiv.id', name
);
88 shouldBeEqualToString('globalDiv.parentNode.id', name
+ "-parent");
89 shouldBeEqualToString('globalDiv.firstChild.id', name
+ "-child");
94 var successfullyParsed
= true;