tor-browser

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

test_mediaElementAudioSourceNodePassThrough.html (1823B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <meta charset="utf-8">
      4 <head>
      5  <title>Test MediaElementAudioSourceNode with passthrough</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 SimpleTest.waitForExplicitFinish();
     13 
     14 function test() {
     15  var audio = new Audio("small-shot.ogg");
     16  var context = new AudioContext();
     17  var node = context.createMediaElementSource(audio);
     18  var sp = context.createScriptProcessor(2048, 1);
     19  node.connect(sp);
     20  var nonzeroSampleCount = 0;
     21  var complete = false;
     22  var iterationCount = 0;
     23 
     24  var srcWrapped = SpecialPowers.wrap(node);
     25  ok("passThrough" in srcWrapped, "MediaElementAudioSourceNode should support the passThrough API");
     26  srcWrapped.passThrough = true;
     27 
     28  // This test ensures we receive at least expectedSampleCount nonzero samples
     29  function processSamples(e) {
     30    if (complete) {
     31      return;
     32    }
     33 
     34    if (iterationCount == 0) {
     35      // Don't start playing the audio until the AudioContext stuff is connected
     36      // and running.
     37      audio.play();
     38    }
     39    ++iterationCount;
     40 
     41    var buf = e.inputBuffer.getChannelData(0);
     42    var nonzeroSamplesThisBuffer = 0;
     43    for (var i = 0; i < buf.length; ++i) {
     44      if (buf[i] != 0) {
     45        ++nonzeroSamplesThisBuffer;
     46      }
     47    }
     48    nonzeroSampleCount += nonzeroSamplesThisBuffer;
     49    if (iterationCount == 10) {
     50      is(nonzeroSampleCount, 0, "The input must be silence");
     51      SimpleTest.finish();
     52      complete = true;
     53    }
     54  }
     55 
     56  audio.oncanplaythrough = function() {
     57    sp.onaudioprocess = processSamples;
     58  };
     59 }
     60 
     61 SpecialPowers.pushPrefEnv({"set": [["media.preload.default", 2], ["media.preload.auto", 3]]}, test);
     62 
     63 </script>
     64 </pre>
     65 </body>
     66 </html>