Bug 1447982 - Add mochitest for audio constraints. r=jib, a=jcristau
authorAndreas Pehrson <pehrsons@mozilla.com>
Wed, 11 Apr 2018 16:05:49 +0200
changeset 463292 15079c3a4d0f9ca29cf4d737c7b112cbb409e741
parent 463291 9e8eacca6e47f0b0a515260c85b5a691a391c8e4
child 463293 821855807c5b55884306ffe17c8b1e26e5d876eb
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, jcristau
bugs1447982
milestone60.0
Bug 1447982 - Add mochitest for audio constraints. r=jib, a=jcristau MozReview-Commit-ID: DGlvTW6EXAO
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_audioConstraints.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -46,16 +46,18 @@ skip-if = true # needed by test_enumerat
 skip-if = os == 'android'
 [test_getUserMedia_active_autoplay.html]
 [test_getUserMedia_audioCapture.html]
 skip-if = toolkit == 'android' # android(Bug 1189784, timeouts on 4.3 emulator), android(Bug 1264333)
 [test_getUserMedia_addTrackRemoveTrack.html]
 skip-if = android_version == '18' || os == 'linux' # android(Bug 1189784, timeouts on 4.3 emulator), linux bug 1377450
 [test_getUserMedia_addtrack_removetrack_events.html]
 skip-if = os == 'linux' && debug # Bug 1389983
+[test_getUserMedia_audioConstraints.html]
+skip-if = os == 'mac' || os == 'win' || toolkit == 'android' # Bug 1404995, no loopback devices on some platforms
 [test_getUserMedia_basicAudio_loopback.html]
 skip-if = os == 'mac' || os == 'win' || toolkit == 'android' # Bug 1404995, no loopback devices on some platforms
 [test_getUserMedia_basicAudio.html]
 [test_getUserMedia_basicVideo.html]
 [test_getUserMedia_basicVideo_playAfterLoadedmetadata.html]
 [test_getUserMedia_basicScreenshare.html]
 skip-if = toolkit == 'android' || (webrender && toolkit == 'windows') # no screenshare on android; bug 1405083 permafail on webrender
 [test_getUserMedia_basicTabshare.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_audioConstraints.html
@@ -0,0 +1,93 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+"use strict";
+
+createHTML({
+  title: "Test that microphone getSettings report correct settings after applyConstraints",
+  bug: "1447982",
+});
+
+function testTrackAgainstAudioConstraints(track, audioConstraints) {
+  let constraints = track.getConstraints();
+  is(constraints.autoGainControl, audioConstraints.autoGainControl,
+     "Should report correct autoGainControl constraint");
+  is(constraints.echoCancellation, audioConstraints.echoCancellation,
+     "Should report correct echoCancellation constraint");
+  is(constraints.noiseSuppression, audioConstraints.noiseSuppression,
+     "Should report correct noiseSuppression constraint");
+
+  let settings = track.getSettings();
+  is(settings.autoGainControl, audioConstraints.autoGainControl,
+     "Should report correct autoGainControl setting");
+  is(settings.echoCancellation, audioConstraints.echoCancellation,
+     "Should report correct echoCancellation setting");
+  is(settings.noiseSuppression, audioConstraints.noiseSuppression,
+     "Should report correct noiseSuppression setting");
+}
+
+async function testAudioConstraints(track, audioConstraints) {
+  // We applyConstraints() first and do a fresh gUM later, to avoid
+  // testing multiple concurrent captures at different settings.
+
+  info(`Testing applying constraints ${JSON.stringify(audioConstraints)} ` +
+       `to track with settings ${JSON.stringify(track.getSettings())}`);
+  await track.applyConstraints(audioConstraints);
+  testTrackAgainstAudioConstraints(track, audioConstraints);
+
+  info("Testing fresh gUM request with audio constraints " +
+       JSON.stringify(audioConstraints));
+  let stream = await getUserMedia({audio: audioConstraints});
+  testTrackAgainstAudioConstraints(stream.getTracks()[0], audioConstraints);
+  stream.getTracks().forEach(t => t.stop());
+}
+
+runTest(async () => {
+  let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
+  if (!audioDevice) {
+    ok(false, "No device set by framework. Try --use-test-media-devices");
+    return;
+  }
+
+  let supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
+  is(supportedConstraints.autoGainControl, true,
+     "autoGainControl constraint should be supported");
+  is(supportedConstraints.echoCancellation, true,
+     "echoCancellation constraint should be supported");
+  is(supportedConstraints.noiseSuppression, true,
+     "noiseSuppression constraint should be supported");
+
+  let egn = (e, g, n) => ({
+    echoCancellation: e,
+    autoGainControl: g,
+    noiseSuppression: n
+  });
+
+  let stream = await getUserMedia({
+    audio: egn(true, true, true),
+  });
+  let track = stream.getTracks()[0];
+  let audioConstraintsToTest = [
+    egn(false, true,  true),
+    egn(true,  false, true),
+    egn(true,  true,  false),
+    egn(false, false, true),
+    egn(false, true,  false),
+    egn(true,  false, false),
+    egn(false, false, false),
+    egn(true,  true,  true),
+  ];
+  for (let audioConstraints of audioConstraintsToTest) {
+    await testAudioConstraints(track, audioConstraints);
+  }
+  track.stop();
+});
+</script>
+</pre>
+</body>
+</html>