Bug 553869 - move error codes constants from UpdateChecker to AddonManager r=rhelmer p=lenikmutungi@gmail.com draft
authorRobert Helmer <rhelmer@mozilla.com>
Thu, 27 Jul 2017 09:00:32 -0700
changeset 617052 36bc03b0a60e2db34feba01a45391d237f07d419
parent 616915 36f95aeb4c77f7cf3b3366583008cd6e4b6b1dba
child 639679 d4736f959707d591f196df1a824830c8b3d30f3b
push id70904
push userrhelmer@mozilla.com
push dateThu, 27 Jul 2017 20:23:28 +0000
reviewersrhelmer
bugs553869
milestone56.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
@@ -3335,33 +3335,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);