Bug 1648631: Part 3 - Update tests to work with the revised L10nRegistry API; r=zbraniecki,robwu

Depends on D81390

Differential Revision: https://phabricator.services.mozilla.com/D81391
This commit is contained in:
Aaron Klotz 2020-06-26 20:27:57 +00:00
Родитель d8cc5eeafb
Коммит 5338289548
10 изменённых файлов: 53 добавлений и 69 удалений

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

@ -86,7 +86,7 @@ region-name-tw = Taiwan
let locales = Services.locale.packagedLocales;
const mockSource = new FileSource("mock", locales, "");
L10nRegistry.registerSource(mockSource);
L10nRegistry.registerSources([mockSource]);
}
do_get_profile();

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

@ -19,11 +19,11 @@ protocol.setSubstitution("l10n-test", Services.io.newURI(uri));
// Real sources should use `resource://` protocol.
let locales = Services.locale.appLocalesAsBCP47;
let mockSource = new FileSource("test", locales, `${uri}localization/`);
L10nRegistry.registerSource(mockSource);
L10nRegistry.registerSources([mockSource]);
registerCleanupFunction(() => {
protocol.setSubstitution("l10n-test", null);
L10nRegistry.removeSource("test");
L10nRegistry.removeSources(["test"]);
SpecialPowers.pushPrefEnv({
set: [["dom.ipc.processPrelaunch.enabled", true]],
});

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

@ -19,8 +19,9 @@ L10nRegistry.load = async function(url) {
add_task(function test_methods_presence() {
equal(typeof L10nRegistry.generateBundles, "function");
equal(typeof L10nRegistry.getAvailableLocales, "function");
equal(typeof L10nRegistry.registerSource, "function");
equal(typeof L10nRegistry.updateSource, "function");
equal(typeof L10nRegistry.registerSources, "function");
equal(typeof L10nRegistry.removeSources, "function");
equal(typeof L10nRegistry.updateSources, "function");
});
/**
@ -30,7 +31,7 @@ add_task(async function test_empty_resourceids() {
fs = {};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
const bundles = L10nRegistry.generateBundles(["en-US"], []);
@ -68,7 +69,7 @@ add_task(async function test_methods_calling() {
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
const bundles = L10nRegistry.generateBundles(["en-US"], ["/browser/menu.ftl"]);
@ -89,7 +90,7 @@ add_task(async function test_has_one_source() {
fs = {
"./app/data/locales/en-US/test.ftl": "key = value en-US",
};
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
// has one source
@ -123,10 +124,8 @@ add_task(async function test_has_one_source() {
*/
add_task(async function test_has_two_sources() {
let oneSource = new FileSource("platform", ["en-US"], "./platform/data/locales/{locale}/");
L10nRegistry.registerSource(oneSource);
let secondSource = new FileSource("app", ["pl"], "./app/data/locales/{locale}/");
L10nRegistry.registerSource(secondSource);
L10nRegistry.registerSources([oneSource, secondSource]);
fs = {
"./platform/data/locales/en-US/test.ftl": "key = platform value",
"./app/data/locales/pl/test.ftl": "key = app value",
@ -184,7 +183,7 @@ add_task(async function test_indexed() {
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
fs = {
"/data/locales/pl/test.ftl": "key = value",
};
@ -206,12 +205,10 @@ add_task(async function test_indexed() {
*/
add_task(async function test_override() {
let fileSource = new FileSource("app", ["pl"], "/app/data/locales/{locale}/");
L10nRegistry.registerSource(fileSource);
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([fileSource, oneSource]);
fs = {
"/app/data/locales/pl/test.ftl": "key = value",
@ -248,7 +245,7 @@ add_task(async function test_updating() {
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
fs = {
"/data/locales/pl/test.ftl": "key = value",
};
@ -265,7 +262,7 @@ add_task(async function test_updating() {
"/data/locales/pl/test.ftl",
]);
fs["/data/locales/pl/test.ftl"] = "key = new value";
L10nRegistry.updateSource(newSource);
L10nRegistry.updateSources([newSource]);
equal(L10nRegistry.sources.size, 1);
bundles = L10nRegistry.generateBundles(["pl"], ["test.ftl"]);
@ -283,12 +280,10 @@ add_task(async function test_updating() {
*/
add_task(async function test_removing() {
let fileSource = new FileSource("app", ["pl"], "/app/data/locales/{locale}/");
L10nRegistry.registerSource(fileSource);
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([fileSource, oneSource]);
fs = {
"/app/data/locales/pl/test.ftl": "key = value",
@ -315,7 +310,7 @@ add_task(async function test_removing() {
// Remove langpack
L10nRegistry.removeSource("langpack-pl");
L10nRegistry.removeSources(["langpack-pl"]);
equal(L10nRegistry.sources.size, 1);
equal(L10nRegistry.sources.has("langpack-pl"), false);
@ -331,7 +326,7 @@ add_task(async function test_removing() {
// Remove app source
L10nRegistry.removeSource("app");
L10nRegistry.removeSources(["app"]);
equal(L10nRegistry.sources.size, 0);
@ -348,9 +343,8 @@ add_task(async function test_removing() {
*/
add_task(async function test_missing_file() {
let oneSource = new FileSource("app", ["en-US"], "./app/data/locales/{locale}/");
L10nRegistry.registerSource(oneSource);
let twoSource = new FileSource("platform", ["en-US"], "./platform/data/locales/{locale}/");
L10nRegistry.registerSource(twoSource);
L10nRegistry.registerSources([oneSource, twoSource]);
fs = {
"./app/data/locales/en-US/test.ftl": "key = value en-US",
@ -422,7 +416,7 @@ add_task(async function test_parallel_io() {
return Promise.resolve("");
};
let oneSource = new FileSource("app", ["en-US"], "/{locale}/");
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
fs = {
"/en-US/test.ftl": "key = value en-US",
@ -455,7 +449,7 @@ add_task(async function test_hasSource() {
equal(L10nRegistry.hasSource("gobbledygook"), false, "Non-existing source doesn't exist");
equal(L10nRegistry.hasSource("app"), false, "hasSource returns true before registering a source");
let oneSource = new FileSource("app", ["en-US"], "/{locale}/");
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
equal(L10nRegistry.hasSource("app"), true, "hasSource returns true after registering a source");
L10nRegistry.sources.clear();
});
@ -466,10 +460,8 @@ add_task(async function test_hasSource() {
*/
add_task(async function test_remove_source_mid_iter_cycle() {
let oneSource = new FileSource("platform", ["en-US"], "./platform/data/locales/{locale}/");
L10nRegistry.registerSource(oneSource);
let secondSource = new FileSource("app", ["pl"], "./app/data/locales/{locale}/");
L10nRegistry.registerSource(secondSource);
L10nRegistry.registerSources([oneSource, secondSource]);
fs = {
"./platform/data/locales/en-US/test.ftl": "key = platform value",
@ -480,7 +472,7 @@ add_task(async function test_remove_source_mid_iter_cycle() {
let bundle0 = await bundles.next();
L10nRegistry.removeSource("app");
L10nRegistry.removeSources(["app"]);
equal((await bundles.next()).done, true);

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

@ -20,8 +20,9 @@ L10nRegistry.loadSync = function(url) {
add_task(function test_methods_presence() {
equal(typeof L10nRegistry.generateBundles, "function");
equal(typeof L10nRegistry.getAvailableLocales, "function");
equal(typeof L10nRegistry.registerSource, "function");
equal(typeof L10nRegistry.updateSource, "function");
equal(typeof L10nRegistry.registerSources, "function");
equal(typeof L10nRegistry.removeSources, "function");
equal(typeof L10nRegistry.updateSources, "function");
});
/**
@ -31,7 +32,7 @@ add_task(function test_empty_resourceids() {
fs = {};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
const bundles = L10nRegistry.generateBundlesSync(["en-US"], []);
@ -69,7 +70,7 @@ add_task(function test_methods_calling() {
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
const bundles = L10nRegistry.generateBundlesSync(["en-US"], ["/browser/menu.ftl"]);
@ -90,7 +91,7 @@ add_task(function test_has_one_source() {
fs = {
"./app/data/locales/en-US/test.ftl": "key = value en-US",
};
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
// has one source
@ -124,10 +125,8 @@ add_task(function test_has_one_source() {
*/
add_task(function test_has_two_sources() {
let oneSource = new FileSource("platform", ["en-US"], "./platform/data/locales/{locale}/");
L10nRegistry.registerSource(oneSource);
let secondSource = new FileSource("app", ["pl"], "./app/data/locales/{locale}/");
L10nRegistry.registerSource(secondSource);
L10nRegistry.registerSources([oneSource, secondSource]);
fs = {
"./platform/data/locales/en-US/test.ftl": "key = platform value",
"./app/data/locales/pl/test.ftl": "key = app value",
@ -185,7 +184,7 @@ add_task(function test_indexed() {
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
fs = {
"/data/locales/pl/test.ftl": "key = value",
};
@ -207,12 +206,10 @@ add_task(function test_indexed() {
*/
add_task(function test_override() {
let fileSource = new FileSource("app", ["pl"], "/app/data/locales/{locale}/");
L10nRegistry.registerSource(fileSource);
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([fileSource, oneSource]);
fs = {
"/app/data/locales/pl/test.ftl": "key = value",
@ -249,7 +246,7 @@ add_task(function test_updating() {
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
fs = {
"/data/locales/pl/test.ftl": "key = value",
};
@ -266,7 +263,7 @@ add_task(function test_updating() {
"/data/locales/pl/test.ftl",
]);
fs["/data/locales/pl/test.ftl"] = "key = new value";
L10nRegistry.updateSource(newSource);
L10nRegistry.updateSources([newSource]);
equal(L10nRegistry.sources.size, 1);
bundles = L10nRegistry.generateBundlesSync(["pl"], ["test.ftl"]);
@ -284,12 +281,10 @@ add_task(function test_updating() {
*/
add_task(function test_removing() {
let fileSource = new FileSource("app", ["pl"], "/app/data/locales/{locale}/");
L10nRegistry.registerSource(fileSource);
let oneSource = new IndexedFileSource("langpack-pl", ["pl"], "/data/locales/{locale}/", [
"/data/locales/pl/test.ftl",
]);
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([fileSource, oneSource]);
fs = {
"/app/data/locales/pl/test.ftl": "key = value",
@ -316,7 +311,7 @@ add_task(function test_removing() {
// Remove langpack
L10nRegistry.removeSource("langpack-pl");
L10nRegistry.removeSources(["langpack-pl"]);
equal(L10nRegistry.sources.size, 1);
equal(L10nRegistry.sources.has("langpack-pl"), false);
@ -332,7 +327,7 @@ add_task(function test_removing() {
// Remove app source
L10nRegistry.removeSource("app");
L10nRegistry.removeSources(["app"]);
equal(L10nRegistry.sources.size, 0);
@ -349,9 +344,8 @@ add_task(function test_removing() {
*/
add_task(function test_missing_file() {
let oneSource = new FileSource("app", ["en-US"], "./app/data/locales/{locale}/");
L10nRegistry.registerSource(oneSource);
let twoSource = new FileSource("platform", ["en-US"], "./platform/data/locales/{locale}/");
L10nRegistry.registerSource(twoSource);
L10nRegistry.registerSources([oneSource, twoSource]);
fs = {
"./app/data/locales/en-US/test.ftl": "key = value en-US",
@ -423,7 +417,7 @@ add_task(function test_parallel_io() {
return Promise.resolve("");
};
let oneSource = new FileSource("app", ["en-US"], "/{locale}/");
L10nRegistry.registerSource(oneSource);
L10nRegistry.registerSources([oneSource]);
fs = {
"/en-US/test.ftl": "key = value en-US",
@ -458,10 +452,8 @@ add_task(function test_parallel_io() {
*/
add_task(function test_remove_source_mid_iter_cycle() {
let oneSource = new FileSource("platform", ["en-US"], "./platform/data/locales/{locale}/");
L10nRegistry.registerSource(oneSource);
let secondSource = new FileSource("app", ["pl"], "./app/data/locales/{locale}/");
L10nRegistry.registerSource(secondSource);
L10nRegistry.registerSources([oneSource, secondSource]);
fs = {
"./platform/data/locales/en-US/test.ftl": "key = platform value",
@ -472,7 +464,7 @@ add_task(function test_remove_source_mid_iter_cycle() {
let bundle0 = bundles.next();
L10nRegistry.removeSource("app");
L10nRegistry.removeSources(["app"]);
equal((bundles.next()).done, true);

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

@ -33,7 +33,7 @@ key-attr =
};
const source = new FileSource("test", ["de", "en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
async function* generateBundles(resIds) {
yield * await L10nRegistry.generateBundles(["de", "en-US"], resIds);
@ -123,7 +123,7 @@ key = { PLATFORM() ->
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
async function* generateBundles(resIds) {
yield * await L10nRegistry.generateBundles(["en-US"], resIds);
@ -158,7 +158,7 @@ add_task(async function test_add_remove_resourceIds() {
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
async function* generateBundles(resIds) {
yield * await L10nRegistry.generateBundles(["en-US"], resIds);
@ -226,7 +226,7 @@ add_task(async function test_switch_to_async() {
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
async function* generateBundles(resIds) {
yield * await L10nRegistry.generateBundles(["en-US"], resIds);

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

@ -27,7 +27,7 @@ key-attr =
};
const source = new FileSource("test", ["de", "en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
function* generateBundlesSync(resIds) {
yield * L10nRegistry.generateBundlesSync(["de", "en-US"], resIds);
@ -118,7 +118,7 @@ key = { PLATFORM() ->
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
function* generateBundlesSync(resIds) {
yield * L10nRegistry.generateBundlesSync(["en-US"], resIds);
@ -153,7 +153,7 @@ add_task(function test_add_remove_resourceIds() {
};
const source = new FileSource("test", ["en-US"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
function* generateBundlesSync(resIds) {
yield * L10nRegistry.generateBundlesSync(["en-US"], resIds);

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

@ -22,7 +22,7 @@ key = This is a single message
};
const source = new FileSource("test", ["de"], "/localization/{locale}");
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
return async function* generateMessages(resIds) {
yield * await L10nRegistry.generateBundles(["de"], resIds);

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

@ -34,7 +34,7 @@ add_task(async function setup() {
Services.locale.requestedLocales,
"resource://l10ntest/"
);
L10nRegistry.registerSource(source);
L10nRegistry.registerSources([source]);
});
// Test that privileged extensions can use fluent to get strings from

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

@ -25,7 +25,7 @@ L10nRegistry.loadSync = function(url) {
let locales = Services.locale.packagedLocales;
const mockSource = new FileSource("mock", locales, "");
L10nRegistry.registerSource(mockSource);
L10nRegistry.registerSources([mockSource]);
const gLangDN = Services.intl.getLanguageDisplayNames.bind(
Services.intl,

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

@ -219,13 +219,13 @@ add_task(async function test_setup() {
// Register a fake it-IT locale (used to test localized AMO details in some
// of the test case defined in this test file).
L10nRegistry.registerSource(
L10nRegistry.registerSources([
new FileSource(
"mock",
["it-IT", "fr-FR"],
"resource://fake/locales/{locale}"
)
);
),
]);
});
add_task(async function test_addon_report_data() {