Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11db0d50b5 |
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))
|
||||
@@ -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))
|
||||
@@ -0,0 +1,361 @@
|
||||
"""A WebGL context tells the page what the session DECLARES, never what the host's GL says.
|
||||
|
||||
Characterises, on the published engine (firefox-68), the hooks of the series folder
|
||||
``fingerprint/webgl/parameters`` in ``dom/canvas`` (``StealthWebGLParams.cpp`` and the hooks in
|
||||
``ClientWebGLContext.cpp``, ``WebGLContextValidate.cpp``): the numeric ``getParameter`` answers
|
||||
(``zoom.stealth.webgl.int_params`` / ``int2_params`` / ``float_params``), the renderer and the
|
||||
vendor strings (``zoom.stealth.webgl.renderer`` / ``vendor``), ``getShaderPrecisionFormat``
|
||||
(``zoom.stealth.webgl.shader_precisions``), the extension list the page reads
|
||||
(``zoom.stealth.webgl.extensions`` / ``zoom.stealth.webgl2.extensions``) and the stencil masks a
|
||||
fresh context starts with. A page reads every one of them with a handful of lines, and they are
|
||||
the biggest part of a WebGL fingerprint, so a value that came from the host's GPU or driver (a
|
||||
Mesa llvmpipe on a Linux runner, a WARP adapter on a Windows one) is a value that tells the
|
||||
machine apart from the Windows the session claims to be.
|
||||
|
||||
Each test declares a value no runner has (a ``MAX_TEXTURE_SIZE`` of 12345, a precision of
|
||||
7:11:13, a Radeon HD 5850, an extension list in a deliberately wrong order) and reads it back
|
||||
where a page reads it. The negative control is in the same test: the same page, the same
|
||||
engine, with the declaration of that value empty, reads the host's own answer, and the test
|
||||
asserts the two DIFFER, so it fails if the declaration is not what the page reads.
|
||||
|
||||
The renderer and the vendor have no empty control: an engine that is on refuses to start
|
||||
without them (the declaration gate), and an engine that is off draws on the host's GL, which a
|
||||
runner without a GPU may not give at all. The control there is the session's own persona (the
|
||||
product default), which the page must NOT read once the declaration says otherwise.
|
||||
|
||||
The stencil masks have no pref at all: the engine starts them at all ones, as ANGLE does, where
|
||||
the driver's own start is the stencil bits (Mesa: 255). The control is the same read after the
|
||||
page writes 255 itself, which proves the read is live and that 255 is what the masks were
|
||||
before the engine.
|
||||
|
||||
The test reads the engine through ``extra_prefs`` (applied last by the core), RFP stays off.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
SEED = 4246
|
||||
|
||||
#: gl.INVALID_ENUM
|
||||
INVALID_ENUM = 1280
|
||||
|
||||
# -- numeric parameters ----------------------------------------------------------------------
|
||||
|
||||
#: A value no runner has for each (the host's are 16384 / 2048 / 32767 on a GL or ANGLE).
|
||||
DECLARED_INT = "3379|12345,34024|23456,34076|9001,32883|4321,35071|777"
|
||||
DECLARED_INT2 = "3386|12345:23456"
|
||||
DECLARED_FLOAT = "33901|1:7777,33902|3:5"
|
||||
EMPTY_NUMERIC = {
|
||||
"zoom.stealth.webgl.int_params": "",
|
||||
"zoom.stealth.webgl.int2_params": "",
|
||||
"zoom.stealth.webgl.float_params": "",
|
||||
}
|
||||
DECLARED_NUMERIC = {
|
||||
"zoom.stealth.webgl.int_params": DECLARED_INT,
|
||||
"zoom.stealth.webgl.int2_params": DECLARED_INT2,
|
||||
"zoom.stealth.webgl.float_params": DECLARED_FLOAT,
|
||||
}
|
||||
|
||||
NUMERIC_JS = """() => {
|
||||
const NAMES = {
|
||||
MAX_TEXTURE_SIZE: 0x0D33, MAX_RENDERBUFFER_SIZE: 0x84E8, MAX_CUBE_MAP_TEXTURE_SIZE: 0x851C,
|
||||
MAX_VIEWPORT_DIMS: 0x0D3A, ALIASED_POINT_SIZE_RANGE: 0x846D, ALIASED_LINE_WIDTH_RANGE: 0x846E,
|
||||
MAX_3D_TEXTURE_SIZE: 0x8073, MAX_ARRAY_TEXTURE_LAYERS: 0x88FF,
|
||||
};
|
||||
const out = {};
|
||||
for (const kind of ["webgl", "webgl2"]) {
|
||||
const gl = document.createElement("canvas").getContext(kind);
|
||||
if (!gl) { out[kind] = null; continue; }
|
||||
gl.getError();
|
||||
const r = {};
|
||||
for (const [name, pname] of Object.entries(NAMES)) {
|
||||
const v = gl.getParameter(pname);
|
||||
const error = gl.getError();
|
||||
const view = v !== null && ArrayBuffer.isView(v);
|
||||
r[name] = {value: view ? Array.from(v) : v,
|
||||
type: v === null ? "null" : (view ? v.constructor.name : typeof v), error};
|
||||
}
|
||||
out[kind] = r;
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
# -- renderer and vendor ---------------------------------------------------------------------
|
||||
|
||||
#: A device no runner has. ``SanitizeRenderer`` keeps the device of this Direct3D string as it
|
||||
#: is (a "Radeon HD 5850" is its own bucket) and rewrites what comes after the suffix, so the
|
||||
#: page reads this prefix whether the string is sanitized or not.
|
||||
RENDERER = "ANGLE (AMD, Radeon HD 5850 Direct3D11 vs_5_0 ps_5_0, D3D11)"
|
||||
RENDERER_READ_PREFIX = "ANGLE (AMD, Radeon HD 5850 Direct3D11 vs_5_0 ps_5_0"
|
||||
VENDOR = "Google Inc. (AMD)"
|
||||
|
||||
RENDERER_JS = """() => {
|
||||
const out = {};
|
||||
for (const kind of ["webgl", "webgl2"]) {
|
||||
const gl = document.createElement("canvas").getContext(kind);
|
||||
if (!gl) { out[kind] = null; continue; }
|
||||
gl.getError();
|
||||
// UNMASKED_RENDERER_WEBGL before the extension is enabled: Mozilla's own error.
|
||||
const before = gl.getParameter(0x9246);
|
||||
const before_error = gl.getError();
|
||||
const ext = gl.getExtension("WEBGL_debug_renderer_info");
|
||||
out[kind] = {
|
||||
renderer: gl.getParameter(gl.RENDERER),
|
||||
vendor: gl.getParameter(gl.VENDOR),
|
||||
unmasked_before_extension: before,
|
||||
unmasked_before_extension_error: before_error,
|
||||
has_extension: !!ext,
|
||||
unmasked_renderer: ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL) : null,
|
||||
unmasked_vendor: ext ? gl.getParameter(ext.UNMASKED_VENDOR_WEBGL) : null,
|
||||
error: gl.getError(),
|
||||
};
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
# -- shader precision ------------------------------------------------------------------------
|
||||
|
||||
#: VERTEX_SHADER*LOW_FLOAT -> 7:11:13 and FRAGMENT_SHADER*HIGH_INT -> 3:5:2. No GPU has either.
|
||||
DECLARED_PRECISION = "35633*36336|7:11:13,35632*36341|3:5:2"
|
||||
|
||||
PRECISION_JS = """() => {
|
||||
const out = {};
|
||||
for (const kind of ["webgl", "webgl2"]) {
|
||||
const gl = document.createElement("canvas").getContext(kind);
|
||||
if (!gl) { out[kind] = null; continue; }
|
||||
gl.getError();
|
||||
const read = (shader, precision) => {
|
||||
const f = gl.getShaderPrecisionFormat(shader, precision);
|
||||
const error = gl.getError();
|
||||
return {format: f === null ? null : [f.rangeMin, f.rangeMax, f.precision], error};
|
||||
};
|
||||
out[kind] = {
|
||||
vertex_low_float: read(gl.VERTEX_SHADER, gl.LOW_FLOAT),
|
||||
fragment_high_int: read(gl.FRAGMENT_SHADER, gl.HIGH_INT),
|
||||
vertex_high_float: read(gl.VERTEX_SHADER, gl.HIGH_FLOAT),
|
||||
bad_precision_type: read(gl.VERTEX_SHADER, 0x1234),
|
||||
bad_shader_type: read(gl.TEXTURE_2D, gl.LOW_FLOAT),
|
||||
};
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
# -- extension list --------------------------------------------------------------------------
|
||||
|
||||
#: ``WebGLExtensionID`` of ``dom/canvas/WebGLTypes.h``, in declaration order (``MOZ_debug`` is
|
||||
#: never listed to a page): the one order a page ever reads, the retail one.
|
||||
ENUM_ORDER = [
|
||||
"ANGLE_instanced_arrays", "EXT_blend_minmax", "EXT_clip_control", "EXT_color_buffer_float",
|
||||
"EXT_color_buffer_half_float", "EXT_depth_clamp", "EXT_disjoint_timer_query", "EXT_float_blend",
|
||||
"EXT_frag_depth", "EXT_polygon_offset_clamp", "EXT_shader_texture_lod", "EXT_sRGB",
|
||||
"EXT_texture_compression_bptc", "EXT_texture_compression_rgtc",
|
||||
"EXT_texture_filter_anisotropic", "EXT_texture_mirror_clamp_to_edge", "EXT_texture_norm16",
|
||||
"OES_draw_buffers_indexed", "OES_element_index_uint", "OES_fbo_render_mipmap",
|
||||
"OES_standard_derivatives", "OES_texture_float", "OES_texture_float_linear",
|
||||
"OES_texture_half_float", "OES_texture_half_float_linear", "OES_vertex_array_object",
|
||||
"OVR_multiview2", "WEBGL_color_buffer_float", "WEBGL_compressed_texture_astc",
|
||||
"WEBGL_compressed_texture_etc", "WEBGL_compressed_texture_etc1",
|
||||
"WEBGL_compressed_texture_pvrtc", "WEBGL_compressed_texture_s3tc",
|
||||
"WEBGL_compressed_texture_s3tc_srgb", "WEBGL_debug_renderer_info", "WEBGL_debug_shaders",
|
||||
"WEBGL_depth_texture", "WEBGL_draw_buffers", "WEBGL_explicit_present", "WEBGL_lose_context",
|
||||
"WEBGL_provoking_vertex",
|
||||
]
|
||||
|
||||
#: Declared in an order that is NOT the enum's: the page must read them in the enum's.
|
||||
DECLARED_EXTENSIONS_1 = ["WEBGL_lose_context", "OES_texture_float", "EXT_blend_minmax",
|
||||
"OES_vertex_array_object", "ANGLE_instanced_arrays"]
|
||||
DECLARED_EXTENSIONS_2 = ["WEBGL_lose_context", "EXT_texture_filter_anisotropic",
|
||||
"EXT_color_buffer_float", "OES_texture_float_linear"]
|
||||
|
||||
EXTENSIONS_JS = """() => {
|
||||
const out = {};
|
||||
for (const kind of ["webgl", "webgl2"]) {
|
||||
const gl = document.createElement("canvas").getContext(kind);
|
||||
if (!gl) { out[kind] = null; continue; }
|
||||
out[kind] = {list: gl.getSupportedExtensions(),
|
||||
depth_texture: gl.getExtension("WEBGL_depth_texture") === null ? null : "object"};
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
# -- stencil masks ---------------------------------------------------------------------------
|
||||
|
||||
STENCIL_JS = """() => {
|
||||
const PNAMES = {STENCIL_VALUE_MASK: 0x0B93, STENCIL_WRITEMASK: 0x0B98,
|
||||
STENCIL_BACK_VALUE_MASK: 0x8CA4, STENCIL_BACK_WRITEMASK: 0x8CA5};
|
||||
const read = gl => {
|
||||
const r = {};
|
||||
for (const [name, pname] of Object.entries(PNAMES)) r[name] = gl.getParameter(pname);
|
||||
return r;
|
||||
};
|
||||
const out = {};
|
||||
for (const kind of ["webgl", "webgl2"]) {
|
||||
for (const stencil of [false, true]) {
|
||||
const key = kind + (stencil ? "+stencil" : "");
|
||||
const gl = document.createElement("canvas").getContext(kind, {stencil});
|
||||
if (!gl) { out[key] = null; continue; }
|
||||
const fresh = read(gl);
|
||||
// The control: the page writes 255 itself and reads it back.
|
||||
gl.stencilMask(255);
|
||||
gl.stencilMaskSeparate(gl.BACK, 255);
|
||||
gl.stencilFunc(gl.ALWAYS, 0, 255);
|
||||
gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 0, 255);
|
||||
out[key] = {fresh, written: read(gl)};
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
|
||||
def _read(firefox_binary, prefs, js):
|
||||
"""One short-lived product session with ``prefs`` overlaid, and what the page answers to ``js``."""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with InvisiblePlaywright(seed=SEED, binary_path=firefox_binary, headless=True,
|
||||
extra_prefs=dict(prefs)) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto("about:blank")
|
||||
return page.evaluate(js)
|
||||
|
||||
|
||||
def _contexts(got, label):
|
||||
for kind in ("webgl", "webgl2"):
|
||||
assert got[kind] is not None, "%s: no %s context at all" % (label, kind)
|
||||
|
||||
|
||||
def test_declared_numeric_parameters_replace_the_hosts_and_webgl2_only_names_stay_null_on_webgl1(
|
||||
firefox_binary):
|
||||
declared = _read(firefox_binary, DECLARED_NUMERIC, NUMERIC_JS)
|
||||
control = _read(firefox_binary, EMPTY_NUMERIC, NUMERIC_JS)
|
||||
_contexts(declared, "declared")
|
||||
_contexts(control, "control")
|
||||
|
||||
want = {
|
||||
"MAX_TEXTURE_SIZE": (12345, "number"),
|
||||
"MAX_RENDERBUFFER_SIZE": (23456, "number"),
|
||||
"MAX_CUBE_MAP_TEXTURE_SIZE": (9001, "number"),
|
||||
"MAX_VIEWPORT_DIMS": ([12345, 23456], "Int32Array"),
|
||||
"ALIASED_POINT_SIZE_RANGE": ([1, 7777], "Float32Array"),
|
||||
"ALIASED_LINE_WIDTH_RANGE": ([3, 5], "Float32Array"),
|
||||
}
|
||||
want_webgl2_only = {"MAX_3D_TEXTURE_SIZE": 4321, "MAX_ARRAY_TEXTURE_LAYERS": 777}
|
||||
|
||||
for kind in ("webgl", "webgl2"):
|
||||
for name, (value, type_) in want.items():
|
||||
got = declared[kind][name]
|
||||
assert got == {"value": value, "type": type_, "error": 0}, (kind, name, got)
|
||||
# The control: the same page with the declaration empty reads the host's answer.
|
||||
assert control[kind][name]["value"] != value, (
|
||||
"%s %s: the host's own answer is the declared one, so this test cannot tell "
|
||||
"the declaration from the host: %r" % (kind, name, control[kind][name]))
|
||||
assert control[kind][name]["error"] == 0, (kind, name, control[kind][name])
|
||||
|
||||
# WebGL 2 only: the declared number is read on a WebGL 2 context ...
|
||||
for name, value in want_webgl2_only.items():
|
||||
got = declared["webgl2"][name]
|
||||
assert got == {"value": value, "type": "number", "error": 0}, (name, got)
|
||||
assert control["webgl2"][name]["value"] != value, (name, control["webgl2"][name])
|
||||
# ... and on a WebGL 1 context the name does not exist: null and INVALID_ENUM, declared
|
||||
# or not (the declaration cannot make a name appear that the context does not have).
|
||||
for label, run in (("declared", declared), ("control", control)):
|
||||
got = run["webgl"][name]
|
||||
assert got == {"value": None, "type": "null", "error": INVALID_ENUM}, (
|
||||
label, name, got)
|
||||
|
||||
|
||||
def test_declared_renderer_and_vendor_are_read_in_every_form(firefox_binary):
|
||||
declared = _read(firefox_binary, {"zoom.stealth.webgl.renderer": RENDERER,
|
||||
"zoom.stealth.webgl.vendor": VENDOR}, RENDERER_JS)
|
||||
# The control: the session's own persona, the product default (the declaration gate refuses
|
||||
# an empty pair on a running engine).
|
||||
control = _read(firefox_binary, {}, RENDERER_JS)
|
||||
_contexts(declared, "declared")
|
||||
_contexts(control, "control")
|
||||
|
||||
for kind in ("webgl", "webgl2"):
|
||||
got = declared[kind]
|
||||
# Every form of the renderer: the masked constant, and the unmasked one through the
|
||||
# extension the page enables.
|
||||
assert got["renderer"].startswith(RENDERER_READ_PREFIX), (kind, got)
|
||||
assert got["has_extension"], (kind, got)
|
||||
assert got["unmasked_renderer"].startswith(RENDERER_READ_PREFIX), (kind, got)
|
||||
assert got["unmasked_vendor"] == VENDOR, (kind, got)
|
||||
# The masked vendor is Firefox's own constant, whatever is declared.
|
||||
assert got["vendor"] == "Mozilla", (kind, got)
|
||||
# Without the extension the unmasked constants are not a thing: Mozilla's error.
|
||||
assert got["unmasked_before_extension"] is None, (kind, got)
|
||||
assert got["unmasked_before_extension_error"] == INVALID_ENUM, (kind, got)
|
||||
assert got["error"] == 0, (kind, got)
|
||||
|
||||
base = control[kind]
|
||||
assert base["has_extension"], (kind, base)
|
||||
assert not base["renderer"].startswith(RENDERER_READ_PREFIX), (kind, base)
|
||||
assert not base["unmasked_renderer"].startswith(RENDERER_READ_PREFIX), (kind, base)
|
||||
assert base["unmasked_vendor"] != VENDOR, (kind, base)
|
||||
assert base["vendor"] == "Mozilla", (kind, base)
|
||||
assert base["unmasked_before_extension"] is None, (kind, base)
|
||||
assert base["unmasked_before_extension_error"] == INVALID_ENUM, (kind, base)
|
||||
|
||||
|
||||
def test_declared_shader_precision_replaces_the_hosts_and_a_bad_pair_still_errors(
|
||||
firefox_binary):
|
||||
declared = _read(firefox_binary,
|
||||
{"zoom.stealth.webgl.shader_precisions": DECLARED_PRECISION}, PRECISION_JS)
|
||||
control = _read(firefox_binary, {"zoom.stealth.webgl.shader_precisions": ""}, PRECISION_JS)
|
||||
_contexts(declared, "declared")
|
||||
_contexts(control, "control")
|
||||
|
||||
for kind in ("webgl", "webgl2"):
|
||||
got, base = declared[kind], control[kind]
|
||||
assert got["vertex_low_float"] == {"format": [7, 11, 13], "error": 0}, (kind, got)
|
||||
assert got["fragment_high_int"] == {"format": [3, 5, 2], "error": 0}, (kind, got)
|
||||
# The control: with the declaration empty the page reads the host's formats.
|
||||
assert base["vertex_low_float"]["format"] not in (None, [7, 11, 13]), (kind, base)
|
||||
assert base["fragment_high_int"]["format"] not in (None, [3, 5, 2]), (kind, base)
|
||||
assert base["vertex_low_float"]["error"] == 0, (kind, base)
|
||||
# A pair nothing declares is the host's, untouched by the declarations next to it.
|
||||
assert got["vertex_high_float"] == base["vertex_high_float"], (kind, got, base)
|
||||
assert got["vertex_high_float"]["format"] is not None, (kind, got)
|
||||
# A bad pair is Mozilla's error with or without a declaration in the pref.
|
||||
for name in ("bad_precision_type", "bad_shader_type"):
|
||||
for label, run in (("declared", got), ("control", base)):
|
||||
assert run[name] == {"format": None, "error": INVALID_ENUM}, (kind, label, name, run)
|
||||
|
||||
|
||||
def test_the_declared_extension_list_is_read_in_firefoxs_order(firefox_binary):
|
||||
declared = _read(firefox_binary, {
|
||||
"zoom.stealth.webgl.extensions": ",".join(DECLARED_EXTENSIONS_1),
|
||||
"zoom.stealth.webgl2.extensions": ",".join(DECLARED_EXTENSIONS_2),
|
||||
}, EXTENSIONS_JS)
|
||||
control = _read(firefox_binary, {"zoom.stealth.webgl.extensions": "",
|
||||
"zoom.stealth.webgl2.extensions": ""}, EXTENSIONS_JS)
|
||||
_contexts(declared, "declared")
|
||||
_contexts(control, "control")
|
||||
|
||||
for kind, names in (("webgl", DECLARED_EXTENSIONS_1), ("webgl2", DECLARED_EXTENSIONS_2)):
|
||||
assert names != sorted(names, key=ENUM_ORDER.index), "the declared order must be wrong"
|
||||
want = [e for e in ENUM_ORDER if e in names]
|
||||
assert declared[kind]["list"] == want, (kind, declared[kind]["list"])
|
||||
# The control: with the declaration empty the page reads the host's own list.
|
||||
assert control[kind]["list"] != want, (kind, control[kind]["list"])
|
||||
assert control[kind]["list"], (kind, "the host list is empty")
|
||||
# Only what is declared is served: the host has WEBGL_depth_texture, the declaration lacks it.
|
||||
assert declared["webgl"]["depth_texture"] is None, declared["webgl"]
|
||||
|
||||
|
||||
def test_the_stencil_masks_start_at_all_ones(firefox_binary):
|
||||
got = _read(firefox_binary, {}, STENCIL_JS)
|
||||
all_ones = 4294967295
|
||||
names = ("STENCIL_VALUE_MASK", "STENCIL_WRITEMASK",
|
||||
"STENCIL_BACK_VALUE_MASK", "STENCIL_BACK_WRITEMASK")
|
||||
for key in ("webgl", "webgl+stencil", "webgl2", "webgl2+stencil"):
|
||||
run = got[key]
|
||||
assert run is not None, "%s: no context at all" % key
|
||||
# A fresh context, on any OS: all ones, as ANGLE starts them.
|
||||
assert run["fresh"] == {n: all_ones for n in names}, (key, run["fresh"])
|
||||
# The control: what the masks were before the engine on a driver GL is the stencil
|
||||
# bits (255 on Mesa), and a page that writes 255 reads 255 back, so the read is live and
|
||||
# all ones is not a constant of the page's reading.
|
||||
assert run["written"] == {n: 255 for n in names}, (key, run["written"])
|
||||
@@ -0,0 +1,106 @@
|
||||
"""``getTranslatedShaderSource`` answers in the DECLARED shader language, not the host's.
|
||||
|
||||
Characterises, on the published engine (firefox-68), the hooks of the series folder
|
||||
``fingerprint/webgl/shader-language`` in ``dom/canvas`` (``StealthWebGLShaderLanguage.cpp``;
|
||||
hooks in ``WebGLShader.cpp``, ``WebGLShaderValidator.cpp``, ``WebGLContext.cpp``): with
|
||||
``zoom.stealth.webgl.shader_output_language`` set to ``essl`` the page that asks
|
||||
``WEBGL_debug_shaders`` for the translated source of a shader reads ANGLE's translation to ESSL,
|
||||
the language a Windows Firefox (ANGLE, a GLES context) always answers in; the driver keeps
|
||||
receiving its own.
|
||||
|
||||
Why a page reads it: the session declares a Windows ANGLE renderer, and on a host whose GL
|
||||
context is not GLES (Linux through GLX) the same translator emits desktop GLSL, so the page
|
||||
would read ``#version 450`` from a browser whose RENDERER says ANGLE: a contradiction inside
|
||||
one page, with no need to know the OS.
|
||||
|
||||
The negative control is in the same test: the same engine, the same shaders, with the
|
||||
declaration empty. It is adapted to the OS, as the engine is. On Linux the host's language is
|
||||
desktop GLSL, so the declared and the undeclared sources DIFFER (the WebGL 2 shaders lose their
|
||||
``#version 300 es`` line). On Windows the context already goes through ANGLE and is already
|
||||
ESSL, so the two are EQUAL (and the declared one is the Windows one). On both, the driver still
|
||||
compiles and links the shader: the page sees one language, the pixels do not move.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
SEED = 4246
|
||||
|
||||
TRANSLATE_JS = """() => {
|
||||
const VS1 = 'attribute vec2 p; void main(){ gl_Position = vec4(p, 0.0, 1.0); }';
|
||||
const FS1 = 'precision mediump float; void main(){ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }';
|
||||
const VS2 = '#version 300 es\\nin vec2 p;\\nvoid main(){ gl_Position = vec4(p, 0.0, 1.0); }';
|
||||
const FS2 = '#version 300 es\\nprecision mediump float;\\nout vec4 o;\\n'
|
||||
+ 'void main(){ o = vec4(1.0, 0.0, 0.0, 1.0); }';
|
||||
const out = {};
|
||||
for (const [kind, vs, fs] of [["webgl", VS1, FS1], ["webgl2", VS2, FS2]]) {
|
||||
const gl = document.createElement("canvas").getContext(kind);
|
||||
if (!gl) { out[kind] = null; continue; }
|
||||
const dbg = gl.getExtension("WEBGL_debug_shaders");
|
||||
const v = gl.createShader(gl.VERTEX_SHADER); gl.shaderSource(v, vs); gl.compileShader(v);
|
||||
const f = gl.createShader(gl.FRAGMENT_SHADER); gl.shaderSource(f, fs); gl.compileShader(f);
|
||||
const prog = gl.createProgram(); gl.attachShader(prog, v); gl.attachShader(prog, f);
|
||||
gl.linkProgram(prog);
|
||||
out[kind] = {
|
||||
has_extension: !!dbg,
|
||||
vertex: dbg ? dbg.getTranslatedShaderSource(v) : null,
|
||||
fragment: dbg ? dbg.getTranslatedShaderSource(f) : null,
|
||||
compiled: gl.getShaderParameter(v, gl.COMPILE_STATUS) && gl.getShaderParameter(f, gl.COMPILE_STATUS),
|
||||
linked: gl.getProgramParameter(prog, gl.LINK_STATUS),
|
||||
};
|
||||
}
|
||||
return out;
|
||||
}"""
|
||||
|
||||
|
||||
def _read(firefox_binary, language):
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
with InvisiblePlaywright(
|
||||
seed=SEED, binary_path=firefox_binary, headless=True,
|
||||
extra_prefs={"zoom.stealth.webgl.shader_output_language": language}) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto("about:blank")
|
||||
return page.evaluate(TRANSLATE_JS)
|
||||
|
||||
|
||||
def test_get_translated_shader_source_is_in_the_declared_language_and_the_driver_still_compiles(
|
||||
firefox_binary):
|
||||
declared = _read(firefox_binary, "essl")
|
||||
control = _read(firefox_binary, "")
|
||||
|
||||
for kind in ("webgl", "webgl2"):
|
||||
for label, run in (("declared", declared), ("control", control)):
|
||||
got = run[kind]
|
||||
assert got is not None, "%s: no %s context at all" % (label, kind)
|
||||
assert got["has_extension"], (label, kind)
|
||||
# The driver is not touched by what the page is shown: it compiles and links.
|
||||
assert got["compiled"] is True and got["linked"] is True, (label, kind, got)
|
||||
assert got["vertex"] and got["fragment"], (label, kind, got)
|
||||
|
||||
# Declared: ESSL, on every OS. A WebGL 1 shader has no #version line in ESSL 1.00 and a
|
||||
# WebGL 2 one keeps its "#version 300 es".
|
||||
assert "#version" not in declared["webgl"]["vertex"], declared["webgl"]
|
||||
assert "#version" not in declared["webgl"]["fragment"], declared["webgl"]
|
||||
assert declared["webgl2"]["vertex"].lstrip().startswith("#version 300 es"), declared["webgl2"]
|
||||
assert declared["webgl2"]["fragment"].lstrip().startswith("#version 300 es"), declared["webgl2"]
|
||||
|
||||
if sys.platform.startswith("linux"):
|
||||
# The host's context is desktop GL: without the declaration the page reads desktop GLSL.
|
||||
# The declaration is what makes the two differ (as a pair of stages: a one-line vertex
|
||||
# shader may translate to the same text in both languages).
|
||||
for kind in ("webgl", "webgl2"):
|
||||
assert (control[kind]["vertex"], control[kind]["fragment"]) != (
|
||||
declared[kind]["vertex"], declared[kind]["fragment"]), (kind, control[kind])
|
||||
assert not control["webgl2"]["vertex"].lstrip().startswith("#version 300 es"), control["webgl2"]
|
||||
assert not control["webgl2"]["fragment"].lstrip().startswith("#version 300 es"), control["webgl2"]
|
||||
else:
|
||||
# Windows (ANGLE, a GLES context): the host's language is already ESSL, nothing to
|
||||
# translate twice, and the declaration changes nothing.
|
||||
for kind in ("webgl", "webgl2"):
|
||||
for stage in ("vertex", "fragment"):
|
||||
assert control[kind][stage] == declared[kind][stage], (kind, stage, control[kind])
|
||||
Reference in new issue
Block a user