Bug 1775393 - Enable Fluent localization in background tasks. r=mossop

The chrome manifest flag parsing is not particularly flexible.  It's
easiest to duplicate the manifest entries rather than further adjust
the parser.

Differential Revision: https://phabricator.services.mozilla.com/D149950
This commit is contained in:
Nick Alexander 2022-06-26 23:38:45 +00:00
parent 8d1555c99b
commit 9651d3efa4
6 changed files with 67 additions and 2 deletions

View File

@ -1 +1,2 @@
category l10n-registry 5-browser resource://app/localization/{locale}/
category l10n-registry 5-browser resource://app/localization/{locale}/ backgroundtask=0
category l10n-registry 5-browser resource://app/localization/{locale}/ backgroundtask=1

View File

@ -65,6 +65,7 @@ TESTING_JS_MODULES.backgroundtasks += [
"tests/BackgroundTask_crash.jsm",
"tests/BackgroundTask_file_exists.jsm",
"tests/BackgroundTask_jsdebugger.jsm",
"tests/BackgroundTask_localization.jsm",
"tests/BackgroundTask_policies.jsm",
"tests/BackgroundTask_profile_is_slim.jsm",
"tests/BackgroundTask_shouldnotprocessupdates.jsm",

View File

@ -0,0 +1,33 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var EXPORTED_SYMBOLS = ["runBackgroundTask"];
const { EXIT_CODE } = ChromeUtils.import(
"resource://gre/modules/BackgroundTasksManager.jsm"
).BackgroundTasksManager;
/**
* Return 0 (success) if in the given resource file, the given string
* identifier has the given string value, 11 (failure) otherwise.
*/
async function runBackgroundTask(commandLine) {
let resource = commandLine.getArgument(0);
let id = commandLine.getArgument(1);
let expected = commandLine.getArgument(2);
let l10n = new Localization([resource]);
let value = await l10n.formatValue(id);
let exitCode = value == expected ? EXIT_CODE.SUCCESS : 11;
console.error(
`runBackgroundTask: in resource '${resource}': for id '${id}', ` +
`expected is '${expected}' and value is '${value}'; ` +
`exiting with status ${exitCode}`
);
return exitCode;
}

View File

@ -0,0 +1,28 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
* vim: sw=4 ts=4 sts=4 et
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
async function doOne(resource, id) {
let l10n = new Localization([resource], true);
let value = await l10n.formatValue(id);
Assert.ok(value, `${id} from ${resource} is not null: ${value}`);
let exitCode = await do_backgroundtask("localization", {
extraArgs: [resource, id, value],
});
Assert.equal(0, exitCode);
}
add_task(async function test_localization() {
// Verify that the `l10n-registry` category is processed and that localization
// works as expected in background tasks. We can use any FTL resource and
// string identifier here as long as the value is short and can be passed as a
// command line argument safely (i.e., is ASCII).
// One from toolkit/.
await doOne("toolkit/global/commonDialog.ftl", "common-dialog-title-system");
// And one from browser/.
await doOne("browser/pageInfo.ftl", "not-set-date");
});

View File

@ -12,6 +12,7 @@ support-files =
[test_backgroundtask_deletes_profile.js]
[test_backgroundtask_exitcodes.js]
[test_backgroundtask_help.js]
[test_backgroundtask_localization.js]
[test_backgroundtask_locked_profile.js]
[test_backgroundtask_policies.js]
[test_backgroundtask_profile_is_slim.js]

View File

@ -1 +1,2 @@
category l10n-registry 0-toolkit resource://gre/localization/{locale}/
category l10n-registry 0-toolkit resource://gre/localization/{locale}/ backgroundtask=0
category l10n-registry 0-toolkit resource://gre/localization/{locale}/ backgroundtask=1