tor-browser

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

test_devicePixelRatio_with_zoom.html (2435B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>DevicePixelRatios with Zoom</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
      7 </head>
      8 
      9 <body>
     10 
     11 <div>Testing devicePixelRatio with different zoom levels</div>
     12 
     13 <script type="application/javascript">
     14 
     15 // We're creating a table of zooms and expected devicePixelRatio (DPR) strings.
     16 // The values in the table are specific to the "native" DPR at zoom level 100%.
     17 // If we don't have a table for a native DPR value, we'll trivially report
     18 // a successful test with a note that we didn't have a table.
     19 // For the moment, we only have a table for native DPR of 2.
     20 let zoomsAndDPRsToTest;
     21 
     22 const originalZoom = SpecialPowers.getFullZoom(window);
     23 const zoom = 1;
     24 SpecialPowers.setFullZoom(window, zoom);
     25 
     26 const dprAtZoom1 = window.devicePixelRatio;
     27 if (dprAtZoom1 == 1) {
     28  zoomsAndDPRsToTest = [
     29    [300, "3"],
     30    [250, "2.5"],
     31    [200, "2"],
     32    [167, "1.6666666666666667"],
     33    [150, "1.5"],
     34    [133, "1.3333333333333333"],
     35    [120, "1.2"],
     36    [110, "1.0909090909090908"],
     37    [100, "1"],
     38    [90,  "0.8955223880597015"],
     39    [80,  "0.8"],
     40    [67,  "0.6666666666666666"],
     41    [50,  "0.5"],
     42  ];
     43 } else if (dprAtZoom1 == 2) {
     44  zoomsAndDPRsToTest = [
     45    [300, "6"],
     46    [250, "5"],
     47    [200, "4"],
     48    [167, "3.3333333333333335"],
     49    [150, "3"],
     50    [133, "2.608695652173913"], // there's a trailing 0 here unreported by JS
     51    [120, "2.4"],
     52    [110, "2.2222222222222223"],
     53    [100, "2"],
     54    [90,  "1.8181818181818181"],
     55    [80,  "1.5789473684210527"],
     56    [67,  "1.3333333333333333"],
     57    [50,  "1"],
     58  ];
     59 }
     60 
     61 if (!zoomsAndDPRsToTest.length) {
     62  // Need to run at least one test function to keep mochitest harness happy.
     63  ok(true, `No table of data for devicePixelRatio of ${dprAtZoom1} at zoom level 100%.`);
     64 }
     65 
     66 for (let i = 0; i < zoomsAndDPRsToTest.length; ++i) {
     67  let data = zoomsAndDPRsToTest[i];
     68  let zoomPercent = data[0];
     69  let targetDPR = data[1];
     70 
     71  let relativeZoom = zoom * zoomPercent / 100;
     72  SpecialPowers.setFullZoom(window, relativeZoom);
     73 
     74  // Force conversion to string for string comparison to targetDPR.
     75  let actualDPR = window.devicePixelRatio + "";
     76  is(actualDPR, targetDPR, `At ${zoomPercent}% zoom, window.devicePixelRatio is rounded correctly.`);
     77 }
     78 
     79 // Reset the zoom when the test is done.
     80 SpecialPowers.setFullZoom(window, originalZoom);
     81 </script>
     82 
     83 </body>
     84 </html>