Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / heap-profiler / heap-samples-in-snapshot.html
blob902327f351119885a6b769549ea41f356044c41d
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
6 if (window.testRunner) {
7 testRunner.dumpAsText();
8 testRunner.waitUntilDone();
11 function junkGenerator()
13 var junkArray = new Array(1000);
14 for (var i = 0; i < junkArray.length; ++i)
15 junkArray[i] = "42 " + i;
16 window.junkArray = junkArray;
19 function setupIntervalAndRunTest()
21 setInterval(junkGenerator, 0);
22 runTest();
25 function test()
27 InspectorTest.importScript("../../../../inspector-protocol/heap-profiler/resources/heap-snapshot-common.js");
29 function trackingStarted()
31 InspectorTest.log("Tracking started");
34 function arraysEqual(a, b)
36 var sa = a.join(", ");
37 var sb = b.join(", ");
38 if (sa === sb)
39 return true;
40 InspectorTest.log("FAIL:\na = [" + sa+ "]\nb = [" + sb + "]");
41 return false;
44 function trackingStopped(snapshot)
46 var samples = snapshot.getSamples();
47 InspectorTest.log("Last assigned id arrays match: " + arraysEqual(lastAssignedIds, samples.lastAssignedIds));
48 var sizesMatch = (sizes.length <= samples.sizes.length);
49 InspectorTest.log("Size arrays length is correct: " + sizesMatch);
50 if (!sizesMatch) {
51 // Print mismatch:
52 arraysEqual(sizes, samples.sizes);
54 var sizesNonGrowing = true;
55 for (var i = 0; i < samples.sizes.length; i++) {
56 if ((sizes[i] === undefined && samples.sizes[i] !== 0) || (sizes[i] < samples.sizes[i])) {
57 sizesNonGrowing = false;
58 InspectorTest.log("FAIL: total size of live objects from interval cannot increase.");
59 // Print mismatch:
60 arraysEqual(sizes, samples.sizes);
63 InspectorTest.log("Sizes non growing: " + sizesNonGrowing);
64 InspectorTest.completeTest();
67 var sizes = [];
68 var lastAssignedIds = [];
69 InspectorTest.eventHandler["HeapProfiler.lastSeenObjectId"] = function(messageObject)
71 lastAssignedIds.push(messageObject["params"]["lastSeenObjectId"]);
72 if (lastAssignedIds.length === 2) {
73 // Wait for two updates and then stop tracing.
74 InspectorTest.stopRecordingHeapTimeline(trackingStopped);
78 InspectorTest.eventHandler["HeapProfiler.heapStatsUpdate"] = function(messageObject)
80 var samples = messageObject["params"]["statsUpdate"];
81 for (var i = 0; i < samples.length; i += 3) {
82 index = samples[i];
83 sizes[index] = samples[i+2];
87 InspectorTest.sendCommand("HeapProfiler.startTrackingHeapObjects", {}, trackingStarted);
88 //@ sourceURL=heap-objects-tracking.html
90 </script>
91 </head>
92 <body onload="setupIntervalAndRunTest()">
93 <p>Test that heap tracking actually reports data fragments.</p>
94 </body>
95 </html>