Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Constructor: AudioBuffer</title> | 4 <title>Test Constructor: AudioBuffer</title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 <script src="new-audionodeoptions.js"></script> | |
| 9 </head> | 10 </head> |
| 10 | 11 |
| 11 <body> | 12 <body> |
| 12 <script> | 13 <script> |
| 13 var context; | 14 let context; |
| 14 | 15 |
| 15 var audit = Audit.createTaskRunner(); | 16 let audit = Audit.createTaskRunner(); |
| 16 | 17 |
| 17 audit.defineTask("initialize", function (taskDone) { | 18 audit.define('initialize', (task, should) => { |
| 18 Should("context = new OfflineAudioContext(...)", function () { | 19 context = initializeContext(should); |
| 19 context = new OfflineAudioContext(1, 1, 48000); | 20 task.done(); |
| 20 }).notThrow(); | |
| 21 | |
| 22 taskDone(); | |
| 23 }); | 21 }); |
| 24 | 22 |
| 25 audit.defineTask("invalid constructor", function (taskDone) { | 23 audit.define('invalid constructor', (task, should) => { |
| 26 var node; | 24 should(() => { |
| 27 var args; | 25 new AudioBuffer(); |
| 28 var success = true; | 26 }, 'new AudioBuffer()').throw('TypeError'); |
| 27 should(() => { | |
| 28 new AudioBuffer(1); | |
| 29 }, 'new AudioBuffer(1)').throw('TypeError'); | |
| 30 should(() => { | |
| 31 new AudioBuffer(Date, 42); | |
| 32 }, 'new AudioBuffer(Date, 42)').throw('TypeError'); | |
| 29 | 33 |
| 30 args = []; | 34 task.done(); |
| 31 success = Should("new AudioBuffer()", function () { | |
| 32 node = new AudioBuffer(); | |
| 33 }).throw("TypeError"); | |
| 34 success = Should("new AudioBuffer(1)", function () { | |
| 35 node = new AudioBuffer(1) && success; | |
| 36 }).throw("TypeError"); | |
| 37 success = Should("new AudioBuffer(Date, 42)", function () { | |
| 38 node = new AudioBuffer(Date, 42) && success; | |
| 39 }).throw("TypeError"); | |
| 40 | |
| 41 Should("Invalid constructors", success) | |
| 42 .summarize( | |
| 43 "correctly threw errors", | |
| 44 "did not throw errors in all cases"); | |
| 45 | |
| 46 taskDone(); | |
| 47 }); | 35 }); |
| 48 | 36 |
| 49 audit.defineTask("required options", function (taskDone) { | 37 audit.define('required options', (task, should) => { |
| 50 var success = true; | 38 let buffer; |
| 51 | |
| 52 var buffer; | |
| 53 | 39 |
| 54 // The length and sampleRate attributes are required; all others are | 40 // The length and sampleRate attributes are required; all others are |
| 55 // optional. | 41 // optional. |
| 56 success = Should("buffer = new AudioBuffer({})", function () { | 42 should(() => { |
| 57 var buffer = new AudioBuffer({}); | 43 new AudioBuffer({}); |
| 58 }).throw("TypeError"); | 44 }, 'buffer = new AudioBuffer({})').throw('TypeError'); |
| 59 | 45 |
| 60 success = Should("buffer = new AudioBuffer({length: 1})", function () { | 46 should(() => { |
| 61 new AudioBuffer({ | 47 new AudioBuffer({length: 1}); |
| 62 length: 1 | 48 }, 'buffer = new AudioBuffer({length: 1})').throw('TypeError'); |
| 63 }); | |
| 64 }).throw("TypeError") && success; | |
| 65 | 49 |
| 66 success = Should("buffer = new AudioBuffer({sampleRate: 48000})", | 50 should(() => { |
| 67 function () { | 51 new AudioBuffer({sampleRate: 48000}); |
| 68 new AudioBuffer({ | 52 }, 'buffer = new AudioBuffer({sampleRate: 48000})').throw('TypeError'); |
| 69 sampleRate: 48000 | |
| 70 }); | |
| 71 }).throw("TypeError") && success; | |
| 72 | 53 |
| 73 success = Should("buffer = new AudioBuffer({numberOfChannels: 1}", | 54 should(() => { |
| 74 function () { | 55 buffer = new AudioBuffer({numberOfChannels: 1}); |
| 75 buffer = new AudioBuffer({ | 56 }, 'buffer = new AudioBuffer({numberOfChannels: 1}').throw('TypeError'); |
| 76 numberOfChannels: 1 | |
| 77 }); | |
| 78 }).throw("TypeError") && success; | |
| 79 | 57 |
| 80 // Length and sampleRate are required, but others are optional. | 58 // Length and sampleRate are required, but others are optional. |
| 81 success = Should( | 59 should( |
| 82 "buffer = new AudioBuffer({length: 21, sampleRate: 48000}", | 60 () => { |
| 83 function () { | 61 buffer = |
| 84 buffer = new AudioBuffer({ | 62 new AudioBuffer({length: 21, sampleRate: context.sampleRate}); |
| 85 length: 21, | 63 }, |
| 86 sampleRate: context.sampleRate | 64 'buffer0 = new AudioBuffer({length: 21, sampleRate: ' + |
| 87 }); | 65 context.sampleRate + '}') |
| 88 }).notThrow() && success; | 66 .notThrow(); |
| 89 // Verify the buffer has the correct values. | 67 // Verify the buffer has the correct values. |
| 90 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | 68 should(buffer.numberOfChannels, 'buffer0.numberOfChannels') |
| 91 .beEqualTo(1) && success; | 69 .beEqualTo(1); |
| 92 success = Should("buffer.length", buffer.length) | 70 should(buffer.length, 'buffer0.length').beEqualTo(21); |
| 93 .beEqualTo(21) && success; | 71 should(buffer.sampleRate, 'buffer0.sampleRate') |
| 94 success = Should("buffer.sampleRate", buffer.sampleRate) | 72 .beEqualTo(context.sampleRate); |
| 95 .beEqualTo(context.sampleRate) && success; | |
| 96 | 73 |
| 97 success = Should( | 74 should( |
| 98 "buffer = new AudioBuffer({numberOfChannels: 1, length: 1, sampleRate: 48000}", | 75 () => { |
| 99 function () { | 76 buffer = new AudioBuffer( |
| 100 buffer = new AudioBuffer({ | 77 {numberOfChannels: 3, length: 1, sampleRate: 48000}); |
| 101 numberOfChannels: 1, | 78 }, |
| 102 length: 1, | 79 'buffer1 = new AudioBuffer({numberOfChannels: 3, length: 1, sampleRa te: 48000}') |
|
hongchan
2017/04/21 21:38:28
Yeah, this is a long string, so clang-format has n
Raymond Toy
2017/04/21 21:55:12
Done.
| |
| 103 sampleRate: 48000 | 80 .notThrow(); |
| 104 }); | 81 // Verify the buffer has the correct values. |
| 105 }).notThrow() && success; | 82 should(buffer.numberOfChannels, 'buffer1.numberOfChannels') |
| 83 .beEqualTo(3); | |
| 84 should(buffer.length, 'buffer1.length').beEqualTo(1); | |
| 85 should(buffer.sampleRate, 'buffer1.sampleRate').beEqualTo(48000); | |
| 106 | 86 |
| 107 Should("Missing option values handled", success) | 87 task.done(); |
| 108 .summarize("correctly", "incorrectly"); | |
| 109 | |
| 110 taskDone(); | |
| 111 }); | 88 }); |
| 112 | 89 |
| 113 audit.defineTask("invalid option values", function (taskDone) { | 90 audit.define('invalid option values', (task, should) => { |
| 114 var success = true; | 91 let options = {numberOfChannels: 0, length: 1, sampleRate: 16000}; |
| 92 should( | |
| 93 () => { | |
| 94 let buffer = new AudioBuffer(options); | |
| 95 }, | |
| 96 'new AudioBuffer(' + JSON.stringify(options) + ')') | |
| 97 .throw('NotSupportedError'); | |
| 115 | 98 |
| 116 var options = { | 99 options = {numberOfChannels: 99, length: 0, sampleRate: 16000}; |
| 117 numberOfChannels: 0, | 100 should( |
| 118 length: 1, | 101 () => { |
| 119 sampleRate: 16000 | 102 let buffer = new AudioBuffer(options); |
| 120 }; | 103 }, |
| 121 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | 104 'new AudioBuffer(' + JSON.stringify(options) + ')') |
| 122 var buffer = new AudioBuffer(options); | 105 .throw('NotSupportedError'); |
| 123 }).throw("NotSupportedError"); | |
| 124 | 106 |
| 125 options = { | 107 options = {numberOfChannels: 1, length: 0, sampleRate: 16000}; |
| 126 numberOfChannels: 99, | 108 should( |
| 127 length: 0, | 109 () => { |
| 128 sampleRate: 16000 | 110 let buffer = new AudioBuffer(options); |
| 129 }; | 111 }, |
| 130 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | 112 'new AudioBuffer(' + JSON.stringify(options) + ')') |
| 131 var buffer = new AudioBuffer(options); | 113 .throw('NotSupportedError'); |
| 132 }).throw("NotSupportedError") && success; | |
| 133 | 114 |
| 134 options = { | 115 options = {numberOfChannels: 1, length: 1, sampleRate: 100}; |
| 135 numberOfChannels: 1, | 116 should( |
| 136 length: 0, | 117 () => { |
| 137 sampleRate: 16000 | 118 let buffer = new AudioBuffer(options); |
| 138 }; | 119 }, |
| 139 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | 120 'new AudioBuffer(' + JSON.stringify(options) + ')') |
| 140 var buffer = new AudioBuffer(options); | 121 .throw('NotSupportedError'); |
| 141 }).throw("NotSupportedError") && success; | |
| 142 | 122 |
| 143 options = { | 123 task.done(); |
| 144 numberOfChannels: 1, | |
| 145 length: 1, | |
| 146 sampleRate: 100 | |
| 147 }; | |
| 148 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | |
| 149 var buffer = new AudioBuffer(options); | |
| 150 }).throw("NotSupportedError") && success; | |
| 151 | |
| 152 Should("Invalid option values handled", success) | |
| 153 .summarize("correctly", "incorrectly"); | |
| 154 | |
| 155 taskDone(); | |
| 156 }); | 124 }); |
| 157 | 125 |
| 158 audit.defineTask("default constructor", function (taskDone) { | 126 audit.define('default constructor', (task, should) => { |
| 159 var buffer; | 127 let buffer; |
| 160 var success = true; | |
| 161 | 128 |
| 162 var options = { | 129 let options = {numberOfChannels: 5, length: 17, sampleRate: 16000}; |
| 163 numberOfChannels: 5, | 130 should( |
| 164 length: 17, | 131 () => { |
| 165 sampleRate: 16000 | 132 buffer = new AudioBuffer(options); |
| 166 }; | 133 }, |
| 167 success = Should( | 134 'buffer = new AudioBuffer(' + JSON.stringify(options) + ')') |
| 168 "buffer = new AudioBuffer(" + JSON.stringify(options) + ")", | 135 .notThrow(); |
| 169 function () { | |
| 170 buffer = new AudioBuffer(options); | |
| 171 }).notThrow(); | |
| 172 | 136 |
| 173 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | 137 should(buffer.numberOfChannels, 'buffer.numberOfChannels') |
| 174 .beEqualTo(options.numberOfChannels) && success; | 138 .beEqualTo(options.numberOfChannels); |
| 175 success = Should("buffer.length", buffer.length) | 139 should(buffer.length, 'buffer.length').beEqualTo(options.length); |
| 176 .beEqualTo(options.length) && success; | 140 should(buffer.sampleRate, 'buffer.sampleRate').beEqualTo(16000); |
| 177 success = Should("buffer.sampleRate", buffer.sampleRate) | |
| 178 .beEqualTo(16000) && success; | |
| 179 | 141 |
| 180 Should("Default constructor values set", success) | 142 task.done(); |
| 181 .summarize("correctly", "incorrectly"); | |
| 182 | |
| 183 taskDone(); | |
| 184 }); | 143 }); |
| 185 | 144 |
| 186 audit.defineTask("valid constructor", function (taskDone) { | 145 audit.define('valid constructor', (task, should) => { |
| 187 var buffer; | 146 let buffer; |
| 188 var success = true; | |
| 189 | 147 |
| 190 var options = { | 148 let options = {numberOfChannels: 3, length: 42, sampleRate: 54321}; |
| 191 numberOfChannels: 3, | |
| 192 length: 42, | |
| 193 sampleRate: 54321 | |
| 194 }; | |
| 195 | 149 |
| 196 var message = "new AudioBuffer(" + JSON.stringify(options) + ")"; | 150 let message = 'new AudioBuffer(' + JSON.stringify(options) + ')'; |
| 197 success = Should(message, function () { | 151 should(() => { |
| 198 buffer = new AudioBuffer(options); | 152 buffer = new AudioBuffer(options); |
| 199 }).notThrow(); | 153 }, message).notThrow(); |
| 200 | 154 |
| 201 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | 155 should(buffer.numberOfChannels, 'buffer.numberOfChannels') |
| 202 .beEqualTo(options.numberOfChannels) && success; | 156 .beEqualTo(options.numberOfChannels); |
| 203 | 157 |
| 204 success = Should("buffer.length", buffer.length) | 158 should(buffer.length, 'buffer.length').beEqualTo(options.length); |
| 205 .beEqualTo(options.length) && success; | |
| 206 | 159 |
| 207 success = Should("buffer.sampleRate", buffer.sampleRate) | 160 should(buffer.sampleRate, 'buffer.sampleRate') |
| 208 .beEqualTo(options.sampleRate) && success; | 161 .beEqualTo(options.sampleRate); |
| 209 | 162 |
| 210 // Verify that we actually got the right number of channels | 163 // Verify that we actually got the right number of channels |
| 211 for (var k = 0; k < options.numberOfChannels; ++k) { | 164 for (let k = 0; k < options.numberOfChannels; ++k) { |
| 212 var data; | 165 let data; |
| 213 var message = "buffer.getChannelData(" + k + ")"; | 166 let message = 'buffer.getChannelData(' + k + ')'; |
| 214 success = Should(message, function () { | 167 should(() => { |
| 215 data = buffer.getChannelData(k); | 168 data = buffer.getChannelData(k); |
| 216 }).notThrow() && success; | 169 }, message).notThrow(); |
| 217 | 170 |
| 218 success = Should(message + " length", data.length) | 171 should(data.length, message + ' length').beEqualTo(options.length); |
| 219 .beEqualTo(options.length) && success; | |
| 220 } | 172 } |
| 221 | 173 |
| 222 Should("buffer.getChannelData(" + options.numberOfChannels + ")", | 174 should( |
| 223 function () { | 175 () => { |
| 224 buffer.getChannelData(options.numberOfChannels); | 176 buffer.getChannelData(options.numberOfChannels); |
| 225 }).throw("IndexSizeError") && success; | 177 }, |
| 178 'buffer.getChannelData(' + options.numberOfChannels + ')') | |
| 179 .throw('IndexSizeError'); | |
| 226 | 180 |
| 227 Should("AudioBuffer constructed", success) | 181 task.done(); |
| 228 .summarize("correctly", "incorrectly"); | |
| 229 | |
| 230 taskDone(); | |
| 231 }); | 182 }); |
| 232 | 183 |
| 233 audit.defineTask("multiple contexts", function (taskDone) { | 184 audit.define('multiple contexts', (task, should) => { |
| 234 // Test that an AudioBuffer can be used for different contexts. | 185 // Test that an AudioBuffer can be used for different contexts. |
| 235 var buffer = new AudioBuffer({ | 186 let buffer = |
| 236 length: 128, | 187 new AudioBuffer({length: 128, sampleRate: context.sampleRate}); |
| 237 sampleRate: context.sampleRate | |
| 238 }); | |
| 239 | 188 |
| 240 var data = buffer.getChannelData(0); | 189 let data = buffer.getChannelData(0); |
| 241 for (var k = 0; k < data.length; ++k) | 190 for (let k = 0; k < data.length; ++k) |
| 242 data[k] = 1 + k; | 191 data[k] = 1 + k; |
| 243 | 192 |
| 244 var c1 = new OfflineAudioContext(1, 128, context.sampleRate); | 193 let c1 = new OfflineAudioContext(1, 128, context.sampleRate); |
| 245 var c2 = new OfflineAudioContext(1, 128, context.sampleRate); | 194 let c2 = new OfflineAudioContext(1, 128, context.sampleRate); |
| 246 | 195 |
| 247 | 196 |
|
hongchan
2017/04/21 21:38:28
Two empty lines.
Raymond Toy
2017/04/21 21:55:12
Done.
| |
| 248 var s1 = new AudioBufferSourceNode(c1, { | 197 let s1 = new AudioBufferSourceNode(c1, {buffer: buffer}); |
| 249 buffer: buffer | 198 let s2 = new AudioBufferSourceNode(c2, {buffer: buffer}); |
| 250 }); | |
| 251 var s2 = new AudioBufferSourceNode(c2, { | |
| 252 buffer: buffer | |
| 253 }); | |
| 254 | 199 |
| 255 s1.connect(c1.destination); | 200 s1.connect(c1.destination); |
| 256 s2.connect(c2.destination); | 201 s2.connect(c2.destination); |
| 257 | 202 |
| 258 s1.start(); | 203 s1.start(); |
| 259 s2.start(); | 204 s2.start(); |
| 260 | 205 |
| 261 var c1Success = false; | 206 let c1Success = false; |
| 262 var c2Success = false; | 207 let c2Success = false; |
|
hongchan
2017/04/21 21:38:29
Then we don't need cXSuccess any more.
Raymond Toy
2017/04/21 21:55:12
Done.
| |
| 263 | 208 |
| 264 Promise.all([ | 209 Promise |
| 265 c1.startRendering().then(function (resultBuffer) { | 210 .all([ |
| 266 c1Success = Should("c1 result", resultBuffer.getChannelData(0)) | 211 c1.startRendering().then(function(resultBuffer) { |
| 267 .beEqualToArray(data); | 212 return should(resultBuffer.getChannelData(0), 'c1 result') |
| 268 }), | 213 .beEqualToArray(data); |
| 269 c2.startRendering().then(function (resultBuffer) { | 214 }), |
| 270 c2Success = Should("c2 result", resultBuffer.getChannelData(0)) | 215 c2.startRendering().then(function(resultBuffer) { |
| 271 .beEqualToArray(data); | 216 return should(resultBuffer.getChannelData(0), 'c2 result') |
| 272 }), | 217 .beEqualToArray(data); |
| 273 ]) | 218 }), |
| 274 .then(function () { | 219 ]) |
| 275 Should("AudioBuffer shared between two different contexts", | 220 .then(returnValues => { |
| 276 c1Success && c2Success) | 221 should( |
| 277 .summarize("correctly", "incorrectly"); | 222 returnValues[0] && returnValues[1], |
| 278 taskDone(); | 223 'AudioBuffer shared between two different contexts') |
| 279 }); | 224 .message('correctly', 'incorrectly'); |
| 225 task.done(); | |
| 226 }); | |
| 280 }); | 227 }); |
| 281 | 228 |
| 282 audit.runTasks(); | 229 audit.run(); |
| 283 </script> | 230 </script> |
| 284 </body> | 231 </body> |
| 285 </html> | 232 </html> |
| OLD | NEW |