Bug 1235372, re-enable browser_contextmenu.js in e10s, r=florian
authorNeil Deakin <neil@mozilla.com>
Wed, 20 Jan 2016 08:42:15 -0500
changeset 280773 ce5869bf392c4d3ecba1ca0c2f4c281e9b53e3f0
parent 280772 a3c338f0bb7c71c4f0122557a17ea9beafab3547
child 280774 1e2214120e147fb38ca06df0e21a5cd4c0b37a34
push id29922
push usercbook@mozilla.com
push dateThu, 21 Jan 2016 10:51:00 +0000
treeherdermozilla-central@977d78a8dd78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1235372
milestone46.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 1235372, re-enable browser_contextmenu.js in e10s, r=florian
browser/components/search/test/browser.ini
browser/components/search/test/browser_contextmenu.js
browser/components/search/test/head.js
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -18,17 +18,16 @@ support-files =
 [browser_addEngine.js]
 [browser_amazon.js]
 [browser_amazon_behavior.js]
 skip-if = e10s # Bug ?????? - some issue with progress listeners [JavaScript Error: "req.originalURI is null" {file: "chrome://mochitests/content/browser/browser/components/search/test/browser_bing_behavior.js" line: 127}]
 [browser_bing.js]
 [browser_bing_behavior.js]
 skip-if = e10s # Bug ?????? - some issue with progress listeners [JavaScript Error: "req.originalURI is null" {file: "chrome://mochitests/content/browser/browser/components/search/test/browser_bing_behavior.js" line: 127}]
 [browser_contextmenu.js]
-skip-if = e10s # Bug ?????? - Test touches content (content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate)....)
 [browser_eBay.js]
 [browser_eBay_behavior.js]
 skip-if = e10s # Bug ?????? - some issue with progress listeners [JavaScript Error: "req.originalURI is null" {file: "chrome://mochitests/content/browser/browser/components/search/test/browser_bing_behavior.js" line: 127}]
 [browser_google.js]
 [browser_google_behavior.js]
 skip-if = e10s # Bug ?????? - some issue with progress listeners [JavaScript Error: "req.originalURI is null" {file: "chrome://mochitests/content/browser/browser/components/search/test/browser_bing_behavior.js" line: 127}]
 [browser_healthreport.js]
 [browser_hiddenOneOffs_cleanup.js]
--- a/browser/components/search/test/browser_contextmenu.js
+++ b/browser/components/search/test/browser_contextmenu.js
@@ -1,111 +1,98 @@
 /* Any copyright is dedicated to the Public Domain.
  *  * http://creativecommons.org/publicdomain/zero/1.0/ */
 /*
  * Test searching for the selected text using the context menu
  */
 
-function test() {
-  waitForExplicitFinish();
-
+add_task(function* () {
   const ss = Services.search;
   const ENGINE_NAME = "Foo";
   var contextMenu;
 
   let envService = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
   let originalValue = envService.get("XPCSHELL_TEST_PROFILE_DIR");
   envService.set("XPCSHELL_TEST_PROFILE_DIR", "1");
 
   let url = "chrome://mochitests/content/browser/browser/components/search/test/";
   let resProt = Services.io.getProtocolHandler("resource")
                         .QueryInterface(Ci.nsIResProtocolHandler);
   let originalSubstitution = resProt.getSubstitution("search-plugins");
   resProt.setSubstitution("search-plugins",
                           Services.io.newURI(url, null, null));
 
-  function observer(aSub, aTopic, aData) {
-    switch (aData) {
-      case "engine-added":
-        var engine = ss.getEngineByName(ENGINE_NAME);
-        ok(engine, "Engine was added.");
-        ss.currentEngine = engine;
-        envService.set("XPCSHELL_TEST_PROFILE_DIR", originalValue);
-        resProt.setSubstitution("search-plugins", originalSubstitution);
-        break;
-      case "engine-current":
-        is(ss.currentEngine.name, ENGINE_NAME, "currentEngine set");
-        startTest();
-        break;
-      case "engine-removed":
-        Services.obs.removeObserver(observer, "browser-search-engine-modified");
-        finish();
-        break;
-    }
-  }
-
-  Services.obs.addObserver(observer, "browser-search-engine-modified", false);
-  ss.addEngine("resource://search-plugins/testEngine_mozsearch.xml",
-               null, "data:image/x-icon,%00", false);
-
-  function startTest() {
-    contextMenu = document.getElementById("contentAreaContextMenu");
-    ok(contextMenu, "Got context menu XUL");
-
-    doOnloadOnce(testContextMenu);
-    let tab = gBrowser.selectedTab = gBrowser.addTab("data:text/plain;charset=utf8,test%20search");
-    registerCleanupFunction(function () {
-      gBrowser.removeTab(tab);
-    });
-  }
-
-  function testContextMenu() {
-    function rightClickOnDocument() {
-      info("rightClickOnDocument: " + content.window.location);
-      waitForBrowserContextMenu(checkContextMenu);
-      var clickTarget = content.document.body;
-      var eventDetails = { type: "contextmenu", button: 2 };
-      EventUtils.synthesizeMouseAtCenter(clickTarget, eventDetails, content);
+  let searchDonePromise;
+  yield new Promise(resolve => {
+    function observer(aSub, aTopic, aData) {
+      switch (aData) {
+        case "engine-added":
+          var engine = ss.getEngineByName(ENGINE_NAME);
+          ok(engine, "Engine was added.");
+          ss.currentEngine = engine;
+          envService.set("XPCSHELL_TEST_PROFILE_DIR", originalValue);
+          resProt.setSubstitution("search-plugins", originalSubstitution);
+          break;
+        case "engine-current":
+          is(ss.currentEngine.name, ENGINE_NAME, "currentEngine set");
+          resolve();
+          break;
+        case "engine-removed":
+          Services.obs.removeObserver(observer, "browser-search-engine-modified");
+          if (searchDonePromise) {
+            searchDonePromise();
+          }
+          break;
+      }
     }
 
-    // check the search menu item and then perform a search
-    function checkContextMenu() {
-      info("checkContextMenu");
-      var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0];
-      ok(searchItem, "Got search context menu item");
-      is(searchItem.label, 'Search ' + ENGINE_NAME + ' for "test search"', "Check context menu label");
-      is(searchItem.disabled, false, "Check that search context menu item is enabled");
-      doOnloadOnce(checkSearchURL);
-      searchItem.click();
-      contextMenu.hidePopup();
-    }
+    Services.obs.addObserver(observer, "browser-search-engine-modified", false);
+    ss.addEngine("resource://search-plugins/testEngine_mozsearch.xml",
+                 null, "data:image/x-icon,%00", false);
+  });
+
+  contextMenu = document.getElementById("contentAreaContextMenu");
+  ok(contextMenu, "Got context menu XUL");
+
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, "data:text/plain;charset=utf8,test%20search");
 
-    function checkSearchURL(event) {
-      is(event.originalTarget.URL,
-         "http://mochi.test:8888/browser/browser/components/search/test/?test=test+search&ie=utf-8&channel=contextsearch",
-         "Checking context menu search URL");
-      // Remove the tab opened by the search
-      gBrowser.removeCurrentTab();
-      ss.removeEngine(ss.currentEngine);
-    }
+  yield ContentTask.spawn(tab.linkedBrowser, "", function*() {
+    return new Promise(resolve => {
+      content.document.addEventListener("selectionchange", function selectionChanged() {
+        content.document.removeEventListener("selectionchange", selectionChanged);
+        resolve();
+      });
+      content.document.getSelection().selectAllChildren(content.document.body);
+    });
+  });
+
+  var eventDetails = { type: "contextmenu", button: 2 };
+
+  let popupPromise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+  BrowserTestUtils.synthesizeMouseAtCenter("body", eventDetails, gBrowser.selectedBrowser);
+  yield popupPromise;
 
-    var selectionListener = {
-      notifySelectionChanged: function(doc, sel, reason) {
-        if (reason != Ci.nsISelectionListener.SELECTALL_REASON || sel.toString() != "test search")
-          return;
-        info("notifySelectionChanged: Text selected");
-        content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
-                                      removeSelectionListener(selectionListener);
-        SimpleTest.executeSoon(rightClickOnDocument);
-      }
-    };
+  info("checkContextMenu");
+  var searchItem = contextMenu.getElementsByAttribute("id", "context-searchselect")[0];
+  ok(searchItem, "Got search context menu item");
+  is(searchItem.label, 'Search ' + ENGINE_NAME + ' for "test search"', "Check context menu label");
+  is(searchItem.disabled, false, "Check that search context menu item is enabled");
+
+  yield BrowserTestUtils.openNewForegroundTab(gBrowser, () => {
+    searchItem.click();
+  });
 
-    // Delay the select all to avoid intermittent selection failures.
-    setTimeout(function delaySelectAll() {
-      info("delaySelectAll: " + content.window.location.toString());
-      // add a listener to know when the selection takes effect
-      content.window.getSelection().QueryInterface(Ci.nsISelectionPrivate).
-                                    addSelectionListener(selectionListener);
-      // select the text on the page
-      goDoCommand('cmd_selectAll');
-    }, 500);
-  }
-}
+  is(gBrowser.currentURI.spec,
+     "http://mochi.test:8888/browser/browser/components/search/test/?test=test+search&ie=utf-8&channel=contextsearch",
+     "Checking context menu search URL");
+
+  contextMenu.hidePopup();
+
+  // Remove the tab opened by the search
+  gBrowser.removeCurrentTab();
+
+  yield new Promise(resolve => {
+    searchDonePromise = resolve;
+    ss.removeEngine(ss.currentEngine);
+  });
+
+  gBrowser.removeCurrentTab();
+});
--- a/browser/components/search/test/head.js
+++ b/browser/components/search/test/head.js
@@ -37,62 +37,28 @@ function getLocalizedPref(aPrefName, aDe
     return Services.prefs.getComplexValue(aPrefName, Ci.nsIPrefLocalizedString).data;
   } catch (ex) {
     return aDefault;
   }
 
   return aDefault;
 }
 
-function waitForPopupShown(aPopupId, aCallback) {
-  let popup = document.getElementById(aPopupId);
-  info("waitForPopupShown: got popup: " + popup.id);
-  function onPopupShown() {
-    info("onPopupShown");
-    removePopupShownListener();
-    SimpleTest.executeSoon(aCallback);
-  }
-  function removePopupShownListener() {
-    popup.removeEventListener("popupshown", onPopupShown);
-  }
-  popup.addEventListener("popupshown", onPopupShown);
-  registerCleanupFunction(removePopupShownListener);
-}
-
 function promiseEvent(aTarget, aEventName, aPreventDefault) {
   let deferred = Promise.defer();
   aTarget.addEventListener(aEventName, function onEvent(aEvent) {
     aTarget.removeEventListener(aEventName, onEvent, true);
     if (aPreventDefault) {
       aEvent.preventDefault();
     }
     deferred.resolve();
   }, true);
   return deferred.promise;
 }
 
-function waitForBrowserContextMenu(aCallback) {
-  waitForPopupShown(gBrowser.selectedBrowser.contextMenu, aCallback);
-}
-
-function doOnloadOnce(aCallback) {
-  function doOnloadOnceListener(aEvent) {
-    info("doOnloadOnce: " + aEvent.originalTarget.location);
-    removeDoOnloadOnceListener();
-    SimpleTest.executeSoon(function doOnloadOnceCallback() {
-      aCallback(aEvent);
-    });
-  }
-  function removeDoOnloadOnceListener() {
-    gBrowser.removeEventListener("load", doOnloadOnceListener, true);
-  }
-  gBrowser.addEventListener("load", doOnloadOnceListener, true);
-  registerCleanupFunction(removeDoOnloadOnceListener);
-}
-
 function promiseNewEngine(basename, options = {}) {
   return new Promise((resolve, reject) => {
     //Default the setAsCurrent option to true.
     let setAsCurrent =
       options.setAsCurrent == undefined ? true : options.setAsCurrent;
     info("Waiting for engine to be added: " + basename);
     Services.search.init({
       onInitComplete: function() {