blob: 9d550d2e060625540019093fe2af581f1a48c6e9 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function triggerGCs()
{
function allocateObjects() {
var list = [];
for (var i = 0; i < 100; ++i)
list.push({x:i});
return list;
}
function allocateLargeList() {
var largeList = [];
for (var i = 0; i < 100; ++i)
largeList.push(allocateObjects());
return largeList;
}
var partialList = [];
for (var i = 0; i < 100; ++i)
partialList.push(allocateLargeList());
}
function periodicallyTriggerGCs()
{
setInterval(triggerGCs, 20);
}
function test()
{
let suite = InspectorTest.createAsyncSuite("Heap.garbageCollected");
suite.addTestCase({
name: "TriggerGCs",
description: "Evaluating allocation-heavy JavaScript should trigger Heap.garbageCollected events.",
test(resolve, reject) {
InspectorTest.evaluateInPage("periodicallyTriggerGCs()");
let seenFull = false;
let seenPartial = false;
WI.heapManager.addEventListener(WI.HeapManager.Event.GarbageCollected, (event) => {
if (seenFull && seenPartial)
return;
if (event.data.collection.type === WI.GarbageCollection.Type.Full)
seenFull = true;
else if (event.data.collection.type === WI.GarbageCollection.Type.Partial)
seenPartial = true;
if (seenFull && seenPartial) {
InspectorTest.log("PASS: Should see both a Partial and Full Garbage Collection.");
resolve();
}
});
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Test for the Heap.garbageCollected event.</p>
</body>
</html>