<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Testing garbage collection after getting tracks</title>
        <script src="../resources/testharness.js"></script>
        <script src="../resources/testharnessreport.js"></script>
    </head>
    <body>
        <script src ="routines.js"></script>
        <script>
promise_test((test) => {
    if (window.testRunner)
        testRunner.setUserMediaPermission(true);

    return navigator.mediaDevices.getUserMedia({ video: true, audio: true}).then((stream) => {
        return new Promise((resolve, reject) => {
            createConnections((firstConnection) => {
                firstConnection.addTrack(stream.getVideoTracks()[0], stream);
                firstConnection.addTrack(stream.getAudioTracks()[0], stream);
            }, (secondConnection) => {
                secondConnection.ontrack = resolve;
            });
            setTimeout(() => reject("Test timed out"), 5000);
        });
    }).then(() => {
        if (window.GCController)
            window.GCController.collect();
        waitFor(1000);
    });
}, "Ensuring collecting tracks does not lead to crashing");
        </script>
    </body>
</html>
