| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 6 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audio-testing.js"></script> |
| 7 <title>Test AudioParam Nominal Range Values</title> | 8 <title>Test AudioParam Nominal Range Values</title> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <script> | 12 <script> |
| 12 description("Test AudioParam Nominal Range Values."); | |
| 13 window.jsTestIsAsync = true; | |
| 14 | 13 |
| 15 // Some arbitrary sample rate for the offline context. | 14 // Some arbitrary sample rate for the offline context. |
| 16 var sampleRate = 48000; | 15 var sampleRate = 48000; |
| 17 | 16 |
| 18 // The actual offline context | 17 // The actual offline context |
| 19 var context; | 18 var context; |
| 20 | 19 |
| 21 // 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 a
ll of the necessary |
| 22 // objects. | 21 // objects. |
| 23 var testedMethods = new Set(); | 22 var testedMethods = new Set(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 ]; | 223 ]; |
| 225 | 224 |
| 226 // Create the context so we can use it in the following test. | 225 // Create the context so we can use it in the following test. |
| 227 audit.defineTask("initialize", function (done) { | 226 audit.defineTask("initialize", function (done) { |
| 228 // Just any context so that we can create the nodes. | 227 // Just any context so that we can create the nodes. |
| 229 context = new OfflineAudioContext(1, 1, sampleRate); | 228 context = new OfflineAudioContext(1, 1, sampleRate); |
| 230 done(); | 229 done(); |
| 231 }); | 230 }); |
| 232 | 231 |
| 233 // Create a task for each entry in testConfigs | 232 // Create a task for each entry in testConfigs |
| 234 for (var test in testConfigs) { | 233 for (let test in testConfigs) { |
| 235 var config = testConfigs[test] | 234 var config = testConfigs[test] |
| 236 audit.defineTask(config.creator, (function (c) { | 235 audit.defineTask(config.creator, (function (c) { |
| 237 return function (done) { | 236 return function (done) { |
| 238 var node = context[c.creator](...c.args); | 237 var node = context[c.creator](...c.args); |
| 239 testLimits(c.creator, node, c.limits); | 238 testLimits(c.creator, node, c.limits); |
| 240 done(); | 239 done(); |
| 241 }; | 240 }; |
| 242 })(config)); | 241 })(config)); |
| 243 } | 242 } |
| 244 | 243 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 296 |
| 298 // Compute the difference between the set of all create methods on the c
ontext and the set | 297 // Compute the difference between the set of all create methods on the c
ontext and the set |
| 299 // of tests that we've run. | 298 // of tests that we've run. |
| 300 var diff = new Set([...allNodes].filter(x => !testedMethods.has(x))); | 299 var diff = new Set([...allNodes].filter(x => !testedMethods.has(x))); |
| 301 | 300 |
| 302 // Can't currently test a MediaStreamSourceNode, so remove it from the d
iff set. | 301 // Can't currently test a MediaStreamSourceNode, so remove it from the d
iff set. |
| 303 diff.delete("createMediaStreamSource"); | 302 diff.delete("createMediaStreamSource"); |
| 304 | 303 |
| 305 // It's a test failure if we didn't test all of the create methods in th
e context (except | 304 // It's a test failure if we didn't test all of the create methods in th
e context (except |
| 306 // createMediaStreamSource, of course). | 305 // createMediaStreamSource, of course). |
| 306 var output = []; |
| 307 if (diff.size) { | 307 if (diff.size) { |
| 308 var output = []; | |
| 309 for (let item of diff) | 308 for (let item of diff) |
| 310 output.push(" " + item.substring(6)); | 309 output.push(" " + item.substring(6)); |
| 311 testFailed("These nodes were not tested:" + output + "\n"); | |
| 312 } else { | |
| 313 testPassed("All nodes were tested.\n"); | |
| 314 } | 310 } |
| 311 |
| 312 Should("Number of nodes not tested", output.length === 0) |
| 313 .summarize(": 0", |
| 314 ": " + output); |
| 315 | 315 |
| 316 done(); | 316 done(); |
| 317 }); | 317 }); |
| 318 | 318 |
| 319 // Simple test of a few automation methods to verify we get warnings. | 319 // Simple test of a few automation methods to verify we get warnings. |
| 320 audit.defineTask("automation", function (done) { | 320 audit.defineTask("automation", function (done) { |
| 321 // Just use a DelayNode for testing because the audio param has finite l
imits. | 321 // Just use a DelayNode for testing because the audio param has finite l
imits. |
| 322 var d = context.createDelay(); | 322 var d = context.createDelay(); |
| 323 | 323 |
| 324 // The console output should have the warnings that we're interested in. | 324 // The console output should have the warnings that we're interested in. |
| 325 d.delayTime.setValueAtTime(-1, 0); | 325 d.delayTime.setValueAtTime(-1, 0); |
| 326 d.delayTime.linearRampToValueAtTime(2, 1); | 326 d.delayTime.linearRampToValueAtTime(2, 1); |
| 327 d.delayTime.exponentialRampToValueAtTime(3, 2); | 327 d.delayTime.exponentialRampToValueAtTime(3, 2); |
| 328 d.delayTime.setTargetAtTime(-1, 3, .1); | 328 d.delayTime.setTargetAtTime(-1, 3, .1); |
| 329 d.delayTime.setValueCurveAtTime(Float32Array.from([.1, .2, 1.5, -1]), 4,
.1); | 329 d.delayTime.setValueCurveAtTime(Float32Array.from([.1, .2, 1.5, -1]), 4,
.1); |
| 330 done(); | 330 done(); |
| 331 }); | 331 }); |
| 332 | 332 |
| 333 // All done! | 333 // All done! |
| 334 audit.defineTask("finish", function (done) { | 334 audit.defineTask("finish", function (done) { |
| 335 finishJSTest(); | |
| 336 done(); | 335 done(); |
| 337 }); | 336 }); |
| 338 | 337 |
| 339 audit.runTasks(); | 338 audit.runTasks(); |
| 340 | 339 |
| 341 // Is |object| an AudioParam? We determine this by checking the construct
or name. | 340 // Is |object| an AudioParam? We determine this by checking the construct
or name. |
| 342 function isAudioParam(object) { | 341 function isAudioParam(object) { |
| 343 return object && object.constructor.name === "AudioParam"; | 342 return object && object.constructor.name === "AudioParam"; |
| 344 } | 343 } |
| 345 | 344 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 363 var isCorrect = Should(prefix + ".minValue", parameter.minValue) | 362 var isCorrect = Should(prefix + ".minValue", parameter.minValue) |
| 364 .beEqualTo(limits[paramName].minValue); | 363 .beEqualTo(limits[paramName].minValue); |
| 365 isCorrect = Should(prefix + ".maxValue", parameter.maxValue) | 364 isCorrect = Should(prefix + ".maxValue", parameter.maxValue) |
| 366 .beEqualTo(limits[paramName].maxValue) && isCorrect; | 365 .beEqualTo(limits[paramName].maxValue) && isCorrect; |
| 367 | 366 |
| 368 // Verify that the min and max attributes are read-only | 367 // Verify that the min and max attributes are read-only |
| 369 parameter.minValue = Math.PI; | 368 parameter.minValue = Math.PI; |
| 370 var isReadOnly; | 369 var isReadOnly; |
| 371 isReadOnly = Should(prefix + ".minValue = Math.PI", parameter.minValue
) | 370 isReadOnly = Should(prefix + ".minValue = Math.PI", parameter.minValue
) |
| 372 .notBeEqualTo(Math.PI); | 371 .notBeEqualTo(Math.PI); |
| 373 if (isReadOnly) | 372 |
| 374 testPassed(prefix + ".minValue is read-only."); | 373 Should(prefix + ".minValue is read-only", isReadOnly) |
| 375 else | 374 .beEqualTo(true); |
| 376 testFailed(prefix + ".minValue should be read-only but was changed."
); | 375 |
| 377 isCorrect = isReadOnly && isCorrect; | 376 isCorrect = isReadOnly && isCorrect; |
| 378 | 377 |
| 379 parameter.maxValue = Math.PI; | 378 parameter.maxValue = Math.PI; |
| 380 isReadOnly = Should(prefix + ".maxValue = Math.PI", parameter.maxValue
) | 379 isReadOnly = Should(prefix + ".maxValue = Math.PI", parameter.maxValue
) |
| 381 .notBeEqualTo(Math.PI); | 380 .notBeEqualTo(Math.PI); |
| 382 if (isReadOnly) | 381 Should(prefix + ".maxValue is read-only", isReadOnly) |
| 383 testPassed(prefix + ".maxValue is read-only."); | 382 .beEqualTo(true); |
| 384 else | 383 |
| 385 testFailed(prefix + ".maxValue should be read-only but was changed."
); | |
| 386 isCorrect = isReadOnly && isCorrect; | 384 isCorrect = isReadOnly && isCorrect; |
| 387 | 385 |
| 388 // Now try to set the parameter outside the nominal range. | 386 // Now try to set the parameter outside the nominal range. |
| 389 var newValue = 2 * limits[paramName].minValue - 1; | 387 var newValue = 2 * limits[paramName].minValue - 1; |
| 390 | 388 |
| 391 var isClipped = true; | 389 var isClipped = true; |
| 392 var clippingTested = false; | 390 var clippingTested = false; |
| 393 // If the new value is beyond float the largest single-precision float
, skip the test | 391 // If the new value is beyond float the largest single-precision float
, skip the test |
| 394 // because Chrome throws an error. | 392 // because Chrome throws an error. |
| 395 if (newValue >= -mostPositiveFloat) { | 393 if (newValue >= -mostPositiveFloat) { |
| 396 parameter.value = newValue; | 394 parameter.value = newValue; |
| 397 clippingTested = true; | 395 clippingTested = true; |
| 398 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet
er.value) | 396 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet
er.value) |
| 399 .beEqualTo(parameter.minValue) && isClipped; | 397 .beEqualTo(parameter.minValue) && isClipped; |
| 400 } | 398 } |
| 401 | 399 |
| 402 newValue = 2 * limits[paramName].maxValue + 1; | 400 newValue = 2 * limits[paramName].maxValue + 1; |
| 403 | 401 |
| 404 if (newValue <= mostPositiveFloat) { | 402 if (newValue <= mostPositiveFloat) { |
| 405 parameter.value = newValue; | 403 parameter.value = newValue; |
| 406 clippingTested = true; | 404 clippingTested = true; |
| 407 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet
er.value) | 405 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet
er.value) |
| 408 .beEqualTo(parameter.maxValue) && isClipped; | 406 .beEqualTo(parameter.maxValue) && isClipped; |
| 409 | 407 |
| 410 } | 408 } |
| 411 | 409 |
| 412 if (clippingTested) { | 410 if (clippingTested) { |
| 413 if (isClipped) | 411 Should(prefix + "was clipped to lie within the nominal range", isCli
pped) |
| 414 testPassed(prefix + " was correctly clipped to lie within the nomi
nal range.") | 412 .beEqualTo(true); |
| 415 else | |
| 416 testPassed(prefix + " was not correctly clipped to lie within the
nominal range.") | |
| 417 } | 413 } |
| 418 | 414 |
| 419 isCorrect = isCorrect && isClipped; | 415 isCorrect = isCorrect && isClipped; |
| 420 | 416 |
| 421 success = isCorrect && success; | 417 success = isCorrect && success; |
| 422 } else { | 418 } else { |
| 423 // Test config didn't specify valid limits. Fail this test! | 419 // Test config didn't specify valid limits. Fail this test! |
| 424 testFailed("Limits for " + nodeName + "." + paramName + " were not cor
rectly defined."); | 420 // testFailed("Limits for " + nodeName + "." + paramName + " were not c
orrectly defined."); |
| 421 Should("Limits for " + nodeName + "." + paramName + " were correctly d
efined", clippingTested) |
| 422 .beEqualTo(false); |
| 423 |
| 425 success = false; | 424 success = false; |
| 426 } | 425 } |
| 427 | 426 |
| 428 return success; | 427 return success; |
| 429 } | 428 } |
| 430 | 429 |
| 431 // Test all of the AudioParams for |node| using the expected values in |li
mits|. | 430 // Test all of the AudioParams for |node| using the expected values in |li
mits|. |
| 432 // |creatorName| is the name of the method to create the node, and is used
to keep trakc of | 431 // |creatorName| is the name of the method to create the node, and is used
to keep trakc of |
| 433 // which tests we've run. | 432 // which tests we've run. |
| 434 function testLimits(creatorName, node, limits) { | 433 function testLimits(creatorName, node, limits) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 451 if (!isValid) | 450 if (!isValid) |
| 452 incorrectParams.push(paramName); | 451 incorrectParams.push(paramName); |
| 453 | 452 |
| 454 success = isValid && success; | 453 success = isValid && success; |
| 455 } | 454 } |
| 456 }); | 455 }); |
| 457 | 456 |
| 458 // Print an appropriate message depending on whether there were AudioPar
ams defined or not. | 457 // Print an appropriate message depending on whether there were AudioPar
ams defined or not. |
| 459 if (audioParams.length) { | 458 if (audioParams.length) { |
| 460 var message = "Nominal ranges for AudioParam(s) of " + node.constructo
r.name; | 459 var message = "Nominal ranges for AudioParam(s) of " + node.constructo
r.name; |
| 461 if (success) | 460 Should(message, success) |
| 462 testPassed(message + " are correct.\n"); | 461 .summarize("are correct", |
| 463 else | 462 "are incorrect for: " + + incorrectParams); |
| 464 testFailed(message + " are incorrect for: " + incorrectParams + ".\n
"); | |
| 465 return success; | 463 return success; |
| 466 } else { | 464 } else { |
| 467 if (limits) | 465 Should(nodeName, !limits) |
| 468 testFailed(nodeName + " has no AudioParams but test expected " + lim
its + ".\n"); | 466 .summarize("has no AudioParams as expected", |
| 469 else | 467 "has no AudioParams but test expected " + limits); |
| 470 testPassed(nodeName + " has no AudioParams as expected.\n"); | |
| 471 } | 468 } |
| 472 } | 469 } |
| 473 </script> | 470 </script> |
| 474 </body> | 471 </body> |
| 475 </html> | 472 </html> |
| OLD | NEW |