content/media/webaudio/test/test_mediaStreamAudioSourceNodeCrossOrigin.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 type="text/javascript" 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();
    14 var audio = new Audio("http://example.org:80/tests/content/media/webaudio/test/small-shot.ogg");
    15 var context = new AudioContext();
    16 var node = context.createMediaStreamSource(audio.mozCaptureStreamUntilEnded());
    17 var sp = context.createScriptProcessor(2048, 1);
    18 node.connect(sp);
    19 var nonzeroSampleCount = 0;
    20 var complete = false;
    21 var iterationCount = 0;
    23 // This test ensures we receive at least expectedSampleCount nonzero samples
    24 function processSamples(e) {
    25   if (complete) {
    26     return;
    27   }
    29   if (iterationCount == 0) {
    30     // Don't start playing the audio until the AudioContext stuff is connected
    31     // and running.
    32     audio.play();
    33   }
    34   ++iterationCount;
    36   var buf = e.inputBuffer.getChannelData(0);
    37   var nonzeroSamplesThisBuffer = 0;
    38   for (var i = 0; i < buf.length; ++i) {
    39     if (buf[i] != 0) {
    40       ++nonzeroSamplesThisBuffer;
    41     }
    42   }
    43   is(nonzeroSamplesThisBuffer, 0,
    44      "Checking all samples are zero");
    45   if (iterationCount >= 20) {
    46     SimpleTest.finish();
    47     complete = true;
    48   }
    49 }
    51 audio.oncanplaythrough = function() {
    52   sp.onaudioprocess = processSamples;
    53 };
    54 </script>
    55 </pre>
    56 </body>
    57 </html>

mercurial