Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit.js"></script> | 6 <script src="../resources/audit.js"></script> |
| 7 <title>Test decodeAudioData promises</title> | 7 <title>Test decodeAudioData promises</title> |
| 8 </head> | 8 </head> |
| 9 <body> | 9 <body> |
| 10 <script> | 10 <script> |
| 11 // Use offline context for decoding because we want a fixed known sample | 11 // The functionality of decodeAudioData() is orthogonal to the type and the |
| 12 // rate, independent of the hardware because the test file is encoded at | 12 // state of AudioContext. So we use the online context in this test. |
|
Raymond Toy
2017/03/24 17:07:46
Add comment that any resampling of the test file i
hongchan
2017/03/24 19:00:36
Done.
| |
| 13 // 44.1 kHz. If we don't, decodeAudioData() will resample the data messing | 13 let context = new AudioContext(); |
| 14 // up the assumptions in this test. The length is unimportant. | |
| 15 let context = new OfflineAudioContext(1, 1, 44100); | |
| 16 | 14 |
| 17 // Test file URLs. | 15 // Test file URLs. |
| 18 let validAudioFileUrl = '../resources/media/24bit-44khz.wav'; | 16 let validAudioFileUrl = '../resources/media/24bit-44khz.wav'; |
| 19 let invalidAudioFileUrl = '../resources/media/invalid-audio-file.txt'; | 17 let invalidAudioFileUrl = '../resources/media/invalid-audio-file.txt'; |
| 20 | 18 |
| 21 // Global storage for array buffers from XHR. | 19 // Global storage for array buffers from XHR. |
| 22 let validArrayBuffer; | 20 let validArrayBuffer; |
| 23 let invalidArrayBuffer; | 21 let invalidArrayBuffer; |
| 24 | 22 |
| 25 // Decoded data from validAudioFile. | 23 // Decoded data from validAudioFile. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // Decode an invalid file and verify that the promise is rejected and the | 105 // Decode an invalid file and verify that the promise is rejected and the |
| 108 // errorCallback is invoked. | 106 // errorCallback is invoked. |
| 109 audit.define("promise-and-error-callback", (task, should) => { | 107 audit.define("promise-and-error-callback", (task, should) => { |
| 110 let successOrErrorCallback = (callbackArg) => { | 108 let successOrErrorCallback = (callbackArg) => { |
| 111 should(callbackArg instanceof Error, | 109 should(callbackArg instanceof Error, |
| 112 'Decoding invalid file with promise and callback:') | 110 'Decoding invalid file with promise and callback:') |
| 113 .message('errorCallback invoked correctly with ' + callbackArg, | 111 .message('errorCallback invoked correctly with ' + callbackArg, |
| 114 'successCallback should not have invoked'); | 112 'successCallback should not have invoked'); |
| 115 }; | 113 }; |
| 116 | 114 |
| 117 let decodeAudioDataPromise = context.decodeAudioData( | 115 let decodeAudioDataPromise = |
| 118 invalidArrayBuffer.slice(), successOrErrorCallback, successOrErrorCall back); | 116 context.decodeAudioData(invalidArrayBuffer.slice(), |
| 117 successOrErrorCallback, | |
| 118 successOrErrorCallback); | |
|
hongchan
2017/03/24 16:52:18
Let me know if this change bothers you too much. I
| |
| 119 | 119 |
| 120 should(decodeAudioDataPromise, 'decodeAudioData promise') | 120 should(decodeAudioDataPromise, 'decodeAudioData promise') |
| 121 .beRejected('EncodingError') | 121 .beRejected('EncodingError') |
| 122 .then(() => task.done()); | 122 .then(() => task.done()); |
| 123 }); | 123 }); |
| 124 | 124 |
| 125 // decodeAudioData() should be functional even after the associated context | 125 // decodeAudioData() should be functional even after the associated context |
| 126 // is closed. | 126 // is closed. |
| 127 // TODO(crbug.com/692650) | 127 audit.define('decoding-on-closed-context', (task, should) => { |
| 128 audit.define('close-context-with-pending-decode', (task, should) => { | |
| 129 // Use one handler for resolve and reject. |promiseArg| is a parameter for | 128 // Use one handler for resolve and reject. |promiseArg| is a parameter for |
| 130 // handlers; it is a decoded audio buffer for success case and an error | 129 // handlers; it is a decoded audio buffer for success case and an error |
| 131 // object for failure case. | 130 // object for failure case. |
| 132 let resolveOrReject = (promiseArg) => { | 131 let resolveOrReject = (promiseArg) => { |
| 133 let didDecode = promiseArg instanceof AudioBuffer; | 132 let didDecode = promiseArg instanceof AudioBuffer; |
| 134 | 133 |
| 135 if (didDecode) { | 134 if (didDecode) { |
| 136 // Compare two decoded AudioBuffers. | 135 // Compare two decoded AudioBuffers. |
| 137 let actual = promiseArg; | 136 let actual = promiseArg; |
| 138 let expected = referenceDecodedAudioBuffer; | 137 let expected = referenceDecodedAudioBuffer; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 165 onlineContext.close() | 164 onlineContext.close() |
| 166 .then(() => { return context.decodeAudioData(validArrayBuffer); }) | 165 .then(() => { return context.decodeAudioData(validArrayBuffer); }) |
| 167 .then(resolveOrReject, resolveOrReject) | 166 .then(resolveOrReject, resolveOrReject) |
| 168 .then(() => { task.done(); }); | 167 .then(() => { task.done(); }); |
| 169 }); | 168 }); |
| 170 | 169 |
| 171 audit.run(); | 170 audit.run(); |
| 172 </script> | 171 </script> |
| 173 </body> | 172 </body> |
| 174 </html> | 173 </html> |
| OLD | NEW |