tor-browser

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

audioworkletglobalscope-creation-time.https.html (1718B)


      1 <!doctype html>
      2 <title>Test consistency of processing after resume()</title>
      3 <script src=/resources/testharness.js></script>
      4 <script src=/resources/testharnessreport.js></script>
      5 <script>
      6 
      7 const get_node_and_reply = (context) => {
      8  const node = new AudioWorkletNode(context, 'port-processor');
      9  return new Promise((resolve) => {
     10    node.port.onmessage = (event) => resolve({node: node, reply: event.data});
     11  });
     12 };
     13 
     14 const modulePath = '/webaudio/the-audio-api/' +
     15    'the-audioworklet-interface/processors/port-processor.js';
     16 
     17 promise_test(async t => {
     18  const realtime = new AudioContext();
     19  const sampleRate = realtime.sampleRate;
     20 
     21  // Create a basic oscillator to form an audio graph.
     22  const oscillator = realtime.createOscillator();
     23  oscillator.connect(realtime.destination);
     24  oscillator.start();
     25 
     26  // Start rendering and suspend after a delay.
     27  await new Promise(resolve => t.step_timeout(resolve, 1000));
     28  await realtime.suspend();
     29 
     30  // Capture currentTime after suspending.
     31  const contextTime = realtime.currentTime;
     32 
     33  // Load the audio module.
     34  await realtime.audioWorklet.addModule(modulePath);
     35 
     36  // creates AudioWorkletNode.
     37  const construct1 = await get_node_and_reply(realtime);
     38 
     39  // workletFrame should be the currentFrame sent in the message
     40  // by the AudioWorkletNode.
     41  const workletFrame = construct1.reply.currentFrame;
     42 
     43  // Assert that contextTime * sampleRate equals workletFrame.
     44  assert_equals(
     45      Math.floor(contextTime * sampleRate), workletFrame,
     46      `Expected workletFrame (${
     47          workletFrame}) to be equal to contextTime * sampleRate (${
     48          contextTime * sampleRate})`);
     49 }, 'currentTime vs currentFrames in Audio Worklet global scope');
     50 
     51 </script>