Bug 1176281 - Part 3: Simplify contextMenuOpened using BrowserTestUtils.waitForEvent. r=Gijs
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Fri, 19 Jun 2015 09:16:01 -0700
changeset 250745 565bb767379d31037693c39519b46ca9409cb5fc
parent 250744 751ca11fdcfea4e46040e1bf314eaf85a1555b5b
child 250746 6a0c6253edc08b4a4d3d23c3f48f3b37462b66d5
push idunknown
push userunknown
push dateunknown
reviewersGijs
bugs1176281
milestone42.0a1
Bug 1176281 - Part 3: Simplify contextMenuOpened using BrowserTestUtils.waitForEvent. r=Gijs
browser/base/content/test/referrer/head.js
--- a/browser/base/content/test/referrer/head.js
+++ b/browser/base/content/test/referrer/head.js
@@ -159,26 +159,21 @@ function newWindowOpened() {
 /**
  * Opens the context menu.
  * @param aWindow The window to open the context menu in.
  * @param aLinkId The id of the link to open the context menu on.
  * @return {Promise}
  * @resolves With the menu popup when the context menu is open.
  */
 function contextMenuOpened(aWindow, aLinkId) {
-  return new Promise(function(resolve) {
-    aWindow.document.addEventListener("popupshown",
-                                      function handleMenu(aEvent) {
-      aWindow.document.removeEventListener("popupshown", handleMenu, false);
-      resolve(aEvent.target);
-    }, false);
-
-    // Simulate right-click that opens the context menu.
-    clickTheLink(aWindow, aLinkId, {type: "contextmenu", button: 2});
-  });
+  let popupShownPromise = BrowserTestUtils.waitForEvent(aWindow.document,
+                                                        "popupshown");
+  // Simulate right-click.
+  clickTheLink(aWindow, aLinkId, { type: "contextmenu", button: 2 });
+  return popupShownPromise.then(e => e.target);
 }
 
 /**
  * Performs a context menu command.
  * @param aWindow The window with the already open context menu.
  * @param aMenu The menu popup to hide.
  * @param aItemId The id of the menu item to activate.
  */