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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioParam/audioparam-nominal-range.html

Issue 2658703002: Convert AudioParam Audit tests to testharness (Closed)
Patch Set: Restore expected results that have console messages and update Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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
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
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
346 // Does |limitOptions| exist and does it have valid values for the expecte d min and max 345 // Does |limitOptions| exist and does it have valid values for the expecte d min and max
347 // values? 346 // values?
348 function hasValidLimits(limitOptions) { 347 function hasValidLimits(limitOptions) {
349 return limitOptions && (typeof limitOptions.minValue === "number") && (t ypeof limitOptions.maxValue === "number"); 348 return limitOptions && (typeof limitOptions.minValue === "number") && (t ypeof limitOptions.maxValue === "number");
350 } 349 }
351 350
352 // Check the min and max values for the AudioParam attribute named |paramN ame| for the |node|. 351 // Check the min and max values for the AudioParam attribute named |paramN ame| for the |node|.
353 // The expected limits is given by the dictionary |limits|. If some test fails, add the name 352 // The expected limits is given by the dictionary |limits|. If some test fails, add the name
354 // of the failed 353 // of the failed
355 function validateAudioParamLimits(node, paramName, limits) { 354 function validateAudioParamLimits(node, paramName, limits) {
356 var nodeName = node.constructor.name; 355 var nodeName = node.constructor.name;
357 var parameter = node[paramName]; 356 var parameter = node[paramName];
358 var prefix = nodeName + "." + paramName; 357 var prefix = nodeName + "." + paramName;
359 358
360 var success = true; 359 var success = true;
361 if (hasValidLimits(limits[paramName])) { 360 if (hasValidLimits(limits[paramName])) {
362 // Verify that the min and max values for the parameter are correct. 361 // Verify that the min and max values for the parameter are correct.
362
hongchan 2017/01/26 22:44:33 A redundant empty line.
363 var isCorrect = Should(prefix + ".minValue", parameter.minValue) 363 var isCorrect = Should(prefix + ".minValue", parameter.minValue)
364 .beEqualTo(limits[paramName].minValue); 364 .beEqualTo(limits[paramName].minValue);
365 isCorrect = Should(prefix + ".maxValue", parameter.maxValue) 365 isCorrect = Should(prefix + ".maxValue", parameter.maxValue)
366 .beEqualTo(limits[paramName].maxValue) && isCorrect; 366 .beEqualTo(limits[paramName].maxValue) && isCorrect;
367 367
368 // Verify that the min and max attributes are read-only 368 // Verify that the min and max attributes are read-only
369 parameter.minValue = Math.PI; 369 parameter.minValue = Math.PI;
370 var isReadOnly; 370 var isReadOnly;
371 isReadOnly = Should(prefix + ".minValue = Math.PI", parameter.minValue ) 371 isReadOnly = Should(prefix + ".minValue = Math.PI", parameter.minValue )
372 .notBeEqualTo(Math.PI); 372 .notBeEqualTo(Math.PI);
373 if (isReadOnly) 373
374 testPassed(prefix + ".minValue is read-only."); 374 Should(prefix + ".minValue is read-only", isReadOnly)
375 else 375 .beEqualTo(true);
376 testFailed(prefix + ".minValue should be read-only but was changed." ); 376
377 isCorrect = isReadOnly && isCorrect; 377 isCorrect = isReadOnly && isCorrect;
378 378
379 parameter.maxValue = Math.PI; 379 parameter.maxValue = Math.PI;
380 isReadOnly = Should(prefix + ".maxValue = Math.PI", parameter.maxValue ) 380 isReadOnly = Should(prefix + ".maxValue = Math.PI", parameter.maxValue )
381 .notBeEqualTo(Math.PI); 381 .notBeEqualTo(Math.PI);
382 if (isReadOnly) 382 Should(prefix + ".maxValue is read-only", isReadOnly)
383 testPassed(prefix + ".maxValue is read-only."); 383 .beEqualTo(true);
384 else 384
385 testFailed(prefix + ".maxValue should be read-only but was changed." );
386 isCorrect = isReadOnly && isCorrect; 385 isCorrect = isReadOnly && isCorrect;
387 386
388 // Now try to set the parameter outside the nominal range. 387 // Now try to set the parameter outside the nominal range.
389 var newValue = 2 * limits[paramName].minValue - 1; 388 var newValue = 2 * limits[paramName].minValue - 1;
390 389
391 var isClipped = true; 390 var isClipped = true;
392 var clippingTested = false; 391 var clippingTested = false;
393 // If the new value is beyond float the largest single-precision float , skip the test 392 // If the new value is beyond float the largest single-precision float , skip the test
394 // because Chrome throws an error. 393 // because Chrome throws an error.
395 if (newValue >= -mostPositiveFloat) { 394 if (newValue >= -mostPositiveFloat) {
396 parameter.value = newValue; 395 parameter.value = newValue;
397 clippingTested = true; 396 clippingTested = true;
398 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet er.value) 397 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet er.value)
399 .beEqualTo(parameter.minValue) && isClipped; 398 .beEqualTo(parameter.minValue) && isClipped;
400 } 399 }
401 400
402 newValue = 2 * limits[paramName].maxValue + 1; 401 newValue = 2 * limits[paramName].maxValue + 1;
403 402
404 if (newValue <= mostPositiveFloat) { 403 if (newValue <= mostPositiveFloat) {
405 parameter.value = newValue; 404 parameter.value = newValue;
406 clippingTested = true; 405 clippingTested = true;
407 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet er.value) 406 isClipped = Should("Set " + prefix + ".value = " + newValue, paramet er.value)
408 .beEqualTo(parameter.maxValue) && isClipped; 407 .beEqualTo(parameter.maxValue) && isClipped;
409 408
410 } 409 }
411 410
412 if (clippingTested) { 411 if (clippingTested) {
413 if (isClipped) 412 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.") 413 .beEqualTo(true);
415 else
416 testPassed(prefix + " was not correctly clipped to lie within the nominal range.")
417 } 414 }
418 415
419 isCorrect = isCorrect && isClipped; 416 isCorrect = isCorrect && isClipped;
420 417
421 success = isCorrect && success; 418 success = isCorrect && success;
422 } else { 419 } else {
423 // Test config didn't specify valid limits. Fail this test! 420 // Test config didn't specify valid limits. Fail this test!
424 testFailed("Limits for " + nodeName + "." + paramName + " were not cor rectly defined."); 421 // testFailed("Limits for " + nodeName + "." + paramName + " were not c orrectly defined.");
422 Should("Limits for " + nodeName + "." + paramName + " were correctly d efined", clippingTested)
423 .beEqualTo(false);
424
425 success = false; 425 success = false;
426 } 426 }
427 427
428 return success; 428 return success;
429 } 429 }
430 430
431 // Test all of the AudioParams for |node| using the expected values in |li mits|. 431 // 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 432 // |creatorName| is the name of the method to create the node, and is used to keep trakc of
433 // which tests we've run. 433 // which tests we've run.
434 function testLimits(creatorName, node, limits) { 434 function testLimits(creatorName, node, limits) {
(...skipping 16 matching lines...) Expand all
451 if (!isValid) 451 if (!isValid)
452 incorrectParams.push(paramName); 452 incorrectParams.push(paramName);
453 453
454 success = isValid && success; 454 success = isValid && success;
455 } 455 }
456 }); 456 });
457 457
458 // Print an appropriate message depending on whether there were AudioPar ams defined or not. 458 // Print an appropriate message depending on whether there were AudioPar ams defined or not.
459 if (audioParams.length) { 459 if (audioParams.length) {
460 var message = "Nominal ranges for AudioParam(s) of " + node.constructo r.name; 460 var message = "Nominal ranges for AudioParam(s) of " + node.constructo r.name;
461 if (success) 461 Should(message, success)
462 testPassed(message + " are correct.\n"); 462 .summarize("are correct",
463 else 463 "are incorrect for: " + + incorrectParams);
464 testFailed(message + " are incorrect for: " + incorrectParams + ".\n ");
465 return success; 464 return success;
466 } else { 465 } else {
467 if (limits) 466 Should(nodeName, !limits)
468 testFailed(nodeName + " has no AudioParams but test expected " + lim its + ".\n"); 467 .summarize("has no AudioParams as expected",
469 else 468 "has no AudioParams but test expected " + limits);
470 testPassed(nodeName + " has no AudioParams as expected.\n");
471 } 469 }
472 } 470 }
473 </script> 471 </script>
474 </body> 472 </body>
475 </html> 473 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698