summaryrefslogtreecommitdiffstats
path: root/dom/l10n/tests/mochitest/dom_localization/test_repeated_l10nid.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/l10n/tests/mochitest/dom_localization/test_repeated_l10nid.html')
-rw-r--r--dom/l10n/tests/mochitest/dom_localization/test_repeated_l10nid.html60
1 files changed, 60 insertions, 0 deletions
diff --git a/dom/l10n/tests/mochitest/dom_localization/test_repeated_l10nid.html b/dom/l10n/tests/mochitest/dom_localization/test_repeated_l10nid.html
new file mode 100644
index 0000000000..64d585f0a0
--- /dev/null
+++ b/dom/l10n/tests/mochitest/dom_localization/test_repeated_l10nid.html
@@ -0,0 +1,60 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test DOMLocalization's matching l10nIds functionality</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+ <script type="application/javascript">
+ "use strict";
+ const l10nReg = new L10nRegistry();
+ const fs = [
+ { path: "/localization/en-US/mock.ftl", source: `
+key1 = Translation For Key 1
+
+key2 = Visit <a data-l10n-name="link">this link<a/>.
+` },
+ ];
+ const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
+ l10nReg.registerSources([source]);
+
+ SimpleTest.waitForExplicitFinish();
+ addLoadEvent(async () => {
+ const domLoc = new DOMLocalization(
+ ["/mock.ftl"],
+ false,
+ l10nReg,
+ ["en-US"],
+ );
+
+ await domLoc.translateFragment(document.body);
+
+ ok(document.querySelector("#elem1").textContent.includes("Key 1"));
+ ok(document.querySelector("#elem2").textContent.includes("Key 1"));
+
+ const elem3 = document.querySelector("#elem3");
+ const elem4 = document.querySelector("#elem4");
+
+ ok(elem3.textContent.includes("Visit"));
+ is(elem3.querySelector("a").getAttribute("href"), "http://www.mozilla.org");
+
+ ok(elem4.textContent.includes("Visit"));
+ is(elem4.querySelector("a").getAttribute("href"), "http://www.firefox.com");
+
+ SimpleTest.finish();
+ });
+ </script>
+</head>
+<body>
+ <h1 id="elem1" data-l10n-id="key1"></h1>
+ <h2 id="elem2" data-l10n-id="key1"></h2>
+
+ <p id="elem3" data-l10n-id="key2">
+ <a href="http://www.mozilla.org" data-l10n-name="link"></a>
+ </p>
+
+ <p id="elem4" data-l10n-id="key2">
+ <a href="http://www.firefox.com" data-l10n-name="link"></a>
+ </p>
+</body>
+</html>