tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_repeated_l10nid.html (1820B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test DOMLocalization's matching l10nIds functionality</title>
      6  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
      8  <script type="application/javascript">
      9  "use strict";
     10  const l10nReg = new L10nRegistry();
     11  const fs = [
     12    { path: "/localization/en-US/mock.ftl", source: `
     13 key1 = Translation For Key 1
     14 
     15 key2 = Visit <a data-l10n-name="link">this link<a/>.
     16 ` },
     17  ];
     18  const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
     19  l10nReg.registerSources([source]);
     20 
     21  SimpleTest.waitForExplicitFinish();
     22  addLoadEvent(async () => {
     23    const domLoc = new DOMLocalization(
     24      ["/mock.ftl"],
     25      false,
     26      l10nReg,
     27      ["en-US"],
     28    );
     29 
     30    await domLoc.translateFragment(document.body);
     31 
     32    ok(document.querySelector("#elem1").textContent.includes("Key 1"));
     33    ok(document.querySelector("#elem2").textContent.includes("Key 1"));
     34 
     35    const elem3 = document.querySelector("#elem3");
     36    const elem4 = document.querySelector("#elem4");
     37 
     38    ok(elem3.textContent.includes("Visit"));
     39    is(elem3.querySelector("a").getAttribute("href"), "http://www.mozilla.org");
     40 
     41    ok(elem4.textContent.includes("Visit"));
     42    is(elem4.querySelector("a").getAttribute("href"), "http://www.firefox.com");
     43 
     44    SimpleTest.finish();
     45  });
     46  </script>
     47 </head>
     48 <body>
     49  <h1 id="elem1" data-l10n-id="key1"></h1>
     50  <h2 id="elem2" data-l10n-id="key1"></h2>
     51 
     52  <p id="elem3" data-l10n-id="key2">
     53    <a href="http://www.mozilla.org" data-l10n-name="link"></a>
     54  </p>
     55 
     56  <p id="elem4" data-l10n-id="key2">
     57    <a href="http://www.firefox.com" data-l10n-name="link"></a>
     58  </p>
     59 </body>
     60 </html>