| OLD | NEW |
| 1 <!doctype html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title> |
| 5 Test AudioParam Nominal Range Values |
| 6 </title> |
| 4 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
| 8 <title>Test AudioParam Nominal Range Values</title> | |
| 9 </head> | 11 </head> |
| 10 | |
| 11 <body> | 12 <body> |
| 12 <script> | 13 <script id="layout-test-code"> |
| 13 | 14 // Some arbitrary sample rate for the offline context. |
| 14 // Some arbitrary sample rate for the offline context. | 15 let sampleRate = 48000; |
| 15 var sampleRate = 48000; | |
| 16 | 16 |
| 17 // The actual offline context | 17 // The actual offline context |
| 18 var context; | 18 let context; |
| 19 | 19 |
| 20 // The set of all methods that we've tested for verifying that we tested a
ll of the necessary | 20 // The set of all methods that we've tested for verifying that we tested |
| 21 // objects. | 21 // all of the necessary objects. |
| 22 var testedMethods = new Set(); | 22 let testedMethods = new Set(); |
| 23 | 23 |
| 24 // The most positive single float value (the value just before infinity).
Be careful when | 24 // The most positive single float value (the value just before infinity). |
| 25 // changing this value! Javascript only uses double floats, so the value
here should be the | 25 // Be careful when changing this value! Javascript only uses double |
| 26 // max single-float value, converted directly to a double-float value. Th
is also depends on | 26 // floats, so the value here should be the max single-float value, |
| 27 // Javascript reading this value and producing the desired double-float va
lue correctly. | 27 // converted directly to a double-float value. This also depends on |
| 28 var mostPositiveFloat = 3.4028234663852886e38; | 28 // Javascript reading this value and producing the desired double-float |
| 29 | 29 // value correctly. |
| 30 var audit = Audit.createTaskRunner(); | 30 let mostPositiveFloat = 3.4028234663852886e38; |
| 31 |
| 32 let audit = Audit.createTaskRunner(); |
| 31 | 33 |
| 32 // Array describing the tests that should be run. | 34 // Array describing the tests that should be run. |
| 33 var testConfigs = [{ | 35 let testConfigs = [ |
| 34 // The name of the method to create the particular node to be tested. | 36 { |
| 35 creator: "createGain", | 37 // The name of the method to create the particular node to be tested. |
| 36 | 38 creator: 'createGain', |
| 37 // Any args to pass to the creator function. | 39 |
| 38 args: [], | 40 // Any args to pass to the creator function. |
| 39 | 41 args: [], |
| 40 // The min/max limits for each AudioParam of the node. This is a dictio
nary whose keys are | 42 |
| 41 // the names of each AudioParam in the node. Don't define this if the n
ode doesn't have any | 43 // The min/max limits for each AudioParam of the node. This is a |
| 42 // AudioParam attributes. | 44 // dictionary whose keys are |
| 43 limits: { | 45 // the names of each AudioParam in the node. Don't define this if the |
| 44 gain: { | 46 // node doesn't have any |
| 45 // The expected min and max values for this AudioParam. | 47 // AudioParam attributes. |
| 46 minValue: -mostPositiveFloat, | 48 limits: { |
| 47 maxValue: mostPositiveFloat | 49 gain: { |
| 48 } | 50 // The expected min and max values for this AudioParam. |
| 49 } | 51 minValue: -mostPositiveFloat, |
| 50 }, { | 52 maxValue: mostPositiveFloat |
| 51 creator: "createDelay", | 53 } |
| 52 // Just specify a non-default value for the maximum delay so we can make
sure the limits are | 54 } |
| 53 // set correctly. | 55 }, |
| 54 args: [1.5], | 56 { |
| 55 limits: { | 57 creator: 'createDelay', |
| 56 delayTime: { | 58 // Just specify a non-default value for the maximum delay so we can |
| 57 minValue: 0, | 59 // make sure the limits are |
| 58 maxValue: 1.5 | 60 // set correctly. |
| 59 } | 61 args: [1.5], |
| 60 } | 62 limits: {delayTime: {minValue: 0, maxValue: 1.5}} |
| 61 }, { | 63 }, |
| 62 creator: "createBufferSource", | 64 { |
| 63 args: [], | 65 creator: 'createBufferSource', |
| 64 limits: { | 66 args: [], |
| 65 playbackRate: { | 67 limits: { |
| 66 minValue: -mostPositiveFloat, | 68 playbackRate: |
| 67 maxValue: mostPositiveFloat | 69 {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat}, |
| 70 detune: |
| 71 {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat} |
| 72 } |
| 73 }, |
| 74 { |
| 75 creator: 'createStereoPanner', |
| 76 args: [], |
| 77 limits: {pan: {minValue: -1, maxValue: 1}} |
| 78 }, |
| 79 { |
| 80 creator: 'createDynamicsCompressor', |
| 81 args: [], |
| 82 // Do not set limits for reduction; it's currently an AudioParam but |
| 83 // should be a float. |
| 84 // So let the test fail for reduction. When reduction is changed, |
| 85 // this test will then |
| 86 // correctly pass. |
| 87 limits: { |
| 88 threshold: {minValue: -100, maxValue: 0}, |
| 89 knee: {minValue: 0, maxValue: 40}, |
| 90 ratio: {minValue: 1, maxValue: 20}, |
| 91 attack: {minValue: 0, maxValue: 1}, |
| 92 release: {minValue: 0, maxValue: 1} |
| 93 } |
| 94 }, |
| 95 { |
| 96 creator: 'createBiquadFilter', |
| 97 args: [], |
| 98 limits: { |
| 99 gain: {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat}, |
| 100 Q: {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat}, |
| 101 frequency: {minValue: 0, maxValue: sampleRate / 2}, |
| 102 detune: |
| 103 {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat} |
| 104 } |
| 105 }, |
| 106 { |
| 107 creator: 'createOscillator', |
| 108 args: [], |
| 109 limits: { |
| 110 frequency: {minValue: -sampleRate / 2, maxValue: sampleRate / 2}, |
| 111 detune: |
| 112 {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat} |
| 113 } |
| 114 }, |
| 115 { |
| 116 creator: 'createPanner', |
| 117 args: [], |
| 118 limits: { |
| 119 positionX: { |
| 120 minValue: -mostPositiveFloat, |
| 121 maxValue: mostPositiveFloat, |
| 122 }, |
| 123 positionY: { |
| 124 minValue: -mostPositiveFloat, |
| 125 maxValue: mostPositiveFloat, |
| 126 }, |
| 127 positionZ: { |
| 128 minValue: -mostPositiveFloat, |
| 129 maxValue: mostPositiveFloat, |
| 130 }, |
| 131 orientationX: { |
| 132 minValue: -mostPositiveFloat, |
| 133 maxValue: mostPositiveFloat, |
| 134 }, |
| 135 orientationY: { |
| 136 minValue: -mostPositiveFloat, |
| 137 maxValue: mostPositiveFloat, |
| 138 }, |
| 139 orientationZ: { |
| 140 minValue: -mostPositiveFloat, |
| 141 maxValue: mostPositiveFloat, |
| 142 } |
| 68 }, | 143 }, |
| 69 detune: { | 144 }, |
| 70 minValue: -mostPositiveFloat, | 145 { |
| 71 maxValue: mostPositiveFloat | 146 creator: 'createConstantSource', |
| 72 } | 147 args: [], |
| 73 } | 148 limits: { |
| 74 }, { | 149 offset: |
| 75 creator: "createStereoPanner", | 150 {minValue: -mostPositiveFloat, maxValue: mostPositiveFloat} |
| 76 args: [], | 151 } |
| 77 limits: { | 152 }, |
| 78 pan: { | 153 // These nodes don't have AudioParams, but we want to test them anyway. |
| 79 minValue: -1, | 154 // Any arguments for the |
| 80 maxValue: 1 | 155 // constructor are pretty much arbitrary; they just need to be valid. |
| 81 } | 156 { |
| 82 } | 157 creator: 'createBuffer', |
| 83 }, { | 158 args: [1, 1, sampleRate], |
| 84 creator: "createDynamicsCompressor", | 159 }, |
| 85 args: [], | 160 {creator: 'createIIRFilter', args: [[1, 2], [1, .9]]}, |
| 86 // Do not set limits for reduction; it's currently an AudioParam but sh
ould be a float. | 161 { |
| 87 // So let the test fail for reduction. When reduction is changed, this
test will then | 162 creator: 'createWaveShaper', |
| 88 // correctly pass. | 163 args: [], |
| 89 limits: { | 164 }, |
| 90 threshold: { | 165 { |
| 91 minValue: -100, | 166 creator: 'createConvolver', |
| 92 maxValue: 0 | 167 args: [], |
| 93 }, | 168 }, |
| 94 knee: { | 169 { |
| 95 minValue: 0, | 170 creator: 'createAnalyser', |
| 96 maxValue: 40 | 171 args: [], |
| 97 }, | 172 }, |
| 98 ratio: { | 173 { |
| 99 minValue: 1, | 174 creator: 'createScriptProcessor', |
| 100 maxValue: 20 | 175 args: [0], |
| 101 }, | 176 }, |
| 102 attack: { | 177 { |
| 103 minValue: 0, | 178 creator: 'createPeriodicWave', |
| 104 maxValue: 1 | 179 args: [Float32Array.from([0, 0]), Float32Array.from([1, 0])], |
| 105 }, | 180 }, |
| 106 release: { | 181 { |
| 107 minValue: 0, | 182 creator: 'createChannelSplitter', |
| 108 maxValue: 1 | 183 args: [], |
| 109 } | 184 }, |
| 110 } | 185 { |
| 111 }, | 186 creator: 'createChannelMerger', |
| 112 { | 187 args: [], |
| 113 creator: "createBiquadFilter", | 188 }, |
| 114 args: [], | 189 {creator: 'createMediaElementSource', args: [new Audio()]}, |
| 115 limits: { | 190 {creator: 'createMediaStreamDestination', args: []} |
| 116 gain: { | 191 // Can't currently test MediaStreamSource because we're using an offline |
| 117 minValue: -mostPositiveFloat, | 192 // context. |
| 118 maxValue: mostPositiveFloat | 193 ]; |
| 119 }, | 194 |
| 120 Q: { | 195 // Create the context so we can use it in the following test. |
| 121 minValue: -mostPositiveFloat, | 196 audit.define('initialize', (task, should) => { |
| 122 maxValue: mostPositiveFloat | 197 // Just any context so that we can create the nodes. |
| 123 }, | 198 should(() => { |
| 124 frequency: { | 199 context = new OfflineAudioContext(1, 1, sampleRate); |
| 125 minValue: 0, | 200 }, 'Create context for tests').notThrow(); |
| 126 maxValue: sampleRate / 2 | 201 task.done(); |
| 127 }, | 202 }); |
| 128 detune: { | 203 |
| 129 minValue: -mostPositiveFloat, | 204 // Create a task for each entry in testConfigs |
| 130 maxValue: mostPositiveFloat | 205 for (let test in testConfigs) { |
| 131 } | 206 let config = testConfigs[test] |
| 132 } | 207 audit.define(config.creator, (function(c) { |
| 133 }, { | 208 return (task, should) => { |
| 134 creator: "createOscillator", | 209 let node = context[c.creator](...c.args); |
| 135 args: [], | 210 testLimits(should, c.creator, node, c.limits); |
| 136 limits: { | 211 task.done(); |
| 137 frequency: { | 212 }; |
| 138 minValue: -sampleRate / 2, | 213 })(config)); |
| 139 maxValue: sampleRate / 2 | 214 } |
| 140 }, | 215 |
| 141 detune: { | 216 // Test the AudioListener params that were added for the automated Panner |
| 142 minValue: -mostPositiveFloat, | 217 audit.define('AudioListener', (task, should) => { |
| 143 maxValue: mostPositiveFloat | 218 testLimits(should, '', context.listener, { |
| 144 } | |
| 145 } | |
| 146 }, { | |
| 147 creator: "createPanner", | |
| 148 args: [], | |
| 149 limits : { | |
| 150 positionX: { | 219 positionX: { |
| 151 minValue: -mostPositiveFloat, | 220 minValue: -mostPositiveFloat, |
| 152 maxValue: mostPositiveFloat, | 221 maxValue: mostPositiveFloat, |
| 153 }, | |
| 154 positionY: { | |
| 155 minValue: -mostPositiveFloat, | |
| 156 maxValue: mostPositiveFloat, | |
| 157 }, | |
| 158 positionZ: { | |
| 159 minValue: -mostPositiveFloat, | |
| 160 maxValue: mostPositiveFloat, | |
| 161 }, | |
| 162 orientationX: { | |
| 163 minValue: -mostPositiveFloat, | |
| 164 maxValue: mostPositiveFloat, | |
| 165 }, | |
| 166 orientationY: { | |
| 167 minValue: -mostPositiveFloat, | |
| 168 maxValue: mostPositiveFloat, | |
| 169 }, | |
| 170 orientationZ: { | |
| 171 minValue: -mostPositiveFloat, | |
| 172 maxValue: mostPositiveFloat, | |
| 173 } | |
| 174 }, | |
| 175 }, { | |
| 176 creator: "createConstantSource", | |
| 177 args: [], | |
| 178 limits: { | |
| 179 offset: { | |
| 180 minValue: -mostPositiveFloat, | |
| 181 maxValue: mostPositiveFloat | |
| 182 } | |
| 183 } | |
| 184 }, | |
| 185 // These nodes don't have AudioParams, but we want to test them anyway. A
ny arguments for the | |
| 186 // constructor are pretty much arbitrary; they just need to be valid. | |
| 187 { | |
| 188 creator: "createBuffer", | |
| 189 args: [1, 1, sampleRate], | |
| 190 }, { | |
| 191 creator: "createIIRFilter", | |
| 192 args: [[1,2],[1, .9]] | |
| 193 }, { | |
| 194 creator: "createWaveShaper", | |
| 195 args: [], | |
| 196 }, { | |
| 197 creator: "createConvolver", | |
| 198 args: [], | |
| 199 }, { | |
| 200 creator: "createAnalyser", | |
| 201 args: [], | |
| 202 }, { | |
| 203 creator: "createScriptProcessor", | |
| 204 args: [0], | |
| 205 }, { | |
| 206 creator: "createPeriodicWave", | |
| 207 args: [Float32Array.from([0, 0]), Float32Array.from([1, 0])], | |
| 208 }, { | |
| 209 creator: "createChannelSplitter", | |
| 210 args: [], | |
| 211 }, { | |
| 212 creator: "createChannelMerger", | |
| 213 args: [], | |
| 214 }, { | |
| 215 creator: "createMediaElementSource", | |
| 216 args: [new Audio()] | |
| 217 },{ | |
| 218 creator: "createMediaStreamDestination", | |
| 219 args: [] | |
| 220 } | |
| 221 // Can't currently test MediaStreamSource because we're using an offline | |
| 222 // context. | |
| 223 ]; | |
| 224 | |
| 225 // Create the context so we can use it in the following test. | |
| 226 audit.define("initialize", (task, should) => { | |
| 227 // Just any context so that we can create the nodes. | |
| 228 should(() => { | |
| 229 context = new OfflineAudioContext(1, 1, sampleRate); | |
| 230 }, "Create context for tests") | |
| 231 .notThrow(); | |
| 232 task.done(); | |
| 233 }); | |
| 234 | |
| 235 // Create a task for each entry in testConfigs | |
| 236 for (let test in testConfigs) { | |
| 237 var config = testConfigs[test] | |
| 238 audit.define(config.creator, (function (c) { | |
| 239 return (task, should) => { | |
| 240 var node = context[c.creator](...c.args); | |
| 241 testLimits(should, c.creator, node, c.limits); | |
| 242 task.done(); | |
| 243 }; | |
| 244 })(config)); | |
| 245 } | |
| 246 | |
| 247 // Test the AudioListener params that were added for the automated Panner | |
| 248 audit.define("AudioListener", (task, should) => { | |
| 249 testLimits(should, "", context.listener, { | |
| 250 positionX: { | |
| 251 minValue: -mostPositiveFloat, | |
| 252 maxValue: mostPositiveFloat, | |
| 253 }, | 222 }, |
| 254 positionY: { | 223 positionY: { |
| 255 minValue: -mostPositiveFloat, | 224 minValue: -mostPositiveFloat, |
| 256 maxValue: mostPositiveFloat, | 225 maxValue: mostPositiveFloat, |
| 257 }, | 226 }, |
| 258 positionZ: { | 227 positionZ: { |
| 259 minValue: -mostPositiveFloat, | 228 minValue: -mostPositiveFloat, |
| 260 maxValue: mostPositiveFloat, | 229 maxValue: mostPositiveFloat, |
| 261 }, | 230 }, |
| 262 forwardX: { | 231 forwardX: { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 280 maxValue: mostPositiveFloat, | 249 maxValue: mostPositiveFloat, |
| 281 }, | 250 }, |
| 282 upZ: { | 251 upZ: { |
| 283 minValue: -mostPositiveFloat, | 252 minValue: -mostPositiveFloat, |
| 284 maxValue: mostPositiveFloat, | 253 maxValue: mostPositiveFloat, |
| 285 } | 254 } |
| 286 }); | 255 }); |
| 287 task.done(); | 256 task.done(); |
| 288 }); | 257 }); |
| 289 | 258 |
| 290 // Verify that we have tested all the create methods available on the cont
ext. | 259 // Verify that we have tested all the create methods available on the |
| 291 audit.define("verifyTests", (task, should) => { | 260 // context. |
| 292 var allNodes = new Set(); | 261 audit.define('verifyTests', (task, should) => { |
| 262 let allNodes = new Set(); |
| 293 // Create the set of all "create" methods from the context. | 263 // Create the set of all "create" methods from the context. |
| 294 for (var method in context) { | 264 for (let method in context) { |
| 295 if (typeof context[method] === "function" && method.substring(0, 6) ==
= "create") { | 265 if (typeof context[method] === 'function' && |
| 266 method.substring(0, 6) === 'create') { |
| 296 allNodes.add(method); | 267 allNodes.add(method); |
| 297 } | 268 } |
| 298 } | 269 } |
| 299 | 270 |
| 300 // Compute the difference between the set of all create methods on the c
ontext and the set | 271 // Compute the difference between the set of all create methods on the |
| 301 // of tests that we've run. | 272 // context and the set of tests that we've run. |
| 302 var diff = new Set([...allNodes].filter(x => !testedMethods.has(x))); | 273 let diff = new Set([...allNodes].filter(x => !testedMethods.has(x))); |
| 303 | 274 |
| 304 // Can't currently test a MediaStreamSourceNode, so remove it from the d
iff set. | 275 // Can't currently test a MediaStreamSourceNode, so remove it from the |
| 305 diff.delete("createMediaStreamSource"); | 276 // diff set. |
| 277 diff.delete('createMediaStreamSource'); |
| 306 | 278 |
| 307 // It's a test failure if we didn't test all of the create methods in th
e context (except | 279 // It's a test failure if we didn't test all of the create methods in |
| 308 // createMediaStreamSource, of course). | 280 // the context (except createMediaStreamSource, of course). |
| 309 var output = []; | 281 let output = []; |
| 310 if (diff.size) { | 282 if (diff.size) { |
| 311 for (let item of diff) | 283 for (let item of diff) |
| 312 output.push(" " + item.substring(6)); | 284 output.push(' ' + item.substring(6)); |
| 313 } | 285 } |
| 314 | 286 |
| 315 should(output.length === 0, "Number of nodes not tested") | 287 should(output.length === 0, 'Number of nodes not tested') |
| 316 .message(": 0", | 288 .message(': 0', ': ' + output); |
| 317 ": " + output); | 289 |
| 318 | |
| 319 task.done(); | 290 task.done(); |
| 320 }); | 291 }); |
| 321 | 292 |
| 322 // Simple test of a few automation methods to verify we get warnings. | 293 // Simple test of a few automation methods to verify we get warnings. |
| 323 audit.define("automation", (task, should) => { | 294 audit.define('automation', (task, should) => { |
| 324 // Just use a DelayNode for testing because the audio param has finite l
imits. | 295 // Just use a DelayNode for testing because the audio param has finite |
| 296 // limits. |
| 325 should(() => { | 297 should(() => { |
| 326 var d = context.createDelay(); | 298 let d = context.createDelay(); |
| 327 | 299 |
| 328 // The console output should have the warnings that we're interested in. | 300 // The console output should have the warnings that we're interested |
| 329 d.delayTime.setValueAtTime(-1, 0); | 301 // in. |
| 330 d.delayTime.linearRampToValueAtTime(2, 1); | 302 d.delayTime.setValueAtTime(-1, 0); |
| 331 d.delayTime.exponentialRampToValueAtTime(3, 2); | 303 d.delayTime.linearRampToValueAtTime(2, 1); |
| 332 d.delayTime.setTargetAtTime(-1, 3, .1); | 304 d.delayTime.exponentialRampToValueAtTime(3, 2); |
| 333 d.delayTime.setValueCurveAtTime(Float32Array.from([.1, .2, 1.5, -1]), 4,
.1); | 305 d.delayTime.setTargetAtTime(-1, 3, .1); |
| 334 }, "Test automations (check console logs)") | 306 d.delayTime.setValueCurveAtTime( |
| 335 .notThrow(); | 307 Float32Array.from([.1, .2, 1.5, -1]), 4, .1); |
| 308 }, 'Test automations (check console logs)').notThrow(); |
| 336 task.done(); | 309 task.done(); |
| 337 }); | 310 }); |
| 338 | 311 |
| 339 audit.run(); | 312 audit.run(); |
| 340 | 313 |
| 341 // Is |object| an AudioParam? We determine this by checking the construct
or name. | 314 // Is |object| an AudioParam? We determine this by checking the |
| 315 // constructor name. |
| 342 function isAudioParam(object) { | 316 function isAudioParam(object) { |
| 343 return object && object.constructor.name === "AudioParam"; | 317 return object && object.constructor.name === 'AudioParam'; |
| 344 } | 318 } |
| 345 | 319 |
| 346 // Does |limitOptions| exist and does it have valid values for the expecte
d min and max | 320 // Does |limitOptions| exist and does it have valid values for the |
| 347 // values? | 321 // expected min and max values? |
| 348 function hasValidLimits(limitOptions) { | 322 function hasValidLimits(limitOptions) { |
| 349 return limitOptions && (typeof limitOptions.minValue === "number") && (t
ypeof limitOptions.maxValue === "number"); | 323 return limitOptions && (typeof limitOptions.minValue === 'number') && |
| 324 (typeof limitOptions.maxValue === 'number'); |
| 350 } | 325 } |
| 351 | 326 |
| 352 // Check the min and max values for the AudioParam attribute named |paramN
ame| for the |node|. | 327 // Check the min and max values for the AudioParam attribute named |
| 353 // The expected limits is given by the dictionary |limits|. If some test
fails, add the name | 328 // |paramName| for the |node|. The expected limits is given by the |
| 354 // of the failed | 329 // dictionary |limits|. If some test fails, add the name of the failed |
| 355 function validateAudioParamLimits(should, node, paramName, limits) { | 330 function validateAudioParamLimits(should, node, paramName, limits) { |
| 356 var nodeName = node.constructor.name; | 331 let nodeName = node.constructor.name; |
| 357 var parameter = node[paramName]; | 332 let parameter = node[paramName]; |
| 358 var prefix = nodeName + "." + paramName; | 333 let prefix = nodeName + '.' + paramName; |
| 359 | 334 |
| 360 var success = true; | 335 let success = true; |
| 361 if (hasValidLimits(limits[paramName])) { | 336 if (hasValidLimits(limits[paramName])) { |
| 362 // Verify that the min and max values for the parameter are correct. | 337 // Verify that the min and max values for the parameter are correct. |
| 363 var isCorrect = should(parameter.minValue, prefix + ".minValue") | 338 let isCorrect = should(parameter.minValue, prefix + '.minValue') |
| 364 .beEqualTo(limits[paramName].minValue); | 339 .beEqualTo(limits[paramName].minValue); |
| 365 isCorrect = should(parameter.maxValue, prefix + ".maxValue") | 340 isCorrect = should(parameter.maxValue, prefix + '.maxValue') |
| 366 .beEqualTo(limits[paramName].maxValue) && isCorrect; | 341 .beEqualTo(limits[paramName].maxValue) && |
| 342 isCorrect; |
| 367 | 343 |
| 368 // Verify that the min and max attributes are read-only | 344 // Verify that the min and max attributes are read-only |
| 369 parameter.minValue = Math.PI; | 345 parameter.minValue = Math.PI; |
| 370 var isReadOnly; | 346 let isReadOnly; |
| 371 isReadOnly = should(parameter.minValue, prefix + ".minValue = Math.PI"
) | 347 isReadOnly = |
| 372 .notBeEqualTo(Math.PI); | 348 should(parameter.minValue, prefix + '.minValue = Math.PI') |
| 349 .notBeEqualTo(Math.PI); |
| 373 | 350 |
| 374 should(isReadOnly, prefix + ".minValue is read-only") | 351 should(isReadOnly, prefix + '.minValue is read-only').beEqualTo(true); |
| 375 .beEqualTo(true); | |
| 376 | 352 |
| 377 isCorrect = isReadOnly && isCorrect; | 353 isCorrect = isReadOnly && isCorrect; |
| 378 | 354 |
| 379 parameter.maxValue = Math.PI; | 355 parameter.maxValue = Math.PI; |
| 380 isReadOnly = should(parameter.maxValue, | 356 isReadOnly = |
| 381 prefix + ".maxValue = Math.PI") | 357 should(parameter.maxValue, prefix + '.maxValue = Math.PI') |
| 382 .notBeEqualTo(Math.PI); | 358 .notBeEqualTo(Math.PI); |
| 383 should(isReadOnly, prefix + ".maxValue is read-only") | 359 should(isReadOnly, prefix + '.maxValue is read-only').beEqualTo(true); |
| 384 .beEqualTo(true); | |
| 385 | 360 |
| 386 isCorrect = isReadOnly && isCorrect; | 361 isCorrect = isReadOnly && isCorrect; |
| 387 | 362 |
| 388 // Now try to set the parameter outside the nominal range. | 363 // Now try to set the parameter outside the nominal range. |
| 389 var newValue = 2 * limits[paramName].minValue - 1; | 364 let newValue = 2 * limits[paramName].minValue - 1; |
| 390 | 365 |
| 391 var isClipped = true; | 366 let isClipped = true; |
| 392 var clippingTested = false; | 367 let clippingTested = false; |
| 393 // If the new value is beyond float the largest single-precision float
, skip the test | 368 // If the new value is beyond float the largest single-precision |
| 394 // because Chrome throws an error. | 369 // float, skip the test because Chrome throws an error. |
| 395 if (newValue >= -mostPositiveFloat) { | 370 if (newValue >= -mostPositiveFloat) { |
| 396 parameter.value = newValue; | 371 parameter.value = newValue; |
| 397 clippingTested = true; | 372 clippingTested = true; |
| 398 isClipped = should(parameter.value, | 373 isClipped = |
| 399 "Set " + prefix + ".value = " + newValue) | 374 should( |
| 400 .beEqualTo(parameter.minValue) && isClipped; | 375 parameter.value, 'Set ' + prefix + '.value = ' + newValue) |
| 376 .beEqualTo(parameter.minValue) && |
| 377 isClipped; |
| 401 } | 378 } |
| 402 | 379 |
| 403 newValue = 2 * limits[paramName].maxValue + 1; | 380 newValue = 2 * limits[paramName].maxValue + 1; |
| 404 | 381 |
| 405 if (newValue <= mostPositiveFloat) { | 382 if (newValue <= mostPositiveFloat) { |
| 406 parameter.value = newValue; | 383 parameter.value = newValue; |
| 407 clippingTested = true; | 384 clippingTested = true; |
| 408 isClipped = should(parameter.value, | 385 isClipped = |
| 409 "Set " + prefix + ".value = " + newValue) | 386 should( |
| 410 .beEqualTo(parameter.maxValue) && isClipped; | 387 parameter.value, 'Set ' + prefix + '.value = ' + newValue) |
| 388 .beEqualTo(parameter.maxValue) && |
| 389 isClipped; |
| 411 } | 390 } |
| 412 | 391 |
| 413 if (clippingTested) { | 392 if (clippingTested) { |
| 414 should(isClipped, | 393 should( |
| 415 prefix + "was clipped to lie within the nominal range") | 394 isClipped, |
| 416 .beEqualTo(true); | 395 prefix + 'was clipped to lie within the nominal range') |
| 396 .beEqualTo(true); |
| 417 } | 397 } |
| 418 | 398 |
| 419 isCorrect = isCorrect && isClipped; | 399 isCorrect = isCorrect && isClipped; |
| 420 | 400 |
| 421 success = isCorrect && success; | 401 success = isCorrect && success; |
| 422 } else { | 402 } else { |
| 423 // Test config didn't specify valid limits. Fail this test! | 403 // Test config didn't specify valid limits. Fail this test! |
| 424 should(clippingTested, | 404 should( |
| 425 "Limits for " + nodeName + "." + paramName + | 405 clippingTested, |
| 426 " were correctly defined") | 406 'Limits for ' + nodeName + '.' + paramName + |
| 427 .beEqualTo(false); | 407 ' were correctly defined') |
| 428 | 408 .beEqualTo(false); |
| 409 |
| 429 success = false; | 410 success = false; |
| 430 } | 411 } |
| 431 | 412 |
| 432 return success; | 413 return success; |
| 433 } | 414 } |
| 434 | 415 |
| 435 // Test all of the AudioParams for |node| using the expected values in |li
mits|. | 416 // Test all of the AudioParams for |node| using the expected values in |
| 436 // |creatorName| is the name of the method to create the node, and is used
to keep trakc of | 417 // |limits|. |creatorName| is the name of the method to create the node, |
| 437 // which tests we've run. | 418 // and is used to keep trakc of which tests we've run. |
| 438 function testLimits(should, creatorName, node, limits) { | 419 function testLimits(should, creatorName, node, limits) { |
| 439 var nodeName = node.constructor.name; | 420 let nodeName = node.constructor.name; |
| 440 testedMethods.add(creatorName); | 421 testedMethods.add(creatorName); |
| 441 | 422 |
| 442 var success = true; | 423 let success = true; |
| 443 | 424 |
| 444 // List of all of the AudioParams that were tested. | 425 // List of all of the AudioParams that were tested. |
| 445 var audioParams = []; | 426 let audioParams = []; |
| 446 | 427 |
| 447 // List of AudioParams that failed the test. | 428 // List of AudioParams that failed the test. |
| 448 var incorrectParams = []; | 429 let incorrectParams = []; |
| 449 | 430 |
| 450 // Look through all of the keys for the node and extract just the AudioP
arams | 431 // Look through all of the keys for the node and extract just the |
| 451 Object.keys(node.__proto__).forEach(function (paramName) { | 432 // AudioParams |
| 433 Object.keys(node.__proto__).forEach(function(paramName) { |
| 452 if (isAudioParam(node[paramName])) { | 434 if (isAudioParam(node[paramName])) { |
| 453 audioParams.push(paramName); | 435 audioParams.push(paramName); |
| 454 var isValid = validateAudioParamLimits(should, node, paramName, | 436 let isValid = validateAudioParamLimits( |
| 455 limits, incorrectParams); | 437 should, node, paramName, limits, incorrectParams); |
| 456 if (!isValid) | 438 if (!isValid) |
| 457 incorrectParams.push(paramName); | 439 incorrectParams.push(paramName); |
| 458 | 440 |
| 459 success = isValid && success; | 441 success = isValid && success; |
| 460 } | 442 } |
| 461 }); | 443 }); |
| 462 | 444 |
| 463 // Print an appropriate message depending on whether there were AudioPar
ams defined or not. | 445 // Print an appropriate message depending on whether there were |
| 446 // AudioParams defined or not. |
| 464 if (audioParams.length) { | 447 if (audioParams.length) { |
| 465 var message = "Nominal ranges for AudioParam(s) of " + node.constructo
r.name; | 448 let message = |
| 449 'Nominal ranges for AudioParam(s) of ' + node.constructor.name; |
| 466 should(success, message) | 450 should(success, message) |
| 467 .message("are correct", | 451 .message('are correct', 'are incorrect for: ' + +incorrectParams); |
| 468 "are incorrect for: " + + incorrectParams); | |
| 469 return success; | 452 return success; |
| 470 } else { | 453 } else { |
| 471 should(!limits, nodeName) | 454 should(!limits, nodeName) |
| 472 .message("has no AudioParams as expected", | 455 .message( |
| 473 "has no AudioParams but test expected " + limits); | 456 'has no AudioParams as expected', |
| 457 'has no AudioParams but test expected ' + limits); |
| 474 } | 458 } |
| 475 } | 459 } |
| 476 </script> | 460 </script> |
| 477 </body> | 461 </body> |
| 478 </html> | 462 </html> |
| OLD | NEW |