mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1396467 - Add tests for the new langpacks consumption code. r=aswan
MozReview-Commit-ID: BFkV4MuRQh1 --HG-- extra : rebase_source : 56a3701df13dd529db16e79cb170ed14bb5c6fb9
This commit is contained in:
parent
6e92bb8d1f
commit
bac6a262f6
@ -1685,7 +1685,7 @@ this.Langpack = class extends ExtensionData {
|
||||
|
||||
// Check if there's a root directory `/localization` in the langpack.
|
||||
// If there is one, add it with the name `toolkit` as a FileSource.
|
||||
const entries = await this.readDirectory("./localization");
|
||||
const entries = await this.readDirectory("localization");
|
||||
if (entries.length > 0) {
|
||||
l10nRegistrySources.toolkit = "";
|
||||
}
|
||||
@ -1729,6 +1729,9 @@ this.Langpack = class extends ExtensionData {
|
||||
`resource://${this.langpackId}/${basePath}localization/{locale}/`
|
||||
));
|
||||
}
|
||||
|
||||
Services.obs.notifyObservers({wrappedJSObject: {langpack: this}},
|
||||
"webextension-langpack-startup");
|
||||
}
|
||||
|
||||
async shutdown(reason) {
|
||||
|
@ -0,0 +1 @@
|
||||
message-browser = Value from Browser
|
@ -0,0 +1 @@
|
||||
message = Value from .properties
|
@ -0,0 +1 @@
|
||||
message-id1 = Value 1
|
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "und Language Pack",
|
||||
"version": "1.0",
|
||||
"manifest_version": 2,
|
||||
"applications": {
|
||||
"gecko": {
|
||||
"id": "langpack-und@test.mozilla.org",
|
||||
"strict_min_version": "58.0",
|
||||
"strict_max_version": "58.*"
|
||||
}
|
||||
},
|
||||
"sources": {
|
||||
"browser": {
|
||||
"base_path": "browser/"
|
||||
}
|
||||
},
|
||||
"langpack_id": "und",
|
||||
"version": "1",
|
||||
"languages": {
|
||||
"und": {
|
||||
"chrome_resources": {
|
||||
"global": "chrome/und/locale/und/global/"
|
||||
},
|
||||
"version": "20171001190118"
|
||||
}
|
||||
},
|
||||
"author": "Mozilla Localization Task Force",
|
||||
"description": "Language pack for Testy for und"
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
const { Services } = Components.utils.import("resource://gre/modules/Services.jsm", {});
|
||||
const { L10nRegistry } = Components.utils.import("resource://gre/modules/L10nRegistry.jsm", {});
|
||||
|
||||
const ID = "langpack-und@test.mozilla.org";
|
||||
|
||||
const profileDir = gProfD.clone();
|
||||
profileDir.append("extensions");
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "58");
|
||||
startupManager();
|
||||
|
||||
function promiseLangpackStartup() {
|
||||
return new Promise(resolve => {
|
||||
const EVENT = "webextension-langpack-startup";
|
||||
Services.obs.addObserver(function observer() {
|
||||
Services.obs.removeObserver(observer, EVENT);
|
||||
resolve();
|
||||
}, EVENT);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a basic life-cycle test which verifies that
|
||||
* the language pack registers and unregisters correct
|
||||
* languages at various stages.
|
||||
*/
|
||||
add_task(async function() {
|
||||
// Make sure that `und` locale is not installed.
|
||||
equal(L10nRegistry.getAvailableLocales().includes("und"), false);
|
||||
equal(Services.locale.getAvailableLocales().includes("und"), false);
|
||||
|
||||
let [{addon}, ] = await Promise.all([
|
||||
promiseInstallFile(do_get_addon("langpack_1"), true),
|
||||
promiseLangpackStartup()
|
||||
]);
|
||||
|
||||
// Now make sure that `und` locale is available.
|
||||
equal(L10nRegistry.getAvailableLocales().includes("und"), true);
|
||||
equal(Services.locale.getAvailableLocales().includes("und"), true);
|
||||
|
||||
addon.userDisabled = true;
|
||||
|
||||
// It is not available after the langpack has been disabled.
|
||||
equal(L10nRegistry.getAvailableLocales().includes("und"), false);
|
||||
equal(Services.locale.getAvailableLocales().includes("und"), false);
|
||||
|
||||
addon.userDisabled = false;
|
||||
await promiseLangpackStartup();
|
||||
|
||||
// After re-enabling it, the `und` locale is available again.
|
||||
equal(L10nRegistry.getAvailableLocales().includes("und"), true);
|
||||
equal(Services.locale.getAvailableLocales().includes("und"), true);
|
||||
|
||||
addon.uninstall();
|
||||
|
||||
// After the langpack has been uninstalled, no more `und` in locales.
|
||||
equal(L10nRegistry.getAvailableLocales().includes("und"), false);
|
||||
equal(Services.locale.getAvailableLocales().includes("und"), false);
|
||||
});
|
||||
|
||||
/**
|
||||
* This test verifies that registries are able to load and return
|
||||
* correct strings available in the language pack.
|
||||
*/
|
||||
add_task(async function() {
|
||||
let [{addon}, ] = await Promise.all([
|
||||
promiseInstallFile(do_get_addon("langpack_1"), true),
|
||||
promiseLangpackStartup()
|
||||
]);
|
||||
|
||||
{
|
||||
// Toolkit string
|
||||
let ctxs = L10nRegistry.generateContexts(["und"], ["toolkit_test.ftl"]);
|
||||
let ctx0 = (await ctxs.next()).value;
|
||||
equal(ctx0.hasMessage("message-id1"), true);
|
||||
}
|
||||
|
||||
{
|
||||
// Browser string
|
||||
let ctxs = L10nRegistry.generateContexts(["und"], ["browser.ftl"]);
|
||||
let ctx0 = (await ctxs.next()).value;
|
||||
equal(ctx0.hasMessage("message-browser"), true);
|
||||
}
|
||||
|
||||
{
|
||||
// Test chrome package
|
||||
let reqLocs = Services.locale.getRequestedLocales();
|
||||
Services.locale.setRequestedLocales(["und"]);
|
||||
|
||||
let bundle = Services.strings.createBundle(
|
||||
"chrome://global/locale/test.properties"
|
||||
);
|
||||
let entry = bundle.GetStringFromName("message");
|
||||
equal(entry, "Value from .properties");
|
||||
|
||||
Services.locale.setRequestedLocales(reqLocs);
|
||||
}
|
||||
|
||||
addon.uninstall();
|
||||
});
|
||||
|
||||
/**
|
||||
* This test verifies that language pack will get disabled after app
|
||||
* gets upgraded.
|
||||
*/
|
||||
add_task(async function() {
|
||||
let [{addon}, ] = await Promise.all([
|
||||
promiseInstallFile(do_get_addon("langpack_1"), true),
|
||||
promiseLangpackStartup()
|
||||
]);
|
||||
do_check_true(addon.isActive);
|
||||
|
||||
await promiseShutdownManager();
|
||||
|
||||
gAppInfo.version = "59";
|
||||
gAppInfo.platformVersion = "59";
|
||||
|
||||
await promiseStartupManager(true);
|
||||
|
||||
addon = await promiseAddonByID(ID);
|
||||
do_check_false(addon.isActive);
|
||||
do_check_true(addon.appDisabled);
|
||||
|
||||
addon.uninstall();
|
||||
});
|
@ -331,6 +331,9 @@ tags = webextensions
|
||||
[test_webextension_embedded.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
tags = webextensions
|
||||
[test_webextension_langpack.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
tags = webextensions
|
||||
[test_webextension_install_syntax_error.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
tags = webextensions
|
||||
|
Loading…
Reference in New Issue
Block a user