tor-browser

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

test_SVG_switch_language_spoof.html (2342B)


      1 <!DOCTYPE html>
      2 <html>
      3  <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=1924087
      5 -->
      6  <head>
      7    <title>Test for Bug 1924087</title>
      8    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     10    <script class="testbody" type="application/javascript">
     11      SimpleTest.waitForExplicitFinish();
     12 
     13      function clearAndAddSVG() {
     14        document.getElementById("display").innerHTML = "";
     15        const template = document.querySelector("template");
     16        const clone = document.importNode(template.content, true);
     17        document.getElementById("display").appendChild(clone);
     18      }
     19 
     20      function getShownTexts() {
     21        const swtch = document.getElementById("switch");
     22        return [...swtch.children].filter(
     23          child => child.getBoundingClientRect().width > 0
     24        );
     25      }
     26 
     27      async function runTests() {
     28        await SpecialPowers.pushPrefEnv({
     29          set: [["intl.accept_languages", "tr"]]
     30        });
     31 
     32        clearAndAddSVG();
     33 
     34        const shown = getShownTexts();
     35        is(shown.length, 1, "Only one child should be selected");
     36        is(
     37          shown[0].textContent,
     38          "Merhaba!",
     39          "The selected child should be the one with the 'tr' language"
     40        );
     41 
     42        await SpecialPowers.pushPrefEnv({
     43          set: [
     44            ["privacy.resistFingerprinting", true],
     45            ["privacy.spoof_english", 2],
     46          ],
     47        });
     48 
     49        clearAndAddSVG();
     50 
     51        const spoofedShown = getShownTexts();
     52        is(spoofedShown.length, 1, "Only one child should be selected");
     53        is(
     54          spoofedShown[0].textContent,
     55          "Hello!",
     56          "The selected child should be the one with the 'en' language"
     57        );
     58 
     59        await SpecialPowers.popPrefEnv();
     60        await SpecialPowers.popPrefEnv();
     61 
     62        SimpleTest.finish();
     63      }
     64    </script>
     65  </head>
     66  <body onload="runTests()">
     67    <a
     68      target="_blank"
     69      href="https://bugzilla.mozilla.org/show_bug.cgi?id=1924087"
     70      >Mozilla Bug 1924087</a
     71    >
     72    <template>
     73      <svg>
     74        <switch id="switch">
     75          <text systemLanguage="en">Hello!</text>
     76          <text systemLanguage="tr">Merhaba!</text>
     77        </switch>
     78      </svg>
     79    </template>
     80    <div id="display"></div>
     81  </body>
     82 </html>