Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b9858570a | ||
|
|
a9ec63caed | ||
|
|
20af8c4509 |
No files matched your search
@@ -0,0 +1,99 @@
|
||||
"""What the window e2e tests share: a headed session of the product, and a wait on a condition of a page.
|
||||
|
||||
The sessions are HEADED on purpose. ``headless=True`` gives every session a display of its own (a fresh Xvfb on Linux, a fresh Win32 desktop on
|
||||
Windows), so two of them never see each other; the focus and occlusion tests need two windows on ONE display, which is what two headed sessions of the
|
||||
same run have (the Linux e2e runs under ``xvfb-run``). Both sessions use the same seed, so both windows are the same declared window and the second one
|
||||
covers the first completely.
|
||||
|
||||
The first session is the one of the test's own thread; the second one lives in a thread of its own (``in_a_thread_of_its_own``, the pattern of
|
||||
``test_popups_reach_the_client_e2e.py``): an open sync client keeps its asyncio loop marked as running in the thread that started it, and a second sync client
|
||||
refuses to start there ("It looks like you are using Playwright Sync API inside the asyncio loop"). A sync client's objects belong to the thread that made
|
||||
them, so everything the test does with the second session is handed to that thread (``run``).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import queue
|
||||
import threading
|
||||
from typing import Any, Callable, Dict, Iterator, Optional
|
||||
|
||||
from _waits import Watch, watch
|
||||
|
||||
#: The seed only has to give two sessions the same window.
|
||||
SEED = 21
|
||||
|
||||
#: The deadline of a wait for something that must happen, in seconds.
|
||||
DEADLINE_S = 30
|
||||
|
||||
|
||||
def launch(firefox_binary: str, *, extra_prefs: Optional[Dict[str, Any]] = None, pin: Optional[Dict[str, Any]] = None, headless: bool = False):
|
||||
"""A session of the product (RFP off, the engine declared as the core launches it); ``extra_prefs`` and ``pin`` only where a test needs them."""
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
return InvisiblePlaywright(seed=SEED, binary_path=firefox_binary, headless=headless, locale="en-US", timezone="America/New_York",
|
||||
extra_prefs=extra_prefs, pin=pin)
|
||||
|
||||
|
||||
def wait_for_condition(page, sample: Callable[[], Any], done: Callable[[Any], Any], what: str, seconds: float = DEADLINE_S) -> Watch:
|
||||
"""Until ``done(sample())``, reading the page between two looks. Red after ``seconds`` with what was seen on the way."""
|
||||
result = watch(sample, done, seconds, lambda: page.wait_for_timeout(100))
|
||||
assert result.ok, "%s; seen: %s" % (what, result.render())
|
||||
return result
|
||||
|
||||
|
||||
class SecondSession:
|
||||
"""A session that lives in a thread of its own: ``run(fn)`` calls ``fn(session)`` in that thread and gives back its result or raises its error."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._jobs: "queue.Queue[Optional[tuple]]" = queue.Queue()
|
||||
|
||||
def run(self, fn: Callable[[Any], Any]) -> Any:
|
||||
box: Dict[str, Any] = {}
|
||||
done = threading.Event()
|
||||
self._jobs.put((fn, box, done))
|
||||
assert done.wait(300), "the second session did not answer within 300 s"
|
||||
if "error" in box:
|
||||
raise box["error"]
|
||||
return box.get("value")
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def in_a_thread_of_its_own(firefox_binary: str, *, extra_prefs: Optional[Dict[str, Any]] = None) -> Iterator[SecondSession]:
|
||||
"""A second headed session on the same display, started and closed in a thread with no asyncio loop; the test keeps the first one in its own thread."""
|
||||
handle = SecondSession()
|
||||
up = threading.Event()
|
||||
failure: Dict[str, BaseException] = {}
|
||||
|
||||
def serve() -> None:
|
||||
try:
|
||||
with launch(firefox_binary, extra_prefs=extra_prefs) as session:
|
||||
up.set()
|
||||
while True:
|
||||
job = handle._jobs.get()
|
||||
if job is None:
|
||||
return
|
||||
fn, box, done = job
|
||||
try:
|
||||
box["value"] = fn(session)
|
||||
except BaseException as exc: # handed back to the test's thread by ``run``
|
||||
box["error"] = exc
|
||||
finally:
|
||||
done.set()
|
||||
except BaseException as exc: # the launch or the close of the session
|
||||
failure["error"] = exc
|
||||
finally:
|
||||
up.set()
|
||||
|
||||
worker = threading.Thread(target=serve, name="second-session", daemon=True)
|
||||
worker.start()
|
||||
assert up.wait(300), "the second session did not start within 300 s"
|
||||
if "error" in failure:
|
||||
raise failure["error"]
|
||||
try:
|
||||
yield handle
|
||||
finally:
|
||||
handle._jobs.put(None)
|
||||
worker.join(120)
|
||||
assert not worker.is_alive(), "the second session did not close within 120 s"
|
||||
if "error" in failure:
|
||||
raise failure["error"]
|
||||
@@ -0,0 +1,81 @@
|
||||
"""A page keeps the focus when another session takes the display, and loses it only to its own session.
|
||||
|
||||
What it fixes: with ``zoom.stealth.focus.ignore_os_deactivation`` (the core declares it true, one value for every session) the window does not give up its
|
||||
activation when the SYSTEM takes it: another application, or another session's window on the same display. A page reads ``document.hasFocus()`` and the
|
||||
``blur`` event; without the pref a second visible session made the first one read ``hasFocus()`` false (4 times in 4 on one display) while nothing in its own
|
||||
session had moved. When the session opens a window of its own the window it replaces is lowered with the blur any Firefox gives.
|
||||
|
||||
The hooks: ``AppWindow::WindowDeactivated`` (the early return) and ``AppWindow::WindowActivated`` (``StealthLowerActiveWindow``, which lowers the active window
|
||||
with its own action id before Mozilla's raise) in ``xpfe/appshell/AppWindow.cpp`` of the series, folder ``fingerprint/screen-window/focus``.
|
||||
|
||||
The steps: session A opens a page that records ``focus`` and ``blur``; session B, headed on the same display, opens a window and takes the focus. A's page
|
||||
still reads ``hasFocus()`` true and has recorded no ``blur``. Then A opens a second page of its own: the first page records its ``blur`` and reads
|
||||
``hasFocus()`` false, the new one reads it true.
|
||||
|
||||
The control, in the same test: ``extra_prefs={"zoom.stealth.focus.ignore_os_deactivation": False}``, the same steps up to B taking the display, and A's page
|
||||
reads ``hasFocus()`` false. It runs first, so a runner where the second session does not take the focus is red there and not a green that means nothing.
|
||||
Both sessions are headed on one display (the Linux e2e runs under ``xvfb-run``; Windows has the interactive desktop of the runner).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from _window_sessions import in_a_thread_of_its_own, launch, wait_for_condition
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
PREF = "zoom.stealth.focus.ignore_os_deactivation"
|
||||
|
||||
RECORD = """() => {
|
||||
window.__events = [];
|
||||
for (const type of ['focus', 'blur']) window.addEventListener(type, () => window.__events.push(type));
|
||||
return document.hasFocus();
|
||||
}"""
|
||||
HAS_FOCUS = "() => document.hasFocus()"
|
||||
EVENTS = "() => window.__events"
|
||||
TWO_FRAMES = "() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done)))"
|
||||
|
||||
|
||||
def takes_the_focus(b):
|
||||
"""Runs in the second session's own thread: opens a window and waits until its page has the focus."""
|
||||
taker = b.new_page()
|
||||
taker.goto("about:blank")
|
||||
wait_for_condition(taker, lambda: taker.evaluate(HAS_FOCUS), lambda focused: focused is True, "the second session's page never took the focus")
|
||||
|
||||
|
||||
def another_session_takes_the_display(firefox_binary, keeps, with_own_page=False):
|
||||
"""What A's page reads once B's window has the focus, and (``with_own_page``) once A has opened a page of its own."""
|
||||
extra = None if keeps else {PREF: False}
|
||||
with launch(firefox_binary, extra_prefs=extra) as a:
|
||||
first = a.new_page()
|
||||
first.goto("about:blank")
|
||||
first.evaluate(RECORD)
|
||||
wait_for_condition(first, lambda: first.evaluate(HAS_FOCUS), lambda focused: focused is True, "the page never had the focus of its own window")
|
||||
with in_a_thread_of_its_own(firefox_binary) as b:
|
||||
b.run(takes_the_focus)
|
||||
if keeps:
|
||||
first.evaluate(TWO_FRAMES)
|
||||
else:
|
||||
wait_for_condition(first, lambda: first.evaluate(HAS_FOCUS), lambda focused: focused is False,
|
||||
"the first page still has the focus although another session's window took it")
|
||||
seen = {"has_focus": first.evaluate(HAS_FOCUS), "events": first.evaluate(EVENTS)}
|
||||
if with_own_page:
|
||||
own = a.new_page()
|
||||
own.goto("about:blank")
|
||||
wait_for_condition(own, lambda: (own.evaluate(HAS_FOCUS), first.evaluate(EVENTS), first.evaluate(HAS_FOCUS)),
|
||||
lambda state: state[0] is True and state[1].count("blur") == 1 and state[2] is False,
|
||||
"a page of the session's own did not take the focus from the first with one blur")
|
||||
seen["after_own_page"] = (own.evaluate(HAS_FOCUS), first.evaluate(EVENTS), first.evaluate(HAS_FOCUS))
|
||||
return seen
|
||||
|
||||
|
||||
def test_a_page_keeps_focus_when_another_session_takes_the_display(firefox_binary):
|
||||
control = another_session_takes_the_display(firefox_binary, keeps=False)
|
||||
assert control["has_focus"] is False, "control: without the pref the first page still has the focus: %r" % control
|
||||
|
||||
kept = another_session_takes_the_display(firefox_binary, keeps=True, with_own_page=True)
|
||||
assert kept["has_focus"] is True, "with the pref the first page lost the focus to another session: %r" % kept
|
||||
assert "blur" not in kept["events"], "with the pref the first page recorded a blur when another session took the display: %r" % kept
|
||||
assert kept["has_focus"] != control["has_focus"]
|
||||
own_focused, events, first_focused = kept["after_own_page"]
|
||||
assert own_focused is True and events.count("blur") == 1 and first_focused is False, "a page of the session's own did not replace the first one with one blur: %r" % kept
|
||||
@@ -0,0 +1,112 @@
|
||||
"""Fullscreen is decided from the declared screen, with no window manager to answer it.
|
||||
|
||||
What it fixes: on an X display with no window manager (Xvfb, the way the engine runs on Linux servers) GTK's fullscreen is a request nobody answers, so
|
||||
Mozilla refuses it: the DOM goes fullscreen and the window does not (``display-mode: fullscreen`` false, ``innerHeight`` the work area). Retail Windows
|
||||
decides it itself and gives the screen. With the engine active the widget decides it too, from the screen the core declared: after ``requestFullscreen()``
|
||||
the page reads ``innerWidth x innerHeight`` equal to the declared screen and ``display-mode: fullscreen``.
|
||||
|
||||
The hook: ``nsWindow::MakeFullScreen`` in ``widget/gtk/nsWindow.cpp`` of the series, folder ``fingerprint/screen-window/occlusion`` (the marker names
|
||||
``fingerprint/screen-window/geometry``, whose function ``StealthMakeFullScreenWithoutWM`` in ``widget/gtk/StealthFullscreenGtk.cpp`` it calls). On Windows
|
||||
the same reading is held by ``nsIWidget::InfallibleMakeFullScreen`` and the Win32 rules of the same folder (``geometry``).
|
||||
|
||||
The screen is pinned to 1600x900, which no runner has (the Linux display is 1920x1080, the Windows runner's monitor 1024x768 or 1920x1080), so a window that
|
||||
filled the host would read differently from the declared one.
|
||||
|
||||
The control, in the same test: the engine inactive (``zoom.stealth.fpp.hw_seed`` 0: the engine is on when it is above 0) keeps Mozilla's behaviour. On
|
||||
Linux without a window manager that is the refusal (``display-mode: fullscreen`` false and the window not the declared screen); on Windows, which always has a
|
||||
window manager and a widget that decides fullscreen, it is the host's monitor, not the declared screen. The same click, the same pinned screen; only the engine
|
||||
differs.
|
||||
|
||||
The click is real input (``page.mouse``): ``requestFullscreen`` needs a user gesture. A page reads it from ``innerWidth``, ``innerHeight``,
|
||||
``matchMedia('(display-mode: fullscreen)')`` and ``document.fullscreenElement``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import http.server
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import pytest
|
||||
|
||||
from _servers import LocalServer
|
||||
from _window_sessions import launch, wait_for_condition
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
#: The device pixel ratio is pinned too: the core declares 1.5 for some personas (Windows runner), and a page reads the screen and the window in
|
||||
#: CSS pixels, declared / dpr (1067x600), which is not what this test is about.
|
||||
DECLARED = {"screen.width": 1600, "screen.height": 900, "screen.dpr": 1.0}
|
||||
|
||||
PAGE = (b"<!doctype html><html><head><meta charset=utf-8><title>fullscreen</title></head><body style=\"margin:0\">"
|
||||
b"<button id=go style=\"position:fixed;left:20px;top:20px;width:160px;height:40px;margin:0\">fullscreen</button>"
|
||||
b"<script>"
|
||||
b"window.__how = null; window.__error = null;"
|
||||
b"for (const t of ['fullscreenchange', 'fullscreenerror']) document.addEventListener(t, () => { window.__how = window.__how || t; });"
|
||||
b"document.getElementById('go').addEventListener('click', () => {"
|
||||
b" document.documentElement.requestFullscreen().catch(e => { window.__error = String(e); });"
|
||||
b"});"
|
||||
b"</script></body></html>")
|
||||
|
||||
GEOMETRY = """() => ({
|
||||
innerWidth, innerHeight,
|
||||
screen: [screen.width, screen.height],
|
||||
displayModeFullscreen: matchMedia('(display-mode: fullscreen)').matches,
|
||||
fullscreenElement: document.fullscreenElement !== null,
|
||||
})"""
|
||||
HOW = "() => [window.__how, window.__error]"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page_url():
|
||||
class Handler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(PAGE)))
|
||||
self.end_headers()
|
||||
self.wfile.write(PAGE)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
with LocalServer(("127.0.0.1", 0), Handler) as server:
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
try:
|
||||
yield "http://127.0.0.1:%d/" % server.server_address[1]
|
||||
finally:
|
||||
server.shutdown()
|
||||
|
||||
|
||||
def fullscreen_geometry(firefox_binary, page_url, engine_on):
|
||||
"""The page's geometry once the window has held still after a click on a button that asks for fullscreen."""
|
||||
extra = None if engine_on else {"zoom.stealth.fpp.hw_seed": 0}
|
||||
with launch(firefox_binary, extra_prefs=extra, pin=DECLARED, headless=True) as browser:
|
||||
page = browser.new_page()
|
||||
page.goto(page_url)
|
||||
page.mouse.move(90, 40)
|
||||
page.mouse.click(100, 40)
|
||||
wait_for_condition(page, lambda: page.evaluate(HOW), lambda how: how[0] is not None,
|
||||
"the click on a button that asks for fullscreen was followed by neither fullscreenchange nor fullscreenerror")
|
||||
seen = []
|
||||
|
||||
def held_still(geometry):
|
||||
seen.append(geometry)
|
||||
return len(seen) >= 4 and all(g == geometry for g in seen[-4:])
|
||||
|
||||
# a transition resizes in steps: the geometry counts once it has been the same for four looks in a row
|
||||
wait_for_condition(page, lambda: page.evaluate(GEOMETRY), held_still, "the window never held still after the fullscreen request")
|
||||
return dict(seen[-1], how=page.evaluate(HOW))
|
||||
|
||||
|
||||
def test_fullscreen_without_a_window_manager_is_the_declared_screen(firefox_binary, page_url):
|
||||
on = fullscreen_geometry(firefox_binary, page_url, engine_on=True)
|
||||
assert on["screen"] == [1600, 900], "the pinned screen is not what the page reads: %r" % on
|
||||
assert (on["innerWidth"], on["innerHeight"]) == (1600, 900), "with the engine on the fullscreen window is not the declared screen: %r" % on
|
||||
assert on["displayModeFullscreen"] is True and on["fullscreenElement"] is True, "with the engine on the page does not read fullscreen: %r" % on
|
||||
|
||||
off = fullscreen_geometry(firefox_binary, page_url, engine_on=False)
|
||||
assert (off["innerWidth"], off["innerHeight"]) != (1600, 900), "control: the engine inactive also gives the declared screen: %r" % off
|
||||
if sys.platform != "win32":
|
||||
# no window manager: Mozilla's refusal, the DOM fullscreen without the window
|
||||
assert off["displayModeFullscreen"] is False, "control: without a window manager and without the engine the window went fullscreen: %r" % off
|
||||
assert (on["innerWidth"], on["innerHeight"], on["displayModeFullscreen"]) != (off["innerWidth"], off["innerHeight"], off["displayModeFullscreen"])
|
||||
@@ -1,361 +0,0 @@
|
||||
"""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"])
|
||||
@@ -1,106 +0,0 @@
|
||||
"""``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])
|
||||
@@ -0,0 +1,76 @@
|
||||
"""A window that another one covers stays visible, unless occlusion tracking is enabled.
|
||||
|
||||
What it fixes: with ``widget.windows.window_occlusion_tracking.enabled`` and ``zoom.stealth.widget.occlusion_tracking.enabled`` false, as the core declares
|
||||
them from one value, a page whose window is fully covered by a second window keeps ``document.visibilityState`` ``visible`` and gets no ``visibilitychange``.
|
||||
Retail Windows with the tracker on says ``hidden`` there (and then throttles ``requestAnimationFrame`` to 1 Hz and the timers to 1000 ms); a session nobody
|
||||
looks at must not read as backgrounded.
|
||||
|
||||
The hook: ``nsWindow::OnVisibilityNotifyEvent`` in ``widget/gtk/nsWindow.cpp`` of the series, folder ``fingerprint/screen-window/occlusion``: the condition of the
|
||||
ternary that decides ``OCCLUDED`` or ``UNKNOWN`` reads the pref (``StealthOcclusionTracked``). On Windows the same declaration is Mozilla's own pref, so the same
|
||||
page reading is the proof that the two builds do not disagree.
|
||||
|
||||
The control, in the same test: the two prefs true. The same two sessions, the same covering, and the covered page turns ``hidden``. Without it the first half
|
||||
proves nothing (a window that was never covered is visible too); it runs first, so a runner on which two windows do not cover each other is red here and not a
|
||||
green that means nothing.
|
||||
|
||||
Two sessions are launched on one display and both are headed: the Linux e2e runs under ``xvfb-run`` (no window manager, so the second window is mapped over the
|
||||
first), Windows uses the interactive desktop of the runner (the second maximized window is created on top of the first and the tracker, when on, calculates
|
||||
the cover). A page reads it from ``document.visibilityState`` and the ``visibilitychange`` event.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from _window_sessions import in_a_thread_of_its_own, launch, wait_for_condition
|
||||
|
||||
pytestmark = pytest.mark.e2e
|
||||
|
||||
#: The one decision, under both engine names (core: ``OCCLUSION_TRACKING``).
|
||||
TRACKING_PREFS = ("widget.windows.window_occlusion_tracking.enabled", "zoom.stealth.widget.occlusion_tracking.enabled")
|
||||
|
||||
#: Records every change of visibility of the document, and answers the current state.
|
||||
WATCH = """() => {
|
||||
window.__visibility = [document.visibilityState];
|
||||
document.addEventListener('visibilitychange', () => window.__visibility.push(document.visibilityState));
|
||||
return document.visibilityState;
|
||||
}"""
|
||||
STATE = "() => document.visibilityState"
|
||||
CHANGES = "() => window.__visibility"
|
||||
#: Two painted frames: the page's own process has handled what the window system told it before this returns.
|
||||
TWO_FRAMES = "() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done)))"
|
||||
|
||||
|
||||
def opens_the_covering_window(second):
|
||||
"""Runs in the second session's own thread: opens a window on the display and waits for two painted frames."""
|
||||
cover = second.new_page()
|
||||
cover.goto("about:blank")
|
||||
cover.evaluate(TWO_FRAMES)
|
||||
|
||||
|
||||
def second_window_over_the_first(firefox_binary, tracking):
|
||||
"""(state, changes) of the first session's page after a second session's window is up over it.
|
||||
|
||||
``tracking`` is None for the product as it launches, or the value both tracking prefs are given."""
|
||||
extra = None if tracking is None else {name: tracking for name in TRACKING_PREFS}
|
||||
with launch(firefox_binary, extra_prefs=extra) as first, in_a_thread_of_its_own(firefox_binary) as second:
|
||||
covered = first.new_page()
|
||||
covered.goto("about:blank")
|
||||
assert covered.evaluate(WATCH) == "visible", "the page was not visible before anything covered it"
|
||||
second.run(opens_the_covering_window)
|
||||
if tracking:
|
||||
wait_for_condition(covered, lambda: covered.evaluate(STATE), lambda state: state == "hidden",
|
||||
"a window that another one covers never turned hidden with occlusion tracking enabled")
|
||||
else:
|
||||
covered.evaluate(TWO_FRAMES)
|
||||
return covered.evaluate(STATE), covered.evaluate(CHANGES)
|
||||
|
||||
|
||||
def test_a_covered_window_stays_visible_unless_occlusion_tracking_is_enabled(firefox_binary):
|
||||
tracked_state, tracked_changes = second_window_over_the_first(firefox_binary, True)
|
||||
assert tracked_state == "hidden" and tracked_changes == ["visible", "hidden"], (
|
||||
"control: with tracking enabled the covered page reads %r, changes %r" % (tracked_state, tracked_changes))
|
||||
|
||||
state, changes = second_window_over_the_first(firefox_binary, None)
|
||||
assert state == "visible" and changes == ["visible"], (
|
||||
"the product's covered page reads %r, changes %r: it must stay visible, with no visibilitychange" % (state, changes))
|
||||
assert state != tracked_state, "enabled and disabled read the same: the declaration decides nothing"
|
||||
Reference in new issue
Block a user