Bug 1404977 - Tests P2: Add test to ensure multiple gUM calls in a single window will work. r?pehrsons draft
authorBryce Van Dyk <bvandyk@mozilla.com>
Fri, 27 Apr 2018 18:34:59 -0400
changeset 800923 e9e19f4b8477fc3a03d17b88caec06d949aa336c
parent 800922 a03d5d4f274ee4ac162a24996eebc390ea43774c
push id111515
push userbvandyk@mozilla.com
push dateTue, 29 May 2018 13:48:26 +0000
reviewerspehrsons
bugs1404977
milestone62.0a1
Bug 1404977 - Tests P2: Add test to ensure multiple gUM calls in a single window will work. r?pehrsons MozReview-Commit-ID: 8ESMN0rNBTE
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_multipleStreamsDifferentConstraints.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -82,16 +82,18 @@ skip-if = android_version == '18' # andr
 [test_getUserMedia_mediaElementCapture_video.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_mediaStreamClone.html]
 skip-if = toolkit == 'android' && debug # Bug 1282262
 [test_getUserMedia_mediaStreamConstructors.html]
 [test_getUserMedia_mediaStreamTrackClone.html]
 [test_getUserMedia_multipleIframes.html]
 skip-if = os == 'mac' || os == 'win' || toolkit == 'android' # Bug 1404995, no loopback devices on some platforms
+[test_getUserMedia_multipleStreamsDifferentConstraints.html]
+skip-if = os == 'mac' || os == 'win' || toolkit == 'android' # Bug 1404995, no loopback devices on some platforms
 [test_getUserMedia_playAudioTwice.html]
 [test_getUserMedia_playVideoAudioTwice.html]
 [test_getUserMedia_playVideoTwice.html]
 [test_getUserMedia_scarySources.html]
 skip-if = toolkit == 'android' # no screenshare or windowshare on android
 [test_getUserMedia_spinEventLoop.html]
 [test_getUserMedia_stopAudioStream.html]
 [test_getUserMedia_stopAudioStreamWithFollowupAudio.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_multipleStreamsDifferentConstraints.html
@@ -0,0 +1,91 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+  createHTML({
+    title: "getUserMedia Multiple Times with Different Constraints",
+    bug: "1404977"
+  });
+  /**
+   * Verify that multiple gUM calls with different constaints can be performed
+   */
+  runTest(async function() {
+    // Compare constraints and return a string with the differences in
+    // echoCancellation, autoGainControl, and noiseSuppression. The string
+    // will be empty if there are no differences.
+    function getConstraintDifferenceString(constraints, otherConstraints) {
+      let diffString = "";
+      if (constraints.echoCancellation != otherConstraints.echoCancellation) {
+        diffString += "echoCancellation different, ";
+      }
+      if (constraints.autoGainControl != otherConstraints.autoGainControl) {
+        diffString += "autoGainControl different, ";
+      }
+      if (constraints.noiseSuppression != otherConstraints.noiseSuppression) {
+        diffString += "noiseSuppression different, ";
+      }
+      // Replace trailing comma and space if any
+      return diffString.replace(/, $/, "");
+    }
+
+    // We need a real device to get a MediaEngine supporting constraints
+    let audioDevice = SpecialPowers.getCharPref("media.audio_loopback_dev", "");
+    if (!audioDevice) {
+      ok(false, "No device set by framework. Try --use-test-media-devices");
+      return;
+    }
+
+    let requestedConstraints = [
+      true,
+      { echoCancellation: true },
+      { autoGainControl: true },
+      { noiseSuppression: true },
+      { echoCancellation: true, autoGainControl: true },
+      { echoCancellation: true, autoGainControl: true, noiseSuppression: true },
+    ];
+    let gumStreams = [];
+    let playMediaPromises = [];
+
+    for (let i = 0; i < requestedConstraints.length; i++) {
+      try {
+        let stream = await getUserMedia({audio: requestedConstraints[i]});
+        gumStreams.push(stream);
+        let differenceString = getConstraintDifferenceString(
+          requestedConstraints[i],
+          stream.getAudioTracks()[0].getSettings());
+        ok(!differenceString,
+          `Stream at index ${i} should have the same constraints as were ` +
+          `requested from gUM. Differences: ${differenceString}`);
+      } catch (e) {
+        ok(false, `getUserMedia calls should not fail! Failed at call#: ${i} with: ${e}!`);
+      }
+    }
+    is(gumStreams.length, requestedConstraints.length, "Should have a stream for each constraint");
+
+    // For each stream we've got from a gUM call make sure the constraints
+    // haven't been mutated by other gUM calls
+    for (let i = 0; i < gumStreams.length; i++) {
+      let differenceString = getConstraintDifferenceString(
+        requestedConstraints[i],
+        gumStreams[i].getAudioTracks()[0].getSettings());
+      ok(!differenceString,
+        `Stream at index ${i} should not have had constraints altered after ` +
+        `all gUM calls are done. Differences: ${differenceString}`);
+    }
+
+    for (let i = 0; i < gumStreams.length; i++) {
+      let testAudio = createMediaElement("audio", `testAudio${i}`);
+      let playback = new LocalMediaStreamPlayback(testAudio, gumStreams[i]);
+      playMediaPromises.push(playback.playMedia(false));
+    }
+
+    await Promise.all(playMediaPromises);
+  });
+</script>
+</pre>
+</body>
+</html>
\ No newline at end of file