Bug 937718 - Test for MediaElementAudioSourceNode and cross-origin resources. r=roc
authorPaul Adenot <paul@paul.cx>
Wed, 24 Dec 2014 13:46:58 +0100
changeset 247841 bcbc64d97fbf4eb28a8c7511f46a9186c4920c60
parent 247840 0c9f97ebf7ead3d855b24f3e7d213eaf74f2c3df
child 247842 c66197902d879b4d6bfd69c7ea9b08560fd2616e
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs937718
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 937718 - Test for MediaElementAudioSourceNode and cross-origin resources. r=roc
dom/media/webaudio/test/corsServer.sjs
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_mediaElementAudioSourceNodeCrossOrigin.html
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/corsServer.sjs
@@ -0,0 +1,26 @@
+function handleRequest(request, response)
+{
+  var file = Components.classes["@mozilla.org/file/directory_service;1"].
+                        getService(Components.interfaces.nsIProperties).
+                        get("CurWorkD", Components.interfaces.nsILocalFile);
+  var fis  = Components.classes['@mozilla.org/network/file-input-stream;1'].
+                        createInstance(Components.interfaces.nsIFileInputStream);
+  var bis  = Components.classes["@mozilla.org/binaryinputstream;1"].
+                        createInstance(Components.interfaces.nsIBinaryInputStream);
+  var paths = "tests/dom/media/webaudio/test/small-shot.ogg";
+  var split = paths.split("/");
+  for(var i = 0; i < split.length; ++i) {
+    file.append(split[i]);
+  }
+  fis.init(file, -1, -1, false);
+  bis.setInputStream(fis);
+  var bytes = bis.readBytes(bis.available());
+  response.setHeader("Content-Duration", "0.233", false);
+  response.setHeader("Content-Type", "video/ogg", false);
+  response.setHeader("Content-Length", ""+ bytes.length, false);
+  response.setHeader("Access-Control-Allow-Origin", "*", false);
+  response.write(bytes, bytes.length);
+  response.processAsync();
+  response.finish();
+  bis.close();
+}
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -2,16 +2,17 @@
 skip-if = ((buildapp == 'mulet' || buildapp == 'b2g') && (toolkit != 'gonk' || debug)) || (os == 'win' && strictContentSandbox) #b2g-debug,b2g-desktop(bug 916135); strictContentSandbox(Bug 1042735)
 support-files =
   audio-expected.wav
   audio-mono-expected-2.wav
   audio-mono-expected.wav
   audio-quad.wav
   audio.ogv
   audioBufferSourceNodeNeutered_worker.js
+  corsServer.sjs
   invalid.txt
   layouttest-glue.js
   noaudio.webm
   small-shot-expected.wav
   small-shot-mono-expected.wav
   small-shot.ogg
   small-shot.mp3
   ting-44.1k-1ch.ogg
@@ -104,16 +105,17 @@ skip-if = toolkit == 'android' # bug 105
 [test_dynamicsCompressorNodePassThrough.html]
 [test_gainNode.html]
 [test_gainNodeInLoop.html]
 [test_gainNodePassThrough.html]
 [test_maxChannelCount.html]
 [test_mediaDecoding.html]
 [test_mediaElementAudioSourceNode.html]
 [test_mediaElementAudioSourceNodePassThrough.html]
+[test_mediaElementAudioSourceNodeCrossOrigin.html]
 [test_mediaStreamAudioDestinationNode.html]
 [test_mediaStreamAudioSourceNode.html]
 [test_mediaStreamAudioSourceNodeCrossOrigin.html]
 [test_mediaStreamAudioSourceNodePassThrough.html]
 [test_mediaStreamAudioSourceNodeResampling.html]
 [test_mixingRules.html]
 skip-if = android_version == '10' # bug 1091965
 [test_mozaudiochannel.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_mediaElementAudioSourceNodeCrossOrigin.html
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML>
+<html>
+<meta charset="utf-8">
+<head>
+  <title>Test MediaStreamAudioSourceNode doesn't get data from cross-origin media resources</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+SimpleTest.waitForExplicitFinish();
+
+var tests = [
+  // Not the same origin no CORS asked for, should have silence
+  { url: "http://example.org:80/tests/dom/media/webaudio/test/small-shot.ogg",
+    cors: null,
+    expectSilence: true },
+  // Same origin, should have sound
+  { url: "small-shot.ogg",
+    cors: null,
+    expectSilence: false },
+  // Cross-origin but we asked for CORS and the server answered with the right
+  // header, should have
+  { url: "http://example.org:80/tests/dom/media/webaudio/test/corsServer.sjs",
+    cors: "anonymous",
+    expectSilence: false }
+];
+
+var testsRemaining = tests.length;
+
+tests.forEach(function(e) {
+  e.ac = new AudioContext();
+  var a = new Audio();
+  a.loop = true;
+  if (e.cors) {
+    a.crossOrigin = e.cors;
+  }
+  a.src = e.url;
+  a.controls = true;
+  var measn = e.ac.createMediaElementSource(a);
+  var sp = e.ac.createScriptProcessor(2048, 1);
+  // Set a couple expandos to track the status of the test
+  sp.iterationsLeft = 20;
+  sp.seenSound = false;
+
+  measn.connect(sp);
+  a.play();
+  document.body.appendChild(a);
+
+  function checkFinished(sp) {
+    if (--sp.iterationsLeft == 0) {
+      sp.onaudioprocess = null;
+      a.pause();
+      var not = e.expectSilence ? "" : "not";
+      is(e.expectSilence, !sp.seenSound,
+         "Buffer is " + not + " silent as expected, for " +
+         e.url + " (cors: " + e.cors + ")");
+      if (--testsRemaining == 0) {
+        SimpleTest.finish();
+      }
+    }
+  }
+
+  function checkBufferSilent(e) {
+    var inputArrayBuffer = e.inputBuffer.getChannelData(0);
+    var silent = true;
+    for (var i = 0; i < inputArrayBuffer.length; i++) {
+      if (inputArrayBuffer[i] != 0.0) {
+        silent = false;
+        break;
+      }
+    }
+    // It is acceptable to find a full buffer of silence here, even if we expect
+    // sound, because Gecko's looping on media elements is not seamless and we
+    // can underrun. We are looking for at least one buffer of non-silent data.
+    e.target.seenSound = !silent || e.target.seenSound;
+    checkFinished(e.target);
+    return silent;
+  }
+
+  a.onplaying = function () {
+    sp.onaudioprocess = checkBufferSilent;
+  }
+});
+</script>
+</pre>
+</body>
+</html>