Bug 1384464 - Intermittent browser/base/content/test/urlbar/browser_page_action_menu.js. r=Gijs
authorDrew Willcoxon <adw@mozilla.com>
Mon, 18 Sep 2017 13:01:56 -0700
changeset 666672 a952a23d3f140766157debe6e8fce757f6b67a97
parent 666671 81ae370514fde636b444e41b8c896ae48f0917fa
child 666673 776e2f2b53a2138d84e8c81a24b34c1f191b0c50
push id80486
push userbmo:tlin@mozilla.com
push dateTue, 19 Sep 2017 03:52:30 +0000
reviewersGijs
bugs1384464
milestone57.0a1
Bug 1384464 - Intermittent browser/base/content/test/urlbar/browser_page_action_menu.js. r=Gijs MozReview-Commit-ID: A2rypvJjvcz
browser/base/content/test/urlbar/head.js
--- a/browser/base/content/test/urlbar/head.js
+++ b/browser/base/content/test/urlbar/head.js
@@ -270,23 +270,35 @@ function promisePanelEvent(panelIDOrNode
     }
     panel.addEventListener(eventType, () => {
       executeSoon(resolve);
     }, { once: true });
   });
 }
 
 function promisePageActionViewShown() {
-  return new Promise(resolve => {
-    BrowserPageActions.panelNode.addEventListener("ViewShown", (event) => {
-      let target = event.originalTarget;
-      window.setTimeout(() => {
-        resolve(target);
-      }, 5000);
-    }, { once: true });
+  let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                  .getInterface(Ci.nsIDOMWindowUtils);
+  info("promisePageActionViewShown waiting for ViewShown");
+  return BrowserTestUtils.waitForEvent(BrowserPageActions.panelNode, "ViewShown").then(async event => {
+    let panelViewNode = event.originalTarget;
+    // Wait for the subview to be really truly shown by making sure there's at
+    // least one child with non-zero bounds.
+    info("promisePageActionViewShown waiting for a child node to be visible");
+    await BrowserTestUtils.waitForCondition(() => {
+      let bodyNode = panelViewNode.firstChild;
+      for (let childNode of bodyNode.childNodes) {
+        let bounds = dwu.getBoundsWithoutFlushing(childNode);
+        if (bounds.width > 0 && bounds.height > 0) {
+          return true;
+        }
+      }
+      return false;
+    });
+    return panelViewNode;
   });
 }
 
 function promiseSpeculativeConnection(httpserver) {
   return BrowserTestUtils.waitForCondition(() => {
     if (httpserver) {
       return httpserver.connectionNumber == 1;
     }