1<html>
2<head>
3<script type="text/javascript" src="../http/tests/inspector-protocol/resources/protocol-test.js"></script>
4<script>
5if (window.testRunner) {
6 testRunner.dumpAsText();
7 testRunner.waitUntilDone();
8}
9
10function addEventListenerAndRunTest()
11{
12 function myEventListener(e) {
13 console.log("myEventListener");
14 }
15 document.body.addEventListener("click", myEventListener, true);
16
17 runTest();
18}
19
20function test()
21{
22 if (!window.WebInspector)
23 window.WebInspector = {};
24 InspectorTest.importScript("../../../../../Source/WebCore/inspector/front-end/HeapSnapshot.js");
25 InspectorTest.importScript("../../../../../Source/WebCore/inspector/front-end/JSHeapSnapshot.js");
26
27 InspectorTest.eventHandler["Profiler.addProfileHeader"] = function(messageObject)
28 {
29 var profileId = messageObject["params"]["header"]["uid"];
30 InspectorTest.sendCommand("Profiler.getHeapSnapshot", { "uid": profileId }, didGetHeapSnapshot);
31
32 function didGetHeapSnapshot(messageObject)
33 {
34 InspectorTest.log("SUCCESS: didGetHeapSnapshot");
35 InspectorTest.completeTest();
36 }
37 }
38
39 var chunks = [];
40 InspectorTest.eventHandler["Profiler.addHeapSnapshotChunk"] = function(messageObject)
41 {
42 chunks.push(messageObject["params"]["chunk"]);
43 }
44 InspectorTest.eventHandler["Profiler.finishHeapSnapshot"] = function(messageObject)
45 {
46 var serializedSnapshot = chunks.join("");
47 var parsed = JSON.parse(serializedSnapshot);
48 var snapshot = new WebInspector.JSHeapSnapshot(parsed);
49
50 var node;
51 for (var it = snapshot._allNodes(); it.hasNext(); it.next()) {
52 if (it.node.type() === "closure" && it.node.name() === "myEventListener") {
53 node = it.node;
54 break;
55 }
56 }
57 if (node)
58 InspectorTest.log("SUCCESS: found " + node.name());
59 else {
60 InspectorTest.log("FAIL: cannot find detached DOM trees root");
61 InspectorTest.completeTest();
62 return;
63 }
64
65 var nativeRetainers = 0;
66 for (var iter = node.retainers(); iter.hasNext(); iter.next()) {
67 var node = iter.retainer.node();
68 var retainingEdge = iter.retainer;
69 if (retainingEdge.isInternal() && retainingEdge.name() === "native") {
70 if (++nativeRetainers === 1) {
71 var retainerName = retainingEdge.node().name();
72 if (retainerName === "HTMLBodyElement")
73 InspectorTest.log("SUCCESS: found link from HTMLBodyElement to " + node.name());
74 else
75 return fail("unexpected retainer of " + node.name() + ": " + retainerName);
76 } else
77 return fail("too many retainers of " + node.name());
78 } else if (!retainingEdge.isWeak())
79 return fail("unexpected retaining edge of " + node.name() + " type: " + retainingEdge.type() + ", name: " + retainingEdge.name());
80 }
81 if (!nativeRetainers)
82 return fail("cannot find HTMLBodyElement among retainers of " + node.name());
83 }
84
85 function fail(message) {
86 InspectorTest.log("FAIL: " + message);
87 InspectorTest.completeTest();
88 }
89
90 InspectorTest.sendCommand("Profiler.takeHeapSnapshot", {});
91}
92</script>
93</head>
94<body onload="addEventListenerAndRunTest()">
95<p>Test that all nodes from the detached DOM tree will get into one group in the heap snapshot. <a href="https://bugs.webkit.org/show_bug.cgi?id=107819">Bug 107819.</p>
96</body>
97</html>