4be577573523a4fe474135966f049bba5ab9ce10
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector-protocol / heap-profiler / heap-objects-tracking.html
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
4 <script>
5
6 if (window.testRunner) {
7     testRunner.dumpAsText();
8     testRunner.waitUntilDone();
9 }
10
11 function junkGenerator()
12 {
13     var junkArray = new Array(1000);
14     for (var i = 0; i < junkArray.length; ++i)
15         junkArray[i] = "42 " + i;
16     window.junkArray = junkArray;
17 }
18
19 function setupIntervalAndRunTest()
20 {
21     setInterval(junkGenerator, 0);
22     runTest();
23 }
24
25 function test()
26 {
27     InspectorTest.importScript("../../../../inspector-protocol/heap-profiler/resources/heap-snapshot-common.js");
28
29     var gotLastSeenObjectIdEvent = false;
30     var gotHeapStatsUpdateEvent = false;
31     var gotHeapProfilerHeader = false;
32     function trackingStarted()
33     {
34         InspectorTest.log("SUCCESS: tracking started");
35     }
36
37     function trackingStopped()
38     {
39         if (gotHeapStatsUpdateEvent)
40             InspectorTest.log("SUCCESS: heapStatsUpdate arrived");
41         if (gotLastSeenObjectIdEvent)
42             InspectorTest.log("SUCCESS: lastSeenObjectId arrived");
43         if (gotHeapProfilerHeader)
44             InspectorTest.log("SUCCESS: addProfileHeader arrived");
45         InspectorTest.log("SUCCESS: tracking stopped");
46         InspectorTest.completeTest();
47     }
48
49     var fragments = [];
50     InspectorTest.eventHandler["HeapProfiler.lastSeenObjectId"] = function(messageObject)
51     {
52
53         var params = messageObject["params"];
54         InspectorTest.assert(params, "no params found in event HeapProfiler.lastSeenObjectId");
55         InspectorTest.assert(params.lastSeenObjectId, "lastSeenObjectId is missing in event HeapProfiler.lastSeenObjectId");
56         InspectorTest.assert(params.timestamp, "timestamp is missing in event HeapProfiler.lastSeenObjectId");
57         InspectorTest.assert(fragments.length, "a heap stats fragment didn't arrive before HeapProfiler.lastSeenObjectId");
58         InspectorTest.sendCommand("HeapProfiler.stopTrackingHeapObjects", {}, trackingStopped);
59         gotLastSeenObjectIdEvent = true;
60     }
61
62     InspectorTest.eventHandler["HeapProfiler.heapStatsUpdate"] = function(messageObject)
63     {
64         var params = messageObject["params"];
65         InspectorTest.assert(params, "no params found in event HeapProfiler.heapStatsUpdate");
66         var statsUpdate = params.statsUpdate;
67         InspectorTest.assert(statsUpdate, "statsUpdata is missing in event HeapProfiler.heapStatsUpdate");
68         InspectorTest.assert(statsUpdate.length, "statsUpdate should have non zero length");
69         InspectorTest.assert(!(statsUpdate.length % 3), "statsUpdate length must be a multiple of three");
70         InspectorTest.assert(!(statsUpdate.length % 3), "statsUpdate length must be a multiple of three");
71         InspectorTest.assert(!statsUpdate[0], "statsUpdate: first fragmentIndex in first update has to be zero");
72         InspectorTest.assert(statsUpdate[1], "statsUpdate: total count of objects should be not zero");
73         InspectorTest.assert(statsUpdate[2], "statsUpdate: total size of objects should be not zero");
74         fragments.push(statsUpdate);
75         gotHeapStatsUpdateEvent = true;
76     }
77
78     InspectorTest.eventHandler["HeapProfiler.addProfileHeader"] = function(messageObject)
79     {
80         gotHeapProfilerHeader = true;
81     }
82
83     InspectorTest.sendCommand("HeapProfiler.startTrackingHeapObjects", {}, trackingStarted);
84     //@ sourceURL=heap-objects-tracking.html
85 }
86 </script>
87 </head>
88 <body onload="setupIntervalAndRunTest()">
89 <p>Test that heap tracking actually reports data fragments.</p>
90 </body>
91 </html>