Bug 1285289 - Use the URL of the addon sourceBundle as the sourceURI of temporary addon. r?aswan draft
authorLuca Greco <lgreco@mozilla.com>
Thu, 07 Jul 2016 21:25:35 +0200
changeset 385464 5c8daf47b13e3b07d01b2e9683cf10ff5d1527fc
parent 385040 4a8d8898e507cc918bb1a06cccfd69cb4f3e04b3
child 385465 554c0dbf12a5bae8841cee03647605cd953b2712
push id22511
push userluca.greco@alcacoop.it
push dateFri, 08 Jul 2016 13:44:13 +0000
reviewersaswan
bugs1285289
milestone50.0a1
Bug 1285289 - Use the URL of the addon sourceBundle as the sourceURI of temporary addon. r?aswan MozReview-Commit-ID: KKeIFOMN3yo
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -7610,16 +7610,26 @@ function defineAddonWrapperProperty(name
   defineAddonWrapperProperty(aProp, function() {
     return new Date(addonFor(this)[aProp]);
   });
 });
 
 ["sourceURI", "releaseNotesURI"].forEach(function(aProp) {
   defineAddonWrapperProperty(aProp, function() {
     let addon = addonFor(this);
+
+    // Temporary Installed Addons do not have a "sourceURI",
+    // But we can use the "_sourceBundle" as an alternative,
+    // which points to the path of the addon xpi installed
+    // or its source dir (if it has been installed from a
+    // directory).
+    if (aProp == "sourceURI" && this.temporarilyInstalled) {
+      return Services.io.newFileURI(addon._sourceBundle);
+    }
+
     let [target, fromRepo] = chooseValue(addon, addon, aProp);
     if (!target)
       return null;
     if (fromRepo)
       return target;
     return NetUtil.newURI(target);
   });
 });
--- a/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js
@@ -52,16 +52,21 @@ add_task(function* test_implicit_id_temp
   do_check_eq(addon, null);
 
   let xpifile = do_get_file(IMPLICIT_ID_XPI);
   yield AddonManager.installTemporaryAddon(xpifile);
 
   addon = yield promiseAddonByID(IMPLICIT_ID_ID);
   do_check_neq(addon, null);
 
+  // The sourceURI of a temporary installed addon should be equal to the
+  // file url of the installed xpi file.
+  do_check_eq(addon.sourceURI && addon.sourceURI.spec,
+              Services.io.newFileURI(xpifile).spec);
+
   addon.uninstall();
 });
 
 // We should be able to temporarily install an unsigned web extension
 // that does not have an ID in its manifest.
 add_task(function* test_unsigned_no_id_temp_install() {
   if (!TEST_UNPACKED) {
     do_print("This test does not apply when using packed extensions");
@@ -74,16 +79,21 @@ add_task(function* test_unsigned_no_id_t
     version: "1.0"
   };
 
   const addonDir = writeWebManifestForExtension(manifest, gTmpD,
                                                 "the-addon-sub-dir");
   const addon = yield AddonManager.installTemporaryAddon(addonDir);
   ok(addon.id, "ID should have been auto-generated");
 
+  // The sourceURI of a temporary installed addon should be equal to the
+  // file url of the installed source dir.
+  do_check_eq(addon.sourceURI && addon.sourceURI.spec,
+              Services.io.newFileURI(addonDir).spec);
+
   // Install the same directory again, as if re-installing or reloading.
   const secondAddon = yield AddonManager.installTemporaryAddon(addonDir);
   // The IDs should be the same.
   equal(secondAddon.id, addon.id);
 
   secondAddon.uninstall();
   addonDir.remove(true);
 });