summaryrefslogtreecommitdiffstats
path: root/dom/l10n/tests/mochitest/document_l10n/test_docl10n.html
blob: 3cff6ded6f7e0bcc34d203bcd877b6eff3852025 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test DocumentL10n in HTML environment</title>
  <script 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"/>
  <script type="application/javascript">
  "use strict";
  SimpleTest.waitForExplicitFinish();

  is(document.l10n.ready && document.l10n.ready.then !== undefined, true,
    "document.l10n.ready exists and is a Promise");

  (async function() {
    await document.l10n.ready;

    // Test for initial localization applied.
    let desc = document.getElementById("main-desc");
    is(!!desc.textContent.length, true);

    // Test for manual value formatting.
    let msg = await document.l10n.formatValue("id-heading");
    is(!!msg.length, true);

    // Test for mutations applied.
    let verifyL10n = () => {
      if (label.textContent.length) {
        window.removeEventListener("MozAfterPaint", verifyL10n);
        SimpleTest.finish();
      }
    };
    window.addEventListener("MozAfterPaint", verifyL10n);

    let label = document.getElementById("label1");
    document.l10n.setAttributes(
      label,
      "date-crashed-heading",
      {
        name: "John",
      }
    );

    // Test for l10n.getAttributes
    let l10nArgs = document.l10n.getAttributes(label);
    is(l10nArgs.id, "date-crashed-heading");
    is(l10nArgs.args.name, "John");
  })();
  </script>
</head>
<body>
  <h1 id="main-desc" data-l10n-id="crash-reports-title"></h1>

  <p id="label1"></p>
</body>
</html>