Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-exceptional-values.html |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-exceptional-values.html b/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-exceptional-values.html |
| index d66f6a247a28faf671e8e1c0b5f31ee09dbc5957..379e43bc38b90b8f0553adc447baa3c5cf55222a 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-exceptional-values.html |
| +++ b/third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-exceptional-values.html |
| @@ -13,112 +13,207 @@ |
| <script id="layout-test-code"> |
| let audit = Audit.createTaskRunner(); |
| - // For these values, AudioParam methods should throw an error because they |
| - // are invalid; only |
| - // finite values are allowed. |
| - let targetValues = [Infinity, -Infinity, NaN]; |
| - |
| - // For these time values, AudioParam methods should throw an error because |
| - // they are |
| - // invalid. Only finite non-negative values are allowed for any time or |
| - // time-like parameter. |
| - let timeValues = [-1, Infinity, -Infinity, NaN]; |
| - |
| - // For these duration values, AudioParam methods should throw an error |
| - // because they are |
| - // invalid. Only finite values are allowed for any duration parameter. |
| - let durationValues = [-1, Infinity, -Infinity, NaN, 0]; |
| - |
| - // For these timeConstant values for setTargetAtTime an error must be |
| - // thrown because they are |
| - // invalid. |
| - let timeConstantValues = [-1, Infinity, -Infinity, NaN]; |
| - |
| - // Just an array for use by setValueCurveAtTime. The length and contents |
| - // of the array are not |
| - // important. |
| - let curve = new Float32Array(10); |
| + // Context to use for all of the tests. The context isn't used for any |
| + // processing; just need to for creating a gain node, which is used for |
| + // all the tests. |
| + let context; |
| + |
| + // For these values, AudioParam methods should throw a Typeerror because |
| + // they are not finite values. |
| + let nonFiniteValues = [Infinity, -Infinity, NaN]; |
| + |
| + audit.define('initialize', (task, should) => { |
| + should(() => { |
| + // Context for testing. Rendering isn't done, so any valid values can |
| + // be used here so might as well make them small. |
| + context = new OfflineAudioContext(1, 1, 8000); |
| + }, 'Creating context for testing').notThrow(); |
| + |
| + task.done(); |
| + }); |
| audit.define( |
| { |
| - label: 'test', |
| - description: |
| - 'Test exceptional arguments for AudioParam timeline events' |
| + label: 'test value', |
| + description: 'Test non-finite arguments for AudioParam value' |
| }, |
| - function(task, should) { |
| - let context = new AudioContext(); |
| + (task, should) => { |
| let gain = context.createGain(); |
| + // Default method for generating the arguments for an automation |
| + // method for testing the value of the automation. |
| + let defaultFuncArg = (value) => [value, 1]; |
| + |
| // Test the value parameter |
| - for (value of targetValues) { |
| - let testMethods = [ |
| - {name: 'setValueAtTime', arg: [value, 1]}, |
| - {name: 'linearRampToValueAtTime', arg: [value, 1]}, |
| - {name: 'exponentialRampToValueAtTime', arg: [value, 1]}, |
| - {name: 'setTargetAtTime', arg: [value, 1, 1]} |
| - ]; |
| - |
| - for (method of testMethods) { |
| - let message = |
| - 'gain.gain.' + method.name + '(' + method.arg + ')'; |
| - should( |
| - () => gain.gain[method.name].apply(gain.gain, method.arg), |
| - message) |
| - .throw(); |
| + doTests(should, gain, 'TypeError', nonFiniteValues, [ |
| + {automationName: 'setValueAtTime', funcArg: defaultFuncArg}, |
| + {automationName: 'linearRampToValueAtTime', funcArg: defaultFuncArg}, |
| + {automationName: 'exponentialRampToValueAtTime', funcArg: defaultFuncArg}, { |
| + automationName: 'setTargetAtTime', |
| + 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!
|
| } |
| - } |
| + ]); |
| + task.done(); |
| + }); |
| + |
| + audit.define( |
| + { |
| + label: 'test time', |
| + description: 'Test non-finite arguments for AudioParam time' |
| + }, |
| + (task, should) => { |
| + let gain = context.createGain(); |
| + |
| + // Default method for generating the arguments for an automation |
| + // method for testing the time parameter of the automation. |
| + let defaultFuncArg = (startTime) => [1, startTime]; |
| // Test the time parameter |
| - for (startTime of timeValues) { |
| - let testMethods = [ |
| - {name: 'setValueAtTime', arg: [1, startTime]}, |
| - {name: 'linearRampToValueAtTime', arg: [1, startTime]}, |
| - {name: 'exponentialRampToValueAtTime', arg: [1, startTime]}, |
| - {name: 'setTargetAtTime', arg: [1, startTime, 1]} |
| - ]; |
| - |
| - for (method of testMethods) { |
| - let message = |
| - 'gain.gain.' + method.name + '(' + method.arg + ')'; |
| - should( |
| - () => gain.gain[method.name].apply(gain.gain, method.arg), |
| - message) |
| - .throw(); |
| - } |
| - } |
| - |
| - // Test time constant |
| - for (value of timeConstantValues) { |
| - should( |
| - () => gain.gain.setTargetAtTime(1, 1, value), |
| - 'gain.gain.setTargetAtTime(1, 1, ' + value + ')') |
| - .throw(); |
| - } |
| - |
| - // Test startTime and duration for setValueCurveAtTime |
| - for (startTime of timeValues) { |
| - should( |
| - () => gain.gain.setValueCurveAtTime(curve, startTime, 1), |
| - 'gain.gain.setValueCurveAtTime(curve, ' + startTime + ', 1)') |
| - .throw(); |
| - } |
| - for (duration of durationValues) { |
| - should( |
| - () => gain.gain.setValueCurveAtTime(curve, 1, duration), |
| - 'gain.gain.setValueCurveAtTime(curve, 1, ' + duration + ')') |
| - .throw(); |
| - } |
| - // Non-finite curve values should signal an error. |
| - for (curve of [[1, 2, Infinity, 3], [1, NaN, 2, 3]]) { |
| - should( |
| - () => gain.gain.setValueCurveAtTime(curve, 1, 1), |
| - 'gain.gain.setValueCurveAtTime([' + curve + '], 1, 1)') |
| - .throw(); |
| - } |
| + doTests(should, gain, 'TypeError', nonFiniteValues, [ |
| + {automationName: 'setValueAtTime', funcArg: defaultFuncArg}, |
| + {automationName: 'linearRampToValueAtTime', funcArg: defaultFuncArg}, |
| + {automationName: 'exponentialRampToValueAtTime', funcArg: defaultFuncArg}, |
| + // Test start time for setTarget |
| + { |
| + automationName: 'setTargetAtTime', |
| + funcArg: (startTime) => [1, startTime, 1] |
| + }, |
| + // Test time constant for setTarget |
| + { |
| + automationName: 'setTargetAtTime', |
| + funcArg: (timeConstant) => [1, 1, timeConstant] |
| + }, |
| + ]); |
| + |
| + task.done(); |
| + }); |
| + |
| + audit.define( |
| + { |
| + label: 'test setValueCurve', |
| + description: 'Test non-finite arguments for setValueCurveAtTime' |
| + }, |
| + (task, should) => { |
| + let gain = context.createGain(); |
| + |
| + // Just an array for use by setValueCurveAtTime. The length and |
| + // contents of the array are not important. |
| + let curve = new Float32Array(3); |
| + |
| + doTests(should, gain, 'TypeError', nonFiniteValues, [ |
| + { |
| + automationName: 'setValueCurveAtTime', |
| + funcArg: (startTime) => [curve, startTime, 1] |
| + }, |
| + ]); |
| + |
| + // Non-finite values for the curve should signal an error |
| + doTests( |
| + should, gain, 'TypeError', |
| + [[1, 2, Infinity, 3], [1, NaN, 2, 3]], [{ |
| + automationName: 'setValueCurveAtTime', |
| + funcArg: (c) => [c, 1, 1] |
| + }]); |
| + |
| + task.done(); |
| + }); |
| + |
| + audit.define( |
| + { |
| + label: 'special cases 1', |
| + description: 'Test exceptions for finite values' |
| + }, |
| + (task, should) => { |
| + let gain = context.createGain(); |
| + |
| + // Default method for generating the arguments for an automation |
| + // method for testing the time parameter of the automation. |
| + let defaultFuncArg = (startTime) => [1, startTime]; |
| + |
| + // Test the time parameter |
| + let curve = new Float32Array(3); |
| + doTests(should, gain, 'RangeError', [-1], [ |
| + {automationName: 'setValueAtTime', funcArg: defaultFuncArg}, |
| + {automationName: 'linearRampToValueAtTime', funcArg: defaultFuncArg}, |
| + {automationName: 'exponentialRampToValueAtTime', funcArg: defaultFuncArg}, |
| + { |
| + automationName: 'setTargetAtTime', |
| + funcArg: (startTime) => [1, startTime, 1] |
| + }, |
| + // Test time constant |
| + { |
| + automationName: 'setTargetAtTime', |
| + funcArg: (timeConstant) => [1, 1, timeConstant] |
| + }, |
| + // startTime and duration for setValueCurve |
| + { |
| + automationName: 'setValueCurveAtTime', |
| + funcArg: (startTime) => [curve, startTime, 1] |
| + }, |
| + { |
| + automationName: 'setValueCurveAtTime', |
| + funcArg: (duration) => [curve, 1, duration] |
| + }, |
| + ]); |
| + |
| + // One final test for setValueCurve: duration can't be 0. |
| + should( |
| + () => gain.gain.setValueCurveAtTime(curve, 1, 0), |
| + 'gain.gain.setValueCurveAtTime(curve, 1, 0)') |
| + .throw('RangeError'); |
| + |
| + task.done(); |
| + }); |
| + |
| + audit.define( |
| + { |
| + label: 'special cases 2', |
| + description: 'Test special cases for expeonentialRamp' |
| + }, |
| + (task, should) => { |
| + let gain = context.createGain(); |
| + |
| + doTests(should, gain, 'RangeError', [0, -1e-100, 1e-100], [{ |
| + automationName: 'exponentialRampToValueAtTime', |
| + funcArg: (value) => [value, 1] |
| + }]); |
| + |
| task.done(); |
| }); |
| audit.run(); |
| + |
| + function doTests(should, node, errorName, testValues, testMethods) { |
| + // Run test over the set of values in |testValues| for all of the |
| + // automation methods in |testMethods|. The expected error type is |
| + // |errorName|. |testMethods| is an array of dictionaries with |
| + // attributes |automationName| giving the name of the automation method |
| + // to be tested and |funcArg| being a function of one parameter that |
| + // produces an array that will be used as the argument to the automation |
| + // 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.
|
| + testValues.forEach(value => { |
| + testMethods.forEach(method => { |
| + let args = method.funcArg(value); |
| + let message = 'gain.gain.' + method.automationName + '(' + |
| + argString(args) + ')'; |
| + should(() => node.gain[method.automationName](...args), message) |
| + .throw(errorName); |
| + }); |
| + }); |
| + } |
| + |
| + function argString(arg) { |
| + // 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.
|
| + // sense. We assume the first element is either a number or an array. |
| + // If it's an array, there are always three elements, and we want to |
| + // print out the brackets for the array argument. |
| + if (typeof(arg[0]) === 'number') { |
| + return arg.toString(); |
| + } |
| + |
| + return '[' + arg[0] + '],' + arg[1] + ',' + arg[2]; |
| + } |
| + |
| </script> |
| </body> |
| </html> |