tor-browser

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

audioworklet-postmessage-sharedarraybuffer.https.html (2522B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test passing SharedArrayBuffer to an AudioWorklet
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9    <script src="/webaudio/resources/audit.js"></script>
     10  </head>
     11  <body>
     12    <script id="layout-test-code">
     13      let audit = Audit.createTaskRunner();
     14 
     15      let context = new AudioContext();
     16 
     17      let filePath = 'processors/sharedarraybuffer-processor.js';
     18 
     19      audit.define(
     20          'Test postMessage from AudioWorkletProcessor to AudioWorkletNode',
     21          (task, should) => {
     22            let workletNode =
     23                new AudioWorkletNode(context, 'sharedarraybuffer-processor');
     24 
     25            // After it is created, the worklet will send a new
     26            // SharedArrayBuffer to the main thread.
     27            //
     28            // The worklet will then wait to receive a message from the main
     29            // thread.
     30            //
     31            // When it receives the message, it will check whether it is a
     32            // SharedArrayBuffer, and send this information back to the main
     33            // thread.
     34 
     35            workletNode.port.onmessage = (event) => {
     36              let data = event.data;
     37              switch (data.state) {
     38                case 'created':
     39                  should(
     40                      data.sab instanceof SharedArrayBuffer,
     41                      'event.data.sab from worklet is an instance of SharedArrayBuffer')
     42                      .beTrue();
     43 
     44                  // Send a SharedArrayBuffer back to the worklet.
     45                  let sab = new SharedArrayBuffer(8);
     46                  workletNode.port.postMessage(sab);
     47                  break;
     48 
     49                case 'received message':
     50                  should(data.isSab, 'event.data from main thread is an instance of SharedArrayBuffer')
     51                      .beTrue();
     52                  task.done();
     53                  break;
     54 
     55                default:
     56                  should(false,
     57                         `Got unexpected message from worklet: ${data.state}`)
     58                      .beTrue();
     59                  task.done();
     60                  break;
     61              }
     62            };
     63 
     64            workletNode.port.onmessageerror = (event) => {
     65              should(false, 'Got messageerror from worklet').beTrue();
     66              task.done();
     67            };
     68          });
     69 
     70      context.audioWorklet.addModule(filePath).then(() => {
     71        audit.run();
     72      });
     73    </script>
     74  </body>
     75 </html>