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 var context; |
|
hongchan
2017/04/21 20:52:39
var -> let
Raymond Toy
2017/04/21 21:02:05
Done.
| |
| 14 | 15 |
| 15 var audit = Audit.createTaskRunner(); | 16 var 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; | |
| 51 | |
| 52 var buffer; | 38 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').beEqualTo(1) ; |
| 91 .beEqualTo(1) && success; | 69 should(buffer.length, 'buffer0.length').beEqualTo(21); |
| 92 success = Should("buffer.length", buffer.length) | 70 should(buffer.sampleRate, 'buffer0.sampleRate') |
| 93 .beEqualTo(21) && success; | 71 .beEqualTo(context.sampleRate); |
| 94 success = Should("buffer.sampleRate", buffer.sampleRate) | |
| 95 .beEqualTo(context.sampleRate) && success; | |
| 96 | 72 |
| 97 success = Should( | 73 should( |
| 98 "buffer = new AudioBuffer({numberOfChannels: 1, length: 1, sampleRate: 48000}", | 74 () => { |
| 99 function () { | 75 buffer = new AudioBuffer( |
| 100 buffer = new AudioBuffer({ | 76 {numberOfChannels: 3, length: 1, sampleRate: 48000}); |
| 101 numberOfChannels: 1, | 77 }, |
| 102 length: 1, | 78 'buffer1 = new AudioBuffer({numberOfChannels: 3, length: 1, sampleRa te: 48000}') |
|
hongchan
2017/04/21 20:52:38
Is this clang-formatted?
Raymond Toy
2017/04/21 21:02:04
It was, and I ran it again. No change here.
| |
| 103 sampleRate: 48000 | 79 .notThrow(); |
| 104 }); | 80 // Verify the buffer has the correct values. |
| 105 }).notThrow() && success; | 81 should(buffer.numberOfChannels, 'buffer1.numberOfChannels').beEqualTo(3) ; |
| 82 should(buffer.length, 'buffer1.length').beEqualTo(1); | |
| 83 should(buffer.sampleRate, 'buffer1.sampleRate').beEqualTo(48000); | |
| 106 | 84 |
| 107 Should("Missing option values handled", success) | 85 task.done(); |
| 108 .summarize("correctly", "incorrectly"); | |
| 109 | |
| 110 taskDone(); | |
| 111 }); | 86 }); |
| 112 | 87 |
| 113 audit.defineTask("invalid option values", function (taskDone) { | 88 audit.define('invalid option values', (task, should) => { |
| 114 var success = true; | 89 var options = {numberOfChannels: 0, length: 1, sampleRate: 16000}; |
| 90 should( | |
| 91 () => { | |
| 92 var buffer = new AudioBuffer(options); | |
| 93 }, | |
| 94 'new AudioBuffer(' + JSON.stringify(options) + ')') | |
| 95 .throw('NotSupportedError'); | |
| 115 | 96 |
| 116 var options = { | 97 options = {numberOfChannels: 99, length: 0, sampleRate: 16000}; |
| 117 numberOfChannels: 0, | 98 should( |
| 118 length: 1, | 99 () => { |
| 119 sampleRate: 16000 | 100 var buffer = new AudioBuffer(options); |
| 120 }; | 101 }, |
| 121 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | 102 'new AudioBuffer(' + JSON.stringify(options) + ')') |
| 122 var buffer = new AudioBuffer(options); | 103 .throw('NotSupportedError'); |
| 123 }).throw("NotSupportedError"); | |
| 124 | 104 |
| 125 options = { | 105 options = {numberOfChannels: 1, length: 0, sampleRate: 16000}; |
| 126 numberOfChannels: 99, | 106 should( |
| 127 length: 0, | 107 () => { |
| 128 sampleRate: 16000 | 108 var buffer = new AudioBuffer(options); |
| 129 }; | 109 }, |
| 130 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | 110 'new AudioBuffer(' + JSON.stringify(options) + ')') |
| 131 var buffer = new AudioBuffer(options); | 111 .throw('NotSupportedError'); |
| 132 }).throw("NotSupportedError") && success; | |
| 133 | 112 |
| 134 options = { | 113 options = {numberOfChannels: 1, length: 1, sampleRate: 100}; |
| 135 numberOfChannels: 1, | 114 should( |
| 136 length: 0, | 115 () => { |
| 137 sampleRate: 16000 | 116 var buffer = new AudioBuffer(options); |
| 138 }; | 117 }, |
| 139 success = Should("new AudioBuffer(" + JSON.stringify(options) + ")", fun ction () { | 118 'new AudioBuffer(' + JSON.stringify(options) + ')') |
| 140 var buffer = new AudioBuffer(options); | 119 .throw('NotSupportedError'); |
| 141 }).throw("NotSupportedError") && success; | |
| 142 | 120 |
| 143 options = { | 121 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 }); | 122 }); |
| 157 | 123 |
| 158 audit.defineTask("default constructor", function (taskDone) { | 124 audit.define('default constructor', (task, should) => { |
| 159 var buffer; | 125 var buffer; |
| 160 var success = true; | |
| 161 | 126 |
| 162 var options = { | 127 var options = {numberOfChannels: 5, length: 17, sampleRate: 16000}; |
| 163 numberOfChannels: 5, | 128 should( |
| 164 length: 17, | 129 () => { |
| 165 sampleRate: 16000 | 130 buffer = new AudioBuffer(options); |
| 166 }; | 131 }, |
| 167 success = Should( | 132 'buffer = new AudioBuffer(' + JSON.stringify(options) + ')') |
| 168 "buffer = new AudioBuffer(" + JSON.stringify(options) + ")", | 133 .notThrow(); |
| 169 function () { | |
| 170 buffer = new AudioBuffer(options); | |
| 171 }).notThrow(); | |
| 172 | 134 |
| 173 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | 135 should(buffer.numberOfChannels, 'buffer.numberOfChannels') |
| 174 .beEqualTo(options.numberOfChannels) && success; | 136 .beEqualTo(options.numberOfChannels); |
| 175 success = Should("buffer.length", buffer.length) | 137 should(buffer.length, 'buffer.length').beEqualTo(options.length); |
| 176 .beEqualTo(options.length) && success; | 138 should(buffer.sampleRate, 'buffer.sampleRate').beEqualTo(16000); |
| 177 success = Should("buffer.sampleRate", buffer.sampleRate) | |
| 178 .beEqualTo(16000) && success; | |
| 179 | 139 |
| 180 Should("Default constructor values set", success) | 140 task.done(); |
| 181 .summarize("correctly", "incorrectly"); | |
| 182 | |
| 183 taskDone(); | |
| 184 }); | 141 }); |
| 185 | 142 |
| 186 audit.defineTask("valid constructor", function (taskDone) { | 143 audit.define('valid constructor', (task, should) => { |
| 187 var buffer; | 144 var buffer; |
| 188 var success = true; | |
| 189 | 145 |
| 190 var options = { | 146 var options = {numberOfChannels: 3, length: 42, sampleRate: 54321}; |
| 191 numberOfChannels: 3, | |
| 192 length: 42, | |
| 193 sampleRate: 54321 | |
| 194 }; | |
| 195 | 147 |
| 196 var message = "new AudioBuffer(" + JSON.stringify(options) + ")"; | 148 var message = 'new AudioBuffer(' + JSON.stringify(options) + ')'; |
| 197 success = Should(message, function () { | 149 should(() => { |
| 198 buffer = new AudioBuffer(options); | 150 buffer = new AudioBuffer(options); |
| 199 }).notThrow(); | 151 }, message).notThrow(); |
| 200 | 152 |
| 201 success = Should("buffer.numberOfChannels", buffer.numberOfChannels) | 153 should(buffer.numberOfChannels, 'buffer.numberOfChannels') |
| 202 .beEqualTo(options.numberOfChannels) && success; | 154 .beEqualTo(options.numberOfChannels); |
| 203 | 155 |
| 204 success = Should("buffer.length", buffer.length) | 156 should(buffer.length, 'buffer.length').beEqualTo(options.length); |
| 205 .beEqualTo(options.length) && success; | |
| 206 | 157 |
| 207 success = Should("buffer.sampleRate", buffer.sampleRate) | 158 should(buffer.sampleRate, 'buffer.sampleRate') |
| 208 .beEqualTo(options.sampleRate) && success; | 159 .beEqualTo(options.sampleRate); |
| 209 | 160 |
| 210 // Verify that we actually got the right number of channels | 161 // Verify that we actually got the right number of channels |
| 211 for (var k = 0; k < options.numberOfChannels; ++k) { | 162 for (var k = 0; k < options.numberOfChannels; ++k) { |
| 212 var data; | 163 var data; |
| 213 var message = "buffer.getChannelData(" + k + ")"; | 164 var message = 'buffer.getChannelData(' + k + ')'; |
| 214 success = Should(message, function () { | 165 should(() => { |
| 215 data = buffer.getChannelData(k); | 166 data = buffer.getChannelData(k); |
| 216 }).notThrow() && success; | 167 }, message).notThrow(); |
| 217 | 168 |
| 218 success = Should(message + " length", data.length) | 169 should(data.length, message + ' length').beEqualTo(options.length); |
| 219 .beEqualTo(options.length) && success; | |
| 220 } | 170 } |
| 221 | 171 |
| 222 Should("buffer.getChannelData(" + options.numberOfChannels + ")", | 172 should( |
| 223 function () { | 173 () => { |
| 224 buffer.getChannelData(options.numberOfChannels); | 174 buffer.getChannelData(options.numberOfChannels); |
| 225 }).throw("IndexSizeError") && success; | 175 }, |
| 176 'buffer.getChannelData(' + options.numberOfChannels + ')') | |
| 177 .throw('IndexSizeError'); | |
| 226 | 178 |
| 227 Should("AudioBuffer constructed", success) | 179 task.done(); |
| 228 .summarize("correctly", "incorrectly"); | |
| 229 | |
| 230 taskDone(); | |
| 231 }); | 180 }); |
| 232 | 181 |
| 233 audit.defineTask("multiple contexts", function (taskDone) { | 182 audit.define('multiple contexts', (task, should) => { |
| 234 // Test that an AudioBuffer can be used for different contexts. | 183 // Test that an AudioBuffer can be used for different contexts. |
| 235 var buffer = new AudioBuffer({ | 184 var buffer = |
| 236 length: 128, | 185 new AudioBuffer({length: 128, sampleRate: context.sampleRate}); |
| 237 sampleRate: context.sampleRate | |
| 238 }); | |
| 239 | 186 |
| 240 var data = buffer.getChannelData(0); | 187 var data = buffer.getChannelData(0); |
| 241 for (var k = 0; k < data.length; ++k) | 188 for (var k = 0; k < data.length; ++k) |
| 242 data[k] = 1 + k; | 189 data[k] = 1 + k; |
| 243 | 190 |
| 244 var c1 = new OfflineAudioContext(1, 128, context.sampleRate); | 191 var c1 = new OfflineAudioContext(1, 128, context.sampleRate); |
| 245 var c2 = new OfflineAudioContext(1, 128, context.sampleRate); | 192 var c2 = new OfflineAudioContext(1, 128, context.sampleRate); |
| 246 | 193 |
| 247 | 194 |
| 248 var s1 = new AudioBufferSourceNode(c1, { | 195 var s1 = new AudioBufferSourceNode(c1, {buffer: buffer}); |
| 249 buffer: buffer | 196 var s2 = new AudioBufferSourceNode(c2, {buffer: buffer}); |
| 250 }); | |
| 251 var s2 = new AudioBufferSourceNode(c2, { | |
| 252 buffer: buffer | |
| 253 }); | |
| 254 | 197 |
| 255 s1.connect(c1.destination); | 198 s1.connect(c1.destination); |
| 256 s2.connect(c2.destination); | 199 s2.connect(c2.destination); |
| 257 | 200 |
| 258 s1.start(); | 201 s1.start(); |
| 259 s2.start(); | 202 s2.start(); |
| 260 | 203 |
| 261 var c1Success = false; | 204 var c1Success = false; |
| 262 var c2Success = false; | 205 var c2Success = false; |
| 263 | 206 |
| 264 Promise.all([ | 207 Promise |
| 265 c1.startRendering().then(function (resultBuffer) { | 208 .all([ |
| 266 c1Success = Should("c1 result", resultBuffer.getChannelData(0)) | 209 c1.startRendering().then(function(resultBuffer) { |
| 267 .beEqualToArray(data); | 210 c1Success = should(resultBuffer.getChannelData(0), 'c1 result') |
| 268 }), | 211 .beEqualToArray(data); |
|
hongchan
2017/04/21 20:52:38
Return the return value of the assertion here.
Raymond Toy
2017/04/21 21:02:04
Done.
| |
| 269 c2.startRendering().then(function (resultBuffer) { | 212 }), |
| 270 c2Success = Should("c2 result", resultBuffer.getChannelData(0)) | 213 c2.startRendering().then(function(resultBuffer) { |
| 271 .beEqualToArray(data); | 214 c2Success = should(resultBuffer.getChannelData(0), 'c2 result') |
| 272 }), | 215 .beEqualToArray(data); |
| 273 ]) | 216 }), |
| 274 .then(function () { | 217 ]) |
| 275 Should("AudioBuffer shared between two different contexts", | 218 .then(() => { |
|
hongchan
2017/04/21 20:52:39
(returnValues => {
should(returnValues[1] && ret
Raymond Toy
2017/04/21 21:02:04
Done.
| |
| 276 c1Success && c2Success) | 219 should( |
| 277 .summarize("correctly", "incorrectly"); | 220 c1Success && c2Success, |
| 278 taskDone(); | 221 'AudioBuffer shared between two different contexts') |
| 279 }); | 222 .message('correctly', 'incorrectly'); |
| 223 task.done(); | |
| 224 }); | |
| 280 }); | 225 }); |
| 281 | 226 |
| 282 audit.runTasks(); | 227 audit.run(); |
| 283 </script> | 228 </script> |
| 284 </body> | 229 </body> |
| 285 </html> | 230 </html> |
| OLD | NEW |