3 <script src=
"../../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"heap-snapshot-test.js"></script>
9 InspectorTest
.runHeapSnapshotTestSuite([
10 function testWeakReferencesDoNotAffectRetainedSize(next
)
12 function createHeapSnapshot()
14 // Mocking a heap snapshot with a node that retained by weak references only.
15 var builder
= new InspectorTest
.HeapSnapshotBuilder();
16 var rootNode
= builder
.rootNode
;
18 var gcRootsNode
= new InspectorTest
.HeapNode("(GC roots)");
19 rootNode
.linkNode(gcRootsNode
, InspectorTest
.HeapEdge
.Type
.element
);
21 var windowNode
= new InspectorTest
.HeapNode("Window", 10);
22 rootNode
.linkNode(windowNode
, InspectorTest
.HeapEdge
.Type
.shortcut
);
23 gcRootsNode
.linkNode(windowNode
, InspectorTest
.HeapEdge
.Type
.element
);
25 var orphanNode
= new InspectorTest
.HeapNode("Orphan", 2000);
26 windowNode
.linkNode(orphanNode
, InspectorTest
.HeapEdge
.Type
.weak
, "weak_ref");
28 var orphanChildNode
= new InspectorTest
.HeapNode("OrphanChild", 2000);
29 orphanNode
.linkNode(orphanChildNode
, InspectorTest
.HeapEdge
.Type
.property
, "child");
31 var aNode
= new InspectorTest
.HeapNode("A", 300);
32 windowNode
.linkNode(aNode
, InspectorTest
.HeapEdge
.Type
.property
, "a");
34 var bNode
= new InspectorTest
.HeapNode("B", 300);
35 aNode
.linkNode(bNode
, InspectorTest
.HeapEdge
.Type
.property
, "b");
36 orphanChildNode
.linkNode(bNode
, InspectorTest
.HeapEdge
.Type
.property
, "b");
38 // Shortcut links should not affect retained sizes.
39 rootNode
.linkNode(windowNode
, InspectorTest
.HeapEdge
.Type
.shortcut
, "w");
40 rootNode
.linkNode(aNode
, InspectorTest
.HeapEdge
.Type
.shortcut
, "a");
41 rootNode
.linkNode(bNode
, InspectorTest
.HeapEdge
.Type
.shortcut
, "b");
42 rootNode
.linkNode(orphanNode
, InspectorTest
.HeapEdge
.Type
.shortcut
, "o");
44 return builder
.generateSnapshot();
47 InspectorTest
.addSniffer(WebInspector
.HeapSnapshotView
.prototype, "_gotStatistics", checkStatistics
, true);
48 InspectorTest
.takeAndOpenSnapshot(createHeapSnapshot
, step1
);
50 function checkStatistics(statistics
)
52 InspectorTest
.assertEquals(4610, statistics
.total
);
53 InspectorTest
.assertEquals(4610, statistics
.v8heap
);
54 InspectorTest
.addResult("SUCCESS: total size is correct.");
59 InspectorTest
.switchToView("Summary", step2
);
64 var row
= InspectorTest
.findRow("A");
65 InspectorTest
.assertEquals(true, !!row
, "\"A\" row");
66 InspectorTest
.assertEquals(1, row
._count
);
67 InspectorTest
.assertEquals(300, row
._retainedSize
);
68 InspectorTest
.assertEquals(300, row
._shallowSize
);
71 row
= InspectorTest
.findRow("B");
72 InspectorTest
.assertEquals(true, !!row
, "\"B\" row");
73 InspectorTest
.assertEquals(1, row
._count
);
74 InspectorTest
.assertEquals(300, row
._retainedSize
);
75 InspectorTest
.assertEquals(300, row
._shallowSize
);
77 row
= InspectorTest
.findRow("Orphan");
78 InspectorTest
.assertEquals(true, !!row
, "\"Orphan\" row");
79 InspectorTest
.assertEquals(1, row
._count
);
80 InspectorTest
.assertEquals(4000, row
._retainedSize
);
81 InspectorTest
.assertEquals(2000, row
._shallowSize
);
84 row
= InspectorTest
.findRow("OrphanChild");
85 InspectorTest
.assertEquals(true, !!row
, "\"OrphanChild\" row");
86 InspectorTest
.assertEquals(1, row
._count
);
87 InspectorTest
.assertEquals(2000, row
._retainedSize
);
88 InspectorTest
.assertEquals(2000, row
._shallowSize
);
90 InspectorTest
.addResult("SUCCESS: all nodes have expected retained sizes.");
99 <body onload=
"runTest()">
101 Tests that weak references are ignored when dominators are calculated and that weak references won't affect object's retained size.