audioworklet-audioparam-range.https.html (3314B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset='utf-8' /> 5 <title>Test AudioWorkletProcessor parameterDescriptors values range</title> 6 <script src='/resources/testharness.js'></script> 7 <script src='/resources/testharnessreport.js'></script> 8 </head> 9 <body> 10 <script id='params'> 11 // Parameter descriptors for different scenarios. 12 const PARAMS_VARIATIONS = [ 13 { name: 'valid-range', defaultValue: 1, minValue: 0, maxValue: 2 }, 14 { name: 'no-default', minValue: -1, maxValue: 1 }, 15 { name: 'only-default', defaultValue: 1 }, 16 { name: 'identical-values', defaultValue: 1, minValue: 1, maxValue: 1 }, 17 { name: 'invalid-default', defaultValue: 1, minValue: 2, maxValue: 4 } 18 ]; 19 </script> 20 21 <script id='processors' type='worklet'> 22 // Valid processors 23 ['valid-range', 'no-defaultValue', 'only-defaultValue', 24 'identical-values'].forEach((name, index) => { 25 registerProcessor(`${name}-processor`, 26 class extends AudioWorkletProcessor { 27 static get parameterDescriptors() { 28 return [PARAMS_VARIATIONS[index]]; 29 } 30 process() { return true; } 31 }); 32 }); 33 34 // Invalid processor 35 try { 36 registerProcessor('invalid-default-processor', 37 class InvalidRangeProcessor extends AudioWorkletProcessor { 38 static get parameterDescriptors() { 39 return [PARAMS_VARIATIONS[4]]; 40 } 41 process() { return true; } 42 }); 43 throw new Error('This should not have been reached.'); 44 } catch (e) { 45 if (e.name !== 'InvalidStateError') { 46 throw new Error('Expected InvalidStateError'); 47 } 48 } 49 </script> 50 51 <script> 52 function createWorkletURL() { 53 return URL.createObjectURL(new Blob([ 54 document.querySelector('script#params').innerText, 55 document.querySelector('script#processors').innerText 56 ], { type: 'application/javascript' })); 57 } 58 59 promise_test(async () => { 60 const context = new AudioContext(); 61 await context.audioWorklet.addModule(createWorkletURL()); 62 63 // Test valid processors 64 const validProcessors = [ 65 'valid-range-processor', 66 'no-defaultValue-processor', 67 'only-defaultValue-processor', 68 'identical-values-processor' 69 ]; 70 71 for (const testName of validProcessors) { 72 let node = new AudioWorkletNode(context, testName); 73 assert_true(node.parameters.has( 74 PARAMS_VARIATIONS.find( 75 p => p.name === node.parameters.keys().next().value 76 ).name 77 ), `Creating an AudioWorkletNode for ${testName} should work.`); 78 } 79 }, 'Valid parameter descriptors should have successful registration.'); 80 81 promise_test(async () => { 82 const context = new AudioContext(); 83 await context.audioWorklet.addModule(createWorkletURL()); 84 85 assert_throws_dom('InvalidStateError', () => { 86 new AudioWorkletNode(context, 'invalid-default-processor'); 87 }, 'Worklet creation failed due to registration failure.'); 88 }, 'Invalid parameter descriptors should fail registration.'); 89 </script> 90 </body> 91 </html>