Profile gains a Telegram card beside Friends, Data and Account & sync, opening the same Telegram panel Settings had; without an account its button opens Account & sync. Settings drops its Telegram tab and the Data row on phones, so it lists only this device's preferences. A saved Telegram tab opens Device. The Data Back test checks that Settings no longer lists Data; the QR test finds Apps by its label wherever the rail puts it; the Telegram panel test gets the qrcode package path its imports now need. Co-Authored-By: Claude Opus 5.5 <[email protected]>
153 lines
7.5 KiB
Python
153 lines
7.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Back from navigation Data exits once; Profile Data returns to its hub, whose Back returns to Apps.
|
|
Data lives in Profile, so the Settings hub no longer lists it."""
|
|
import csv
|
|
import io
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
from PIL import Image, ImageOps
|
|
from native_visual_test import read_text
|
|
|
|
assert int(os.environ.get("DISPLAY", ":0").split(":")[-1].split(".")[0]) >= 300
|
|
root = Path(__file__).resolve().parents[1]
|
|
binary = Path(sys.argv[1]).resolve()
|
|
output = root / "build/data-back-ui-test"
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def command(*args):
|
|
return subprocess.check_output(args, text=True, timeout=5).strip()
|
|
|
|
|
|
def click(window, x, y):
|
|
command("xdotool", "mousemove", "--window", window, str(x), str(y),
|
|
"mousedown", "1", "sleep", "0.12", "mouseup", "1")
|
|
time.sleep(0.5)
|
|
|
|
|
|
def capture_title(window, name, width):
|
|
path = output / (name + ".png")
|
|
command("import", "-window", window, str(path))
|
|
with Image.open(path) as image:
|
|
left = 88 if width >= 640 else 0
|
|
return read_text(image.crop((left, 0, width, 64)), name)
|
|
|
|
|
|
def screen_words(window, path, width, height):
|
|
"""Rendered words with positions at three times the window size."""
|
|
ocr_path = path.with_name(path.stem + "-ocr.png")
|
|
command("import", "-window", window, str(path))
|
|
with Image.open(path) as image:
|
|
gray = ImageOps.autocontrast(ImageOps.grayscale(image))
|
|
gray.resize((width * 3, height * 3)).save(ocr_path)
|
|
text = command("tesseract", str(ocr_path), "stdout", "--psm", "11",
|
|
"-c", "tessedit_create_tsv=1")
|
|
ocr_path.unlink()
|
|
return list(csv.DictReader(io.StringIO(text), delimiter="\t"))
|
|
|
|
|
|
def click_word(window, word):
|
|
click(window, (int(word["left"]) + int(word["width"]) // 2) // 3,
|
|
(int(word["top"]) + int(word["height"]) // 2) // 3)
|
|
|
|
|
|
def settings_lists_data(window, name, width, height):
|
|
return any(word.get("text", "").lower() == "data"
|
|
for word in screen_words(window, output / (name + "-overview.png"), width, height))
|
|
|
|
|
|
def open_practice(window, name, width, height):
|
|
path = output / (name + "-navigation.png")
|
|
words = [word for word in screen_words(window, path, width, height)
|
|
# An unselected favorite can be partially offscreen in the
|
|
# scrolling dock. Selecting it must then reveal the whole label.
|
|
if word.get("text", "").lower().startswith("pract")
|
|
and (int(word["left"]) < 88 * 3 if width >= 640
|
|
else int(word["top"]) > (height - 84) * 3)]
|
|
assert len(words) == 1, "The rendered Practice navigation shortcut is missing or ambiguous"
|
|
click_word(window, words[0])
|
|
command("import", "-window", window, str(path))
|
|
with Image.open(path) as image:
|
|
# On phones read only the label row: CI's tesseract 5.3.4 misreads
|
|
# the dock when its icons and the selection outline are included.
|
|
dock = image.crop((0, 0, 88, height)) if width >= 640 else image.crop((0, height - 24, width, height - 4))
|
|
assert "practice" in read_text(dock, name + "-selected-navigation"), \
|
|
"Selecting Practice did not reveal its complete navigation label"
|
|
|
|
|
|
for scene in ("data_from_navigation", "profile_data", "settings_overview"):
|
|
sizes = ((360, 740),) if scene == "settings_overview" else ((900, 720), (360, 740))
|
|
for width, height in sizes:
|
|
name = f"{scene}-{width}"
|
|
logfile = output / f"{name}.log"
|
|
initial = output / f"{name}.png"
|
|
env = os.environ.copy()
|
|
env.update(APP_SHOT_WINDOW="1", APP_NO_TRAY="1", INBE_DEBUG_ROUTE="1",
|
|
SDL_VIDEODRIVER="x11", YUE_DESKTOP_RECOVERY="0")
|
|
with logfile.open("w") as log:
|
|
app = subprocess.Popen([str(binary), "--screenshot", str(initial),
|
|
"--bundle", str(root / "build/inbe-full.zib"),
|
|
"--screenshot-scene", scene, "--screenshot-width", str(width),
|
|
"--screenshot-height", str(height), "--screenshot-ui-scale", "10"],
|
|
cwd=root, env=env, stdout=log, stderr=subprocess.STDOUT)
|
|
try:
|
|
deadline = time.monotonic() + 15
|
|
window = ""
|
|
while time.monotonic() < deadline:
|
|
assert app.poll() is None, logfile.read_text()[-2000:]
|
|
found = subprocess.run(["xdotool", "search", "--onlyvisible", "--pid", str(app.pid)],
|
|
capture_output=True, text=True)
|
|
database = Path('/tmp') / f'inbe-screenshot-{app.pid}' / 'inbe.db'
|
|
if found.returncode == 0 and found.stdout.strip() and database.is_file():
|
|
window = found.stdout.splitlines()[0]
|
|
break
|
|
time.sleep(0.1)
|
|
assert window, "private child did not become ready"
|
|
command("xdotool", "windowfocus", "--sync", window)
|
|
time.sleep(0.5)
|
|
if scene == "settings_overview":
|
|
assert "settings" in capture_title(window, name + "-initial", width)
|
|
assert not settings_lists_data(window, name, width, height), "Settings still lists Data"
|
|
continue
|
|
title = capture_title(window, name + "-data", width)
|
|
assert "data" in title, (name, "Data did not render before Back", title)
|
|
baseline = len(logfile.read_text())
|
|
back_x = 88 + 26 if width >= 640 else 26
|
|
click(window, back_x, 24)
|
|
after = logfile.read_text()[baseline:]
|
|
switches = re.findall(r"ROUTE switch frame=\d+ screen=(\d+)->(\d+)", after)
|
|
if scene == "data_from_navigation":
|
|
assert switches == [("10", "16")], (name, switches, after[-1200:])
|
|
else:
|
|
assert switches == [], (name, "Profile Data skipped its parent", switches)
|
|
command("import", "-window", window, str(output / f"{name}-hub.png"))
|
|
assert "profile" in capture_title(window, name + "-parent", width)
|
|
# The Profile hub's Back returns to Apps: one switch
|
|
# leaves Profile, and Data was not skipped on the way.
|
|
click(window, back_x, 24)
|
|
left = re.findall(r"ROUTE switch frame=\d+ screen=(\d+)->(\d+)",
|
|
logfile.read_text()[baseline:])
|
|
assert len(left) == 1 and left[0][0] == "10", (name, "Profile hub Back did not leave Profile once", left)
|
|
open_practice(window, name, width, height)
|
|
after = logfile.read_text()[baseline:]
|
|
switches = re.findall(r"ROUTE switch frame=\d+ screen=(\d+)->(\d+)", after)
|
|
assert switches[-1][1] == "0", (name, switches, after[-1200:])
|
|
time.sleep(0.5)
|
|
command("import", "-window", window, str(output / f"{name}-after.png"))
|
|
assert "APP: frame rejected with status" not in logfile.read_text()
|
|
finally:
|
|
app.terminate()
|
|
try:
|
|
app.wait(timeout=5)
|
|
except subprocess.TimeoutExpired:
|
|
app.kill()
|
|
app.wait(timeout=5)
|
|
shutil.rmtree(Path('/tmp') / f'inbe-screenshot-{app.pid}', ignore_errors=True)
|
|
print("Data Back: navigation exits once; Profile Data returns to its hub, whose Back returns to Apps; Settings lists no Data")
|