Bug 1677135 fix APP_SHUTDOWN for langpacks r=rpl,zbraniecki

Differential Revision: https://phabricator.services.mozilla.com/D97204
This commit is contained in:
Shane Caraveo 2020-11-19 20:18:17 +00:00
parent 35fe61fa35
commit 50b906c350
5 changed files with 124 additions and 43 deletions

View File

@ -118,6 +118,14 @@ class L10nRegistryService {
}
}
/**
* Empty the sources to mimic shutdown for testing from xpcshell.
*/
clearSources() {
this.sources = new Map();
Services.locale.availableLocales = this.getAvailableLocales();
}
handleEvent(event) {
if (event.type === "change") {
if (event.changedKeys.includes("L10nRegistry:Sources")) {

View File

@ -1844,18 +1844,19 @@ class DictionaryBootstrapScope extends BootstrapScope {
}
}
class LangpackBootstrapScope {
class LangpackBootstrapScope extends BootstrapScope {
install(data, reason) {}
uninstall(data, reason) {}
update(data, reason) {}
startup(data, reason) {
// eslint-disable-next-line no-use-before-define
this.langpack = new Langpack(data);
return this.langpack.startup();
return this.langpack.startup(this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
}
shutdown(data, reason) {
this.langpack.shutdown();
this.langpack.shutdown(this.BOOTSTRAP_REASON_TO_STRING_MAP[reason]);
this.langpack = null;
}
}

View File

@ -2,17 +2,24 @@
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const { AddonManager } = ChromeUtils.import(
"resource://gre/modules/AddonManager.jsm"
);
const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",
"XPCShell",
"1",
"42",
"42"
);
@ -65,6 +72,41 @@ add_task(async function() {
Preferences.set("extensions.logging.enabled", false);
await AddonTestUtils.promiseStartupManager();
// Install langpacks to get proper locale startup.
let langpack = {
"manifest.json": {
name: "test Language Pack",
version: "1.0",
manifest_version: 2,
applications: {
gecko: {
id: "@test-langpack",
strict_min_version: "42.0",
strict_max_version: "42.0",
},
},
langpack_id: "fr",
languages: {
fr: {
chrome_resources: {
global: "chrome/fr/locale/fr/global/",
},
version: "20171001190118",
},
},
sources: {
browser: {
base_path: "browser/",
},
},
},
};
let [, { addon }] = await Promise.all([
TestUtils.topicObserved("webextension-langpack-startup"),
AddonTestUtils.promiseInstallXPI(langpack),
]);
let extension = ExtensionTestUtils.loadExtension(
makeExtension({ version: "1.0" })
);
@ -80,7 +122,7 @@ add_task(async function() {
//
// In the future, we should provide some way for tests to decouple their
// language selection from that of Firefox.
Services.locale.availableLocales = ["en-US", "fr", "jp"];
ok(Services.locale.availableLocales.includes("fr"), "fr locale is avialable");
await extension.startup();
@ -121,5 +163,10 @@ add_task(async function() {
manifest = await getManifest();
equal(manifest.name, "en-US 1.1", "Got expected manifest name");
info("uninstall locale 'fr'");
addon = await AddonManager.getAddonByID("@test-langpack");
await addon.uninstall();
ok(!Services.locale.availableLocales.includes("fr"), "fr locale is removed");
await extension.unload();
});

View File

@ -31,42 +31,16 @@ const { EventEmitter } = ChromeUtils.import(
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter(
this,
"AMTelemetry",
"resource://gre/modules/AddonManager.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"ExtensionTestCommon",
"resource://testing-common/ExtensionTestCommon.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"Management",
"resource://gre/modules/Extension.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"ExtensionAddonObserver",
"resource://gre/modules/Extension.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"FileTestUtils",
"resource://testing-common/FileTestUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"HttpServer",
"resource://testing-common/httpd.js"
);
ChromeUtils.defineModuleGetter(
this,
"MockRegistrar",
"resource://testing-common/MockRegistrar.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
AMTelemetry: "resource://gre/modules/AddonManager.jsm",
ExtensionTestCommon: "resource://testing-common/ExtensionTestCommon.jsm",
Management: "resource://gre/modules/Extension.jsm",
ExtensionAddonObserver: "resource://gre/modules/Extension.jsm",
FileTestUtils: "resource://testing-common/FileTestUtils.jsm",
HttpServer: "resource://testing-common/httpd.js",
L10nRegistry: "resource://gre/modules/L10nRegistry.jsm",
MockRegistrar: "resource://testing-common/MockRegistrar.jsm",
});
XPCOMUtils.defineLazyServiceGetters(this, {
aomStartup: [
@ -1059,6 +1033,9 @@ var AddonTestUtils = {
Services.obs.notifyObservers(file, "flush-cache-entry");
}
// Clear L10nRegistry entries so restaring the AOM will work correctly with locales.
L10nRegistry.clearSources();
// Clear any crash report annotations
this.appInfo.annotations = {};

View File

@ -11,6 +11,12 @@ const { ExtensionUtils } = ChromeUtils.import(
"resource://gre/modules/ExtensionUtils.jsm"
);
XPCOMUtils.defineLazyGetter(this, "resourceProtocol", () =>
Services.io
.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler)
);
Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
const ID = "langpack-und@test.mozilla.org";
@ -299,10 +305,52 @@ add_task(async function test_locale_registries_async() {
await promiseShutdownManager();
});
add_task(async function test_langpack_app_shutdown() {
let langpackId = `langpack-und-${AppConstants.MOZ_BUILD_APP.replace(
"/",
"-"
)}`;
let check = (yes, msg) => {
equal(resourceProtocol.hasSubstitution(langpackId), yes, msg);
};
await promiseStartupManager();
check(false, "no initial resource substitution");
await Promise.all([
promiseLangpackStartup(),
AddonTestUtils.promiseInstallXPI(ADDONS.langpack_1),
]);
check(true, "langpack resource available after startup");
await promiseShutdownManager();
check(true, "langpack resource available after app shutdown");
await promiseStartupManager();
let addon = await AddonManager.getAddonByID(ID);
await addon.uninstall();
check(false, "langpack resource removed during shutdown for uninstall");
await promiseShutdownManager();
});
add_task(async function test_amazing_disappearing_langpacks() {
let check = yes => {
equal(L10nRegistry.getAvailableLocales().includes("und"), yes);
equal(Services.locale.availableLocales.includes("und"), yes);
equal(
L10nRegistry.getAvailableLocales().includes("und"),
yes,
"check L10nRegistry"
);
equal(
Services.locale.availableLocales.includes("und"),
yes,
"check availableLocales"
);
};
await promiseStartupManager();