Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title> | 4 <title> |
| 5 audioparam-exceptional-values.html | 5 audioparam-exceptional-values.html |
| 6 </title> | 6 </title> |
| 7 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
| 8 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
| 9 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
| 10 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
| 11 </head> | 11 </head> |
| 12 <body> | 12 <body> |
| 13 <script id="layout-test-code"> | 13 <script id="layout-test-code"> |
| 14 let audit = Audit.createTaskRunner(); | 14 let audit = Audit.createTaskRunner(); |
| 15 | 15 |
| 16 // For these values, AudioParam methods should throw an error because they | 16 // Context to use for all of the tests. The context isn't used for any |
| 17 // are invalid; only | 17 // processing; just need to for creating a gain node, which is used for |
| 18 // finite values are allowed. | 18 // all the tests. |
| 19 let targetValues = [Infinity, -Infinity, NaN]; | 19 let context; |
| 20 | 20 |
| 21 // For these time values, AudioParam methods should throw an error because | 21 // For these values, AudioParam methods should throw a Typeerror because |
| 22 // they are | 22 // they are not finite values. |
| 23 // invalid. Only finite non-negative values are allowed for any time or | 23 let nonFiniteValues = [Infinity, -Infinity, NaN]; |
| 24 // time-like parameter. | 24 |
| 25 let timeValues = [-1, Infinity, -Infinity, NaN]; | 25 audit.define('initialize', (task, should) => { |
| 26 | 26 should(() => { |
| 27 // For these duration values, AudioParam methods should throw an error | 27 // Context for testing. Rendering isn't done, so any valid values can |
| 28 // because they are | 28 // be used here so might as well make them small. |
| 29 // invalid. Only finite values are allowed for any duration parameter. | 29 context = new OfflineAudioContext(1, 1, 8000); |
| 30 let durationValues = [-1, Infinity, -Infinity, NaN, 0]; | 30 }, 'Creating context for testing').notThrow(); |
| 31 | 31 |
| 32 // For these timeConstant values for setTargetAtTime an error must be | 32 task.done(); |
| 33 // thrown because they are | 33 }); |
| 34 // invalid. | 34 |
| 35 let timeConstantValues = [-1, Infinity, -Infinity, NaN]; | 35 audit.define( |
| 36 | 36 { |
| 37 // Just an array for use by setValueCurveAtTime. The length and contents | 37 label: 'test value', |
| 38 // of the array are not | 38 description: 'Test non-finite arguments for AudioParam value' |
| 39 // important. | 39 }, |
| 40 let curve = new Float32Array(10); | 40 (task, should) => { |
| 41 | 41 let gain = context.createGain(); |
| 42 audit.define( | 42 |
| 43 { | 43 // Default method for generating the arguments for an automation |
| 44 label: 'test', | 44 // method for testing the value of the automation. |
| 45 description: | 45 let defaultFuncArg = (value) => [value, 1]; |
| 46 'Test exceptional arguments for AudioParam timeline events' | |
| 47 }, | |
| 48 function(task, should) { | |
| 49 let context = new AudioContext(); | |
| 50 let gain = context.createGain(); | |
| 51 | 46 |
| 52 // Test the value parameter | 47 // Test the value parameter |
| 53 for (value of targetValues) { | 48 doTests(should, gain, 'TypeError', nonFiniteValues, [ |
| 54 let testMethods = [ | 49 {automationName: 'setValueAtTime', funcArg: defaultFuncArg}, |
| 55 {name: 'setValueAtTime', arg: [value, 1]}, | 50 {automationName: 'linearRampToValueAtTime', funcArg: defaultFuncAr g}, |
| 56 {name: 'linearRampToValueAtTime', arg: [value, 1]}, | 51 {automationName: 'exponentialRampToValueAtTime', funcArg: defaultF uncArg}, { |
| 57 {name: 'exponentialRampToValueAtTime', arg: [value, 1]}, | 52 automationName: 'setTargetAtTime', |
| 58 {name: 'setTargetAtTime', arg: [value, 1, 1]} | 53 funcArg: (value) => [value, 1, 1] |
|
hongchan
2017/06/06 16:34:29
Line 48-53 needs to be wrapped properly.
Raymond Toy
2017/06/06 17:55:33
clang-format all the things!
| |
| 59 ]; | |
| 60 | |
| 61 for (method of testMethods) { | |
| 62 let message = | |
| 63 'gain.gain.' + method.name + '(' + method.arg + ')'; | |
| 64 should( | |
| 65 () => gain.gain[method.name].apply(gain.gain, method.arg), | |
| 66 message) | |
| 67 .throw(); | |
| 68 } | 54 } |
| 69 } | 55 ]); |
| 56 task.done(); | |
| 57 }); | |
| 58 | |
| 59 audit.define( | |
| 60 { | |
| 61 label: 'test time', | |
| 62 description: 'Test non-finite arguments for AudioParam time' | |
| 63 }, | |
| 64 (task, should) => { | |
| 65 let gain = context.createGain(); | |
| 66 | |
| 67 // Default method for generating the arguments for an automation | |
| 68 // method for testing the time parameter of the automation. | |
| 69 let defaultFuncArg = (startTime) => [1, startTime]; | |
| 70 | 70 |
| 71 // Test the time parameter | 71 // Test the time parameter |
| 72 for (startTime of timeValues) { | 72 doTests(should, gain, 'TypeError', nonFiniteValues, [ |
| 73 let testMethods = [ | 73 {automationName: 'setValueAtTime', funcArg: defaultFuncArg}, |
| 74 {name: 'setValueAtTime', arg: [1, startTime]}, | 74 {automationName: 'linearRampToValueAtTime', funcArg: defaultFuncAr g}, |
| 75 {name: 'linearRampToValueAtTime', arg: [1, startTime]}, | 75 {automationName: 'exponentialRampToValueAtTime', funcArg: defaultF uncArg}, |
| 76 {name: 'exponentialRampToValueAtTime', arg: [1, startTime]}, | 76 // Test start time for setTarget |
| 77 {name: 'setTargetAtTime', arg: [1, startTime, 1]} | 77 { |
| 78 ]; | 78 automationName: 'setTargetAtTime', |
| 79 | 79 funcArg: (startTime) => [1, startTime, 1] |
| 80 for (method of testMethods) { | 80 }, |
| 81 let message = | 81 // Test time constant for setTarget |
| 82 'gain.gain.' + method.name + '(' + method.arg + ')'; | 82 { |
| 83 should( | 83 automationName: 'setTargetAtTime', |
| 84 () => gain.gain[method.name].apply(gain.gain, method.arg), | 84 funcArg: (timeConstant) => [1, 1, timeConstant] |
| 85 message) | 85 }, |
| 86 .throw(); | 86 ]); |
| 87 } | 87 |
| 88 } | 88 task.done(); |
| 89 | 89 }); |
| 90 // Test time constant | 90 |
| 91 for (value of timeConstantValues) { | 91 audit.define( |
| 92 should( | 92 { |
| 93 () => gain.gain.setTargetAtTime(1, 1, value), | 93 label: 'test setValueCurve', |
| 94 'gain.gain.setTargetAtTime(1, 1, ' + value + ')') | 94 description: 'Test non-finite arguments for setValueCurveAtTime' |
| 95 .throw(); | 95 }, |
| 96 } | 96 (task, should) => { |
| 97 | 97 let gain = context.createGain(); |
| 98 // Test startTime and duration for setValueCurveAtTime | 98 |
| 99 for (startTime of timeValues) { | 99 // Just an array for use by setValueCurveAtTime. The length and |
| 100 should( | 100 // contents of the array are not important. |
| 101 () => gain.gain.setValueCurveAtTime(curve, startTime, 1), | 101 let curve = new Float32Array(3); |
| 102 'gain.gain.setValueCurveAtTime(curve, ' + startTime + ', 1)') | 102 |
| 103 .throw(); | 103 doTests(should, gain, 'TypeError', nonFiniteValues, [ |
| 104 } | 104 { |
| 105 for (duration of durationValues) { | 105 automationName: 'setValueCurveAtTime', |
| 106 should( | 106 funcArg: (startTime) => [curve, startTime, 1] |
| 107 () => gain.gain.setValueCurveAtTime(curve, 1, duration), | 107 }, |
| 108 'gain.gain.setValueCurveAtTime(curve, 1, ' + duration + ')') | 108 ]); |
| 109 .throw(); | 109 |
| 110 } | 110 // Non-finite values for the curve should signal an error |
| 111 // Non-finite curve values should signal an error. | 111 doTests( |
| 112 for (curve of [[1, 2, Infinity, 3], [1, NaN, 2, 3]]) { | 112 should, gain, 'TypeError', |
| 113 should( | 113 [[1, 2, Infinity, 3], [1, NaN, 2, 3]], [{ |
| 114 () => gain.gain.setValueCurveAtTime(curve, 1, 1), | 114 automationName: 'setValueCurveAtTime', |
| 115 'gain.gain.setValueCurveAtTime([' + curve + '], 1, 1)') | 115 funcArg: (c) => [c, 1, 1] |
| 116 .throw(); | 116 }]); |
| 117 } | 117 |
| 118 task.done(); | |
| 119 }); | |
| 120 | |
| 121 audit.define( | |
| 122 { | |
| 123 label: 'special cases 1', | |
| 124 description: 'Test exceptions for finite values' | |
| 125 }, | |
| 126 (task, should) => { | |
| 127 let gain = context.createGain(); | |
| 128 | |
| 129 // Default method for generating the arguments for an automation | |
| 130 // method for testing the time parameter of the automation. | |
| 131 let defaultFuncArg = (startTime) => [1, startTime]; | |
| 132 | |
| 133 // Test the time parameter | |
| 134 let curve = new Float32Array(3); | |
| 135 doTests(should, gain, 'RangeError', [-1], [ | |
| 136 {automationName: 'setValueAtTime', funcArg: defaultFuncArg}, | |
| 137 {automationName: 'linearRampToValueAtTime', funcArg: defaultFuncAr g}, | |
| 138 {automationName: 'exponentialRampToValueAtTime', funcArg: defaultF uncArg}, | |
| 139 { | |
| 140 automationName: 'setTargetAtTime', | |
| 141 funcArg: (startTime) => [1, startTime, 1] | |
| 142 }, | |
| 143 // Test time constant | |
| 144 { | |
| 145 automationName: 'setTargetAtTime', | |
| 146 funcArg: (timeConstant) => [1, 1, timeConstant] | |
| 147 }, | |
| 148 // startTime and duration for setValueCurve | |
| 149 { | |
| 150 automationName: 'setValueCurveAtTime', | |
| 151 funcArg: (startTime) => [curve, startTime, 1] | |
| 152 }, | |
| 153 { | |
| 154 automationName: 'setValueCurveAtTime', | |
| 155 funcArg: (duration) => [curve, 1, duration] | |
| 156 }, | |
| 157 ]); | |
| 158 | |
| 159 // One final test for setValueCurve: duration can't be 0. | |
| 160 should( | |
| 161 () => gain.gain.setValueCurveAtTime(curve, 1, 0), | |
| 162 'gain.gain.setValueCurveAtTime(curve, 1, 0)') | |
| 163 .throw('RangeError'); | |
| 164 | |
| 165 task.done(); | |
| 166 }); | |
| 167 | |
| 168 audit.define( | |
| 169 { | |
| 170 label: 'special cases 2', | |
| 171 description: 'Test special cases for expeonentialRamp' | |
| 172 }, | |
| 173 (task, should) => { | |
| 174 let gain = context.createGain(); | |
| 175 | |
| 176 doTests(should, gain, 'RangeError', [0, -1e-100, 1e-100], [{ | |
| 177 automationName: 'exponentialRampToValueAtTime', | |
| 178 funcArg: (value) => [value, 1] | |
| 179 }]); | |
| 180 | |
| 118 task.done(); | 181 task.done(); |
| 119 }); | 182 }); |
| 120 | 183 |
| 121 audit.run(); | 184 audit.run(); |
| 185 | |
| 186 function doTests(should, node, errorName, testValues, testMethods) { | |
| 187 // Run test over the set of values in |testValues| for all of the | |
| 188 // automation methods in |testMethods|. The expected error type is | |
| 189 // |errorName|. |testMethods| is an array of dictionaries with | |
| 190 // attributes |automationName| giving the name of the automation method | |
| 191 // to be tested and |funcArg| being a function of one parameter that | |
| 192 // produces an array that will be used as the argument to the automation | |
| 193 // method. | |
|
hongchan
2017/06/06 16:34:29
Not a showstopper, but the comment is usually loca
Raymond Toy
2017/06/06 17:55:33
Done.
| |
| 194 testValues.forEach(value => { | |
| 195 testMethods.forEach(method => { | |
| 196 let args = method.funcArg(value); | |
| 197 let message = 'gain.gain.' + method.automationName + '(' + | |
| 198 argString(args) + ')'; | |
| 199 should(() => node.gain[method.automationName](...args), message) | |
| 200 .throw(errorName); | |
| 201 }); | |
| 202 }); | |
| 203 } | |
| 204 | |
| 205 function argString(arg) { | |
| 206 // Specialized printer for automation arguments so that messages make | |
|
hongchan
2017/06/06 16:34:29
Ditto.
Raymond Toy
2017/06/06 17:55:33
Done.
| |
| 207 // sense. We assume the first element is either a number or an array. | |
| 208 // If it's an array, there are always three elements, and we want to | |
| 209 // print out the brackets for the array argument. | |
| 210 if (typeof(arg[0]) === 'number') { | |
| 211 return arg.toString(); | |
| 212 } | |
| 213 | |
| 214 return '[' + arg[0] + '],' + arg[1] + ',' + arg[2]; | |
| 215 } | |
| 216 | |
| 122 </script> | 217 </script> |
| 123 </body> | 218 </body> |
| 124 </html> | 219 </html> |
| OLD | NEW |