Bug 553869 - move error codes constants from UpdateChecker to AddonManager r=rhelmer p=lenikmutungi@gmail.com
authorRobert Helmer <rhelmer@mozilla.com>
Thu, 27 Jul 2017 09:00:32 -0700
changeset 642656 3e13ecea8235e6d356843e868e40e8098649e5bc
parent 642655 96f8096db6320a178dd3d6f44ae31385c92b8f28
child 642657 8d64da85644e03c63a3cf9aa62b33af1975bd35a
push id72833
push userbmo:emilio+bugs@crisal.io
push dateTue, 08 Aug 2017 16:50:16 +0000
reviewersrhelmer
bugs553869
milestone57.0a1
Bug 553869 - move error codes constants from UpdateChecker to AddonManager r=rhelmer p=lenikmutungi@gmail.com MozReview-Commit-ID: 98XGu4M6RV1
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm
toolkit/mozapps/extensions/test/browser/browser_updatessl.js
toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -3336,33 +3336,43 @@ this.AddonManager = {
     ["ERROR_FILE_ACCESS", -4],
     // The add-on must be signed and isn't.
     ["ERROR_SIGNEDSTATE_REQUIRED", -5],
     // The downloaded add-on had a different type than expected.
     ["ERROR_UNEXPECTED_ADDON_TYPE", -6],
     // The addon did not have the expected ID
     ["ERROR_INCORRECT_ID", -7],
   ]),
-
+  // The update check timed out
+  ERROR_TIMEOUT: -1,
+  // There was an error while downloading the update information.
+  ERROR_DOWNLOAD_ERROR: -2,
+  // The update information was malformed in some way.
+  ERROR_PARSE_ERROR: -3,
+  // The update information was not in any known format.
+  ERROR_UNKNOWN_FORMAT: -4,
+  // The update information was not correctly signed or there was an SSL error.
+  ERROR_SECURITY_ERROR: -5,
+  // The update was cancelled
+  ERROR_CANCELLED: -6,
   // These must be kept in sync with AddonUpdateChecker.
   // No error was encountered.
   UPDATE_STATUS_NO_ERROR: 0,
   // The update check timed out
   UPDATE_STATUS_TIMEOUT: -1,
   // There was an error while downloading the update information.
   UPDATE_STATUS_DOWNLOAD_ERROR: -2,
   // The update information was malformed in some way.
   UPDATE_STATUS_PARSE_ERROR: -3,
   // The update information was not in any known format.
   UPDATE_STATUS_UNKNOWN_FORMAT: -4,
   // The update information was not correctly signed or there was an SSL error.
   UPDATE_STATUS_SECURITY_ERROR: -5,
   // The update was cancelled.
   UPDATE_STATUS_CANCELLED: -6,
-
   // Constants to indicate why an update check is being performed
   // Update check has been requested by the user.
   UPDATE_WHEN_USER_REQUESTED: 1,
   // Update check is necessary to see if the Addon is compatibile with a new
   // version of the application.
   UPDATE_WHEN_NEW_APP_DETECTED: 2,
   // Update check is necessary because a new application has been installed.
   UPDATE_WHEN_NEW_APP_INSTALLED: 3,
--- a/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonUpdateChecker.jsm
@@ -602,31 +602,31 @@ UpdateParser.prototype = {
     this._doneAt = new Error("place holder");
 
     let requireBuiltIn = Services.prefs.getBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, true);
 
     try {
       CertUtils.checkCert(request.channel, !requireBuiltIn);
     } catch (e) {
       logger.warn("Request failed: " + this.url + " - " + e);
-      this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR);
+      this.notifyError(AddonManager.ERROR_DOWNLOAD_ERROR);
       return;
     }
 
     if (!Components.isSuccessCode(request.status)) {
       logger.warn("Request failed: " + this.url + " - " + request.status);
-      this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR);
+      this.notifyError(AddonManager.ERROR_DOWNLOAD_ERROR);
       return;
     }
 
     let channel = request.channel;
     if (channel instanceof Ci.nsIHttpChannel && !channel.requestSucceeded) {
       logger.warn("Request failed: " + this.url + " - " + channel.responseStatus +
            ": " + channel.responseStatusText);
-      this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR);
+      this.notifyError(AddonManager.ERROR_DOWNLOAD_ERROR);
       return;
     }
 
     // Detect the manifest type by first attempting to parse it as
     // JSON, and falling back to parsing it as XML if that fails.
     let parser;
     try {
       try {
@@ -641,26 +641,26 @@ UpdateParser.prototype = {
 
         if (xml.documentElement.namespaceURI == XMLURI_PARSE_ERROR)
           throw new Error("Update manifest was not valid XML or JSON");
 
         parser = () => parseRDFManifest(this.id, this.updateKey, request, xml);
       }
     } catch (e) {
       logger.warn("onUpdateCheckComplete failed to determine manifest type");
-      this.notifyError(AddonUpdateChecker.ERROR_UNKNOWN_FORMAT);
+      this.notifyError(AddonManager.ERROR_UNKNOWN_FORMAT);
       return;
     }
 
     let results;
     try {
       results = parser();
     } catch (e) {
       logger.warn("onUpdateCheckComplete failed to parse update manifest", e);
-      this.notifyError(AddonUpdateChecker.ERROR_PARSE_ERROR);
+      this.notifyError(AddonManager.ERROR_PARSE_ERROR);
       return;
     }
 
     if ("onUpdateCheckComplete" in this.observer) {
       try {
         this.observer.onUpdateCheckComplete(results);
       } catch (e) {
         logger.warn("onUpdateCheckComplete notification failed", e);
@@ -672,17 +672,17 @@ UpdateParser.prototype = {
 
   /**
    * Called when the request times out
    */
   onTimeout() {
     this.request = null;
     this._doneAt = new Error("Timed out");
     logger.warn("Request for " + this.url + " timed out");
-    this.notifyError(AddonUpdateChecker.ERROR_TIMEOUT);
+    this.notifyError(AddonManager.ERROR_TIMEOUT);
   },
 
   /**
    * Called when the manifest failed to load.
    */
   onError() {
     if (!Components.isSuccessCode(this.request.status)) {
       logger.warn("Request failed: " + this.url + " - " + this.request.status);
@@ -698,17 +698,17 @@ UpdateParser.prototype = {
       }
     } else {
       logger.warn("Request failed for an unknown reason");
     }
 
     this.request = null;
     this._doneAt = new Error("UP_onError");
 
-    this.notifyError(AddonUpdateChecker.ERROR_DOWNLOAD_ERROR);
+    this.notifyError(AddonManager.ERROR_DOWNLOAD_ERROR);
   },
 
   /**
    * Helper method to notify the observer that an error occured.
    */
   notifyError(aStatus) {
     if ("onUpdateCheckError" in this.observer) {
       try {
@@ -725,17 +725,17 @@ UpdateParser.prototype = {
   cancel() {
     if (!this.request) {
       logger.error("Trying to cancel already-complete request", this._doneAt);
       return;
     }
     this.request.abort();
     this.request = null;
     this._doneAt = new Error("UP_cancel");
-    this.notifyError(AddonUpdateChecker.ERROR_CANCELLED);
+    this.notifyError(AddonManager.ERROR_CANCELLED);
   }
 };
 
 /**
  * Tests if an update matches a version of the application or platform
  *
  * @param  aUpdate
  *         The available update
@@ -776,30 +776,16 @@ function matchesVersions(aUpdate, aAppVe
       result = (Services.vc.compare(aPlatformVersion, app.minVersion) >= 0) &&
                (aIgnoreMaxVersion || (Services.vc.compare(aPlatformVersion, app.maxVersion) <= 0));
     }
   }
   return result;
 }
 
 this.AddonUpdateChecker = {
-  // These must be kept in sync with AddonManager
-  // The update check timed out
-  ERROR_TIMEOUT: -1,
-  // There was an error while downloading the update information.
-  ERROR_DOWNLOAD_ERROR: -2,
-  // The update information was malformed in some way.
-  ERROR_PARSE_ERROR: -3,
-  // The update information was not in any known format.
-  ERROR_UNKNOWN_FORMAT: -4,
-  // The update information was not correctly signed or there was an SSL error.
-  ERROR_SECURITY_ERROR: -5,
-  // The update was cancelled
-  ERROR_CANCELLED: -6,
-
   /**
    * Retrieves the best matching compatibility update for the application from
    * a list of available update objects.
    *
    * @param  aUpdates
    *         An array of update objects
    * @param  aVersion
    *         The version of the add-on to get new compatibility information for
--- a/toolkit/mozapps/extensions/test/browser/browser_updatessl.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_updatessl.js
@@ -4,17 +4,17 @@
 
 var tempScope = {};
 Components.utils.import("resource://gre/modules/addons/AddonUpdateChecker.jsm", tempScope);
 var AddonUpdateChecker = tempScope.AddonUpdateChecker;
 
 const updaterdf = RELATIVE_DIR + "browser_updatessl.rdf";
 const redirect = RELATIVE_DIR + "redirect.sjs?";
 const SUCCESS = 0;
-const DOWNLOAD_ERROR = AddonUpdateChecker.ERROR_DOWNLOAD_ERROR;
+const DOWNLOAD_ERROR = AddonManager.ERROR_DOWNLOAD_ERROR;
 
 const HTTP = "http://example.com/";
 const HTTPS = "https://example.com/";
 const NOCERT = "https://nocert.example.com/";
 const SELFSIGNED = "https://self-signed.example.com/";
 const UNTRUSTED = "https://untrusted.example.com/";
 const EXPIRED = "https://expired.example.com/";
 
--- a/toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_updatecheck.js
@@ -175,17 +175,17 @@ add_task(async function() {
 add_task(async function() {
   for (let file of ["test_updatecheck.rdf", "test_updatecheck.json"]) {
     try {
       await checkUpdates("test_bug378216_15@tests.mozilla.org",
                          null, file);
 
       throw "Update check should have failed";
     } catch (e) {
-      equal(e.status, AddonUpdateChecker.ERROR_PARSE_ERROR);
+      equal(e.status, AddonManager.ERROR_PARSE_ERROR);
     }
   }
 });
 
 add_task(async function() {
   for (let file of ["test_updatecheck.rdf", "test_updatecheck.json"]) {
     let updates = await checkUpdates("ignore-compat@tests.mozilla.org",
                                      null, file);