Chromium Code Reviews| 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/compatibility.js"></script> | 8 <script src="resources/compatibility.js"></script> |
| 9 <script type="text/javascript" src="resources/audio-testing.js"></script> | 9 <script type="text/javascript" src="resources/audio-testing.js"></script> |
| 10 <script type="text/javascript" src="../resources/js-test.js"></script> | 10 <script type="text/javascript" src="../resources/js-test.js"></script> |
| 11 </head> | 11 </head> |
| 12 | 12 |
| 13 <body> | 13 <body> |
| 14 <div id="description"></div> | 14 <div id="description"></div> |
| 15 <div id="console"></div> | 15 <div id="console"></div> |
| 16 | 16 |
| 17 <script> | 17 <script> |
| 18 description("Basic test of setting Oscillator node types."); | 18 description("Basic test of setting Oscillator node types."); |
| 19 | 19 |
| 20 var sampleRate = 44100; | 20 var sampleRate = 44100; |
| 21 var renderLengthSeconds = 0.25; | 21 var renderLengthSeconds = 0.25; |
| 22 | 22 |
| 23 var oscTypes = [{type: "sine", integerType: 0, name: "SINE"}, | 23 var oscTypes = ["sine", "square", "sawtooth", "triangle", "custom"]; |
| 24 {type: "square", integerType: 1, name: "SQUARE"}, | |
| 25 {type: "sawtooth", integerType: 2, name: "SAWTOOTH"}, | |
| 26 {type: "triangle", integerType: 3, name: "TRIANGLE"}, | |
| 27 {type: "custom", integerType: 4, name: "CUSTOM"}]; | |
| 28 | 24 |
| 29 function runTest() | 25 function runTest() |
| 30 { | 26 { |
| 31 if (window.testRunner) { | 27 if (window.testRunner) { |
| 32 testRunner.dumpAsText(); | 28 testRunner.dumpAsText(); |
| 33 testRunner.waitUntilDone(); | 29 testRunner.waitUntilDone(); |
| 34 } | 30 } |
| 35 | 31 |
| 36 window.jsTestIsAsync = true; | 32 window.jsTestIsAsync = true; |
| 37 | 33 |
| 38 // Create offline audio context. | 34 // Create offline audio context. |
| 39 var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, s ampleRate); | 35 var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, s ampleRate); |
| 40 var osc = context.createOscillator(); | 36 var osc = context.createOscillator(); |
| 41 | 37 |
| 42 // Set each possible oscillator type (except CUSTOM) and verify that the typ e is correct. | 38 // Set each possible oscillator type (except CUSTOM) and verify that the typ e is correct. |
| 43 // Here we're setting the type using WebIDL enum values which are strings. | 39 // Here we're setting the type using WebIDL enum values which are strings. |
| 44 for (var k = 0; k < oscTypes.length - 1; ++k) { | 40 for (var k = 0; k < oscTypes.length - 1; ++k) { |
| 45 osc.type = oscTypes[k].type; | 41 osc.type = oscTypes[k]; |
| 46 if (osc.type == oscTypes[k].type) | 42 if (osc.type == oscTypes[k]) |
| 47 testPassed("Oscillator correctly set to " + oscTypes[k].name + " typ e."); | 43 testPassed('Oscillator correctly set to "' + oscTypes[k] + '" type.' ); |
| 48 else | 44 else |
| 49 testFailed("Oscillator set to " + oscTypes[k].name + " type, but ret urns " + oscTypes[osc.type].name + " type."); | 45 testFailed('Oscillator set to "' + oscTypes[k] + '" type, but return s "' + osc.type + '" type.'); |
| 50 } | 46 } |
| 51 | 47 |
| 52 // For legacy support, verify that we can set the type attribute as an integ er value and | 48 // Verify that setting a custom type directly does not set the custom type. This test has to be |
| 53 // verify that this translates correctly to the WebIDL enum value. | 49 // done before using setPeriodicWave. |
| 54 for (var k = 0; k < oscTypes.length - 1; ++k) { | 50 |
| 55 osc.type = oscTypes[k].integerType; | 51 osc.type = "custom"; |
| 56 if (osc.type == oscTypes[k].type) | 52 if (osc.type == "custom") |
|
Ken Russell (switch to Gerrit)
2014/04/08 17:48:22
The fact that the OscillatorType enum contains "cu
Raymond Toy
2014/04/08 18:34:20
Good point. I think this is a spec issue; I'll try
| |
| 57 testPassed("Oscillator correctly set to " + oscTypes[k].name + " typ e using legacy integer value."); | 53 testFailed('Directly setting oscillator type to "custom" incorrectly suc ceeded.'); |
| 58 else | 54 else |
| 59 testFailed("Oscillator set to " + oscTypes[k].name + " type, but ret urns " + oscTypes[osc.type].name + " type using legacy integer value."); | 55 testPassed('Directly setting oscillator type to "custom" correctly faile d.'); |
| 60 } | |
| 61 | 56 |
| 62 // Now set a custom oscillator | 57 // Now set a custom oscillator |
| 63 var coeffA = new Float32Array([0, 1, 0.5]); | 58 var coeffA = new Float32Array([0, 1, 0.5]); |
| 64 var coeffB = new Float32Array([0, 0, 0]); | 59 var coeffB = new Float32Array([0, 0, 0]); |
| 65 var wave = context.createPeriodicWave(coeffA, coeffB); | 60 var wave = context.createPeriodicWave(coeffA, coeffB); |
| 66 osc.setPeriodicWave(wave); | 61 osc.setPeriodicWave(wave); |
| 67 if (osc.type == "custom") | 62 if (osc.type == "custom") |
| 68 testPassed("Oscillator correctly set to CUSTOM type using setPeriodicWav e."); | 63 testPassed('Oscillator correctly set to "custom" type using setPeriodicW ave.'); |
| 69 else | 64 else |
| 70 testFailed("Oscillator set to CUSTOM type, but returns " + oscTypes[osc. type].name + " type."); | 65 testFailed('Oscillator set to "custom" type, but returns "' + osc.type + '" type.'); |
| 71 | 66 |
| 72 // Try setting some invalid types | 67 |
| 73 try { | 68 // Check that numerical values are no longer supported |
| 74 osc.type = "custom"; | 69 osc.type = 0; |
| 75 testFailed("Directly setting oscillator type to CUSTOM did not throw exc eption."); | 70 if (osc.type == 0) |
| 76 } catch (e) { | 71 testFailed("Oscillator incorrectly set to 0.") |
| 77 testPassed("Directly setting oscillator type to CUSTOM correctly throws exception."); | 72 else |
| 78 } | 73 testPassed("Oscillator correctly not set to 0."); |
| 79 | |
| 80 var oscType = osc.CUSTOM + 1; | |
| 81 try { | |
| 82 osc.type = oscType; | |
| 83 testFailed("Setting oscillator to invalid type " + oscType + " did not t hrow exception."); | |
| 84 } catch (e) { | |
| 85 testPassed("Setting oscillator to invalid type " + oscType + " correctly throws exception."); | |
| 86 } | |
| 87 | |
| 88 // Check specifically that we throw a TypeError. | |
| 89 shouldThrowTypeError(function() { osc.type = "xyz12349jfksd"; }, "Setting .t ype to illegal string value"); | |
| 90 shouldThrowTypeError(function() { osc.type = new Float32Array(1); }, "Settin g .type to illegal type of Float32Array"); | |
| 91 | 74 |
| 92 finishJSTest(); | 75 finishJSTest(); |
| 93 } | 76 } |
| 94 | 77 |
| 95 runTest(); | 78 runTest(); |
| 96 successfullyParsed = true; | 79 successfullyParsed = true; |
| 97 | 80 |
| 98 </script> | 81 </script> |
| 99 | 82 |
| 100 | 83 |
| 101 </body> | 84 </body> |
| 102 </html> | 85 </html> |
| OLD | NEW |