diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
commit | 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch) | |
tree | a4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /testing/web-platform/mozilla/tests/common/reftest-zoom.js | |
parent | Adding debian version 124.0.1-1. (diff) | |
download | firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/mozilla/tests/common/reftest-zoom.js')
-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); |