| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | 2 |
| 3 <!-- | 3 <!-- |
| 4 Create an oscillator of each type and verify that the type is set correctly. | 4 Create an oscillator of each type and verify that the type is set correctly. |
| 5 --> | 5 --> |
| 6 <html> | 6 <html> |
| 7 <head> | 7 <head> |
| 8 <script src="../../resources/testharness.js"></script> | 8 <script src="../../resources/testharness.js"></script> |
| 9 <script src="../../resources/testharnessreport.js"></script> | 9 <script src="../../resources/testharnessreport.js"></script> |
| 10 <script src="../resources/audit-util.js"></script> | 10 <script src="../resources/audit-util.js"></script> |
| 11 <script src="../resources/audio-testing.js"></script> | 11 <script src="../resources/audit.js"></script> |
| 12 </head> | 12 </head> |
| 13 | 13 |
| 14 <body> | 14 <body> |
| 15 <script> | 15 <script> |
| 16 var sampleRate = 44100; | 16 var sampleRate = 44100; |
| 17 var renderLengthSeconds = 0.25; | 17 var renderLengthSeconds = 0.25; |
| 18 | 18 |
| 19 var oscTypes = ["sine", "square", "sawtooth", "triangle", "custom"]; | 19 var oscTypes = ["sine", "square", "sawtooth", "triangle", "custom"]; |
| 20 | 20 |
| 21 function runTest() | 21 let audit = Audit.createTaskRunner(); |
| 22 { | 22 |
| 23 audit.define("basic osc tests", (task, should) => { |
| 23 // Create offline audio context. | 24 // Create offline audio context. |
| 24 var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, s
ampleRate); | 25 var context = new OfflineAudioContext(2, sampleRate * |
| 26 renderLengthSeconds, sampleRate); |
| 25 var osc = context.createOscillator(); | 27 var osc = context.createOscillator(); |
| 26 | 28 |
| 27 // Set each possible oscillator type (except CUSTOM) and verify that the typ
e is correct. | 29 // Set each possible oscillator type (except CUSTOM) and verify that the |
| 28 // Here we're setting the type using WebIDL enum values which are strings. | 30 // type is correct. Here we're setting the type using WebIDL enum values |
| 31 // which are strings. |
| 29 for (var k = 0; k < oscTypes.length - 1; ++k) { | 32 for (var k = 0; k < oscTypes.length - 1; ++k) { |
| 30 osc.type = oscTypes[k]; | 33 osc.type = oscTypes[k]; |
| 31 Should("osc.type = '" + oscTypes[k] + "'", osc.type).beEqualTo(oscTypes[
k]); | 34 should(osc.type, "osc.type = '" + oscTypes[k] + "'") |
| 35 .beEqualTo(oscTypes[k]); |
| 32 } | 36 } |
| 33 | 37 |
| 34 // Verify that setting a custom type directly does not set the custom type.
This test has to be | 38 // Verify that setting a custom type directly does not set the custom |
| 35 // done before using setPeriodicWave. | 39 // type. This test has to be done before using setPeriodicWave. |
| 36 | 40 |
| 37 Should("osc.type = 'custom'", function () { | 41 should(function () { |
| 38 osc.type = "custom"; | 42 osc.type = "custom"; |
| 39 }).throw('InvalidStateError'); | 43 }, "osc.type = 'custom'") |
| 44 .throw('InvalidStateError'); |
| 40 | 45 |
| 41 // Now set a custom oscillator | 46 // Now set a custom oscillator |
| 42 var coeffA = new Float32Array([0, 1, 0.5]); | 47 var coeffA = new Float32Array([0, 1, 0.5]); |
| 43 var coeffB = new Float32Array([0, 0, 0]); | 48 var coeffB = new Float32Array([0, 0, 0]); |
| 44 var wave = context.createPeriodicWave(coeffA, coeffB); | 49 var wave = context.createPeriodicWave(coeffA, coeffB); |
| 45 | 50 |
| 46 Should("osc.setPeriodicWave(wave)", function () { | 51 should(function () { |
| 47 osc.setPeriodicWave(wave); | 52 osc.setPeriodicWave(wave); |
| 48 }).notThrow(); | 53 }, "osc.setPeriodicWave(wave)").notThrow(); |
| 49 Should("After setting periodicWave, osc.type", osc.type).beEqualTo("custom")
; | 54 should(osc.type, "After setting periodicWave, osc.type") |
| 50 | 55 .beEqualTo("custom"); |
| 56 |
| 51 // Check that numerical values are no longer supported | 57 // Check that numerical values are no longer supported |
| 52 var oldType = osc.type; | 58 var oldType = osc.type; |
| 53 osc.type = 0; | 59 osc.type = 0; |
| 54 Should("osc.type = 0", osc.type).notBeEqualTo(0); | 60 should(osc.type, "osc.type = 0").notBeEqualTo(0); |
| 55 Should("osc.type", osc.type).beEqualTo(oldType); | 61 should(osc.type, "osc.type").beEqualTo(oldType); |
| 56 } | |
| 57 | 62 |
| 58 runTest(); | 63 task.done(); |
| 64 }); |
| 65 |
| 66 audit.run(); |
| 59 </script> | 67 </script> |
| 60 | 68 |
| 61 | 69 |
| 62 </body> | 70 </body> |
| 63 </html> | 71 </html> |
| OLD | NEW |