summaryrefslogtreecommitdiffstats
path: root/dom/l10n/tests/mochitest/l10n_mutations/test_set_attributes.html
blob: 762353a06c457464ff7d213b24005a3002b05afb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test L10n Mutations for AttributeChange after DOMContentLoaded</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
  <link rel="localization" href="crashreporter/aboutcrashes.ftl"/>
  <link rel="localization" href="toolkit/about/aboutCompat.ftl"/>
  <script type="application/javascript">
  "use strict";
  SimpleTest.waitForExplicitFinish();

  document.addEventListener("DOMContentLoaded", async function() {
    await document.l10n.ready;
    let elem = document.getElementById("elem1");
    let elem2 = document.getElementById("elem2");
    is(elem.textContent.length, 0);
    is(elem2.textContent.includes("Initial string"), true);
    document.l10n.setAttributes(elem, "crash-reports-title");
    elem2.setAttribute("data-l10n-args", JSON.stringify({bug: "New string"}));

    let verifyL10n = () => {
      if (elem.textContent.length && elem2.textContent.includes("New string")) {
        window.removeEventListener("MozAfterPaint", verifyL10n);
        SimpleTest.finish();
      }
    };
    window.addEventListener("MozAfterPaint", verifyL10n);
  });
  </script>
</head>
<body>
  <div id="elem1"></div>
  <div id="elem2" data-l10n-id="label-more-information" data-l10n-args='{"bug":"Initial string"}'></div>
</body>
</html>