tor-browser

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

browser_l10n_localizeMarkup.js (3316B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /* import-globals-from ../../../server/tests/browser/head.js */
      7 
      8 // Tests that the markup localization works properly.
      9 
     10 const { localizeMarkup } = require("resource://devtools/shared/l10n.js");
     11 const HTML_NS = "http://www.w3.org/1999/xhtml";
     12 
     13 add_task(async function () {
     14  info("Check that the strings used for this test are still valid");
     15  const STARTUP_L10N = new LocalizationHelper(
     16    "devtools/client/locales/startup.properties"
     17  );
     18  const TOOLBOX_L10N = new LocalizationHelper(
     19    "devtools/client/locales/toolbox.properties"
     20  );
     21  const str1 = STARTUP_L10N.getStr("inspector.label");
     22  const str2 = STARTUP_L10N.getStr("inspector.accesskey");
     23  const str3 = TOOLBOX_L10N.getStr("toolbox.defaultTitle");
     24  ok(
     25    str1 && str2 && str3,
     26    "If this failed, strings should be updated in the test"
     27  );
     28 
     29  info("Create the test markup");
     30  const div = document.createElementNS(HTML_NS, "div");
     31  div.setAttribute(
     32    "data-localization-bundle",
     33    "devtools/client/locales/startup.properties"
     34  );
     35  const div0 = document.createElementNS(HTML_NS, "div");
     36  div0.setAttribute("id", "d0");
     37  div0.setAttribute("data-localization", "content=inspector.someInvalidKey");
     38  div.appendChild(div0);
     39  const div1 = document.createElementNS(HTML_NS, "div");
     40  div1.setAttribute("id", "d1");
     41  div1.setAttribute("data-localization", "content=inspector.label");
     42  div.appendChild(div1);
     43  div1.append("Text will disappear");
     44  const div2 = document.createElementNS(HTML_NS, "div");
     45  div2.setAttribute("id", "d2");
     46  div2.setAttribute(
     47    "data-localization",
     48    "content=inspector.label;title=inspector.accesskey"
     49  );
     50  div.appendChild(div2);
     51  const div3 = document.createElementNS(HTML_NS, "div");
     52  div3.setAttribute("id", "d3");
     53  div3.setAttribute(
     54    "data-localization",
     55    "content=inspector.label;title=inspector.accesskey"
     56  );
     57  div.appendChild(div3);
     58  const div4 = document.createElementNS(HTML_NS, "div");
     59  div4.setAttribute("id", "d4");
     60  div4.setAttribute("data-localization", "aria-label=inspector.label");
     61  div.appendChild(div4);
     62  div4.append("Some content");
     63  const toolboxDiv = document.createElementNS(HTML_NS, "div");
     64  toolboxDiv.setAttribute(
     65    "data-localization-bundle",
     66    "devtools/client/locales/toolbox.properties"
     67  );
     68  div.appendChild(toolboxDiv);
     69  const div5 = document.createElementNS(HTML_NS, "div");
     70  div5.setAttribute("id", "d5");
     71  div5.setAttribute("data-localization", "content=toolbox.defaultTitle");
     72  toolboxDiv.appendChild(div5);
     73 
     74  info("Use localization helper to localize the test markup");
     75  localizeMarkup(div);
     76 
     77  is(div1.innerHTML, str1, "The content of #d1 is localized");
     78  is(div2.innerHTML, str1, "The content of #d2 is localized");
     79  is(div2.getAttribute("title"), str2, "The title of #d2 is localized");
     80  is(div3.innerHTML, str1, "The content of #d3 is localized");
     81  is(div3.getAttribute("title"), str2, "The title of #d3 is localized");
     82  is(div4.innerHTML, "Some content", "The content of #d4 is not replaced");
     83  is(
     84    div4.getAttribute("aria-label"),
     85    str1,
     86    "The aria-label of #d4 is localized"
     87  );
     88  is(
     89    div5.innerHTML,
     90    str3,
     91    "The content of #d5 is localized with another bundle"
     92  );
     93 });