Bug 1313648 - Add previousVersion to onInstalled details draft
authorTomislav Jovanovic <tomica@gmail.com>
Mon, 13 Mar 2017 05:55:52 +0100
changeset 497371 314051ca8bf470e551761bc0af08a8d767c1b531
parent 497274 f923de5a11109e677c993d7d95d1a9aba1a89e9a
child 548869 7505f8ae30df85ff7f41e999187c7d3eda895798
push id48877
push userbmo:tomica@gmail.com
push dateMon, 13 Mar 2017 08:07:32 +0000
bugs1313648
milestone55.0a1
Bug 1313648 - Add previousVersion to onInstalled details MozReview-Commit-ID: Cmw7zp8CV7e
toolkit/components/extensions/ext-runtime.js
toolkit/components/extensions/schemas/runtime.json
toolkit/components/extensions/test/xpcshell/test_ext_runtime_onInstalled_and_onStartup.js
--- a/toolkit/components/extensions/ext-runtime.js
+++ b/toolkit/components/extensions/ext-runtime.js
@@ -44,17 +44,17 @@ extensions.registerSchemaAPI("runtime", 
               if (Extension.browserUpdated) {
                 fire.sync({reason: "browser_update"});
               }
               break;
             case "ADDON_INSTALL":
               fire.sync({reason: "install"});
               break;
             case "ADDON_UPGRADE":
-              fire.sync({reason: "update"});
+              fire.sync({reason: "update", previousVersion: extension.addonData.oldVersion});
               break;
           }
         };
         extension.on("startup", listener);
         return () => {
           extension.off("startup", listener);
         };
       }).api(),
--- a/toolkit/components/extensions/schemas/runtime.json
+++ b/toolkit/components/extensions/schemas/runtime.json
@@ -468,17 +468,16 @@
             "properties": {
               "reason": {
                 "$ref": "OnInstalledReason",
                 "description": "The reason that this event is being dispatched."
               },
               "previousVersion": {
                 "type": "string",
                 "optional": true,
-                "unsupported": true,
                 "description": "Indicates the previous version of the extension, which has just been updated. This is present only if 'reason' is 'update'."
               },
               "id": {
                 "type": "string",
                 "optional": true,
                 "unsupported": true,
                 "description": "Indicates the ID of the imported shared module extension which updated. This is present only if 'reason' is 'shared_module_update'."
               }
--- a/toolkit/components/extensions/test/xpcshell/test_ext_runtime_onInstalled_and_onStartup.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_runtime_onInstalled_and_onStartup.js
@@ -52,21 +52,24 @@ function background() {
   });
 
   browser.runtime.onUpdateAvailable.addListener(details => {
     browser.test.sendMessage("reloading");
     browser.runtime.reload();
   });
 }
 
-function* expectEvents(extension, {onStartupFired, onInstalledFired, onInstalledReason}) {
+function* expectEvents(extension, {onStartupFired, onInstalledFired, onInstalledReason, onInstalledPrevious}) {
   extension.sendMessage("get-on-installed-details");
   let details = yield extension.awaitMessage("on-installed-details");
   if (onInstalledFired) {
     equal(details.reason, onInstalledReason, "runtime.onInstalled fired with the correct reason");
+    if (onInstalledPrevious) {
+      equal(details.previousVersion, onInstalledPrevious, "runtime.onInstalled after update with correct previousVersion");
+    }
   } else {
     equal(details.fired, onInstalledFired, "runtime.onInstalled should not have fired");
   }
 
   extension.sendMessage("did-on-startup-fire");
   let fired = yield extension.awaitMessage("on-startup-fired");
   equal(fired, onStartupFired, `Expected runtime.onStartup to ${onStartupFired ? "" : "not "} fire`);
 }
@@ -152,16 +155,17 @@ add_task(function* test_should_fire_on_a
   equal(updated_addon.version, "2.0", "The updated addon has the correct version");
 
   yield extension.awaitStartup();
 
   yield expectEvents(extension, {
     onStartupFired: false,
     onInstalledFired: true,
     onInstalledReason: "update",
+    onInstalledPrevious: "1.0",
   });
 
   yield extension.unload();
 
   yield promiseShutdownManager();
 });
 
 add_task(function* test_should_fire_on_browser_update() {