Bug 1235372, remove Promise.jsm usage from search tests, r=florian
authorNeil Deakin <neil@mozilla.com>
Wed, 20 Jan 2016 08:42:15 -0500
changeset 323577 6f5d184b3b4259832374bd86bd84cee1a4a7186a
parent 323576 1e2214120e147fb38ca06df0e21a5cd4c0b37a34
child 323578 dd033af22d121e2ce58242e75ebaea4b4574b0b9
push id9750
push userdtownsend@mozilla.com
push dateWed, 20 Jan 2016 18:02:09 +0000
reviewersflorian
bugs1235372
milestone46.0a1
Bug 1235372, remove Promise.jsm usage from search tests, r=florian
browser/components/search/test/browser.ini
browser/components/search/test/browser_searchbar_keyboard_navigation.js
browser/components/search/test/browser_searchbar_smallpanel_keyboard_navigation.js
browser/components/search/test/head.js
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -24,19 +24,18 @@ support-files =
 [browser_eBay.js]
 [browser_eBay_behavior.js]
 [browser_google.js]
 [browser_google_behavior.js]
 [browser_healthreport.js]
 [browser_hiddenOneOffs_cleanup.js]
 [browser_hiddenOneOffs_diacritics.js]
 [browser_oneOffHeader.js]
-skip-if = e10s # bug ?????? - Test alters the searchbar textbox value which causes issues with other tests in e10s.
 [browser_private_search_perwindowpb.js]
 [browser_yahoo.js]
 [browser_yahoo_behavior.js]
 [browser_abouthome_behavior.js]
-skip-if = e10s || true # Bug ??????, Bug 1100301 - leaks windows until shutdown when --run-by-dir
+skip-if = true # Bug ??????, Bug 1100301 - leaks windows until shutdown when --run-by-dir
 [browser_searchbar_openpopup.js]
 skip-if = os == "linux" # Linux has different focus behaviours.
 [browser_searchbar_keyboard_navigation.js]
 [browser_searchbar_smallpanel_keyboard_navigation.js]
 [browser_webapi.js]
--- a/browser/components/search/test/browser_searchbar_keyboard_navigation.js
+++ b/browser/components/search/test/browser_searchbar_keyboard_navigation.js
@@ -376,30 +376,18 @@ add_task(function* test_tab_and_arrows()
 
   // Finally close the panel.
   let promise = promiseEvent(searchPopup, "popuphidden");
   searchPopup.hidePopup();
   yield promise;
 });
 
 add_task(function* test_open_search() {
-  let tab = gBrowser.addTab();
-  gBrowser.selectedTab = tab;
-
-  let deferred = Promise.defer();
-  let browser = gBrowser.selectedBrowser;
-  browser.addEventListener("load", function onload() {
-    browser.removeEventListener("load", onload, true);
-    deferred.resolve();
-  }, true);
-
   let rootDir = getRootDirectory(gTestPath);
-  content.location = rootDir + "opensearch.html";
-
-  yield deferred.promise;
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, rootDir + "opensearch.html");
 
   let promise = promiseEvent(searchPopup, "popupshown");
   info("Opening search panel");
   searchbar.focus();
   yield promise;
 
   let engines = getOpenSearchItems();
   is(engines.length, 2, "the opensearch.html page exposes 2 engines")
--- a/browser/components/search/test/browser_searchbar_smallpanel_keyboard_navigation.js
+++ b/browser/components/search/test/browser_searchbar_smallpanel_keyboard_navigation.js
@@ -304,30 +304,18 @@ add_task(function* test_tab_and_arrows()
 
   // Finally close the panel.
   let promise = promiseEvent(searchPopup, "popuphidden");
   searchPopup.hidePopup();
   yield promise;
 });
 
 add_task(function* test_open_search() {
-  let tab = gBrowser.addTab();
-  gBrowser.selectedTab = tab;
-
-  let deferred = Promise.defer();
-  let browser = gBrowser.selectedBrowser;
-  browser.addEventListener("load", function onload() {
-    browser.removeEventListener("load", onload, true);
-    deferred.resolve();
-  }, true);
-
   let rootDir = getRootDirectory(gTestPath);
-  content.location = rootDir + "opensearch.html";
-
-  yield deferred.promise;
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, rootDir + "opensearch.html");
 
   let promise = promiseEvent(searchPopup, "popupshown");
   info("Opening search panel");
   EventUtils.synthesizeMouseAtCenter(searchIcon, {});
   yield promise;
   is(searchPopup.getAttribute("showonlysettings"), "true", "Should show the small popup");
 
   let engines = getOpenSearchItems();
--- a/browser/components/search/test/head.js
+++ b/browser/components/search/test/head.js
@@ -1,14 +1,11 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
-  "resource://gre/modules/Promise.jsm");
-
 /**
  * Recursively compare two objects and check that every property of expectedObj has the same value
  * on actualObj.
  */
 function isSubObjectOf(expectedObj, actualObj, name) {
   for (let prop in expectedObj) {
     if (typeof expectedObj[prop] == 'function')
       continue;
@@ -38,25 +35,25 @@ function getLocalizedPref(aPrefName, aDe
   } catch (ex) {
     return aDefault;
   }
 
   return aDefault;
 }
 
 function promiseEvent(aTarget, aEventName, aPreventDefault) {
-  let deferred = Promise.defer();
-  aTarget.addEventListener(aEventName, function onEvent(aEvent) {
-    aTarget.removeEventListener(aEventName, onEvent, true);
+  function cancelEvent(event) {
     if (aPreventDefault) {
-      aEvent.preventDefault();
+      event.preventDefault();
     }
-    deferred.resolve();
-  }, true);
-  return deferred.promise;
+
+    return true;
+  }
+
+  return BrowserTestUtils.waitForEvent(aTarget, aEventName, false, cancelEvent);
 }
 
 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);