4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"resources/compatibility.js"></script>
6 <script type=
"text/javascript" src=
"resources/audio-testing.js"></script>
10 description("Basic tests for decodeAudioData function.");
12 if (window
.testRunner
) {
13 testRunner
.dumpAsText();
14 testRunner
.waitUntilDone();
17 window
.jsTestIsAsync
= true;
19 var context
= new AudioContext();
22 context
.decodeAudioData(null, function(){}, function(){});
23 testFailed("decodeAudioData should raise exception when arraybuffer parameter is null.");
25 testPassed("decodeAudioData raises exception correctly when arraybuffer parameter is null.");
28 var decodeCaseArray
= [{url
: "resources/media/24bit-44khz.wav", result
: true},
29 {url
: "resources/media/invalid-audio-file.txt", result
: false}];
31 function runDecodeTest(index
) {
32 if (index
>= decodeCaseArray
.length
) {
37 var request
= new XMLHttpRequest();
38 request
.open("GET", decodeCaseArray
[index
].url
, true);
39 request
.responseType
= "arraybuffer";
41 request
.onload = function() {
42 context
.decodeAudioData(request
.response
, successCallback
, errorCallback
);
44 function successCallback() {
45 if (decodeCaseArray
[index
].result
)
46 testPassed("The " + decodeCaseArray
[index
].url
+ " test: successCallback has been called correctly.");
48 testFailed("The " + decodeCaseArray
[index
].url
+ " test: successCallback was not called.");
50 runDecodeTest(++index
);
53 function errorCallback() {
54 if (decodeCaseArray
[index
].result
)
55 testFailed("The " + decodeCaseArray
[index
].url
+ " test: errorCallback was called incorrectly.");
57 testPassed("The " + decodeCaseArray
[index
].url
+ " test: errorCallback has been called correctly.");
59 runDecodeTest(++index
);