Bug 1075157 - Support action: reset search. r=gfritzsche, r=florian, r=bholley
authorAndré Reinald <areinald@mozilla.com>
Fri, 24 Apr 2015 17:57:52 +0200
changeset 272289 d544be8b3dc3a983dbd50a5942080eb870d15477
parent 272288 d2417b6791606caacd9db1d224c7720bace00efc
child 272290 541073e6d2272d777df949850f059a29da9273f1
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche, florian, bholley
bugs1075157
milestone40.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 1075157 - Support action: reset search. r=gfritzsche, r=florian, r=bholley
CLOBBER
browser/components/selfsupport/SelfSupportService.js
browser/components/selfsupport/test/browser_selfsupportAPI.js
dom/webidl/MozSelfSupport.webidl
netwerk/base/nsIBrowserSearchService.idl
toolkit/components/search/nsSearchService.js
--- a/CLOBBER
+++ b/CLOBBER
@@ -17,9 +17,9 @@
 #
 # Modifying this file will now automatically clobber the buildbot machines \o/
 #
 
 # Are you updating CLOBBER because you think it's needed for your WebIDL
 # changes to stick? As of bug 928195, this shouldn't be necessary! Please
 # don't change CLOBBER for WebIDL changes any more.
 
-Bug 1128037 needed a clobber to properly build on OS X
+Bug 1075157 needed a clobber for unknown reasons due to Android debug mochitest crashes.
--- a/browser/components/selfsupport/SelfSupportService.js
+++ b/browser/components/selfsupport/SelfSupportService.js
@@ -63,11 +63,16 @@ MozSelfSupportInterface.prototype = {
         aReject(new Error("No reporter"));
       }
     }.bind(this));
   },
 
   resetPref: function(name) {
     Services.prefs.clearUserPref(name);
   },
+
+  resetSearchEngines: function() {
+    Services.search.restoreDefaultEngines();
+    Services.search.resetToOriginalDefaultEngine();
+  },
 }
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MozSelfSupportInterface]);
--- a/browser/components/selfsupport/test/browser_selfsupportAPI.js
+++ b/browser/components/selfsupport/test/browser_selfsupportAPI.js
@@ -1,11 +1,11 @@
 Cu.import("resource://gre/modules/Preferences.jsm");
 
-function test() {
+function test_resetPref() {
   const prefNewName = "browser.newpref.fake";
   Assert.ok(!Preferences.has(prefNewName), "pref should not exist");
 
   const prefExistingName = "extensions.hotfix.id";
   Assert.ok(Preferences.has(prefExistingName), "pref should exist");
   Assert.ok(!Preferences.isSet(prefExistingName), "pref should not be user-set");
   let prefExistingOriginalValue = Preferences.get(prefExistingName);
 
@@ -40,8 +40,49 @@ function test() {
   Assert.ok(Preferences.has(prefExistingName), "pref should still exist");
   Assert.equal(Preferences.get(prefExistingName), prefExistingOriginalValue, "pref value should be the same as original");
 
   // 5. delete an existing pref
   // deleteBranch is implemented in such a way that
   // clearUserPref can't undo its action
   // see discussion in bug 1075160
 }
+
+function test_resetSearchEngines()
+{
+  const defaultEngineOriginal = Services.search.defaultEngine;
+  const visibleEnginesOriginal = Services.search.getVisibleEngines();
+
+  // 1. do nothing on unchanged search configuration
+  MozSelfSupport.resetSearchEngines();
+  Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset");
+  Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal,
+                   "default visible engines set should be reset");
+
+  // 2. change the default search engine
+  const defaultEngineNew = visibleEnginesOriginal[3];
+  Assert.notEqual(defaultEngineOriginal, defaultEngineNew, "new default engine should be different from original");
+  Services.search.defaultEngine = defaultEngineNew;
+  Assert.equal(Services.search.defaultEngine, defaultEngineNew, "default engine should be set to new");
+  MozSelfSupport.resetSearchEngines();
+  Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset");
+  Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal,
+                   "default visible engines set should be reset");
+
+  // 3. remove an engine
+  const engineRemoved = visibleEnginesOriginal[2];
+  Services.search.removeEngine(engineRemoved);
+  Assert.ok(Services.search.getVisibleEngines().indexOf(engineRemoved) == -1,
+            "removed engine should not be visible any more");
+  MozSelfSupport.resetSearchEngines();
+  Assert.equal(Services.search.defaultEngine, defaultEngineOriginal, "default engine should be reset");
+  Assert.deepEqual(Services.search.getVisibleEngines(), visibleEnginesOriginal,
+                   "default visible engines set should be reset");
+
+  // 4. add an angine
+  // we don't remove user-added engines as they are only used if selected
+}
+
+function test()
+{
+  test_resetPref();
+  test_resetSearchEngines();
+}
--- a/dom/webidl/MozSelfSupport.webidl
+++ b/dom/webidl/MozSelfSupport.webidl
@@ -45,9 +45,14 @@ interface MozSelfSupport
    * - if there is a default value, then change the value back to default,
    * - if there's no default value, then delete the pref,
    * - no-op otherwise.
    *
    * @param DOMString
    *        The name of the pref to reset.
    */
   void resetPref(DOMString name);
+
+  /**
+   * Resets original search engines, and resets the default one.
+   */
+  void resetSearchEngines();
 };
--- a/netwerk/base/nsIBrowserSearchService.idl
+++ b/netwerk/base/nsIBrowserSearchService.idl
@@ -248,17 +248,17 @@ interface nsIBrowserSearchInitObserver :
   /**
    * Called once initialization of the browser search service is complete.
    *
    * @param aStatus The status of that service.
    */
   void onInitComplete(in nsresult aStatus);
 };
 
-[scriptable, uuid(4a4ce87d-7cb9-4975-a267-345f6a49bb8f)]
+[scriptable, uuid(75731859-c7b1-4edf-8d1c-3d4d79a55d1d)]
 interface nsIBrowserSearchService : nsISupports
 {
   /**
    * Start asynchronous initialization.
    *
    * The callback is triggered once initialization is complete, which may be
    * immediately, if initialization has already been completed by some previous
    * call to this method. The callback is always invoked asynchronously.
@@ -277,16 +277,21 @@ interface nsIBrowserSearchService : nsIS
    * Note that this attribute does not indicate that initialization has succeeded.
    *
    * @return |true| if the search service is now initialized, |false| if
    * initialization has not been triggered yet.
    */
   readonly attribute bool isInitialized;
 
   /**
+   * Resets the default engine to its original value.
+   */
+  void resetToOriginalDefaultEngine();
+
+  /**
    * Adds a new search engine from the file at the supplied URI, optionally
    * asking the user for confirmation first.  If a confirmation dialog is
    * shown, it will offer the option to begin using the newly added engine
    * right away.
    *
    * @param engineURL
    *        The URL to the search engine's description file.
    *
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -3299,16 +3299,20 @@ SearchService.prototype = {
       defaultEngine = defaultPrefB.getComplexValue(defPref, nsIPLS).data;
     } catch (ex) {
       // If the default pref is invalid (e.g. an add-on set it to a bogus value)
       // getEngineByName will just return null, which is the best we can do.
     }
     return this.getEngineByName(defaultEngine);
   },
 
+  resetToOriginalDefaultEngine: function SRCH_SVC__resetToOriginalDefaultEngine() {
+    this.defaultEngine = this._originalDefaultEngine;
+  },
+
   _buildCache: function SRCH_SVC__buildCache() {
     if (!getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true))
       return;
 
     TelemetryStopwatch.start("SEARCH_SERVICE_BUILD_CACHE_MS");
     let cache = {};
     let locale = getLocale();
     let buildID = Services.appinfo.platformBuildID;