blob: 2edcef8f5244f312ce8ec8f554c436fc445daf40 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script type="text/javascript" src="resources/audio-testing.js"></script>
</head>
<body>
<script>
description("Basic tests for decodeAudioData function.");
window.jsTestIsAsync = true;
var context = new webkitAudioContext();
// decodeAudioData should raise exception when arraybuffer parameter is null.
shouldThrow("context.decodeAudioData(null, function(){}, function(){});", "'TypeError: Argument 1 (\\'audioData\\') to webkitAudioContext.decodeAudioData must be an instance of ArrayBuffer'");
var decodeCaseArray = [{url: "resources/media/24bit-44khz.wav", result: true},
{url: "resources/media/invalid-audio-file.txt", result: false}];
function runDecodeTest(index) {
if (index >= decodeCaseArray.length) {
finishJSTest();
return;
}
var request = new XMLHttpRequest();
request.open("GET", decodeCaseArray[index].url, true);
request.responseType = "arraybuffer";
request.onload = function() {
context.decodeAudioData(request.response, successCallback, errorCallback);
function successCallback() {
if (decodeCaseArray[index].result)
testPassed("The " + decodeCaseArray[index].url + " test: successCallback has been called correctly.");
else
testFailed("The " + decodeCaseArray[index].url + " test: successCallback was not called.");
runDecodeTest(++index);
}
function errorCallback() {
if (decodeCaseArray[index].result)
testFailed("The " + decodeCaseArray[index].url + " test: errorCallback was called incorrectly.");
else
testPassed("The " + decodeCaseArray[index].url + " test: errorCallback has been called correctly.");
runDecodeTest(++index);
}
}
request.send();
}
runDecodeTest(0);
</script>
</body>
</html>