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 --- .../newtab/test/browser/browser_remote_l10n.js | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 browser/components/newtab/test/browser/browser_remote_l10n.js (limited to 'browser/components/newtab/test/browser/browser_remote_l10n.js') diff --git a/browser/components/newtab/test/browser/browser_remote_l10n.js b/browser/components/newtab/test/browser/browser_remote_l10n.js new file mode 100644 index 0000000000..967236a721 --- /dev/null +++ b/browser/components/newtab/test/browser/browser_remote_l10n.js @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { RemoteL10n } = ChromeUtils.importESModule( + "resource://activity-stream/lib/RemoteL10n.sys.mjs" +); + +const ID = "remote_l10n_test_string"; +const VALUE = "RemoteL10n string"; +const CONTENT = `${ID} = ${VALUE}`; + +add_setup(async () => { + const l10nRegistryInstance = L10nRegistry.getInstance(); + const localProfileDir = Services.dirsvc.get("ProfD", Ci.nsIFile).path; + const dirPath = PathUtils.join( + localProfileDir, + ...["settings", "main", "ms-language-packs", "browser", "newtab"] + ); + const filePath = PathUtils.join(dirPath, "asrouter.ftl"); + + await IOUtils.makeDirectory(dirPath, { + ignoreExisting: true, + from: localProfileDir, + }); + await IOUtils.writeUTF8(filePath, CONTENT, { + tmpPath: `${filePath}.tmp`, + }); + + // Remove any cached l10n resources, "cfr" is the cache key + // used for strings from the remote `asrouter.ftl` see RemoteL10n.sys.mjs + RemoteL10n.reloadL10n(); + if (l10nRegistryInstance.hasSource("cfr")) { + l10nRegistryInstance.removeSources(["cfr"]); + } +}); + +add_task(async function test_TODO() { + let [{ value }] = await RemoteL10n.l10n.formatMessages([{ id: ID }]); + + Assert.equal(value, VALUE, "Got back the string we wrote to disk"); +}); + +// Test that the formatting helper works. This helper is lower-level than the +// DOM localization apparatus, and as such doesn't require the weight of the +// `browser` test framework, but it's nice to co-locate related tests. +add_task(async function test_formatLocalizableText() { + let value = await RemoteL10n.formatLocalizableText({ string_id: ID }); + + Assert.equal(value, VALUE, "Got back the string we wrote to disk"); + + value = await RemoteL10n.formatLocalizableText("unchanged"); + + Assert.equal(value, "unchanged", "Got back the string provided"); +}); -- cgit v1.2.3