mirror of
https://github.com/daijro/camoufox.git
synced 2026-11-19 00:07:28 +00:00
A Linux build claiming Windows edited text the GTK way, which both the user and the page could tell: Alt+Backspace did not undo, Shift+Delete with nothing selected did nothing, Ctrl+Up in a textarea moved up a line instead of to its start, Ctrl+/ selected all, Ctrl+Backspace on a rich text selection deleted only the selection, and AltGr reported keyCode 225 where Windows reports 18. windows-keyboard.patch switches on config input:windowsKeyboard, which the launcher sets for Windows identities on a non-Windows host, where upstream did nothing. The shortcut tables are Windows' own, built from the same definitions file with the Windows platform macros; GTK's native text bindings are skipped, including the emulated ones that synthesized (Playwright) key events get from GetEditCommandsForTests; AltGr reports Alt and HTML editors take Windows' caret style. Without the key, or with it false, behaviour is unchanged. The key is launch-wide: the shortcut tables and GTK's key handling are process-level. The patch relies on touchscreen-fingerprint-spoofing for /camoucfg in dom/events and was re-derived on 156. The windows-keyboard guard checks each behaviour for a Windows and a Linux identity, with real X11 keys where only a native event exercises the code, so the parity leg installs xdotool and setxkbmap. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
"""A Windows identity on another host behaves as stock Windows Firefox does.
|
|
|
|
Each value the launcher sets here was measured on stock Firefox on Windows
|
|
against this build on a Linux host claiming Windows. On a Windows host the
|
|
build already behaves that way, and a macOS or Linux identity is left as it is.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from camoufox import utils
|
|
|
|
from test_launch_environment import isolated_launch_dependencies # noqa: F401
|
|
|
|
WIN_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:156.0) Gecko/20100101 Firefox/156.0"
|
|
MAC_UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:156.0) Gecko/20100101 Firefox/156.0"
|
|
LIN_UA = "Mozilla/5.0 (X11; Linux x86_64; rv:156.0) Gecko/20100101 Firefox/156.0"
|
|
|
|
|
|
@pytest.fixture
|
|
def launch(monkeypatch, isolated_launch_dependencies): # noqa: F811
|
|
"""launch_options on a Linux host; returns (config, prefs)."""
|
|
monkeypatch.setattr(utils, "_host_os_key", lambda: "lin")
|
|
seen = {}
|
|
|
|
def capture(config, *args, **kwargs):
|
|
seen["config"] = dict(config)
|
|
return {}
|
|
|
|
monkeypatch.setattr(utils, "get_env_vars", capture)
|
|
|
|
def run(ua, **kwargs):
|
|
config = {"navigator.userAgent": ua, **kwargs.pop("config", {})}
|
|
prefs = utils.launch_options(config=config, i_know_what_im_doing=True, **kwargs)["firefox_user_prefs"]
|
|
return seen["config"], prefs
|
|
|
|
return run
|
|
|
|
|
|
def test_windows_identity_gets_windows_crt_math(launch):
|
|
_, prefs = launch(WIN_UA)
|
|
assert prefs["javascript.options.use_ucrt_math"] is True
|
|
|
|
|
|
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
|
|
def test_other_identities_keep_host_math(launch, ua):
|
|
_, prefs = launch(ua)
|
|
assert "javascript.options.use_ucrt_math" not in prefs
|
|
|
|
|
|
def test_windows_identity_on_windows_host_is_left_alone(launch, monkeypatch):
|
|
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
|
|
_, prefs = launch(WIN_UA)
|
|
assert "javascript.options.use_ucrt_math" not in prefs
|
|
|
|
|
|
def test_caller_values_win(launch):
|
|
_, prefs = launch(WIN_UA, firefox_user_prefs={"javascript.options.use_ucrt_math": False})
|
|
assert prefs["javascript.options.use_ucrt_math"] is False
|
|
|
|
|
|
def test_windows_identity_gets_windows_keyboard(launch):
|
|
config, _ = launch(WIN_UA)
|
|
assert config["input:windowsKeyboard"] is True
|
|
|
|
|
|
@pytest.mark.parametrize("ua", [MAC_UA, LIN_UA])
|
|
def test_other_identities_keep_host_keyboard(launch, ua):
|
|
config, _ = launch(ua)
|
|
assert "input:windowsKeyboard" not in config
|
|
|
|
|
|
def test_windows_keyboard_on_windows_host_is_left_alone(launch, monkeypatch):
|
|
monkeypatch.setattr(utils, "_host_os_key", lambda: "win")
|
|
config, _ = launch(WIN_UA)
|
|
assert "input:windowsKeyboard" not in config
|
|
|
|
|
|
def test_caller_keyboard_wins(launch):
|
|
config, _ = launch(WIN_UA, config={"input:windowsKeyboard": False})
|
|
assert config["input:windowsKeyboard"] is False
|