tor-browser

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

test_overlay.html (1771B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test DOMLocalization's DOMOverlay functionality</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  <script type="application/javascript">
      9  "use strict";
     10  const l10nReg = new L10nRegistry();
     11  const fs = [
     12    { path: "/localization/en-US/mock.ftl", source: `
     13 title = <strong>Hello</strong> World
     14 title2 = This is <a data-l10n-name="link">a link</a>!
     15 ` },
     16  ];
     17  const source = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}", fs);
     18  l10nReg.registerSources([source]);
     19 
     20  window.onload = async function() {
     21    SimpleTest.waitForExplicitFinish();
     22 
     23    const domLoc = new DOMLocalization(
     24      ["/mock.ftl"],
     25      false,
     26      l10nReg,
     27      ["en-US"],
     28    );
     29 
     30    const p1 = document.querySelectorAll("p")[0];
     31    const p2 = document.querySelectorAll("p")[1];
     32    const a = p2.querySelector("a");
     33    // We want to test that the event listener persists after
     34    // translateFragment().
     35    a.addEventListener("click", function(e) {
     36      SimpleTest.finish();
     37      // We cannot connect to non-local connections on automation, so prevent
     38      // the navigation.
     39      e.preventDefault();
     40    });
     41 
     42    await domLoc.translateFragment(document.body);
     43 
     44 
     45    is(p1.querySelector("strong").textContent, "Hello");
     46 
     47    is(p2.querySelector("a").getAttribute("href"), "http://www.mozilla.org");
     48    is(p2.querySelector("a").textContent, "a link");
     49 
     50    a.click();
     51  };
     52  </script>
     53 </head>
     54 <body>
     55  <p data-l10n-id="title" />
     56  <p data-l10n-id="title2">
     57    <a href="http://www.mozilla.org" data-l10n-name="link"></a>
     58  </p>
     59 </body>
     60 </html>