Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / profiler / heap-snapshot-weak-dominator.html
1 <html>
2 <head>
3   <script src="../../http/tests/inspector/inspector-test.js"></script>
4   <script src="heap-snapshot-test.js"></script>
5 <script>
6
7 function test()
8 {
9     InspectorTest.runHeapSnapshotTestSuite([
10         function testWeakReferencesDoNotAffectRetainedSize(next)
11         {
12             function createHeapSnapshot()
13             {
14                 // Mocking results of running the following code:
15                 // root = [new Uint8Array(1000), new Uint8Array(1000), new Uint8Array(1000)]
16                 var builder = new InspectorTest.HeapSnapshotBuilder();
17                 var rootNode = builder.rootNode;
18
19                 var gcRootsNode = new InspectorTest.HeapNode("(GC roots)");
20                 rootNode.linkNode(gcRootsNode, InspectorTest.HeapEdge.Type.element);
21
22                 var windowNode = new InspectorTest.HeapNode("Window", 20);
23                 rootNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.shortcut);
24                 gcRootsNode.linkNode(windowNode, InspectorTest.HeapEdge.Type.element);
25
26                 var arrayNode = new InspectorTest.HeapNode("Array", 10);
27                 windowNode.linkNode(arrayNode, InspectorTest.HeapEdge.Type.property, "root");
28                 var prevBufferNode = null;
29                 for (var i = 0; i < 3; i++) {
30                     var typedArrayNode = new InspectorTest.HeapNode("Uint8Array", 100);
31                     arrayNode.linkNode(typedArrayNode, InspectorTest.HeapEdge.Type.element);
32
33                     var bufferNode = new InspectorTest.HeapNode("ArrayBuffer", 1000);
34                     typedArrayNode.linkNode(bufferNode, InspectorTest.HeapEdge.Type.internal);
35                     if (prevBufferNode)
36                         prevBufferNode.linkNode(bufferNode, InspectorTest.HeapEdge.Type.weak, "weak_next");
37                     prevBufferNode = bufferNode;
38                 }
39
40                 return builder.generateSnapshot();
41             }
42
43             InspectorTest.takeAndOpenSnapshot(createHeapSnapshot, step1);
44
45             function step1()
46             {
47                 InspectorTest.switchToView("Summary", step2);
48             }
49
50             function step2()
51             {
52                 var row = InspectorTest.findRow("Array");
53                 InspectorTest.assertEquals(true, !!row, "\"Array\" row");
54                 InspectorTest.expandRow(row, step3);
55             }
56
57             function step3(row)
58             {
59                 InspectorTest.assertEquals(1, row._count);
60                 InspectorTest.assertEquals(3310, row._retainedSize);
61                 InspectorTest.assertEquals(10, row._shallowSize);
62                 InspectorTest.expandRow(row.children[0], step4);
63             }
64
65             function step4(arrayInstanceRow)
66             {
67                 InspectorTest.assertEquals(2, arrayInstanceRow._distance);
68                 InspectorTest.assertEquals(3310, arrayInstanceRow._retainedSize);
69                 InspectorTest.assertEquals(10, arrayInstanceRow._shallowSize);
70
71                 var children = arrayInstanceRow.children;
72                 InspectorTest.assertEquals(3, children.length);
73
74                 for (var i = 0; i < children.length; i++) {
75                     InspectorTest.assertEquals("Uint8Array", children[i]._name);
76                     InspectorTest.assertEquals(100, children[i]._shallowSize);
77                     InspectorTest.assertEquals(1100, children[i]._retainedSize);
78                 }
79                 setTimeout(next, 0);
80             }
81         }
82     ]);
83 }
84
85 </script>
86 </head>
87 <body onload="runTest()">
88 <pre>
89 Tests that weak references are ignored when dominators are calculated and that weak references won't affect object's retained size.
90 </pre>
91 </body>
92 </html>