Bug 1213453 - Update mochitest to expect group id. r=pehrsons
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 08 Mar 2019 11:52:17 +0000
changeset 521026 75033c11fa3c9f10f2697badbf7c0887a5fd7e5b
parent 521025 a90a2cb536f39a37905aeb7c19ae5c04014b290a
child 521027 33c69b500eedc3d30b612887b5e271d11a7a7d6a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1213453
milestone67.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 1213453 - Update mochitest to expect group id. r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D20373
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_enumerateDevices.html
dom/media/tests/mochitest/test_groupId.html
dom/media/webrtc/MediaEngineDefault.cpp
dom/media/webrtc/MediaEngineDefault.h
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -42,16 +42,17 @@ skip-if = toolkit == 'android'  # Bug 11
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_bug1013809.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_dataOnlyBufferedAmountLow.html]
 skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
 [test_dataChannel_noOffer.html]
 [test_enumerateDevices.html]
 [test_enumerateDevices_navigation.html]
+[test_groupId.html]
 [test_ondevicechange.html]
 skip-if = os == 'android' || verify
 [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]
--- a/dom/media/tests/mochitest/test_enumerateDevices.html
+++ b/dom/media/tests/mochitest/test_enumerateDevices.html
@@ -33,19 +33,17 @@ async function mustFailWith(msg, reason,
 }
 
 var gUM = c => navigator.mediaDevices.getUserMedia(c);
 
 var validateDevice = ({kind, label, deviceId, groupId}) => {
   ok(kind == "videoinput" || kind == "audioinput", "Known device kind");
   is(deviceId.length, 44, "deviceId length id as expected for Firefox");
   ok(label.length !== undefined, "Device label: " + label);
-
-  // TODO: s/todo_// once Bug 1213453 is fixed.
-  todo_isnot(groupId, "", "groupId must be present.");
+  isnot(groupId, "", "groupId must be present.");
 }
 
 runTest(async () => {
   await pushPrefs(["media.navigator.streams.fake", true]);
 
   // Validate enumerated devices.
 
   let devices = await navigator.mediaDevices.enumerateDevices();
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_groupId.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <script src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript">
+createHTML({ title: "Test group id of MediaDeviceInfo", bug: "1213453" });
+
+let getDefaultDevices = async () => {
+  let devices = await navigator.mediaDevices.enumerateDevices();
+  is(devices.length, 2, "Two fake devices found.");
+
+  devices.forEach(d => isnot(d.groupId, "", "GroupId is included in every device"));
+
+  let videos = devices.filter(d => d.kind == "videoinput");
+  is(videos.length, 1, "One video device found.");
+  let audios = devices.filter(d => d.kind == "audioinput");
+  is(audios.length, 1, "One microphone device found.");
+
+  return {audio: audios[0], video: videos[0]};
+}
+
+runTest(async () => {
+  // Force fake devices in order to be able to change camera name by pref.
+  await pushPrefs(["media.navigator.streams.fake", true],
+                  ["media.audio_loopback_dev", ""],
+                  ["media.video_loopback_dev", ""]);
+
+  let {audio, video} = await getDefaultDevices();
+
+  /* The low level method to correlate groupIds is by device names.
+   * Use a similar comparison here to verify that it works.
+   * Multiple devices of the same device name are not expected in
+   * automation. */
+  isnot(audio.groupId, video.groupId,"Not the same groupIds");
+  // Change video name to match.
+  await pushPrefs(["media.getusermedia.fake-camera-name", audio.label]);
+  ({audio, video} = await getDefaultDevices());
+  is(audio.groupId, video.groupId, "GroupIds should be the same");
+});
+</script>
+</pre>
+</body>
+</html>
--- a/dom/media/webrtc/MediaEngineDefault.cpp
+++ b/dom/media/webrtc/MediaEngineDefault.cpp
@@ -27,27 +27,49 @@
 #  include "YuvStamper.h"
 #endif
 
 #define DEFAULT_AUDIO_TIMER_MS 10
 namespace mozilla {
 
 using namespace mozilla::gfx;
 
+static nsString DefaultVideoName() {
+  // For the purpose of testing we allow to change the name of the fake device
+  // by pref.
+  nsAutoString cameraNameFromPref;
+  nsresult rv;
+  NS_DispatchToMainThread(
+      NS_NewRunnableFunction(__func__,
+                             [&]() {
+                               rv = Preferences::GetString(
+                                   "media.getusermedia.fake-camera-name",
+                                   cameraNameFromPref);
+                             }),
+      NS_DISPATCH_SYNC);
+
+  if (NS_SUCCEEDED(rv)) {
+    return std::move(cameraNameFromPref);
+  }
+  return NS_LITERAL_STRING(u"Default Video Device");
+}
+
 /**
  * Default video source.
  */
 
 MediaEngineDefaultVideoSource::MediaEngineDefaultVideoSource()
-    : mTimer(nullptr), mMutex("MediaEngineDefaultVideoSource::mMutex") {}
+    : mTimer(nullptr),
+      mMutex("MediaEngineDefaultVideoSource::mMutex"),
+      mName(DefaultVideoName()) {}
 
 MediaEngineDefaultVideoSource::~MediaEngineDefaultVideoSource() {}
 
 nsString MediaEngineDefaultVideoSource::GetName() const {
-  return NS_LITERAL_STRING(u"Default Video Device");
+  return mName;
 }
 
 nsCString MediaEngineDefaultVideoSource::GetUUID() const {
   return NS_LITERAL_CSTRING("1041FCBD-3F12-4F7B-9E9B-1EC556DD5676");
 }
 
 nsString MediaEngineDefaultVideoSource::GetGroupId() const {
   return NS_LITERAL_STRING(u"Default Video Group");
--- a/dom/media/webrtc/MediaEngineDefault.h
+++ b/dom/media/webrtc/MediaEngineDefault.h
@@ -94,16 +94,19 @@ class MediaEngineDefaultVideoSource : pu
   MediaEngineSourceState mState = kReleased;
   RefPtr<layers::Image> mImage;
   RefPtr<SourceMediaStream> mStream;
   TrackID mTrackID = TRACK_NONE;
 
   MediaEnginePrefs mOpts;
   int mCb = 16;
   int mCr = 16;
+
+private:
+  const nsString mName;
 };
 
 class SineWaveGenerator;
 
 class MediaEngineDefaultAudioSource : public MediaEngineSource {
  public:
   MediaEngineDefaultAudioSource();