tor-browser

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

audioworkletprocessor-options.https.html (2777B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test cross-thread passing of AudioWorkletNodeOptions
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9  </head>
     10  <body>
     11    <script>
     12      const context = new AudioContext();
     13 
     14      const filePath = 'processors/option-test-processor.js';
     15 
     16      // Create a OptionTestProcessor and feed |processorData| to it. The
     17      // processor should echo the received data to the node's |onmessage|
     18      // handler.
     19      promise_test(async () => {
     20        await context.audioWorklet.addModule(filePath);
     21 
     22        const processorOptions = {
     23          description: 'foo',
     24          payload: [0, 1, 2, 3],
     25        };
     26 
     27        const optionTestNode =
     28            new AudioWorkletNode(context, 'option-test-processor', {
     29              processorOptions: processorOptions,
     30            });
     31 
     32        await new Promise((resolve) => {
     33          optionTestNode.port.onmessage = (event) => {
     34            assert_equals(
     35                event.data.processorOptions.description,
     36                processorOptions.description,
     37                `|description| field in processorOptions from processor(` +
     38                    `"${event.data.processorOptions.description}") vs ` +
     39                        `constructor ("${processorOptions.description}")`);
     40            assert_array_equals(
     41                event.data.processorOptions.payload,
     42                processorOptions.payload,
     43                `|payload| array in processorOptions from processor(` +
     44                    `[${event.data.processorOptions.payload}]) vs constructor` +
     45                        ` ([${processorOptions.payload}])`);
     46            resolve();
     47          };
     48        });
     49      }, `valid-processor-data: processorOptions round-trip`);
     50 
     51      // Passing empty option dictionary should work without a problem.
     52      promise_test(async () => {
     53        await context.audioWorklet.addModule(filePath);
     54 
     55        const optionTestNode =
     56            new AudioWorkletNode(context, 'option-test-processor');
     57 
     58        await new Promise((resolve) => {
     59          optionTestNode.port.onmessage = (event) => {
     60            assert_equals(
     61                Object.keys(event.data).length,
     62                2,
     63                `Number of properties in data from processor`);
     64            assert_equals(
     65                event.data.numberOfInputs,
     66                1,
     67                `|numberOfInputs| field in data from processor`);
     68            assert_equals(
     69                event.data.numberOfOutputs,
     70                1,
     71                `|numberOfOutputs| field in data from processor`);
     72            resolve();
     73          };
     74        });
     75      }, `empty-option: default processorOptions behavior`);
     76    </script>
     77  </body>
     78 </html>