Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac75085d10 | ||
|
|
f5234742e6 | ||
|
|
c65828d809 |
No files matched your search
@@ -1,110 +0,0 @@
|
||||
"""A popup opened the way a page opens one, and what it reads of its own window.
|
||||
|
||||
Shared by `test_popup_geometry_is_the_declared_frame_e2e.py` and by the inner-size test of
|
||||
`test_fingerprint_surface.py`: both need a popup (`window.open` with features, from a click) whose document may carry an
|
||||
iframe of another site (so, under Fission, in another process), and both read the window geometry from inside it.
|
||||
|
||||
The popup is read with a CONDITION, not a pause: the reading is repeated (with the client's events being read between two
|
||||
looks) until the caller's `ready` holds or 30 s have passed, and the last reading is returned either way, so the caller's
|
||||
assertion names what was read when it never settled.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import threading
|
||||
from typing import Any, Callable, Dict, Optional
|
||||
|
||||
from _fission_frames import Sites, wait_frame
|
||||
from _waits import wait_until
|
||||
|
||||
#: The scale at which the declared window frame is the one of `WINDOW_FRAME_BY_DPR[1.0]`: border 8, popup UI 72, default
|
||||
#: position 4 (device pixels, and CSS pixels at 1.0). The screen is the one the other surface tests pin.
|
||||
PIN = {"screen.width": 1920, "screen.height": 1080, "screen.dpr": 1.0}
|
||||
|
||||
#: A second declared window frame that no runner has: a border of 6, a popup UI of 53 above the content, a default position of 9. The declared frame at scale 1.0
|
||||
#: (8, 72, 4) is the frame of a retail Windows window, so a Windows runner's own popup has it too (outer - inner = 16 x 80) and a launch with the engine off
|
||||
#: cannot tell the declaration from the host there; a launch declared with ANOTHER frame can (the prefs are applied last, over the core's declaration).
|
||||
OTHER_FRAME = {"zoom.stealth.screen.frame_border": 6, "zoom.stealth.screen.popup_ui": 53, "zoom.stealth.screen.popup_position": 9}
|
||||
OTHER_BORDER, OTHER_POPUP_UI, OTHER_POSITION = 6, 53, 9
|
||||
|
||||
READ = """() => ({iw: innerWidth, ih: innerHeight, ow: outerWidth, oh: outerHeight,
|
||||
sx: screenX, sy: screenY, mx: mozInnerScreenX, my: mozInnerScreenY})"""
|
||||
|
||||
|
||||
def in_a_thread_of_its_own(fn: Callable[[], Any], timeout: float = 300) -> Any:
|
||||
"""Runs `fn` in a thread with no asyncio loop and gives back its result or raises its error.
|
||||
|
||||
For a module whose own fixture keeps a sync client open for the whole module: an open sync client leaves its loop marked as
|
||||
running in its thread, and a second sync client started in that thread refuses with "Playwright Sync API inside the asyncio
|
||||
loop". The second browser needs a thread of its own.
|
||||
"""
|
||||
box: Dict[str, Any] = {}
|
||||
|
||||
def run() -> None:
|
||||
try:
|
||||
box["value"] = fn()
|
||||
except BaseException as exc: # handed back to the test's thread below
|
||||
box["error"] = exc
|
||||
|
||||
worker = threading.Thread(target=run, name="second-sync-client", daemon=True)
|
||||
worker.start()
|
||||
worker.join(timeout)
|
||||
if worker.is_alive():
|
||||
raise AssertionError("the browser of the test did not end within %d s" % timeout)
|
||||
if "error" in box:
|
||||
raise box["error"]
|
||||
return box.get("value")
|
||||
|
||||
|
||||
def frame_of_the_declaration():
|
||||
"""The window frame the core declares at scale 1.0: what the engine adds to a popup's inner size."""
|
||||
from invisible_core.constants import WINDOW_FRAME_BY_DPR
|
||||
|
||||
return WINDOW_FRAME_BY_DPR[1.0]
|
||||
|
||||
|
||||
def frame_extra(border: int, popup_ui: int):
|
||||
"""What a popup adds to its inner size: (outer - inner) wide and high, for a border and a popup UI."""
|
||||
return (2 * border, popup_ui + border)
|
||||
|
||||
|
||||
def _plausible(reading: Dict[str, Any]) -> bool:
|
||||
"""Every size of every window read is above 0: the window (and its frame, if any) has been laid out."""
|
||||
return all(r["iw"] > 0 and r["ih"] > 0 and r["ow"] > 0 and r["oh"] > 0
|
||||
for r in (reading["popup"], reading["frame"]) if r is not None)
|
||||
|
||||
|
||||
def read_popup(binary: str, extra_prefs: Optional[Dict[str, Any]] = None, iframe: bool = False,
|
||||
ready: Optional[Callable[[Dict[str, Any]], bool]] = None,
|
||||
features: str = "width=500,height=400") -> Dict[str, Any]:
|
||||
"""Open `window.open(url, 'p', features)` (default `width=500,height=400`) from a click and read it.
|
||||
|
||||
Returns `{"popup": {...}, "frame": {...} or None}` with `iw ih ow oh sx sy mx my` (innerWidth, innerHeight,
|
||||
outerWidth, outerHeight, screenX, screenY, mozInnerScreenX, mozInnerScreenY) of the popup and, with `iframe`, of its
|
||||
iframe (another site, 200x150). `ready(reading)` says when the reading has settled (default: every size above 0).
|
||||
"""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with Sites() as s:
|
||||
s.route("A", "/main", "<!doctype html><title>main</title><button id='open' onclick=\"window.open('%s', 'p', "
|
||||
"'%s')\">open</button>" % (s.url("A", "/popup"), features))
|
||||
frame_html = ("<iframe id='f' src='%s' style='position:absolute;left:0;top:0;width:200px;height:150px;border:0'>"
|
||||
"</iframe>" % s.url("B", "/frame")) if iframe else ""
|
||||
s.route("A", "/popup", "<!doctype html><title>popup</title>" + frame_html)
|
||||
s.route("B", "/frame", "<!doctype html><title>frame</title>")
|
||||
with InvisiblePlaywright(seed=42, pin=PIN, binary_path=binary, headless=True, humanize=False,
|
||||
extra_prefs=extra_prefs) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto(s.url("A", "/main"), wait_until="load", timeout=30000)
|
||||
with page.expect_popup(timeout=30000) as info:
|
||||
page.click("#open", timeout=30000)
|
||||
popup = info.value
|
||||
popup.wait_for_load_state("load", timeout=30000)
|
||||
frame = wait_frame(popup, s.origin["B"], "/frame", seconds=30) if iframe else None
|
||||
seen: Dict[str, Any] = {}
|
||||
|
||||
def settled() -> bool:
|
||||
seen["now"] = {"popup": popup.evaluate(READ), "frame": frame.evaluate(READ) if frame else None}
|
||||
return _plausible(seen["now"]) and (ready is None or bool(ready(seen["now"])))
|
||||
|
||||
wait_until(settled, 30, lambda: popup.wait_for_timeout(100))
|
||||
return seen["now"]
|
||||
@@ -1,93 +0,0 @@
|
||||
"""A real click inside an iframe: `screenX - clientX` is the iframe's own `mozInnerScreenX`.
|
||||
|
||||
What it fixes: the relation a page checks with one subtraction on every mouse event, `event.screenX - event.clientX ==
|
||||
window.mozInnerScreenX` (and the same on Y), INSIDE an iframe placed at (220, 150) of the page. The defect of 2026-08-10:
|
||||
`mozInnerScreenX/Y` answered the origin of the top-level content to every window, so the iframe read (top origin) while
|
||||
its events still carried the iframe's offset, and `screenX - clientX` was 220 against a `mozInnerScreenX` of 0.
|
||||
|
||||
Engine hook: `fingerprint/screen-window/geometry` of the engine series: `nsGlobalWindowOuter::GetMozInnerScreenX/Y` and
|
||||
`Event::GetScreenCoords` both add the ONE content origin shift (`nsGlobalWindowOuter::StealthContentOriginShift`, declared
|
||||
window against real one) to the window's OWN real rectangle, so the offset between frames stays true at every depth.
|
||||
|
||||
Control, in the same test: the top window's `mozInnerScreenX/Y` is a different number (the iframe sits 220 and 150 CSS
|
||||
pixels off it). The test asserts the iframe's `mozInnerScreenX/Y` is the top's plus the iframe's rectangle, and that what
|
||||
the events carry (`screenX - clientX`) is NOT the top's origin: a window that answered the top origin to every frame fails
|
||||
both.
|
||||
|
||||
The click is a real one (`page.mouse.click` at a point inside the iframe, the pointer events the engine makes), not a
|
||||
dispatched event. The page and the iframe are one site, so the page may read the iframe's `mozInnerScreenX`.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from _fission_frames import Sites
|
||||
from _waits import wait_until
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
LEFT, TOP = 220, 150
|
||||
|
||||
PARENT = """<!doctype html><meta charset=utf-8><title>parent</title>
|
||||
<style>html,body{margin:0;padding:0;height:100%%}
|
||||
#f{position:absolute;left:%dpx;top:%dpx;width:360px;height:220px;border:0}</style>
|
||||
<body><iframe id=f src="/child"></iframe>
|
||||
<script>
|
||||
window.__geom = () => {
|
||||
const w = document.getElementById('f').contentWindow;
|
||||
const r = document.getElementById('f').getBoundingClientRect();
|
||||
return {top_x: window.mozInnerScreenX, top_y: window.mozInnerScreenY,
|
||||
ifr_x: w.mozInnerScreenX, ifr_y: w.mozInnerScreenY, rect_x: r.x, rect_y: r.y};
|
||||
};
|
||||
</script>""" % (LEFT, TOP)
|
||||
|
||||
CHILD = """<!doctype html><meta charset=utf-8><title>child</title>
|
||||
<style>html,body{margin:0;padding:0;height:100%}
|
||||
#g{position:absolute;left:30px;top:40px;width:220px;height:130px;background:#06c}</style>
|
||||
<body><div id=g>y</div>
|
||||
<script>
|
||||
window.__ev = [];
|
||||
for (const t of ['mousemove', 'mousedown', 'mouseup', 'click']) {
|
||||
window.addEventListener(t, e => {
|
||||
window.__ev.push({t: t, cx: e.clientX, cy: e.clientY, sx: e.screenX, sy: e.screenY});
|
||||
}, true);
|
||||
}
|
||||
window.__inner = () => [window.mozInnerScreenX, window.mozInnerScreenY];
|
||||
</script>"""
|
||||
|
||||
|
||||
def test_a_real_click_in_an_iframe_has_the_screen_origin_of_the_iframe(firefox_binary):
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with Sites() as s:
|
||||
s.route("A", "/parent", PARENT)
|
||||
s.route("A", "/child", CHILD)
|
||||
with InvisiblePlaywright(seed=42, binary_path=firefox_binary, headless=True, humanize=False) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto(s.url("A", "/parent"), wait_until="load", timeout=30000)
|
||||
geom = page.evaluate("() => window.__geom()")
|
||||
frame = page.frames[1]
|
||||
frame.evaluate("() => { window.__ev = []; }")
|
||||
# a point inside the blue square of the iframe, in the coordinates of the page
|
||||
page.mouse.click(LEFT + 30 + 100, TOP + 40 + 60)
|
||||
kinds = {"mousedown", "mouseup", "click"}
|
||||
assert wait_until(lambda: kinds <= {e["t"] for e in frame.evaluate("() => window.__ev")}, 30,
|
||||
lambda: page.wait_for_timeout(100)), (
|
||||
"the iframe heard %r of the click" % [e["t"] for e in frame.evaluate("() => window.__ev")])
|
||||
events = frame.evaluate("() => window.__ev")
|
||||
inner = frame.evaluate("() => window.__inner()")
|
||||
|
||||
# the iframe is where it was put, and answers its OWN origin: the top's plus the iframe's rectangle
|
||||
assert (geom["rect_x"], geom["rect_y"]) == (LEFT, TOP)
|
||||
assert (geom["ifr_x"], geom["ifr_y"]) == (geom["top_x"] + geom["rect_x"], geom["top_y"] + geom["rect_y"]), (
|
||||
"the iframe reads mozInnerScreen (%r, %r), the page's is (%r, %r) and the iframe sits at (%d, %d)"
|
||||
% (geom["ifr_x"], geom["ifr_y"], geom["top_x"], geom["top_y"], LEFT, TOP))
|
||||
assert (inner[0], inner[1]) != (geom["top_x"], geom["top_y"]), "the iframe answers the origin of the top-level content"
|
||||
clicks = [e for e in events if e["t"] == "click"]
|
||||
assert clicks, "no click event in the iframe: %r" % events
|
||||
for e in events:
|
||||
assert e["sx"] - e["cx"] == inner[0], (
|
||||
"%s in the iframe: screenX - clientX = %r against mozInnerScreenX = %r" % (e["t"], e["sx"] - e["cx"], inner[0]))
|
||||
assert e["sy"] - e["cy"] == inner[1], (
|
||||
"%s in the iframe: screenY - clientY = %r against mozInnerScreenY = %r" % (e["t"], e["sy"] - e["cy"], inner[1]))
|
||||
# the control: the top window's origin is NOT what the events carry
|
||||
assert (e["sx"] - e["cx"], e["sy"] - e["cy"]) != (geom["top_x"], geom["top_y"])
|
||||
@@ -1,136 +0,0 @@
|
||||
"""The size and pointer media queries answer the declaration, not the host.
|
||||
|
||||
What it fixes, from the page's side (`matchMedia`):
|
||||
|
||||
* `(device-width: Wpx)` / `(device-height: Hpx)` are the declared screen (`zoom.stealth.screen.width/height`), not the
|
||||
host's monitor.
|
||||
* `(pointer: ...)` / `(any-pointer: ...)` / `(hover: ...)` are the declared pointer capabilities
|
||||
(`zoom.stealth.pointer.primary` / `.all`, the bitmask Coarse 1, Fine 2, Hover 4), not the host's (a Windows machine
|
||||
with a digitizer adds Coarse by itself).
|
||||
* A context made with `has_touch=True` (Juggler's touch override) still reads a COARSE pointer when a fine one is
|
||||
declared: the override of the context decides before the declaration does.
|
||||
|
||||
Engine hook: `fingerprint/screen-window/css-media` of the engine series (`layout/style/nsMediaFeatures.cpp`:
|
||||
`GetDeviceSize`, `GetPointerCapabilities`; the declarations in `StealthMediaFeatures.h`).
|
||||
|
||||
Negative controls, in the same test: the device size is read on a launch declared with ANOTHER screen (2623x1411): the
|
||||
wrapper hands the declared screen to the browser by two roads (the screen prefs and the screen of the context, which Juggler
|
||||
emulates), so a launch with the prefs at 0 still reads the pinned screen; the queries must follow each declaration. The
|
||||
pointer is read with the engine off (`hw_seed` 0, stock Firefox: an active engine refuses a declaration cleared with -1), the
|
||||
host's answer; and has_touch is read in a context without it, on the same launch.
|
||||
|
||||
Linux and Windows run the same assertions: the declared values are the ones no runner has (a 2731x1537 screen; a coarse
|
||||
primary pointer on a machine with a mouse).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
#: A screen no runner has.
|
||||
SCREEN = {"screen.width": 2731, "screen.height": 1537, "screen.dpr": 1.0}
|
||||
|
||||
#: Another screen no runner has: the control of the device size is a launch declared with this one.
|
||||
OTHER_SCREEN = {"screen.width": 2623, "screen.height": 1411, "screen.dpr": 1.0}
|
||||
|
||||
#: The engine off (stock Firefox): the control of the pointer. The engine refuses an active launch with a declaration cleared.
|
||||
ENGINE_OFF = {"zoom.stealth.fpp.hw_seed": 0}
|
||||
|
||||
COARSE, FINE, HOVER = 1, 2, 4
|
||||
|
||||
QUERIES = {name: "matchMedia('%s').matches" % query for name, query in {
|
||||
"pointer_coarse": "(pointer: coarse)", "pointer_fine": "(pointer: fine)",
|
||||
"any_coarse": "(any-pointer: coarse)", "any_fine": "(any-pointer: fine)",
|
||||
"hover_none": "(hover: none)", "any_hover_none": "(any-hover: none)"}.items()}
|
||||
|
||||
READ_POINTER = "() => ({%s})" % ", ".join("%s: %s" % (k, v) for k, v in QUERIES.items())
|
||||
|
||||
|
||||
def _launch(binary, pin=None, extra_prefs=None):
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
return InvisiblePlaywright(seed=42, pin=pin, binary_path=binary, headless=True, humanize=False,
|
||||
extra_prefs=extra_prefs)
|
||||
|
||||
|
||||
def _read_pointer(binary, primary=None, every=None):
|
||||
"""Declared pointer prefs, or (both None) the engine off."""
|
||||
prefs = ENGINE_OFF if primary is None else {"zoom.stealth.pointer.primary": primary, "zoom.stealth.pointer.all": every}
|
||||
with _launch(binary, extra_prefs=prefs) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto("about:blank", timeout=30000)
|
||||
return page.evaluate(READ_POINTER)
|
||||
|
||||
|
||||
def test_a_declared_pointer_is_what_the_media_queries_read(firefox_binary):
|
||||
declared = _read_pointer(firefox_binary, COARSE, COARSE)
|
||||
assert declared == {"pointer_coarse": True, "pointer_fine": False, "any_coarse": True, "any_fine": False,
|
||||
"hover_none": True, "any_hover_none": True}, (
|
||||
"a coarse pointer without hover is declared and the page reads %r" % declared)
|
||||
|
||||
# The control: the engine off is not that machine. A fine pointer with hover is the declaration of a desktop; the host
|
||||
# with no declaration answers its own, and it is not a coarse one without hover.
|
||||
undeclared = _read_pointer(firefox_binary)
|
||||
assert undeclared != declared, "with no pointer declared the page reads the same as with a coarse one: %r" % undeclared
|
||||
assert undeclared["pointer_coarse"] is False and undeclared["any_coarse"] is False, (
|
||||
"with no pointer declared the page reads %r" % undeclared)
|
||||
|
||||
fine = _read_pointer(firefox_binary, FINE | HOVER, FINE | HOVER)
|
||||
assert fine == {"pointer_coarse": False, "pointer_fine": True, "any_coarse": False, "any_fine": True,
|
||||
"hover_none": False, "any_hover_none": False}, (
|
||||
"a fine pointer with hover is declared and the page reads %r" % fine)
|
||||
|
||||
|
||||
def test_has_touch_reads_a_coarse_pointer_even_when_a_fine_one_is_declared(firefox_binary):
|
||||
with _launch(firefox_binary, extra_prefs={"zoom.stealth.pointer.primary": FINE | HOVER,
|
||||
"zoom.stealth.pointer.all": FINE | HOVER}) as browser:
|
||||
plain = browser.new_context().new_page()
|
||||
plain.goto("about:blank", timeout=30000)
|
||||
touch = browser.new_context(has_touch=True).new_page()
|
||||
touch.goto("about:blank", timeout=30000)
|
||||
without = plain.evaluate(READ_POINTER)
|
||||
with_touch = touch.evaluate(READ_POINTER)
|
||||
# the control: the same launch, a context without the override, reads the declared fine pointer
|
||||
assert without["pointer_fine"] is True and without["pointer_coarse"] is False, (
|
||||
"a context without has_touch reads %r under a declared fine pointer" % without)
|
||||
assert with_touch["pointer_coarse"] is True and with_touch["pointer_fine"] is False, (
|
||||
"a context with has_touch reads %r under a declared fine pointer: the touch override must win" % with_touch)
|
||||
assert with_touch["any_coarse"] is True, "any-pointer in a has_touch context reads %r" % with_touch
|
||||
|
||||
|
||||
def _read_device_size(binary, pin, ask):
|
||||
"""The page of a launch pinned to ``pin``, asked for the device size ``ask`` (width, height) and for its own."""
|
||||
with _launch(binary, pin=pin) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto("about:blank", timeout=30000)
|
||||
return page.evaluate("""([w, h]) => ({
|
||||
screen_w: screen.width, screen_h: screen.height,
|
||||
device_width: matchMedia('(device-width: ' + w + 'px)').matches,
|
||||
device_height: matchMedia('(device-height: ' + h + 'px)').matches,
|
||||
own_width: matchMedia('(device-width: ' + screen.width + 'px)').matches,
|
||||
own_height: matchMedia('(device-height: ' + screen.height + 'px)').matches})""", list(ask))
|
||||
|
||||
|
||||
def test_the_device_size_media_queries_read_the_declared_screen(firefox_binary):
|
||||
first = (SCREEN["screen.width"], SCREEN["screen.height"])
|
||||
second = (OTHER_SCREEN["screen.width"], OTHER_SCREEN["screen.height"])
|
||||
|
||||
declared = _read_device_size(firefox_binary, SCREEN, first)
|
||||
assert declared["device_width"] is True and declared["device_height"] is True, (
|
||||
"(device-width: 2731px) and (device-height: 1537px) do not match under a declared 2731x1537 screen: %r" % declared)
|
||||
assert (declared["screen_w"], declared["screen_h"]) == first
|
||||
assert declared["own_width"] is True and declared["own_height"] is True, (
|
||||
"the device size the media queries read is not the screen the page reads: %r" % declared)
|
||||
|
||||
# The control: the wrapper hands the declared screen to the browser by two roads (the prefs, and the screen of the context
|
||||
# that Juggler emulates), so the absent declaration is not a control. A launch with ANOTHER declared screen is: the same
|
||||
# query for the first size does not match there, and the queries follow that declaration.
|
||||
other = _read_device_size(firefox_binary, OTHER_SCREEN, first)
|
||||
assert (other["screen_w"], other["screen_h"]) == second, other
|
||||
assert other["device_width"] is False and other["device_height"] is False, (
|
||||
"(device-width: 2731px) matches under a declared %dx%d screen: the media queries do not follow the declaration, %r"
|
||||
% (second + (other,)))
|
||||
assert other["own_width"] is True and other["own_height"] is True, (
|
||||
"the device size the media queries read is not the screen the page reads: %r" % other)
|
||||
assert second != first and other != declared
|
||||
@@ -313,105 +313,3 @@ def test_webgl_readpixels_no_masking_signature(page):
|
||||
f"WebGL readPixels shows {res['spikes']} high-frequency noise spikes "
|
||||
f"(pixelscan-maskable); the stealth noise must be a smooth gamma remap."
|
||||
)
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
# The declared screen, and the inner size of the top level (characterisation of
|
||||
# the engine hooks fingerprint/screen-window/screen: nsScreen.cpp, nsPresContext.cpp)
|
||||
# ===========================================================================
|
||||
|
||||
#: A screen no runner has: 2731x1537, a 41 px taskbar, 30-bit colour, at scale 1.0.
|
||||
_DECLARED_SCREEN = {"screen.width": 2731, "screen.height": 1537, "screen.taskbar_px": 41,
|
||||
"screen.color_depth": 30, "screen.dpr": 1.0}
|
||||
|
||||
#: Another screen no runner has, for the control: the wrapper hands the declared screen to the browser by two roads (the prefs and
|
||||
#: the screen of the context that Juggler emulates), so a launch with the prefs at 0 still reads the pinned screen.
|
||||
_OTHER_SCREEN = {"screen.width": 2623, "screen.height": 1411, "screen.taskbar_px": 37,
|
||||
"screen.color_depth": 24, "screen.dpr": 1.0}
|
||||
|
||||
_READ_SCREEN = """() => ({width: screen.width, height: screen.height, availWidth: screen.availWidth,
|
||||
availHeight: screen.availHeight, pixelDepth: screen.pixelDepth,
|
||||
colorDepth: screen.colorDepth})"""
|
||||
|
||||
|
||||
def _read_screen(firefox_binary, pin=_DECLARED_SCREEN):
|
||||
with InvisiblePlaywright(seed=42, pin=pin, binary_path=firefox_binary, headless=True) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto("about:blank", timeout=30_000)
|
||||
return page.evaluate(_READ_SCREEN)
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_a_declared_screen_that_no_runner_has_is_what_the_page_reads(firefox_binary):
|
||||
"""The page reads the screen the core declares (nsScreen::GetRect, GetAvailRect, PixelDepth), not the host's.
|
||||
|
||||
The available height is the declared height less the declared taskbar (2731x1537, taskbar 41, depth 30 -> availWidth
|
||||
2731, availHeight 1496). The control is a launch declared with ANOTHER screen (2623x1411, taskbar 37, depth 24: the wrapper
|
||||
hands the declared screen to the browser by two roads, so the absent declaration is not a control): the page reads that one, and
|
||||
none of the first declaration's numbers.
|
||||
"""
|
||||
from _popup_geometry import in_a_thread_of_its_own
|
||||
|
||||
# The module's `page` fixture keeps a sync client open in this thread: a second browser needs a thread of its own.
|
||||
declared = in_a_thread_of_its_own(lambda: _read_screen(firefox_binary))
|
||||
assert declared == {"width": 2731, "height": 1537, "availWidth": 2731, "availHeight": 1537 - 41,
|
||||
"pixelDepth": 30, "colorDepth": 30}, "the page reads %r under a declared 2731x1537 screen" % declared
|
||||
|
||||
host = in_a_thread_of_its_own(lambda: _read_screen(firefox_binary, _OTHER_SCREEN))
|
||||
assert host == {"width": 2623, "height": 1411, "availWidth": 2623, "availHeight": 1411 - 37,
|
||||
"pixelDepth": 24, "colorDepth": 24}, "the page reads %r under another declared screen" % host
|
||||
for key in ("width", "height", "availWidth", "availHeight", "pixelDepth"):
|
||||
assert host[key] != declared[key], (
|
||||
"under another declared screen screen.%s reads %r, the first declared value: the control reads the first declaration "
|
||||
"(%r)" % (key, host[key], host))
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
def test_the_inner_size_of_the_top_is_synced_with_the_engine_active_and_not_without(firefox_binary):
|
||||
"""A popup's iframe reads the top level's inner size (nsPresContext::UpdateInnerSizeSpoofedForRFP).
|
||||
|
||||
With the engine active the top-level inner size is synced to every process of the browsing context, so an iframe of
|
||||
another site in a popup (200x150, in its own process) answers the outer size of the POPUP: the top's inner size plus the
|
||||
declared frame, 2 * border wide and popup UI + border high, and not the size of its own 200x150. The popup itself
|
||||
answers the same. The control is the same page in a launch declared with a SECOND frame that no runner has (border 6, popup
|
||||
UI 53): the iframe then answers the top's inner size plus THAT frame, and none of the first declaration's. The engine off is
|
||||
not the control: the declared frame is the one of a retail Windows window at scale 1.0, so a Windows runner's own popup
|
||||
reads it with the engine off too (measured: 516x480 for a 500x400 popup) and the test could not fail there.
|
||||
"""
|
||||
from _popup_geometry import (OTHER_BORDER, OTHER_FRAME, OTHER_POPUP_UI, frame_extra, frame_of_the_declaration,
|
||||
in_a_thread_of_its_own, read_popup)
|
||||
|
||||
frame = frame_of_the_declaration()
|
||||
extra = frame_extra(frame.border, frame.popup_ui)
|
||||
other_extra = frame_extra(OTHER_BORDER, OTHER_POPUP_UI)
|
||||
assert other_extra != extra
|
||||
|
||||
def synced_to(wanted):
|
||||
def synced(reading):
|
||||
top = reading["popup"]
|
||||
return (reading["frame"]["ow"], reading["frame"]["oh"]) == (top["iw"] + wanted[0], top["ih"] + wanted[1])
|
||||
return synced
|
||||
|
||||
# The module's `page` fixture keeps a sync client open in this thread: a second browser needs a thread of its own.
|
||||
on = in_a_thread_of_its_own(lambda: read_popup(firefox_binary, iframe=True, ready=synced_to(extra)))
|
||||
top, inner = on["popup"], on["frame"]
|
||||
assert (top["ow"], top["oh"]) == (top["iw"] + extra[0], top["ih"] + extra[1]), (
|
||||
"the popup reads outer %dx%d for inner %dx%d, the declared frame adds %r" % (top["ow"], top["oh"], top["iw"],
|
||||
top["ih"], extra))
|
||||
assert (inner["ow"], inner["oh"]) == (top["iw"] + extra[0], top["ih"] + extra[1]), (
|
||||
"the iframe of the popup reads outer %dx%d, the top level's inner %dx%d plus the declared frame %r is %dx%d (the "
|
||||
"iframe's own inner size is %dx%d)" % (inner["ow"], inner["oh"], top["iw"], top["ih"], extra,
|
||||
top["iw"] + extra[0], top["ih"] + extra[1], inner["iw"], inner["ih"]))
|
||||
assert (inner["iw"], inner["ih"]) != (top["iw"], top["ih"]), "the iframe has the size of the popup: the read proves nothing"
|
||||
|
||||
other = in_a_thread_of_its_own(lambda: read_popup(firefox_binary, extra_prefs=OTHER_FRAME, iframe=True, ready=synced_to(other_extra)))
|
||||
other_top, other_inner = other["popup"], other["frame"]
|
||||
assert (other_inner["ow"], other_inner["oh"]) == (other_top["iw"] + other_extra[0], other_top["ih"] + other_extra[1]), (
|
||||
"declared with another frame the iframe of a popup reads outer %dx%d, the top's inner %dx%d plus the second declared frame %r is %dx%d: %r"
|
||||
% (other_inner["ow"], other_inner["oh"], other_top["iw"], other_top["ih"], other_extra,
|
||||
other_top["iw"] + other_extra[0], other_top["ih"] + other_extra[1], other))
|
||||
assert (other_top["ow"], other_top["oh"]) == (other_top["iw"] + other_extra[0], other_top["ih"] + other_extra[1]), (
|
||||
"declared with another frame the popup reads outer %dx%d for inner %dx%d, the second declared frame adds %r"
|
||||
% (other_top["ow"], other_top["oh"], other_top["iw"], other_top["ih"], other_extra))
|
||||
assert (other_inner["ow"] - other_top["iw"], other_inner["oh"] - other_top["ih"]) != (inner["ow"] - top["iw"], inner["oh"] - top["ih"]), (
|
||||
"the iframe reads the same frame under two declarations: it does not follow the declaration: %r vs %r" % (other, on))
|
||||
@@ -0,0 +1,279 @@
|
||||
"""An IPv6 literal a page asks for is judged by the declared network, and a destination behind a SOCKS proxy is left to the proxy.
|
||||
|
||||
What this fixes in place (characterisation of the published engine firefox-68; the engine hook is `nsSocketTransport::InitiateSocket` in
|
||||
`netwerk/base/nsSocketTransport2.cpp`, the decision is `StealthConnect` / `StealthConnectError` in `netwerk/base/StealthIPv6Literal.cpp`, series folder
|
||||
`network/ipv6-literal`):
|
||||
|
||||
* The session declares its host network in `STEALTHFOX_WEBRTC_NETWORK` (`v6=0`: no IPv6). A hostname then never resolves to AAAA, but a LITERAL
|
||||
(`http://[2001:db8::1]/`) is handed to the socket by Firefox without any lookup, and the route table of the machine under the browser would decide.
|
||||
The engine decides instead: a direct connection to a routable IPv6 literal fails before `connect()` is called, the way a Windows machine that has the
|
||||
IPv6 stack and no IPv6 route fails it, and nothing is sent. The client reads it as `NS_ERROR_CONNECTION_REFUSED` (a failed `fetch` is a `TypeError`,
|
||||
and `requestfailed` carries that text). A page reads this: whether `fetch("http://[<global IPv6>]/")` fails at once or hangs, and with which error, is
|
||||
the first thing that tells a machine with an IPv6 route from one without.
|
||||
* An IPv4-mapped literal (`::ffff:127.0.0.1`) is refused on every system and whatever the declaration says: Windows refuses `connect()` to a mapped
|
||||
address on a socket that is IPv6-only (Firefox's are), and a dual-stack Linux socket would connect over IPv4. The listener below never sees it.
|
||||
* A destination behind a SOCKS proxy is never judged: the proxy reaches it, not this host. The same literal that is refused with no proxy reaches the
|
||||
proxy as a CONNECT whose destination is that address and port, as an IPv6 address (SOCKS5 address type 4), never as a name. How many times the
|
||||
browser tries it (Mozilla retries a connection that did not answer at once) is Mozilla's code and is not fixed here: every CONNECT of the
|
||||
navigation to the documentation destination has that shape, and there is at least one.
|
||||
|
||||
Not clocks: "refused by the engine" and "timed out" are told apart by the error (`TypeError` with the failure text `NS_ERROR_CONNECTION_REFUSED`, against a
|
||||
`TimeoutError` of the 30 s deadline of the fetch), and by the listener having heard nothing; no duration is read anywhere.
|
||||
|
||||
Negative controls, in the same test:
|
||||
|
||||
* the listener is real: the same address by its IPv4 literal (`127.0.0.1`) reaches it, once, in the launches where the mapped literal does not;
|
||||
* the mapped literal is refused with IPv6 declared on as well as off (a rule of its own: the declaration decides the other literals, not this one);
|
||||
* behind the proxy the documentation-prefix literal that is refused direct IS carried: an engine that judged it behind SOCKS (or that always passed
|
||||
`kDirect`) would make the proxy record no CONNECT, and the fetch would fail; and an engine that handed the proxy the literal in another shape (a
|
||||
name, an IPv4 address) fails the shape assertion.
|
||||
|
||||
What this test cannot tell, by design: with IPv6 declared on, a global IPv6 literal goes to the OS, whose answer depends on the machine (a runner with no
|
||||
IPv6 route answers `ENETUNREACH`, the same `NS_ERROR_CONNECTION_REFUSED` as the engine's), so the documentation-prefix fetch is judged only in the
|
||||
declared-off launch and behind the proxy. The port is 80: Firefox bans port 9 (discard) before any connect, so a fetch to it never reaches the gate.
|
||||
|
||||
Hermetic: a local listener, a local SOCKS5 gateway of `tests/_socks_servers.py` that maps the documentation address to the listener and forwards
|
||||
NOTHING else: the browser's own background traffic also arrives at the gateway, and every CONNECT to an address that is not the lab's is refused
|
||||
(reply 5) and recorded. Every request, refused or carried, is recorded with its time since the launch, its SOCKS5 address type, its destination as received and
|
||||
its port. The refused list is written, always, under `$RUNNER_TEMP/invpw-evidence/` (the folder the e2e jobs upload), so that a reader sees
|
||||
what the browser asked for besides the literal.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import socket
|
||||
import socketserver
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from _servers import LocalServer
|
||||
from _socks_servers import EXIT, Gateway, _recv_exact
|
||||
from _udp_line import egress_by_proxy, measure_servers
|
||||
from _waits import wait_until
|
||||
from test_declared_host_network_e2e import DUAL, NETWORK_ENV, V4_ONLY
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
#: A global-unicast-looking address that no host routes (RFC 3849 documentation prefix): the gate answers for it, whatever the machine has.
|
||||
DOCUMENTATION = "2001:db8::1"
|
||||
DOCUMENTATION_HTTP = 80
|
||||
#: What a failed connect of the engine is called by the browser (NSPR's PR_NETWORK_UNREACHABLE_ERROR and PR_ADDRESS_NOT_AVAILABLE_ERROR both end here).
|
||||
REFUSED = "NS_ERROR_CONNECTION_REFUSED"
|
||||
#: SOCKS5 address type of an IPv6 address (RFC 1928); 1 is IPv4, 3 a domain name.
|
||||
ATYP_IPV6 = 4
|
||||
#: The folder under ``$RUNNER_TEMP`` the e2e workflows upload (``invpw-evidence-*``).
|
||||
EVIDENCE_FOLDER = "invpw-evidence"
|
||||
#: The deadline of a fetch that must END (refused, or carried): far beyond a healthy run; what the page reads on a timeout is a `TimeoutError`, never a verdict.
|
||||
FETCH_SECONDS = 30
|
||||
|
||||
_FETCH_JS = """async (url) => {
|
||||
try {
|
||||
const response = await fetch(url, {mode: 'no-cors', cache: 'no-store', signal: AbortSignal.timeout(%d)});
|
||||
return {ok: true, type: response.type};
|
||||
} catch (e) {
|
||||
return {ok: false, name: e.name, message: String(e.message)};
|
||||
}
|
||||
}""" % (FETCH_SECONDS * 1000)
|
||||
|
||||
|
||||
class _Listener:
|
||||
"""A local HTTP-ish listener that remembers every connection it accepted and answers each with a tiny 200."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.connections: list = []
|
||||
outer = self
|
||||
|
||||
class Handler(socketserver.BaseRequestHandler):
|
||||
def handle(self) -> None:
|
||||
outer.connections.append(self.client_address)
|
||||
self.request.settimeout(FETCH_SECONDS)
|
||||
try:
|
||||
self.request.recv(65536)
|
||||
self.request.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok")
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
self.server = LocalServer(("127.0.0.1", 0), Handler)
|
||||
self.port: int = self.server.server_address[1]
|
||||
threading.Thread(target=self.server.serve_forever, daemon=True).start()
|
||||
|
||||
def __enter__(self) -> "_Listener":
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc) -> None:
|
||||
self.server.shutdown()
|
||||
self.server.server_close()
|
||||
|
||||
|
||||
class _GatewayToALocalListener(Gateway):
|
||||
"""The SOCKS5 gateway of the tests (UDP refused) that carries the documentation address to a local listener and forwards nothing else: the destination
|
||||
it is asked for is what it records in ``connects`` (with its SOCKS5 address type in ``addresses``), what the listener hears is what it carried, and
|
||||
every CONNECT to an address that is not the lab's is refused and recorded in ``refused``."""
|
||||
|
||||
def __init__(self, carried: dict) -> None:
|
||||
self._carried = dict(carried)
|
||||
#: Every address of a request the gateway read, as (host, port, address type), in order.
|
||||
self.addresses: list = []
|
||||
#: Every CONNECT that was not the lab's and was refused (reply 5, connection refused), as (host, port), in order.
|
||||
self.refused: list = []
|
||||
#: Every request, as a dict, for the evidence file: ``t`` (seconds, monotonic, since ``launch_started``), ``atyp`` (SOCKS5 address type: 1 IPv4,
|
||||
#: 3 domain name, 4 IPv6), ``destination`` (as received: the NAME when the type is 3), ``port``, ``outcome``.
|
||||
self.records: list = []
|
||||
self._launch_t0 = time.monotonic()
|
||||
self._current = threading.local()
|
||||
super().__init__(udp="refuse", tcp_exit=EXIT, udp_exit=EXIT)
|
||||
|
||||
@staticmethod
|
||||
def _address_of(c: socket.socket):
|
||||
atyp = _recv_exact(c, 1)[0]
|
||||
if atyp == 1:
|
||||
host = socket.inet_ntoa(_recv_exact(c, 4))
|
||||
elif atyp == 3:
|
||||
host = _recv_exact(c, _recv_exact(c, 1)[0]).decode()
|
||||
else:
|
||||
host = socket.inet_ntop(socket.AF_INET6, _recv_exact(c, 16))
|
||||
return host, struct.unpack("!H", _recv_exact(c, 2))[0], atyp
|
||||
|
||||
def launch_started(self) -> None:
|
||||
"""Call just before the launch of the browser behind this gateway: the origin of the times of ``records``."""
|
||||
self._launch_t0 = time.monotonic()
|
||||
|
||||
def _read_address(self, c: socket.socket):
|
||||
host, port, atyp = self._address_of(c)
|
||||
self.addresses.append((host, port, atyp))
|
||||
record = {"t": round(time.monotonic() - self._launch_t0, 3), "atyp": atyp, "destination": host, "port": port,
|
||||
"outcome": "answered by the lab (or not a CONNECT)"}
|
||||
self.records.append(record)
|
||||
self._current.record = record
|
||||
return host, port
|
||||
|
||||
def _target(self, host: str, port: int):
|
||||
return self._carried.get((host, port), (host, port))
|
||||
|
||||
def _open_upstream(self, target):
|
||||
if target not in self._carried.values():
|
||||
self.refused.append(target)
|
||||
self._current.record["outcome"] = "refused"
|
||||
raise OSError("the lab forwards nothing outside the lab: %s:%d" % target)
|
||||
self._current.record["outcome"] = "carried to the listener of the lab"
|
||||
return super()._open_upstream(target)
|
||||
|
||||
def documentation_connects(self) -> list:
|
||||
"""Every request of the navigation to the documentation destination, in whatever shape it arrived: the host is told by its digits."""
|
||||
return [(host, port, atyp) for host, port, atyp in self.addresses if "2001:db8" in host.lower()]
|
||||
|
||||
|
||||
def _write_refused(gateway: "_GatewayToALocalListener") -> None:
|
||||
"""What the gateway refused, always (a few lines): under ``$RUNNER_TEMP/invpw-evidence/`` the e2e jobs upload. Off a runner nothing is written."""
|
||||
runner_temp = os.environ.get("RUNNER_TEMP")
|
||||
if not runner_temp:
|
||||
return
|
||||
folder = pathlib.Path(runner_temp) / EVIDENCE_FOLDER / "ipv6-literal-refused-connects" / ("%d-%d" % (os.getpid(), int(time.time() * 1000)))
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
(folder / "refused-connects.json").write_text(json.dumps({
|
||||
"refused": ["%s:%d" % target for target in gateway.refused],
|
||||
"requests": gateway.records,
|
||||
}, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def _launch(firefox_binary, gateway=None):
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
kw = {"seed": 42, "binary_path": firefox_binary, "headless": True, "timezone": "America/New_York"}
|
||||
if gateway is not None:
|
||||
kw.update(proxy=gateway.proxy, udp_stun_servers=measure_servers(gateway))
|
||||
return InvisiblePlaywright(**kw)
|
||||
|
||||
|
||||
def _try(page, failures, url, needle):
|
||||
"""One fetch of ``url`` from the page: what the page read, and the failure texts the client reported for the request whose URL holds ``needle``."""
|
||||
result = page.evaluate(_FETCH_JS, url)
|
||||
if not result["ok"]:
|
||||
wait_until(lambda: [text for seen, text in failures if needle in seen], FETCH_SECONDS, lambda: page.wait_for_timeout(50))
|
||||
return result, [text for seen, text in failures if needle in seen]
|
||||
|
||||
|
||||
def _page_of(browser):
|
||||
page = browser.new_context().new_page()
|
||||
failures: list = []
|
||||
page.on("requestfailed", lambda request: failures.append((request.url, request.failure)))
|
||||
page.goto("about:blank")
|
||||
return page, failures
|
||||
|
||||
|
||||
def _direct_launch(firefox_binary, monkeypatch, declaration, listener, with_documentation_prefix):
|
||||
"""One launch with no proxy and ``declaration``: the IPv4 literal of the listener (control), the mapped literal of the same listener, and, when
|
||||
asked, the documentation-prefix literal. Returns what was read and the connections the listener heard after each step."""
|
||||
monkeypatch.setenv(NETWORK_ENV, declaration)
|
||||
seen = {}
|
||||
with _launch(firefox_binary) as browser:
|
||||
page, failures = _page_of(browser)
|
||||
before = len(listener.connections)
|
||||
seen["control"] = _try(page, failures, "http://127.0.0.1:%d/" % listener.port, "127.0.0.1")
|
||||
wait_until(lambda: len(listener.connections) > before, FETCH_SECONDS, lambda: page.wait_for_timeout(50))
|
||||
seen["after_control"] = len(listener.connections) - before
|
||||
seen["mapped"] = _try(page, failures, "http://[::ffff:127.0.0.1]:%d/" % listener.port, "[::ffff:")
|
||||
seen["after_mapped"] = len(listener.connections) - before
|
||||
if with_documentation_prefix:
|
||||
seen["documentation"] = _try(page, failures, "http://[%s]:%d/" % (DOCUMENTATION, DOCUMENTATION_HTTP), "[%s]" % DOCUMENTATION)
|
||||
return seen
|
||||
|
||||
|
||||
def test_a_direct_ipv6_literal_is_refused_and_one_behind_socks_is_left_to_the_proxy(firefox_binary, monkeypatch):
|
||||
from invisible_core import _geo
|
||||
|
||||
with _Listener() as direct, _Listener() as behind:
|
||||
off = _direct_launch(firefox_binary, monkeypatch, V4_ONLY, direct, with_documentation_prefix=True)
|
||||
on = _direct_launch(firefox_binary, monkeypatch, DUAL, direct, with_documentation_prefix=False)
|
||||
|
||||
# Behind a SOCKS5 gateway, IPv6 declared off as in the first launch: the documentation-prefix literal is the proxy's to reach.
|
||||
gateway = _GatewayToALocalListener({(DOCUMENTATION, DOCUMENTATION_HTTP): ("127.0.0.1", behind.port)})
|
||||
try:
|
||||
monkeypatch.setattr(_geo, "discover_egress_ip", egress_by_proxy(gateway))
|
||||
monkeypatch.setenv(NETWORK_ENV, V4_ONLY)
|
||||
gateway.launch_started()
|
||||
with _launch(firefox_binary, gateway) as browser:
|
||||
page, failures = _page_of(browser)
|
||||
proxied = _try(page, failures, "http://[%s]:%d/" % (DOCUMENTATION, DOCUMENTATION_HTTP), "[%s]" % DOCUMENTATION)
|
||||
wait_until(lambda: behind.connections, FETCH_SECONDS, lambda: page.wait_for_timeout(50))
|
||||
documentation = gateway.documentation_connects()
|
||||
finally:
|
||||
gateway.close()
|
||||
_write_refused(gateway)
|
||||
|
||||
# The listener is real: its IPv4 literal reaches it, once per launch.
|
||||
for name, seen in (("declared off", off), ("declared on", on)):
|
||||
control, _failed = seen["control"]
|
||||
assert control["ok"], "%s: the IPv4 literal of the local listener was not reached: %s" % (name, seen)
|
||||
assert seen["after_control"] == 1, "%s: the listener heard %d connections for one fetch of its IPv4 literal: %s" % (name, seen["after_control"], seen)
|
||||
|
||||
# An IPv4-mapped literal is refused by the engine, declared off or on, and the listener hears nothing for it.
|
||||
for name, seen in (("declared off", off), ("declared on", on)):
|
||||
result, failed = seen["mapped"]
|
||||
assert result["ok"] is False and result["name"] == "TypeError", (
|
||||
"%s: the fetch of the mapped literal did not fail as a refused connection (a TimeoutError would be a connect that was attempted): %s" % (name, seen))
|
||||
assert failed == [REFUSED], "%s: the client reported %r for the mapped literal, not the engine's refusal: %s" % (name, failed, seen)
|
||||
assert seen["after_mapped"] == seen["after_control"], "%s: the listener heard a connection through the mapped literal: %s" % (name, seen)
|
||||
|
||||
# With IPv6 declared off, a direct documentation-prefix literal is refused by the engine: the same failure as a machine with no IPv6 route.
|
||||
result, failed = off["documentation"]
|
||||
assert result["ok"] is False and result["name"] == "TypeError", (
|
||||
"declared off: the direct fetch of %s did not fail as a refused connection (a TimeoutError means a connect was attempted): %s" % (DOCUMENTATION, off))
|
||||
assert failed == [REFUSED], "declared off: the client reported %r for the direct documentation-prefix literal: %s" % (failed, off)
|
||||
|
||||
# The same literal behind the SOCKS5 gateway is carried: every CONNECT of the navigation to the documentation destination is the IPv6 literal and port,
|
||||
# as an IPv6 address (how many the browser makes is Mozilla's), and the listener behind it answered.
|
||||
assert proxied[0] == {"ok": True, "type": "opaque"}, (
|
||||
"the fetch of %s behind the SOCKS5 gateway was not carried (it is refused with no proxy): %s; failures %s; gateway requests %s" % (
|
||||
DOCUMENTATION, proxied[0], proxied[1], gateway.addresses))
|
||||
assert documentation, "the gateway was asked for no CONNECT to %s:%d: %s" % (DOCUMENTATION, DOCUMENTATION_HTTP, gateway.addresses)
|
||||
assert set(documentation) == {(DOCUMENTATION, DOCUMENTATION_HTTP, ATYP_IPV6)}, (
|
||||
"every CONNECT to the documentation destination should carry the IPv6 literal %s port %d as an IPv6 address (type %d): %s" % (
|
||||
DOCUMENTATION, DOCUMENTATION_HTTP, ATYP_IPV6, documentation))
|
||||
assert (DOCUMENTATION, DOCUMENTATION_HTTP) not in gateway.refused, "the gateway refused the destination of the lab: %s" % gateway.refused
|
||||
assert len(behind.connections) >= 1, "the listener behind the gateway heard nothing"
|
||||
@@ -1,120 +0,0 @@
|
||||
"""A popup reads the window frame the core declares, not the one of the host.
|
||||
|
||||
What it fixes: the geometry of a window a page opens with `window.open(url, 'p', 'width=500,height=400')`, read from
|
||||
inside the popup. A popup is its real inner size plus the declared frame (retail Windows Firefox, measured by the core at
|
||||
scale 1.0: a border of 8 on the left, right and bottom, the popup UI of 72 above the content, and a default position of
|
||||
4,4 when the page names no left/top):
|
||||
|
||||
* `outerWidth == innerWidth + 2 * border`
|
||||
* `outerHeight == innerHeight + popup_ui + border`
|
||||
* `screenX == screenY ==` the declared default position (the page named none)
|
||||
* `mozInnerScreenX == screenX + border`, `mozInnerScreenY == screenY + popup_ui`
|
||||
|
||||
Engine hook: `fingerprint/screen-window/geometry` of the engine series (`nsGlobalWindowOuter::GetOuterSize`,
|
||||
`GetScreenXY`, `GetMozInnerScreenX/Y`, with the content origin shift of `StealthScreenCoords`) and
|
||||
`fingerprint/screen-window/popup-position` (`nsWindowWatcher`, the default position of a popup).
|
||||
|
||||
Negative control, in the same test: the same page in a launch declared with a SECOND frame that no runner has (border 6,
|
||||
popup UI 53, default position 9). The popup reads that one (outer - inner = 12 x 59, screen 9, mozInnerScreen 15 x 62) and
|
||||
none of the first declaration's numbers, and the two readings DIFFER. The engine off is not the control: the declared frame
|
||||
is the one of a retail Windows window at scale 1.0, so on a Windows runner the host's own popup has the very same frame
|
||||
(measured: 16 x 80 with the engine off) and the test could not tell a hook that answers from one that does not.
|
||||
|
||||
A popup that names ONLY `left` (`window.open(url, 'p', 'width=500,height=400,left=137')`, `test_a_popup_naming_only_left_..`): the
|
||||
hook (`StealthPlacePopupAtDefault`, `fingerprint/screen-window/popup-position`) fills in only the coordinate the page did not give, so
|
||||
`screenX` is the 137 the page asked for (the opener's CSS-to-desktop scale is 1.0 here, no second conversion) and `screenY` is the
|
||||
declared default position, 4 (9 under the second frame); the frame relations are the same as for a popup with no position at all.
|
||||
|
||||
Why a page reads it: `outerWidth - innerWidth`, `screenX` and `mozInnerScreenX/Y` are one line each, and a popup whose
|
||||
frame is not a Windows frame is a browser that does not run on Windows. Linux and Windows run the same assertions: the
|
||||
declaration, not the host, is what is read.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from _popup_geometry import (OTHER_BORDER, OTHER_FRAME, OTHER_POPUP_UI, OTHER_POSITION, frame_extra, frame_of_the_declaration,
|
||||
read_popup)
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
|
||||
def test_a_popup_is_its_inner_size_plus_the_declared_frame(firefox_binary):
|
||||
frame = frame_of_the_declaration()
|
||||
declared = (2 * frame.border, frame.popup_ui + frame.border)
|
||||
|
||||
def has_the_frame(reading):
|
||||
p = reading["popup"]
|
||||
return (p["ow"] - p["iw"], p["oh"] - p["ih"]) == declared
|
||||
|
||||
on = read_popup(firefox_binary, ready=has_the_frame)["popup"]
|
||||
assert (on["ow"] - on["iw"], on["oh"] - on["ih"]) == declared, (
|
||||
"the popup reads outer %dx%d for inner %dx%d: the frame is %r, the declaration is %r"
|
||||
% (on["ow"], on["oh"], on["iw"], on["ih"], (on["ow"] - on["iw"], on["oh"] - on["ih"]), declared))
|
||||
assert (on["sx"], on["sy"]) == (frame.popup_position, frame.popup_position), (
|
||||
"a popup that names no position reads screen %r, the declared default is %d" % ((on["sx"], on["sy"]),
|
||||
frame.popup_position))
|
||||
assert on["mx"] == pytest.approx(on["sx"] + frame.border, abs=0.01), (
|
||||
"mozInnerScreenX %r is not screenX %r plus the border %d" % (on["mx"], on["sx"], frame.border))
|
||||
assert on["my"] == pytest.approx(on["sy"] + frame.popup_ui, abs=0.01), (
|
||||
"mozInnerScreenY %r is not screenY %r plus the popup UI %d" % (on["my"], on["sy"], frame.popup_ui))
|
||||
|
||||
# The control: a launch declared with another frame reads that one, and none of the first declaration's relations.
|
||||
other_declared = frame_extra(OTHER_BORDER, OTHER_POPUP_UI)
|
||||
assert other_declared != declared
|
||||
|
||||
def has_the_other_frame(reading):
|
||||
p = reading["popup"]
|
||||
return (p["ow"] - p["iw"], p["oh"] - p["ih"]) == other_declared
|
||||
|
||||
other = read_popup(firefox_binary, extra_prefs=OTHER_FRAME, ready=has_the_other_frame)["popup"]
|
||||
assert (other["ow"] - other["iw"], other["oh"] - other["ih"]) == other_declared, (
|
||||
"declared with another frame the popup reads outer %dx%d for inner %dx%d: the frame is %r, the second declaration is %r"
|
||||
% (other["ow"], other["oh"], other["iw"], other["ih"], (other["ow"] - other["iw"], other["oh"] - other["ih"]), other_declared))
|
||||
assert (other["sx"], other["sy"]) == (OTHER_POSITION, OTHER_POSITION), (
|
||||
"declared with another default position the popup reads screen %r, the second declaration is %d" % ((other["sx"], other["sy"]), OTHER_POSITION))
|
||||
assert other["mx"] == pytest.approx(other["sx"] + OTHER_BORDER, abs=0.01)
|
||||
assert other["my"] == pytest.approx(other["sy"] + OTHER_POPUP_UI, abs=0.01)
|
||||
assert (other["ow"] - other["iw"], other["oh"] - other["ih"]) != (on["ow"] - on["iw"], on["oh"] - on["ih"]), (
|
||||
"the two declared frames read the same frame: the declaration decides nothing")
|
||||
assert (other["sx"], other["sy"]) != (on["sx"], on["sy"]) and other["my"] - other["sy"] != on["my"] - on["sy"], (
|
||||
"the two declared frames read the same position or content origin: %r vs %r" % (other, on))
|
||||
|
||||
|
||||
LEFT = 137
|
||||
|
||||
|
||||
def test_a_popup_naming_only_left_reads_that_x_and_the_declared_default_y(firefox_binary):
|
||||
frame = frame_of_the_declaration()
|
||||
features = "width=500,height=400,left=%d" % LEFT
|
||||
declared = (2 * frame.border, frame.popup_ui + frame.border)
|
||||
|
||||
def has_the_frame(reading):
|
||||
p = reading["popup"]
|
||||
return (p["ow"] - p["iw"], p["oh"] - p["ih"]) == declared
|
||||
|
||||
on = read_popup(firefox_binary, ready=has_the_frame, features=features)["popup"]
|
||||
assert (on["ow"] - on["iw"], on["oh"] - on["ih"]) == declared, (
|
||||
"the popup reads outer %dx%d for inner %dx%d: the frame is %r, the declaration is %r"
|
||||
% (on["ow"], on["oh"], on["iw"], on["ih"], (on["ow"] - on["iw"], on["oh"] - on["ih"]), declared))
|
||||
assert on["sx"] == LEFT, "a popup that names left=%d reads screenX %r: the page's own x is lost" % (LEFT, on["sx"])
|
||||
assert on["sy"] == frame.popup_position, (
|
||||
"a popup that names no top reads screenY %r, the declared default is %d" % (on["sy"], frame.popup_position))
|
||||
assert on["mx"] == pytest.approx(on["sx"] + frame.border, abs=0.01)
|
||||
assert on["my"] == pytest.approx(on["sy"] + frame.popup_ui, abs=0.01)
|
||||
|
||||
# The control: a launch declared with a second frame keeps the page's x and reads the second default for y.
|
||||
other_declared = frame_extra(OTHER_BORDER, OTHER_POPUP_UI)
|
||||
|
||||
def has_the_other_frame(reading):
|
||||
p = reading["popup"]
|
||||
return (p["ow"] - p["iw"], p["oh"] - p["ih"]) == other_declared
|
||||
|
||||
other = read_popup(firefox_binary, extra_prefs=OTHER_FRAME, ready=has_the_other_frame, features=features)["popup"]
|
||||
assert (other["ow"] - other["iw"], other["oh"] - other["ih"]) == other_declared
|
||||
assert other["sx"] == LEFT, "declared with another frame the popup reads screenX %r, the page asked for %d" % (other["sx"], LEFT)
|
||||
assert other["sy"] == OTHER_POSITION, (
|
||||
"declared with another default position the popup reads screenY %r, the second declaration is %d" % (other["sy"], OTHER_POSITION))
|
||||
assert other["mx"] == pytest.approx(LEFT + OTHER_BORDER, abs=0.01)
|
||||
assert other["my"] == pytest.approx(OTHER_POSITION + OTHER_POPUP_UI, abs=0.01)
|
||||
assert other["sy"] != on["sy"] and other["sx"] == on["sx"], (
|
||||
"the declaration decides y alone when the page names x: %r vs %r" % (other, on))
|
||||
Reference in new issue
Block a user