<!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;
            WebInspector.heapManager.addEventListener(WebInspector.HeapManager.Event.GarbageCollected, (event) => {
                if (seenFull && seenPartial)
                    return;

                if (event.data.collection.type === WebInspector.GarbageCollection.Type.Full)
                    seenFull = true;
                else if (event.data.collection.type === WebInspector.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>
