Files
archived-camoufox/python/tests/test_display_scale.py
T
Jake WriterandClaude Opus 5.5 55fb795ba4 Always render at the identity's devicePixelRatio
Replace the display_scale option with the one behaviour: the browser renders
at the final config's window.devicePixelRatio (layout.css.devPixelsPerPx), so
(resolution) and the CSS geometry agree with it, whether the identity was
drawn, a preset or supplied. A pref the caller passes still wins. The fpgen
draw's ratio is no longer read, which gave a supplied 2.5 identity no scale
or a scale of 2.

Headful on a real monitor, the display clamp divides by the scale, and a
window that still needs more pixels than the monitor has raises a ValueError
saying so. The monitor is only known in pixels at scale 1 on Linux, so the
scale is applied to the bound there.

New guard: display-scale-resolution (spoofing), which fails on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 19:46:48 -06:00

34 lines
1.4 KiB
Python

"""The browser renders at the identity's devicePixelRatio (#933)."""
import pytest
from camoufox import utils
from camoufox.fingerprints import Screen
from test_launch_environment import isolated_launch_dependencies # noqa: F401
PREF = "layout.css.devPixelsPerPx"
WIN = {"navigator.userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:158.0) Gecko/20100101 Firefox/158.0",
"screen.width": 1382, "screen.height": 864, "window.outerWidth": 1280, "window.outerHeight": 900}
def prefs(dpr, **kwargs):
return utils.launch_options(config={**WIN, "window.devicePixelRatio": dpr}, i_know_what_im_doing=True,
**{"headless": True, **kwargs})["firefox_user_prefs"]
def test_renders_at_the_claimed_scale(isolated_launch_dependencies): # noqa: F811
assert prefs(2.5)[PREF] == "2.5"
assert PREF not in prefs(1)
def test_caller_pref_wins(isolated_launch_dependencies): # noqa: F811
assert prefs(2.5, firefox_user_prefs={PREF: "1.0"})[PREF] == "1.0"
def test_window_too_large_for_the_monitor_raises(monkeypatch, isolated_launch_dependencies): # noqa: F811
monkeypatch.setattr(utils, "OS_NAME", "lin")
with pytest.raises(ValueError, match="needs 3200 pixels, but this monitor has 1920"):
prefs(2.5, headless=False, screen=Screen(max_width=1920, max_height=1080))
assert prefs(1.25, headless=False, screen=Screen(max_width=1920, max_height=1200))[PREF] == "1.25"