Bug 1094761 - Fix browser_contextSearchTabPosition.js to not hit the network. r=Florian draft
authorFelipe Gomes <felipc@gmail.com>
Mon, 15 Feb 2016 20:13:31 -0200
changeset 331120 f02295c1405722769d11c457eb38bdeda096a874
parent 330984 ea39d4a6232c278dd8d805608a07cf9f4cc4c76b
child 514303 75ccf5d59c3718b56626d08ee4e832fcfa2d1685
push id10900
push userfelipc@gmail.com
push dateMon, 15 Feb 2016 22:14:02 +0000
reviewersFlorian
bugs1094761
milestone47.0a1
Bug 1094761 - Fix browser_contextSearchTabPosition.js to not hit the network. r=Florian MozReview-Commit-ID: BbsLGoh4o5y
browser/base/content/test/general/browser_contextSearchTabPosition.js
browser/components/search/test/browser.ini
browser/components/search/test/browser_contextSearchTabPosition.js
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -16,16 +16,18 @@ support-files =
 [browser_426329.js]
 [browser_483086.js]
 [browser_addEngine.js]
 [browser_amazon.js]
 [browser_amazon_behavior.js]
 [browser_bing.js]
 [browser_bing_behavior.js]
 [browser_contextmenu.js]
+[browser_contextSearchTabPosition.js]
+skip-if = os == "mac"
 [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]
rename from browser/base/content/test/general/browser_contextSearchTabPosition.js
rename to browser/components/search/test/browser_contextSearchTabPosition.js
--- a/browser/base/content/test/general/browser_contextSearchTabPosition.js
+++ b/browser/components/search/test/browser_contextSearchTabPosition.js
@@ -1,30 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 add_task(function* test() {
+  let engine = yield promiseNewEngine("testEngine.xml");
+  let histogramKey = "other-" + engine.name + ".contextmenu";
+  let numSearchesBefore = 0;
 
-  // Will need to be changed if Google isn't the default search engine.
-  // Note: geoSpecificDefaults are disabled for mochitests, so this is the
-  // non-US en-US default.
-  let histogramKey = "google.contextmenu";
-  let numSearchesBefore = 0;
   try {
     let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
     if (histogramKey in hs) {
       numSearchesBefore = hs[histogramKey].sum;
     }
   } catch (ex) {
     // No searches performed yet, not a problem, |numSearchesBefore| is 0.
   }
 
   let tabs = [];
-  let tabsLoadedDeferred = Promise.defer();
+  let tabsLoadedDeferred = new Deferred();
 
   function tabAdded(event) {
     let tab = event.target;
     tabs.push(tab);
 
     // We wait for the blank tab and the two context searches tabs to open.
     if (tabs.length == 3) {
       tabsLoadedDeferred.resolve();
@@ -49,8 +47,15 @@ add_task(function* test() {
   tabs.forEach(gBrowser.removeTab, gBrowser);
 
   // Make sure that the context searches are correctly recorded.
   let hs = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS").snapshot();
   Assert.ok(histogramKey in hs, "The histogram must contain the correct key");
   Assert.equal(hs[histogramKey].sum, numSearchesBefore + 2,
                "The histogram must contain the correct search count");
 });
+
+function Deferred() {
+  this.promise = new Promise((resolve, reject) => {
+    this.resolve = resolve;
+    this.reject = reject;
+  });
+}