Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test Constructor: PeriodicWave</title> | 4 <title>Test Constructor: PeriodicWave</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/audio-testing.js"></script> |
| 9 <script src="audionodeoptions.js"></script> | 9 <script src="audionodeoptions.js"></script> |
| 10 </head> | 10 </head> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 | 44 |
| 45 taskDone(); | 45 taskDone(); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 audit.defineTask("default constructor", function (taskDone) { | 48 audit.defineTask("default constructor", function (taskDone) { |
| 49 var node; | 49 var node; |
| 50 var success = true; | 50 var success = true; |
| 51 | 51 |
| 52 success = Should("node = new PeriodicWave(context)", function () { | 52 success = Should("node = new PeriodicWave(context)", function () { |
| 53 node = new PeriodicWave(context); | 53 node = new PeriodicWave(context); |
| 54 }).throw("InvalidStateError"); | 54 }).notThrow(); |
| 55 | 55 |
| 56 taskDone(); | 56 taskDone(); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 audit.defineTask("constructor with options", function (taskDone) { | 59 audit.defineTask("constructor with options", function (taskDone) { |
| 60 var node; | 60 var node1; |
| 61 var success = true; | 61 var success = true; |
| 62 | 62 |
| 63 var options = { | 63 var options = { |
| 64 real: [1, 1] | 64 real: [1, 1] |
| 65 }; | 65 }; |
| 66 success = Should("node = new PeriodicWave(context, " + JSON.stringify(op tions) + ")", | 66 success = Should("node = new PeriodicWave(context, " + JSON.stringify(op tions) + ")", |
| 67 function () { | 67 function () { |
| 68 node = new PeriodicWave(context, options); | 68 node1 = new PeriodicWave(context, options); |
| 69 }).notThrow(); | 69 }).notThrow(); |
| 70 success = Should("node instanceof PeriodicWave", node instanceof Periodi cWave) | 70 success = Should("node1 instanceof PeriodicWave", node1 instanceof Perio dicWave) |
| 71 .beEqualTo(true) && success; | 71 .beEqualTo(true) && success; |
| 72 | 72 |
| 73 var node2; | |
| 73 options = { | 74 options = { |
| 74 imag: [1, 1] | 75 imag: [1, 1] |
| 75 }; | 76 }; |
| 76 success = Should("node = new PeriodicWave(context, " + JSON.stringify(op tions) + ")", | 77 success = Should("node2 = new PeriodicWave(context, " + JSON.stringify(o ptions) + ")", |
| 77 function () { | 78 function () { |
| 78 node = new PeriodicWave(context, options); | 79 node2 = new PeriodicWave(context, options); |
| 79 }).notThrow(); | 80 }).notThrow(); |
| 80 success = Should("node instanceof PeriodicWave", node instanceof Periodi cWave) | 81 success = Should("node2 instanceof PeriodicWave", node2 instanceof Perio dicWave) |
| 81 .beEqualTo(true) && success; | 82 .beEqualTo(true) && success; |
| 82 | 83 |
| 84 var node3; | |
| 83 options = { | 85 options = { |
| 84 real: [1, 2], | 86 real: [1, 2], |
| 85 imag: [1, 1] | 87 imag: [1, 1] |
| 86 }; | 88 }; |
| 87 success = Should("node = new PeriodicWave(context, " + JSON.stringify(op tions) + ")", | 89 success = Should("node3 = new PeriodicWave(context, " + JSON.stringify(o ptions) + ")", |
| 88 function () { | 90 function () { |
| 89 node = new PeriodicWave(context, options); | 91 node3 = new PeriodicWave(context, options); |
| 90 }).notThrow(); | 92 }).notThrow(); |
| 91 success = Should("node instanceof PeriodicWave", node instanceof Periodi cWave) | 93 success = Should("node3 instanceof PeriodicWave", node3 instanceof Perio dicWave) |
| 92 .beEqualTo(true) && success; | 94 .beEqualTo(true) && success; |
| 93 | 95 |
| 94 Should("new PeriodicWave() with options", success) | 96 Should("new PeriodicWave() with options", success) |
| 95 .summarize( | 97 .summarize( |
| 96 "constructed with correct attributes", | 98 "constructed with correct attributes", |
| 97 "was not constructed correctly"); | 99 "was not constructed correctly"); |
| 98 | 100 |
| 99 taskDone(); | 101 taskDone(); |
| 100 }); | 102 }); |
| 101 | 103 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 if (waveOptions.imag) { | 283 if (waveOptions.imag) { |
| 282 if (message.length > 0) | 284 if (message.length > 0) |
| 283 message += ", " | 285 message += ", " |
| 284 message += "imag: [" + waveOptions.imag + "]"; | 286 message += "imag: [" + waveOptions.imag + "]"; |
| 285 } | 287 } |
| 286 Should("Oscillator with periodicWave {" + message + "}", actual) | 288 Should("Oscillator with periodicWave {" + message + "}", actual) |
| 287 .beCloseToArray(expected, threshold); | 289 .beCloseToArray(expected, threshold); |
| 288 }); | 290 }); |
| 289 } | 291 } |
| 290 | 292 |
| 293 function sineWaveTest(waveFun, message) { | |
| 294 // Verify that the default PeriodicWave produces a sine wave. Use a | |
| 295 // 2-channel context to verify this. Channel 0 is the output from the | |
| 296 // PeriodicWave, and channel 1 is the reference oscillator output. | |
| 297 let context = new OfflineAudioContext(2, 40000, 40000); | |
| 298 let oscRef = | |
| 299 new OscillatorNode(context, {type: 'sine', frequency: 440}); | |
| 300 let wave = waveFun(context); | |
| 301 let oscTest = | |
| 302 new OscillatorNode(context, {frequency: 440, periodicWave: wave}); | |
| 303 | |
| 304 let merger = new ChannelMergerNode(context, {numberOfInputs: 2}); | |
| 305 | |
| 306 oscRef.connect(merger, 0, 1); | |
| 307 oscTest.connect(merger, 0, 0); | |
| 308 | |
| 309 merger.connect(context.destination); | |
| 310 | |
| 311 oscRef.start(); | |
| 312 oscTest.start(); | |
| 313 | |
| 314 return context.startRendering().then(output => { | |
| 315 // The output from the two channels MUST match exactly. | |
| 316 let actual = output.getChannelData(0); | |
| 317 let ref = output.getChannelData(1); | |
| 318 | |
| 319 Should(message, actual).beEqualToArray(ref); | |
| 320 }) | |
|
hongchan
2017/03/16 21:50:21
A missing semicolon!
Raymond Toy
2017/03/16 22:18:17
Done.
| |
| 321 } | |
| 322 | |
| 323 audit.defineTask('default wave', function(taskDone) { | |
| 324 // Verify that the default PeriodicWave produces a sine wave. | |
| 325 sineWaveTest( | |
| 326 (context) => new PeriodicWave(context), | |
| 327 'new PeriodicWave(context) output') | |
| 328 .then(taskDone); | |
|
hongchan
2017/03/16 21:50:21
Is this indentation from clang-format? If so, clan
Raymond Toy
2017/03/16 22:18:17
Yes, clang format. And rerunning after fixing the
| |
| 329 }); | |
| 330 | |
| 331 audit.defineTask('default wave (with dict)', function(taskDone) { | |
| 332 // Verify that the default PeriodicWave produces a sine wave when the | |
| 333 // PeriodicWaveOptions dictionary is given, but real and imag members | |
| 334 // are not set. | |
| 335 sineWaveTest( | |
| 336 (context) => new PeriodicWave(context, {foo: 42}), | |
| 337 'new PeriodicWave(context, {foo: 42}) output') | |
| 338 .then(taskDone); | |
| 339 }); | |
| 340 | |
| 291 audit.runTasks(); | 341 audit.runTasks(); |
| 292 </script> | 342 </script> |
| 293 </body> | 343 </body> |
| 294 </html> | 344 </html> |
| OLD | NEW |