The four cases of wrapper.e2e.stock_twin.tooltip died on the engine candidate with "win.windowUtils.sendMouseEvent is not a function": Firefox 159 has no
nsIDOMWindowUtils.sendMouseEvent, its chrome input is Window.synthesizeMouseEvent. SEND_JS of the retail reference now calls
win.synthesizeMouseEvent(type, x, y, {button, clickCount, modifiers, inputSource}, {ignoreRootScrollFrame, isDOMEventSynthesized}), with Mozilla's own field names
and the same offsets (CSS pixels of the browser window).
Static check, no browser: scripts/extract_mozilla_chrome_api.py reads nsIDOMWindowUtils.idl and Window.webidl at the release tag into ci/mozilla-chrome-api.json
(path, tag, commit and sha256 of each source; what only our engine tree has is listed apart under "ours"). tests/test_the_chrome_calls_of_the_tests_exist_in_firefox.py
scans the strings of every test and script for windowUtils.<name>, .synthesize<...>( and the keys of the dictionaries those calls pass: a name that no Firefox
has is red, a name only our engine has is red in code that runs on retail or stock Firefox. Red on the old SEND_JS (sendMouseEvent is not in 159), green on this
one. The extractor has its own unit test on a small IDL and WebIDL sample.
Both files join wrapper.unit.all.linux and wrapper.unit.all.windows, min_tests raised by 18 each (12 + 6).
228 lines
11 KiB
Python
228 lines
11 KiB
Python
#!/usr/bin/env python3
|
|
"""Extracts, from Mozilla's own sources at a release tag, the names a chrome-scope script of a test may call, into ci/mozilla-chrome-api.json.
|
|
|
|
A twin of the retail Firefox runs chrome JS (through Marionette) on a Firefox that is NOT ours. A call to a name that this Firefox does not have fails there only, at the run:
|
|
``win.windowUtils.sendMouseEvent`` is not in Firefox 159 (its chrome input is ``Window.synthesizeMouseEvent``), and nothing red said so before the twins ran. The names are therefore read
|
|
from the source of the release the twins use, never typed:
|
|
|
|
* ``dom/interfaces/base/nsIDOMWindowUtils.idl``: the methods, attributes and constants of ``nsIDOMWindowUtils`` (what ``win.windowUtils.<name>`` reaches);
|
|
* ``dom/webidl/Window.webidl``: the members of ``interface Window`` and ``partial interface Window`` (with the parameter types and whether the member is ``ChromeOnly``), and every
|
|
dictionary with its fields, parents included (what the options of ``win.synthesizeMouseEvent`` may carry).
|
|
|
|
The same two files of OUR engine tree are read the same way, and what they carry that Mozilla's do not is written apart, under ``ours``: ``jugglerSendMouseEvent``, the fields of the
|
|
latency line. A call to one of those from code that runs on retail Firefox is red (tests/test_the_chrome_calls_of_the_tests_exist_in_firefox.py).
|
|
|
|
The file records, for every source, its path, the tag or commit and the sha256 of the bytes read. The wrapper's CI has no Firefox source, so the test reads the committed file and this
|
|
module's functions are tested on a small sample (tests/test_the_extractor_of_the_chrome_names_reads_idl_and_webidl.py). One command regenerates the file:
|
|
|
|
python scripts/extract_mozilla_chrome_api.py --mozilla-repo <git repository with the Mozilla tag> --tag FIREFOX_159_0_RELEASE --ours-repo <our engine tree> --ours-ref <commit> --write
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any, Dict, List, Optional, Tuple
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
DATA_PATH = ROOT / "ci" / "mozilla-chrome-api.json"
|
|
|
|
WINDOW_UTILS_IDL = "dom/interfaces/base/nsIDOMWindowUtils.idl"
|
|
WINDOW_WEBIDL = "dom/webidl/Window.webidl"
|
|
SOURCES = (WINDOW_UTILS_IDL, WINDOW_WEBIDL)
|
|
|
|
_BLOCK_COMMENT = re.compile(r"/\*.*?\*/", re.S)
|
|
_LINE_COMMENT = re.compile(r"//[^\n]*")
|
|
_LEADING_ATTRS = re.compile(r"^\s*(?:\[[^\]]*\]\s*)*")
|
|
_WORD = re.compile(r"[A-Za-z_]\w*")
|
|
|
|
|
|
def strip_comments(text: str) -> str:
|
|
"""The text without comments and without preprocessor lines."""
|
|
text = _BLOCK_COMMENT.sub(" ", text)
|
|
text = _LINE_COMMENT.sub("", text)
|
|
return "\n".join(line for line in text.splitlines() if not line.lstrip().startswith("#"))
|
|
|
|
|
|
def _bodies(text: str, header: "re.Pattern[str]") -> List[Tuple[re.Match, str]]:
|
|
"""Every ``header { body }`` of ``text`` (braces matched), with the header's match."""
|
|
out: List[Tuple[re.Match, str]] = []
|
|
for m in header.finditer(text):
|
|
depth, i = 1, m.end()
|
|
while i < len(text) and depth:
|
|
depth += {"{": 1, "}": -1}.get(text[i], 0)
|
|
i += 1
|
|
out.append((m, text[m.end():i - 1]))
|
|
return out
|
|
|
|
|
|
def _statements(body: str) -> List[str]:
|
|
"""The ``;``-terminated statements at the top level of ``body`` (a nested ``{}`` or ``()`` does not end one)."""
|
|
out, depth, cur = [], 0, []
|
|
for ch in body:
|
|
if ch in "{(":
|
|
depth += 1
|
|
elif ch in "})":
|
|
depth -= 1
|
|
if ch == ";" and depth == 0:
|
|
out.append("".join(cur).strip())
|
|
cur = []
|
|
else:
|
|
cur.append(ch)
|
|
return [s for s in out if s]
|
|
|
|
|
|
def _split_params(text: str) -> List[str]:
|
|
out, depth, cur = [], 0, []
|
|
for ch in text:
|
|
if ch in "<([":
|
|
depth += 1
|
|
elif ch in ">)]":
|
|
depth -= 1
|
|
if ch == "," and depth == 0:
|
|
out.append("".join(cur).strip())
|
|
cur = []
|
|
else:
|
|
cur.append(ch)
|
|
tail = "".join(cur).strip()
|
|
return out + [tail] if tail else out
|
|
|
|
|
|
def _params(signature: str) -> List[List[str]]:
|
|
"""``[[name, type], ...]`` of the parameters of the call in ``signature`` (``optional`` and defaults dropped, ``in`` of the IDL dropped)."""
|
|
start = signature.index("(")
|
|
depth, i = 0, start
|
|
while i < len(signature):
|
|
depth += {"(": 1, ")": -1}.get(signature[i], 0)
|
|
if depth == 0:
|
|
break
|
|
i += 1
|
|
out = []
|
|
for raw in _split_params(signature[start + 1:i]):
|
|
raw = re.sub(r"\[[^\]]*\]", " ", raw.split("=")[0])
|
|
words = [w for w in raw.replace("<", " < ").replace(">", " > ").split() if w not in ("optional", "in", "out", "inout", "required")]
|
|
text = " ".join(words).replace(" < ", "<").replace(" > ", ">").replace(" ,", ",")
|
|
if not text:
|
|
continue
|
|
m = re.search(r"(\w+)$", text)
|
|
out.append([m.group(1), text[:m.start()].strip()])
|
|
return out
|
|
|
|
|
|
def window_utils(idl_text: str) -> Dict[str, List[str]]:
|
|
"""The methods, attributes and constants of ``nsIDOMWindowUtils`` in the text of its IDL file."""
|
|
text = strip_comments(idl_text)
|
|
methods, attributes, constants = set(), set(), set()
|
|
for _m, body in _bodies(text, re.compile(r"interface\s+nsIDOMWindowUtils\b[^{;]*\{")):
|
|
for statement in _statements(body):
|
|
rest = _LEADING_ATTRS.sub("", statement).strip()
|
|
if rest.startswith("const "):
|
|
constants.add(_WORD.findall(rest.split("=")[0])[-1])
|
|
elif re.search(r"\battribute\b", rest):
|
|
attributes.add(_WORD.findall(rest.split("=")[0])[-1])
|
|
elif "(" in rest:
|
|
methods.add(_WORD.findall(rest.split("(")[0])[-1])
|
|
return {"methods": sorted(methods), "attributes": sorted(attributes), "constants": sorted(constants)}
|
|
|
|
|
|
def window(webidl_text: str) -> Dict[str, Any]:
|
|
"""The members of ``Window`` (``interface`` and ``partial interface``) and every dictionary, parents folded in, from the text of a WebIDL file."""
|
|
text = strip_comments(webidl_text)
|
|
methods: Dict[str, Dict[str, Any]] = {}
|
|
attributes: Dict[str, Dict[str, Any]] = {}
|
|
for _m, body in _bodies(text, re.compile(r"(?:partial\s+)?interface\s+Window\b[^{;]*\{")):
|
|
for statement in _statements(body):
|
|
attrs = re.match(r"^\s*((?:\[[^\]]*\]\s*)*)", statement).group(1)
|
|
rest = _LEADING_ATTRS.sub("", statement).strip()
|
|
chrome_only = bool(re.search(r"\bChromeOnly\b", attrs))
|
|
if re.search(r"\battribute\b", rest):
|
|
attributes[_WORD.findall(rest.split("=")[0])[-1]] = {"chrome_only": chrome_only}
|
|
elif "(" in rest and not rest.startswith("constructor"):
|
|
name = _WORD.findall(rest.split("(")[0])[-1]
|
|
methods[name] = {"chrome_only": chrome_only, "params": _params(rest)}
|
|
own: Dict[str, Tuple[Optional[str], List[str]]] = {}
|
|
for m, body in _bodies(text, re.compile(r"dictionary\s+(\w+)\s*(?::\s*(\w+))?\s*\{")):
|
|
fields = []
|
|
for statement in _statements(body):
|
|
rest = _LEADING_ATTRS.sub("", statement.split("=")[0]).strip()
|
|
if rest:
|
|
fields.append(_WORD.findall(rest)[-1])
|
|
own[m.group(1)] = (m.group(2), fields)
|
|
|
|
def flat(name: str) -> List[str]:
|
|
parent, fields = own[name]
|
|
return sorted(set(fields) | (set(flat(parent)) if parent in own else set()))
|
|
|
|
return {
|
|
"methods": {k: methods[k] for k in sorted(methods)},
|
|
"attributes": {k: attributes[k] for k in sorted(attributes)},
|
|
"dictionaries": {k: flat(k) for k in sorted(own)},
|
|
}
|
|
|
|
|
|
def extract(idl_text: str, webidl_text: str) -> Dict[str, Any]:
|
|
return {"window_utils": window_utils(idl_text), "window": window(webidl_text)}
|
|
|
|
|
|
def only_in_ours(mozilla: Dict[str, Any], ours: Dict[str, Any]) -> Dict[str, Any]:
|
|
"""What the extraction of our tree carries and Mozilla's does not."""
|
|
out: Dict[str, Any] = {"window_utils": {}, "window": {"methods": [], "attributes": [], "dictionaries": {}}}
|
|
for kind in ("methods", "attributes", "constants"):
|
|
out["window_utils"][kind] = sorted(set(ours["window_utils"][kind]) - set(mozilla["window_utils"][kind]))
|
|
for kind in ("methods", "attributes"):
|
|
out["window"][kind] = sorted(set(ours["window"][kind]) - set(mozilla["window"][kind]))
|
|
for name, fields in ours["window"]["dictionaries"].items():
|
|
extra = sorted(set(fields) - set(mozilla["window"]["dictionaries"].get(name, [])))
|
|
if extra:
|
|
out["window"]["dictionaries"][name] = extra
|
|
return out
|
|
|
|
|
|
def _git_show(repo: Path, ref: str, path: str) -> bytes:
|
|
return subprocess.run(["git", "-C", str(repo), "show", "%s:%s" % (ref, path)], check=True, capture_output=True).stdout
|
|
|
|
|
|
def _read_source(repo: Path, ref: str) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
|
blobs = {path: _git_show(repo, ref, path) for path in SOURCES}
|
|
parsed = extract(blobs[WINDOW_UTILS_IDL].decode("utf-8"), blobs[WINDOW_WEBIDL].decode("utf-8"))
|
|
sources = [{"path": path, "sha256": hashlib.sha256(blobs[path]).hexdigest()} for path in SOURCES]
|
|
commit = subprocess.run(["git", "-C", str(repo), "rev-parse", "%s^{commit}" % ref], check=True, capture_output=True, text=True).stdout.strip()
|
|
return parsed, {"ref": ref, "commit": commit, "files": sources}
|
|
|
|
|
|
def build(mozilla_repo: Path, tag: str, ours_repo: Path, ours_ref: str) -> Dict[str, Any]:
|
|
mozilla, mozilla_source = _read_source(mozilla_repo, tag)
|
|
ours, ours_source = _read_source(ours_repo, ours_ref)
|
|
return {
|
|
"about": "Names a chrome-scope script of a test may call on the retail Firefox of the twins, extracted by scripts/extract_mozilla_chrome_api.py. Never edited by hand.",
|
|
"mozilla": dict(mozilla_source, **mozilla),
|
|
"ours": dict(ours_source, **only_in_ours(mozilla, ours)),
|
|
}
|
|
|
|
|
|
def main(argv: Optional[List[str]] = None) -> int:
|
|
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
|
ap.add_argument("--mozilla-repo", type=Path, required=True)
|
|
ap.add_argument("--tag", required=True)
|
|
ap.add_argument("--ours-repo", type=Path, required=True)
|
|
ap.add_argument("--ours-ref", required=True)
|
|
ap.add_argument("--write", action="store_true", help="write ci/mozilla-chrome-api.json; without it the file is compared and the exit is 1 when it differs")
|
|
args = ap.parse_args(argv)
|
|
data = build(args.mozilla_repo, args.tag, args.ours_repo, args.ours_ref)
|
|
text = json.dumps(data, indent=2, sort_keys=True) + "\n"
|
|
if args.write:
|
|
DATA_PATH.write_text(text, encoding="utf-8", newline="\n")
|
|
print("wrote %s" % DATA_PATH)
|
|
return 0
|
|
same = DATA_PATH.read_text(encoding="utf-8") == text
|
|
print("%s %s" % (DATA_PATH, "is what the sources give" if same else "DIFFERS from what the sources give: regenerate it with --write"))
|
|
return 0 if same else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|