878507a2712d2f94df856bf476a8cf8cd06bbc61
[WebKit-https.git] / LayoutTests / inspector / heap / garbageCollected.html
1 <!doctype html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script>
6 function triggerGCs()
7 {
8     function allocateObjects() {
9         var list = [];
10         for (var i = 0; i < 100; ++i)
11             list.push({x:i});
12         return list;
13     }
14
15     function allocateLargeList() {
16         var largeList = [];
17         for (var i = 0; i < 100; ++i)
18             largeList.push(allocateObjects());
19         return largeList;
20     }
21
22     var partialList = [];
23     for (var i = 0; i < 100; ++i)
24         partialList.push(allocateLargeList());
25 }
26
27 function periodicallyTriggerGCs()
28 {
29     setInterval(triggerGCs, 20);
30 }
31
32 function test()
33 {
34     let suite = InspectorTest.createAsyncSuite("Heap.garbageCollected");
35
36     suite.addTestCase({
37         name: "TriggerGCs",
38         description: "Evaluating allocation heavy JavaScript should trigger Heap.garbageCollected events.",
39         test: (resolve, reject) => {
40             InspectorTest.evaluateInPage("periodicallyTriggerGCs()");
41
42             let seenFull = false;
43             let seenPartial = false;
44             WebInspector.heapManager.addEventListener(WebInspector.HeapManager.Event.GarbageCollected, (event) => {
45                 if (seenFull && seenPartial)
46                     return;
47
48                 if (event.data.collection.type === WebInspector.GarbageCollection.Type.Full)
49                     seenFull = true;
50                 else if (event.data.collection.type === WebInspector.GarbageCollection.Type.Partial)
51                     seenPartial = true;
52
53                 if (seenFull && seenPartial) {
54                     InspectorTest.log("PASS: Should see both a Partial and Full Garbage Collection.");
55                     resolve();
56                 }
57             });
58         }
59     });
60
61     suite.runTestCasesAndFinish();
62 }
63 </script>
64 </head>
65 <body onload="runTest()">
66 <p>Test for the Heap.garbageCollected event.</p>
67 </body>
68 </html>