tor-browser

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

processing-after-resume.https.html (2393B)


      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 const get_node_and_reply = (context) => {
      7  const node = new AudioWorkletNode(context, 'port-processor');
      8  return new Promise((resolve) => {
      9    node.port.onmessage = (event) => resolve({node: node, reply: event.data});
     10  });
     11 };
     12 const ping_for_reply = (node) => {
     13  return new Promise((resolve) => {
     14    node.port.onmessage = (event) => resolve(event.data);
     15    node.port.postMessage('ping');
     16  });
     17 };
     18 const assert_consistent = (constructReply, pong, expectedPongTime, name) => {
     19  const blockSize = 128;
     20  assert_equals(pong.timeStamp, expectedPongTime, `${name} pong time`);
     21  assert_equals(pong.processCallCount * blockSize,
     22                pong.currentFrame - constructReply.currentFrame,
     23                `${name} processed frame count`);
     24 };
     25 const modulePath = '/webaudio/the-audio-api/' +
     26    'the-audioworklet-interface/processors/port-processor.js';
     27 
     28 promise_test(async () => {
     29  const realtime = new AudioContext();
     30  await realtime.audioWorklet.addModule(modulePath);
     31  await realtime.suspend();
     32  const timeBeforeResume = realtime.currentTime;
     33  // Two AudioWorkletNodes are constructed.
     34  // node1 is constructed before and node2 after the resume() call.
     35  const construct1 = get_node_and_reply(realtime);
     36  const resume = realtime.resume();
     37  const construct2 = get_node_and_reply(realtime);
     38  const {node: node1, reply: constructReply1} = await construct1;
     39  assert_equals(constructReply1.timeStamp, timeBeforeResume,
     40                'construct time before resume');
     41  const {node: node2, reply: constructReply2} = await construct2;
     42  assert_greater_than_equal(constructReply2.timeStamp, timeBeforeResume,
     43                'construct time after resume');
     44  await resume;
     45  // Suspend the context to freeze time and check that the processing for each
     46  // node matches the elapsed time.
     47  await realtime.suspend();
     48  const timeAfterSuspend = realtime.currentTime;
     49  const pong1 = await ping_for_reply(node1);
     50  const pong2 = await ping_for_reply(node2);
     51  assert_consistent(constructReply1, pong1, timeAfterSuspend, 'node1');
     52  assert_consistent(constructReply2, pong2, timeAfterSuspend, 'node2');
     53  assert_equals(pong1.currentFrame, pong2.currentFrame, 'currentFrame matches');
     54 });
     55 </script>