Bug 1281427 - move browser_devices_* tests to a webrtc folder, r=Gijs.
authorFlorian Quèze <florian@queze.net>
Mon, 27 Jun 2016 12:23:57 +0200
changeset 381553 587632fc8560f2fc8fb81097eb1fa291609b0bae
parent 381552 3f257dd4c81aaa3ef5d4db262d1ffd7eadd3e7fe
child 381554 c2df79b7e04db32eff4fe14d0c91b46c67ef4684
push id21509
push userfelipc@gmail.com
push dateMon, 27 Jun 2016 19:25:05 +0000
reviewersGijs
bugs1281427
milestone50.0a1
Bug 1281427 - move browser_devices_* tests to a webrtc folder, r=Gijs.
browser/base/content/test/general/browser.ini
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/browser_devices_get_user_media_anim.js
browser/base/content/test/general/browser_devices_get_user_media_in_frame.js
browser/base/content/test/general/get_user_media.html
browser/base/content/test/general/get_user_media_content_script.js
browser/base/content/test/general/get_user_media_helpers.js
browser/base/content/test/general/head.js
browser/base/content/test/webrtc/browser.ini
browser/base/content/test/webrtc/browser_devices_get_user_media.js
browser/base/content/test/webrtc/browser_devices_get_user_media_about_urls.js
browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
browser/base/content/test/webrtc/get_user_media.html
browser/base/content/test/webrtc/get_user_media_content_script.js
browser/base/content/test/webrtc/get_user_media_helpers.js
browser/base/content/test/webrtc/head.js
browser/base/moz.build
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -64,19 +64,16 @@ support-files =
   file_bug970276_popup2.html
   file_bug970276_favicon1.ico
   file_bug970276_favicon2.ico
   file_documentnavigation_frameset.html
   file_double_close_tab.html
   file_favicon_change.html
   file_favicon_change_not_in_document.html
   file_fullscreen-window-open.html
-  get_user_media.html
-  get_user_media_content_script.js
-  get_user_media_helpers.js
   head.js
   healthreport_pingData.js
   healthreport_testRemoteCommands.html
   moz.png
   navigating_window_with_download.html
   offlineQuotaNotification.cacheManifest
   offlineQuotaNotification.html
   page_style_sample.html
@@ -288,22 +285,16 @@ skip-if = toolkit == "gtk2" || toolkit =
 [browser_contextmenu_input.js]
 skip-if = toolkit == "gtk2" || toolkit == "gtk3" # disabled on Linux due to bug 513558
 [browser_ctrlTab.js]
 [browser_datachoices_notification.js]
 skip-if = !datareporting
 [browser_decoderDoctor.js]
 skip-if = os == "mac" # decoder doctor isn't implemented on osx
 [browser_devedition.js]
-[browser_devices_get_user_media.js]
-skip-if = buildapp == 'mulet' || (os == "linux" && debug) # linux: bug 976544
-[browser_devices_get_user_media_about_urls.js]
-skip-if = e10s && debug
-[browser_devices_get_user_media_anim.js]
-[browser_devices_get_user_media_in_frame.js]
 [browser_discovery.js]
 [browser_double_close_tab.js]
 [browser_documentnavigation.js]
 [browser_duplicateIDs.js]
 [browser_drag.js]
 skip-if = true # browser_drag.js is disabled, as it needs to be updated for the new behavior from bug 320638.
 [browser_favicon_change.js]
 [browser_favicon_change_not_in_document.js]
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -654,129 +654,16 @@ function promiseTabLoadEvent(tab, url)
  * @resolves to the TabOpen event that was fired.
  * @rejects Never.
  */
 function waitForNewTabEvent(aTabBrowser) {
   return promiseWaitForEvent(aTabBrowser.tabContainer, "TabOpen");
 }
 
 /**
- * Waits for a window with the given URL to exist.
- *
- * @param url
- *        The url of the window.
- * @return {Promise} resolved when the window exists.
- * @resolves to the window
- */
-function promiseWindow(url) {
-  info("expecting a " + url + " window");
-  return new Promise(resolve => {
-    Services.obs.addObserver(function obs(win) {
-      win.QueryInterface(Ci.nsIDOMWindow);
-      win.addEventListener("load", function loadHandler() {
-        win.removeEventListener("load", loadHandler);
-
-        if (win.location.href !== url) {
-          info("ignoring a window with this url: " + win.location.href);
-          return;
-        }
-
-        Services.obs.removeObserver(obs, "domwindowopened");
-        resolve(win);
-      });
-    }, "domwindowopened", false);
-  });
-}
-
-function promiseIndicatorWindow() {
-  // We don't show the indicator window on Mac.
-  if ("nsISystemStatusBar" in Ci)
-    return Promise.resolve();
-
-  return promiseWindow("chrome://browser/content/webrtcIndicator.xul");
-}
-
-function assertWebRTCIndicatorStatus(expected) {
-  let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI;
-  let expectedState = expected ? "visible" : "hidden";
-  let msg = "WebRTC indicator " + expectedState;
-  if (!expected && ui.showGlobalIndicator) {
-    // It seems the global indicator is not always removed synchronously
-    // in some cases.
-    info("waiting for the global indicator to be hidden");
-    yield promiseWaitForCondition(() => !ui.showGlobalIndicator);
-  }
-  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");
-
-  let windows = Services.wm.getEnumerator("navigator:browser");
-  while (windows.hasMoreElements()) {
-    let win = windows.getNext();
-    let menu = win.document.getElementById("tabSharingMenu");
-    is(menu && !menu.hidden, !!expected, "WebRTC menu should be " + expectedState);
-  }
-
-  if (!("nsISystemStatusBar" in Ci)) {
-    if (!expected) {
-      let win = Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator");
-      if (win) {
-        yield new Promise((resolve, reject) => {
-          win.addEventListener("unload", function listener(e) {
-            if (e.target == win.document) {
-              win.removeEventListener("unload", listener);
-              resolve();
-            }
-          }, false);
-        });
-      }
-    }
-    let indicator = Services.wm.getEnumerator("Browser:WebRTCGlobalIndicator");
-    let hasWindow = indicator.hasMoreElements();
-    is(hasWindow, !!expected, "popup " + msg);
-    if (hasWindow) {
-      let document = indicator.getNext().document;
-      let docElt = document.documentElement;
-
-      if (document.readyState != "complete") {
-        info("Waiting for the sharing indicator's document to load");
-        let deferred = Promise.defer();
-        document.addEventListener("readystatechange",
-                                  function onReadyStateChange() {
-          if (document.readyState != "complete")
-            return;
-          document.removeEventListener("readystatechange", onReadyStateChange);
-          deferred.resolve();
-        });
-        yield deferred.promise;
-      }
-
-      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");
-    }
-  }
-}
-
-/**
  * Test the state of the identity box and control center to make
  * sure they are correctly showing the expected mixed content states.
  *
  * @note The checks are done synchronously, but new code should wait on the
  *       returned Promise object to ensure the identity panel has closed.
  *       Bug 1221114 is filed to fix the existing code.
  *
  * @param tabbrowser
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/webrtc/browser.ini
@@ -0,0 +1,13 @@
+[DEFAULT]
+support-files =
+  get_user_media.html
+  get_user_media_content_script.js
+  get_user_media_helpers.js
+  head.js
+
+[browser_devices_get_user_media.js]
+skip-if = buildapp == 'mulet' || (os == "linux" && debug) # linux: bug 976544
+[browser_devices_get_user_media_about_urls.js]
+skip-if = e10s && debug
+[browser_devices_get_user_media_anim.js]
+[browser_devices_get_user_media_in_frame.js]
rename from browser/base/content/test/general/browser_devices_get_user_media.js
rename to browser/base/content/test/webrtc/browser_devices_get_user_media.js
rename from browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
rename to browser/base/content/test/webrtc/browser_devices_get_user_media_about_urls.js
rename from browser/base/content/test/general/browser_devices_get_user_media_anim.js
rename to browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
rename from browser/base/content/test/general/browser_devices_get_user_media_in_frame.js
rename to browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
rename from browser/base/content/test/general/get_user_media.html
rename to browser/base/content/test/webrtc/get_user_media.html
rename from browser/base/content/test/general/get_user_media_content_script.js
rename to browser/base/content/test/webrtc/get_user_media_content_script.js
rename from browser/base/content/test/general/get_user_media_helpers.js
rename to browser/base/content/test/webrtc/get_user_media_helpers.js
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/webrtc/head.js
@@ -0,0 +1,172 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Promise",
+  "resource://gre/modules/Promise.jsm");
+
+function waitForCondition(condition, nextTest, errorMsg, retryTimes) {
+  retryTimes = typeof retryTimes !== 'undefined' ?  retryTimes : 30;
+  var tries = 0;
+  var interval = setInterval(function() {
+    if (tries >= retryTimes) {
+      ok(false, errorMsg);
+      moveOn();
+    }
+    var conditionPassed;
+    try {
+      conditionPassed = condition();
+    } catch (e) {
+      ok(false, e + "\n" + e.stack);
+      conditionPassed = false;
+    }
+    if (conditionPassed) {
+      moveOn();
+    }
+    tries++;
+  }, 100);
+  var moveOn = function() { clearInterval(interval); nextTest(); };
+}
+
+function promiseWaitForCondition(aConditionFn) {
+  let deferred = Promise.defer();
+  waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass.");
+  return deferred.promise;
+}
+
+/**
+ * Waits for a window with the given URL to exist.
+ *
+ * @param url
+ *        The url of the window.
+ * @return {Promise} resolved when the window exists.
+ * @resolves to the window
+ */
+function promiseWindow(url) {
+  info("expecting a " + url + " window");
+  return new Promise(resolve => {
+    Services.obs.addObserver(function obs(win) {
+      win.QueryInterface(Ci.nsIDOMWindow);
+      win.addEventListener("load", function loadHandler() {
+        win.removeEventListener("load", loadHandler);
+
+        if (win.location.href !== url) {
+          info("ignoring a window with this url: " + win.location.href);
+          return;
+        }
+
+        Services.obs.removeObserver(obs, "domwindowopened");
+        resolve(win);
+      });
+    }, "domwindowopened", false);
+  });
+}
+
+function promiseIndicatorWindow() {
+  // We don't show the indicator window on Mac.
+  if ("nsISystemStatusBar" in Ci)
+    return Promise.resolve();
+
+  return promiseWindow("chrome://browser/content/webrtcIndicator.xul");
+}
+
+function assertWebRTCIndicatorStatus(expected) {
+  let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI;
+  let expectedState = expected ? "visible" : "hidden";
+  let msg = "WebRTC indicator " + expectedState;
+  if (!expected && ui.showGlobalIndicator) {
+    // It seems the global indicator is not always removed synchronously
+    // in some cases.
+    info("waiting for the global indicator to be hidden");
+    yield promiseWaitForCondition(() => !ui.showGlobalIndicator);
+  }
+  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");
+
+  let windows = Services.wm.getEnumerator("navigator:browser");
+  while (windows.hasMoreElements()) {
+    let win = windows.getNext();
+    let menu = win.document.getElementById("tabSharingMenu");
+    is(menu && !menu.hidden, !!expected, "WebRTC menu should be " + expectedState);
+  }
+
+  if (!("nsISystemStatusBar" in Ci)) {
+    if (!expected) {
+      let win = Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator");
+      if (win) {
+        yield new Promise((resolve, reject) => {
+          win.addEventListener("unload", function listener(e) {
+            if (e.target == win.document) {
+              win.removeEventListener("unload", listener);
+              resolve();
+            }
+          }, false);
+        });
+      }
+    }
+    let indicator = Services.wm.getEnumerator("Browser:WebRTCGlobalIndicator");
+    let hasWindow = indicator.hasMoreElements();
+    is(hasWindow, !!expected, "popup " + msg);
+    if (hasWindow) {
+      let document = indicator.getNext().document;
+      let docElt = document.documentElement;
+
+      if (document.readyState != "complete") {
+        info("Waiting for the sharing indicator's document to load");
+        let deferred = Promise.defer();
+        document.addEventListener("readystatechange",
+                                  function onReadyStateChange() {
+          if (document.readyState != "complete")
+            return;
+          document.removeEventListener("readystatechange", onReadyStateChange);
+          deferred.resolve();
+        });
+        yield deferred.promise;
+      }
+
+      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");
+    }
+  }
+}
+
+function promisePopupEvent(popup, eventSuffix) {
+  let endState = {shown: "open", hidden: "closed"}[eventSuffix];
+
+  if (popup.state == endState)
+    return Promise.resolve();
+
+  let eventType = "popup" + eventSuffix;
+  let deferred = Promise.defer();
+  popup.addEventListener(eventType, function onPopupShown(event) {
+    popup.removeEventListener(eventType, onPopupShown);
+    deferred.resolve();
+  });
+
+  return deferred.promise;
+}
+
+function promiseNotificationShown(notification) {
+  let win = notification.browser.ownerDocument.defaultView;
+  if (win.PopupNotifications.panel.state == "open") {
+    return Promise.resolve();
+  }
+  let panelPromise = promisePopupEvent(win.PopupNotifications.panel, "shown");
+  notification.reshow();
+  return panelPromise;
+}
--- a/browser/base/moz.build
+++ b/browser/base/moz.build
@@ -20,16 +20,17 @@ BROWSER_CHROME_MANIFESTS += [
     'content/test/general/browser.ini',
     'content/test/newtab/browser.ini',
     'content/test/plugins/browser.ini',
     'content/test/popupNotifications/browser.ini',
     'content/test/referrer/browser.ini',
     'content/test/social/browser.ini',
     'content/test/tabPrompts/browser.ini',
     'content/test/urlbar/browser.ini',
+    'content/test/webrtc/browser.ini',
 ]
 
 DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']
 DEFINES['MOZ_APP_VERSION_DISPLAY'] = CONFIG['MOZ_APP_VERSION_DISPLAY']
 
 DEFINES['APP_LICENSE_BLOCK'] = '%s/content/overrides/app-license.html' % SRCDIR
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('windows', 'gtk2', 'gtk3', 'cocoa'):