Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-exceptional-values.html

Issue 2656993002: Throw TypeError instead of InvalidAccessError for invalid times (Closed)
Patch Set: Address review comments and clang-format it Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..01faf80b247cd22acf03427bcb83f25365925e25 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,223 @@
<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 one 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]
}
- }
+ ]);
+ 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();
+
+ // 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.
+ function doTests(should, node, errorName, testValues, testMethods) {
+ 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);
+ });
+ });
+ }
+
+ // Specialized printer for automation arguments so that messages make
+ // 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.
+ function argString(arg) {
+ if (typeof(arg[0]) === 'number') {
+ return arg.toString();
+ }
+
+ return '[' + arg[0] + '],' + arg[1] + ',' + arg[2];
+ }
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698