b=938450 use an OfflineAudioContext to test decodeAudioData at different sample rates f=padenot

--HG--
extra : transplant_source : %CF.%22r%F8%BB%D7%21%17%E9%96%19y1%5B%D0%E6%F0%D1%18
This commit is contained in:
Karl Tomlinson 2013-12-03 12:23:49 +13:00
Родитель b20fe1ce50
Коммит 75eb0073f7
1 изменённых файлов: 25 добавлений и 28 удалений

Просмотреть файл

@ -107,8 +107,6 @@ function createWaveFileData(audioBuffer) {
SimpleTest.waitForExplicitFinish();
var cx = new AudioContext();
// fuzzTolerance and fuzzToleranceMobile are used to determine fuzziness
// thresholds. They're needed to make sure that we can deal with neglibible
// differences in the binary buffer caused as a result of resampling the
@ -191,9 +189,9 @@ var files = [
// // A wave file
// //{ url: "24bit-44khz.wav", valid: true, expectedUrl: "24bit-44khz-expected.wav" },
// A non-audio file
{ url: "invalid.txt", valid: false },
{ url: "invalid.txt", valid: false, sampleRate: 44100 },
// A webm file with no audio
{ url: "noaudio.webm", valid: false },
{ url: "noaudio.webm", valid: false, sampleRate: 48000 },
// A video ogg file with audio
{
url: "audio.ogv",
@ -237,9 +235,9 @@ function checkAudioBuffer(buffer, test) {
if (Math.abs(buffer.duration - test.duration) >= 1e-3) {
ok(false, "got: " + buffer.duration + ", expected: " + test.duration);
}
is(buffer.sampleRate, cx.sampleRate, "Correct sample rate");
is(buffer.sampleRate, test.sampleRate, "Correct sample rate");
// Take into account the resampling when checking the size
var expectedLength = test.frames * cx.sampleRate / test.sampleRate;
var expectedLength = test.frames * buffer.sampleRate / test.sampleRate;
ok(Math.abs(buffer.length - expectedLength) < 1.0, "Correct length", "got " + buffer.length + ", expected about " + expectedLength);
var wave = createWaveFileData(buffer);
@ -248,6 +246,7 @@ function checkAudioBuffer(buffer, test) {
function runTest(test, response, callback) {
var expectCallback = false;
var cx = new OfflineAudioContext(1, 1, test.sampleRate);
cx.decodeAudioData(response, function onSuccess(asyncResult) {
ok(expectCallback, "Success callback should fire asynchronously");
ok(test.valid, "Did expect success for test " + test.url);
@ -293,29 +292,27 @@ function loadNextTest() {
function callbackShouldNeverRun() {
ok(false, "callback should not fire");
}
expectTypeError(function() {
cx.decodeAudioData(null, callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData(undefined, callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData(123, callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData("buffer", callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData(new Uint8Array(100), callbackShouldNeverRun, callbackShouldNeverRun);
});
(function() {
var cx = new AudioContext();
expectTypeError(function() {
cx.decodeAudioData(null, callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData(undefined, callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData(123, callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData("buffer", callbackShouldNeverRun, callbackShouldNeverRun);
});
expectTypeError(function() {
cx.decodeAudioData(new Uint8Array(100), callbackShouldNeverRun, callbackShouldNeverRun);
});
})();
if (cx.sampleRate >= 44100) {
// Now, let's get real!
loadNextTest();
} else {
todo(false, "Decoded data tests disabled; context sampleRate " + cx.sampleRate + " not supported");
SimpleTest.finish();
}
// Now, let's get real!
loadNextTest();
</script>
</pre>