Bug 1443525 - Add mochitests to test gUM when a cubeb context cannot be obtained. r?padenot draft
authorBryce Van Dyk <bvandyk@mozilla.com>
Tue, 20 Mar 2018 16:46:33 -0400
changeset 776631 b5d6ce13d79c677163105d5ece7081d17127d21c
parent 776630 0a54d7b7924647d1bb991fcf3fffaf71b252c300
push id104929
push userbvandyk@mozilla.com
push dateTue, 03 Apr 2018 14:09:16 +0000
reviewerspadenot
bugs1443525
milestone61.0a1
Bug 1443525 - Add mochitests to test gUM when a cubeb context cannot be obtained. r?padenot Add two mochitests to provide coverage for getUserMedia when getting a cubeb context fails. - The first test checks that gUM fails with no audio devices returned. In normal circumstances, without cubeb we do not expect devices to be available. Android is a notable exception here, due to it having a number of different code paths during enumaration, and the test attempts to accomodate this. - The second test checks that if fake streams are enabled, gUM will still return a stream and that this stream can be used. MozReview-Commit-ID: Fn6rGi6W9hM
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_getUserMedia_cubebDisabled.html
dom/media/tests/mochitest/test_getUserMedia_cubebDisabledFakeStreams.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -62,16 +62,18 @@ skip-if = toolkit == 'android' || (webre
 [test_getUserMedia_basicTabshare.html]
 skip-if = toolkit == 'android' # no windowshare on android
 [test_getUserMedia_basicWindowshare.html]
 skip-if = toolkit == 'android' # no windowshare on android
 [test_getUserMedia_basicVideoAudio.html]
 [test_getUserMedia_bug1223696.html]
 [test_getUserMedia_constraints.html]
 [test_getUserMedia_callbacks.html]
+[test_getUserMedia_cubebDisabled.html]
+[test_getUserMedia_cubebDisabledFakeStreams.html]
 [test_getUserMedia_GC_MediaStream.html]
 [test_getUserMedia_getTrackById.html]
 [test_getUserMedia_gumWithinGum.html]
 [test_getUserMedia_loadedmetadata.html]
 [test_getUserMedia_mediaElementCapture_audio.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_getUserMedia_mediaElementCapture_tracks.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_cubebDisabled.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+  createHTML({
+    title: "getUserMedia with Cubeb Disabled Test",
+    bug: "1443525"
+  });
+  /**
+   * Run a test to verify we fail gracefully if we cannot fetch a cubeb context
+   * during a gUM call.
+   */
+  runTest(async function () {
+    info("Get user media with cubeb disabled starting");
+    // Push prefs to ensure no cubeb context and no fake streams.
+    await pushPrefs(["media.cubeb.force_null_context", true],
+                    ["media.navigator.streams.fake", false]);
+
+    // Android has its own codepath which means it works even when cubeb is
+    // disabled. For examples see MediaEngineWebRTC::GetNumOfRecordingDevices and
+    // MediaEngineWebRTC::GetRecordingDeviceName.
+    let isAndroid = navigator.appVersion.includes("Android");
+    // We're on android we expect to get an audio stream, create an elem for it
+    let testAudio = createMediaElement('audio', 'testAudio');
+
+    // Request audio only, to avoid cams
+    let constraints = {audio: true, video: false};
+    let stream;
+    try {
+      stream = await getUserMedia(constraints);
+    } catch (e) {
+      if (isAndroid) {
+        ok(false, `getUserMedia expected to succeed on android, even with null cubeb context, but got ${e}`);
+        return;
+      }
+      // !isAndroid
+      // We've got no audio backend, so we expect gUM to fail.
+      ok(e.name == "NotFoundError", "Expected NotFoundError due to no audio tracks!");
+      return;
+    }
+    if (isAndroid) {
+      ok(stream, "getUserMedia expected to return a stream on Android even when cubeb context null!");
+      let playback = new LocalMediaStreamPlayback(testAudio, stream);
+      return playback.playMedia(false);
+    }
+    // !isAndroid
+    // If we're not on android we should not have gotten a stream without a cubeb context!
+    ok(false, "getUserMedia not expected to succeed when cubeb is disabled, but it did!");
+  });
+
+
+</script>
+</pre>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_getUserMedia_cubebDisabledFakeStreams.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+  createHTML({
+    title: "getUserMedia fake stream with Cubeb Disabled Test",
+    bug: "1443525"
+  });
+  /**
+   * Run a test to verify we can still return a fake stream even if we cannot
+   * get a cubeb context. See also Bug 1434477
+   */
+  runTest(async function () {
+    info("Get user media with cubeb disabled and fake tracks starting");
+    // Push prefs to ensure no cubeb context and fake streams
+    await pushPrefs(["media.cubeb.force_null_context", true],
+                    ["media.navigator.streams.fake", true],
+                    ['media.audio_loopback_dev', '']);
+    let testAudio = createMediaElement('audio', 'testAudio');
+    // Request audio only, to avoid cams
+    let constraints = {audio: true, video: false};
+    let stream;
+    try {
+      stream = await getUserMedia(constraints);
+    } catch (e) {
+      // We've got no audio backend, so we expect gUM to fail
+      ok(false, `Did not expect to fail, but got ${e}`);
+      return;
+    }
+    ok(stream, "getUserMedia should get a stream!");
+    let playback = new LocalMediaStreamPlayback(testAudio, stream);
+    return playback.playMedia(false);
+  });
+
+
+</script>
+</pre>
+</body>
+</html>