Bug 1270572 - write tests for the umprompted gUM request; r=florian draft
authorMunro Mengjue Chiang <mchiang@mozilla.com>
Thu, 15 Dec 2016 15:41:58 +0800
changeset 450837 26e8ea5ddf5999f3bf6cc0742cb4fda5b0fd3eb2
parent 450836 af0367bfbe920f4aa6c23212117214d5907e90dd
child 539840 ee691de017cfb1ce0edd27c862fedfb61f387279
push id38960
push usermchiang@mozilla.com
push dateMon, 19 Dec 2016 03:19:27 +0000
reviewersflorian
bugs1270572
milestone53.0a1
Bug 1270572 - write tests for the umprompted gUM request; r=florian MozReview-Commit-ID: LwXICrIVAfd
browser/base/content/test/webrtc/browser_devices_get_user_media.js
browser/base/content/test/webrtc/get_user_media.html
browser/base/content/test/webrtc/head.js
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media.js
@@ -39,16 +39,53 @@ var gTests = [
 
     yield indicator;
     yield checkSharingUI({audio: true, video: true});
     yield closeStream();
   }
 },
 
 {
+  desc: "getUserMedia audio+video while page already has live tracks connected to the same devices",
+  run: function* checkAudioVideoWhileLiveTracksExist() {
+    let promise = promisePopupNotificationShown("webRTC-shareDevices");
+    yield promiseRequestDevice(true, true, 0, 0, false);
+    yield promise;
+    yield expectObserverCalled("getUserMedia:request");
+
+    let indicator = promiseIndicatorWindow();
+    yield promiseMessage("ok", () => {
+      PopupNotifications.panel.firstChild.button.click();
+    });
+    yield expectObserverCalled("getUserMedia:response:allow");
+    yield expectObserverCalled("recording-device-events");
+    is((yield getMediaCaptureState()), "CameraAndMicrophone",
+       "expected camera and microphone to be shared");
+
+    yield indicator;
+    yield checkSharingUI({audio: true, video: true});
+
+    promise = promiseMessage("ok");
+    yield promiseRequestDevice(true, true, 0, 0, true);
+    yield promise;
+
+    yield expectObserverCalled("getUserMedia:request");
+    yield promiseNoPopupNotification("webRTC-shareDevices");
+    yield expectObserverCalled("getUserMedia:response:allow");
+    yield expectObserverCalled("recording-device-events");
+    is((yield getMediaCaptureState()), "CameraAndMicrophone",
+       "expected camera and microphone to be shared");
+
+    yield checkSharingUI({audio: true, video: true});
+    yield closeStream(false, 0, true);
+    yield closeStream(false, 0, false);
+  }
+},
+
+{
   desc: "getUserMedia audio only",
   run: function* checkAudioOnly() {
     let promise = promisePopupNotificationShown("webRTC-shareDevices");
     yield promiseRequestDevice(true);
     yield promise;
     yield expectObserverCalled("getUserMedia:request");
 
     is(PopupNotifications.getNotification("webRTC-shareDevices").anchorID,
--- a/browser/base/content/test/webrtc/get_user_media.html
+++ b/browser/base/content/test/webrtc/get_user_media.html
@@ -18,38 +18,55 @@ try {
 }
 
 function message(m) {
   document.getElementById("message").innerHTML = m;
   window.parent.postMessage(m, "*");
 }
 
 var gStream;
+var gSecondStream;
 
-function requestDevice(aAudio, aVideo, aShare) {
+function requestDevice(aAudio, aVideo, aShare, aSecondStream) {
   var opts = {video: aVideo, audio: aAudio};
   if (aShare) {
     opts.video = {
       mozMediaSource: aShare,
       mediaSource: aShare
     }
   } else if (useFakeStreams) {
     opts.fake = true;
   }
 
-  window.navigator.mediaDevices.getUserMedia(opts)
-    .then(stream => {
-      gStream = stream;
-      message("ok");
-    }, err => message("error: " + err));
+  if (!aSecondStream) {
+    window.navigator.mediaDevices.getUserMedia(opts)
+      .then(stream => {
+        gStream = stream;
+        message("ok");
+      }, err => message("error: " + err));
+  } else {
+    window.navigator.mediaDevices.getUserMedia(opts)
+      .then(stream => {
+        gSecondStream = stream;
+        message("ok");
+      }, err => message("error: " + err));
+  }
 }
 message("pending");
 
-function closeStream() {
-  if (!gStream)
-    return;
-  gStream.getTracks().forEach(t => t.stop());
-  gStream = null;
-  message("closed");
+function closeStream(aSecondStream) {
+  if (!aSecondStream) {
+    if (!gStream)
+      return;
+    gStream.getTracks().forEach(t => t.stop());
+    gStream = null;
+    message("closed");
+  } else {
+    if (!gSecondStream)
+      return;
+    gSecondStream.getTracks().forEach(t => t.stop());
+    gSecondStream = null;
+    message("closed");
+  }
 }
 </script>
 </body>
 </html>
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -339,49 +339,56 @@ function* stopSharing(aType = "camera") 
   gIdentityHandler._identityPopup.hidden = true;
   yield promiseRecordingEvent;
   yield expectObserverCalled("getUserMedia:revoke");
   yield expectObserverCalled("recording-window-ended");
   yield expectNoObserverCalled();
   yield* checkNotSharing();
 }
 
-function promiseRequestDevice(aRequestAudio, aRequestVideo, aFrameId, aType) {
+function promiseRequestDevice(aRequestAudio, aRequestVideo, aFrameId, aType, aSecondStream) {
   info("requesting devices");
   return ContentTask.spawn(gBrowser.selectedBrowser,
-                           {aRequestAudio, aRequestVideo, aFrameId, aType},
+                           {aRequestAudio, aRequestVideo, aFrameId, aType, aSecondStream},
                            function*(args) {
     let global = content.wrappedJSObject;
     if (args.aFrameId)
       global = global.document.getElementById(args.aFrameId).contentWindow;
-    global.requestDevice(args.aRequestAudio, args.aRequestVideo, args.aType);
+    global.requestDevice(args.aRequestAudio, args.aRequestVideo, args.aType, args.aSecondStream);
   });
 }
 
-function* closeStream(aAlreadyClosed, aFrameId) {
+function* closeStream(aAlreadyClosed, aFrameId, aSecondStream) {
   yield expectNoObserverCalled();
 
   let promises;
   if (!aAlreadyClosed) {
-    promises = [promiseObserverCalled("recording-device-events"),
-                promiseObserverCalled("recording-window-ended")];
+    if (aSecondStream) {
+      promises = [promiseObserverCalled("recording-device-events")];
+    } else {
+      promises = [promiseObserverCalled("recording-device-events"),
+                  promiseObserverCalled("recording-window-ended")];
+    }
   }
 
   info("closing the stream");
-  yield ContentTask.spawn(gBrowser.selectedBrowser, aFrameId, function*(contentFrameId) {
+  yield ContentTask.spawn(gBrowser.selectedBrowser,
+                          {aFrameId, aSecondStream},
+                          function*(args) {
     let global = content.wrappedJSObject;
-    if (contentFrameId)
-      global = global.document.getElementById(contentFrameId).contentWindow;
-    global.closeStream();
+    if (args.aFrameId)
+      global = global.document.getElementById(args.aFrameId).contentWindow;
+    global.closeStream(args.aSecondStream);
   });
 
   if (promises)
     yield Promise.all(promises);
 
-  yield* assertWebRTCIndicatorStatus(null);
+  if (!aSecondStream)
+    yield* assertWebRTCIndicatorStatus(null);
 }
 
 function checkDeviceSelectors(aAudio, aVideo) {
   let micSelector = document.getElementById("webRTC-selectMicrophone");
   if (aAudio)
     ok(!micSelector.hidden, "microphone selector visible");
   else
     ok(micSelector.hidden, "microphone selector hidden");