Bug 948092 - Random failure in test_largemenu.xul. r=roc, a=test-only
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Wed, 15 Jan 2014 14:00:44 +0200
changeset 175747 2438db0b749f18af2eaf44725678a9ed99d72e6a
parent 175746 fdddb77835762992a8f60d35454b17a51092bca3
child 175748 2abe1f3609bd1715ca3019196cc7e479c6d370bf
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, test-only
bugs948092
milestone28.0a2
Bug 948092 - Random failure in test_largemenu.xul. r=roc, a=test-only
toolkit/content/tests/chrome/window_largemenu.xul
toolkit/content/tests/widgets/popup_shared.js
--- a/toolkit/content/tests/chrome/window_largemenu.xul
+++ b/toolkit/content/tests/chrome/window_largemenu.xul
@@ -38,16 +38,26 @@ function getScreenXY(element)
   // a hacky way to get the screen position of an element without using the box object
   window.addEventListener("mousedown", mouseFn, false);
   synthesizeMouse(element, 1, 1, { });
   window.removeEventListener("mousedown", mouseFn, false);
 
   return [screenX, screenY];
 }
 
+function hidePopup() {
+  window.requestAnimationFrame(
+    function() {
+      setTimeout(
+        function() {
+          document.getElementById("popup").hidePopup();
+        }, 0);
+    });
+}
+
 function runTests()
 {
   [, gScreenY] = getScreenXY(document.documentElement);
   nextTest();
 }
 
 function nextTest()
 {
@@ -68,17 +78,22 @@ function nextTest()
       popup.appendChild(menu);
     }
   }
   else if (gTestIndex == 4) {
     for (var t = 1; t <= 30; t++)
       popup.removeChild(popup.lastChild);
   }
 
-  popup.openPopupAtScreen(100, y, false);
+  window.requestAnimationFrame(function() {
+    setTimeout(
+      function() {
+        popup.openPopupAtScreen(100, y, false);
+      }, 0);
+  });
 }
 
 function popupShown()
 {
   if (gTests[gTestIndex] == "menu movement")
     return testPopupMovement();
 
   if (gContextMenuTests)
@@ -129,17 +144,17 @@ function popupShown()
                                 gTests[gTestIndex] + " bottom");
     ok(!gOverflowed && gUnderflowed, gTests[gTestIndex] + " overflow")
   }
 
   var sx = { }, sy = { };
   sbo.getPosition(sx, sy);
   is(sy.value, expectedScrollPos, "menu scroll position");
 
-  popup.hidePopup();
+  hidePopup();
 }
 
 function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
 function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }
 
 var oldx, oldy, waitSteps = 0;
 function moveWindowTo(x, y, callback, arg)
 {
@@ -221,17 +236,17 @@ function contextMenuPopupShown()
       ok(rect.top == pos || rect.top == availPos,
          gTests[gTestIndex] + " top");
       break;
     case "context menu larger than screen":
       ok(rect.top == -(gScreenY - screen.availTop) || rect.top == -(gScreenY - screen.top), gTests[gTestIndex] + " top");
       break;
   }
 
-  popup.hidePopup();
+  hidePopup();
 }
 
 function contextMenuPopupHidden()
 {
   var screenAvailBottom = screen.availTop + screen.availHeight;
 
   if (gTests[gTestIndex] == "context menu more space above") {
     moveWindowTo(window.screenX, screenAvailBottom - 80, nextContextMenuTest, -1);
--- a/toolkit/content/tests/widgets/popup_shared.js
+++ b/toolkit/content/tests/widgets/popup_shared.js
@@ -205,16 +205,27 @@ function goNextStep()
     }
   }
 
   goNext();
 }
 
 function goNext()
 {
+  // We want to continue after the next animation frame so that
+  // we're in a stable state and don't get spurious mouse events at unexpected targets.
+  window.requestAnimationFrame(
+    function() {
+      setTimeout(goNextStepSync, 0);
+    }
+  );
+}
+
+function goNextStepSync()
+{
   if (gTestIndex >= 0 && "end" in gPopupTests[gTestIndex] && gPopupTests[gTestIndex].end) {
     finish();
     return;
   }
 
   gTestIndex++;
   gTestStepIndex = 0;
   if (gTestIndex < gPopupTests.length) {