<!doctype html>
<html>
<head>
<title>Test GC of OfflineAudioContext</title>
<script src="../../resources/gc.js"></script>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script>
<script src="../resources/audit.js"></script>
</head>
<body>
<script>
const audit = Audit.createTaskRunner();
// Number of contexts to create for testing. Fairly arbitrary, but since
// we actually start rendering the context which creates a thread, we
// don't want too many.
const numberOfContexts = 20;
audit.define('Test GC of OfflineAudioContexts', (task, should) => {
// Initial number of handlers.
let initialCount = 0;
asyncGC()
.then(() => {
initialCount = internals.audioHandlerCount();
// For information only
should(initialCount, 'Number of handlers before GC')
.beEqualTo(initialCount);
})
.then(() => {
// Create a bunch of contexts for testing. The oscillators are
// important because they hold cause the context to exist until
// the oscillators are collected.
const contexts = [];
for (let k = 0; k < numberOfContexts; ++k) {
let c = new OfflineAudioContext(1, 44100, 44100);
let s = new OscillatorNode(c);
s.start();
contexts.push(c.startRendering());
c = null;
}
// Wait for all the close methods to resolve before we check.
Promise.all(contexts).then(() => {
asyncGC()
.then(() => {
should(contexts.length, 'Number of contexts created')
.beEqualTo(numberOfContexts);
should(
internals.audioHandlerCount(),
'Number of handlers after GC')
.beEqualTo(initialCount);
})
.then(() => task.done());
})
});
});
audit.run();
</script>
</body>
</html>