OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
5 <script src="../resources/audit-util.js"></script> | 5 <script src="../resources/audit-util.js"></script> |
6 <script src="../resources/audio-testing.js"></script> | 6 <script src="../resources/audio-testing.js"></script> |
7 <title>Test decodeAudioData promises</title> | 7 <title>Test decodeAudioData promises</title> |
8 </head> | 8 </head> |
9 | 9 |
10 <body> | 10 <body> |
11 <script> | 11 <script> |
12 description("Basic tests for decodeAudioData promise."); | 12 description("Basic tests for decodeAudioData promise."); |
13 window.jsTestIsAsync = true; | 13 window.jsTestIsAsync = true; |
14 | 14 |
15 // Use offline context for decoding because we want a fixed know sample rate
, independent of the | 15 // Use offline context for decoding because we want a fixed know sample rate
, independent of the |
16 // hardware because the test file is encoded at 44.1 kHz. If we don't decod
eAudioData will | 16 // hardware because the test file is encoded at 44.1 kHz. If we don't decod
eAudioData will |
17 // resample the data messing up the assumptions in this test. The length is
unimportant. | 17 // resample the data messing up the assumptions in this test. The length is
unimportant. |
18 var context = new OfflineAudioContext(1, 1, 44100); | 18 var context = new OfflineAudioContext(1, 1, 44100); |
19 | 19 |
20 // Test files for decodeAudioData | 20 // Test files for decodeAudioData |
21 var validAudioFile = "../resources/media/24bit-44khz.wav"; | 21 var validAudioFile = "../resources/media/24bit-44khz.wav"; |
22 var invalidAudioFile = "../resources/media/invalid-audio-file.txt"; | 22 var invalidAudioFile = "../resources/media/invalid-audio-file.txt"; |
23 var invalidLiveStream = '../../media/resources/test-live.webm'; | |
24 | 23 |
25 // Decoded data from validAudioFile | 24 // Decoded data from validAudioFile |
26 var referenceDecodedAudioBuffer; | 25 var referenceDecodedAudioBuffer; |
27 // Encoded audio data for testing decodeAudioData after the context has been
closed. | 26 // Encoded audio data for testing decodeAudioData after the context has been
closed. |
28 var encodedAudioData; | 27 var encodedAudioData; |
29 // Decoded data from decodeAudioData after the context has been closed. | 28 // Decoded data from decodeAudioData after the context has been closed. |
30 var decodedAudioBufferAfterClose; | 29 var decodedAudioBufferAfterClose; |
31 | 30 |
32 // Utility to load an encoded audio file from |url| and decode it. |success
| and |failure| are | 31 // Utility to load an encoded audio file from |url| and decode it. |success
| and |failure| are |
33 // functions to handle the then and else cases of the promise returned by de
codeAudioData. | 32 // functions to handle the then and else cases of the promise returned by de
codeAudioData. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 runDecode(url, | 100 runDecode(url, |
102 function (buffer) { | 101 function (buffer) { |
103 testFailed(prefix + "Incorrectly succeeded in decoding " + url); | 102 testFailed(prefix + "Incorrectly succeeded in decoding " + url); |
104 }, | 103 }, |
105 function (e) { | 104 function (e) { |
106 testPassed(prefix + "Correctly failed to decode " + url + ": " + e.toS
tring()); | 105 testPassed(prefix + "Correctly failed to decode " + url + ": " + e.toS
tring()); |
107 }, | 106 }, |
108 done); | 107 done); |
109 }); | 108 }); |
110 | 109 |
111 // Decode an invalid file (due to an unknown duration) and verify that the | |
112 // promise is rejected correctly. | |
113 audit.defineTask("decode-invalid-file-unknown-duration", function (done) { | |
114 var url = invalidLiveStream; | |
115 var prefix = "Decode invalid file with promise: "; | |
116 runDecode(url, | |
117 function (buffer) { | |
118 testFailed(prefix + "Incorrectly succeeded in decoding " + url); | |
119 }, | |
120 function (e) { | |
121 testPassed(prefix + "Correctly failed to decode " + url + ": " + e.toS
tring()); | |
122 }, | |
123 done); | |
124 }); | |
125 | |
126 // Decode a valid file and verify that the promise is fulfilled and the succ
essCallback is | 110 // Decode a valid file and verify that the promise is fulfilled and the succ
essCallback is |
127 // invoked and both have identical decode audio buffers. | 111 // invoked and both have identical decode audio buffers. |
128 audit.defineTask("promise-and-success-callback", function (done) { | 112 audit.defineTask("promise-and-success-callback", function (done) { |
129 var request = new XMLHttpRequest(); | 113 var request = new XMLHttpRequest(); |
130 request.open("GET", validAudioFile, true); | 114 request.open("GET", validAudioFile, true); |
131 request.responseType = "arraybuffer"; | 115 request.responseType = "arraybuffer"; |
132 | 116 |
133 request.onload = function () { | 117 request.onload = function () { |
134 var prefix = "Decoding valid file with promise and callback: "; | 118 var prefix = "Decoding valid file with promise and callback: "; |
135 // The buffer returned by the success callback | 119 // The buffer returned by the success callback |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 finishJSTest(); | 207 finishJSTest(); |
224 done(); | 208 done(); |
225 }); | 209 }); |
226 | 210 |
227 audit.runTasks(); | 211 audit.runTasks(); |
228 | 212 |
229 successfullyParsed = true; | 213 successfullyParsed = true; |
230 </script> | 214 </script> |
231 </body> | 215 </body> |
232 </html> | 216 </html> |
OLD | NEW |