Bug 1109728 - Intermittent browser_devices_get_user_media.js | popup WebRTC indicator visible - Got false, expected true. r=Gijs, a=test-only
authorFlorian Quèze <florian@queze.net>
Mon, 13 Apr 2015 16:04:49 +0200
changeset 260233 fe8c5e74565f
parent 260232 90d2538212ab
child 260234 8d4a0b33d32e
push id724
push userryanvm@gmail.com
push date2015-04-23 01:08 +0000
treeherdermozilla-release@db41e8e267ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, test-only
bugs1109728
milestone38.0
Bug 1109728 - Intermittent browser_devices_get_user_media.js | popup WebRTC indicator visible - Got false, expected true. r=Gijs, a=test-only
browser/base/content/test/general/head.js
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -625,16 +625,40 @@ function promiseTabLoadEvent(tab, url, e
  *        Resolved when the new tab has been opened.
  * @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("waiting for a " + url + " window");
+  return new Promise(resolve => {
+    Services.obs.addObserver(function obs(win) {
+      win.QueryInterface(Ci.nsIDOMWindow);
+      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 assertWebRTCIndicatorStatus(expected) {
   let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI;
   let expectedState = expected ? "visible" : "hidden";
   let msg = "WebRTC indicator " + expectedState;
   is(ui.showGlobalIndicator, !!expected, msg);
 
   let expectVideo = false, expectAudio = false, expectScreen = false;
   if (expected) {
@@ -665,16 +689,19 @@ function assertWebRTCIndicatorStatus(exp
             if (e.target == win.document) {
               win.removeEventListener("unload", arguments.callee);
               resolve();
             }
           }, false);
         });
       }
     }
+    if (expected &&
+        !Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator"))
+      yield promiseWindow("chrome://browser/content/webrtcIndicator.xul");
     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") {
@@ -820,9 +847,8 @@ function promiseTopicObserved(aTopic)
   return new Promise((resolve) => {
     Services.obs.addObserver(
       function PTO_observe(aSubject, aTopic, aData) {
         Services.obs.removeObserver(PTO_observe, aTopic);
         resolve({subject: aSubject, data: aData});
       }, aTopic, false);
   });
 }
-