Bug 1041658 - write tests for the global webrtc sharing indicator, r=Gijs, a=sledru.
authorFlorian Quèze <florian@queze.net>
Fri, 29 Aug 2014 20:47:08 +0200
changeset 217711 0ec4d34c39a53f205d025b3e5c970bbda691ecce
parent 217710 38ba0d3221e5fe54d2a937c0a5c3d98928308222
child 217712 d80de0830f77a0ad1b5debfce556f814cfa90d99
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, sledru
bugs1041658
milestone33.0a2
Bug 1041658 - write tests for the global webrtc sharing indicator, r=Gijs, a=sledru.
browser/base/content/test/general/browser_devices_get_user_media.js
browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
browser/base/content/test/general/head.js
--- a/browser/base/content/test/general/browser_devices_get_user_media.js
+++ b/browser/base/content/test/general/browser_devices_get_user_media.js
@@ -180,46 +180,46 @@ function closeStream(aAlreadyClosed) {
 
   if (!aAlreadyClosed)
     yield promiseObserverCalled("recording-device-events");
 
   yield promiseNoPopupNotification("webRTC-sharingDevices");
   if (!aAlreadyClosed)
     expectObserverCalled("recording-window-ended");
 
-  assertWebRTCIndicatorStatus(false);
+  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");
 
   let cameraSelector = document.getElementById("webRTC-selectCamera");
   if (aVideo)
     ok(!cameraSelector.hidden, "camera selector visible");
   else
     ok(cameraSelector.hidden, "camera selector hidden");
 }
 
-function checkSharingUI() {
+function checkSharingUI(aExpected) {
   yield promisePopupNotification("webRTC-sharingDevices");
 
-  assertWebRTCIndicatorStatus(true);
+  assertWebRTCIndicatorStatus(aExpected);
 }
 
 function checkNotSharing() {
   is(getMediaCaptureState(), "none", "expected nothing to be shared");
 
   ok(!PopupNotifications.getNotification("webRTC-sharingDevices"),
      "no webRTC-sharingDevices popup notification");
 
-  assertWebRTCIndicatorStatus(false);
+  assertWebRTCIndicatorStatus(null);
 }
 
 let gTests = [
 
 {
   desc: "getUserMedia audio+video",
   run: function checkAudioVideo() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
@@ -237,17 +237,17 @@ let gTests = [
     yield promiseMessage("ok", () => {
       PopupNotifications.panel.firstChild.button.click();
     });
     expectObserverCalled("getUserMedia:response:allow");
     expectObserverCalled("recording-device-events");
     is(getMediaCaptureState(), "CameraAndMicrophone",
        "expected camera and microphone to be shared");
 
-    yield checkSharingUI();
+    yield checkSharingUI({audio: true, video: true});
     yield closeStream();
   }
 },
 
 {
   desc: "getUserMedia audio only",
   run: function checkAudioOnly() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
@@ -264,17 +264,17 @@ let gTests = [
 
     yield promiseMessage("ok", () => {
       PopupNotifications.panel.firstChild.button.click();
     });
     expectObserverCalled("getUserMedia:response:allow");
     expectObserverCalled("recording-device-events");
     is(getMediaCaptureState(), "Microphone", "expected microphone to be shared");
 
-    yield checkSharingUI();
+    yield checkSharingUI({audio: true});
     yield closeStream();
   }
 },
 
 {
   desc: "getUserMedia video only",
   run: function checkVideoOnly() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
@@ -291,17 +291,17 @@ let gTests = [
 
     yield promiseMessage("ok", () => {
       PopupNotifications.panel.firstChild.button.click();
     });
     expectObserverCalled("getUserMedia:response:allow");
     expectObserverCalled("recording-device-events");
     is(getMediaCaptureState(), "Camera", "expected camera to be shared");
 
-    yield checkSharingUI();
+    yield checkSharingUI({video: true});
     yield closeStream();
   }
 },
 
 {
   desc: "getUserMedia audio+video, user disables video",
   run: function checkDisableVideo() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
@@ -321,17 +321,17 @@ let gTests = [
     // reset the menuitem to have no impact on the following tests.
     document.getElementById("webRTC-selectCamera-menulist").value = 0;
 
     expectObserverCalled("getUserMedia:response:allow");
     expectObserverCalled("recording-device-events");
     is(getMediaCaptureState(), "Microphone",
        "expected microphone to be shared");
 
-    yield checkSharingUI();
+    yield checkSharingUI({audio: true});
     yield closeStream();
   }
 },
 
 {
   desc: "getUserMedia audio+video, user disables audio",
   run: function checkDisableAudio() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
@@ -351,17 +351,17 @@ let gTests = [
     // reset the menuitem to have no impact on the following tests.
     document.getElementById("webRTC-selectMicrophone-menulist").value = 0;
 
     expectObserverCalled("getUserMedia:response:allow");
     expectObserverCalled("recording-device-events");
     is(getMediaCaptureState(), "Camera",
        "expected microphone to be shared");
 
-    yield checkSharingUI();
+    yield checkSharingUI({video: true});
     yield closeStream();
   }
 },
 
 {
   desc: "getUserMedia audio+video, user disables both audio and video",
   run: function checkDisableAudioVideo() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
@@ -422,17 +422,17 @@ let gTests = [
     yield promiseMessage("ok", () => {
       PopupNotifications.panel.firstChild.button.click();
     });
     expectObserverCalled("getUserMedia:response:allow");
     expectObserverCalled("recording-device-events");
     is(getMediaCaptureState(), "CameraAndMicrophone",
        "expected camera and microphone to be shared");
 
-    yield checkSharingUI();
+    yield checkSharingUI({video: true, audio: true});
 
     PopupNotifications.getNotification("webRTC-sharingDevices").reshow();
     activateSecondaryAction(kActionDeny);
 
     yield promiseObserverCalled("recording-device-events");
     expectObserverCalled("getUserMedia:revoke");
 
     yield promiseNoPopupNotification("webRTC-sharingDevices");
@@ -686,17 +686,17 @@ let gTests = [
 
       // Start sharing what's been requested.
       yield promiseMessage("ok", () => {
         content.wrappedJSObject.requestDevice(aRequestAudio, aRequestVideo);
       });
       expectObserverCalled("getUserMedia:request");
       expectObserverCalled("getUserMedia:response:allow");
       expectObserverCalled("recording-device-events");
-      yield checkSharingUI();
+      yield checkSharingUI({video: aRequestVideo, audio: aRequestAudio});
 
       PopupNotifications.getNotification("webRTC-sharingDevices").reshow();
       let expectedIcon = "webRTC-sharingDevices";
       if (aRequestAudio && !aRequestVideo)
         expectedIcon = "webRTC-sharingMicrophone";
       is(PopupNotifications.getNotification("webRTC-sharingDevices").anchorID,
          expectedIcon + "-notification-icon", "anchored to correct icon");
       is(PopupNotifications.panel.firstChild.getAttribute("popupid"), expectedIcon,
@@ -740,16 +740,56 @@ let gTests = [
     info("request audio, stop sharing resets audio only");
     yield stopAndCheckPerm(true, false);
     info("request video, stop sharing resets video only");
     yield stopAndCheckPerm(false, true);
   }
 },
 
 {
+  desc: "test showSharingDoorhanger",
+  run: function checkShowSharingDoorhanger() {
+    yield promisePopupNotificationShown("webRTC-shareDevices", () => {
+      info("requesting devices");
+      content.wrappedJSObject.requestDevice(false, true);
+    });
+    expectObserverCalled("getUserMedia:request");
+    checkDeviceSelectors(false, true);
+
+    yield promiseMessage("ok", () => {
+      PopupNotifications.panel.firstChild.button.click();
+    });
+    expectObserverCalled("getUserMedia:response:allow");
+    expectObserverCalled("recording-device-events");
+    is(getMediaCaptureState(), "Camera", "expected camera to be shared");
+
+    yield checkSharingUI({video: true});
+
+    yield promisePopupNotificationShown("webRTC-sharingDevices", () => {
+      if ("nsISystemStatusBar" in Ci) {
+        let activeStreams = gWebRTCUI.getActiveStreams(true, false, false);
+        gWebRTCUI.showSharingDoorhanger(activeStreams[0], "Devices");
+      }
+      else {
+        let win =
+          Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator");
+        let elt = win.document.getElementById("audioVideoButton");
+        EventUtils.synthesizeMouseAtCenter(elt, {}, win);
+      }
+    });
+
+    PopupNotifications.panel.firstChild.button.click();
+    ok(!PopupNotifications.isPanelOpen, "notification panel closed");
+    expectNoObserverCalled();
+
+    yield closeStream();
+  }
+},
+
+{
   desc: "'Always Allow' ignored and not shown on http pages",
   run: function checkNoAlwaysOnHttp() {
     // Load an http page instead of the https version.
     let deferred = Promise.defer();
     let browser = gBrowser.selectedTab.linkedBrowser;
     browser.addEventListener("load", function onload() {
       browser.removeEventListener("load", onload, true);
       deferred.resolve();
--- a/browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
+++ b/browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
@@ -117,17 +117,17 @@ function closeStream(aAlreadyClosed) {
 
   if (!aAlreadyClosed)
     yield promiseObserverCalled("recording-device-events");
 
   yield promiseNoPopupNotification("webRTC-sharingDevices");
   if (!aAlreadyClosed)
     expectObserverCalled("recording-window-ended");
 
-  assertWebRTCIndicatorStatus(false);
+  assertWebRTCIndicatorStatus(null);
 }
 
 function loadPage(aUrl) {
   let deferred = Promise.defer();
 
   gTab.linkedBrowser.addEventListener("load", function onload() {
     gTab.linkedBrowser.removeEventListener("load", onload, true);
 
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -541,10 +541,39 @@ function promiseTabLoadEvent(tab, url, e
   if (url)
     tab.linkedBrowser.loadURI(url);
   return deferred.promise;
 }
 
 function assertWebRTCIndicatorStatus(expected) {
   let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI;
   let msg = "WebRTC indicator " + (expected ? "visible" : "hidden");
-  is(ui.showGlobalIndicator, expected, msg);
+  is(ui.showGlobalIndicator, !!expected, msg);
+
+  let expectVideo = false, expectAudio = false, expectScreen = false;
+  if (expected) {
+    if (expected.video)
+      expectVideo = true;
+    if (expected.audio)
+      expectAudio = true;
+    if (expected.screen)
+      expectScreen = true;
+  }
+  is(ui.showCameraIndicator, expectVideo, "camera global indicator as expected");
+  is(ui.showMicrophoneIndicator, expectAudio, "microphone global indicator as expected");
+  is(ui.showScreenSharingIndicator, expectScreen, "screen global indicator as expected");
+
+  if (!("nsISystemStatusBar" in Ci)) {
+    let indicator = Services.wm.getEnumerator("Browser:WebRTCGlobalIndicator");
+    let hasWindow = indicator.hasMoreElements();
+    is(hasWindow, !!expected, "popup " + msg);
+    if (hasWindow) {
+      let docElt = indicator.getNext().document.documentElement;
+      for (let item of ["video", "audio", "screen"]) {
+        let expectedValue = (expected && expected[item]) ? "true" : "";
+        is(docElt.getAttribute("sharing" + item), expectedValue,
+           item + " global indicator attribute as expected");
+      }
+
+      ok(!indicator.hasMoreElements(), "only one global indicator window");
+    }
+  }
 }