Files
archived-camoufox/python/tests/test_humanize.py
T
Jake WriterandClaude Opus 5.5 0bb4f14b74 Keep the caller's launch inputs unchanged, and claim the avail screen and touch points baseline protection reports
launch_options/launchOptions filled the caller's config, prefs, args and
addons in place. A config reused for a second launch then carried the first
identity's webGl:vendor in, which read as a GPU the caller named: the second
launch covered its canvas while claiming the host's GPU. The TypeScript
end-to-end test caught it through its Python probe, which calls
launch_options before Camoufox with the same kwargs. Both launchers now work
on copies.

Firefox's baseline fingerprinting protection reports the available screen as
the screen less a fixed taskbar for the claimed OS (48px Windows, 76px macOS,
none on Linux) and collapses more than one touch point to 5, and the browser
applies that to the spoofed values. The launchers still claimed fpgen's
recorded avail rect, adjusted by fix_screen_no_taskbar, so a Linux identity's
config said availHeight 1053 while the page read 1080. follow_baseline_protection
/ followBaselineProtection replaces it and claims what the browser reports.

The end-to-end test now compares a covered canvas by being covered (its
readback is random on every read, so its size was too), launches the
NewContext scenario with canvas_noise, since an uncovered browser binds its
contexts to the host, and checks a headful launch against its own config,
because Xvfb can render on another device than headless.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:39:02 -06:00

68 lines
2.3 KiB
Python

"""Regression tests for humanized cursor launch configuration."""
import pytest
from camoufox import utils
@pytest.fixture
def captured_launch_config(monkeypatch):
captured = {}
monkeypatch.setattr(utils, "generate_fingerprint", lambda **_kwargs: object())
monkeypatch.setattr(utils, "from_fpgen", lambda *_args, **_kwargs: {})
monkeypatch.setattr(utils, "get_screen_cons", lambda *_args, **_kwargs: {})
monkeypatch.setattr(
utils, "_generate_random_font_subset", lambda *_args, **_kwargs: []
)
monkeypatch.setattr(
utils, "_generate_random_voice_subset", lambda *_args, **_kwargs: []
)
monkeypatch.setattr(utils, "validate_config", lambda *_args, **_kwargs: None)
monkeypatch.setattr(utils, "add_default_addons", lambda *_args, **_kwargs: None)
monkeypatch.setattr(utils, "fix_navigator_arch", lambda *_args, **_kwargs: None)
monkeypatch.setattr(
utils, "follow_baseline_protection", lambda *_args, **_kwargs: None
)
monkeypatch.setattr(
utils, "clamp_window_dimensions", lambda *_args, **_kwargs: None
)
monkeypatch.setattr(utils, "installed_verstr", lambda *_args, **_kwargs: "152.0")
monkeypatch.setattr(utils, "launch_path", lambda *_args, **_kwargs: "/camoufox")
monkeypatch.setattr(utils.LeakWarning, "warn", lambda *_args, **_kwargs: None)
def capture_env(config, _target_os, **_kwargs):
captured.clear()
captured.update(config)
return {}
monkeypatch.setattr(utils, "get_env_vars", capture_env)
def launch(humanize):
utils.launch_options(
humanize=humanize,
block_webgl=True,
i_know_what_im_doing=True,
)
return captured.copy()
return launch
def test_humanize_true_does_not_set_boolean_duration(captured_launch_config) -> None:
config = captured_launch_config(True)
assert config["humanize"] is True
assert "humanize:maxTime" not in config
@pytest.mark.parametrize("duration", [1, 5, 1.25])
def test_humanize_duration_is_encoded_as_double(
captured_launch_config, duration
) -> None:
config = captured_launch_config(duration)
assert config["humanize"] is True
assert config["humanize:maxTime"] == float(duration)
assert type(config["humanize:maxTime"]) is float