Bug 1650880 - Refactor toJSON in SearchEngine.jsm. r=Standard8
☠☠ backed out by ee66b0925c55 ☠ ☠
authorDale Harvey <dale@arandomurl.com>
Thu, 23 Jul 2020 15:37:11 +0000
changeset 541777 103d388bac7473c617ddf3c6794ee7651ff86422
parent 541776 0fb59851d956c1fce39125bf9b52de8003be840f
child 541778 5fffdf68ca3d9d2ca55bfbbbbeb67448c2dc0f27
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1650880
milestone80.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 1650880 - Refactor toJSON in SearchEngine.jsm. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D84411
toolkit/components/search/SearchEngine.jsm
toolkit/components/search/tests/xpcshell/data/search.json
toolkit/components/search/tests/xpcshell/test_json_cache.js
--- a/toolkit/components/search/SearchEngine.jsm
+++ b/toolkit/components/search/SearchEngine.jsm
@@ -1161,25 +1161,22 @@ class SearchEngine {
     this._updateURL = json._updateURL || null;
     this._iconUpdateURL = json._iconUpdateURL || null;
     this._iconURI = SearchUtils.makeURI(json._iconURL);
     this._iconMapObj = json._iconMapObj;
     this._metaData = json._metaData || {};
     this._orderHint = json._orderHint || null;
     this._telemetryId = json._telemetryId || null;
     this._definedAlias = json._definedAlias || null;
-    if (json.filePath) {
-      this._filePath = json.filePath;
-    }
-    if (json.extensionID) {
-      this._extensionID = json.extensionID;
-    }
-    if (json.extensionLocale) {
-      this._locale = json.extensionLocale;
-    }
+    // These changed keys in Firefox 80, maintain the old keys
+    // for backwards compatibility.
+    this._filePath = json.filePath || json._filePath || null;
+    this._extensionID = json.extensionID || json._extensionID || null;
+    this._locale = json.extensionLocale || json._locale || null;
+
     for (let i = 0; i < json._urls.length; ++i) {
       let url = json._urls[i];
       let engineURL = new EngineURL(
         url.type || SearchUtils.URL_TYPE.SEARCH,
         url.method || "GET",
         url.template,
         url.resultDomain || undefined
       );
@@ -1199,60 +1196,51 @@ class SearchEngine {
     if (gModernConfig && this._isAppProvided) {
       return {
         _name: this.name,
         _isAppProvided: true,
         _metaData: this._metaData,
       };
     }
 
-    var json = {
-      _name: this._name,
-      _shortName: this._shortName,
-      _loadPath: this._loadPath,
-      description: this.description,
-      __searchForm: this.__searchForm,
-      _iconURL: this._iconURL,
-      _iconMapObj: this._iconMapObj,
-      _metaData: this._metaData,
-      _urls: this._urls,
-      _isAppProvided: this._isAppProvided,
-      _orderHint: this._orderHint,
-      _telemetryId: this._telemetryId,
-    };
+    const fieldsToCopy = [
+      "_name",
+      "_shortName",
+      "_loadPath",
+      "description",
+      "__searchForm",
+      "_iconURL",
+      "_iconMapObj",
+      "_metaData",
+      "_urls",
+      "_isAppProvided",
+      "_orderHint",
+      "_telemetryId",
+      "_updateInterval",
+      "_updateURL",
+      "_iconUpdateURL",
+      "_filePath",
+      "_extensionID",
+      "_locale",
+      "_definedAlias",
+    ];
 
-    if (this._updateInterval) {
-      json._updateInterval = this._updateInterval;
+    let json = {};
+    for (const field of fieldsToCopy) {
+      if (field in this) {
+        json[field] = this[field];
+      }
     }
-    if (this._updateURL) {
-      json._updateURL = this._updateURL;
-    }
-    if (this._iconUpdateURL) {
-      json._iconUpdateURL = this._iconUpdateURL;
-    }
+
     if (!this._hasPreferredIcon) {
       json._hasPreferredIcon = this._hasPreferredIcon;
     }
     if (this.queryCharset != SearchUtils.DEFAULT_QUERY_CHARSET) {
       json.queryCharset = this.queryCharset;
     }
-    if (this._filePath) {
-      // File path is stored so that we can remove legacy xml files
-      // from the profile if the user removes the engine.
-      json.filePath = this._filePath;
-    }
-    if (this._extensionID) {
-      json.extensionID = this._extensionID;
-    }
-    if (this._locale) {
-      json.extensionLocale = this._locale;
-    }
-    if (this._definedAlias) {
-      json._definedAlias = this._definedAlias;
-    }
 
     return json;
   }
 
   setAttr(name, val) {
     this._metaData[name] = val;
   }
 
--- a/toolkit/components/search/tests/xpcshell/data/search.json
+++ b/toolkit/components/search/tests/xpcshell/data/search.json
@@ -74,12 +74,12 @@
               "name": "channel",
               "value": "rcs",
               "purpose": "contextmenu"
             }
           ]
         }
       ],
       "queryCharset": "UTF-8",
-      "extensionID": "test-addon-id@mozilla.org"
+      "_extensionID": "test-addon-id@mozilla.org"
     }
   ]
 }
--- a/toolkit/components/search/tests/xpcshell/test_json_cache.js
+++ b/toolkit/components/search/tests/xpcshell/test_json_cache.js
@@ -61,16 +61,20 @@ async function loadCacheFile(cacheFile) 
   if (!gModernConfig) {
     // For the legacy config, make sure we switch _isBuiltin to _isAppProvided
     // after saving, so that the expected results match.
     for (let engine of cacheTemplate.engines) {
       if ("_isBuiltin" in engine) {
         engine._isAppProvided = engine._isBuiltin;
         delete engine._isBuiltin;
       }
+      if ("extensionID" in engine) {
+        engine._extensionID = engine.extensionID;
+        delete engine.extensionID;
+      }
     }
   }
 }
 
 /**
  * Start the search service and confirm the engine properties match the expected values.
  *
  * @param {string} cacheFile