content/media/webaudio/test/test_mediaStreamAudioSourceNodeCrossOrigin.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_mediaStreamAudioSourceNodeCrossOrigin.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<meta charset="utf-8">
     1.7 +<head>
     1.8 +  <title>Test MediaStreamAudioSourceNode doesn't get data from cross-origin media resources</title>
     1.9 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +SimpleTest.waitForExplicitFinish();
    1.16 +
    1.17 +var audio = new Audio("http://example.org:80/tests/content/media/webaudio/test/small-shot.ogg");
    1.18 +var context = new AudioContext();
    1.19 +var node = context.createMediaStreamSource(audio.mozCaptureStreamUntilEnded());
    1.20 +var sp = context.createScriptProcessor(2048, 1);
    1.21 +node.connect(sp);
    1.22 +var nonzeroSampleCount = 0;
    1.23 +var complete = false;
    1.24 +var iterationCount = 0;
    1.25 +
    1.26 +// This test ensures we receive at least expectedSampleCount nonzero samples
    1.27 +function processSamples(e) {
    1.28 +  if (complete) {
    1.29 +    return;
    1.30 +  }
    1.31 +
    1.32 +  if (iterationCount == 0) {
    1.33 +    // Don't start playing the audio until the AudioContext stuff is connected
    1.34 +    // and running.
    1.35 +    audio.play();
    1.36 +  }
    1.37 +  ++iterationCount;
    1.38 +
    1.39 +  var buf = e.inputBuffer.getChannelData(0);
    1.40 +  var nonzeroSamplesThisBuffer = 0;
    1.41 +  for (var i = 0; i < buf.length; ++i) {
    1.42 +    if (buf[i] != 0) {
    1.43 +      ++nonzeroSamplesThisBuffer;
    1.44 +    }
    1.45 +  }
    1.46 +  is(nonzeroSamplesThisBuffer, 0,
    1.47 +     "Checking all samples are zero");
    1.48 +  if (iterationCount >= 20) {
    1.49 +    SimpleTest.finish();
    1.50 +    complete = true;
    1.51 +  }
    1.52 +}
    1.53 +
    1.54 +audio.oncanplaythrough = function() {
    1.55 +  sp.onaudioprocess = processSamples;
    1.56 +};
    1.57 +</script>
    1.58 +</pre>
    1.59 +</body>
    1.60 +</html>

mercurial