blob: b99613661b2e0f7e334c42117c78d52d57eb59af [file] [log] [blame]
<!doctype html>
<html>
<head>
<title>Test AudioContext.close()</title>
<script src="../resources/js-test.js"></script>
<script src="resources/compatibility.js"></script>
<script src="resources/audio-testing.js"></script>
</head>
<body>
<script>
description("Basic functionality test of closing an AudioContext");
window.jsTestIsAsync = true;
var context;
var destination;
var offline;
var osc;
var gain;
var promise1;
var promise2;
var offlinePromise;
var wave = new Float32Array(1);
var audit = Audit.createTaskRunner();
// Task: test online context (1).
audit.defineTask('test-online-context-1', function (done) {
// Create a context and verify that the various states are correct and
// that close() exists.
shouldNotThrow("context = new AudioContext()");
shouldBeEqualToString("context.state", "running");
// Create gain and oscillator for testing later.
shouldNotThrow("osc = context.createOscillator()");
shouldNotThrow("gain = context.createGain()");
destination = context.destination;
shouldNotThrow("gain.connect(context.destination)");
// Close the context. When the promise is resolved, continue the next
// test task.
context.close().then(
function () {
testPassed("context.close() was correctly resolved");
shouldNotThrow("gain.disconnect(destination)");
},
function () {
testFailed("context.close() was erroneously rejected");
}
).then(done);
});
// Task: test online context (2).
audit.defineTask('test-online-context-2', function (done) {
// Context is closed, so verify that we cannot create any more nodes,
// nor connect any.
shouldThrow("context.createAnalyser()");
shouldThrow("context.createBiquadFilter()");
// createBuffer is an exception because it's not really tied in any way
// to an audio context. And it's useful to be able to create a buffer
// inside the oncomplete event of an offline context to use for testing
// purposes.
shouldNotThrow("context.createBuffer(1, 1, 48000)");
shouldThrow("context.createBufferSource()");
shouldThrow("context.createChannelMerger()");
shouldThrow("context.createChannelSplitter()");
shouldThrow("context.createConvolver()");
shouldThrow("context.createDelay()");
shouldThrow("context.createDynamicsCompressor()");
shouldThrow("context.createGain()");
shouldThrow("context.createOscillator()");
shouldThrow("context.createPanner()");
shouldThrow("context.createPeriodicWave(wave, wave)");
shouldThrow("context.createScriptProcessor()");
shouldThrow("context.createStereoPanner()");
shouldThrow("context.createWaveShaper()");
shouldThrow("osc.connect(gain)");
shouldNotThrow("gain.disconnect()");
// Can't resume a context that is closed (released).
context.resume().then(
function () {
testFailed("Attempt to resume a closed context erroneously succeeded");
},
function () {
testPassed("Attempt to resume a closed context was correctly rejected");
}
).then(done);
});
// Task: test online context (3).
audit.defineTask('test-online-context-3', function (done) {
// Try closing the context again. The promise should be rejected.
context.close().then(
function () {
testFailed("Closing context again erroneously resolved successfully.");
},
function () {
testPassed("Closing context again correctly rejected promise.");
// Finally, run GC. The context should be gone, but this seems difficult to verify.
gc();
shouldBeNull("context.destination");
}
).then(done);
});
// Task: test offline context (1).
audit.defineTask('test-offline-context-1', function (done) {
// For an offline context, verify that close is not defined.
shouldNotThrow("offline = new OfflineAudioContext(1, 1000, 48000)");
shouldBeEqualToString("offline.state", "suspended");
shouldBeUndefined("offline.close");
done();
});
audit.defineTask('finish-test', function (done) {
done();
finishJSTest();
});
audit.runTasks();
successfullyParsed = true;
</script>
</body>
</html>