tor-browser

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

test_docl10n.html (2200B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test DocumentL10n in HTML environment</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  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
      9  <script>
     10  "use strict";
     11  SimpleTest.waitForExplicitFinish();
     12 
     13  is(document.l10n.ready && document.l10n.ready.then !== undefined, true,
     14    "document.l10n.ready exists and is a Promise");
     15 
     16  (async function() {
     17    await document.l10n.ready;
     18 
     19    const desc = document.getElementById("main-desc");
     20    is(!!desc.textContent.length, true, "initial localization is applied");
     21 
     22    const msg = await document.l10n.formatValue("id-heading");
     23    is(!!msg.length, true, "value is formatted manually");
     24 
     25    const label = document.getElementById("label1");
     26    let l10nArgs = document.l10n.getAttributes(label);
     27    is(l10nArgs.id, null, "id is null if not set");
     28 
     29    SimpleTest.doesThrow(
     30      () => {
     31        const bad = {};
     32        bad.bad = bad;
     33        document.l10n.setAttributes(label, "date-crashed-heading", bad);
     34      },
     35      "an error is thrown for invalid args",
     36    );
     37 
     38    l10nArgs = document.l10n.getAttributes(label);
     39    is(l10nArgs.id, null, "id is not set if args are invalid");
     40 
     41    document.l10n.setAttributes(
     42      label,
     43      "date-crashed-heading",
     44      {
     45        name: "John",
     46      }
     47    );
     48    ok(document.hasPendingL10nMutations, "Should have pending mutations");
     49    l10nArgs = document.l10n.getAttributes(label);
     50    is(l10nArgs.id, "date-crashed-heading", "id is set by setAttributes");
     51    is(l10nArgs.args.name, "John", "args are set by setAttributes");
     52    // Test for mutations applied.
     53    document.addEventListener("L10nMutationsFinished", function() {
     54      ok(!!label.textContent.length, "Should've applied translation");
     55      ok(!document.hasPendingL10nMutations, "Should have no more pending mutations");
     56      SimpleTest.finish();
     57    }, { once: true });
     58  })();
     59  </script>
     60 </head>
     61 <body>
     62  <h1 id="main-desc" data-l10n-id="crash-reports-title"></h1>
     63 
     64  <p id="label1"></p>
     65 </body>
     66 </html>