| 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> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // Decoded data from validAudioFile. | 25 // Decoded data from validAudioFile. |
| 26 let referenceDecodedAudioBuffer; | 26 let referenceDecodedAudioBuffer; |
| 27 | 27 |
| 28 let audit = Audit.createTaskRunner(); | 28 let audit = Audit.createTaskRunner(); |
| 29 | 29 |
| 30 // Preload ArrayBuffer and the reference AudioBuffer from URLs. | 30 // Preload ArrayBuffer and the reference AudioBuffer from URLs. |
| 31 audit.define('preload-arraybuffer', (task, should) => { | 31 audit.define('preload-arraybuffer', (task, should) => { |
| 32 Promise | 32 Promise |
| 33 .all([ | 33 .all([ |
| 34 Audit.loadFileFromUrl(validAudioFileUrl), | 34 should(Audit.loadFileFromUrl(validAudioFileUrl), |
| 35 Audit.loadFileFromUrl(invalidAudioFileUrl) | 35 "Loading valid audio file") |
| 36 .beResolved(), |
| 37 should(Audit.loadFileFromUrl(invalidAudioFileUrl), |
| 38 "loading invalid audio file") |
| 39 .beResolved() |
| 36 ]) | 40 ]) |
| 37 .then((arrayBuffers) => { | 41 .then((arrayBuffers) => { |
| 38 validArrayBuffer = arrayBuffers[0]; | 42 validArrayBuffer = arrayBuffers[0]; |
| 39 invalidArrayBuffer = arrayBuffers[1]; | 43 invalidArrayBuffer = arrayBuffers[1]; |
| 40 context.decodeAudioData(validArrayBuffer).then((audioBuffer) => { | 44 }) |
| 41 referenceDecodedAudioBuffer = audioBuffer; | 45 .then(() => task.done()); |
| 42 task.done(); | |
| 43 }) | |
| 44 }); | |
| 45 }); | 46 }); |
| 46 | 47 |
| 47 // Decode a valid encoded file and verify that the promise succeeds | 48 // Decode a valid encoded file and verify that the promise succeeds |
| 48 // correctly. | 49 // correctly. |
| 49 audit.define('decode-valid-file', (task, should) => { | 50 audit.define('decode-valid-file', (task, should) => { |
| 50 // Note that the order of completion for each promise is undefined and | 51 // Note that the order of completion for each promise is undefined and |
| 51 // we do not care about it in this test. | 52 // we do not care about it in this test. |
| 52 Promise | 53 Promise |
| 53 .all([ | 54 .all([ |
| 54 should(context.decodeAudioData(validArrayBuffer), | 55 // Do not use the original arrayBuffers for decoding; decode a copy |
| 56 // because decodeAudioData will detach the buffers. |
| 57 should(context.decodeAudioData(validArrayBuffer.slice(0)), |
| 55 'Decoding a valid audio file') | 58 'Decoding a valid audio file') |
| 56 .beResolved(), | 59 .beResolved(), |
| 57 should(context.decodeAudioData(invalidArrayBuffer), | 60 should(context.decodeAudioData(invalidArrayBuffer.slice(0)), |
| 58 'Decoding an invalid audio file') | 61 'Decoding an invalid audio file') |
| 59 .beRejected('EncodingError'), | 62 .beRejectedWith('EncodingError'), |
| 60 should(context.decodeAudioData(null), 'Decoding null AudioBuffer') | 63 should(context.decodeAudioData(null), 'Decoding null AudioBuffer') |
| 61 .beRejected() | 64 .beRejected() |
| 62 ]) | 65 ]) |
| 63 .then(() => task.done()); | 66 .then(() => task.done()); |
| 64 }); | 67 }); |
| 65 | 68 |
| 66 // Decode a valid file and verify that the promise is fulfilled and the | 69 // Decode a valid file and verify that the promise is fulfilled and the |
| 67 // successCallback is invoked and both have identical decoded audio buffers. | 70 // successCallback is invoked and both have identical decoded audio buffers. |
| 68 audit.define("promise-and-success-callback", (task, should) => { | 71 audit.define("promise-and-success-callback", (task, should) => { |
| 69 let bufferByCallback; | 72 let bufferByCallback; |
| 70 let bufferByPromise; | 73 let bufferByPromise; |
| 71 | 74 |
| 72 // Use one callback for success and error. |callbackArg| is a parameter | 75 // Use one callback for success and error. |callbackArg| is a parameter |
| 73 // for callback functions; it is a decoded audio buffer for success case | 76 // for callback functions; it is a decoded audio buffer for success case |
| 74 // and an error object for failure case. | 77 // and an error object for failure case. |
| 75 let successOrErrorCallback = (callbackArg) => { | 78 let successOrErrorCallback = (callbackArg) => { |
| 76 should(callbackArg instanceof AudioBuffer, | 79 should(callbackArg instanceof AudioBuffer, |
| 77 'Decoding valid file by callback function') | 80 'Decoding valid file by callback function') |
| 78 .message('successCallback invoked correctly', | 81 .message('successCallback invoked correctly', |
| 79 'errorCallback incorrectly invoked with ' + callbackArg); | 82 'errorCallback incorrectly invoked with ' + callbackArg); |
| 80 bufferByCallback = callbackArg; | 83 bufferByCallback = callbackArg; |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 // Step 1: Decode a file with callback functions. | 86 // Step 1: Decode a file with callback functions. |
| 84 let step1 = context.decodeAudioData(validArrayBuffer, | 87 let step1 = context.decodeAudioData(validArrayBuffer.slice(), |
| 85 successOrErrorCallback, | 88 successOrErrorCallback, |
| 86 successOrErrorCallback); | 89 successOrErrorCallback); |
| 87 | 90 |
| 88 // Step 2: Then decode a file with promise pattern. | 91 // Step 2: Then decode a file with promise pattern. |
| 89 let step2 = should(step1, 'Decoding a file via promise') | 92 let step2 = should(step1, 'Decoding a file via promise') |
| 90 .beResolved() | 93 .beResolved() |
| 91 .then((audioBuffer) => { | 94 .then((audioBuffer) => { |
| 92 bufferByPromise = audioBuffer; | 95 bufferByPromise = audioBuffer; |
| 93 }); | 96 }); |
| 94 | 97 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 105 // errorCallback is invoked. | 108 // errorCallback is invoked. |
| 106 audit.define("promise-and-error-callback", (task, should) => { | 109 audit.define("promise-and-error-callback", (task, should) => { |
| 107 let successOrErrorCallback = (callbackArg) => { | 110 let successOrErrorCallback = (callbackArg) => { |
| 108 should(callbackArg instanceof Error, | 111 should(callbackArg instanceof Error, |
| 109 'Decoding invalid file with promise and callback:') | 112 'Decoding invalid file with promise and callback:') |
| 110 .message('errorCallback invoked correctly with ' + callbackArg, | 113 .message('errorCallback invoked correctly with ' + callbackArg, |
| 111 'successCallback should not have invoked'); | 114 'successCallback should not have invoked'); |
| 112 }; | 115 }; |
| 113 | 116 |
| 114 let decodeAudioDataPromise = context.decodeAudioData( | 117 let decodeAudioDataPromise = context.decodeAudioData( |
| 115 invalidArrayBuffer, successOrErrorCallback, successOrErrorCallback); | 118 invalidArrayBuffer.slice(), successOrErrorCallback, successOrErrorCall
back); |
| 116 | 119 |
| 117 should(decodeAudioDataPromise, 'decodeAudioData promise') | 120 should(decodeAudioDataPromise, 'decodeAudioData promise') |
| 118 .beRejected('EncodingError') | 121 .beRejected('EncodingError') |
| 119 .then(() => task.done()); | 122 .then(() => task.done()); |
| 120 }); | 123 }); |
| 121 | 124 |
| 122 // decodeAudioData() should be functional even after the associated context | 125 // decodeAudioData() should be functional even after the associated context |
| 123 // is closed. | 126 // is closed. |
| 124 // TODO(crbug.com/692650) | 127 // TODO(crbug.com/692650) |
| 125 audit.define('close-context-with-pending-decode', (task, should) => { | 128 audit.define('close-context-with-pending-decode', (task, should) => { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 onlineContext.close() | 165 onlineContext.close() |
| 163 .then(() => { return context.decodeAudioData(validArrayBuffer); }) | 166 .then(() => { return context.decodeAudioData(validArrayBuffer); }) |
| 164 .then(resolveOrReject, resolveOrReject) | 167 .then(resolveOrReject, resolveOrReject) |
| 165 .then(() => { task.done(); }); | 168 .then(() => { task.done(); }); |
| 166 }); | 169 }); |
| 167 | 170 |
| 168 audit.run(); | 171 audit.run(); |
| 169 </script> | 172 </script> |
| 170 </body> | 173 </body> |
| 171 </html> | 174 </html> |
| OLD | NEW |