From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../tests/browser/browser_l10n_localizeMarkup.js | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 devtools/shared/tests/browser/browser_l10n_localizeMarkup.js (limited to 'devtools/shared/tests/browser/browser_l10n_localizeMarkup.js') diff --git a/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js new file mode 100644 index 0000000000..9c4118b572 --- /dev/null +++ b/devtools/shared/tests/browser/browser_l10n_localizeMarkup.js @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +// Tests that the markup localization works properly. + +const { + localizeMarkup, + LocalizationHelper, +} = require("resource://devtools/shared/l10n.js"); +const HTML_NS = "http://www.w3.org/1999/xhtml"; + +add_task(async function () { + info("Check that the strings used for this test are still valid"); + const STARTUP_L10N = new LocalizationHelper( + "devtools/client/locales/startup.properties" + ); + const TOOLBOX_L10N = new LocalizationHelper( + "devtools/client/locales/toolbox.properties" + ); + const str1 = STARTUP_L10N.getStr("inspector.label"); + const str2 = STARTUP_L10N.getStr("inspector.accesskey"); + const str3 = TOOLBOX_L10N.getStr("toolbox.defaultTitle"); + ok( + str1 && str2 && str3, + "If this failed, strings should be updated in the test" + ); + + info("Create the test markup"); + const div = document.createElementNS(HTML_NS, "div"); + div.setAttribute( + "data-localization-bundle", + "devtools/client/locales/startup.properties" + ); + const div0 = document.createElementNS(HTML_NS, "div"); + div0.setAttribute("id", "d0"); + div0.setAttribute("data-localization", "content=inspector.someInvalidKey"); + div.appendChild(div0); + const div1 = document.createElementNS(HTML_NS, "div"); + div1.setAttribute("id", "d1"); + div1.setAttribute("data-localization", "content=inspector.label"); + div.appendChild(div1); + div1.append("Text will disappear"); + const div2 = document.createElementNS(HTML_NS, "div"); + div2.setAttribute("id", "d2"); + div2.setAttribute( + "data-localization", + "content=inspector.label;title=inspector.accesskey" + ); + div.appendChild(div2); + const div3 = document.createElementNS(HTML_NS, "div"); + div3.setAttribute("id", "d3"); + div3.setAttribute( + "data-localization", + "content=inspector.label;title=inspector.accesskey" + ); + div.appendChild(div3); + const div4 = document.createElementNS(HTML_NS, "div"); + div4.setAttribute("id", "d4"); + div4.setAttribute("data-localization", "aria-label=inspector.label"); + div.appendChild(div4); + div4.append("Some content"); + const toolboxDiv = document.createElementNS(HTML_NS, "div"); + toolboxDiv.setAttribute( + "data-localization-bundle", + "devtools/client/locales/toolbox.properties" + ); + div.appendChild(toolboxDiv); + const div5 = document.createElementNS(HTML_NS, "div"); + div5.setAttribute("id", "d5"); + div5.setAttribute("data-localization", "content=toolbox.defaultTitle"); + toolboxDiv.appendChild(div5); + + info("Use localization helper to localize the test markup"); + localizeMarkup(div); + + is(div1.innerHTML, str1, "The content of #d1 is localized"); + is(div2.innerHTML, str1, "The content of #d2 is localized"); + is(div2.getAttribute("title"), str2, "The title of #d2 is localized"); + is(div3.innerHTML, str1, "The content of #d3 is localized"); + is(div3.getAttribute("title"), str2, "The title of #d3 is localized"); + is(div4.innerHTML, "Some content", "The content of #d4 is not replaced"); + is( + div4.getAttribute("aria-label"), + str1, + "The aria-label of #d4 is localized" + ); + is( + div5.innerHTML, + str3, + "The content of #d5 is localized with another bundle" + ); +}); -- cgit v1.2.3