Compare commits

...
Author SHA1 Message Date
feder-cr 3ec01d7dde tests: the canvas text a page reads is the same bytes on every host (wrapper.e2e.text-bytes, the idwr line)
Windows: every text key of page_bytes_probe.js and 80 single-font draws (tests/text_bytes_probe.js) against tests/data/text_bytes_reference.json, recorded with the idwr canvas engine on windows-2025 and equal on windows-2022 (run 43744178165). On the engine with the host's DWrite, windows-2022 differs from it on 7 keys and 9 draws (run 43718413937). Linux: the same but the 6 synthetic-bold fallback draws and the composite keys that hold them, covered by their own test with the port that fixes them. Gated engine_at_least("firefox-66").
2026-11-15 19:24:16 +01:00
4 changed files with 1197 additions and 1 deletions

No files matched your search

+2 -1
View File
@@ -11,5 +11,6 @@
{"id": "wrapper.e2e.page", "giro": "G2", "os": ["linux", "windows"], "min_tests": 120, "exact": true, "tests": ["tests/test_a_tiny_download_on_a_served_browser_is_saved_e2e.py", "tests/test_a_page_that_moves_on_e2e.py", "tests/test_a_popup_is_reported_when_the_engine_says_it_is_ready_as_playwright_does_e2e.py", "tests/test_a_popup_of_a_link_reaches_the_client_e2e.py", "tests/test_popup_destinations_e2e.py", "tests/test_popups_reach_the_client_e2e.py", "tests/test_route_superseded_e2e.py", "tests/test_closing_one_of_four_browsers_does_not_hold_the_loop_e2e.py"], "marker": "e2e", "needs_root": false, "note": "114 + the 5 of test_closing_one_of_four_browsers_does_not_hold_the_loop_e2e.py (four browsers in one process, one closes: the loop is held less than 50 ms by the clock of its own thread, the other three keep answering; the control holds the loop on purpose). 114 = 100 + the 14 of test_a_page_that_moves_on_e2e.py (a navigation the page overtook with location.replace ends; the engine fix 860ef8a6d9 is proved by it). 100 counted at the collection; was 96 = 10+32+16+34+4 before the popup tests of 6200bc2). A page is handed over when the engine says Page.ready; a popup reaches the client (link, noopener, window.open; own site and another; with and without a route; in-process and over launch_server) as Playwright's does; a superseded route. Needs the candidate binary, and the stock Playwright client of the dev extra."},
{"id": "wrapper.unit.page", "giro": "G1", "os": ["linux", "windows"], "min_tests": 72, "exact": true, "tests": ["tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_page_number_follows_the_call.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_the_hand_over_of_a_popup_holds_under_concurrency.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py"], "marker": "unit", "needs_root": false, "note": "72 = 44 + 3+9+5+1+10 of the popup hand-over (24 counted at the collection before; was 20 = 3+8+1+8 before 6200bc2). The page dispatcher's wait for Page.ready and what it hands over; the drive gate goes through the core (the engine waits for the session's road)."},
{"id": "wrapper.e2e.compositing", "giro": "G2", "os": ["linux", "windows"], "min_tests": 3, "exact": true, "tests": ["tests/test_software_compositing_is_declared_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The engine DECLARES software compositing on every machine (core: the compositing entries of zoom.stealth.gfx.feature_status carry the VM decision, and on Windows gfx.webrender.software=true, gfx.webrender.software.d3d11=false). 3 = (1) the compositor read from a privileged context is 'WebRender (Software)' on Windows and on Linux (windowUtils.layerManagerType of each window: Troubleshoot.snapshot().graphics throws on this engine, `ext is null`, so it is not the route); (2) the GPU process uses under 1.5 s of CPU on the fixed 10-scene loop of one browser (Windows runner: 0.32 s declared, 2.7-4.2 s not, runs 43652292533 and 43642744101; on Linux it is held to the bound if a GPU process exists); (3) the 86 keys of the page-bytes probe plus the canvas 2D scenes (drawImage scaled with smoothing off/low/medium/high, text with linear/radial/conic gradients) equal tests/data/page_bytes_<os>.json, PNGs on decoded pixels. EXPECTED RED on the core 64.71.0 (tests 1 and 2 on Windows). The reference of Windows holds the 75 stable keys and 6 of the 11 PNG keys of run 43652292533; the five other PNG keys and the new canvas keys, and all of Linux, are written from the first run on the engine of the reference (the failure of test 3 prints RECORD-BEGIN ... RECORD-END with the entries to merge): a reference that is not complete is red, never skipped."},
{"id": "wrapper.unit.compositing", "giro": "G1", "os": ["linux", "windows"], "min_tests": 19, "exact": true, "tests": ["tests/test_the_page_bytes_reference_compares_decoded_pixels.py"], "marker": "unit", "needs_root": false, "note": "The helpers of wrapper.e2e.compositing on known inputs, no browser: the PNG compared on decoded pixels (another deBG chunk and compression are the same, one pixel is not, every scanline filter), the comparison with a reference (changed, missing and extra keys named, the entry to record), the type of an engine process, an engine process known by its executable and not by the name it gives itself (Linux), and the CPU of a window, and the shape of the committed Windows reference."}
{"id": "wrapper.unit.compositing", "giro": "G1", "os": ["linux", "windows"], "min_tests": 19, "exact": true, "tests": ["tests/test_the_page_bytes_reference_compares_decoded_pixels.py"], "marker": "unit", "needs_root": false, "note": "The helpers of wrapper.e2e.compositing on known inputs, no browser: the PNG compared on decoded pixels (another deBG chunk and compression are the same, one pixel is not, every scanline filter), the comparison with a reference (changed, missing and extra keys named, the entry to record), the type of an engine process, an engine process known by its executable and not by the name it gives itself (Linux), and the CPU of a window, and the shape of the committed Windows reference."},
{"id": "wrapper.e2e.text-bytes", "giro": "G2", "os": ["linux", "windows"], "min_tests": 3, "exact": true, "tests": ["tests/test_text_bytes_are_the_same_on_every_host_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The canvas text a page reads is the same bytes on every host, against tests/data/text_bytes_reference.json (recorded with the idwr canvas engine on windows-2025, equal on windows-2022: run 43744178165). Windows: every text key of page_bytes_probe.js and the 80 single-font draws of text_bytes_probe.js; red on the engine with the host's DWrite (windows-2022 against the windows-2025 reference: 7 keys, 9 draws, run 43718413937). Linux: the same but the 6 draws of a fallback face made bold synthetically and the 3 composite keys holding them, which tests/test_synthetic_bold_of_a_fallback_face_is_windows_e2e.py covers when the port of the synthetic bold lands. Gated engine_at_least(\"firefox-66\") (the idwr line). 3 = keys + draws + the reference's own shape."}
]
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,141 @@
"""The canvas text a page reads is the same bytes on every host: one seed, one set of bytes, whatever Windows build or OS runs it.
With the host's DWrite.dll rasterizing the glyphs, the same seed gave different canvas-text bytes on windows-2022 (DWrite
10.0.20348) and windows-2025 (10.0.26100): 7 keys and 9 of 80 single-font draws, with the measureText boxes identical and
georgia.ttf and verdana.ttf byte-identical on both hosts (oss-invisible/playwright run 43718413937; DWriteCore
captures/host-env/page-bytes-windows-2022-vs-2025). With idwr answering in place of DWrite.dll in the canvas path the two Windows
hosts give the same bytes, recorded in tests/data/text_bytes_reference.json (run 43744178165).
* Windows: every text key of page_bytes_probe.js and every one of the 80 draws of text_bytes_probe.js equals the reference. On
windows-2022 it fails on today's engine (7 keys, 9 draws) and passes with idwr.
* Linux: the same, except the draws whose glyphs come from a fallback face made bold synthetically (CJK and emoji text in a bold
font that has no such glyphs) and the composite keys that contain them. That synthetic bold is the one place Linux and Windows
still differ (Windows 0.1 to 1.7 px wider, other ink), and it has a test of its own that is red until it is fixed:
tests/test_synthetic_bold_of_a_fallback_face_is_windows_e2e.py, which comes with the port that fixes it.
A difference names its key or its (font, text) draw, so a failure says which font and script moved.
"""
from __future__ import annotations
import json
import sys
import threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
import pytest
pytestmark = pytest.mark.e2e
TESTS = Path(__file__).resolve().parent
REFERENCE = TESTS / "data" / "text_bytes_reference.json"
#: What a launch is given when the reference was recorded: the same seed, locale and timezone, so the same persona.
LAUNCH = dict(seed=42, headless=True, locale="en-US", timezone="Europe/Rome")
#: The keys of page_bytes_probe.js that are canvas or DOM text.
TEXT_KEYS = ("c2d.text.", "c2d.gradtext.", "c2d.offscreen.", "c2d.measure", "dom.span_boxes", "dom.paragraphs")
#: The composite keys that draw CJK or emoji text in a bold font (page_bytes_probe.js FONTS x TEXTS): on Linux they hold the
#: synthetic bold of a fallback face, which the test of the synthetic bold covers.
HOLDS_SYNTHETIC_BOLD = ("c2d.text.", "c2d.measure", "dom.span_boxes")
def synthetic_bold_of_a_fallback(draw) -> bool:
"""A draw whose glyphs come from a fallback face made bold: CJK or emoji text in a bold font with no such glyphs."""
return draw["font"].startswith("bold ") and draw["text"] in ("cjk", "emoji")
class _Page(BaseHTTPRequestHandler):
def log_message(self, *args):
pass
def do_GET(self): # noqa: N802
body = b"<!doctype html><meta charset=utf-8><title>probe</title><body></body>"
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
@pytest.fixture(scope="module")
def measured(firefox_binary, engine_at_least):
"""The text keys and the 80 draws of this host, once for the module."""
engine_at_least("firefox-66")
import _page_bytes
from invisible_playwright import InvisiblePlaywright
server = ThreadingHTTPServer(("127.0.0.1", 0), _Page)
threading.Thread(target=server.serve_forever, daemon=True).start()
url = "http://127.0.0.1:%d/" % server.server_address[1]
try:
with InvisiblePlaywright(binary_path=firefox_binary, **LAUNCH) as browser:
page = browser.new_page()
page.goto(url, wait_until="load", timeout=60000)
keys = page.evaluate((TESTS / "page_bytes_probe.js").read_text(encoding="utf-8"))
page.goto(url, wait_until="load", timeout=60000)
draws = page.evaluate((TESTS / "text_bytes_probe.js").read_text(encoding="utf-8"))
finally:
server.shutdown()
entries = {k: _page_bytes.entry_of(k, v) for k, v in keys.items() if k.startswith(TEXT_KEYS)}
return entries, draws
@pytest.fixture(scope="module")
def reference():
return json.loads(REFERENCE.read_text(encoding="utf-8"))
def _same(a, b) -> bool:
return json.dumps(a, sort_keys=True) == json.dumps(b, sort_keys=True)
def _key_problems(entries, reference, skip=()):
out = []
for key, want in sorted(reference["entries"].items()):
if key.startswith(skip):
continue
got = entries.get(key)
if got is None:
out.append("%s: missing" % key)
elif not _same(got, want):
out.append("%s: %s, the reference %s" % (key, json.dumps(got, sort_keys=True)[:160], json.dumps(want, sort_keys=True)[:160]))
return out
def _draw_problems(draws, reference, keep=lambda draw: True):
out = []
want = {(d["font"], d["text"]): d for d in reference["each_font"]}
got = {(d["font"], d["text"]): d for d in draws}
for name, w in sorted(want.items()):
if not keep(w):
continue
g = got.get(name)
if g is None:
out.append("%s %s: not drawn" % name)
continue
moved = [f for f in ("raster", "ink", "width", "asc", "desc", "fasc", "fdesc", "check") if g.get(f) != w.get(f)]
if moved:
out.append("%s %s: %s" % (name[0], name[1], ", ".join("%s %r (reference %r)" % (f, g.get(f), w.get(f)) for f in moved)))
return out
def test_the_canvas_text_keys_are_the_reference_of_every_host(measured, reference):
"""Windows: every text key. Linux: every text key but the composite ones that hold the synthetic bold of a fallback face."""
entries, _ = measured
skip = HOLDS_SYNTHETIC_BOLD if sys.platform.startswith("linux") else ()
problems = _key_problems(entries, reference, skip)
assert not problems, "%d text key(s) differ from the reference (%s):\n %s" % (len(problems), reference["_source"], "\n ".join(problems))
def test_every_font_and_script_draws_the_reference_bytes(measured, reference):
"""The 80 single-font draws, raster and boxes. Linux leaves out the 6 synthetic-bold fallback draws, tested on their own."""
_, draws = measured
keep = (lambda draw: not synthetic_bold_of_a_fallback(draw)) if sys.platform.startswith("linux") else (lambda draw: True)
problems = _draw_problems(draws, reference, keep)
assert not problems, "%d draw(s) differ from the reference:\n %s" % (len(problems), "\n ".join(problems))
def test_the_reference_was_the_same_on_both_windows_hosts_and_names_its_source(reference):
"""The reference is one set of bytes for every host: recorded on windows-2025, equal on windows-2022, with its engine and run."""
assert "windows-2025" in reference["_source"] and "windows-2022" in reference["_source"]
assert len(reference["each_font"]) == 80
assert sum(1 for d in reference["each_font"] if synthetic_bold_of_a_fallback(d)) == 6
+28
View File
@@ -0,0 +1,28 @@
// The canvas text of each probe font drawn alone, one string at a time: its raster (sha-256 of the RGBA, first 8 bytes), its ink and its
// measureText boxes. One row per (font, text) says WHICH font and script a difference comes from, where the composite keys of
// page_bytes_probe.js only say that something changed. Used by tests/test_text_bytes_are_the_same_on_every_host_e2e.py.
async () => {
const FONTS = ["16px sans-serif", "20px serif", "18px monospace", "bold 16px Arial", "italic 15px 'Segoe UI'", "16px 'Times New Roman'",
"16px Calibri", "14px Consolas", "16px Verdana", "16px Tahoma", "17px Georgia", "16px 'Segoe UI Emoji'", "16px 'Microsoft YaHei'",
"16px 'Yu Gothic'", "bold 40px sans-serif", "italic 34px serif", "28px monospace", "bold 44px Arial", "36px 'Times New Roman'", "30px 'Segoe UI'"];
const TEXTS = {latin: "Hamburgefonstiv 0123456789 Ag", cjk: "日本語のテキスト 漢字", emoji: "😀🚀👍🏽", arabic: "مرحبا بالعالم"};
async function digest(data) {
const h = await crypto.subtle.digest("SHA-256", data);
return Array.from(new Uint8Array(h)).slice(0, 8).map((b) => b.toString(16).padStart(2, "0")).join("");
}
const out = [];
for (const f of FONTS) {
for (const [name, t] of Object.entries(TEXTS)) {
const c = document.createElement("canvas"); c.width = 640; c.height = 64;
const g = c.getContext("2d"); g.fillStyle = "#fff"; g.fillRect(0, 0, 640, 64);
g.font = f; g.fillStyle = "#101820"; g.textBaseline = "alphabetic"; g.fillText(t, 4, 44);
const m = g.measureText(t);
const px = g.getImageData(0, 0, 640, 64).data;
let ink = 0; for (let i = 0; i < px.length; i += 4) if (px[i] < 250) ink++;
out.push({font: f, text: name, raster: await digest(px), ink, width: m.width, asc: m.actualBoundingBoxAscent,
desc: m.actualBoundingBoxDescent, fasc: m.fontBoundingBoxAscent, fdesc: m.fontBoundingBoxDescent,
check: document.fonts.check(f)});
}
}
return out;
}