tor-browser

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

test_l10n_overlays.xhtml (2562B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
      4                 type="text/css"?>
      5 
      6 
      7 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      8        xmlns:html="http://www.w3.org/1999/xhtml"
      9        title="Testing DocumentL10n in XUL environment">
     10 
     11  <linkset>
     12    <html:link rel="localization" href="toolkit/about/aboutAddons.ftl"/>
     13  </linkset>
     14 
     15  <script type="application/javascript"
     16          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
     17  <script type="application/javascript">
     18  <![CDATA[
     19  /* global L10nOverlays */
     20 
     21  function elem(name) {
     22    return function(str) {
     23      const element = document.createXULElement(name);
     24      element.innerHTML = str;
     25      return element;
     26    };
     27  }
     28 
     29  const { translateElement } = L10nOverlays;
     30 
     31  SimpleTest.waitForExplicitFinish();
     32 
     33  {
     34    // Allowed attribute
     35    const element = elem("description")``;
     36    const translation = {
     37      value: null,
     38      attributes: [
     39        {name: "title", value: "FOO"},
     40      ],
     41    };
     42    translateElement(element, translation);
     43    is(element.outerHTML, '<description xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" title="FOO"/>');
     44  }
     45 
     46  document.addEventListener("DOMContentLoaded", () => {
     47    {
     48      // Handle HTML translation
     49      const element = document.getElementById("test2");
     50      const translation = {
     51      value: "This is <a data-l10n-name=\"link\">a link</a>.",
     52        attributes: null,
     53      };
     54      translateElement(element, translation);
     55      is(element.innerHTML, 'This is <html:a xmlns:html="http://www.w3.org/1999/xhtml" data-l10n-name=\"link\" href="https://www.mozilla.org\">a link</html:a>.');
     56    }
     57 
     58    {
     59      // Don't handle XUL translation
     60      //
     61      // Current iteration of L10nOverlays will replace
     62      // XUL elements from translation with text.
     63      //
     64      // See bug 1545704 for details.
     65      const element = document.getElementById("test3");
     66      const translation = {
     67      value: "This is <description data-l10n-name=\"desc\">a desc</description>.",
     68        attributes: null,
     69      };
     70      translateElement(element, translation);
     71      is(element.innerHTML, 'This is a desc.');
     72    }
     73    SimpleTest.finish();
     74  }, {once: true});
     75 
     76  ]]>
     77  </script>
     78 
     79  <description id="test2">
     80    <html:a data-l10n-name="link" href="https://www.mozilla.org"/>
     81  </description>
     82 
     83  <box id="test3">
     84    <description data-l10n-name="desc"/>
     85  </box>
     86 </window>