tor-browser

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

audioworkletglobalscope-timing-info.https.html (1715B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <title>
      5      Test currentTime and currentFrame in AudioWorkletGlobalScope
      6    </title>
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9  </head>
     10  <body>
     11    <script>
     12      promise_test(async () => {
     13        const sampleRate = 48000;
     14        const renderLength = 512;
     15        const context = new OfflineAudioContext(1, renderLength, sampleRate);
     16 
     17        const filePath = 'processors/timing-info-processor.js';
     18 
     19        await context.audioWorklet.addModule(filePath);
     20 
     21        const portWorkletNode =
     22            new AudioWorkletNode(context, 'timing-info-processor');
     23        portWorkletNode.connect(context.destination);
     24 
     25        // Suspend at render quantum boundary and check the timing
     26        // information between the main thread and the rendering thread.
     27        [0, 128, 256, 384].forEach(suspendFrame => {
     28          context.suspend(suspendFrame / sampleRate).then(() => {
     29            portWorkletNode.port.onmessage = (event) => {
     30              assert_equals(
     31                  event.data.currentFrame,
     32                  suspendFrame,
     33                  'currentFrame from the processor at ' + suspendFrame);
     34              assert_equals(
     35                  event.data.currentTime,
     36                  context.currentTime,
     37                  'currentTime from the processor at ' +
     38                      context.currentTime);
     39              context.resume();
     40            };
     41 
     42            portWorkletNode.port.postMessage('query-timing-info');
     43          });
     44        });
     45 
     46        await context.startRendering();
     47      }, 'Check the timing information from AudioWorkletProcessor');
     48    </script>
     49  </body>
     50 </html>