<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/gc.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
const limit = 10;
promise_test(async t => {
const baseline = internals.peerConnectionCount();
let pc;
for (let count = 0; count < limit; count++) {
pc = new RTCPeerConnection();
pc.close();
}
await asyncGC();
// All the non-referenced PCs should now be collected.
if (baseline == 0) {
assert_equals(internals.peerConnectionCount(), 1, "Failed at Check 1 (baseline zero)");
} else {
// Some or all of the baseline PCs may also have been collected
assert_between_inclusive(internals.peerConnectionCount(), 1, baseline + 1, "Failed at Check 1 (baseline " + baseline + ")");
}
pc = null;
await asyncGC();
if (baseline == 0) {
assert_equals(internals.peerConnectionCount(), 0, "Failed at Check 2 (baseline zero)");
} else {
// Some or all of the baseline PCs may also have been collected
assert_between_inclusive(internals.peerConnectionCount(), 0, baseline, "Failed at Check 2 (baseline " + baseline + ")");
}
}, 'Closed Peerconnections are garbage collected');
promise_test(async t => {
const baseline = internals.peerConnectionCount();
for (let count = 0; count < limit; count++) {
pc = new RTCPeerConnection();
}
pc = null;
await asyncGC();
if (baseline == 0) {
assert_equals(internals.peerConnectionCount(), limit, "Failed at open PC (baseline zero)");
} else {
// Some or all of the baseline PCs may also have been collected
assert_between_inclusive(internals.peerConnectionCount(), limit, baseline + limit, "Failed at open PC (baseline " + baseline + ")");
}
}, 'Non-closed Peerconnections are NOT garbage collected');
</script>
</body>
</html>