Bug 1352709 - Fix browser_plainTextLinks.js to work around some context menu issues. r=Gijs
authorJan de Mooij <jdemooij@mozilla.com>
Sun, 11 Jun 2017 13:21:20 +0200
changeset 413880 1b58c5233eaa7968dc289d9113130ea6bf2985c8
parent 413872 799d43edb324395cf02da6b028e803712334615f
child 413881 d8042b28922a3c4324fd1bbd0e9ba18e9c4e2490
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1352709
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1352709 - Fix browser_plainTextLinks.js to work around some context menu issues. r=Gijs
browser/base/content/test/general/browser_plainTextLinks.js
--- a/browser/base/content/test/general/browser_plainTextLinks.js
+++ b/browser/base/content/test/general/browser_plainTextLinks.js
@@ -124,23 +124,40 @@ add_task(async function() {
 
       // Get the range of the selection and determine its coordinates. These
       // coordinates will be returned to the parent process and the context menu
       // will be opened at that location.
       let rangeRect = range.getBoundingClientRect();
       return [rangeRect.x + 3, rangeRect.y + 3];
     });
 
-    let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown");
-    await BrowserTestUtils.synthesizeMouseAtPoint(menuPosition[0], menuPosition[1],
-          { type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
+    // Trigger a mouse event until we receive the popupshown event.
+    let sawPopup = false;
+    let popupShownPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popupshown", false, () => {
+      sawPopup = true;
+      return true;
+    });
+    while (!sawPopup) {
+      await BrowserTestUtils.synthesizeMouseAtPoint(menuPosition[0], menuPosition[1],
+            { type: "contextmenu", button: 2 }, gBrowser.selectedBrowser);
+      if (!sawPopup) {
+        await new Promise(r => setTimeout(r, 100));
+      }
+    }
     await popupShownPromise;
 
     checks[testid]();
 
+    // On Linux non-e10s it's possible the menu was closed by a focus-out event
+    // on the window. Work around this by calling hidePopup only if the menu
+    // hasn't been closed yet. See bug 1352709 comment 36.
+    if (contentAreaContextMenu.state === "closed") {
+      continue;
+    }
+
     let popupHiddenPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popuphidden");
     contentAreaContextMenu.hidePopup();
     await popupHiddenPromise;
   }
 
   gBrowser.removeCurrentTab();
 });