diff --git a/content/media/webaudio/test/test_mediaDecoding.html b/content/media/webaudio/test/test_mediaDecoding.html index f8b62ed9e41..4a19213158f 100644 --- a/content/media/webaudio/test/test_mediaDecoding.html +++ b/content/media/webaudio/test/test_mediaDecoding.html @@ -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();