Bug 1260102 followup - Simplify newly added test with util functions.
authorXidorn Quan <quanxunzhen@gmail.com>
Mon, 04 Apr 2016 10:21:22 +1000
changeset 291524 0a0465d2c85b8b3bd6cc38dede241e839cfa7bc0
parent 291520 57cc6679cc6676168353229733cfbb6d96510b85
child 291525 f7eef7358c99b93677fdd356c0d4cdf1a328f9fe
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1260102
milestone48.0a1
Bug 1260102 followup - Simplify newly added test with util functions. MozReview-Commit-ID: lodB36EXUK
dom/html/test/browser_content_contextmenu_userinput.js
--- a/dom/html/test/browser_content_contextmenu_userinput.js
+++ b/dom/html/test/browser_content_contextmenu_userinput.js
@@ -1,45 +1,18 @@
 "use strict";
 
-function frameScript() {
-  let Ci = Components.interfaces;
-  let windowUtils = content.QueryInterface(Ci.nsIInterfaceRequestor)
-                           .getInterface(Ci.nsIDOMWindowUtils);
-  let menuitem = content.document.getElementById("menuitem");
-  menuitem.addEventListener("click", function() {
-    sendAsyncMessage("Test:ContextMenuClick", windowUtils.isHandlingUserInput);
-  });
-}
-
-var gMessageManager;
-
-function listenOneMessage(aMsg, aListener) {
-  function listener({ data }) {
-    gMessageManager.removeMessageListener(aMsg, listener);
-    aListener(data);
-  }
-  gMessageManager.addMessageListener(aMsg, listener);
-}
-
-function promiseOneMessage(aMsg) {
-  return new Promise(resolve => listenOneMessage(aMsg, resolve));
-}
-
 const kPage = "http://example.org/browser/" +
               "dom/html/test/file_content_contextmenu.html";
 
 add_task(function* () {
   yield BrowserTestUtils.withNewTab({
     gBrowser,
     url: kPage
   }, function*(aBrowser) {
-    gMessageManager = aBrowser.messageManager;
-    ContentTask.spawn(aBrowser, null, frameScript);
-
     let contextMenu = document.getElementById("contentAreaContextMenu");
     ok(contextMenu, "Got context menu");
 
     info("Open context menu");
     is(contextMenu.state, "closed", "Should not have opened context menu");
     let popupShownPromise = promiseWaitForEvent(window, "popupshown");
     EventUtils.synthesizeMouse(aBrowser, window.innerWidth / 3,
                                window.innerHeight / 3,
@@ -48,14 +21,25 @@ add_task(function* () {
     is(contextMenu.state, "open", "Should have opened context menu");
 
     let pageMenuSep = document.getElementById("page-menu-separator");
     ok(pageMenuSep && !pageMenuSep.hidden,
        "Page menu separator should be shown");
     let testMenuItem = pageMenuSep.previousSibling;
     is(testMenuItem.label, "Test Context Menu Click", "Got context menu item");
 
-    let promiseContextMenuClick = promiseOneMessage("Test:ContextMenuClick");
+    let promiseCtxMenuClick = ContentTask.spawn(aBrowser, null, function*() {
+      yield new Promise(resolve => {
+        let Ci = Components.interfaces;
+        let windowUtils = content.QueryInterface(Ci.nsIInterfaceRequestor)
+                                 .getInterface(Ci.nsIDOMWindowUtils);
+        let menuitem = content.document.getElementById("menuitem");
+        menuitem.addEventListener("click", function() {
+          Assert.ok(windowUtils.isHandlingUserInput,
+                    "Content menu click should be a user input");
+          resolve();
+        });
+      });
+    });
     EventUtils.synthesizeMouseAtCenter(testMenuItem, {}, window);
-    let isUserInput = yield promiseContextMenuClick;
-    ok(isUserInput, "Content menu click should be a user input");
+    yield promiseCtxMenuClick;
   });
 });