Bug 1428234 Part 1: Remove incorrect uses of persistentDescriptor in AddonManager
MozReview-Commit-ID: 3pyF58rQcoa
--- a/toolkit/mozapps/extensions/internal/XPIInstall.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIInstall.jsm
@@ -1836,26 +1836,26 @@ class AddonInstall {
});
// Update the metadata in the database
this.addon._sourceBundle = file;
this.addon.visible = true;
if (isUpgrade) {
this.addon = XPIDatabase.updateAddonMetadata(this.existingAddon, this.addon,
- file.persistentDescriptor);
+ file.path);
let state = XPIStates.getAddon(this.installLocation.name, this.addon.id);
if (state) {
state.syncWithDB(this.addon, true);
} else {
logger.warn("Unexpected missing XPI state for add-on ${id}", this.addon);
}
} else {
this.addon.active = (this.addon.visible && !this.addon.disabled);
- this.addon = XPIDatabase.addAddonMetadata(this.addon, file.persistentDescriptor);
+ this.addon = XPIDatabase.addAddonMetadata(this.addon, file.path);
XPIStates.addAddon(this.addon);
this.addon.installDate = this.addon.updateDate;
XPIDatabase.saveChanges();
}
XPIStates.save();
let extraParams = {};
if (this.existingAddon) {
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -402,20 +402,17 @@ function getRelativePath(file, dir) {
path = path.replace(/\//g, "\\");
}
return path;
}
return file.path;
}
/**
- * Converts the given opaque descriptor string into an ordinary path
- * string. In practice, the path string is always exactly equal to the
- * descriptor string, but theoretically may not have been on some legacy
- * systems.
+ * Converts the given opaque descriptor string into an ordinary path string.
*
* @param {string} descriptor
* The opaque descriptor string to convert.
* @param {nsIFile} [dir]
* If passed, return a path relative to this directory.
* @returns {string}
* The file's path.
*/
@@ -3621,17 +3618,17 @@ this.XPIProvider = {
addon.state = AddonManager.STATE_INSTALLED;
logger.debug("Install of temporary addon in " + aFile.path + " completed.");
addon.visible = true;
addon.enabled = true;
addon.active = true;
// WebExtension themes are installed as disabled, fix that here.
addon.userDisabled = false;
- addon = XPIDatabase.addAddonMetadata(addon, file.persistentDescriptor);
+ addon = XPIDatabase.addAddonMetadata(addon, file.path);
XPIStates.addAddon(addon);
XPIDatabase.saveChanges();
XPIStates.save();
AddonManagerPrivate.callAddonListeners("onInstalling", addon.wrapper,
false);
XPIProvider.callBootstrapMethod(addon, file, "startup", installReason, extraParams);
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_db_path.js
@@ -0,0 +1,55 @@
+
+Components.utils.import("resource://testing-common/AddonTestUtils.jsm");
+Components.utils.import("resource://gre/modules/FileUtils.jsm");
+const { OS } = Components.utils.import("resource://gre/modules/osfile.jsm", {});
+
+let global = this;
+
+// Test that paths in the extensions database are stored properly
+// if they include non-ascii characters (see bug 1428234 for an example of
+// a past bug with such paths)
+add_task(async function test_non_ascii_path() {
+ let env = Components.classes["@mozilla.org/process/environment;1"]
+ .getService(Components.interfaces.nsIEnvironment);
+ const PROFILE_VAR = "XPCSHELL_TEST_PROFILE_DIR";
+ let profileDir = OS.Path.join(env.get(PROFILE_VAR),
+ "\u00ce \u00e5m \u00f1\u00f8t \u00e5s\u00e7ii");
+ env.set(PROFILE_VAR, profileDir);
+
+ AddonTestUtils.init(global);
+ AddonTestUtils.overrideCertDB();
+ AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1");
+
+ const ID1 = "profile1@tests.mozilla.org";
+ let xpi1 = await AddonTestUtils.createTempWebExtensionFile({
+ id: ID1,
+ manifest: {
+ applications: {gecko: {id: ID1}},
+ },
+ });
+
+ const ID2 = "profile2@tests.mozilla.org";
+ let xpi2 = await AddonTestUtils.createTempWebExtensionFile({
+ id: ID2,
+ manifest: {
+ applications: {gecko: {id: ID2}},
+ },
+ });
+
+ await AddonTestUtils.manuallyInstall(xpi1);
+ await AddonTestUtils.promiseStartupManager();
+ await AddonTestUtils.promiseInstallFile(xpi2);
+ await AddonTestUtils.promiseShutdownManager();
+
+ let dbfile = OS.Path.join(profileDir, "extensions.json");
+ let raw = new TextDecoder().decode(await OS.File.read(dbfile));
+ let data = JSON.parse(raw);
+
+ Assert.ok(Array.isArray(data.addons), "extensions.json has addons array");
+ Assert.equal(2, data.addons.length, "extensions.json has 2 addons");
+ Assert.ok(data.addons[0].path.startsWith(profileDir),
+ "path property for sideloaded extension has the proper profile directory");
+ Assert.ok(data.addons[1].path.startsWith(profileDir),
+ "path property for extension installed at runtime has the proper profile directory");
+});
+
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell-shared.ini
@@ -160,16 +160,18 @@ tags = blocklist
[test_checkcompatibility.js]
[test_childprocess.js]
[test_ChromeManifestParser.js]
[test_compatoverrides.js]
[test_corrupt.js]
[test_corrupt_strictcompat.js]
[test_corruptfile.js]
[test_dataDirectory.js]
+[test_db_path.js]
+head =
[test_default_providers_pref.js]
[test_dictionary.js]
[test_disable.js]
[test_distribution.js]
[test_duplicateplugins.js]
# Bug 676992: test consistently hangs on Android
skip-if = os == "android"
[test_error.js]