Bug 1538975 read the raw extension manifest if we need to localize it r=rpl

Differential Revision: https://phabricator.services.mozilla.com/D24803

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Shane Caraveo 2019-03-26 15:35:53 +00:00
Родитель f81aa92481
Коммит 237485f661
2 изменённых файлов: 43 добавлений и 0 удалений

Просмотреть файл

@ -578,6 +578,13 @@ class ExtensionData {
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,

Просмотреть файл

@ -2,6 +2,10 @@
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);
@ -139,3 +143,35 @@ add_task(async function testExtractLocalizedManifest() {
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();
});