Bug 1538975 read the raw extension manifest if we need to localize it r=rpl
authorShane Caraveo <scaraveo@mozilla.com>
Tue, 26 Mar 2019 15:35:53 +0000
changeset 466116 6070d963e387db57215201580c75b78de9766c75
parent 466115 f755dfcfc421e45d63aef09ca95805c1cbd34a4d
child 466117 3a212aece7e4ae048615644fa52699ceeb1d9b88
push id35761
push userdvarga@mozilla.com
push dateTue, 26 Mar 2019 21:49:44 +0000
treeherdermozilla-central@0969fd6383ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1538975
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1538975 read the raw extension manifest if we need to localize it r=rpl Differential Revision: https://phabricator.services.mozilla.com/D24803
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/test/xpcshell/test_locale_data.js
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -573,16 +573,23 @@ class ExtensionData {
    *
    * @param {string} locale to load, if necessary.
    * @returns {object} normalized manifest.
    */
   async getLocalizedManifest(locale) {
     if (!this.type || !this.localeData) {
       throw new Error("The extension has not been initialized.");
     }
+    // Upon update or reinstall, the Extension.manifest may be read from
+    // StartupCache.manifest, however rawManifest is *not*.  We need the
+    // raw manifest in order to get a localized manifest.
+    if (!this.rawManifest) {
+      this.rawManifest = await this.readJSON("manifest.json");
+    }
+
     if (!this.localeData.has(locale)) {
       // Locales are not avialable until some additional
       // initialization is done.  We could just call initAllLocales,
       // but that is heavy handed, especially when we likely only
       // need one out of 20.
       let locales = await this.promiseLocales();
       if (locales.get(locale)) {
         await this.initLocale(locale);
--- a/toolkit/components/extensions/test/xpcshell/test_locale_data.js
+++ b/toolkit/components/extensions/test/xpcshell/test_locale_data.js
@@ -1,12 +1,16 @@
 "use strict";
 
 const {ExtensionData} = ChromeUtils.import("resource://gre/modules/Extension.jsm");
 
+AddonTestUtils.init(this);
+AddonTestUtils.overrideCertDB();
+AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
+
 async function generateAddon(data) {
   let xpi = AddonTestUtils.createTempWebExtensionFile(data);
 
   let fileURI = Services.io.newFileURI(xpi);
   let jarURI = NetUtil.newURI(`jar:${fileURI.spec}!/`);
 
   let extension = new ExtensionData(jarURI);
   await extension.loadManifest();
@@ -134,8 +138,40 @@ add_task(async function testExtractLocal
 
   let manifest = await extension.getLocalizedManifest("de-DE");
   ok(extension.localeData.has("de-DE"), "has de_DE locale");
   equal(manifest.name, "bar", "name localized");
 
   await Assert.rejects(extension.getLocalizedManifest("xx-XX"),
                        /does not contain the locale xx-XX/, "xx-XX does not exist");
 });
+
+add_task(async function testRestartThenExtractLocalizedManifest() {
+  await AddonTestUtils.promiseStartupManager();
+
+  let wrapper = ExtensionTestUtils.loadExtension({
+    "manifest": {
+      "name": "__MSG_extensionName__",
+      "default_locale": "en_US",
+    },
+    useAddonManager: "permanent",
+    "files": {
+      "_locales/en_US/messages.json": '{"extensionName": {"message": "foo"}}',
+      "_locales/de_DE/messages.json": '{"extensionName": {"message": "bar"}}',
+    },
+  });
+
+  await wrapper.startup();
+
+  await AddonTestUtils.promiseRestartManager();
+  await wrapper.startupPromise;
+
+  let {extension} = wrapper;
+  let manifest = await extension.getLocalizedManifest("de-DE");
+  ok(extension.localeData.has("de-DE"), "has de_DE locale");
+  equal(manifest.name, "bar", "name localized");
+
+  await Assert.rejects(extension.getLocalizedManifest("xx-XX"),
+                       /does not contain the locale xx-XX/, "xx-XX does not exist");
+
+  await wrapper.unload();
+  await AddonTestUtils.promiseShutdownManager();
+});