Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / gc-dom-tree-lifetime.html
blob06f1420ab812606f8c6638dfeb5dc71bfde89e92
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <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) {
20 var divX, divY, divZ;
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 = "";
46 divX = null;
47 gc();
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 = "";
57 divX = null;
58 divY = null;
59 gc();
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]);
67 if (window.internals)
68 prevNodes = window.internals.numberOfLiveNodes();
69 rootDiv.innerHTML = "";
70 divX = null;
71 divY = null;
72 divZ = null;
73 gc();
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.");
80 else
81 testFailed("<div> objects in a DOM tree are not destructed.");
83 });
85 function checkParentAndChildAlive(div, name) {
86 globalDiv = div;
87 shouldBeEqualToString('globalDiv.id', name);
88 shouldBeEqualToString('globalDiv.parentNode.id', name + "-parent");
89 shouldBeEqualToString('globalDiv.firstChild.id', name + "-child");
90 globalDiv = null;
91 gc();
94 var successfullyParsed = true;
95 </script>
96 </body>
97 </html>