Commit 0cc26bbb authored by rtoy's avatar rtoy Committed by Commit bot

Throw exceptions for invalid number of channels for ConvolverNode

The ConvolverNode only supports 1, 2 or 4 channels and must throw an
exception for any other number of channels.

BUG=563379
TEST=convolver-channels.html

Review URL: https://codereview.chromium.org/1497803002

Cr-Commit-Position: refs/heads/master@{#363024}
parent 0877e82a
Test Supported Number of Channels for ConvolverNode
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS ConvolverNode with buffer of 1 channels did not throw an exception.
PASS ConvolverNode with buffer of 2 channels did not throw an exception.
PASS ConvolverNode with buffer of 3 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 3.
PASS ConvolverNode with buffer of 4 channels did not throw an exception.
PASS ConvolverNode with buffer of 5 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 5.
PASS ConvolverNode with buffer of 6 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 6.
PASS ConvolverNode with buffer of 7 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 7.
PASS ConvolverNode with buffer of 8 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 8.
PASS ConvolverNode with buffer of 9 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 9.
PASS ConvolverNode with buffer of 10 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 10.
PASS ConvolverNode with buffer of 11 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 11.
PASS ConvolverNode with buffer of 12 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 12.
PASS ConvolverNode with buffer of 13 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 13.
PASS ConvolverNode with buffer of 14 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 14.
PASS ConvolverNode with buffer of 15 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 15.
PASS ConvolverNode with buffer of 16 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 16.
PASS ConvolverNode with buffer of 17 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 17.
PASS ConvolverNode with buffer of 18 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 18.
PASS ConvolverNode with buffer of 19 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 19.
PASS ConvolverNode with buffer of 20 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 20.
PASS ConvolverNode with buffer of 21 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 21.
PASS ConvolverNode with buffer of 22 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 22.
PASS ConvolverNode with buffer of 23 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 23.
PASS ConvolverNode with buffer of 24 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 24.
PASS ConvolverNode with buffer of 25 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 25.
PASS ConvolverNode with buffer of 26 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 26.
PASS ConvolverNode with buffer of 27 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 27.
PASS ConvolverNode with buffer of 28 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 28.
PASS ConvolverNode with buffer of 29 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 29.
PASS ConvolverNode with buffer of 30 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 30.
PASS ConvolverNode with buffer of 31 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 31.
PASS ConvolverNode with buffer of 32 channels threw NotSupportedError: Failed to set the 'buffer' property on 'ConvolverNode': The buffer must have 1, 2, or 4 channels, not 32.
PASS Multiple channels for the convolver correctly handled.
PASS successfullyParsed is true
TEST COMPLETE
<!doctype html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/compatibility.js"></script>
<script src="resources/audio-testing.js"></script>
<title>Test Supported Number of Channels for ConvolverNode</title>
</head>
<body>
<script>
description("Test Supported Number of Channels for ConvolverNode");
window.jsTestIsAsync = true;
var audit = Audit.createTaskRunner();
audit.defineTask("channel-count-test", function (done) {
// Just need a context to create nodes on, so any allowed length and rate is ok.
var context = new OfflineAudioContext(1, 1, 48000);
var success = true;
for (var count = 1; count <= 32; ++count) {
var convolver = context.createConvolver();
var buffer = context.createBuffer(count, 1, context.sampleRate);
var message = "ConvolverNode with buffer of " + count + " channels";
if (count == 1 || count == 2 || count == 4) {
// These are the only valid channel counts for the buffer.
success = Should(message, function () {
convolver.buffer = buffer;
}).notThrow() && success;
} else {
success = Should(message, function () {
convolver.buffer = buffer;
}).throw("NotSupportedError") && success;
}
}
if (success)
testPassed("Multiple channels for the convolver correctly handled.");
else
testFailed("Multiple channels for the convolver were not correctly handled.");
done();
});
audit.defineTask("finish", function (done) {
finishJSTest();
done();
});
audit.runTasks();
</script>
</body>
</html>
......@@ -111,11 +111,16 @@ void ConvolverHandler::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionS
unsigned numberOfChannels = buffer->numberOfChannels();
size_t bufferLength = buffer->length();
// The current implementation supports up to four channel impulse responses, which are interpreted as true-stereo (see Reverb class).
bool isBufferGood = numberOfChannels > 0 && numberOfChannels <= 4 && bufferLength;
ASSERT(isBufferGood);
if (!isBufferGood)
// The current implementation supports only 1-, 2-, or 4-channel impulse responses, with the
// 4-channel response being interpreted as true-stereo (see Reverb class).
bool isChannelCountGood = numberOfChannels == 1 || numberOfChannels == 2 || numberOfChannels == 4;
if (!isChannelCountGood) {
exceptionState.throwDOMException(
NotSupportedError,
"The buffer must have 1, 2, or 4 channels, not " + String::number(numberOfChannels));
return;
}
// Wrap the AudioBuffer by an AudioBus. It's an efficient pointer set and not a memcpy().
// This memory is simply used in the Reverb constructor and no reference to it is kept for later use in that class.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment