test(vault): a page cannot claim a focus it does not hold; drop unused document cleanup

The forged-verdict tests covered the refusal paths; this one covers the focus verdict on the
checked origin. CDP never reuses a session id, so clearing per-session document counts on reconnect
or detach changed nothing (mutation-proven) and is removed.
This commit is contained in:
Maciej Lisiewski
2026-11-19 15:34:50 +01:00
parent e30acfe013
commit 89c2feff2d
3 changed files with 12 additions and 2 deletions

View File

@@ -357,3 +357,15 @@ class TestForgedVerdicts:
"""
out = _run(setup, _GUARDED_SCRIPTS[script]())
assert isinstance(out, dict) and "refused" not in out, out
@pytest.mark.parametrize("page", ["json-stringify", "everything"])
def test_a_page_cannot_claim_a_focus_it_does_not_hold(self, page):
"""On the checked origin too, the focus verdict is the script's own: focus held by another
element (an iframe's host, a decoy input) reads as lost whatever the page's JSON says."""
setup = """
const pw = stamp(add(document, "input", { type: "password", value: "" }), 1);
const decoy = add(document, "iframe");
pw.focus = () => focusOn(decoy);
""" + _LYING_PAGES[page]
out = _run(setup, _GUARDED_SCRIPTS["focus"]())
assert isinstance(out, dict) and out.get("refused") == "focus_lost", out

View File

@@ -502,7 +502,6 @@ class CDPSupervisor(DialogSupervisionMixin, FrameTrackingMixin):
# are deliberately kept — they reconcile as fresh events arrive (worst case a
# stale dialog entry is rejected with "no dialog is showing", logged only).
self._page_session_id = None
self._documents.clear() # session ids die with the connection
await self._attach_initial_page()
self._set_active(True)
last_success_at = time.time()

View File

@@ -132,7 +132,6 @@ class FrameTrackingMixin:
with self._state_lock:
self._frames.update({fid: replace(f, cdp_session_id=None) for fid, f in self._frames.items()
if f.cdp_session_id == sid})
self._documents.pop(sid, None)
def _build_frame_tree_locked(self) -> dict[str, Any]:
"""Capped frame_tree payload (must hold state lock). Top frame = one with