tor-browser

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

reftest-zoom.js (1076B)


      1 // This JS file allows to emulate reftest-zoom.
      2 // See https://firefox-source-docs.mozilla.org/layout/Reftest.html#zoom-tests-reftest-zoom-float
      3 
      4 // Retrieve reftest-zoom attribute.
      5 const reftestZoom = "reftest-zoom";
      6 const root = document.documentElement;
      7 if (!root.hasAttribute(reftestZoom)) {
      8  throw new Error(`${reftestZoom} attribute not found on the root element.`);
      9 }
     10 
     11 // Parse reftest-zoom value.
     12 let zoom = parseFloat(root.getAttribute(reftestZoom));
     13 if (Number.isNaN(zoom)) {
     14  throw new Error(`${reftestZoom} is not a float number.`);
     15 }
     16 
     17 // Clamp reftest-zoom value.
     18 let minZoom = SpecialPowers.getIntPref("zoom.minPercent") / 100;
     19 let maxZoom = SpecialPowers.getIntPref("zoom.maxPercent") / 100;
     20 zoom = Math.min(Math.max(zoom, minZoom), maxZoom);
     21 
     22 // Ensure the original zoom level is restored after the screenshot.
     23 const originalZoom = SpecialPowers.getFullZoom(window);
     24 window.addEventListener("beforeunload", () => {
     25  SpecialPowers.setFullZoom(window, originalZoom);
     26 });
     27 
     28 // Set the zoom level to the specified value.
     29 SpecialPowers.setFullZoom(window, zoom);