diff options
Diffstat (limited to 'testing/web-platform/mozilla/tests/common')
-rw-r--r-- | testing/web-platform/mozilla/tests/common/reftest-zoom.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/testing/web-platform/mozilla/tests/common/reftest-zoom.js b/testing/web-platform/mozilla/tests/common/reftest-zoom.js new file mode 100644 index 0000000000..a20f2cc800 --- /dev/null +++ b/testing/web-platform/mozilla/tests/common/reftest-zoom.js @@ -0,0 +1,29 @@ +// This JS file allows to emulate reftest-zoom. +// See https://firefox-source-docs.mozilla.org/layout/Reftest.html#zoom-tests-reftest-zoom-float + +// Retrieve reftest-zoom attribute. +const reftestZoom = "reftest-zoom"; +const root = document.documentElement; +if (!root.hasAttribute(reftestZoom)) { + throw new Error(`${reftestZoom} attribute not found on the root element.`); +} + +// Parse reftest-zoom value. +let zoom = parseFloat(root.getAttribute(reftestZoom)); +if (Number.isNaN(zoom)) { + throw new Error(`${reftestZoom} is not a float number.`); +} + +// Clamp reftest-zoom value. +let minZoom = SpecialPowers.getIntPref("zoom.minPercent") / 100; +let maxZoom = SpecialPowers.getIntPref("zoom.maxPercent") / 100; +zoom = Math.min(Math.max(zoom, minZoom), maxZoom); + +// Ensure the original zoom level is restored after the screenshot. +const originalZoom = SpecialPowers.getFullZoom(window); +window.addEventListener("beforeunload", () => { + SpecialPowers.setFullZoom(window, originalZoom); +}); + +// Set the zoom level to the specified value. +SpecialPowers.setFullZoom(window, zoom); |