tor-browser

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

test_scriptProcessorNode_playbackTime1.html (1552B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test ScriptProcessorNode playbackTime for bug 970773</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7 </head>
      8 <body>
      9 <pre id="test">
     10 <script class="testbody" type="text/javascript">
     11 
     12 SimpleTest.waitForExplicitFinish();
     13 
     14 var context = new AudioContext();
     15 const delay = 0.1;
     16 
     17 function doTest() {
     18  const processorBufferLength = 256;
     19  // |currentTime| may include double precision floating point
     20  // rounding errors, so round to nearest integer sample to ignore these.
     21  var minimumPlaybackSample =
     22    Math.round(context.currentTime * context.sampleRate) +
     23    processorBufferLength;
     24  var sp = context.createScriptProcessor(processorBufferLength);
     25  sp.connect(context.destination);
     26  sp.onaudioprocess =
     27    function(e) {
     28      is(e.inputBuffer.length, processorBufferLength,
     29         "expected buffer length");
     30      var playbackSample = Math.round(e.playbackTime * context.sampleRate)
     31      ok(playbackSample >= minimumPlaybackSample,
     32         "playbackSample " + playbackSample +
     33         " beyond expected minimum " + minimumPlaybackSample);
     34      sp.onaudioprocess = null;
     35      SimpleTest.finish();
     36    };
     37 }
     38 
     39 // Wait until AudioDestinationNode has accumulated enough 'extra' time so that
     40 // a failure would be easily detected.
     41 (function waitForExtraTime() {
     42  if (context.currentTime < delay) {
     43    SimpleTest.executeSoon(waitForExtraTime);
     44  } else {
     45    doTest();
     46  }
     47 })();
     48 
     49 </script>
     50 </pre>
     51 </body>
     52 </html>