Bug 1447982 - Add mochitest for audio constraints. r?jib draft
authorAndreas Pehrson <pehrsons@mozilla.com>
Wed, 11 Apr 2018 16:05:49 +0200
changeset 781062 a647d1638bd3d7f8b6ce1d788255d0fbcdfccdcd
parent 779146 30d72755b1749953d438199456f1524ce84ab5e5
child 781063 86652814519f1a0ae473119ec1f38fe2b69e2dc6
push id106197
push userbmo:apehrson@mozilla.com
push dateThu, 12 Apr 2018 13:32:52 +0000
reviewersjib
bugs1447982
milestone61.0a1
Bug 1447982 - Add mochitest for audio constraints. r?jib 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
@@ -47,16 +47,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>