tor-browser

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

test_mediaStreamAudioSourceNodeCrossOrigin.html (1616B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <meta charset="utf-8">
      4 <head>
      5  <title>Test MediaStreamAudioSourceNode doesn't get data from cross-origin media resources</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 var audio = new Audio("http://example.org:80/tests/dom/media/webaudio/test/small-shot.ogg");
     15 audio.load();
     16 var context = new AudioContext();
     17 audio.onloadedmetadata = function() {
     18  var node = context.createMediaStreamSource(audio.mozCaptureStreamUntilEnded());
     19  var sp = context.createScriptProcessor(2048, 1);
     20  node.connect(sp);
     21  var complete = false;
     22  var iterationCount = 0;
     23 
     24  // This test ensures we receive at least expectedSampleCount nonzero samples
     25  function processSamples(e) {
     26    if (complete) {
     27      return;
     28    }
     29 
     30    if (iterationCount == 0) {
     31      // Don't start playing the audio until the AudioContext stuff is connected
     32      // and running.
     33      audio.play();
     34    }
     35    ++iterationCount;
     36 
     37    var buf = e.inputBuffer.getChannelData(0);
     38    var nonzeroSamplesThisBuffer = 0;
     39    for (var i = 0; i < buf.length; ++i) {
     40      if (buf[i] != 0) {
     41        ++nonzeroSamplesThisBuffer;
     42      }
     43    }
     44    is(nonzeroSamplesThisBuffer, 0,
     45       "Checking all samples are zero");
     46    if (iterationCount >= 20) {
     47      SimpleTest.finish();
     48      complete = true;
     49    }
     50  }
     51 
     52  audio.oncanplaythrough = function() {
     53    sp.onaudioprocess = processSamples;
     54  };
     55 }
     56 </script>
     57 </pre>
     58 </body>
     59 </html>