tor-browser

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

test_switch.xhtml (2597B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi?id=484176
      4 -->
      5 <head>
      6  <title>Test SVG Switch</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 </head>
     10 <body>
     11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=484176">Mozilla Bug 484176</a>
     12 <p id="display"></p>
     13 <div id="content"></div>
     14 
     15 <iframe id="svg" src="switch-helper.svg"></iframe>
     16 
     17 <pre id="test">
     18 <script class="testbody" type="text/javascript">
     19        <![CDATA[
     20 
     21 SimpleTest.waitForExplicitFinish();
     22 
     23 var test = 1;
     24 
     25 function checkWidth(element, w) {
     26  var bbox = element.getBBox();
     27  var name = element.nodeName;
     28 
     29  is(bbox.width, w, test + " " + name + ".getBBox().width");
     30  ++test;
     31 }
     32 
     33 async function run() {
     34  try {
     35    // Set accept_languages to something we know
     36    await SpecialPowers.pushPrefEnv({"set": [["intl.accept_languages", "en-gb,en,it"]]}, run1);
     37  } finally {
     38    SimpleTest.finish();
     39  }
     40 }
     41 
     42 function run1() {
     43  let doc = $("svg").contentDocument;
     44  let s = doc.getElementById("s");
     45  let first = doc.getElementById("first");
     46  let second = doc.getElementById("second");
     47  let third = doc.getElementById("third");
     48 
     49  first.setAttribute("systemLanguage", "fr");
     50 
     51  /* test for an exact match */
     52  second.setAttribute("systemLanguage", "en-gb");
     53  checkWidth(s, 50);
     54 
     55  /* test for a close match i.e. the same language prefix */
     56  second.setAttribute("systemLanguage", "en");
     57  checkWidth(s, 50);
     58 
     59  /* test for a close match regardless of case */
     60  second.setAttribute("systemLanguage", "eN");
     61  checkWidth(s, 50);
     62 
     63  /* test that different regions don't match */
     64  second.setAttribute("systemLanguage", "en-us");
     65  checkWidth(s, 80);
     66 
     67  /* test that we pick the best match */
     68  second.setAttribute("systemLanguage", "it");
     69  checkWidth(s, 50);
     70 
     71  /* test that we use the default if nothing matches */
     72  second.setAttribute("systemLanguage", "fr");
     73  checkWidth(s, 80);
     74 
     75  /* test we still ignore non-matches */
     76  second.removeAttribute("systemLanguage");
     77  third.setAttribute("systemLanguage", "fr");
     78  checkWidth(s, 50);
     79 
     80  /* check what happens if nothing matches */
     81  second.setAttribute("systemLanguage", "fr");
     82  third.setAttribute("systemLanguage", "fr");
     83  checkWidth(s, 0);
     84 
     85  /* test that we pick the best match */
     86  first.setAttribute("systemLanguage", "en");
     87  second.setAttribute("systemLanguage", "en-gb");
     88  third.removeAttribute("systemLanguage");
     89  checkWidth(s, 50);
     90 }
     91 
     92 window.addEventListener("load", run);
     93 
     94 ]]>
     95 </script>
     96 </pre>
     97 </body>
     98 </html>