Compare commits

...
Author SHA1 Message Date
feder-crandClaude Sonnet 5.5 690e5a3bf0 e2e: the refusal test launches the engine with the crash reporter off
The three missing-pref cases end in a deliberate abort (the engine refuses the launch), and each
opened the crash reporter on the desktop of whoever ran it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 17:30:17 +01:00
feder-crandClaude Sonnet 5.5 a9aa906985 e2e: the missing-system-theme-pref helper's regex compiles, with a unit test that fails on the old one
The regex that finds a pref's line in user.js had a lone backslash before its closing bracket
(an unterminated character set): every case of the e2e died with re.error before launching
a browser (candidate 42624473465, Windows gate). tests/unit/test_theme_refusal_drop.py runs
the helper on a user.js of its own and fails on the old regex.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-09 15:28:08 +01:00
2 changed files with 62 additions and 2 deletions

No files matched your search

@@ -33,7 +33,7 @@ def _drop(user_js: Path, names) -> int:
variants are other prefs and stay). Returns how many lines went."""
kept, dropped = [], 0
for line in user_js.read_text(encoding="utf-8").splitlines():
m = re.match(r'user_pref\(("(?:[^"\]|\.)*"),', line)
m = re.match(r'user_pref\(("(?:[^"\\]|\\.)*"),', line)
if m and json.loads(m.group(1)) in names:
dropped += 1
else:
@@ -54,7 +54,10 @@ def _launch(firefox_binary, drop):
assert _drop(Path(profile_dir) / "user.js", {drop}) == 1, (
"%s is not declared by this core, so there is nothing to remove" % drop)
return conn.launch(firefox_binary, profile_dir, headless=True,
env=plan.env, ready_timeout=60.0), profile_dir
# A refusal ends in an abort on purpose, and the crash reporter would open
# a window on the desktop of whoever runs the test.
env=dict(plan.env, MOZ_CRASHREPORTER_DISABLE="1"),
ready_timeout=60.0), profile_dir
except BaseException:
shutil.rmtree(profile_dir, ignore_errors=True)
raise
+57
View File
@@ -0,0 +1,57 @@
"""The helper of the missing-system-theme-pref e2e removes exactly the prefs it is told to.
Its first regex had an unterminated character set (a lone backslash before the closing
bracket) and every parametrised case of the e2e died with re.error before launching a browser
(candidate 42624473465's Windows gate). This runs the helper on a user.js of its own.
Known-bad input: the regex as it was, which raises re.error on the first line.
"""
import importlib.util
import json
from pathlib import Path
import pytest
pytestmark = pytest.mark.unit
E2E = Path(__file__).resolve().parents[1] / "test_a_missing_system_theme_pref_refuses_the_launch_e2e.py"
BACKSLASH = chr(92)
NEWLINE = chr(10)
def _helper():
spec = importlib.util.spec_from_file_location("theme_refusal_e2e", E2E)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module._drop
def _line(name, value):
return "user_pref(%s, %s);" % (json.dumps(name), json.dumps(value))
def test_drop_removes_the_named_pref_and_nothing_else(tmp_path):
user_js = tmp_path / "user.js"
lines = [
_line("ui.highlight", "rgb(1, 2, 3)"),
_line("ui.highlight.dark", "rgb(4, 5, 6)"),
_line("ui.-moz-field", "rgb(7, 8, 9)"),
_line("ui.font.menu", "Segoe UI"),
_line("ui.font.menu.size", "12"),
_line("browser.path", "C:" + BACKSLASH + "Users" + BACKSLASH + "x"),
_line("a.quote", 'say "hi"'),
]
user_js.write_text(NEWLINE.join(lines) + NEWLINE, encoding="utf-8")
drop = _helper()
assert drop(user_js, {"ui.highlight"}) == 1
left = user_js.read_text(encoding="utf-8")
assert json.dumps("ui.highlight") not in left
for kept in ("ui.highlight.dark", "ui.-moz-field", "ui.font.menu", "ui.font.menu.size",
"browser.path", "a.quote"):
assert json.dumps(kept) in left, kept
def test_drop_leaves_a_pref_that_is_not_there_alone(tmp_path):
user_js = tmp_path / "user.js"
user_js.write_text(_line("a.b", 1) + NEWLINE, encoding="utf-8")
assert _helper()(user_js, {"c.d"}) == 0