tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

audioworkletnode-constructor-options.https.html (4772B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>AudioWorkletNodeOptions: Basic Construction & Validation</title>
      5    <script src="/resources/testharness.js"></script>
      6    <script src="/resources/testharnessreport.js"></script>
      7  </head>
      8  <body>
      9    <script>
     10      const sampleRate = 48000;
     11      const filePath = 'processors/dummy-processor.js';
     12 
     13      promise_test(async () => {
     14        const context = new OfflineAudioContext(1, 1, sampleRate);
     15        await context.audioWorklet.addModule(filePath);
     16 
     17        const testNode = new AudioWorkletNode(context, 'dummy');
     18        assert_true(
     19            testNode instanceof AudioWorkletNode,
     20            'testNode should be an instance of AudioWorkletNode');
     21        assert_equals(testNode.numberOfInputs, 1, 'Default numberOfInputs');
     22        assert_equals(testNode.numberOfOutputs, 1, 'Default numberOfOutputs');
     23        assert_equals(testNode.channelCount, 2, 'Default channelCount');
     24        assert_equals(
     25            testNode.channelCountMode, 'max', 'Default channelCountMode');
     26        assert_equals(
     27            testNode.channelInterpretation, 'speakers',
     28            'Default channelInterpretation');
     29      }, 'Construct AudioWorkletNode without options and check default values');
     30 
     31      promise_test(async () => {
     32        const context = new OfflineAudioContext(1, 1, sampleRate);
     33        await context.audioWorklet.addModule(filePath);
     34 
     35        const options = {
     36          numberOfInputs: 7,
     37          numberOfOutputs: 18,
     38          channelCount: 4,
     39          channelCountMode: 'clamped-max',
     40          channelInterpretation: 'discrete'
     41        };
     42 
     43        const testNode = new AudioWorkletNode(context, 'dummy', options);
     44        assert_equals(testNode.numberOfInputs, options.numberOfInputs);
     45        assert_equals(testNode.numberOfOutputs, options.numberOfOutputs);
     46        assert_equals(testNode.channelCount, options.channelCount);
     47        assert_equals(testNode.channelCountMode, options.channelCountMode);
     48        assert_equals(
     49            testNode.channelInterpretation, options.channelInterpretation);
     50      }, 'Construct AudioWorkletNode with explicit AudioNodeOptions');
     51 
     52      promise_test(async () => {
     53        const context = new OfflineAudioContext(1, 1, sampleRate);
     54        await context.audioWorklet.addModule(filePath);
     55 
     56        const optionsValid = {channelCount: 17};
     57        const testNode = new AudioWorkletNode(context, 'dummy', optionsValid);
     58        assert_equals(testNode.channelCount, optionsValid.channelCount);
     59 
     60        const optionsTooSmall = {channelCount: 0};
     61        assert_throws_dom('NotSupportedError', () => {
     62          new AudioWorkletNode(context, 'dummy', optionsTooSmall);
     63        }, 'channelCount of 0 should throw NotSupportedError');
     64 
     65        const optionsTooLarge = {channelCount: 33};
     66        assert_throws_dom('NotSupportedError', () => {
     67          new AudioWorkletNode(context, 'dummy', optionsTooLarge);
     68        }, 'channelCount of 33 should throw NotSupportedError');
     69      }, 'Validate channelCount boundaries for AudioWorkletNode');
     70 
     71      promise_test(async () => {
     72        const context = new OfflineAudioContext(1, 1, sampleRate);
     73        await context.audioWorklet.addModule(filePath);
     74 
     75        const channelCountModes = ['max', 'clamped-max', 'explicit'];
     76        for (const mode of channelCountModes) {
     77          const node = new AudioWorkletNode(context, 'dummy', {
     78            channelCountMode: mode
     79          });
     80          assert_equals(
     81              node.channelCountMode, mode, `Set channelCountMode to '${mode}'`);
     82        }
     83 
     84        const invalidMode = {channelCountMode: 'foobar'};
     85        assert_throws_js(TypeError, () => {
     86          new AudioWorkletNode(context, 'dummy', invalidMode);
     87        }, 'Invalid channelCountMode should throw TypeError');
     88      }, 'Validate allowed and disallowed channelCountMode options');
     89 
     90      promise_test(async () => {
     91        const context = new OfflineAudioContext(1, 1, sampleRate);
     92        await context.audioWorklet.addModule(filePath);
     93 
     94        const channelInterpretations = ['speakers', 'discrete'];
     95        for (const interpretation of channelInterpretations) {
     96          const node = new AudioWorkletNode(context, 'dummy', {
     97            channelInterpretation: interpretation
     98          });
     99          assert_equals(node.channelInterpretation, interpretation,
    100              `Set channelInterpretation to '${interpretation}'`);
    101        }
    102 
    103        const invalidInterpretation = {channelInterpretation: 'foobar'};
    104        assert_throws_js(TypeError, () => {
    105          new AudioWorkletNode(context, 'dummy', invalidInterpretation);
    106        }, 'Invalid channelInterpretation should throw TypeError');
    107      }, 'Validate allowed and disallowed channelInterpretation values');
    108    </script>
    109  </body>
    110 </html>