Bug 1387454 - Mochitests for non default rate on webaudio and media recorder. r=padenot
authorAlex Chronopoulos <achronop@gmail.com>
Tue, 03 Apr 2018 20:02:15 +0300
changeset 411953 a8e2605332f30c7af7c9e72b69c9e79614dfbf8d
parent 411952 6e227df35207d4eac605804c925ae2c916c79134
child 411954 b33c66f1d444cf65dd53f929ae31c68284132525
push id33778
push userapavel@mozilla.com
push dateFri, 06 Apr 2018 09:57:38 +0000
treeherdermozilla-central@46a5fc19bd7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1387454
milestone61.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 1387454 - Mochitests for non default rate on webaudio and media recorder. r=padenot MozReview-Commit-ID: Bs7oI94WrPu
dom/media/webaudio/test/mochitest.ini
dom/media/webaudio/test/test_audioContextParams_recordNonDefaultSampleRate.html
dom/media/webaudio/test/test_audioContextParams_sampleRate.html
--- a/dom/media/webaudio/test/mochitest.ini
+++ b/dom/media/webaudio/test/mochitest.ini
@@ -25,16 +25,18 @@ support-files =
   ting-48k-1ch.ogg
   ting-48k-2ch.ogg
   ting-44.1k-1ch.wav
   ting-44.1k-2ch.wav
   ting-48k-1ch.wav
   ting-48k-2ch.wav
   sine-440-10s.opus
   webaudio.js
+  ../../tests/mochitest/mediaStreamPlayback.js
+  ../../tests/mochitest/head.js
 
 [test_analyserNode.html]
 skip-if = !asan || toolkit != android
 [test_analyserScale.html]
 skip-if = !asan || toolkit != android
 [test_analyserNodeOutput.html]
 skip-if = !asan || toolkit != android
 [test_analyserNodePassThrough.html]
@@ -216,8 +218,10 @@ skip-if = toolkit == 'android' # bug 109
 [test_stereoPanningWithGain.html]
 [test_waveDecoder.html]
 [test_waveShaper.html]
 [test_waveShaperGain.html]
 [test_waveShaperNoCurve.html]
 [test_waveShaperPassThrough.html]
 [test_waveShaperInvalidLengthCurve.html]
 [test_WebAudioMemoryReporting.html]
+[test_audioContextParams_sampleRate.html]
+[test_audioContextParams_recordNonDefaultSampleRate.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_audioContextParams_recordNonDefaultSampleRate.html
@@ -0,0 +1,48 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<pre id="test">
+
+<script class="testbody" type="text/javascript">
+function startTest() {
+  let ctx = new AudioContext({sampleRate: 32000});
+  oscillator = ctx.createOscillator();
+  let dest = ctx.createMediaStreamDestination();
+  oscillator.connect(dest);
+  oscillator.start();
+  let stream = dest.stream;
+
+  recorder = new MediaRecorder(stream);
+  recorder.ondataavailable = (e) => {
+      ok(true, 'recorder ondataavailable event');
+      if (recorder.state == 'recording') {
+        ok(e.data.size > 0, 'check blob has data');
+        recorder.stop();
+      }
+  }
+
+  recorder.onstop = () => {
+      ok(true, 'recorder stop event');
+      SimpleTest.finish();
+  }
+
+  try {
+    recorder.start(1000);
+    ok(true, 'recorder started');
+    is('recording', recorder.state, 'check record state recording');
+  } catch (e) {
+    ok(false, 'Can t record audio context');
+  }
+}
+
+startTest();
+SimpleTest.waitForExplicitFinish();
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/webaudio/test/test_audioContextParams_sampleRate.html
@@ -0,0 +1,78 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+
+<script>
+  createHTML({
+    title: "Parallel MSG by setting AudioContextParam sample rate",
+    bug: "1387454",
+    visible: true
+  });
+
+  scriptsReady
+  .then(() => FAKE_ENABLED = false)
+  .then(() => runTestWhenReady( async () => {
+    // Test an AudioContext of specific sample rate.
+    // Verify that the oscillator produces a tone.
+    let rate1 = 500;
+    let ac1 = new AudioContext({sampleRate: 44100});
+    let dest_ac1 = ac1.createMediaStreamDestination();
+    let osc_ac1 = ac1.createOscillator();
+    osc_ac1.frequency.value = rate1;
+    osc_ac1.connect(dest_ac1);
+    osc_ac1.start(0);
+
+    let analyser = new AudioStreamAnalyser(ac1, dest_ac1.stream);
+    analyser.enableDebugCanvas();
+    await analyser.waitForAnalysisSuccess( array => {
+      const freg_50Hz   = array[analyser.binIndexForFrequency(50)];
+      const freq_rate1  = array[analyser.binIndexForFrequency(rate1)];
+      const freq_4000Hz = array[analyser.binIndexForFrequency(4000)];
+
+      info("Analysing audio frequency - low:target1:high = "
+              + freg_50Hz + ':' + freq_rate1 + ':' + freq_4000Hz);
+      return freg_50Hz < 50 && freq_rate1 > 200 && freq_4000Hz < 50;
+    })
+    osc_ac1.stop();
+
+    // Same test using a  new AudioContext of different sample rate.
+    let rate2 = 1500;
+    let ac2 = new AudioContext({sampleRate: 48000});
+    let dest_ac2 = ac2.createMediaStreamDestination();
+    let osc_ac2 = ac2.createOscillator();
+    osc_ac2.frequency.value = rate2;
+    osc_ac2.connect(dest_ac2);
+    osc_ac2.start(0);
+
+    let analyser2 = new AudioStreamAnalyser(ac2, dest_ac2.stream);
+    analyser2.enableDebugCanvas();
+    await analyser2.waitForAnalysisSuccess( array => {
+      const freg_50Hz   = array[analyser2.binIndexForFrequency(50)];
+      const freq_rate2  = array[analyser2.binIndexForFrequency(rate2)];
+      const freq_4000Hz = array[analyser2.binIndexForFrequency(4000)];
+
+      info("Analysing audio frequency - low:target2:high = "
+              + freg_50Hz + ':' + freq_rate2 + ':' + freq_4000Hz);
+      return freg_50Hz < 50 && freq_rate2 > 200 && freq_4000Hz < 50;
+    })
+    osc_ac2.stop();
+
+    // Two AudioContexts with different sample rate cannot communicate.
+    mustThrowWith("Connect nodes with different sample rate", "NotSupportedError",
+                  () => {let source_ac2 = ac2.createMediaStreamSource(dest_ac1.stream)});
+
+    // Two AudioContext with the same sample rate can communicate.
+    let ac3 = new AudioContext({sampleRate: 48000});
+    let dest_ac3 = ac3.createMediaStreamDestination();
+    let source_ac2 = ac2.createMediaStreamSource(dest_ac3.stream);
+    ok(true, "Connect nodes with the same sample rate is ok");
+  }))
+  .then(() => finish())
+</script>
+</pre>
+</body>
+</html>