Bug 1106926 - Ensure that removing a hidden one click search provider also removes it from the browser.search.hiddenOneOffs pref. r=florian, a=lmandel
💩💩 backed out by 89b593b91e5e 💩 💩
authorChris <chrishood@eagles.ewu.edu>
Mon, 02 Feb 2015 16:50:52 -0800
changeset 250299 7fc259f73c1d
parent 250298 7ffee9383f87
child 250300 a09088484ddf
push id4541
push userryanvm@gmail.com
push date2015-03-09 19:01 +0000
treeherdermozilla-beta@58b004077c10 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, lmandel
bugs1106926
milestone37.0
Bug 1106926 - Ensure that removing a hidden one click search provider also removes it from the browser.search.hiddenOneOffs pref. r=florian, a=lmandel
browser/app/profile/firefox.js
browser/components/nsBrowserGlue.js
browser/components/search/test/browser.ini
browser/components/search/test/browser_hiddenOneOffs_cleanup.js
browser/components/search/test/testEngine_dupe.xml
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -400,16 +400,19 @@ pref("browser.search.order.US.3",       
 // search bar results always open in a new tab
 pref("browser.search.openintab", false);
 
 // context menu searches open in the foreground
 pref("browser.search.context.loadInBackground", false);
 
 pref("browser.search.showOneOffButtons", true);
 
+// comma seperated list of of engines to hide in the search panel.
+pref("browser.search.hiddenOneOffs", "");
+
 // Never show the new search highlight on Firefox 37.
 pref("browser.search.highlightCount", 0);
 
 pref("browser.sessionhistory.max_entries", 50);
 
 // handle links targeting new windows
 // 1=current window/tab, 2=new window, 3=new tab in most recent window
 pref("browser.link.open_newwindow", 3);
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -409,16 +409,28 @@ BrowserGlue.prototype = {
             reporter.getProvider("org.mozilla.searches").recordSearch(engine, "urlbar");
           } catch (ex) {
             Cu.reportError(ex);
           }
         });
 #endif
         break;
       case "browser-search-engine-modified":
+        // Ensure we cleanup the hiddenOneOffs pref when removing
+        // an engine, and that newly added engines are visible.
+        if (data == "engine-added" || data == "engine-removed") {
+          let engineName = subject.QueryInterface(Ci.nsISearchEngine).name;
+          let hiddenPref =
+            Services.prefs.getCharPref("browser.search.hiddenOneOffs");
+          let hiddenEngines = hiddenPref ? hiddenPref.split(",") : [];
+          hiddenEngines = hiddenEngines.filter(x => x !== engineName);
+          Services.prefs.setCharPref("browser.search.hiddenOneOffs",
+                                     hiddenEngines.join(","));
+        }
+
         if (data != "engine-default" && data != "engine-current") {
           break;
         }
         // Enforce that the search service's defaultEngine is always equal to
         // its currentEngine. The search service will notify us any time either
         // of them are changed (either by directly setting the relevant prefs,
         // i.e. if add-ons try to change this directly, or if the
         // nsIBrowserSearchService setters are called).
--- a/browser/components/search/test/browser.ini
+++ b/browser/components/search/test/browser.ini
@@ -4,16 +4,17 @@ support-files =
   426329.xml
   483086-1.xml
   483086-2.xml
   head.js
   opensearch.html
   test.html
   testEngine.src
   testEngine.xml
+  testEngine_dupe.xml
   testEngine_mozsearch.xml
 
 [browser_405664.js]
 [browser_426329.js]
 skip-if = e10s # Bug ?????? - Test uses load event and checks event.target.
 [browser_483086.js]
 [browser_addEngine.js]
 [browser_amazon.js]
@@ -26,16 +27,17 @@ skip-if = e10s # Bug ?????? - some issue
 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]
 [browser_private_search_perwindowpb.js]
 skip-if = e10s # Bug ?????? - Test uses load event and checks event.target.
 [browser_yahoo.js]
 [browser_yahoo_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_abouthome_behavior.js]
 skip-if = e10s || true # Bug ??????, Bug 1100301 - leaks windows until shutdown when --run-by-dir
 [browser_searchbar_openpopup.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/search/test/browser_hiddenOneOffs_cleanup.js
@@ -0,0 +1,76 @@
+/* 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/. */
+const cachedPref = Services.prefs.getCharPref("browser.search.hiddenOneOffs");
+const testPref = "Foo,FooDupe";
+
+function promiseNewEngine(basename) {
+  return new Promise((resolve, reject) => {
+    info("Waiting for engine to be added: " + basename);
+    Services.search.init({
+      onInitComplete: function() {
+        let url = getRootDirectory(gTestPath) + basename;
+        Services.search.addEngine(url, Ci.nsISearchEngine.TYPE_MOZSEARCH, "", false, {
+          onSuccess: function (engine) {
+            info("Search engine added: " + basename);
+            resolve(engine);
+          },
+          onError: function (errCode) {
+            ok(false, "addEngine failed with error code " + errCode);
+            reject();
+          }
+        });
+      }
+    });
+  });
+}
+
+add_task(function* test_remove() {
+  yield promiseNewEngine("testEngine_dupe.xml");
+  yield promiseNewEngine("testEngine.xml");
+  Services.prefs.setCharPref("browser.search.hiddenOneOffs", testPref);
+
+  info("Removing testEngine_dupe.xml");
+  Services.search.removeEngine(Services.search.getEngineByName("FooDupe"));
+
+  let hiddenOneOffs =
+    Services.prefs.getCharPref("browser.search.hiddenOneOffs").split(",");
+
+  is(hiddenOneOffs.length, 1,
+     "hiddenOneOffs has the correct engine count post removal.");
+  is(hiddenOneOffs.includes("FooDupe"), false,
+     "Removed Engine is not in hiddenOneOffs after removal");
+  is(hiddenOneOffs.includes("Foo"), true,
+     "Current hidden engine is not affected by removal.");
+
+  info("Removing testEngine.xml");
+  Services.search.removeEngine(Services.search.getEngineByName("Foo"));
+
+  is(Services.prefs.getCharPref("browser.search.hiddenOneOffs"), "",
+     "hiddenOneOffs is empty after removing all hidden engines.");
+});
+
+add_task(function* test_add() {
+  yield promiseNewEngine("testEngine.xml");
+  info("setting prefs to " + testPref);
+  Services.prefs.setCharPref("browser.search.hiddenOneOffs", testPref);
+  yield promiseNewEngine("testEngine_dupe.xml");
+
+  let hiddenOneOffs =
+    Services.prefs.getCharPref("browser.search.hiddenOneOffs").split(",");
+
+  is(hiddenOneOffs.length, 1,
+     "hiddenOneOffs has the correct number of hidden engines present post add.");
+  is(hiddenOneOffs.includes("FooDupe"), false,
+     "Added engine is not present in hidden list.");
+  is(hiddenOneOffs.includes("Foo"), true,
+     "Adding an engine does not remove engines from hidden list.");
+});
+
+registerCleanupFunction(() => {
+  info("Removing testEngine.xml");
+  Services.search.removeEngine(Services.search.getEngineByName("Foo"));
+  info("Removing testEngine_dupe.xml");
+  Services.search.removeEngine(Services.search.getEngineByName("FooDupe"));
+  Services.prefs.setCharPref("browser.search.hiddenOneOffs", cachedPref);
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/search/test/testEngine_dupe.xml
@@ -0,0 +1,12 @@
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
+                       xmlns:moz="http://www.mozilla.org/2006/browser/search/">
+  <ShortName>FooDupe</ShortName>
+  <Description>Second Engine Search</Description>
+  <InputEncoding>utf-8</InputEncoding>
+  <Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC</Image>
+  <Url type="text/html" method="GET" template="http://mochi.test:8888/browser/browser/components/search/test/?search">
+    <Param name="test" value="{searchTerms}"/>
+  </Url>
+  <moz:SearchForm>http://mochi.test:8888/browser/browser/components/search/test/</moz:SearchForm>
+  <moz:Alias>secondalias</moz:Alias>
+</OpenSearchDescription>