From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../extensions/test/xpcshell/test_locale.js | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/xpcshell/test_locale.js (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_locale.js') diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_locale.js b/toolkit/mozapps/extensions/test/xpcshell/test_locale.js new file mode 100644 index 0000000000..2824c489b4 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_locale.js @@ -0,0 +1,103 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ +add_task(async function setup() { + // Setup for test + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + await promiseStartupManager(); +}); + +// Tests that the localized properties are visible before installation +add_task(async function test_1() { + await restartWithLocales(["fr-FR"]); + + let xpi = AddonTestUtils.createTempWebExtensionFile({ + manifest: { + name: "__MSG_name__", + description: "__MSG_description__", + default_locale: "en", + + browser_specific_settings: { + gecko: { + id: "addon1@tests.mozilla.org", + }, + }, + }, + + files: { + "_locales/en/messages.json": { + name: { + message: "Fallback Name", + description: "name", + }, + description: { + message: "Fallback Description", + description: "description", + }, + }, + "_locales/fr_FR/messages.json": { + name: { + message: "fr-FR Name", + description: "name", + }, + description: { + message: "fr-FR Description", + description: "description", + }, + }, + "_locales/de-DE/messages.json": { + name: { + message: "de-DE Name", + description: "name", + }, + }, + }, + }); + + let install = await AddonManager.getInstallForFile(xpi); + Assert.equal(install.addon.name, "fr-FR Name"); + Assert.equal(install.addon.description, "fr-FR Description"); + await install.install(); +}); + +// Tests that the localized properties are visible after installation +add_task(async function test_2() { + let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org"); + Assert.notEqual(addon, null); + + Assert.equal(addon.name, "fr-FR Name"); + Assert.equal(addon.description, "fr-FR Description"); + + await addon.disable(); +}); + +// Test that the localized properties are still there when disabled. +add_task(async function test_3() { + let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org"); + Assert.notEqual(addon, null); + Assert.equal(addon.name, "fr-FR Name"); +}); + +// Test that changing locale works +add_task(async function test_5() { + await restartWithLocales(["de-DE"]); + + let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org"); + Assert.notEqual(addon, null); + + Assert.equal(addon.name, "de-DE Name"); + Assert.equal(addon.description, "Fallback Description"); +}); + +// Test that missing locales use the fallbacks +add_task(async function test_6() { + await restartWithLocales(["nl-NL"]); + + let addon = await AddonManager.getAddonByID("addon1@tests.mozilla.org"); + Assert.notEqual(addon, null); + + Assert.equal(addon.name, "Fallback Name"); + Assert.equal(addon.description, "Fallback Description"); + + await addon.enable(); +}); -- cgit v1.2.3